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/pangox.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/pangox.c')
-rw-r--r-- | pango/pangox.c | 162 |
1 files changed, 79 insertions, 83 deletions
diff --git a/pango/pangox.c b/pango/pangox.c index fe85cd98..06694713 100644 --- a/pango/pangox.c +++ b/pango/pangox.c @@ -399,21 +399,58 @@ pango_x_render (Display *display, * the ink rect here would be a noticeable speed hit. * This is close enough. */ - if (!(glyph != PANGO_GLYPH_NULL && + if (!(glyph != PANGO_GLYPH_EMPTY && glyph_x >= -16384 && glyph_x <= 32767 && glyph_y >= -16384 && glyph_y <= 32767)) goto next_glyph; - if (glyph & PANGO_GLYPH_UNKNOWN_FLAG) - { - PangoFontMetrics *metrics = pango_font_get_metrics (font, - pango_language_from_string ("en")); + if ((glyph & PANGO_GLYPH_UNKNOWN_FLAG) == 0) + { + guint16 index = PANGO_X_GLYPH_INDEX (glyph); + guint16 subfont_index = PANGO_X_GLYPH_SUBFONT (glyph); + PangoXSubfontInfo *subfont; + + subfont = pango_x_find_subfont (font, subfont_index); + if (subfont) + { + fs = pango_x_get_font_struct (font, subfont); + if (!fs) + continue; + + if (fs->fid != old_fid) + { + FLUSH; + XSetFont (display, gc, fs->fid); + old_fid = fs->fid; + } + + if (charcount == G_N_ELEMENTS (xcharbuffer) || + (charcount > 0 && (glyph_y != glyph_y0 || + glyph_x != expected_x))) + FLUSH; + + if (charcount == 0) + { + glyph_x0 = glyph_x; + glyph_y0 = glyph_y; + } + xcharbuffer[charcount].byte1 = index / 256; + xcharbuffer[charcount].byte2 = index % 256; + + expected_x = glyph_x + XTextWidth16 (fs, &xcharbuffer[charcount], 1); + + charcount++; + } else + goto unknown_glyph; + } else { + PangoFontMetrics *metrics; int x1, y1, x2, y2; /* rectangle the character should go inside. */ int baseline; int stroke_thick; - gunichar wc; - + + unknown_glyph: + metrics = pango_font_get_metrics (font, pango_language_from_string ("en")); FLUSH; x1 = glyph_x; @@ -423,7 +460,10 @@ pango_x_render (Display *display, baseline = glyph_y; stroke_thick = MAX ((int) (0.5 + 0.075 * (y2 - y1)), 1); - wc = glyph & (~PANGO_GLYPH_UNKNOWN_FLAG); + if (glyph & PANGO_GLYPH_UNKNOWN_FLAG) + wc = glyph & (~PANGO_GLYPH_UNKNOWN_FLAG); + else + wc = 0; switch (wc) { @@ -518,44 +558,6 @@ pango_x_render (Display *display, pango_font_metrics_unref (metrics); } - else - { - guint16 index = PANGO_X_GLYPH_INDEX (glyph); - guint16 subfont_index = PANGO_X_GLYPH_SUBFONT (glyph); - PangoXSubfontInfo *subfont; - - subfont = pango_x_find_subfont (font, subfont_index); - if (subfont) - { - fs = pango_x_get_font_struct (font, subfont); - if (!fs) - continue; - - if (fs->fid != old_fid) - { - FLUSH; - XSetFont (display, gc, fs->fid); - old_fid = fs->fid; - } - - if (charcount == G_N_ELEMENTS (xcharbuffer) || - (charcount > 0 && (glyph_y != glyph_y0 || - glyph_x != expected_x))) - FLUSH; - - if (charcount == 0) - { - glyph_x0 = glyph_x; - glyph_y0 = glyph_y; - } - xcharbuffer[charcount].byte1 = index / 256; - xcharbuffer[charcount].byte2 = index % 256; - - expected_x = glyph_x + XTextWidth16 (fs, &xcharbuffer[charcount], 1); - - charcount++; - } - } next_glyph: x_off += glyphs->glyphs[i].geometry.width; @@ -574,7 +576,32 @@ pango_x_font_get_glyph_extents (PangoFont *font, XCharStruct *cs; PangoXSubfontInfo *subfont; - if (glyph != PANGO_GLYPH_NULL && glyph & PANGO_GLYPH_UNKNOWN_FLAG) + if (glyph == PANGO_GLYPH_EMPTY) + { + if (ink_rect) + ink_rect->x = ink_rect->width = ink_rect->y = ink_rect->height = 0; + if (logical_rect) + logical_rect->x = logical_rect->width = logical_rect->y = logical_rect->height = 0; + return; + } + if ((glyph & PANGO_GLYPH_UNKNOWN_FLAG) == 0 && pango_x_find_glyph (font, glyph, &subfont, &cs)) + { + if (ink_rect) + { + ink_rect->x = PANGO_SCALE * cs->lbearing; + ink_rect->width = PANGO_SCALE * (cs->rbearing - cs->lbearing); + ink_rect->y = PANGO_SCALE * -cs->ascent; + ink_rect->height = PANGO_SCALE * (cs->ascent + cs->descent); + } + if (logical_rect) + { + logical_rect->x = 0; + logical_rect->width = PANGO_SCALE * cs->width; + logical_rect->y = - PANGO_SCALE * subfont->font_struct->ascent; + logical_rect->height = PANGO_SCALE * (subfont->font_struct->ascent + subfont->font_struct->descent); + } + } + else { PangoFontMetrics *metrics = pango_font_get_metrics (font, pango_language_from_string ("en")); @@ -582,7 +609,10 @@ pango_x_font_get_glyph_extents (PangoFont *font, gdouble width_factor; int w; - wc = glyph & (~PANGO_GLYPH_UNKNOWN_FLAG); + if (glyph & PANGO_GLYPH_UNKNOWN_FLAG) + wc = glyph & (~PANGO_GLYPH_UNKNOWN_FLAG); + else + wc = 0; switch (wc) { @@ -623,40 +653,6 @@ pango_x_font_get_glyph_extents (PangoFont *font, } } - else if (glyph != PANGO_GLYPH_NULL && pango_x_find_glyph (font, glyph, &subfont, &cs)) - { - if (ink_rect) - { - ink_rect->x = PANGO_SCALE * cs->lbearing; - ink_rect->width = PANGO_SCALE * (cs->rbearing - cs->lbearing); - ink_rect->y = PANGO_SCALE * -cs->ascent; - ink_rect->height = PANGO_SCALE * (cs->ascent + cs->descent); - } - if (logical_rect) - { - logical_rect->x = 0; - logical_rect->width = PANGO_SCALE * cs->width; - logical_rect->y = - PANGO_SCALE * subfont->font_struct->ascent; - logical_rect->height = PANGO_SCALE * (subfont->font_struct->ascent + subfont->font_struct->descent); - } - } - else - { - if (ink_rect) - { - ink_rect->x = 0; - ink_rect->width = 0; - ink_rect->y = 0; - ink_rect->height = 0; - } - if (logical_rect) - { - logical_rect->x = 0; - logical_rect->width = 0; - logical_rect->y = 0; - logical_rect->height = 0; - } - } } static gboolean @@ -701,7 +697,7 @@ itemize_string_foreach (PangoFont *font, PangoGlyphString *glyph_str = pango_glyph_string_new (); PangoEngineShape *shaper, *last_shaper; int last_level; - long n_chars, i; + int i; guint8 *embedding_levels; PangoDirection base_dir = PANGO_DIRECTION_LTR; gboolean finished = FALSE; |