[cairo] Expected behavior of dashes, lines and patterns under transform

Chris Wilson chris at chris-wilson.co.uk
Sun Apr 29 14:51:22 PDT 2012

On Sun, 29 Apr 2012 17:39:41 -0400, cu <cairouser at yahoo.com> wrote:
> I've been trying to draw into Cairo context with transform matrix set.
> Under scaling transform (with scaling factor of, say, 1000 with small
> coordinate values supplied to drawing functions which then scale them up
> to user level pixel coordinates) I've seen the following:
> 1. Line widths seem to be scaled up (which is counter-intuitive)

Long-standing bug that was not fixed in time for cairo-1.0, hence now
locked in stone. The matrix for line-widths is the CTM at the time of
the stroke not the CTM at the time of setting the line-width.
> 2. Even if transform is set before drawing and reset to identity before
> setting line width, lines don't look quite the same as if scaled
> coordinates are used as input - anialiasing is relatively poor.

That's unexpected since all that happens is the coordinates are
transformed. However, I notice that dashes are handled natively by
Quartz. Are you seeing similar results using an image surface?
> 3. Can't tell for sure what happens with dashes - they seem not to work
> half the time (endless loops, perhaps the new release takes care of
> that). It seems that dash lengths are scaled as well. Resetting to
> identity before drawing dashed lines helps somewhat, but dash lengths
> still appear "off" (different from drawing with pre-scaled coordinates).

Dash lengths were broken for rectilinear strokes in cairo-1.12.0. Like
the line-width, the dash lengths will be scaled by the CTM at the time
of the stroke.

> 4. I was unable to draw a source "sprite" pattern  onto a scaled
> surface, no matter what combination of scaling/resetting to
> identity/moving etc. I tried.

That's a basic procedure for compositing and is most definitely expected
to work! Can you show us the code you think should work and perhaps a
sketch of the result you want?

Chris Wilson, Intel Open Source Technology Centre

More information about the cairo mailing list