cairo samples

 arc
 arc_negative
 clip
 clip_image
 curve_rectangle
 curve_to
 fill_and_stroke2
 fill_and_stroke
 gradient
 image
 imagepattern
 libsvg
 operator_add
 operator_atop
 operator_atop_reverse
 operator_in
 operator_in_reverse
 operator_out
 operator_out_reverse
 operator_over
 operator_over_reverse
 operator_saturate
 operator_xor
 path
 set_line_cap
 set_line_join
 text_align_center
 text
 text_extents
 xxx_clip_rectangle
 xxx_dash
 xxx_long_lines
 xxx_multi_segment_caps
 xxx_self_intersect
prev
next
/* a custom shape, that could be wrapped in a function */
double x0     = 0.1,   /*< parameters like cairo_rectangle */
       y0     = 0.1,
       width  = 0.8,
       height = 0.8,
       radius = 0.4;   /*< and an approximate curvature radius */

double x1,y1;

x1=x0+width;
y1=y0+height;
if (!width || !height)
    return;
if (width/2<radius) {
    if (height/2<radius) {
        cairo_move_to  (cr, x0, (y0 + y1)/2);
        cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
        cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
        cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
        cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
    } else {
        cairo_move_to  (cr, x0, y0 + radius);
        cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
        cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
        cairo_line_to (cr, x1 , y1 - radius);
        cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
        cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
    }
} else {
    if (height/2<radius) {
        cairo_move_to  (cr, x0, (y0 + y1)/2);
        cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
        cairo_line_to (cr, x1 - radius, y0);
        cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
        cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
        cairo_line_to (cr, x0 + radius, y1);
        cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
    } else {
        cairo_move_to  (cr, x0, y0 + radius);
        cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
        cairo_line_to (cr, x1 - radius, y0);
        cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
        cairo_line_to (cr, x1 , y1 - radius);
        cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
        cairo_line_to (cr, x0 + radius, y1);
        cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
    }
}
cairo_close_path (cr);

/* and fill/stroke it */
cairo_save (cr);
    cairo_set_rgb_color (cr, 0.5,0.5,1);
    cairo_fill (cr);
cairo_restore (cr);
cairo_set_alpha (cr, 0.5);
cairo_set_rgb_color (cr, 0.5, 0,0);
cairo_stroke (cr);