diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2006-04-27 23:47:15 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2006-04-27 23:47:15 +0000 |
commit | 2b59a2594b6aa44324d2032d5dedc43b2eff5d10 (patch) | |
tree | c110b241a03cb260a5762702567679b8cf7c3578 | |
parent | 19d6d0cfd923641e9e2f946db86fa4073a1e899a (diff) | |
download | pango-2b59a2594b6aa44324d2032d5dedc43b2eff5d10.tar.gz |
Add more warning_history items and handle more font failures, to make sure
2006-04-27 Behdad Esfahbod <behdad@gnome.org>
* pango/pango-impl-utils.h:
* pango/fonts.c (pango_font_get_glyph_extents),
(pango_font_get_metrics), (pango_font_get_font_map):
* pango/pangocairo-render.c (pango_cairo_show_glyph_string),
(pango_cairo_glyph_string_path): Add more warning_history items and
handle more font failures, to make sure that instead of crashing,
gedit runs and draws empty boxes when pango.modules is not set
properly.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | pango/fonts.c | 26 | ||||
-rw-r--r-- | pango/pango-impl-utils.h | 2 | ||||
-rw-r--r-- | pango/pangocairo-render.c | 40 |
4 files changed, 69 insertions, 10 deletions
@@ -1,3 +1,14 @@ +2006-04-27 Behdad Esfahbod <behdad@gnome.org> + + * pango/pango-impl-utils.h: + * pango/fonts.c (pango_font_get_glyph_extents), + (pango_font_get_metrics), (pango_font_get_font_map): + * pango/pangocairo-render.c (pango_cairo_show_glyph_string), + (pango_cairo_glyph_string_path): Add more warning_history items and + handle more font failures, to make sure that instead of crashing, + gedit runs and draws empty boxes when pango.modules is not set + properly. + 2006-04-26 Behdad Esfahbod <behdad@gnome.org> Bug 339747 – pango_font_metrics_get_approximate_digit_width docs diff --git a/pango/fonts.c b/pango/fonts.c index 29d97b68..69c3fef1 100644 --- a/pango/fonts.c +++ b/pango/fonts.c @@ -29,6 +29,8 @@ #include "pango-fontmap.h" #include "pango-impl-utils.h" +static const char bad_font_warning[] = "%s called with bad font, expect ugly output"; + struct _PangoFontDescription { char *family_name; @@ -1171,7 +1173,7 @@ pango_font_get_glyph_extents (PangoFont *font, if (!_pango_warning_history.get_glyph_extents) { _pango_warning_history.get_glyph_extents = TRUE; - g_warning ("pango_font_get_glyph_extents called with bad font, expect ugly output"); + g_warning (bad_font_warning, "pango_font_get_glyph_extents"); } if (ink_rect) { @@ -1212,6 +1214,17 @@ PangoFontMetrics * pango_font_get_metrics (PangoFont *font, PangoLanguage *language) { + if (G_UNLIKELY (!PANGO_IS_FONT (font))) + { + + if (!_pango_warning_history.get_metrics) + { + _pango_warning_history.get_metrics = TRUE; + g_warning (bad_font_warning, "pango_font_get_metrics"); + } + return pango_font_metrics_new (); + } + return PANGO_FONT_GET_CLASS (font)->get_metrics (font, language); } @@ -1228,6 +1241,17 @@ pango_font_get_metrics (PangoFont *font, PangoFontMap * pango_font_get_font_map (PangoFont *font) { + if (G_UNLIKELY (!PANGO_IS_FONT (font))) + { + + if (!_pango_warning_history.get_font_map) + { + _pango_warning_history.get_font_map = TRUE; + g_warning (bad_font_warning, "pango_font_get_font_map"); + } + return NULL; + } + if (PANGO_FONT_GET_CLASS (font)->get_font_map) return PANGO_FONT_GET_CLASS (font)->get_font_map (font); else diff --git a/pango/pango-impl-utils.h b/pango/pango-impl-utils.h index ebc4406d..59494ed8 100644 --- a/pango/pango-impl-utils.h +++ b/pango/pango-impl-utils.h @@ -83,6 +83,8 @@ struct _PangoWarningHistory { guint shape_font : 1; guint shape_shape_engine : 1; guint get_glyph_extents : 1; + guint get_metrics : 1; + guint get_font_map : 1; }; extern PangoWarningHistory _pango_warning_history; diff --git a/pango/pangocairo-render.c b/pango/pangocairo-render.c index 08a58def..98c0237e 100644 --- a/pango/pangocairo-render.c +++ b/pango/pangocairo-render.c @@ -419,13 +419,19 @@ pango_cairo_show_glyph_string (cairo_t *cr, PangoFontMap *fontmap; PangoCairoRenderer *crenderer; PangoRenderer *renderer; + gboolean unref_renderer = FALSE; g_return_if_fail (cr != NULL); - g_return_if_fail (PANGO_IS_CAIRO_FONT (font)); g_return_if_fail (glyphs != NULL); fontmap = pango_font_get_font_map (font); renderer = _pango_cairo_font_map_get_renderer (PANGO_CAIRO_FONT_MAP (fontmap)); + if (G_UNLIKELY (!renderer)) + { + renderer = g_object_new (PANGO_TYPE_CAIRO_RENDERER, NULL); + unref_renderer = TRUE; + } + crenderer = PANGO_CAIRO_RENDERER (renderer); cairo_save (cr); @@ -445,9 +451,14 @@ pango_cairo_show_glyph_string (cairo_t *cr, pango_renderer_deactivate (renderer); - crenderer->cr = NULL; - crenderer->x_offset = 0.; - crenderer->y_offset = 0.; + if (G_UNLIKELY (unref_renderer)) + g_object_unref (renderer); + else + { + crenderer->cr = NULL; + crenderer->x_offset = 0.; + crenderer->y_offset = 0.; + } cairo_restore (cr); } @@ -558,13 +569,19 @@ pango_cairo_glyph_string_path (cairo_t *cr, PangoFontMap *fontmap; PangoCairoRenderer *crenderer; PangoRenderer *renderer; + gboolean unref_renderer = FALSE; g_return_if_fail (cr != NULL); - g_return_if_fail (PANGO_IS_CAIRO_FONT (font)); g_return_if_fail (glyphs != NULL); fontmap = pango_font_get_font_map (font); renderer = _pango_cairo_font_map_get_renderer (PANGO_CAIRO_FONT_MAP (fontmap)); + if (G_UNLIKELY (!renderer)) + { + renderer = g_object_new (PANGO_TYPE_CAIRO_RENDERER, NULL); + unref_renderer = TRUE; + } + crenderer = PANGO_CAIRO_RENDERER (renderer); crenderer->cr = cr; @@ -573,10 +590,15 @@ pango_cairo_glyph_string_path (cairo_t *cr, pango_renderer_draw_glyphs (renderer, font, glyphs, 0, 0); - crenderer->cr = NULL; - crenderer->do_path = FALSE; - crenderer->x_offset = 0.; - crenderer->y_offset = 0.; + if (G_UNLIKELY (unref_renderer)) + g_object_unref (renderer); + else + { + crenderer->cr = NULL; + crenderer->do_path = FALSE; + crenderer->x_offset = 0.; + crenderer->y_offset = 0.; + } cairo_set_font_face (cr, NULL); } |