From 15bab1c163ddc7dd43ebd7107e8ada02e448ea86 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 1 Aug 2016 10:52:08 -0300 Subject: [PATCH] sch2fig/cairo.c: support dashed lines (for *_line); line width 2 also for PNG --- sch2fig/TODO | 1 - sch2fig/cairo.c | 23 +++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sch2fig/TODO b/sch2fig/TODO index f90f699..7b0b041 100644 --- a/sch2fig/TODO +++ b/sch2fig/TODO @@ -13,7 +13,6 @@ - find libraries (e.g., from .pro) - PDF TOC - let user set PNG size or zoom level -- implement dashed lines in cairo.c - directly pick versions out of git, without requiring checkout to file - handle differences - parse .kicad_wks diff --git a/sch2fig/cairo.c b/sch2fig/cairo.c index 42384ce..3444ebd 100644 --- a/sch2fig/cairo.c +++ b/sch2fig/cairo.c @@ -116,6 +116,21 @@ static void paint(cairo_t *cr, int color, int fill_color) /* ----- General items ----------------------------------------------------- */ +static void cr_line(void *ctx, int sx, int sy, int ex, int ey, + int color, unsigned layer) +{ + struct cairo_ctx *cc = ctx; + static const double dashes[] = { 4, 2 }; + + cairo_new_path(cc->cr); + cairo_move_to(cc->cr, cx(cc, sx), cy(cc, sy)); + cairo_line_to(cc->cr, cx(cc, ex), cy(cc, ey)); + cairo_set_dash(cc->cr, dashes, ARRAY_ELEMENTS(dashes), 0); + paint(cc->cr, color, COLOR_NONE); + cairo_set_dash(cc->cr, NULL, 0, 0); +} + + static void cr_poly(void *ctx, int points, const int x[points], const int y[points], int color, int fill_color, unsigned layer) @@ -217,7 +232,7 @@ static unsigned cr_text_width(void *ctx, const char *s, unsigned size) static const struct gfx_ops real_cairo_ops = { .name = "cairo", - // .line = cr_line, @@@ later + .line = cr_line, .poly = cr_poly, .circ = cr_circ, .arc = cr_arc, @@ -320,7 +335,7 @@ static void cr_png_end(void *ctx) cairo_select_font_face(cc->cr, "Helvetica", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_set_line_width(cc->cr, 3); + cairo_set_line_width(cc->cr, 2); layer_replay(&cc->layer); layer_destroy(&cc->layer); @@ -385,7 +400,7 @@ static void cr_pdf_end(void *ctx) const struct gfx_ops cairo_png_ops = { .name = "png", - // .line = cr_line, @@@ later + .line = layer_line, .poly = layer_poly, .circ = layer_circ, .arc = layer_arc, @@ -397,7 +412,7 @@ const struct gfx_ops cairo_png_ops = { const struct gfx_ops cairo_pdf_ops = { .name = "pdf", - // .line = cr_line, @@@ later + .line = layer_line, .poly = layer_poly, .circ = layer_circ, .arc = layer_arc,