1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-12-22 23:41:10 +02:00

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.
This commit is contained in:
Werner Almesberger 2012-07-12 18:16:54 -03:00
parent 86c082f5a9
commit 1c01bc3c2a
3 changed files with 43 additions and 10 deletions

34
fped.c
View File

@ -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':

View File

@ -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));

View File

@ -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;