summaryrefslogtreecommitdiff
path: root/pango/pangoxft-font.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2002-07-10 10:17:14 +0000
committerOwen Taylor <otaylor@src.gnome.org>2002-07-10 10:17:14 +0000
commit1753306eec6eeeebf0964a9f94ae7f59fb10f7db (patch)
treea1be9b5b27db436bad8f24a006b11df7d816cf1e /pango/pangoxft-font.c
parent0a70a9de2ea865be280fe8702383c601da1cc3bf (diff)
downloadpango-1753306eec6eeeebf0964a9f94ae7f59fb10f7db.tar.gz
Be more robust when trying to set the unicode character map on the font.
Wed Jul 3 18:39:45 2002 Owen Taylor <otaylor@redhat.com> * pango/pangoft2.c pango/pangoxft-font.c: Be more robust when trying to set the unicode character map on the font. (#86911)
Diffstat (limited to 'pango/pangoxft-font.c')
-rw-r--r--pango/pangoxft-font.c86
1 files changed, 62 insertions, 24 deletions
diff --git a/pango/pangoxft-font.c b/pango/pangoxft-font.c
index ed35be84..a0771c22 100644
--- a/pango/pangoxft-font.c
+++ b/pango/pangoxft-font.c
@@ -677,6 +677,52 @@ 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,
+ XFT_FAMILY, XftTypeString, "sans",
+ XFT_ENCODING, XftTypeString, "glyphs-fontspecific",
+ XFT_CORE, XftTypeBool, False,
+ XFT_SIZE, XftTypeDouble, (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);
+ }
+
+ if (!set_unicode_charmap (xft_font->u.ft.font->face))
+ {
+ g_warning ("Cannot set unicode character map for fallback font, nothing to do");
+ exit (1);
+ }
+
+ xfont->xft_font = xft_font;
+}
+
/**
* pango_xft_font_get_font:
* @font: a #PangoFont.
@@ -691,9 +737,6 @@ pango_xft_font_get_font (PangoFont *font)
PangoXftFont *xfont;
Display *display;
int screen;
- FT_Face face;
- FT_Error error;
- int charmap;
g_return_val_if_fail (PANGO_XFT_IS_FONT (font), NULL);
@@ -715,31 +758,26 @@ pango_xft_font_get_font (PangoFont *font)
g_warning ("Cannot open font file for font %s", name);
g_free (name);
- xfont->xft_font = XftFontOpen (display, screen,
- XFT_FAMILY, XftTypeString, "sans",
- XFT_ENCODING, XftTypeString, "glyphs-fontspecific",
- XFT_CORE, XftTypeBool, False,
- XFT_SIZE, XftTypeDouble, (double)pango_font_description_get_size (xfont->description)/PANGO_SCALE,
- NULL);
+ load_fallback_font (xfont);
}
- if (!xfont->xft_font)
+ else
{
- g_warning ("Cannot open fallback font, nothing to do");
- exit (1);
+ /* There should be a unicode encoding, since we queried for it */
+ if (!set_unicode_charmap (xfont->xft_font->u.ft.font->face))
+ {
+ gchar *name = pango_font_description_to_string (xfont->description);
+
+ g_warning ("Cannot load unicode character map for font %s", name);
+ g_free (name);
+
+ XftFontClose (display, xfont->xft_font);
+ xfont->xft_font = NULL;
+
+ load_fallback_font (xfont);
+ }
}
-
- face = xfont->xft_font->u.ft.font->face;
-
- /* There should be a unicode encoding, since we queried for it */
- for (charmap = 0; charmap < face->num_charmaps; charmap++)
- if (face->charmaps[charmap]->encoding == ft_encoding_unicode)
- break;
-
- g_assert (charmap != face->num_charmaps);
-
- error = FT_Set_Charmap(face, face->charmaps[charmap]);
}
-
+
return xfont->xft_font;
}