#include <stdio.h>
#include <stdlib.h>
#include "allheaders.h"
Макросы | |
#define | NFONTS 9 |
#define | DEBUG_BASELINE 0 |
#define | DEBUG_CHARS 0 |
#define | DEBUG_FONT_GEN 0 |
Функции | |
static l_int32 | pixGetTextBaseline (PIX *pixs, l_int32 *tab8, l_int32 *py) |
static l_int32 | bmfMakeAsciiTables (BMF *bmf) |
BMF * | bmfCreate (const char *dir, l_int32 size) |
void | bmfDestroy (BMF **pbmf) |
PIX * | bmfGetPix (BMF *bmf, char chr) |
l_int32 | bmfGetWidth (BMF *bmf, char chr, l_int32 *pw) |
l_int32 | bmfGetBaseline (BMF *bmf, char chr, l_int32 *pbaseline) |
PIXA * | pixaGetFont (const char *dir, l_int32 size, l_int32 *pbl0, l_int32 *pbl1, l_int32 *pbl2) |
l_int32 | pixaSaveFont (const char *indir, const char *outdir, l_int32 size) |
PIXA * | pixaGenerateFont (const char *dir, l_int32 size, l_int32 *pbl0, l_int32 *pbl1, l_int32 *pbl2) |
Переменные | |
static const char * | inputfonts [] |
static const char * | outputfonts [] |
static const l_int32 | baselines [NFONTS][3] |
static const l_float32 | VERT_FRACT_SEP = 0.3 |
#define DEBUG_BASELINE 0 |
#define DEBUG_CHARS 0 |
#define DEBUG_FONT_GEN 0 |
#define NFONTS 9 |
Input: dir (directory holding pixa of character set) size (4, 6, 8, ... , 20) Return: bmf (holding the bitmap font and associated information)
Notes: (1) This first tries to read a pre-computed pixa file with the 95 ascii chars in it. If the file is not found, it creates the pixa from the raw image. It then generates all associated data required to use the bmf.
void bmfDestroy | ( | BMF ** | pbmf | ) |
Input: &bmf (<set to="" null>="">) Return: void
Input: bmf chr (should be one of the 95 supported bitmaps) &baseline (<return>; distance below UL corner of bitmap char) Return: 0 if OK, 1 on error
Input: bmf chr (should be one of the 95 supported printable bitmaps) Return: pix (clone of pix in bmf), or null on error
Input: bmf chr (should be one of the 95 supported bitmaps) &w (<return> character width; -1 if not printable) Return: 0 if OK, 1 on error
bmfMakeAsciiTables
Input: bmf Return: 0 if OK, 1 on error
Notes: (1) This makes three tables, each of size 128, as follows:
PIXA* pixaGenerateFont | ( | const char * | dir, | |
l_int32 | size, | |||
l_int32 * | pbl0, | |||
l_int32 * | pbl1, | |||
l_int32 * | pbl2 | |||
) |
Input: dir (directory holding image of character set) size (4, 6, 8, ... , 20, in pts at 300 ppi) &bl1 (<return> baseline of row 1) &bl2 (<return> baseline of row 2) &bl3 (<return> baseline of row 3) Return: pixa of font bitmaps for 95 characters, or null on error
These font generation functions use 9 sets, each with bitmaps of 94 ascii characters, all in Palatino-Roman font. Each input bitmap has 3 rows of characters. The range of ascii values in each row is as follows: row 0: 32-57 (32 is a space) row 1: 58-91 (92, '\', is not represented in this font) row 2: 93-126 We LR flip the '/' char to generate a bitmap for the missing '\' character, so that we have representations of all 95 printable chars.
Computation of the bitmaps and baselines for a single font takes from 40 to 200 msec on a 2 GHz processor, depending on the size. Use pixaGetFont() to read the generated character set directly from files that were produced in prog/genfonts.c using this function.
PIXA* pixaGetFont | ( | const char * | dir, | |
l_int32 | size, | |||
l_int32 * | pbl0, | |||
l_int32 * | pbl1, | |||
l_int32 * | pbl2 | |||
) |
Input: dir (directory holding pixa of character set) size (4, 6, 8, ... , 20) &bl1 (<return> baseline of row 1) &bl2 (<return> baseline of row 2) &bl3 (<return> baseline of row 3) Return: pixa of font bitmaps for 95 characters, or null on error
Notes: (1) This reads a pre-computed pixa file with the 95 ascii chars.
Input: indir (directory holding image of character set) outdir (directory into which the output pixa file will be written) size (in pts, at 300 ppi) Return: 0 if OK, 1 on error
Notes: (1) This saves a font of a particular size. (2) prog/genfonts calls this function for each of the nine font sizes, to generate all the font pixa files.
Input: pixs (1 bpp, one textline character set) tab8 (<optional> pixel sum table) &y (<return> baseline value) Return: 0 if OK, 1 on error
Notes: (1) Method: find the largest difference in pixel sums from one raster line to the next one below it. The baseline is the upper raster line for the pair of raster lines that maximizes this function.
Инициализатор
{{11, 12, 12}, {18, 18, 18}, {24, 24, 24}, {30, 30, 30}, {36, 36, 36}, {42, 42, 42}, {48, 48, 48}, {54, 54, 54}, {60, 60, 60}}
const char* inputfonts[] [static] |
Инициализатор
{"chars-4.tif", "chars-6.tif", "chars-8.tif", "chars-10.tif", "chars-12.tif", "chars-14.tif", "chars-16.tif", "chars-18.tif", "chars-20.tif"}
const char* outputfonts[] [static] |
Инициализатор
{"chars-4.pixa", "chars-6.pixa", "chars-8.pixa", "chars-10.pixa", "chars-12.pixa", "chars-14.pixa", "chars-16.pixa", "chars-18.pixa", "chars-20.pixa"}
const l_float32 VERT_FRACT_SEP = 0.3 [static] |