[cairo] Getting pattern extents.

Donn donn.ingle at gmail.com
Sun Dec 14 03:42:43 PST 2014

Hi all,
Once you have a pattern, how do do you get its new extents when the CTM 

I need the new bounding box of future uses of a pattern under CTMs that 
differ from the original it was created under.


1. 'pat' is some shape drawn and cairo_pop_group() into 'pat' ref.
As vala code:
Pattern makepat( Context cr ){
     cr.rectangle( 0,0,50,50 ); //to get a 50x50px path down.
     cr.clip_preserve(); //to start clip.

      //cex1 etc. are globals.
      cr.clip_extents (out cex1, out cey1, out cex2, out cey2);

     //Draw again but to a 'group'
     Pattern apat = cr.pop_group(); //grab a cache of that drawing.
   cr.restore(); //ends that clip call.
   return apat;

Back in main():
2. Set the CTM to something.
3. pat = makepat( cr );
    Now 'pat' contains an image of a rectangle - same as the clip's size.

4. Now, I set_source(pat) and paint() it.

5. Now, I change the CTM by scaling it by 2 and translating it some — I 
paint() another 'stamp' of pat in a new size and place.

Question: How do I get the new extents of pat now? Either via cairo or 
by basic math? i.e. It's twice as big and has moved. How to get its new 
top and left, right and bottom?

I want to use 'pat' *without* redrawing the path (i.e. I use it as a 
bitmap cache to 'stamp' with) — but it seems I can't use 
cairo_clip_extents() or cairo_path_extents to get the bounding boxes of 
the stamps.

(By 'extents' I mean an axis-aligned rect that bounds the pattern in 
device coordinates.)

(I need the bounding boxes (extents) for clipping and for testing 
against the mouse and so on.)

Does that make sense? I hope so...

I hope someone can help,

More information about the cairo mailing list