1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-23 05:48:06 +02:00

sch2fig/: new cairo options -o outfile.png and -s scale

This commit is contained in:
Werner Almesberger 2016-08-01 00:11:53 -03:00
parent 8590b960e9
commit d9eedec02a
3 changed files with 45 additions and 32 deletions

View File

@ -45,18 +45,16 @@ testref:
./$(NAME) test.lib test.sch | fig2dev -L png -m 2 >ref.png ./$(NAME) test.lib test.sch | fig2dev -L png -m 2 >ref.png
png: png:
./$(NAME) test.lib test.sch -- cairo ./$(NAME) test.lib test.sch -- cairo -o _out.png -s 2
[ ! -r pngref.png ] || \ [ ! -r pngref.png ] || \
compare -metric AE pngref.png test.png _diff.png || \ compare -metric AE pngref.png _out.png _diff.png || \
qiv -t -R -D _diff.png pngref.png test.png qiv -t -R -D _diff.png pngref.png _out.png
pngref: pngref:
./$(NAME) test.lib test.sch -- cairo ./$(NAME) test.lib test.sch -- cairo -o pngref.png -s 2
mv test.png pngref.png
clean:: clean::
rm -f out.fig _out.png _diff.png rm -f out.fig _out.png _diff.png
rm -f test.png
#----- Render Neo900 schematics ----------------------------------------------- #----- Render Neo900 schematics -----------------------------------------------

View File

@ -12,7 +12,9 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h>
#include <math.h> #include <math.h>
#include <cairo/cairo.h> #include <cairo/cairo.h>
@ -22,27 +24,9 @@
#include "text.h" #include "text.h"
#include "gfx.h" #include "gfx.h"
#include "layer.h" #include "layer.h"
#include "main.h"
#include "cairo.h" #include "cairo.h"
#if 0
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#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 * FIG works with 1/1200 in
@ -50,28 +34,43 @@ struct cairo_ctx {
* 1 point = 1/72 in * 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) 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) 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) 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) 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) static void *cr_init(int argc, char *const *argv)
{ {
struct cairo_ctx *cc; struct cairo_ctx *cc;
char c;
cc = alloc_type(struct cairo_ctx); cc = alloc_type(struct cairo_ctx);
cc->xo = cc->yo = 0; 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); layer_init(&cc->layer, &real_cairo_ops, cc);
/* cr_text_width needs *something* to work with */ /* cr_text_width needs *something* to work with */
@ -269,7 +283,8 @@ static void cr_end(void *ctx)
layer_replay(&cc->layer); layer_replay(&cc->layer);
layer_destroy(&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);
} }

View File

@ -46,7 +46,7 @@ void usage(const char *name)
" FIG driver spec:\n" " FIG driver spec:\n"
" fig [-t template.fig] [var=value ...]\n" " fig [-t template.fig] [var=value ...]\n"
" Cairo driver spec:\n" " Cairo driver spec:\n"
" cairo\n" " cairo [-o output.png] [-s scale]\n"
, name); , name);
exit(1); exit(1);
} }