1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-26 04:12:28 +02:00

New option -P for batch output for full-page postscript.

- fped.c (main, usage): new option -P to output full-page Postscript
- postscript.c (postscript): renamed full-page output to postscript_page,
  uncommented it, and added auto-zoom
- file.c, file.h (write_ps_fullpage): handler for full-page postscript
- fped.c (usage): clarified that -k and -p/-P don/t exclude each other



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5849 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
werner 2010-02-19 22:27:25 +00:00
parent c8cf877204
commit ea8e848f72
5 changed files with 48 additions and 22 deletions

22
file.c
View File

@ -1,8 +1,8 @@
/* /*
* file.c - File handling * file.c - File handling
* *
* Written 2009 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 2009 by Werner Almesberger * Copyright 2009, 2010 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
@ -172,16 +172,28 @@ void write_kicad(void)
} }
void write_ps(void) static void do_write_ps(int (*fn)(FILE *file))
{ {
char *name; char *name;
if (save_file_name) { if (save_file_name) {
name = set_extension(save_file_name, "ps"); name = set_extension(save_file_name, "ps");
save_to(name, postscript); save_to(name, fn);
free(name); free(name);
} else { } else {
if (!postscript(stdout)) if (!fn(stdout))
perror("stdout"); perror("stdout");
} }
} }
void write_ps(void)
{
do_write_ps(postscript);
}
void write_ps_fullpage(void)
{
do_write_ps(postscript_fullpage);
}

5
file.h
View File

@ -1,8 +1,8 @@
/* /*
* file.h - File handling * file.h - File handling
* *
* Written 2009 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 2009 by Werner Almesberger * Copyright 2009, 2010 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
@ -29,5 +29,6 @@ void save_with_backup(const char *name, int (*fn)(FILE *file));
void save_fpd(void); void save_fpd(void);
void write_kicad(void); void write_kicad(void);
void write_ps(void); void write_ps(void);
void write_ps_fullpage(void);
#endif /* !FILE_H */ #endif /* !FILE_H */

22
fped.c
View File

@ -1,8 +1,8 @@
/* /*
* fped.c - Footprint editor, main function * fped.c - Footprint editor, main function
* *
* Written 2009 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 2009 by Werner Almesberger * Copyright 2009, 2010 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
@ -44,9 +44,10 @@ 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] [cpp_option ...] [in_file [out_file]]\n\n" "usage: %s [-k] [-p|-P] [cpp_option ...] [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"
" cpp_option -Idir, -Dname[=value], or -Uname\n" " cpp_option -Idir, -Dname[=value], or -Uname\n"
, name); , name);
exit(1); exit(1);
@ -61,10 +62,11 @@ int main(int argc, char **argv)
int fake_argc; int fake_argc;
char opt[] = "-?"; char opt[] = "-?";
int error, batch; int error, batch;
int batch_write_kicad = 0, batch_write_ps = 0; int batch_write_kicad = 0;
int batch_write_ps = 0, batch_write_ps_fullpage = 0;
int c; int c;
while ((c = getopt(argc, argv, "kpD:U:I:")) != EOF) while ((c = getopt(argc, argv, "kpD:I:U:P")) != EOF)
switch (c) { switch (c) {
case 'k': case 'k':
batch_write_kicad = 1; batch_write_kicad = 1;
@ -72,6 +74,9 @@ int main(int argc, char **argv)
case 'p': case 'p':
batch_write_ps = 1; batch_write_ps = 1;
break; break;
case 'P':
batch_write_ps_fullpage = 1;
break;
case 'D': case 'D':
case 'U': case 'U':
case 'I': case 'I':
@ -83,7 +88,10 @@ int main(int argc, char **argv)
usage(name); usage(name);
} }
batch = batch_write_kicad || batch_write_ps; if (batch_write_ps && batch_write_ps_fullpage)
usage(name);
batch = batch_write_kicad || batch_write_ps || batch_write_ps_fullpage;
if (!batch) { if (!batch) {
args[0] = name; args[0] = name;
@ -125,6 +133,8 @@ int main(int argc, char **argv)
write_kicad(); write_kicad();
if (batch_write_ps) if (batch_write_ps)
write_ps(); write_ps();
if (batch_write_ps_fullpage)
write_ps_fullpage();
if (!batch) { if (!batch) {
error = gui_main(); error = gui_main();
if (error) if (error)

View File

@ -1,8 +1,8 @@
/* /*
* postscript.c - Dump objects in Postscript * postscript.c - Dump objects in Postscript
* *
* Written 2009 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 2009 by Werner Almesberger * Copyright 2009, 2010 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
@ -1004,7 +1004,6 @@ static void epilogue(FILE *file)
} }
#if 1
int postscript(FILE *file) int postscript(FILE *file)
{ {
struct pkg *pkg; struct pkg *pkg;
@ -1023,16 +1022,17 @@ int postscript(FILE *file)
fflush(file); fflush(file);
return !ferror(file); return !ferror(file);
} }
#else
/* /*
* Experimental. Doesn't work properly. * Experimental. Doesn't work properly.
*/ */
int postscript(FILE *file)
int postscript_fullpage(FILE *file)
{ {
unit_type cx, cy; unit_type cx, cy;
struct bbox bbox; struct bbox bbox;
double f = 0.2; double fx, fy, f;
prologue(file, 1); prologue(file, 1);
ps_page(file, 1, pkgs); ps_page(file, 1, pkgs);
@ -1040,6 +1040,9 @@ int postscript(FILE *file)
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);
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, pkgs->next, f); ps_draw_package(file, pkgs->next, f);
fprintf(file, "showpage\n"); fprintf(file, "showpage\n");
@ -1047,4 +1050,3 @@ int postscript(FILE *file)
fflush(file); fflush(file);
return !ferror(file); return !ferror(file);
} }
#endif

View File

@ -1,8 +1,8 @@
/* /*
* ps.h - Dump objects in Postscript * ps.h - Dump objects in Postscript
* *
* Written 2009 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 2009 by Werner Almesberger * Copyright 2009, 2010 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
@ -27,5 +27,6 @@ struct postscript_params {
int postscript(FILE *file); int postscript(FILE *file);
int postscript_fullpage(FILE *file);
#endif /* !POSTSCRIPT_H */ #endif /* !POSTSCRIPT_H */