[cairo] Drawing a logo

Charles Doutriaux doutriaux1 at llnl.gov
Tue Nov 1 16:16:25 PDT 2011


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);
}





More information about the cairo mailing list