[cairo] A newbie question on surfaces
thomas at wsinnovations.com
Wed Oct 17 09:56:11 PDT 2007
hmmm. I'm still working on my understanding as well. Let us clear up the picture a little.
-In the current gtk versions, if you want to draw something with cairo, you obtain a cairo_t via gdk_cairo_create() inside the expose event handler for typically a gtk_drawing_area, and draw on that. This context will have a width and a height from the current widget size.
-If you want to know what the width and the height of this widget / "cairo device" are you examine the members of the widget's allocation structure, ie width = drawing_area->allocation.width
-One of the big reasons for using cairo in this case is that your drawing can be done at an arbitrary scale, and then be dynamically sized for a given window at each expose event.
-If your drawing/rendering function does not work with a dynamic aspect ratio, the expose handler can center the drawing and pad either the left/right or top/bottom margins with matching background color for better results.
Now about your question, I'm personally still fuzzy on the relation ship between contexts and surfaces. All I'm using cairo for is inside gtk apps, and all I ever seem to need is just the context type (cairo_t) retrieved from gdk. I definitely think you can do what ever you want, but I'm not following you. Give a little more description of what you want accomplished.
Date: Tue, 16 Oct 2007 20:17:36 +0530
From: "Anurag Singh" <anurag12singh at gmail.com>
Subject: [cairo] A newbie question on surfaces
To: cairo at cairographics.org
<21ead2f90710160747uebb2781gde179bf9417d9501 at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
I have to write an application in which I would be getting a cairo
context(cairo_t *) from some other windowing application which uses a
combination of cairo and Gtk+2.0 and then I have to use that cairo
context to scale down the image according to the size of my window.
For example, if my window size is 200 x 150 and the surface size is
800 x 600, I would have to use cairo_scale ( new, .25, .25) . My
question is that can I get the cairo surface from the cairo context I
am getting using cairo_get_target() even if the cairo context which I
get was created using gdk_cairo_create().
My apologioes if the question is a bit unclear.
More information about the cairo