diff options
Diffstat (limited to 'pango/pangoft2.c')
-rw-r--r-- | pango/pangoft2.c | 151 |
1 files changed, 105 insertions, 46 deletions
diff --git a/pango/pangoft2.c b/pango/pangoft2.c index d18f3b7a..d95de873 100644 --- a/pango/pangoft2.c +++ b/pango/pangoft2.c @@ -119,6 +119,73 @@ _pango_ft2_font_new (PangoFontMap *fontmap, return ft2font; } +gboolean +set_unicode_charmap (FT_Face face) +{ + int charmap; + + for (charmap = 0; charmap < face->num_charmaps; charmap++) + if (face->charmaps[charmap]->encoding == ft_encoding_unicode) + { + FT_Error error = FT_Set_Charmap(face, face->charmaps[charmap]); + return error == FT_Err_Ok; + } + + return FALSE; +} + +void +load_fallback_face (PangoFT2Font *ft2font, + const char *original_file) +{ + FcPattern *sans; + FcPattern *matched; + FcResult result; + FT_Error error; + FcChar8 *filename2 = NULL; + gchar *name; + int id; + + sans = FcPatternBuild (NULL, + FC_FAMILY, FcTypeString, "sans", + FC_SIZE, FcTypeDouble, (double)pango_font_description_get_size (ft2font->description)/PANGO_SCALE, + NULL); + + matched = FcFontMatch (0, sans, &result); + + if (FcPatternGetString (matched, FC_FILE, 0, &filename2) != FcResultMatch) + goto bail1; + + if (FcPatternGetInteger (matched, FC_INDEX, 0, &id) != FcResultMatch) + goto bail1; + + error = FT_New_Face (_pango_ft2_font_map_get_library (ft2font->fontmap), + (char *) filename2, id, &ft2font->face); + + + if (error) + { + bail1: + name = pango_font_description_to_string (ft2font->description); + g_warning ("Unable to open font file %s for font %s, exiting\n", filename2, name); + exit (1); + } + else + { + name = pango_font_description_to_string (ft2font->description); + g_warning ("Unable to open font file %s for font %s, falling back to %s\n", original_file, name, filename2); + g_free (name); + } + + if (!set_unicode_charmap (ft2font->face)) + { + g_warning ("Unable to load unicode charmap from file %s, exiting\n", filename2); + exit (1); + } + + FcPatternDestroy (sans); + FcPatternDestroy (matched); +} /** * pango_ft2_font_get_face: @@ -137,6 +204,7 @@ pango_ft2_font_get_face (PangoFont *font) FT_Error error; FcPattern *pattern; FcChar8 *filename; + FcBool hinting, autohint; int id; pattern = ft2font->font_pattern; @@ -148,52 +216,29 @@ pango_ft2_font_get_face (PangoFont *font) if (FcPatternGetInteger (pattern, FC_INDEX, 0, &id) != FcResultMatch) goto bail0; - - error = FT_New_Face (_pango_ft2_font_map_get_library (ft2font->fontmap), - (char *) filename, id, &ft2font->face); - if (error) - { - FcPattern *sans; - FcPattern *matched; - FcResult result; - FcChar8 *filename2 = NULL; - gchar *name; - bail0: - - sans = FcPatternBuild (NULL, - FC_FAMILY, FcTypeString, "sans", - FC_SIZE, FcTypeDouble, (double)pango_font_description_get_size (ft2font->description)/PANGO_SCALE, - NULL); + ft2font->load_flags = FT_LOAD_DEFAULT; - matched = FcFontMatch (0, sans, &result); + /* disable hinting if requested */ + if (FcPatternGetBool (pattern, FC_HINTING, 0, &hinting) != FcResultMatch) + hinting = FcTrue; - if (FcPatternGetString (matched, FC_FILE, 0, &filename2) != FcResultMatch) - goto bail1; - - if (FcPatternGetInteger (matched, FC_INDEX, 0, &id) != FcResultMatch) - goto bail1; - - error = FT_New_Face (_pango_ft2_font_map_get_library (ft2font->fontmap), - (char *) filename2, id, &ft2font->face); + if (!hinting) + f2font->load_flags |= FT_LOAD_NO_HINTING; - - if (error) - { - bail1: - name = pango_font_description_to_string (ft2font->description); - g_warning ("Unable to open font file %s for font %s, exiting\n", filename2, name); - exit (1); - } - else - { - name = pango_font_description_to_string (ft2font->description); - g_warning ("Unable to open font file %s for font %s, falling back to %s\n", filename, name, filename2); - g_free (name); - } + /* force autohinting if requested */ + if (FcPatternGetBool (pattern, FC_AUTOHINT, 0, &autohint) != FcResultMatch) + autohint = FcFalse; - FcPatternDestroy (sans); - FcPatternDestroy (matched); + if (autohint) + f2font->load_flags |= FT_LOAD_FORCE_AUTOHINT; + + error = FT_New_Face (_pango_ft2_font_map_get_library (ft2font->fontmap), + (char *) filename, id, &ft2font->face); + if (error != FT_Err_Ok) + { + bail0: + load_fallback_face (ft2font, filename); } ft2font->face->generic.data = 0; } @@ -202,6 +247,16 @@ pango_ft2_font_get_face (PangoFont *font) face = ft2font->face; + if (!set_unicode_charmap (face)) + { + g_warning ("Unable to load unicode charmap from font file %s", filename); + + FT_Done_Face (ft2font->face); + ft2font->face = NULL; + + load_fallback_face (ft2font, filename); + } + if (ft2font->size != GPOINTER_TO_UINT (face->generic.data)) { face->generic.data = GUINT_TO_POINTER (ft2font->size); @@ -296,8 +351,7 @@ pango_ft2_font_render_glyph (PangoFont *font, if (face) { /* Draw glyph */ - /* FIXME hint or not? */ - FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT); + FT_Load_Glyph (face, glyph_index, f2font->load_flags); FT_Render_Glyph (face->glyph, ft_render_mode_normal); rendered->bitmap = face->glyph->bitmap; @@ -438,10 +492,15 @@ pango_ft2_render (FT_Bitmap *bitmap, } static FT_Glyph_Metrics * -pango_ft2_get_per_char (FT_Face face, - guint32 glyph_index) +pango_ft2_get_per_char (PangoFont *font, + guint32 glyph_index) { - FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT); + PangoFT2Font *ft2font = (PangoFT2Font *)font; + FT_Face face; + + face = pango_ft2_font_get_face (font); + + FT_Load_Glyph (face, glyph_index, ft2font->load_flags); return &face->glyph->metrics; } |