![]() |
Leptonica 1.85.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.3f |
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 118 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(), and L_Bmf::size.
| void bmfDestroy | ( | L_BMF ** | pbmf | ) |
| [in,out] | pbmf | will be set to null before returning |
Definition at line 168 of file bmf.c.
References L_Bmf::baselinetab, L_Bmf::directory, L_Bmf::fonttab, and L_Bmf::pixa.
Referenced by bmfCreate().
| 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 274 of file bmf.c.
References L_Bmf::baselinetab.
| [in] | bmf | |
| [in] | chr | should be one of the 95 supported printable bitmaps |
Definition at line 200 of file bmf.c.
References L_Bmf::fonttab, L_CLONE, and L_Bmf::pixa.
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 235 of file bmf.c.
References L_Bmf::fonttab, and L_Bmf::pixa.
Referenced by bmfMakeAsciiTables().
|
static |
bmfMakeAsciiTables
| [in] | bmf |
Notes:
(1) This makes two 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
(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 785 of file bmf.c.
References L_Bmf::baseline1, L_Bmf::baseline2, L_Bmf::baseline3, L_Bmf::baselinetab, bmfGetPix(), bmfGetWidth(), L_Bmf::fonttab, L_Bmf::kernwidth, L_Bmf::lineheight, L_Bmf::spacewidth, and L_Bmf::vertlinesep.
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 546 of file bmf.c.
References Box::h, L_CLONE, L_COPY, L_FLIP_PIXELS, L_INSERT, L_SORT_BY_X, L_SORT_INCREASING, pixGetTextBaseline(), Box::w, Box::x, and Box::y.
Referenced by pixaGenerateFontFromFile(), and pixaGenerateFontFromString().
|
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 428 of file bmf.c.
References pixaGenerateFont().
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 477 of file bmf.c.
References pixaGenerateFont().
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 320 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 368 of file bmf.c.
References 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 715 of file bmf.c.
Referenced by pixaGenerateFont().