Replace character discovery loop with simpler, faster version.

The existing loop for discovering which characters map to glyphs is ugly and
inefficient. The replacement is functionally identical, but far cleaner and
faster.
This commit is contained in:
David Turner 2006-09-07 14:29:35 -07:00 committed by Keith Packard
parent 8d779ce4b3
commit 31e0f03210
1 changed files with 33 additions and 56 deletions

View File

@ -2584,71 +2584,48 @@ FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
} }
else else
{ {
FT_UInt gindex; page = ~0;
leaf = NULL;
/* ucs4 = FT_Get_First_Char (face, &glyph);
* Find the first encoded character in the font while (glyph != 0)
*/
if (FT_Get_Char_Index (face, 0))
{ {
ucs4 = 0; if (FcFreeTypeCheckGlyph (face, ucs4, glyph, blanks, &advance))
gindex = 1;
}
else
{
ucs4 = FT_Get_Next_Char (face, 0, &gindex);
if (!ucs4)
gindex = 0;
}
while (gindex)
{
page = ucs4 >> 8;
leaf = 0;
while ((ucs4 >> 8) == page)
{ {
glyph = FT_Get_Char_Index (face, ucs4); if (advance)
if (glyph && FcFreeTypeCheckGlyph (face, ucs4,
glyph, blanks, &advance))
{ {
if (advance) if (!has_advance)
{ {
if (!has_advance) has_advance = FcTrue;
{ advance_one = advance;
has_advance = FcTrue;
advance_one = advance;
}
else if (!APPROXIMATELY_EQUAL (advance, advance_one))
{
if (fixed_advance)
{
dual_advance = FcTrue;
fixed_advance = FcFalse;
advance_two = advance;
}
else if (!APPROXIMATELY_EQUAL (advance, advance_two))
dual_advance = FcFalse;
}
} }
else if (!APPROXIMATELY_EQUAL (advance, advance_one))
if (!leaf)
{ {
leaf = FcCharSetFindLeafCreate (fcs, ucs4); if (fixed_advance)
if (!leaf) {
goto bail1; dual_advance = FcTrue;
fixed_advance = FcFalse;
advance_two = advance;
}
else if (!APPROXIMATELY_EQUAL (advance, advance_two))
dual_advance = FcFalse;
} }
off = ucs4 & 0xff;
leaf->map[off >> 5] |= (1 << (off & 0x1f));
#ifdef CHECK
if (ucs4 > font_max)
font_max = ucs4;
#endif
} }
ucs4++;
if ((ucs4 >> 8) != page)
{
page = (ucs4 >> 8);
leaf = FcCharSetFindLeafCreate (fcs, ucs4);
if (!leaf)
goto bail1;
}
off = ucs4 & 0xff;
leaf->map[off >> 5] |= (1 << (off & 0x1f));
#ifdef CHECK
if (ucs4 > font_max)
font_max = ucs4;
#endif
} }
ucs4 = FT_Get_Next_Char (face, ucs4 - 1, &gindex); ucs4 = FT_Get_Next_Char (face, ucs4, &glyph);
if (!ucs4)
gindex = 0;
} }
#ifdef CHECK #ifdef CHECK
for (ucs4 = 0; ucs4 < 0x10000; ucs4++) for (ucs4 = 0; ucs4 < 0x10000; ucs4++)