[cairo] create an image from window for printing
Owen Taylor
otaylor at redhat.com
Sat Jan 20 20:25:51 PST 2007
Hmm, it just occurred to me that there was a small bit of nonsense
in my examples:
On Sat, 2007-01-20 at 17:50 -0500, Owen Taylor wrote:
> So, say you have an surface of dimensions w0, h0, and you want to draw
> it at x,y and size w,h
>
> cairo_save(cr);
> cairo_move_to(cr, x, y);
^^^^^^^
translate
> cairo_scale(cr, w/w0, h/h0);
> cairo_set_source_surface(cr, surface, 0, 0);
> cairo_paint(cr);
>
> You really should study that until you realize that there is zero magic
> in it; it's just a straightforward consequence of how cairo works.
>
> So, say if you were drawing directly to a PDF surface, and you wanted to
> paint it with the top left at 1cm, 1cm and with width of 10cm, then you
> would do:
>
> #define POINTS_PER_CM (72. / 2.54);
>
> cairo_save(cr);
> cairo_move_to(cr, POINTS_PER_CM, POINTS_PER_CM);
^^^^^^^
translate
> double scale = (10 * POINTS_PER_CM) / w0;
> cairo_scale(cr, scale, scale); /* Preserve aspect ratio */
> cairo_set_source_surface(cr, surface, 0, 0);
> cairo_paint(cr);
Sorry for any confusion,
Owen
More information about the cairo
mailing list