Advertisement
ifoundthetao

Cairo Simple SVG Example

Sep 14th, 2012
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. #include "cairo.h"
  2. #include "cairo-svg.h"
  3. int main(int argc, char* argv[])
  4. {
  5.    double font_size = 25.0,
  6.           height    = 200.0,
  7.           left      = 15.0,
  8.           top       = 15.0,
  9.           width     = 200.0;
  10.  
  11.    char  filename[8]= "temp.svg",
  12.          *text      = "This is a Test";
  13.  
  14.    cairo_surface_t *surface = cairo_svg_surface_create(filename,
  15.                                                        width,
  16.                                                        height);
  17.  
  18.    //cairo_svg_surface_restrict_to_version (surface, CAIRO_SVG_VERSION_1_1);
  19.    cairo_t* cr = cairo_create (surface);
  20.  
  21.    int size = height * width;
  22.    int data[size];
  23.    
  24.    cairo_surface_t *text_surface = cairo_image_surface_create_for_data(data,
  25.                                                                        width,
  26.                                                                        height,
  27.                                                                        512*4);
  28.    cairo_set_source_surface(cr, text_surface, 0, 0);
  29.    cairo_paint(cr);
  30.    
  31.    cairo_move_to (cr, left, top);
  32.  
  33.    cairo_text_extents_t te;
  34.    cairo_select_font_face (cr,
  35.                            "Georgia",
  36.                            CAIRO_FONT_SLANT_NORMAL,
  37.                            CAIRO_FONT_WEIGHT_BOLD);
  38.                                  
  39.    cairo_set_font_size (cr, (double)font_size);
  40.    cairo_text_extents (cr, text, &te);
  41.    cairo_show_text (cr, text);
  42.  
  43.    cairo_fill(cr);
  44.      
  45.    return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement