Guest User

Cairo Text Example

a guest
Jan 31st, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <cairo.h>
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. #define SIZEX 1000
  9. #define SIZEY  500
  10.  
  11. void paint(cairo_surface_t *cs)
  12. {
  13.     cairo_t *c;
  14.  
  15.     c=cairo_create(cs);
  16.  
  17.     cairo_rectangle(c, 0.0, 0.0, SIZEX, SIZEY);
  18.     cairo_set_source_rgb(c, 0.0, 0.0, 0.5);
  19.     cairo_fill(c);
  20.  
  21.     cairo_move_to(c, 100.0, 100.0);
  22.     cairo_set_source_rgb(c, 1.0, 1.0, 0.0);
  23.     cairo_select_font_face (c, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
  24.     cairo_set_font_size (c, 52.0);
  25.     cairo_show_text(c, "Hello World!");
  26.  
  27.     cairo_move_to(c, 200.0, 200.0);
  28.     cairo_set_source_rgb(c, 1.0, 1.0, 0.0);
  29.     cairo_select_font_face (c, "Courier", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
  30.     cairo_set_font_size (c, 52.0);
  31.     cairo_show_text(c, "Hello World!");
  32.  
  33.     cairo_move_to(c, 300.0, 300.0);
  34.     cairo_set_source_rgb(c, 1.0, 1.0, 0.0);
  35.     cairo_select_font_face (c, "Arial", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
  36.     cairo_set_font_size (c, 52.0);
  37.     cairo_show_text(c, "Hello World!");
  38.        
  39.     cairo_show_page(c);
  40.  
  41.     cairo_destroy(c);
  42. }
  43.  
  44.  
  45. void writepng(const char *fname)
  46. {
  47.     cairo_surface_t *cs;
  48.  
  49.     cs=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, SIZEX, SIZEY);
  50.  
  51.     paint(cs);
  52.  
  53.     cairo_surface_write_to_png(cs, fname);
  54.     cairo_surface_destroy(cs);
  55. }
  56.  
  57.  
  58. int main() {
  59.        
  60.     writepng("image.png");
  61. }
Advertisement
Add Comment
Please, Sign In to add comment