[cairo] clipping

Theo Veenker T.J.G.Veenker at uu.nl
Fri Feb 8 06:48:58 PST 2013


Hi all,

Since 1.12.0 I have noticed a problem with drawing text (using pango) onto
an xlib surface or similar surface when there is global scaling applied and
the text drawing involves some clipping.

My purpose is as follows. Let's say I have some graphics (containing text)
which is normally displayed in a fullscreen window, but in some situations
I want to show a scaled down version of the window, so the user can see a
mock-up of the fullscreen version. It's nothing special. It works as expected
with cairo 1.10.2 and earlier. It also works fine when drawing onto an image
surface.

I have created a test case which demonstrates the bug. See attached images
for the 1.10.2 (OK) and for 1.12.x (not OK). The drawing routine for the
test case is this:

void drawText(cairo_surface_t *dst, PangoLayout *layout,
     int winwidth, int winheight, int virtualwidth, int virtualheight)
{
     double scalingx = (double)winwidth / virtualwidth;
     double scalingy = (double)winheight / virtualheight;

     cairo_t *cr = cairo_create(dst);

     // Apply 'global' scaling.
     cairo_scale(cr, scalingx, scalingy);

     // Let's assume the drawing involves some clipping.
     cairo_rectangle(cr, 10, 10, virtualwidth-20, virtualheight-20);
     cairo_clip(cr);

     // Clear background.
     cairo_set_source_rgb(cr, 0.8, 1, 1);
     cairo_paint(cr);

     // Draw text.
     cairo_translate(cr, 15, 15);
     cairo_set_source_rgb(cr, 0, 0, 0);
     pango_cairo_show_layout(cr, layout);
     cairo_new_path(cr);

     cairo_destroy(cr);
}

As said this works fine when drawing into an image surface or when using
cairo <= 1.10.2. There seems to be a problem with the clipping code.
Commenting out the cairo_clip() call makes the program work as expected
besides that there's no clipping going on.

Attached are two test programs scaledtextclipbug1.c and scaledtextclipbug2.c.
The first shows the graphic artifacts when you start it. The latter is an
interactive version to play with (F1=freeze virtual size, F2=make virtual
size equal to window size). After starting scaledtextclipbug2 hit F1 and
then resize the window horizontally; you'll see the weirdness.

Note the problem only affects text.

I apologize not having reported the problem before, but I just didn't have
the time to work out a test case.

Theo

-------------- next part --------------
A non-text attachment was scrubbed...
Name: scaledtextclipbug1.c
Type: text/x-csrc
Size: 4902 bytes
Desc: scaledtextclipbug1.c
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130208/9ba70bfe/attachment-0002.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scaledtextclipbug2.c
Type: text/x-csrc
Size: 6288 bytes
Desc: scaledtextclipbug2.c
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130208/9ba70bfe/attachment-0003.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screenshot-not-ok.png
Type: image/png
Size: 18394 bytes
Desc: screenshot-not-ok.png
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130208/9ba70bfe/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screenshot-ok.png
Type: image/png
Size: 22133 bytes
Desc: screenshot-ok.png
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130208/9ba70bfe/attachment-0003.png>


More information about the cairo mailing list