[cairo] Unsymmetrical rotation

Olaf Schmidt ng at vbRichClient.com
Mon Mar 4 17:11:09 PST 2013


Am 04.03.2013 22:03, schrieb Blagoj Kupev:

> Does anyone else have any other idea? Can this be a bug in cairo?

I'm pretty sure, it's not a bug - and could also be done whilst
working against the canvas directly - but why not trying a nicer
base-approach, which would allow you to "pre-set" certain things
for even more drawing-objects than just a "single box" (in case
you want to go there in the future).


What helped me with "complex individual rotations" of different
drawing-objects (having all kind of individual sizes on a given
"base-canvas"), was to just wrap the surface of any such image
in a pattern - and then using the *pattern*-matrix to set the
individual centerpoint and rotation for each of those child-objects.

Based on a simple sequence against the the current pattern-matrix, using 
the current sub-surface width/height as follows:
   Translate CurImgWidth / 2, CurImgHeight / 2
     Rotate YourAngle
   Translate -CurImgWidth / 2, -CurImgHeight / 2

After pattern-wrapping and applying such an individual pattern-
matrix, the main-rendering-routine for those child-objects didn't
need to be changed at all (with regards to the x- and y-Offsets
for the placement of those child-objects on the canvas).
You can then treat those child-containers offsets, as if they'd
be always (or still) in "original, unchanged simple box-mode".

Only thing to change of course in the main-rendering-routine,
in case it contains a sub-routine like this (or will be changed
to use something like the following one in a first step - still
using unrotated "box-surfaces" and no patterns - just for testing):

place_box_surface(cr, boxSrf, xOffs, yOffs){
   cairo_save cr
     cairo_translate cr, xOffs, yOffs
     cairo_set_source_surface cr, boxSrf, 0, 0
     cairo_paint cr
   cairo_restore cr
}

Will be the replacment of the above:
   cairo_set_source_surface cr, boxSrf, 0, 0
with:
   cairo_set_source cr, boxPat

So later, when you have your pattern-wrapped surface(s) in place -
and the individual box-rotation applied to the pattern-matrix,
you could switch-over to something like that routine here:

place_box_pattern(cr, boxPat, xOffs, yOffs){
   cairo_save cr
     cairo_translate cr, xOffs, yOffs
     cairo_set_source cr, boxPat
     cairo_paint cr
   cairo_restore cr
}


Olaf



More information about the cairo mailing list