Re: Bump: ImageSurface from a Pattern

Bill Spitzak <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
Try doing the clip before you do cairo_push_group?

On 12/11/2014 11:45 PM, Donn wrote:
> Hello list. It's heading for the weekend, so I'm gonna risk a bump
> before the quiet..
>
> In the C below, my intent is:
> 1. Draw a 100px rectangle.
> 2. Set it as a clip - so that the size will be 100px.
> 3. pop_group into 'pat' var.
> 4. Get the surface of that pattern.
> 5. Get the width of that surface (i.e. 100px)
>
> The code is giving me 400px - the size of the initial cr surface.
>
>
> I am making many patterns and keeping them in my objects. I am drawing
> from the pattern rather than re-drawing by cairo draw commands - for speed.
>
> I'd like to know if those patterns are the size I want them to be, not
> to mention keeping track of how much memory they are taking.
>
> If I draw a 10px by 10px circle, then the pattern *should* be 10px by
> 10px - not the size of the main window, for example.
>
>
> I hope someone can assist.
>
>
>
>
> C code pasted:
> ---------
> //gcc thiscode.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;
> }
>
> ---------
>
> Thanks,
> \d
>
-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.