X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=example.c;h=aa71e233cee108f95056f3d6d9edd18371c5fbb2;hb=f9d9d432a8511172a75e0ebc12eb2ab32bb75b8d;hp=7c69182f1e0e914aa84b1e2b22ab97ffe0f96fc1;hpb=64e09f16a76b3bc808bf1fe224f6efeb8c7963d1;p=libsvgtiny-pixbuf.git diff --git a/example.c b/example.c index 7c69182..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, @@ -284,18 +287,21 @@ int main(int argc, char** argv) { return 1; } - /* We're using the diagram width and height and not the viewport - * width/height for the image. This has the potential to create an - * image with a different size and aspect ratio than the viewport, - * but since our viewport is entirely made-up... I don't know. This - * relies on libsvgtiny being good at scaling/stretching/etc an SVG - * that may only have partial width/height/viewBox information. + /* We're using the viewport width and height and not the diagram + * width/height for the image. The diagram can be of a different + * size and aspect ratio than the viewport, and our main use case is + * for icons that are generally square and reasonably sized. If the + * diagram is "small," then we want to scale it up until it fits + * nicely in the viewport before rendering it. That's as opposed to + * rendering the image small, and letting GDK scale it up. Of course + * this reasoning makes the assumption that the viewport is usually + * larger than the diagram. */ pb = gdk_pixbuf_get_from_surface(cairo_get_target(cr), 0, 0, - diagram->width, - diagram->height); + VIEWPORT_WIDTH, + VIEWPORT_HEIGHT); if (pb) { @@ -324,18 +330,22 @@ static GdkPixbuf* gdk_pixbuf_from_svg_file_stream(FILE *fp, GError **error) { return NULL; } - /* We're using the diagram width and height and not the viewport - * width/height for the image. This has the potential to create an - * image with a different size and aspect ratio than the viewport, - * but since our viewport is entirely made-up... I don't know. This - * relies on libsvgtiny being good at scaling/stretching/etc an SVG - * that may only have partial width/height/viewBox information. - */ + + /* We're using the viewport width and height and not the diagram + * width/height for the image. The diagram can be of a different + * size and aspect ratio than the viewport, and our main use case is + * for icons that are generally square and reasonably sized. If the + * diagram is "small," then we want to scale it up until it fits + * nicely in the viewport before rendering it. That's as opposed to + * rendering the image small, and letting GDK scale it up. Of course + * this reasoning makes the assumption that the viewport is usually + * larger than the diagram. + */ pb = gdk_pixbuf_get_from_surface(cairo_get_target(cr), 0, 0, - diagram->width, - diagram->height); + VIEWPORT_WIDTH, + VIEWPORT_HEIGHT); if (!pb) {