Save work on Unicode font support - still something isn't quite right.

This commit is contained in:
Michael R Sweet
2021-06-21 07:58:23 -04:00
parent a2da67c415
commit e9d5e082af
7 changed files with 417 additions and 244 deletions

32
ttf.c
View File

@@ -187,6 +187,8 @@ struct _ttf_s
char *postscript_name; // PostScript name string
char *version; // Font version string
bool is_fixed; // Is this a fixed-width font?
int max_char, // Last character in font
min_char; // First character in font
_ttf_metric_t *widths[TTF_FONT_MAX_CHAR / 256];
// Character metrics (sparse array)
float units; // Width units
@@ -447,6 +449,8 @@ ttfCreate(const char *filename, // I - Filename
font->x_height = 3 * font->ascent / 5;
// Build a sparse glyph widths table...
font->min_char = -1;
for (i = 0; i < num_cmap; i ++)
{
if (cmap[i] >= 0)
@@ -454,6 +458,12 @@ ttfCreate(const char *filename, // I - Filename
int bin = i / 256, // Sub-array bin
glyph = cmap[i]; // Glyph index
// Update min/max...
if (font->min_char < 0)
font->min_char = i;
font->max_char = i;
// Allocate a sub-array as needed...
if (!font->widths[bin])
font->widths[bin] = (_ttf_metric_t *)calloc(256, sizeof(_ttf_metric_t));
@@ -720,6 +730,28 @@ ttfGetItalicAngle(ttf_t *font) // I - Font
}
//
// 'ttfGetMaxChar()' - Get the last character in the font.
//
int // O - Last character in font
ttfGetMaxChar(ttf_t *font) // I - Font
{
return (font ? font->max_char : 0);
}
//
// 'ttfGetMinChar()' - Get the first character in the font.
//
int // O - First character in font
ttfGetMinChar(ttf_t *font) // I - Font
{
return (font ? font->min_char : 0);
}
//
// 'ttfGetNumFonts()' - Get the number of fonts in this collection.
//