[cairo] Image rendering help?

Ian Britten britten at caris.com
Thu Oct 2 09:01:37 PDT 2008


Ian Britten wrote:
> Hi all,
> I was wondering if someone knowledgeable could take a bit of a
> look at the attached (cairomm) test I'm playing with?

[ snip ]

> For the VIA_PATTERN case:
> - (sigh) It doesn't seem to work, even though it seems to be the
>   same as my SURFACE case (to me, at least).  Can anyone point
>   out what's wrong?

Ok, I've made a bit of progress, but I still can't seem to
understand what it's doing, nor how to get what I want.

If I change my VIA_PATTERN case to this:
         Cairo::RefPtr<Cairo::SurfacePattern> pattern(
                 Cairo::SurfacePattern::create(image));
         Cairo::Matrix tmpMatrix;
         context->get_matrix(tmpMatrix);
         pattern->set_matrix(tmpMatrix);
         context->set_source(pattern);
         context->paint();
then my image draws in the upper-left corner.  :)

However:
- I don't understand what the get_matrix()/set_matrix() is doing
   or why it's necessary.  In my mind, I'd think that the default
   transformation on the Pattern would be Identity, and when I set
   the Pattern on the Context, it would add the Patterns
   transformation to the current transformation of the Context,
   which would basically be a NOOP in this case.  Obviously it
   doesn't work that way, and I don't fully understand what's
   going on.
- I still can't figure out how to change where the image is being
   drawn.  I've tried adding translate() calls to my matrix,
   and/or to my Context (Both before and after setting the Pattern
   on it), I've tried adding move_to() calls, and am running out
   of ideas...
- To try to get the Image to fill my Surface, I tried adding
   a scale() call to the tmpMatrix before setting it on the
   pattern.  However, my image just disappears then :(
   Shouldn't a call like
         cairo_matrix_scale(&tmpMatrix, 2, 2);
   result in my image drawing at twice its size?
- If I set a rotation on my Surface, then the vector path I'm
   drawing is correctly rotated, but my image still appears
   unrotated (upright), in the upper-left corner.  Does a Pattern
   not rotate with a Surface?
   [ BTW - I'm using Cairo 1.6.4, just in case it's a bug ]

Am I maybe going about this the wrong way?

Any help/explanation would be _most_ appreciated!
Ian


More information about the cairo mailing list