![]() |
Leptonica
1.82.0
Image processing and image analysis suite
|
Go to the source code of this file.
Macros | |
#define | DEBUG_BASELINE 0 |
#define | DEBUG_CHARS 0 |
#define | DEBUG_FONT_GEN 0 |
Functions | |
static PIXA * | pixaGenerateFontFromFile (const char *dir, l_int32 fontsize, l_int32 *pbl0, l_int32 *pbl1, l_int32 *pbl2) |
static PIXA * | pixaGenerateFontFromString (l_int32 fontsize, l_int32 *pbl0, l_int32 *pbl1, l_int32 *pbl2) |
static PIXA * | pixaGenerateFont (PIX *pixs, l_int32 fontsize, l_int32 *pbl0, l_int32 *pbl1, l_int32 *pbl2) |
static l_int32 | pixGetTextBaseline (PIX *pixs, l_int32 *tab8, l_int32 *py) |
static l_int32 | bmfMakeAsciiTables (L_BMF *bmf) |
L_BMF * | bmfCreate (const char *dir, l_int32 fontsize) |
void | bmfDestroy (L_BMF **pbmf) |
PIX * | bmfGetPix (L_BMF *bmf, char chr) |
l_ok | bmfGetWidth (L_BMF *bmf, char chr, l_int32 *pw) |
l_ok | bmfGetBaseline (L_BMF *bmf, char chr, l_int32 *pbaseline) |
PIXA * | pixaGetFont (const char *dir, l_int32 fontsize, l_int32 *pbl0, l_int32 *pbl1, l_int32 *pbl2) |
l_ok | pixaSaveFont (const char *indir, const char *outdir, l_int32 fontsize) |
Variables | |
static const l_float32 | VertFractSep = 0.3 |
Acquisition and generation of bitmap fonts.
L_BMF *bmfCreate() L_BMF *bmfDestroy()
PIX *bmfGetPix() l_int32 bmfGetWidth() l_int32 bmfGetBaseline()
PIXA *pixaGetFont() l_int32 pixaSaveFont() static PIXA *pixaGenerateFontFromFile() static PIXA *pixaGenerateFontFromString() static PIXA *pixaGenerateFont() static l_int32 pixGetTextBaseline() static l_int32 bmfMakeAsciiTables()
This is not a very general utility, because it only uses bitmap representations of a single font, Palatino-Roman, with the normal style. It uses bitmaps generated for nine sizes, from 4 to 20 pts, rendered at 300 ppi. Generalization to different fonts, styles and sizes is straightforward.
I chose Palatino-Roman is because I like it. The input font images were generated from a set of small PostScript files, such as chars-12.ps, which were rendered into the inputfont[] bitmap files using GhostScript. See, for example, the bash script prog/ps2tiff, which will "rip" a PostScript file into a set of ccitt-g4 compressed tiff files.
The set of ascii characters from 32 through 126 are the 95 printable ascii chars. Palatino-Roman is missing char 92, '\'. I have substituted an LR flip of '/', char 47, for 92, so that there are no missing printable chars in this set. The space is char 32, and I have given it a width equal to twice the width of '!'.
Definition in file bmf.c.
L_BMF* bmfCreate | ( | const char * | dir, |
l_int32 | fontsize | ||
) |
[in] | dir | [optional] directory holding pixa of character set |
[in] | fontsize | 4, 6, 8, ... , 20 |
Notes: (1) If dir == null, this generates the font bitmaps from a compiled string. (2) Otherwise, this tries to read a pre-computed pixa file with the 95 ascii chars in it. If the file is not found, it then attempts to generate the pixa and associated baseline data from a tiff image containing all the characters. If that fails, it uses the compiled string.
Definition at line 117 of file bmf.c.
References L_Bmf::baseline1, L_Bmf::baseline2, L_Bmf::baseline3, bmfDestroy(), bmfMakeAsciiTables(), L_Bmf::directory, L_Bmf::pixa, pixaGenerateFontFromFile(), pixaGenerateFontFromString(), pixaGetFont(), L_Bmf::size, and stringNew().
Referenced by boxaDisplayTiled(), compareTilesByHisto(), dewarpaShowArrays(), dewarpShowResults(), fpixaDisplayQuadtree(), partifyPixac(), pixaAddPixWithText(), pixaConvertToNUpPixa(), pixaDisplayTiledByIndex(), pixaDisplayTiledWithText(), pixaSelectToPdf(), pixCompareTilesByHisto(), pixDisplayColorArray(), recogShowPath(), and showExtractNumbers().
void bmfDestroy | ( | L_BMF ** | pbmf | ) |
[in,out] | pbmf | will be set to null before returning |
Definition at line 169 of file bmf.c.
References L_Bmf::baselinetab, L_Bmf::directory, L_Bmf::fonttab, L_Bmf::pixa, pixaDestroy(), and L_Bmf::widthtab.
Referenced by bmfCreate(), boxaDisplayTiled(), pixaConvertToNUpPixa(), pixaDisplayTiledByIndex(), pixaDisplayTiledWithText(), pixaSelectToPdf(), pixDisplayColorArray(), recogDestroy(), recogShowPath(), and showExtractNumbers().
l_ok bmfGetBaseline | ( | L_BMF * | bmf, |
char | chr, | ||
l_int32 * | pbaseline | ||
) |
[in] | bmf | |
[in] | chr | should be one of the 95 supported bitmaps |
[out] | pbaseline | distance below UL corner of bitmap char |
Definition at line 278 of file bmf.c.
References L_Bmf::baselinetab.
[in] | bmf | |
[in] | chr | should be one of the 95 supported printable bitmaps |
Definition at line 204 of file bmf.c.
References L_Bmf::fonttab, L_CLONE, L_Bmf::pixa, and pixaGetPix().
Referenced by bmfMakeAsciiTables().
l_ok bmfGetWidth | ( | L_BMF * | bmf, |
char | chr, | ||
l_int32 * | pw | ||
) |
[in] | bmf | |
[in] | chr | should be one of the 95 supported bitmaps |
[out] | pw | character width; -1 if not printable |
Definition at line 239 of file bmf.c.
References L_Bmf::fonttab, L_Bmf::pixa, and pixaGetPixDimensions().
Referenced by bmfGetLineStrings(), bmfGetStringWidth(), and bmfMakeAsciiTables().
|
static |
bmfMakeAsciiTables
[in] | bmf |
Notes: (1) This makes three tables, each of size 128, as follows: ~ fonttab is a table containing the index of the Pix that corresponds to each input ascii character; it maps (ascii-index) --> Pixa index ~ baselinetab is a table containing the baseline offset for the Pix that corresponds to each input ascii character; it maps (ascii-index) --> baseline offset ~ widthtab is a table containing the character width in pixels for the Pix that corresponds to that character; it maps (ascii-index) --> bitmap width (2) This also computes ~ lineheight (sum of maximum character extensions above and below the baseline) ~ kernwidth (spacing between characters within a word) ~ spacewidth (space between words) ~ vertlinesep (extra vertical spacing between textlines) (3) The baselines apply as follows: baseline1 (ascii 32 - 57), ascii 92 baseline2 (ascii 58 - 91) baseline3 (ascii 93 - 126) (4) The only array in bmf that is not ascii-based is the array of bitmaps in the pixa, which starts at ascii 32.
Definition at line 804 of file bmf.c.
References L_Bmf::baseline1, L_Bmf::baseline2, L_Bmf::baseline3, L_Bmf::baselinetab, bmfGetPix(), bmfGetWidth(), L_Bmf::fonttab, and L_Bmf::widthtab.
Referenced by bmfCreate().
|
static |
[in] | pixs | of 95 characters in 3 rows |
[in] | fontsize | 4, 6, 8, ... , 20, in pts at 300 ppi |
[out] | pbl0 | baseline of row 1 |
[out] | pbl1 | baseline of row 2 |
[out] | pbl2 | baseline of row 3 |
Notes: (1) This does all the work. See pixaGenerateFontFromFile() for an overview. (2) The pix is for one of the 9 fonts. fontsize is only used here for debugging.
Definition at line 558 of file bmf.c.
References L_Bilateral::pixs.
|
static |
[in] | dir | directory holding image of character set |
[in] | fontsize | 4, 6, 8, ... , 20, in pts at 300 ppi |
[out] | pbl0 | baseline of row 1 |
[out] | pbl1 | baseline of row 2 |
[out] | pbl2 | baseline of row 3 |
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.
Typically, use pixaGetFont() to generate the character bitmaps in memory for a bmf. This will simply access the bitmap files in a serialized pixa that were produced in prog/genfonts.c using this function.
Definition at line 436 of file bmf.c.
Referenced by bmfCreate(), and pixaSaveFont().
|
static |
[in] | fontsize | 4, 6, 8, ... , 20, in pts at 300 ppi |
[out] | pbl0 | baseline of row 1 |
[out] | pbl1 | baseline of row 2 |
[out] | pbl2 | baseline of row 3 |
Notes: (1) See pixaGenerateFontFromFile() for details.
Definition at line 487 of file bmf.c.
Referenced by bmfCreate(), and pixaSaveFont().
PIXA* pixaGetFont | ( | const char * | dir, |
l_int32 | fontsize, | ||
l_int32 * | pbl0, | ||
l_int32 * | pbl1, | ||
l_int32 * | pbl2 | ||
) |
[in] | dir | directory holding pixa of character set |
[in] | fontsize | 4, 6, 8, ... , 20 |
[out] | pbl0 | baseline of row 1 |
[out] | pbl1 | baseline of row 2 |
[out] | pbl2 | baseline of row 3 |
Notes: (1) This reads a pre-computed pixa file with the 95 ascii chars.
Definition at line 324 of file bmf.c.
Referenced by bmfCreate().
l_ok pixaSaveFont | ( | const char * | indir, |
const char * | outdir, | ||
l_int32 | fontsize | ||
) |
[in] | indir | [optional] directory holding image of character set |
[in] | outdir | directory into which the output pixa file will be written |
[in] | fontsize | in pts, at 300 ppi |
Notes: (1) This saves a font of a particular size. (2) If indir == null, this generates the font bitmaps from a compiled string. (3) prog/genfonts calls this function for each of the nine font sizes, to generate all the font pixa files.
Definition at line 374 of file bmf.c.
References pathJoin(), pixaGenerateFontFromFile(), and pixaGenerateFontFromString().
|
static |
[in] | pixs | 1 bpp, one textline character set |
[in] | tab8 | [optional] pixel sum table |
[out] | py | baseline value |
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.
Definition at line 729 of file bmf.c.
References makePixelSumTab8(), numaDestroy(), numaGetCount(), numaGetIValue(), pixCountPixelsByRow(), and L_Bilateral::pixs.