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/pangoxft-render.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/pangoxft-render.c')
-rw-r--r-- | pango/pangoxft-render.c | 187 |
1 files changed, 102 insertions, 85 deletions
diff --git a/pango/pangoxft-render.c b/pango/pangoxft-render.c index 7d85008b..3c5e5bed 100644 --- a/pango/pangoxft-render.c +++ b/pango/pangoxft-render.c @@ -68,11 +68,6 @@ static void pango_xft_renderer_draw_glyphs (PangoRenderer *renderer, PangoGlyphString *glyphs, int x, int y); -static void pango_xft_renderer_draw_glyph (PangoRenderer *renderer, - PangoFont *font, - PangoGlyph glyph, - double x, - double y); static void pango_xft_renderer_draw_trapezoid (PangoRenderer *renderer, PangoRenderPart part, double y1, @@ -109,7 +104,6 @@ pango_xft_renderer_class_init (PangoXftRendererClass *klass) klass->composite_trapezoids = pango_xft_renderer_real_composite_trapezoids; renderer_class->draw_glyphs = pango_xft_renderer_draw_glyphs; - renderer_class->draw_glyph = pango_xft_renderer_draw_glyph; renderer_class->draw_trapezoid = pango_xft_renderer_draw_trapezoid; renderer_class->part_changed = pango_xft_renderer_part_changed; renderer_class->end = pango_xft_renderer_end; @@ -314,6 +308,88 @@ draw_box (PangoRenderer *renderer, } static void +_pango_xft_renderer_draw_box_glyph (PangoRenderer *renderer, + PangoGlyphInfo *gi, + int glyph_x, + int glyph_y) +{ + int x = glyph_x + PANGO_SCALE; + int y = glyph_y - PANGO_SCALE * (PANGO_UNKNOWN_GLYPH_HEIGHT - 1); + int width = gi->geometry.width - PANGO_SCALE * 2; + int height = PANGO_SCALE * (PANGO_UNKNOWN_GLYPH_HEIGHT - 2); + + if (box_in_bounds (renderer, x, y, width, height)) + draw_box (renderer, PANGO_SCALE, x, y, width, height); +} + +static void +_pango_xft_renderer_draw_unknown_glyph (PangoRenderer *renderer, + PangoXftFont *xfont, + XftFont *xft_font, + PangoGlyphInfo *gi, + int glyph_x, + int glyph_y) +{ + char buf[7]; + int ys[3]; + int xs[4]; + int row, col; + int cols; + PangoGlyph glyph; + + PangoFont *mini_font = _pango_xft_font_get_mini_font (xfont); + XftFont *mini_xft_font = pango_xft_font_get_font (mini_font); + if (!mini_xft_font) + { + _pango_xft_renderer_draw_box_glyph (renderer, gi, glyph_x, glyph_y); + return; + } + + glyph = gi->glyph & ~PANGO_GLYPH_UNKNOWN_FLAG; + + ys[0] = glyph_y - PANGO_SCALE * xft_font->ascent + PANGO_SCALE * (((xft_font->ascent + xft_font->descent) - (xfont->mini_height * 2 + xfont->mini_pad * 5 + PANGO_SCALE / 2) / PANGO_SCALE) / 2); + ys[1] = ys[0] + 2 * xfont->mini_pad + xfont->mini_height; + ys[2] = ys[1] + xfont->mini_height + xfont->mini_pad; + + xs[0] = glyph_x; + xs[1] = xs[0] + 2 * xfont->mini_pad; + xs[2] = xs[1] + xfont->mini_width + xfont->mini_pad; + xs[3] = xs[2] + xfont->mini_width + xfont->mini_pad; + + if (glyph > 0xffff) + { + cols = 3; + g_snprintf (buf, sizeof(buf), "%06X", glyph); + } + else + { + cols = 2; + g_snprintf (buf, sizeof(buf), "%04X", glyph); + } + + if (box_in_bounds (renderer, + xs[0], ys[0], + xfont->mini_width * cols + xfont->mini_pad * (2 * cols + 1), + xfont->mini_height * 2 + xfont->mini_pad * 5)) + { + draw_box (renderer, xfont->mini_pad, + xs[0], ys[0], + xfont->mini_width * cols + xfont->mini_pad * (2 * cols + 1), + xfont->mini_height * 2 + xfont->mini_pad * 5); + + for (row = 0; row < 2; row++) + for (col = 0; col < cols; col++) + { + draw_glyph (renderer, mini_font, + XftCharIndex (NULL, mini_xft_font, + buf[row * cols + col] & 0xff), + xs[col+1], + ys[row+1]); + } + } +} + +static void pango_xft_renderer_draw_glyphs (PangoRenderer *renderer, PangoFont *font, PangoGlyphString *glyphs, @@ -330,22 +406,17 @@ pango_xft_renderer_draw_glyphs (PangoRenderer *renderer, { for (i=0; i<glyphs->num_glyphs; i++) { - PangoGlyph glyph = glyphs->glyphs[i].glyph; - int glyph_x = x + x_off + glyphs->glyphs[i].geometry.x_offset; - int glyph_y = y + glyphs->glyphs[i].geometry.y_offset; + PangoGlyphInfo *gi = &glyphs->glyphs[i]; - if (glyph != PANGO_GLYPH_NULL && glyph & PANGO_GLYPH_UNKNOWN_FLAG) + if (gi->glyph != PANGO_GLYPH_EMPTY) { - int x = glyph_x + PANGO_SCALE; - int y = glyph_y + PANGO_SCALE; - int width = PANGO_SCALE * (PANGO_UNKNOWN_GLYPH_WIDTH - 2); - int height = PANGO_SCALE * (PANGO_UNKNOWN_GLYPH_HEIGHT - 2); + int glyph_x = x + x_off + gi->geometry.x_offset; + int glyph_y = y + gi->geometry.y_offset; - if (box_in_bounds (renderer, x, y, width, height)) - draw_box (renderer, PANGO_SCALE, x, y, width, height); + _pango_xft_renderer_draw_box_glyph (renderer, gi, glyph_x, glyph_y); } - x_off += glyphs->glyphs[i].geometry.width; + x_off += gi->geometry.width; } return; } @@ -355,87 +426,33 @@ pango_xft_renderer_draw_glyphs (PangoRenderer *renderer, for (i=0; i<glyphs->num_glyphs; i++) { - PangoGlyph glyph = glyphs->glyphs[i].glyph; - int glyph_x = x + x_off + glyphs->glyphs[i].geometry.x_offset; - int glyph_y = y + glyphs->glyphs[i].geometry.y_offset; + PangoGlyphInfo *gi = &glyphs->glyphs[i]; - if (glyph != PANGO_GLYPH_NULL) + if (gi->glyph != PANGO_GLYPH_EMPTY) { - if (glyph & PANGO_GLYPH_UNKNOWN_FLAG) + int glyph_x = x + x_off + gi->geometry.x_offset; + int glyph_y = y + gi->geometry.y_offset; + + if (gi->glyph & PANGO_GLYPH_UNKNOWN_FLAG) { - char buf[7]; - int ys[3]; - int xs[4]; - int row, col; - int cols; - - PangoFont *mini_font = _pango_xft_font_get_mini_font (xfont); - XftFont *mini_xft_font = pango_xft_font_get_font (mini_font); - - glyph &= ~PANGO_GLYPH_UNKNOWN_FLAG; - - ys[0] = glyph_y - PANGO_SCALE * xft_font->ascent + PANGO_SCALE * (((xft_font->ascent + xft_font->descent) - (xfont->mini_height * 2 + xfont->mini_pad * 5 + PANGO_SCALE / 2) / PANGO_SCALE) / 2); - ys[1] = ys[0] + 2 * xfont->mini_pad + xfont->mini_height; - ys[2] = ys[1] + xfont->mini_height + xfont->mini_pad; - - xs[0] = glyph_x; - xs[1] = xs[0] + 2 * xfont->mini_pad; - xs[2] = xs[1] + xfont->mini_width + xfont->mini_pad; - xs[3] = xs[2] + xfont->mini_width + xfont->mini_pad; - - if (glyph > 0xffff) - { - cols = 3; - g_snprintf (buf, sizeof(buf), "%06X", glyph); - } - else - { - cols = 2; - g_snprintf (buf, sizeof(buf), "%04X", glyph); - } - - if (box_in_bounds (renderer, - xs[0], ys[0], - xfont->mini_width * cols + xfont->mini_pad * (2 * cols + 1), - xfont->mini_height * 2 + xfont->mini_pad * 5)) - { - draw_box (renderer, xfont->mini_pad, - xs[0], ys[0], - xfont->mini_width * cols + xfont->mini_pad * (2 * cols + 1), - xfont->mini_height * 2 + xfont->mini_pad * 5); - - for (row = 0; row < 2; row++) - for (col = 0; col < cols; col++) - { - draw_glyph (renderer, mini_font, - XftCharIndex (NULL, mini_xft_font, - buf[row * cols + col] & 0xff), - xs[col+1], - ys[row+1]); - } - } + _pango_xft_renderer_draw_unknown_glyph (renderer, + xfont, + xft_font, + gi, + glyph_x, + glyph_y); } else { - draw_glyph (renderer, font, glyph, glyph_x, glyph_y); + draw_glyph (renderer, font, gi->glyph, glyph_x, glyph_y); } } - x_off += glyphs->glyphs[i].geometry.width; + x_off += gi->geometry.width; } } static void -pango_xft_renderer_draw_glyph (PangoRenderer *renderer, - PangoFont *font, - PangoGlyph glyph, - double x, - double y) -{ - g_critical ("pango_xft_renderer_draw_glyph(): should not be called"); -} - -static void flush_trapezoids (PangoXftRenderer *xftrenderer) { if (!xftrenderer->priv->trapezoids || |