1 /* M_PI is defined in math.h in the case of Microsoft Visual C++, Solaris,
2  * et. al.
3  */
4 #if defined(_MSC_VER)
5 #define _USE_MATH_DEFINES
6 #endif
7 
8 #include <string>
9 #include <iostream>
10 #include <cairommconfig.h>
11 #include <cairomm/context.h>
12 #include <cairomm/surface.h>
13 
14 #include <cmath>
15 
main()16 int main()
17 {
18 #ifdef CAIRO_HAS_SVG_SURFACE
19 
20     std::string filename = "image.svg";
21     double width = 600;
22     double height = 400;
23     auto surface =
24         Cairo::SvgSurface::create(filename, width, height);
25 
26     auto cr = Cairo::Context::create(surface);
27 
28     cr->save(); // save the state of the context
29     cr->set_source_rgb(0.86, 0.85, 0.47);
30     cr->paint();    // fill image with the color
31     cr->restore();  // color is back to black now
32 
33     cr->save();
34     // draw a border around the image
35     cr->set_line_width(20.0);    // make the line wider
36     cr->rectangle(0.0, 0.0, cairo_image_surface_get_width(surface->cobj()), height);
37     cr->stroke();
38 
39     cr->set_source_rgba(0.0, 0.0, 0.0, 0.7);
40     // draw a circle in the center of the image
41     cr->arc(width / 2.0, height / 2.0,
42             height / 4.0, 0.0, 2.0 * M_PI);
43     cr->stroke();
44 
45     // draw a diagonal line
46     cr->move_to(width / 4.0, height / 4.0);
47     cr->line_to(width * 3.0 / 4.0, height * 3.0 / 4.0);
48     cr->stroke();
49     cr->restore();
50 
51     cr->show_page();
52 
53     std::cout << "Wrote SVG file \"" << filename << "\"" << std::endl;
54     return 0;
55 
56 #else
57 
58     std::cout << "You must compile cairo with SVG support for this example to work."
59         << std::endl;
60     return 1;
61 
62 #endif
63 }
64