[cairo] Fwd: Cairo buglet

Carl Worth cworth at cworth.org
Sat Jul 23 09:39:12 PDT 2005

On Fri, 22 Jul 2005 22:40:40 -0400, Pat Beirne wrote:
> Carl, I was in your Fri tutorial and I wrote a little
> clock/power monitor.
> Here's the code, if you want. I should just "drop" into the tutorial
> directory; it uses the same -gtk,-xlib,-png,-pdf wrappers.

Thanks, I'll drop that in.

> Is this a bug? Is there another way to query the drawing
> state for its size?

This is a bug in the program. The note I made in the corresponding
bugzilla bug is:
    > In a -gtk or -xlib environment,
    > cairo_surface_t *cs = cairo_get_target(cr);
    > int width = cairo_image_surface_get_width(cs);
    > int height = cairo_image_surface_get_height(cs);
    The code above is in error. When it calls cairo_get_target it is
    returning an xlib surface, but then it goes on to call
    cairo_image_surface_get_width/height which are calls that will
    only work correctly given an image surface, (not an xlib surface).
    As it turns out, we can't provide completely general functions such
    as cairo_surface_get_width/height since there are some surface types
    that have no notion of a size.
    So the fix for the code above will require using size information that
    the application already has. It must of necessity have size
    available since the size is required when creating the surface.
    There is still a bug here in that the error isn't being reported in
    a useful manner. I'll be working on a fix for that shortly.

Seeing the entire program here it's more obvious why you hit this.

My "cairo-tutoral.h" hack hides the original size information for
creating the surface. The fix is to use the support it provides for
setting your own size. Something like this:

	#define WIDTH 500
	#define HEIGHT 500

	#include "cairo-tutorial.h"


	/* Just use WIDTH/HEIGHT down below. */

I hope that helps,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050723/2c3089de/attachment.pgp

More information about the cairo mailing list