mirror of
git://projects.qi-hardware.com/fped.git
synced 2024-11-22 07:30:16 +02:00
postscript.c: show key for pad types at bottom of fullpage drawings (-P -K)
This commit is contained in:
parent
26b74e867a
commit
d250ed236c
10
fped.c
10
fped.c
@ -73,12 +73,13 @@ static void usage(const char *name)
|
|||||||
" write gnuplot output, then exit\n"
|
" write gnuplot output, then exit\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 [-s scale] [-1 package]\n"
|
" -P [-K] [-s scale] [-1 package]\n"
|
||||||
" write Postscript output (full page), then exit\n"
|
" write Postscript output (full page), then exit\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\n"
|
" -T -T test mode. Load file, dump to stdout, then exit\n\n"
|
||||||
"Common options:\n"
|
"Common options:\n"
|
||||||
" -1 name output only the specified package\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 scale scale factor for -P (default: auto-scale)\n"
|
||||||
" -s [width]x[heigth]\n"
|
" -s [width]x[heigth]\n"
|
||||||
" auto-scale to fit within specified box. Dimensions in mm.\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;
|
const char *one = NULL;
|
||||||
int c;
|
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) {
|
switch (c) {
|
||||||
case '1':
|
case '1':
|
||||||
one = optarg;
|
one = optarg;
|
||||||
@ -157,6 +158,9 @@ int main(int argc, char **argv)
|
|||||||
usage(*argv);
|
usage(*argv);
|
||||||
batch = batch_ps_fullpage;
|
batch = batch_ps_fullpage;
|
||||||
break;
|
break;
|
||||||
|
case 'K':
|
||||||
|
postscript_params.show_key = 1;
|
||||||
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
if (batch != batch_ps_fullpage)
|
if (batch != batch_ps_fullpage)
|
||||||
usage(*argv);
|
usage(*argv);
|
||||||
@ -181,6 +185,8 @@ int main(int argc, char **argv)
|
|||||||
if (one && batch != batch_ps && batch != batch_ps_fullpage &&
|
if (one && batch != batch_ps && batch != batch_ps_fullpage &&
|
||||||
batch != batch_gnuplot)
|
batch != batch_gnuplot)
|
||||||
usage(name);
|
usage(name);
|
||||||
|
if (postscript_params.show_key && batch != batch_ps_fullpage)
|
||||||
|
usage(name);
|
||||||
|
|
||||||
if (!batch) {
|
if (!batch) {
|
||||||
args[0] = name;
|
args[0] = name;
|
||||||
|
62
postscript.c
62
postscript.c
@ -14,6 +14,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@ -88,6 +89,9 @@
|
|||||||
#define PS_CROSS_WIDTH mm_to_units(0.01)
|
#define PS_CROSS_WIDTH mm_to_units(0.01)
|
||||||
#define PS_CROSS_DASH mm_to_units(0.1)
|
#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 */
|
#define TEXT_HEIGHT_FACTOR 1.5 /* height/width of typical text */
|
||||||
|
|
||||||
|
|
||||||
@ -99,6 +103,7 @@ struct postscript_params postscript_params = {
|
|||||||
.show_stuff = 0,
|
.show_stuff = 0,
|
||||||
.label_vecs = 0,
|
.label_vecs = 0,
|
||||||
.show_meas = 1,
|
.show_meas = 1,
|
||||||
|
.show_key = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct postscript_params minimal_params;
|
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)
|
static void ps_package(FILE *file, const struct pkg *pkg, int page)
|
||||||
{
|
{
|
||||||
struct bbox bbox;
|
struct bbox bbox;
|
||||||
@ -1141,7 +1182,8 @@ 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;
|
double w = 2.0*PAGE_HALF_WIDTH;
|
||||||
|
double h = 2.0*PAGE_HALF_HEIGHT;
|
||||||
|
|
||||||
ps_page(file, page, pkg);
|
ps_page(file, page, pkg);
|
||||||
active_params = postscript_params;
|
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) {
|
if (active_params.zoom) {
|
||||||
f = active_params.zoom;
|
f = active_params.zoom;
|
||||||
} else {
|
} else {
|
||||||
d = active_params.max_width ? active_params.max_width :
|
if (active_params.max_width)
|
||||||
2.0*PAGE_HALF_WIDTH;
|
w = active_params.max_width;
|
||||||
fx = d/(bbox.max.x-bbox.min.x);
|
fx = w/(bbox.max.x-bbox.min.x);
|
||||||
d = active_params.max_height ? active_params.max_height :
|
if (active_params.max_height)
|
||||||
2.0*PAGE_HALF_HEIGHT;
|
h = active_params.max_height;
|
||||||
fy = d/(bbox.max.y-bbox.min.y);
|
if (active_params.show_key)
|
||||||
|
h -= 2*PS_KEY_HEIGTH;
|
||||||
|
fy = h/(bbox.max.y-bbox.min.y);
|
||||||
f = fx < fy ? fx : fy;
|
f = fx < fy ? fx : fy;
|
||||||
}
|
}
|
||||||
|
fprintf(file, "gsave\n");
|
||||||
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, 0);
|
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");
|
fprintf(file, "showpage\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,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;
|
||||||
|
int show_key;
|
||||||
} postscript_params;
|
} postscript_params;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user