#include <string.h>
#include <cairo.h>
#include <cairo-svg.h>

void example (char *name);

int main (int argc, char *argv[])
{
	example ("clear");

	example ("source");
	example ("over");
	example ("in");
	example ("out");
	example ("atop");

	example ("dest");
	example ("dest_over");
	example ("dest_in");
	example ("dest_out");
	example ("dest_atop");

	example ("xor");
	example ("add");
	example ("saturate");

        return 0;
}

void example (char *name)
{
        cairo_surface_t *surface;
        cairo_t *cr;

	char svg_filename[50];
        char png_filename[50];
        strcpy (svg_filename, name);
        strcpy (png_filename, name);
        strcat (svg_filename, ".svg");
        strcat (png_filename, ".png");

        surface = cairo_svg_surface_create (svg_filename, 160, 120);
        cr = cairo_create (surface);
	
	cairo_rectangle (cr, 0, 0, 120, 90);
	cairo_set_source_rgba (cr, 0.7, 0, 0, 0.8);
	cairo_fill (cr);

	if (strcmp(name, "clear") == 0)
		cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);

	else if (strcmp(name, "source") == 0)
		cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
	else if (strcmp(name, "over") == 0)
		cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
	else if (strcmp(name, "in") == 0)
		cairo_set_operator (cr, CAIRO_OPERATOR_IN);
	else if (strcmp(name, "out") == 0)
		cairo_set_operator (cr, CAIRO_OPERATOR_OUT);
	else if (strcmp(name, "atop") == 0)
		cairo_set_operator (cr, CAIRO_OPERATOR_ATOP);

	else if (strcmp(name, "dest") == 0)
		cairo_set_operator (cr, CAIRO_OPERATOR_DEST);
	else if (strcmp(name, "dest_over") == 0)
		cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
	else if (strcmp(name, "dest_in") == 0)
		cairo_set_operator (cr, CAIRO_OPERATOR_DEST_IN);
	else if (strcmp(name, "dest_out") == 0)
		cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OUT);
	else if (strcmp(name, "dest_atop") == 0)
		cairo_set_operator (cr, CAIRO_OPERATOR_DEST_ATOP);

	else if (strcmp(name, "xor") == 0)
		cairo_set_operator (cr, CAIRO_OPERATOR_XOR);
	else if (strcmp(name, "add") == 0)
		cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
	else if (strcmp(name, "saturate") == 0)
		cairo_set_operator (cr, CAIRO_OPERATOR_SATURATE);

	cairo_rectangle (cr, 40, 30, 120, 90);
	cairo_set_source_rgba (cr, 0, 0, 0.9, 0.4);
	cairo_fill (cr);

        cairo_destroy (cr);
        cairo_surface_write_to_png (surface, png_filename);
        cairo_surface_destroy (surface);
}
