1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-22 08:51:53 +02:00

New option "-s scale" to set the exact scale factor for full-page Postscript

output.

- postscript.h (postscript_params): didn't declare this global variable
- postscript.c (ps_package_fullpage): if postscript_params.zoom is non-zero,
  scale to this value (instead of auto-scaling) 
- fped.c (usage, main): added option "-s scale" to set the scale factor for -P



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5954 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
werner 2010-05-03 13:41:24 +00:00
parent 24011c74d6
commit 8e60952ba1
3 changed files with 25 additions and 8 deletions

18
fped.c
View File

@ -14,6 +14,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include <errno.h> #include <errno.h>
#include "cpp.h" #include "cpp.h"
@ -22,6 +23,7 @@
#include "obj.h" #include "obj.h"
#include "inst.h" #include "inst.h"
#include "file.h" #include "file.h"
#include "postscript.h"
#include "dump.h" #include "dump.h"
#include "gui.h" #include "gui.h"
#include "delete.h" #include "delete.h"
@ -65,14 +67,16 @@ static void load_file(const char *name)
static void usage(const char *name) static void usage(const char *name)
{ {
fprintf(stderr, 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" " -k write KiCad output, then exit\n"
" -p write Postscript output, then exit\n" " -p write Postscript output, then exit\n"
" -P write Postscript output (full page), 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 test mode. Load file, then exit\n"
" -T -T test mode. Load file, dump to stdout, then exit\n" " -T -T test mode. Load file, dump to stdout, then exit\n"
" cpp_option -Idir, -Dname[=value], or -Uname\n" " cpp_option -Idir, -Dname[=value], or -Uname\n"
, name); , name, (int) strlen(name), "");
exit(1); exit(1);
} }
@ -84,6 +88,7 @@ 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 batch = 0; int batch = 0;
int test_mode = 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 batch_write_ps = 0, batch_write_ps_fullpage = 0;
int c; int c;
while ((c = getopt(argc, argv, "kpD:I:PTU:")) != EOF) while ((c = getopt(argc, argv, "kps:D:I:PTU:")) != EOF)
switch (c) { switch (c) {
case 'k': case 'k':
batch_write_kicad = 1; batch_write_kicad = 1;
@ -102,6 +107,13 @@ int main(int argc, char **argv)
case 'P': case 'P':
batch_write_ps_fullpage = 1; batch_write_ps_fullpage = 1;
break; break;
case 's':
if (!batch_write_ps_fullpage)
usage(*argv);
postscript_params.zoom = strtod(optarg, &end);
if (*end)
usage(*argv);
break;
case 'T': case 'T':
batch = 1; batch = 1;
test_mode++; test_mode++;

View File

@ -88,6 +88,7 @@
struct postscript_params postscript_params = { struct postscript_params postscript_params = {
.zoom = 0,
.show_pad_names = 1, .show_pad_names = 1,
.show_stuff = 0, .show_stuff = 0,
.label_vecs = 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(); bbox = inst_get_bbox();
cx = (bbox.min.x+bbox.max.x)/2; cx = (bbox.min.x+bbox.max.x)/2;
cy = (bbox.min.y+bbox.max.y)/2; cy = (bbox.min.y+bbox.max.y)/2;
fx = 2.0*PAGE_HALF_WIDTH/(bbox.max.x-bbox.min.x); if (active_params.zoom)
fy = 2.0*PAGE_HALF_HEIGHT/(bbox.max.y-bbox.min.y); f = active_params.zoom;
f = fx < fy ? fx : fy; 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)); fprintf(file, "%d %d translate\n", (int) (-cx*f), (int) (-cy*f));
ps_draw_package(file, pkg, f); ps_draw_package(file, pkg, f);
fprintf(file, "showpage\n"); fprintf(file, "showpage\n");

View File

@ -1,5 +1,5 @@
/* /*
* ps.h - Dump objects in Postscript * postscript.h - Dump objects in Postscript
* *
* Written 2009, 2010 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 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 show_stuff; /* vecs and frames */
int label_vecs; int label_vecs;
int show_meas; int show_meas;
}; } postscript_params;
int postscript(FILE *file); int postscript(FILE *file);