summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-06 10:29:33 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-09-06 10:29:33 (GMT)
commit7236f343a616ecfe8f2379e8ce1618263359d947 (patch)
tree3fa06f3ec749a7ad20300b5c62d2ad8c51b3b57e /gfx
parent8fab1145d6bec466c68601522c0969161f02160a (diff)
downloadeeshow-7236f343a616ecfe8f2379e8ce1618263359d947.zip
eeshow-7236f343a616ecfe8f2379e8ce1618263359d947.tar.gz
eeshow-7236f343a616ecfe8f2379e8ce1618263359d947.tar.bz2
gfx/cro.c: add experimental SVG support
Diffstat (limited to 'gfx')
-rw-r--r--gfx/cro.c89
-rw-r--r--gfx/cro.h1
2 files changed, 90 insertions, 0 deletions
diff --git a/gfx/cro.c b/gfx/cro.c
index 4b86414..6bf527c 100644
--- a/gfx/cro.c
+++ b/gfx/cro.c
@@ -23,6 +23,7 @@
#include <cairo/cairo.h>
#include <cairo/cairo-pdf.h>
#include <cairo/cairo-ps.h>
+#include <cairo/cairo-svg.h>
#include <pango/pangocairo.h>
#include "misc/util.h"
@@ -809,6 +810,76 @@ static int cr_eps_end(void *ctx)
}
+/* ----- SVG (auto-sizing, using redraw) ----------------------------------- */
+
+
+static void *cr_svg_init(void)
+{
+ struct cro_ctx *cc = new_cc();
+
+ cc->scale *= 16;
+ cc->default_scale *= 16;
+
+ /* cr_text_width needs *something* to work with */
+
+ cc->s = cairo_svg_surface_create(NULL, 16, 16);
+ cc->cr = cairo_create(cc->s);
+ setup_font(cc);
+
+ return cc;
+}
+
+
+static int cr_svg_end(void *ctx)
+{
+ struct cro_ctx *cc = ctx;
+ int w, h;
+ unsigned i;
+
+ end_common(cc, &w, &h, NULL, NULL);
+
+ w = ((w + 15) >> 4) + ceil(0.5 * cc->scale);
+ h = ((h + 15) >> 4) + ceil(0.5 * cc->scale);
+
+ if (cc->output_name && strcmp(cc->output_name, "-"))
+ cc->s = cairo_svg_surface_create(cc->output_name, w, h);
+ else
+ cc->s = cairo_svg_surface_create_for_stream(stream_to_stdout,
+ NULL, w, h);
+ cc->cr = cairo_create(cc->s);
+
+ cairo_set_tolerance(cc->cr, 72 / 10000.0); // 0.1 mil
+ cairo_scale(cc->cr, 1.0 / 16.0, 1.0 / 16);
+ setup_font(cc);
+ cairo_set_line_width(cc->cr, 0.5 * cc->scale);
+ /* @@@ CAIRO_LINE_CAP_ROUND makes all non-dashed lines disappear */
+ cairo_set_line_cap(cc->cr, CAIRO_LINE_CAP_SQUARE);
+
+ for (i = 0; i != cc->n_sheets; i++) {
+ set_color(cc, COLOR_WHITE);
+ cairo_paint(cc->cr);
+
+ record_replay(cc->sheets + i);
+ record_destroy(cc->sheets + i);
+
+ cairo_show_page(cc->cr);
+ }
+
+ record_replay(&cc->record);
+ record_destroy(&cc->record);
+
+ cairo_show_page(cc->cr);
+
+ cairo_surface_destroy(cc->s);
+ cairo_destroy(cc->cr);
+
+ free(cc->sheets);
+ free(cc);
+
+ return 0;
+}
+
+
/* ----- PNG (auto-sizing, using redraw) ----------------------------------- */
@@ -1102,3 +1173,21 @@ const struct gfx_ops cro_eps_ops = {
.args = cr_ps_args,
.end = cr_eps_end,
};
+
+static const char *const cro_svg_ext[] = { "svg" };
+
+const struct gfx_ops cro_svg_ops = {
+ .ext = cro_svg_ext,
+ .n_ext = ARRAY_ELEMENTS(cro_svg_ext),
+ .opts = "o:s:",
+
+ .line = record_line,
+ .poly = record_poly,
+ .circ = record_circ,
+ .arc = record_arc,
+ .text = record_text,
+ .text_width = cr_text_width,
+ .init = cr_svg_init,
+ .args = cr_ps_args,
+ .end = cr_svg_end,
+};
diff --git a/gfx/cro.h b/gfx/cro.h
index 25725f1..8018e26 100644
--- a/gfx/cro.h
+++ b/gfx/cro.h
@@ -32,6 +32,7 @@ extern const struct gfx_ops cro_png_ops;
extern const struct gfx_ops cro_pdf_ops;
extern const struct gfx_ops cro_ps_ops;
extern const struct gfx_ops cro_eps_ops;
+extern const struct gfx_ops cro_svg_ops;
#define cro_img_ops cro_png_ops /* just don't call cro_img_ops.end */
#define cro_canvas_ops cro_png_ops /* just don't call cro_canvas_ops.end */