Re: ImageSurface from a Pattern
Donn <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <[email protected]> |
Hello there Uli, I'm not a native C ninja, so I spent an hour writing the attached to show you where my head's at. In Vala I'm having trouble moving from a "Surface" to an "ImageSurface", however I know Vala is not your bag, so leave that aside. In the C, my intent is: 1. Draw a 100px rectangle. 2. Set is as a clip - so that the size will be 100px (IIUC what you explained.) 3. pop_group into pat var. 4. Get the surface of that pat. 5. Get the width of that surface (i.e. 100px) The code is giving me 400px - the size of the initial cr surface. Where did I up-screw? :D \d Once again, I really appreciate your help on my annual Cairo holidays. :) -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo
surfaces.c
(text/x-csrc, 1.2 KB)
//gcc surf_test.c -o test -lm `pkg-config --cflags --libs cairo`
#include <cairo.h>
#include<stdio.h>
static cairo_t *get_surface(int width, int height)
{
cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cr = cairo_create (surface);
cairo_surface_destroy (surface);
return cr;
}
int main(void) {
cairo_t *cr = get_surface (400, 400);
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_paint (cr);
cairo_pattern_t *pat;
cairo_push_group(cr);
cairo_rectangle (cr, 0,0,100,100);
cairo_clip_preserve (cr);//try to limit the size to 100 px
cairo_set_source_rgb (cr,1,1,1);
cairo_stroke (cr); //Draw it.
pat = cairo_pop_group(cr); //record it.
cairo_set_source(cr,pat); //Just..
cairo_paint(cr); //show it anyway.
cairo_surface_t *surface;
cairo_pattern_get_surface (pat, &surface); //Get the surface of the pattern
//..and fail to get 100px as the width.
printf ("width: %d\n", cairo_image_surface_get_width (surface));
//Make a png for kicks.
cairo_surface_write_to_png (cairo_get_target (cr), "pat.png");
cairo_pattern_destroy(pat);
cairo_destroy(cr);
return 0;
}