diff options
author | Owen Taylor <otaylor@redhat.com> | 2003-05-27 20:13:37 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2003-05-27 20:13:37 +0000 |
commit | cae7211594d3c2b8c0aacee1f067e53c0e9823ba (patch) | |
tree | 1ec486ad18782b5dfcd5ab79c968d78121ac7560 /pango/pangox.c | |
parent | 6301eeece77b8c6b6b07be8415142b5d2e1085ca (diff) | |
download | pango-cae7211594d3c2b8c0aacee1f067e53c0e9823ba.tar.gz |
Patch from Morten Welinder to collect characters into runs of the same
Tue May 27 16:06:34 2003 Owen Taylor <otaylor@redhat.com>
* pango/pangox.c (pango_x_render): Patch from Morten
Welinder to collect characters into runs of the
same font with natural offsets before drawing them.
(#106892, Morten Welinder)
Diffstat (limited to 'pango/pangox.c')
-rw-r--r-- | pango/pangox.c | 61 |
1 files changed, 47 insertions, 14 deletions
diff --git a/pango/pangox.c b/pango/pangox.c index 80151a65..e3036d5b 100644 --- a/pango/pangox.c +++ b/pango/pangox.c @@ -455,6 +455,19 @@ pango_x_load_font (Display *display, return (PangoFont *)result; } + + +#define FLUSH \ + G_STMT_START { \ + if (charcount) \ + { \ + XDrawString16 (display, d, gc, \ + glyph_x0, glyph_y0, \ + xcharbuffer, charcount); \ + charcount = 0; \ + } \ + } G_STMT_END + /** * pango_x_render: @@ -477,15 +490,21 @@ pango_x_render (Display *display, int x, int y) { - /* Slow initial implementation. For speed, it should really - * collect the characters into runs, and draw multiple - * characters with each XDrawString16 call. - */ Font old_fid = None; XFontStruct *fs; int i; int x_off = 0; + /* + * We collect the characters in this buffer as long as the font does not + * change. At that time, or when the buffer runs full, or at the end, + * then we empty the buffer. + */ + XChar2b xcharbuffer[1000]; + int glyph_x0 = 0, expected_x = 0; /* x/y initializations are to quiet GCC */ + int glyph_y0 = 0; + int charcount = 0; + g_return_if_fail (display != NULL); g_return_if_fail (glyphs != NULL); @@ -515,7 +534,9 @@ pango_x_render (Display *display, int stroke_thick; gunichar wc; - + + FLUSH; + x1 = glyph_x; y1 = glyph_y - PANGO_PIXELS (metrics->ascent); x2 = x1 + PANGO_PIXELS (glyphs->glyphs[i].geometry.width); @@ -624,35 +645,47 @@ pango_x_render (Display *display, guint16 subfont_index = PANGO_X_GLYPH_SUBFONT (glyph); PangoXSubfontInfo *subfont; - XChar2b c; - subfont = pango_x_find_subfont (font, subfont_index); if (subfont) { - c.byte1 = index / 256; - c.byte2 = index % 256; - 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; } - - XDrawString16 (display, d, gc, - glyph_x, glyph_y, - &c, 1); + + 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; } + FLUSH; } +#undef FLUSH + static void pango_x_font_get_glyph_extents (PangoFont *font, PangoGlyph glyph, |