diff --git a/sch2fig/Makefile b/sch2fig/Makefile index 8d22805..7bcb47a 100644 --- a/sch2fig/Makefile +++ b/sch2fig/Makefile @@ -45,18 +45,16 @@ testref: ./$(NAME) test.lib test.sch | fig2dev -L png -m 2 >ref.png png: - ./$(NAME) test.lib test.sch -- cairo + ./$(NAME) test.lib test.sch -- cairo -o _out.png -s 2 [ ! -r pngref.png ] || \ - compare -metric AE pngref.png test.png _diff.png || \ - qiv -t -R -D _diff.png pngref.png test.png + compare -metric AE pngref.png _out.png _diff.png || \ + qiv -t -R -D _diff.png pngref.png _out.png pngref: - ./$(NAME) test.lib test.sch -- cairo - mv test.png pngref.png + ./$(NAME) test.lib test.sch -- cairo -o pngref.png -s 2 clean:: rm -f out.fig _out.png _diff.png - rm -f test.png #----- Render Neo900 schematics ----------------------------------------------- diff --git a/sch2fig/cairo.c b/sch2fig/cairo.c index 5027537..94bf8d7 100644 --- a/sch2fig/cairo.c +++ b/sch2fig/cairo.c @@ -12,7 +12,9 @@ #include +#include #include +#include #include #include @@ -22,27 +24,9 @@ #include "text.h" #include "gfx.h" #include "layer.h" +#include "main.h" #include "cairo.h" -#if 0 -#include -#include -#include - -#include "util.h" -#include "style.h" -#include "text.h" -#include "fig.h" -#endif - - -struct cairo_ctx { - struct layer layer; /* must be first */ - int xo, yo; - int scale; - cairo_t *cr; - cairo_surface_t *s; -}; /* * FIG works with 1/1200 in @@ -50,28 +34,43 @@ struct cairo_ctx { * 1 point = 1/72 in */ +#define DEFAULT_SCALE (72.0 / 1200) + + +struct cairo_ctx { + struct layer layer; /* must be first */ + + int xo, yo; + float scale; + + cairo_t *cr; + cairo_surface_t *s; + + const char *output_name; +}; + static inline int cd(struct cairo_ctx *cc, int x) { - return x / cc->scale; + return x * cc->scale; } static inline int cx(struct cairo_ctx *cc, int x) { - return cc->xo + x / cc->scale; + return cc->xo + x * cc->scale; } static inline int xc(struct cairo_ctx *cc, int x) { - return (x - cc->xo) * cc->scale; + return (x - cc->xo) / cc->scale; } static inline int cy(struct cairo_ctx *cc, int y) { - return cc->yo + y / cc->scale; + return cc->yo + y * cc->scale; } @@ -224,10 +223,25 @@ static const struct gfx_ops real_cairo_ops = { static void *cr_init(int argc, char *const *argv) { struct cairo_ctx *cc; + char c; cc = alloc_type(struct cairo_ctx); cc->xo = cc->yo = 0; - cc->scale = 5; + cc->scale = DEFAULT_SCALE; + + cc->output_name = NULL; + while ((c = getopt(argc, argv, "o:s:")) != EOF) + switch (c) { + case 'o': + cc->output_name = optarg; + break; + case 's': + cc->scale = atof(optarg) * DEFAULT_SCALE; + break; + default: + usage(*argv); + } + layer_init(&cc->layer, &real_cairo_ops, cc); /* cr_text_width needs *something* to work with */ @@ -269,7 +283,8 @@ static void cr_end(void *ctx) layer_replay(&cc->layer); layer_destroy(&cc->layer); - cairo_surface_write_to_png(cc->s, "test.png"); + if (cc->output_name) + cairo_surface_write_to_png(cc->s, cc->output_name); } diff --git a/sch2fig/main.c b/sch2fig/main.c index a8438e4..0a0d5d1 100644 --- a/sch2fig/main.c +++ b/sch2fig/main.c @@ -46,7 +46,7 @@ void usage(const char *name) " FIG driver spec:\n" " fig [-t template.fig] [var=value ...]\n" " Cairo driver spec:\n" -" cairo\n" +" cairo [-o output.png] [-s scale]\n" , name); exit(1); }