From 1c01bc3c2a98c9e39bcf13729c8dd9e8cea4553d Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Thu, 12 Jul 2012 18:16:54 -0300 Subject: [PATCH] new use of option -s (scaling): -s [width]x[heigth] The new scaling variants set the maximum size in one or both directions. If one of the sizes is omitted, the default paper size is assumed. --- fped.c | 34 +++++++++++++++++++++++++++++----- postscript.c | 11 +++++++++-- postscript.h | 8 +++++--- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/fped.c b/fped.c index 1eba208..1dbb7b4 100644 --- a/fped.c +++ b/fped.c @@ -1,8 +1,8 @@ /* * fped.c - Footprint editor, main function * - * Written 2009-2011 by Werner Almesberger - * Copyright 2009-2011 by Werner Almesberger + * Written 2009-2012 by Werner Almesberger + * Copyright 2009-2012 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -80,12 +80,38 @@ static void usage(const char *name) "Common options:\n" " -1 name output only the specified package\n" " -s scale scale factor for -P (default: auto-scale)\n" +" -s [width]x[heigth]\n" +" auto-scale to fit within specified box. Dimensions in mm.\n" " cpp_option -Idir, -Dname[=value], or -Uname\n" , name); exit(1); } +static int parse_scaling(const char *arg) +{ + const char *x; + char *end; + + x = strchr(arg, 'x'); + if (!x) { + postscript_params.zoom = strtod(arg, &end); + return !*end; + } + if (x != arg) { + postscript_params.max_width = mm_to_units(strtod(arg, &end)); + if (*end != 'x') + return 0; + } + if (x[1]) { + postscript_params.max_height = mm_to_units(strtod(x+1, &end)); + if (*end) + return 0; + } + return 1; +} + + int main(int argc, char **argv) { enum { @@ -101,7 +127,6 @@ int main(int argc, char **argv) char *args[2]; int fake_argc; char opt[] = "-?"; - char *end; int error; int test_mode = 0; const char *one = NULL; @@ -135,8 +160,7 @@ int main(int argc, char **argv) case 's': if (batch != batch_ps_fullpage) usage(*argv); - postscript_params.zoom = strtod(optarg, &end); - if (*end) + if (!parse_scaling(optarg)) usage(*argv); break; case 'T': diff --git a/postscript.c b/postscript.c index 5b71b67..7eed5a8 100644 --- a/postscript.c +++ b/postscript.c @@ -93,6 +93,8 @@ struct postscript_params postscript_params = { .zoom = 0, + .max_width = 0, + .max_height = 0, .show_pad_names = 1, .show_stuff = 0, .label_vecs = 0, @@ -1129,6 +1131,7 @@ static void ps_package_fullpage(FILE *file, const struct pkg *pkg, int page) unit_type cx, cy; struct bbox bbox; double fx, fy, f; + double d; ps_page(file, page, pkg); active_params = postscript_params; @@ -1138,8 +1141,12 @@ static void ps_package_fullpage(FILE *file, const struct pkg *pkg, int page) 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); + d = active_params.max_width ? active_params.max_width : + 2.0*PAGE_HALF_WIDTH; + fx = d/(bbox.max.x-bbox.min.x); + d = active_params.max_height ? active_params.max_height : + 2.0*PAGE_HALF_HEIGHT; + fy = d/(bbox.max.y-bbox.min.y); f = fx < fy ? fx : fy; } fprintf(file, "%d %d translate\n", (int) (-cx*f), (int) (-cy*f)); diff --git a/postscript.h b/postscript.h index cf6dfba..f0f8b4c 100644 --- a/postscript.h +++ b/postscript.h @@ -1,8 +1,8 @@ /* * postscript.h - Dump objects in Postscript * - * Written 2009-2011 by Werner Almesberger - * Copyright 2009-2011 by Werner Almesberger + * Written 2009-2012 by Werner Almesberger + * Copyright 2009-2012 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,9 @@ struct postscript_params { - double zoom; + double zoom; /* 0 for auto-zoom */ + double max_width; /* in fped units; 0 for paper width */ + double max_height; /* in fped units; 0 for paper height */ int show_pad_names; int show_stuff; /* vecs and frames */ int label_vecs;