diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2006-01-31 00:44:04 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2006-01-31 00:44:04 +0000 |
commit | 4c64086f6cee60fb5275b8fabf2a465212ab8420 (patch) | |
tree | d8bcf6e7ba91e91a8c8e7009a828c0c53d91cfc5 /pango | |
parent | 71f0113fe55447c026fb00115c552a8762bf9e91 (diff) | |
download | pango-4c64086f6cee60fb5275b8fabf2a465212ab8420.tar.gz |
Improve error handling in high-frequency functions: Only warn once.
2006-01-30 Behdad Esfahbod <behdad@gnome.org>
* pango/shape.c (pango_shape):
* pango/fonts.c (pango_font_get_glyph_extents):
* pango/pangocairo-font.c (_pango_cairo_font_install):
Improve error handling in high-frequency functions: Only warn
once.
* pango-impl-utils.h, pangoutils.h:
* pangocairo-private.h, pangocairo-font.c:
Add machinery for above: _pango_warning_history and
_pango_cairo_warning_history.
Diffstat (limited to 'pango')
-rw-r--r-- | pango/fonts.c | 26 | ||||
-rw-r--r-- | pango/pango-impl-utils.h | 12 | ||||
-rw-r--r-- | pango/pango-utils.c | 6 | ||||
-rw-r--r-- | pango/pangocairo-font.c | 13 | ||||
-rw-r--r-- | pango/pangocairo-private.h | 8 | ||||
-rw-r--r-- | pango/shape.c | 23 |
6 files changed, 71 insertions, 17 deletions
diff --git a/pango/fonts.c b/pango/fonts.c index 2142d58b..4835a198 100644 --- a/pango/fonts.c +++ b/pango/fonts.c @@ -24,6 +24,7 @@ #include <math.h> #include <string.h> +#include "pango-impl-utils.h" #include "pango-types.h" #include "pango-font.h" #include "pango-fontmap.h" @@ -1163,7 +1164,30 @@ pango_font_get_glyph_extents (PangoFont *font, PangoRectangle *ink_rect, PangoRectangle *logical_rect) { - g_return_if_fail (font != NULL); + if (G_UNLIKELY (font == NULL)) + { + + if (!_pango_warning_history.get_glyph_extents) + { + _pango_warning_history.get_glyph_extents = TRUE; + g_critical ("pango_font_get_glyph_extents called with font == NULL, expect ugly output"); + } + if (ink_rect) + { + ink_rect->x = 0; + ink_rect->y = 0; + ink_rect->height = 12 * PANGO_SCALE; + ink_rect->width = 12 * PANGO_SCALE; + } + if (logical_rect) + { + logical_rect->x = 0; + logical_rect->y = 0; + logical_rect->height = 12 * PANGO_SCALE; + logical_rect->width = 12 * PANGO_SCALE; + } + return; + } PANGO_FONT_GET_CLASS (font)->get_glyph_extents (font, glyph, ink_rect, logical_rect); } diff --git a/pango/pango-impl-utils.h b/pango/pango-impl-utils.h index 7dabeb47..7e1d3136 100644 --- a/pango/pango-impl-utils.h +++ b/pango/pango-impl-utils.h @@ -72,6 +72,18 @@ prefix ## _get_type (void) \ class_init, instance_init, \ parent_type, G_TYPE_FLAG_ABSTRACT) + + +typedef struct _PangoWarningHistory PangoWarningHistory; + +struct _PangoWarningHistory { + guint shape_font : 1; + guint shape_shape_engine : 1; + guint get_glyph_extents : 1; +}; + +extern PangoWarningHistory _pango_warning_history; + G_END_DECLS #endif /* __PANGO_IMPL_UTILS_H__ */ diff --git a/pango/pango-utils.c b/pango/pango-utils.c index fce42896..5ae1246f 100644 --- a/pango/pango-utils.c +++ b/pango/pango-utils.c @@ -25,8 +25,9 @@ #include <string.h> #include <stdlib.h> -#include "pango-font.h" +#include "pango-impl-utils.h" #include "pango-utils.h" +#include "pango-font.h" #include <glib/gstdio.h> @@ -57,6 +58,8 @@ struct PangoAlias static GHashTable *pango_aliases_ht = NULL; +PangoWarningHistory _pango_warning_history = {}; + /** * pango_trim_string: * @str: a string @@ -1461,7 +1464,6 @@ pango_log2vis_get_embedding_levels (const gchar *str, PangoDirection *pbase_dir) { FriBidiCharType fribidi_base_dir; - gboolean result; guint8 *embedding_levels_list; switch (*pbase_dir) diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c index a727e053..ee98020f 100644 --- a/pango/pangocairo-font.c +++ b/pango/pangocairo-font.c @@ -21,10 +21,13 @@ #include <config.h> +#include "pango-impl-utils.h" #include "pangocairo.h" #include "pangocairo-private.h" #include "pango-utils.h" +PangoCairoWarningHistory _pango_cairo_warning_history = {}; + GType pango_cairo_font_get_type (void) { @@ -68,7 +71,15 @@ void _pango_cairo_font_install (PangoCairoFont *font, cairo_t *cr) { - g_return_if_fail (PANGO_IS_CAIRO_FONT (font)); + if (G_UNLIKELY (!PANGO_IS_CAIRO_FONT (font))) + { + if (!_pango_cairo_warning_history.font_install) + { + _pango_cairo_warning_history.font_install = TRUE; + g_critical ("_pango_cairo_font_install called with font == NULL, expect ugly output"); + } + return; + } (* PANGO_CAIRO_FONT_GET_IFACE (font)->install) (font, cr); } diff --git a/pango/pangocairo-private.h b/pango/pangocairo-private.h index 290c761c..48d3c0f3 100644 --- a/pango/pangocairo-private.h +++ b/pango/pangocairo-private.h @@ -103,6 +103,14 @@ void _pango_cairo_get_glyph_extents_missing (PangoCairoFont *cfont, PangoRectangle *ink_rect, PangoRectangle *logical_rect); +typedef struct _PangoCairoWarningHistory PangoCairoWarningHistory; + +struct _PangoCairoWarningHistory { + guint font_install : 1; +}; + +extern PangoCairoWarningHistory _pango_cairo_warning_history; + G_END_DECLS #endif /* __PANGOCAIRO_PRIVATE_H__ */ diff --git a/pango/shape.c b/pango/shape.c index 3020007a..37fc34d2 100644 --- a/pango/shape.c +++ b/pango/shape.c @@ -20,8 +20,10 @@ */ #include <config.h> -#include <pango/pango-glyph.h> -#include <pango/pango-engine-private.h> + +#include "pango-impl-utils.h" +#include "pango-glyph.h" +#include "pango-engine-private.h" /** * pango_shape: @@ -82,20 +84,15 @@ pango_shape (const gchar *text, } else { - static struct { - guint font : 1; - guint shape_engine : 1; - } warned = { FALSE, FALSE }; - - if (!analysis->shape_engine && !warned.shape_engine) + if (!analysis->shape_engine && !_pango_warning_history.shape_shape_engine) { - g_critical ("pango_shape called with analysis->shape_engine == NULL"); - warned.font = TRUE; + _pango_warning_history.shape_font = TRUE; + g_critical ("pango_shape called with analysis->shape_engine == NULL, expect ugly output"); } - if (!analysis->font && !warned.font) + if (!analysis->font && !_pango_warning_history.shape_font) { - g_critical ("pango_shape called with analysis->font == NULL"); - warned.font = TRUE; + _pango_warning_history.shape_font = TRUE; + g_critical ("pango_shape called with analysis->font == NULL, expect ugly output"); } glyphs->num_glyphs = 0; |