1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-24 23:49:42 +02:00

postscript.c: show key for pad types at bottom of fullpage drawings (-P -K)

This commit is contained in:
Werner Almesberger 2012-07-18 22:09:47 -03:00
parent 26b74e867a
commit d250ed236c
3 changed files with 64 additions and 9 deletions

10
fped.c
View File

@ -73,12 +73,13 @@ static void usage(const char *name)
" write gnuplot output, then exit\n"
" -k write KiCad output, then exit\n"
" -p write Postscript output, then exit\n"
" -P [-s scale] [-1 package]\n"
" -P [-K] [-s scale] [-1 package]\n"
" write Postscript output (full page), then exit\n"
" -T test mode. Load file, then exit\n"
" -T -T test mode. Load file, dump to stdout, then exit\n\n"
"Common options:\n"
" -1 name output only the specified package\n"
" -K show the pad type key\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"
@ -132,7 +133,7 @@ int main(int argc, char **argv)
const char *one = NULL;
int c;
while ((c = getopt(argc, argv, "1:gkps:D:I:PTU:")) != EOF)
while ((c = getopt(argc, argv, "1:gkps:D:I:KPTU:")) != EOF)
switch (c) {
case '1':
one = optarg;
@ -157,6 +158,9 @@ int main(int argc, char **argv)
usage(*argv);
batch = batch_ps_fullpage;
break;
case 'K':
postscript_params.show_key = 1;
break;
case 's':
if (batch != batch_ps_fullpage)
usage(*argv);
@ -181,6 +185,8 @@ int main(int argc, char **argv)
if (one && batch != batch_ps && batch != batch_ps_fullpage &&
batch != batch_gnuplot)
usage(name);
if (postscript_params.show_key && batch != batch_ps_fullpage)
usage(name);
if (!batch) {
args[0] = name;

View File

@ -14,6 +14,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "util.h"
@ -88,6 +89,9 @@
#define PS_CROSS_WIDTH mm_to_units(0.01)
#define PS_CROSS_DASH mm_to_units(0.1)
#define PS_KEY_GAP mm_to_units(8)
#define PS_KEY_HEIGTH mm_to_units(8)
#define TEXT_HEIGHT_FACTOR 1.5 /* height/width of typical text */
@ -99,6 +103,7 @@ struct postscript_params postscript_params = {
.show_stuff = 0,
.label_vecs = 0,
.show_meas = 1,
.show_key = 0,
};
static const struct postscript_params minimal_params;
@ -806,6 +811,42 @@ static void ps_unit(FILE *file,
}
static void ps_key(FILE *file, double w, double h, enum pad_type type)
{
char tmp[20]; /* @@@ plenty :) */
double f = 32;
struct coord a, b;
unit_type key_w;
key_w = (w-2*PS_KEY_GAP-PS_KEY_GAP*(pt_n-1))/pt_n;
a.x = b.x = (key_w+PS_KEY_GAP)*type-w/2+PS_KEY_GAP;
a.y = b.y = -h/2-PS_KEY_GAP;
b.x += key_w;
b.y -= PS_KEY_HEIGTH;
a.x /= f;
a.y /= f;
b.x /= f;
b.y /= f;
strcpy(tmp, pad_type_name(type));
tmp[0] = toupper(tmp[0]);
fprintf(file, "gsave %f %f scale\n", f, f);
ps_filled_box(file, a, b, hatch(type));
ps_outlined_text_in_rect(file, tmp, a, b);
fprintf(file, "grestore\n");
}
static void ps_keys(FILE *file, double w, double h)
{
enum pad_type i;
for (i = 0; i != pt_n; i++)
ps_key(file, w, h, i);
}
static void ps_package(FILE *file, const struct pkg *pkg, int page)
{
struct bbox bbox;
@ -1141,7 +1182,8 @@ 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;
double w = 2.0*PAGE_HALF_WIDTH;
double h = 2.0*PAGE_HALF_HEIGHT;
ps_page(file, page, pkg);
active_params = postscript_params;
@ -1151,16 +1193,22 @@ static void ps_package_fullpage(FILE *file, const struct pkg *pkg, int page)
if (active_params.zoom) {
f = active_params.zoom;
} else {
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);
if (active_params.max_width)
w = active_params.max_width;
fx = w/(bbox.max.x-bbox.min.x);
if (active_params.max_height)
h = active_params.max_height;
if (active_params.show_key)
h -= 2*PS_KEY_HEIGTH;
fy = h/(bbox.max.y-bbox.min.y);
f = fx < fy ? fx : fy;
}
fprintf(file, "gsave\n");
fprintf(file, "%d %d translate\n", (int) (-cx*f), (int) (-cy*f));
ps_draw_package(file, pkg, f, 0);
fprintf(file, "grestore\n");
if (active_params.show_key)
ps_keys(file, w, h);
fprintf(file, "showpage\n");
}

View File

@ -25,6 +25,7 @@ struct postscript_params {
int show_stuff; /* vecs and frames */
int label_vecs;
int show_meas;
int show_key;
} postscript_params;