mirror of
git://projects.qi-hardware.com/fped.git
synced 2024-12-23 04:43:21 +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:
parent
86c082f5a9
commit
1c01bc3c2a
34
fped.c
34
fped.c
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* fped.c - Footprint editor, main function
|
* fped.c - Footprint editor, main function
|
||||||
*
|
*
|
||||||
* Written 2009-2011 by Werner Almesberger
|
* Written 2009-2012 by Werner Almesberger
|
||||||
* Copyright 2009-2011 by Werner Almesberger
|
* Copyright 2009-2012 by Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* 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"
|
"Common options:\n"
|
||||||
" -1 name output only the specified package\n"
|
" -1 name output only the specified package\n"
|
||||||
" -s scale scale factor for -P (default: auto-scale)\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"
|
" cpp_option -Idir, -Dname[=value], or -Uname\n"
|
||||||
, name);
|
, name);
|
||||||
exit(1);
|
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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
enum {
|
enum {
|
||||||
@ -101,7 +127,6 @@ int main(int argc, char **argv)
|
|||||||
char *args[2];
|
char *args[2];
|
||||||
int fake_argc;
|
int fake_argc;
|
||||||
char opt[] = "-?";
|
char opt[] = "-?";
|
||||||
char *end;
|
|
||||||
int error;
|
int error;
|
||||||
int test_mode = 0;
|
int test_mode = 0;
|
||||||
const char *one = NULL;
|
const char *one = NULL;
|
||||||
@ -135,8 +160,7 @@ int main(int argc, char **argv)
|
|||||||
case 's':
|
case 's':
|
||||||
if (batch != batch_ps_fullpage)
|
if (batch != batch_ps_fullpage)
|
||||||
usage(*argv);
|
usage(*argv);
|
||||||
postscript_params.zoom = strtod(optarg, &end);
|
if (!parse_scaling(optarg))
|
||||||
if (*end)
|
|
||||||
usage(*argv);
|
usage(*argv);
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
|
11
postscript.c
11
postscript.c
@ -93,6 +93,8 @@
|
|||||||
|
|
||||||
struct postscript_params postscript_params = {
|
struct postscript_params postscript_params = {
|
||||||
.zoom = 0,
|
.zoom = 0,
|
||||||
|
.max_width = 0,
|
||||||
|
.max_height = 0,
|
||||||
.show_pad_names = 1,
|
.show_pad_names = 1,
|
||||||
.show_stuff = 0,
|
.show_stuff = 0,
|
||||||
.label_vecs = 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;
|
unit_type cx, cy;
|
||||||
struct bbox bbox;
|
struct bbox bbox;
|
||||||
double fx, fy, f;
|
double fx, fy, f;
|
||||||
|
double d;
|
||||||
|
|
||||||
ps_page(file, page, pkg);
|
ps_page(file, page, pkg);
|
||||||
active_params = postscript_params;
|
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) {
|
if (active_params.zoom) {
|
||||||
f = active_params.zoom;
|
f = active_params.zoom;
|
||||||
} else {
|
} else {
|
||||||
fx = 2.0*PAGE_HALF_WIDTH/(bbox.max.x-bbox.min.x);
|
d = active_params.max_width ? active_params.max_width :
|
||||||
fy = 2.0*PAGE_HALF_HEIGHT/(bbox.max.y-bbox.min.y);
|
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;
|
f = fx < fy ? fx : fy;
|
||||||
}
|
}
|
||||||
fprintf(file, "%d %d translate\n", (int) (-cx*f), (int) (-cy*f));
|
fprintf(file, "%d %d translate\n", (int) (-cx*f), (int) (-cy*f));
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* postscript.h - Dump objects in Postscript
|
* postscript.h - Dump objects in Postscript
|
||||||
*
|
*
|
||||||
* Written 2009-2011 by Werner Almesberger
|
* Written 2009-2012 by Werner Almesberger
|
||||||
* Copyright 2009-2011 by Werner Almesberger
|
* Copyright 2009-2012 by Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -18,7 +18,9 @@
|
|||||||
|
|
||||||
|
|
||||||
struct postscript_params {
|
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_pad_names;
|
||||||
int show_stuff; /* vecs and frames */
|
int show_stuff; /* vecs and frames */
|
||||||
int label_vecs;
|
int label_vecs;
|
||||||
|
Loading…
Reference in New Issue
Block a user