#include #include #include int main( int argc, char *argv[] ) { cairo_t *cr = NULL; cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1280, 720); double x1, y1, x2, y2; cr = cairo_create(surface); cairo_new_path( cr ); cairo_reset_clip( cr ); /* Starting clip rect */ cairo_rectangle( cr, 607, 38, 491, 48 ); cairo_set_fill_rule( cr, CAIRO_FILL_RULE_EVEN_ODD ); cairo_set_antialias( cr, CAIRO_ANTIALIAS_NONE ); cairo_clip( cr ); #if 1 /* Set outer rounded border clip */ cairo_move_to( cr, 1011, 74 ); cairo_line_to( cr, 1161, 74 ); cairo_curve_to( cr, 1163.76, 74, 1166, 76.24, 1166, 79 ); cairo_line_to( cr, 1166, 89 ); cairo_curve_to( cr, 1166, 91.76, 1163.76, 94, 1161, 94 ); cairo_line_to( cr, 1011, 94 ); cairo_curve_to( cr, 1008.24, 94, 1006, 91.76, 1006, 89 ); cairo_line_to( cr, 1006, 79 ); cairo_curve_to( cr, 1006, 76.24, 1008.24, 74, 1011, 74 ); cairo_close_path( cr ); cairo_set_fill_rule( cr, CAIRO_FILL_RULE_EVEN_ODD ); cairo_clip( cr ); #endif #if 1 /* Get current clip and add to path */ cairo_clip_extents( cr, &x1, &y1, &x2, &y2 ); cairo_rectangle( cr, x1, y1, x2 - x1, y2 - y1 ); /* Set inner rounded border clip - Append inner rounded rect to path, creating ring shape */ cairo_move_to( cr, 1011, 76 ); cairo_line_to( cr, 1161, 76 ); cairo_curve_to( cr, 1162.66, 76, 1164, 77.34, 1164, 79 ); cairo_line_to( cr, 1164, 89 ); cairo_curve_to( cr, 1164, 90.66, 1162.66, 92, 1161, 92 ); cairo_line_to( cr, 1011, 92 ); cairo_curve_to( cr, 1009.34, 92, 1008, 90.66, 1008, 89 ); cairo_line_to( cr, 1008, 79 ); cairo_curve_to( cr, 1008, 77.34, 1009.34, 76, 1011, 76 ); cairo_close_path( cr ); cairo_set_fill_rule( cr, CAIRO_FILL_RULE_EVEN_ODD ); cairo_clip( cr ); #endif #if 1 /* Add bottom polygon (1) to clip, this should of clip out everything */ cairo_new_path( cr ); cairo_set_antialias( cr, CAIRO_ANTIALIAS_NONE ); cairo_set_fill_rule( cr, CAIRO_FILL_RULE_WINDING ); cairo_move_to( cr, 1006, 94 ); cairo_line_to( cr, 1016, 84 ); cairo_line_to( cr, 1166, 84 ); cairo_line_to( cr, 1166, 94 ); cairo_close_path( cr ); cairo_clip( cr ); #endif #if 1 /* Add bottom polygon (2) to clip */ cairo_new_path( cr ); #if 1 // Bug cairo_set_antialias( cr, CAIRO_ANTIALIAS_DEFAULT ); #else // No bug cairo_set_antialias( cr, CAIRO_ANTIALIAS_NONE ); #endif cairo_set_fill_rule( cr, CAIRO_FILL_RULE_WINDING ); cairo_move_to( cr, 1006, 94 ); cairo_line_to( cr, 1006, 84 ); cairo_line_to( cr, 1156, 84 ); cairo_line_to( cr, 1166, 94 ); cairo_close_path( cr ); cairo_clip( cr ); #endif /* Fill color */ cairo_set_fill_rule( cr, CAIRO_FILL_RULE_WINDING ); cairo_set_source_rgba( cr, 1.0, 0.3, 0.3, 1.0 ); cairo_rectangle( cr, 0, 0, 1280, 720 ); cairo_fill( cr ); /* Save to PNG and clean up */ cairo_surface_write_to_png(surface, "result.png"); cairo_destroy(cr); cairo_surface_destroy(surface); return 0; }