diff --git a/fped.c b/fped.c index 8a840a6..1793676 100644 --- a/fped.c +++ b/fped.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "cpp.h" @@ -22,6 +23,7 @@ #include "obj.h" #include "inst.h" #include "file.h" +#include "postscript.h" #include "dump.h" #include "gui.h" #include "delete.h" @@ -65,14 +67,16 @@ static void load_file(const char *name) static void usage(const char *name) { fprintf(stderr, -"usage: %s [-k] [-p|-P] [-T [-T]] [cpp_option ...] [in_file [out_file]]\n\n" +"usage: %s [-k] [-p|-P [-s scale]] [-T [-T]] [cpp_option ...]\n" +" %*s [in_file [out_file]]\n\n" " -k write KiCad output, then exit\n" " -p write Postscript output, then exit\n" " -P write Postscript output (full page), then exit\n" +" -s scale scale factor for -P (default: auto-scale)\n" " -T test mode. Load file, then exit\n" " -T -T test mode. Load file, dump to stdout, then exit\n" " cpp_option -Idir, -Dname[=value], or -Uname\n" - , name); + , name, (int) strlen(name), ""); exit(1); } @@ -84,6 +88,7 @@ int main(int argc, char **argv) char *args[2]; int fake_argc; char opt[] = "-?"; + char *end; int error; int batch = 0; int test_mode = 0; @@ -91,7 +96,7 @@ int main(int argc, char **argv) int batch_write_ps = 0, batch_write_ps_fullpage = 0; int c; - while ((c = getopt(argc, argv, "kpD:I:PTU:")) != EOF) + while ((c = getopt(argc, argv, "kps:D:I:PTU:")) != EOF) switch (c) { case 'k': batch_write_kicad = 1; @@ -102,6 +107,13 @@ int main(int argc, char **argv) case 'P': batch_write_ps_fullpage = 1; break; + case 's': + if (!batch_write_ps_fullpage) + usage(*argv); + postscript_params.zoom = strtod(optarg, &end); + if (*end) + usage(*argv); + break; case 'T': batch = 1; test_mode++; diff --git a/postscript.c b/postscript.c index 7559a74..eff4c9e 100644 --- a/postscript.c +++ b/postscript.c @@ -88,6 +88,7 @@ struct postscript_params postscript_params = { + .zoom = 0, .show_pad_names = 1, .show_stuff = 0, .label_vecs = 0, @@ -1106,9 +1107,13 @@ static void ps_package_fullpage(FILE *file, const struct pkg *pkg, int page) bbox = inst_get_bbox(); cx = (bbox.min.x+bbox.max.x)/2; cy = (bbox.min.y+bbox.max.y)/2; - fx = 2.0*PAGE_HALF_WIDTH/(bbox.max.x-bbox.min.x); - fy = 2.0*PAGE_HALF_HEIGHT/(bbox.max.y-bbox.min.y); - f = fx < fy ? fx : fy; + if (active_params.zoom) + f = active_params.zoom; + else { + fx = 2.0*PAGE_HALF_WIDTH/(bbox.max.x-bbox.min.x); + fy = 2.0*PAGE_HALF_HEIGHT/(bbox.max.y-bbox.min.y); + f = fx < fy ? fx : fy; + } fprintf(file, "%d %d translate\n", (int) (-cx*f), (int) (-cy*f)); ps_draw_package(file, pkg, f); fprintf(file, "showpage\n"); diff --git a/postscript.h b/postscript.h index 9e9a971..0b5129c 100644 --- a/postscript.h +++ b/postscript.h @@ -1,5 +1,5 @@ /* - * ps.h - Dump objects in Postscript + * postscript.h - Dump objects in Postscript * * Written 2009, 2010 by Werner Almesberger * Copyright 2009, 2010 by Werner Almesberger @@ -23,7 +23,7 @@ struct postscript_params { int show_stuff; /* vecs and frames */ int label_vecs; int show_meas; -}; +} postscript_params; int postscript(FILE *file);