[cairo] Drawing a logo
Charles Doutriaux
doutriaux1 at llnl.gov
Tue Nov 1 17:06:33 PDT 2011
The following does the trick for me:
void draw_logo(cairo_t *cr) {
int w,h,wl,hl;
float ratio = .075;
float ws,hs,x,y;
cairo_surface_t *logo;
logo =
cairo_image_surface_create_from_png("/lgm/cdat/Qt/Library/Frameworks/Python.framework/Versions/2.7/bin/UV-CDAT_logo_sites.png");
wl=cairo_image_surface_get_width(logo);
hl=cairo_image_surface_get_height(logo);
w=cairo_image_surface_get_width(cairo_get_target(cr));
h=cairo_image_surface_get_height(cairo_get_target(cr));
fprintf(stderr,"ratio is: %f, %f,
%f\n",ratio,(float)w*ratio,(float)h*ratio);
x=(float)w*(1.-ratio);
y= (float)h*(1.-ratio);
cairo_rectangle(cr,x,y,(float)w*ratio,(float)h*ratio);
cairo_clip(cr);
hs = (float)h*ratio/(float)hl;
ws=(float)w*ratio/(float)wl;
cairo_scale(cr,ws,hs);
cairo_set_source_surface(cr,logo,x/ws,y/hs);
cairo_paint(cr);
}
C.
On 11/1/11 4:16 PM, Charles Doutriaux wrote:
> Hello,
>
> I am running into a "simple" problem and I can't seem to figure it out
> from the doc.
>
> I have a cairo_t cr on which I drew a bunch of things.
>
>
> Now I would like at the end to add a logo/stamp in the bottom right corner.
>
> I can't seem to be able to "scale" the logo down to the right size, the
> following code will draw the logo at the right place but if I put the
> scaling in the will only scale the "rectangle" down therefore still only
> showing about a 1/4 of the logo.
>
> Hope somebody can help!
>
> Thanks in advance,
>
> C.
>
> void draw_logo(cairo_t *cr) {
> int w,h,wl,hl;
> float ratio = .25;
> cairo_surface_t *logo;
> logo =
> cairo_image_surface_create_from_png("/lgm/cdat/Qt/Library/Frameworks/Python.framework/Versions/2.7/bin/UV-CDAT_logo_sites.png");
> wl=cairo_image_surface_get_width(logo);
> hl=cairo_image_surface_get_height(logo);
> w=cairo_image_surface_get_width(cairo_get_target(cr));
> h=cairo_image_surface_get_height(cairo_get_target(cr));
> fprintf(stderr,"ratio is: %f, %f,
> %f\n",ratio,(float)w*ratio,(float)h*ratio);
> //cairo_scale(cr,(float)w*ratio/(float)wl,(float)h*ratio/(float)hl);
>
> cairo_set_source_surface(cr,logo,(float)w*(1.-ratio),(float)h*(1.-ratio));
>
> cairo_rectangle(cr,(float)w*(1.-ratio),(float)h*(1.-ratio),(float)w*ratio,(float)h*ratio);
> cairo_clip(cr);
> cairo_paint(cr);
> }
>
>
>
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
More information about the cairo
mailing list