[cairo] Polygon fill styles?
bertram.felgenhauer at googlemail.com
Fri Aug 22 03:44:18 PDT 2008
Ian Britten wrote:
>> Sound like it, once I get the patterns made... I may have more
>> questions at that time though.
> Would anyone have a few minutes that they could look at (or try) the
> self-contained (cairomm) sample I've attached, to explain what I'm
> doing wrong regarding the size/scaling of the patterns?
> Basically, I've made a square PDF surface, mapped a square user-unit
> cover into it, and drawn a simple diamond polygon into it. This
> works no problem, irregardless of the of the user unit cover I use.
> When I try to add a pattern to the polygon, the resulting output
> doesn't match my expectation, nor do the numbers I'm seeing in the
> debugger match the result.
This would be because when you call context->set_source, the current
transformation of the context gets applied to the pattern.
As a result, 1 device unit of the pattern now maps to 1mm of the
context's user space; in effect the scaling factor 72/25.4 gets
The easy solution is to just create a 5x5 surface; you'll see 20x20
tiles of the small square, which is correct. This will work nicely
on vector surfaces like pdf, but has quality problems with image
surfaces, because 5x5 is an awfully small resolution.
Alternatively, you can temporarily reset the context's transformation
matrix to the identity to get the behaviour that you probably expected.
Thirdly, you can set a transformation on the pattern itself, using
set_matrix(). The effect is somewhat counter-intuitive (it applies the
inverse transformation of the matrix to the pattern); see the
documentation on cairo_pattern_set_matrix() at
So you could, say, create a 15x15 surface and then do
cairo_matrix_init_scale(&pattern_transform, 3, 3);
before setting it as a source.
More information about the cairo