diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2006-02-03 02:46:17 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2006-02-03 02:46:17 +0000 |
commit | 6c9e853b93be4c01027e625427787e38be9b99f3 (patch) | |
tree | 9b1f07249ff96f43ce9f8af61613e067e0e1ea74 /pango/pangoft2.c | |
parent | b1e264aa208e43a3d98aa2f985a0eaafdb328bb8 (diff) | |
download | pango-6c9e853b93be4c01027e625427787e38be9b99f3.tar.gz |
Finish the 'glyph 0' work of this morning: PANGO_GLYPH_NULL that I
2006-02-02 Behdad Esfahbod <behdad@gnome.org>
Finish the 'glyph 0' work of this morning:
PANGO_GLYPH_NULL that I introduced is renamed to
PANGO_GLYPH_EMPTY. It means, no rendering should
be performed. The backends however, still return
0 if a glyph is not found. The modules then are
free to replace this 0 glyph with an unknown
character.
* modules/arabic/arabic-fc.c, modules/basic/basic-atsui.c,
modules/basic/basic-fc.c, modules/basic/basic-win32.c,
modules/basic/basic-x.c, modules/hangul/hangul-fc.c,
modules/hebrew/hebrew-fc.c, modules/indic/indic-fc.c,
modules/khmer/khmer-fc.c, modules/syriac/syriac-fc.c,
modules/thai/thai-fc.c, modules/tibetan/tibetan-fc.c,
pango/pangox.c, pango/pangowin32.c:
Adapt to above change. Backends return 0 if glyph not
found.
* pango/fonts.c (pango_font_get_glyph_extents): If font
is not usable (!PANGO_IS_FONT (font)), return the generic
UNKNOWN_GLYPH metrics. This is used when your backends
are misconfigured and you don't find *any* font at all.
* pango/pango-engince.c: Add unknown glyphs in fallback
shaper, instead of empty glyphs.
* pango/shape.c: Call the fall-back shaper if shaper
fails, instead of generating a dummy glyph string ourselves.
* pango/pango-layout.c (imposed_shape, shape_tab): Use
PANGO_GLYPH_EMPTY instead of glyph 0.
* pango/pango-renderer.c (pango_renderer_draw_glyph): No-op on
PANGO_GLYPH_EMPTY instead of glyph 0.
* pango/pangocairo-atsuifont.c, pango/pangocairo-win32font.c,
pango/pangocairo-fcfont.c, pango/pangocairo-font.c,
pango/pangocairo-private.h: install_font returns a boolean now.
* pango/pangocairo-render.c, pango/pangoxft-render.c: Handle font
and hex-box failures more gracefully by drawing a generic
unknown-box glyph.
* pango/pangoft2.c, pango/pangoft2-render.c: Draw the generic
unknown-box glyph here too. For unknown glyphs though, if
the font is TTF (FT_IS_SFNT), use the zero-indexed glyph,
otherwise, draw a box of proper size.
Diffstat (limited to 'pango/pangoft2.c')
-rw-r--r-- | pango/pangoft2.c | 86 |
1 files changed, 59 insertions, 27 deletions
diff --git a/pango/pangoft2.c b/pango/pangoft2.c index 459fa0ab..c20afdf5 100644 --- a/pango/pangoft2.c +++ b/pango/pangoft2.c @@ -33,6 +33,8 @@ #include "pangofc-fontmap.h" #include "pangofc-private.h" +PangoFT2WarningHistory _pango_ft2_warning_history = { FALSE }; + /* for compatibility with older freetype versions */ #ifndef FT_LOAD_TARGET_MONO #define FT_LOAD_TARGET_MONO FT_LOAD_MONOCHROME @@ -58,8 +60,6 @@ static void pango_ft2_font_get_glyph_extents (PangoFont * static FT_Face pango_ft2_font_real_lock_face (PangoFcFont *font); static void pango_ft2_font_real_unlock_face (PangoFcFont *font); -static PangoGlyph pango_ft2_font_real_get_unknown_glyph (PangoFcFont *font, - gunichar wc); PangoFT2Font * _pango_ft2_font_new (PangoFT2FontMap *ft2fontmap, @@ -173,6 +173,16 @@ pango_ft2_font_get_face (PangoFont *font) FcBool antialias, hinting, autohint; int id; + if (G_UNLIKELY (!PANGO_FT2_IS_FONT (font))) + { + if (!_pango_ft2_warning_history.get_face) + { + _pango_ft2_warning_history.get_face = TRUE; + g_critical ("pango_ft2_font_get_face called with bad font, expect ugly output"); + } + return NULL; + } + pattern = fcfont->font_pattern; if (!ft2font->face) @@ -259,7 +269,6 @@ pango_ft2_font_class_init (PangoFT2FontClass *class) fc_font_class->lock_face = pango_ft2_font_real_lock_face; fc_font_class->unlock_face = pango_ft2_font_real_unlock_face; - fc_font_class->get_unknown_glyph = pango_ft2_font_real_get_unknown_glyph; } static PangoFT2GlyphInfo * @@ -296,25 +305,52 @@ pango_ft2_font_get_glyph_extents (PangoFont *font, { PangoFT2GlyphInfo *info; - if (glyph & PANGO_GLYPH_UNKNOWN_FLAG) - glyph = PANGO_GLYPH_NULL; - if (glyph == PANGO_GLYPH_NULL) + if (glyph == PANGO_GLYPH_EMPTY) { if (ink_rect) - { - ink_rect->x = 0; - ink_rect->y = 0; - ink_rect->height = PANGO_UNKNOWN_GLYPH_HEIGHT * PANGO_SCALE; - ink_rect->width = PANGO_UNKNOWN_GLYPH_WIDTH * PANGO_SCALE; - } + ink_rect->x = ink_rect->y = ink_rect->height = ink_rect->width = 0; if (logical_rect) + logical_rect->x = logical_rect->y = logical_rect->height = logical_rect->width = 0; + return; + } + + if (glyph & PANGO_GLYPH_UNKNOWN_FLAG) + { + FT_Face face = pango_ft2_font_get_face (font); + if (face && FT_IS_SFNT (face)) + glyph = pango_ft2_get_unknown_glyph (font); + else { - logical_rect->x = 0; - logical_rect->y = 0; - logical_rect->height = PANGO_UNKNOWN_GLYPH_HEIGHT * PANGO_SCALE; - logical_rect->width = PANGO_UNKNOWN_GLYPH_WIDTH * PANGO_SCALE; + PangoFontMetrics *metrics = pango_font_get_metrics (font, NULL); + + if (metrics) + { + if (ink_rect) + { + ink_rect->x = PANGO_SCALE; + ink_rect->y = - (metrics->ascent - PANGO_SCALE); + ink_rect->height = metrics->ascent + metrics->descent - 2 * PANGO_SCALE; + ink_rect->width = metrics->approximate_char_width - 2 * PANGO_SCALE; + } + if (logical_rect) + { + logical_rect->x = 0; + logical_rect->y = -metrics->ascent; + logical_rect->height = metrics->ascent + metrics->descent; + logical_rect->width = metrics->approximate_char_width; + } + + pango_font_metrics_unref (metrics); + } + else + { + if (ink_rect) + ink_rect->x = ink_rect->y = ink_rect->height = ink_rect->width = 0; + if (logical_rect) + logical_rect->x = logical_rect->y = logical_rect->height = logical_rect->width = 0; + } + return; } - return; } info = pango_ft2_font_get_glyph_info (font, glyph, TRUE); @@ -381,13 +417,6 @@ pango_ft2_font_real_unlock_face (PangoFcFont *font) { } -static PangoGlyph -pango_ft2_font_real_get_unknown_glyph (PangoFcFont *font, - gunichar wc) -{ - return 0; -} - static gboolean pango_ft2_free_glyph_info_callback (gpointer key, gpointer value, @@ -505,7 +534,8 @@ _pango_ft2_font_get_cache_glyph_data (PangoFont *font, { PangoFT2GlyphInfo *info; - g_return_val_if_fail (PANGO_FT2_IS_FONT (font), NULL); + if (!PANGO_FT2_IS_FONT (font)) + return NULL; info = pango_ft2_font_get_glyph_info (font, glyph_index, FALSE); @@ -522,7 +552,8 @@ _pango_ft2_font_set_cache_glyph_data (PangoFont *font, { PangoFT2GlyphInfo *info; - g_return_if_fail (PANGO_FT2_IS_FONT (font)); + if (!PANGO_FT2_IS_FONT (font)) + return; info = pango_ft2_font_get_glyph_info (font, glyph_index, TRUE); @@ -535,7 +566,8 @@ void _pango_ft2_font_set_glyph_cache_destroy (PangoFont *font, GDestroyNotify destroy_notify) { - g_return_if_fail (PANGO_FT2_IS_FONT (font)); + if (!PANGO_FT2_IS_FONT (font)) + return; PANGO_FT2_FONT (font)->glyph_cache_destroy = destroy_notify; } |