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

Uli Schlachter psychon at znc.in
Tue Oct 19 03:02:39 PDT 2010


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 -
	    y = _cairo_lround (info->glyphs[i].y -

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.

Uli Schlachter


"Do you know that books smell like nutmeg or some spice from a foreign land?"
                                                  -- Faber in Fahrenheit 451

More information about the cairo mailing list