From 6ebb942adbf89cfda1ac868a47057d9cabe91780 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Wed, 3 Jul 2002 22:40:20 +0000 Subject: Be more robust when trying to set the unicode character map on the font. Wed Jul 3 18:39:45 2002 Owen Taylor * pango/pangoft2.c pango/pangoxft-font.c: Be more robust when trying to set the unicode character map on the font. * pango/pangoft2.c pango/pangoft2-private.h: Obey FC_HINTING, FC_AUTOHINT. --- ChangeLog | 9 +++ ChangeLog.pre-1-10 | 9 +++ ChangeLog.pre-1-2 | 9 +++ ChangeLog.pre-1-4 | 9 +++ ChangeLog.pre-1-6 | 9 +++ ChangeLog.pre-1-8 | 9 +++ pango/pangoft2-private.h | 1 + pango/pangoft2.c | 151 ++++++++++++++++++++++++++++++++--------------- pango/pangoxft-font.c | 45 +++++++++++++- 9 files changed, 203 insertions(+), 48 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef84f6cf..ea0d19dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Wed Jul 3 18:39:45 2002 Owen Taylor + + * pango/pangoft2.c pango/pangoxft-font.c: Be more + robust when trying to set the unicode character + map on the font. + + * pango/pangoft2.c pango/pangoft2-private.h: + Obey FC_HINTING, FC_AUTOHINT. + Mon Jul 1 19:45:10 2002 Owen Taylor * pango/pangoxft-fontmap.c (pango_xft_set_default_substitute): diff --git a/ChangeLog.pre-1-10 b/ChangeLog.pre-1-10 index ef84f6cf..ea0d19dc 100644 --- a/ChangeLog.pre-1-10 +++ b/ChangeLog.pre-1-10 @@ -1,3 +1,12 @@ +Wed Jul 3 18:39:45 2002 Owen Taylor + + * pango/pangoft2.c pango/pangoxft-font.c: Be more + robust when trying to set the unicode character + map on the font. + + * pango/pangoft2.c pango/pangoft2-private.h: + Obey FC_HINTING, FC_AUTOHINT. + Mon Jul 1 19:45:10 2002 Owen Taylor * pango/pangoxft-fontmap.c (pango_xft_set_default_substitute): diff --git a/ChangeLog.pre-1-2 b/ChangeLog.pre-1-2 index ef84f6cf..ea0d19dc 100644 --- a/ChangeLog.pre-1-2 +++ b/ChangeLog.pre-1-2 @@ -1,3 +1,12 @@ +Wed Jul 3 18:39:45 2002 Owen Taylor + + * pango/pangoft2.c pango/pangoxft-font.c: Be more + robust when trying to set the unicode character + map on the font. + + * pango/pangoft2.c pango/pangoft2-private.h: + Obey FC_HINTING, FC_AUTOHINT. + Mon Jul 1 19:45:10 2002 Owen Taylor * pango/pangoxft-fontmap.c (pango_xft_set_default_substitute): diff --git a/ChangeLog.pre-1-4 b/ChangeLog.pre-1-4 index ef84f6cf..ea0d19dc 100644 --- a/ChangeLog.pre-1-4 +++ b/ChangeLog.pre-1-4 @@ -1,3 +1,12 @@ +Wed Jul 3 18:39:45 2002 Owen Taylor + + * pango/pangoft2.c pango/pangoxft-font.c: Be more + robust when trying to set the unicode character + map on the font. + + * pango/pangoft2.c pango/pangoft2-private.h: + Obey FC_HINTING, FC_AUTOHINT. + Mon Jul 1 19:45:10 2002 Owen Taylor * pango/pangoxft-fontmap.c (pango_xft_set_default_substitute): diff --git a/ChangeLog.pre-1-6 b/ChangeLog.pre-1-6 index ef84f6cf..ea0d19dc 100644 --- a/ChangeLog.pre-1-6 +++ b/ChangeLog.pre-1-6 @@ -1,3 +1,12 @@ +Wed Jul 3 18:39:45 2002 Owen Taylor + + * pango/pangoft2.c pango/pangoxft-font.c: Be more + robust when trying to set the unicode character + map on the font. + + * pango/pangoft2.c pango/pangoft2-private.h: + Obey FC_HINTING, FC_AUTOHINT. + Mon Jul 1 19:45:10 2002 Owen Taylor * pango/pangoxft-fontmap.c (pango_xft_set_default_substitute): diff --git a/ChangeLog.pre-1-8 b/ChangeLog.pre-1-8 index ef84f6cf..ea0d19dc 100644 --- a/ChangeLog.pre-1-8 +++ b/ChangeLog.pre-1-8 @@ -1,3 +1,12 @@ +Wed Jul 3 18:39:45 2002 Owen Taylor + + * pango/pangoft2.c pango/pangoxft-font.c: Be more + robust when trying to set the unicode character + map on the font. + + * pango/pangoft2.c pango/pangoft2-private.h: + Obey FC_HINTING, FC_AUTOHINT. + Mon Jul 1 19:45:10 2002 Owen Taylor * pango/pangoxft-fontmap.c (pango_xft_set_default_substitute): diff --git a/pango/pangoft2-private.h b/pango/pangoft2-private.h index 16938c5a..2fe8f719 100644 --- a/pango/pangoft2-private.h +++ b/pango/pangoft2-private.h @@ -65,6 +65,7 @@ struct _PangoFT2Font FcPattern *font_pattern; FT_Face face; + int load_flags; int size; 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; } diff --git a/pango/pangoxft-font.c b/pango/pangoxft-font.c index 48fea5c0..2d017bde 100644 --- a/pango/pangoxft-font.c +++ b/pango/pangoxft-font.c @@ -685,6 +685,44 @@ pango_xft_font_find_shaper (PangoFont *font, return (PangoEngineShape *)pango_map_get_engine (shape_map, ch); } +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_font (PangoXftFont *xfont) +{ + Display *display; + int screen; + XftFont *xft_font; + + _pango_xft_font_map_get_info (xfont->fontmap, &display, &screen); + + xft_font = XftFontOpen (display, screen, + FC_FAMILY, FcTypeString, "sans", + FC_SIZE, FcTypeDouble, (double)pango_font_description_get_size (xfont->description)/PANGO_SCALE, + NULL); + + if (!xft_font) + { + g_warning ("Cannot open fallback font, nothing to do"); + exit (1); + } + + xfont->xft_font = xft_font; +} + /** * pango_xft_font_get_font: * @font: a #PangoFont. @@ -711,8 +749,11 @@ pango_xft_font_get_font (PangoFont *font) xfont->xft_font = XftFontOpenPattern (display, FcPatternDuplicate (xfont->font_pattern)); if (!xfont->xft_font) { - g_warning ("Cannot open fallback font, nothing to do"); - exit (1); + gchar *name = pango_font_description_to_string (xfont->description); + g_warning ("Cannot open font file for font %s", name); + g_free (name); + + load_fallback_font (xfont); } } -- cgit v1.2.1