summaryrefslogtreecommitdiff
path: root/pango/pangoft2-render.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2006-02-03 02:46:17 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2006-02-03 02:46:17 +0000
commit6c9e853b93be4c01027e625427787e38be9b99f3 (patch)
tree9b1f07249ff96f43ce9f8af61613e067e0e1ea74 /pango/pangoft2-render.c
parentb1e264aa208e43a3d98aa2f985a0eaafdb328bb8 (diff)
downloadpango-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-render.c')
-rw-r--r--pango/pangoft2-render.c114
1 files changed, 106 insertions, 8 deletions
diff --git a/pango/pangoft2-render.c b/pango/pangoft2-render.c
index 5aa1872e..2a814861 100644
--- a/pango/pangoft2-render.c
+++ b/pango/pangoft2-render.c
@@ -100,20 +100,97 @@ pango_ft2_free_rendered_glyph (PangoFT2RenderedGlyph *rendered)
}
static PangoFT2RenderedGlyph *
+pango_ft2_font_render_box_glyph (int width,
+ int height,
+ int top)
+{
+ PangoFT2RenderedGlyph *box;
+ int i, j, offset1, offset2, line_width;
+
+ line_width = MAX ((height + 43) / 44, 1);
+ if (width < 1 || height < 1)
+ line_width = 0;
+
+ box = g_slice_new (PangoFT2RenderedGlyph);
+
+ box->bitmap_left = 0;
+ box->bitmap_top = top;
+
+ box->bitmap.pixel_mode = ft_pixel_mode_grays;
+
+ box->bitmap.width = width;
+ box->bitmap.rows = height;
+ box->bitmap.pitch = height;
+
+ box->bitmap.buffer = g_malloc0 (box->bitmap.rows * box->bitmap.pitch);
+
+ /* draw the box */
+ for (j = 0; j < line_width; j++)
+ {
+ offset1 = box->bitmap.pitch * (MIN (1 + j, height - 1));
+ offset2 = box->bitmap.pitch * (MAX (box->bitmap.rows - 2 - j, 0));
+ for (i = 1;
+ i < box->bitmap.width - 1;
+ i++)
+ {
+ box->bitmap.buffer[offset1 + i] = 0xff;
+ box->bitmap.buffer[offset2 + i] = 0xff;
+ }
+ }
+ for (j = 0; j < line_width; j++)
+ {
+ offset1 = MIN (1 + j, width - 1);
+ offset2 = MAX (box->bitmap.width - 2 - j, 0);
+ for (i = box->bitmap.pitch;
+ i < (box->bitmap.rows - 1) * box->bitmap.pitch;
+ i += box->bitmap.pitch)
+ {
+ box->bitmap.buffer[offset1 + i] = 0xff;
+ box->bitmap.buffer[offset2 + i] = 0xff;
+ }
+ }
+
+ return box;
+}
+
+static PangoFT2RenderedGlyph *
pango_ft2_font_render_glyph (PangoFont *font,
int glyph_index)
{
- PangoFT2RenderedGlyph *rendered;
FT_Face face;
- rendered = g_slice_new (PangoFT2RenderedGlyph);
+ if (glyph_index & PANGO_GLYPH_UNKNOWN_FLAG)
+ {
+ static PangoFT2RenderedGlyph *box;
+ PangoFontMetrics *metrics;
+
+ if (!font)
+ goto generic_box;
+
+ metrics = pango_font_get_metrics (font, NULL);
+ if (!metrics)
+ goto generic_box;
+
+ /* this box gets cached, so don't bother with static'ing it.
+ */
+
+ box = pango_ft2_font_render_box_glyph (PANGO_PIXELS (metrics->approximate_char_width),
+ PANGO_PIXELS (metrics->ascent + metrics->descent),
+ PANGO_PIXELS (metrics->ascent));
+ pango_font_metrics_unref (metrics);
+
+ return box;
+ }
face = pango_ft2_font_get_face (font);
if (face)
{
+ PangoFT2RenderedGlyph *rendered;
PangoFT2Font *ft2font = (PangoFT2Font *) font;
+ rendered = g_slice_new (PangoFT2RenderedGlyph);
+
/* Draw glyph */
FT_Load_Glyph (face, glyph_index, ft2font->load_flags);
FT_Render_Glyph (face->glyph,
@@ -125,11 +202,23 @@ pango_ft2_font_render_glyph (PangoFont *font,
face->glyph->bitmap.rows * face->glyph->bitmap.pitch);
rendered->bitmap_left = face->glyph->bitmap_left;
rendered->bitmap_top = face->glyph->bitmap_top;
+
+ return rendered;
}
else
- g_warning ("couldn't get face for PangoFT2Face, expect ugly output");
+ {
+ static PangoFT2RenderedGlyph *box = NULL;
+
+ generic_box:
+ if (!box)
+ {
+ box = pango_ft2_font_render_box_glyph (PANGO_UNKNOWN_GLYPH_WIDTH,
+ PANGO_UNKNOWN_GLYPH_HEIGHT,
+ PANGO_UNKNOWN_GLYPH_HEIGHT);
+ }
- return rendered;
+ return box;
+ }
}
static void
@@ -151,9 +240,18 @@ pango_ft2_renderer_draw_glyph (PangoRenderer *renderer,
int ix, iy;
if (glyph & PANGO_GLYPH_UNKNOWN_FLAG)
- glyph = PANGO_GLYPH_NULL;
- if (glyph == PANGO_GLYPH_NULL)
- return;
+ {
+ FT_Face face = pango_ft2_font_get_face (font);
+ if (face && FT_IS_SFNT (face))
+ glyph = pango_ft2_get_unknown_glyph (font);
+ else
+ {
+ /* Since we only draw an empty box for FT2 renderer,
+ * unify the rendered bitmaps in the cache.
+ */
+ glyph = PANGO_GLYPH_UNKNOWN_FLAG;
+ }
+ }
rendered_glyph = _pango_ft2_font_get_cache_glyph_data (font, glyph);
add_glyph_to_cache = FALSE;
@@ -588,8 +686,8 @@ pango_ft2_render_transformed (FT_Bitmap *bitmap,
PangoRenderer *renderer;
g_return_if_fail (bitmap != NULL);
- g_return_if_fail (PANGO_FT2_IS_FONT (font));
g_return_if_fail (glyphs != NULL);
+ g_return_if_fail (PANGO_FT2_IS_FONT (font));
fontmap = PANGO_FC_FONT (font)->fontmap;
renderer = _pango_ft2_font_map_get_renderer (PANGO_FT2_FONT_MAP (fontmap));