From f9d9d432a8511172a75e0ebc12eb2ab32bb75b8d Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 4 Aug 2023 09:19:51 -0400 Subject: [PATCH] example.c: use transparent background. --- example.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/example.c b/example.c index d0b0af0..aa71e23 100644 --- a/example.c +++ b/example.c @@ -69,17 +69,19 @@ static void render_path(cairo_t* cr, shape_t* path) { } } if (path->fill != svgtiny_TRANSPARENT) { - cairo_set_source_rgb(cr, - svgtiny_RED(path->fill) / 255.0, - svgtiny_GREEN(path->fill) / 255.0, - svgtiny_BLUE(path->fill) / 255.0); + cairo_set_source_rgba(cr, + svgtiny_RED(path->fill) / 255.0, + svgtiny_GREEN(path->fill) / 255.0, + svgtiny_BLUE(path->fill) / 255.0, + 1); cairo_fill_preserve(cr); } if (path->stroke != svgtiny_TRANSPARENT) { - cairo_set_source_rgb(cr, - svgtiny_RED(path->stroke) / 255.0, - svgtiny_GREEN(path->stroke) / 255.0, - svgtiny_BLUE(path->stroke) / 255.0); + cairo_set_source_rgba(cr, + svgtiny_RED(path->stroke) / 255.0, + svgtiny_GREEN(path->stroke) / 255.0, + svgtiny_BLUE(path->stroke) / 255.0, + 1); cairo_set_line_width(cr, path->stroke_width); cairo_stroke_preserve(cr); } @@ -175,7 +177,7 @@ static cairo_t* cairo_context_from_diagram(diagram_t* diagram) { cairo_status_t crs; unsigned int i; - surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, + surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, diagram->width, diagram->height); @@ -203,7 +205,7 @@ static cairo_t* cairo_context_from_diagram(diagram_t* diagram) { return NULL; } - cairo_set_source_rgb(cr, 1, 1, 1); + cairo_set_source_rgba(cr, 0, 0, 0, 0); cairo_paint(cr); /* Loop through the shapes in the diagram... */ @@ -218,10 +220,11 @@ static cairo_t* cairo_context_from_diagram(diagram_t* diagram) { if (diagram->shape[i].text) { /* Figure out what color to use from the R/G/B components of the shape's stroke. */ - cairo_set_source_rgb(cr, - svgtiny_RED(diagram->shape[i].stroke) / 255.0, - svgtiny_GREEN(diagram->shape[i].stroke) / 255.0, - svgtiny_BLUE(diagram->shape[i].stroke) / 255.0); + cairo_set_source_rgba(cr, + svgtiny_RED(diagram->shape[i].stroke) / 255.0, + svgtiny_GREEN(diagram->shape[i].stroke) / 255.0, + svgtiny_BLUE(diagram->shape[i].stroke) / 255.0, + 1); /* Then move to the actual position of the text within the shape... */ cairo_move_to(cr, -- 2.43.2