// Example 1: Create a RefPtr to manage a new Cairo context and stroke a path #includeint main() { // Create new cairo context auto cr = cairo_create(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200, 200)); // Set stroke color to red cairo_set_source_rgb(cr, 1.0, 0.0, 0.0); // Move to initial point and draw path cairo_move_to(cr, 10, 10); cairo_line_to(cr, 50, 50); cairo_stroke(cr); // Destroy context and surface cairo_destroy(cr); return 0; }
// Example 2: Load an image file, create a surface with it, and stroke a path #includeIn this example, we use the cairomm library to load an image file and create a surface with it, which we then use to create a new Cairo context. We set the stroke color to blue and draw a path using the move_to and line_to member functions of the context object. Finally, we stroke the path using the stroke member function and destroy the context using the unique_ptr class.#include #include int main() { // Load image file auto surfaceImg = Cairo::ImageSurface::create_from_png("./image.png"); // Create new cairo context with image surface auto cr = Cairo::Context::create(surfaceImg); // Set stroke color to blue cr->set_source_rgb(0.0, 0.0, 1.0); // Move to initial point and draw path cr->move_to(10, 10); cr->line_to(50, 50); cr->stroke(); // Destroy context and surface cr.reset(); return 0; }