[cairo] Wrong extents when rendering glyphs to non-integer positions

Behdad Esfahbod behdad at behdad.org
Wed Oct 20 17:24:40 PDT 2010


Long term, there's a LOT to be fixed (including, first defining what the
extents really mean in raster backend), but for now a hack shall be used.
Your's misses a few corner cases (analysis surface targeting raster surface,
recording surface targeting raster, etc).

I suggest instead you add a private font-options member and set it to ON/OFF
in different surface types like we already do for hinting.

b

On 10/19/10 06:02, Uli Schlachter wrote:
> Hi,
> 
> thanks to a bug in the XCB backend, I noticed that
> _cairo_composite_rectangles_init_for_glyphs returns a wrong extent for
> non-integer-aligned glyphs (see the result of xcb's overlapping-glyphs test).
> 
> The problem is that the xcb and image backends (and others?) round the pixel
> coordinates before drawing, e.g. cairo-image-surface.c, line 3977:
> 
> 	    x = _cairo_lround (info->glyphs[i].x -
> 			       glyph_surface->base.device_transform.x0);
> 	    y = _cairo_lround (info->glyphs[i].y -
> 			       glyph_surface->base.device_transform.y0);
> 
> However, the function that does all the extents-work
> (_cairo_scaled_font_glyph_device_extents) doesn't do this rounding. Instead, it
> generates a cairo_box_t with the exact bounding rectangle and then rounds this
> via _cairo_box_round_to_rectangle to a cairo_rectangle_int_t.
> 
> I did a quick-and-dirty hack that makes _cairo_scaled_font_glyph_device_extents
> use _cairo_lround[1]. The test suite then said that this fixed text-rotate in
> the test suite (and only broke Xlib's clip-text due to a wrong text postion).
> 
> Andrea Canciani suggested that this change might break hinting. Looking at the
> font face code, I need someone else to confirm this. ;)
> 
> Could somehow who has a better understanding of cairo's glyph rendering take a
> look at this and perhaps come up with a nice(r) fix? IMHO, all backends that can
> only draw glyphs to integer positions and thus use _cairo_lround might be
> affected by this problem in one way or another.
> 
> Cheers,
> Uli Schlachter
> 
> [1]
> http://git.znc.in/?p=psychon/cairo.git;a=commitdiff;h=41ea61f8fd5abf7e9f462b97052d31a75ae4b97c
> 


More information about the cairo mailing list