From d80869b6422fc0d3541b8f2750e2f8deaaf38f4e Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Thu, 9 May 2013 20:07:42 +0100 Subject: svgwrite: First attempt at an SVG output device. No font support (just font names are sent through). No group support. No shading support. No image mask support. Line art, text position/size, bitmaps, clipping all seem to work though. --- apps/mudraw.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'apps') diff --git a/apps/mudraw.c b/apps/mudraw.c index 0b99114d..efc06f25 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -12,7 +12,7 @@ enum { TEXT_PLAIN = 1, TEXT_HTML = 2, TEXT_XML = 3 }; -enum { OUT_PNG, OUT_PPM, OUT_PNM, OUT_PAM, OUT_PGM, OUT_PBM }; +enum { OUT_PNG, OUT_PPM, OUT_PNM, OUT_PAM, OUT_PGM, OUT_PBM, OUT_SVG }; typedef struct { @@ -28,6 +28,7 @@ static const suffix_t suffix_table[] = { ".pnm", OUT_PNM }, { ".pam", OUT_PAM }, { ".pbm", OUT_PBM }, + { ".svg", OUT_SVG }, }; /* @@ -423,7 +424,53 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) if (showmd5 || showtime) printf("page %s %d", filename, pagenum); - if (output || showmd5 || showtime) + if (output && output_format == OUT_SVG) + { + float zoom; + fz_matrix ctm; + fz_rect bounds, tbounds; + char buf[512]; + FILE *file; + fz_output *out; + + sprintf(buf, output, pagenum); + file = fopen(buf, "wb"); + if (file == NULL) + fz_throw(ctx, "cannot open file '%s': %s", buf, strerror(errno)); + out = fz_new_output_with_file(ctx, file); + + fz_bound_page(doc, page, &bounds); + zoom = resolution / 72; + fz_pre_rotate(fz_scale(&ctm, zoom, zoom), rotation); + tbounds = bounds; + fz_transform_rect(&tbounds, &ctm); + + fz_try(ctx) + { + dev = fz_new_svg_device(ctx, out, tbounds.x1-tbounds.x0, tbounds.y1-tbounds.y0); + if (list) + fz_run_display_list(list, dev, &ctm, &tbounds, &cookie); + else + fz_run_page(doc, page, dev, &ctm, &cookie); + fz_free_device(dev); + dev = NULL; + } + fz_always(ctx) + { + fz_free_device(dev); + dev = NULL; + fz_close_output(out); + fclose(file); + } + fz_catch(ctx) + { + fz_free_display_list(ctx, list); + fz_free_page(doc, page); + fz_rethrow(ctx); + } + } + + if ((output && output_format != OUT_SVG)|| showmd5 || showtime) { float zoom; fz_matrix ctm; -- cgit v1.2.3