]> granicus.if.org Git - libass/commitdiff
Improved "last resort" charmap matching
authorGrigori Goronzy <greg@blackbox>
Sat, 9 Apr 2011 19:48:08 +0000 (21:48 +0200)
committerGrigori Goronzy <greg@blackbox>
Sat, 9 Apr 2011 19:48:08 +0000 (21:48 +0200)
After font reselection, loop through all charmaps if no glyph can't be
found until we hopefully find one that works. If we get here at all, the
font is seriously broken, so this is unlikely to harm anything.

This improves the last resort charmap fallback introduced in 96057d.

libass/ass_font.c

index 74467df6b03aaebea00dbe2811aa3733685a3f2d..d732dfed9583abd4f80c095e57b530a56d89ba9f 100644 (file)
@@ -446,12 +446,13 @@ FT_Glyph ass_font_get_glyph(void *fontconfig_priv, ASS_Font *font,
             face = font->faces[face_idx];
             index = FT_Get_Char_Index(face, ch);
             if (index == 0 && face->num_charmaps > 0) {
+                int i;
                 ass_msg(font->library, MSGL_WARN,
-                    "Glyph 0x%X not found, falling back to first charmap", ch);
-                FT_CharMap cur = face->charmap;
-                FT_Set_Charmap(face, face->charmaps[0]);
-                index = FT_Get_Char_Index(face, ch);
-                FT_Set_Charmap(face, cur);
+                    "Glyph 0x%X not found, broken font? Trying all charmaps", ch);
+                for (i = 0; i < face->num_charmaps; i++) {
+                    FT_Set_Charmap(face, face->charmaps[i]);
+                    if ((index = FT_Get_Char_Index(face, ch)) != 0) break;
+                }
             }
             if (index == 0) {
                 ass_msg(font->library, MSGL_ERR,