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

Behdad Esfahbod behdad at behdad.org
Thu Oct 21 11:57:46 PDT 2010

On 10/21/10 08:26, Uli Schlachter wrote:
> Hi,
> attached is a diff between current master and my try at this. I got this split
> up into multiple commits at [1]. I hope this works roughly like you wanted it to
> work.

Close.  Instead of a bool, use an enum with default/on/off like all the other
font options.  Also, please turn it on for any backend that rounds.


> I only enable this for the image and xcb backends, because this is where I know
> that it fixes test suite failures. Other backends could do the same if needed.
> Cheers,
> Uli
> [1]
> http://git.znc.in/?p=psychon/cairo.git;a=shortlog;h=refs/heads/glyph_pos_rounding
> Am 21.10.2010 02:24, Behdad Esfahbod wrote:
>> 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