From 238830c02d01e0e408155ea5d89f974ed0af54f9 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 18 Jul 2012 20:24:00 -0300 Subject: [PATCH] postscript.c: move drawing part of ps_pad_name and ps_pad to separate functions For sharing. --- postscript.c | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/postscript.c b/postscript.c index 7eed5a8..8c143ef 100644 --- a/postscript.c +++ b/postscript.c @@ -189,18 +189,26 @@ static void ps_string(FILE *file, const char *s) } -/* ----- Items ------------------------------------------------------------- */ - - -static void ps_pad_name(FILE *file, const struct inst *inst) +static void ps_filled_box(FILE *file, struct coord a, struct coord b, + const char *pattern) { - struct coord a = inst->base; - struct coord b = inst->u.pad.other; - const char *s; + fprintf(file, "0 setgray %d setlinewidth\n", PS_HATCH_LINE); + fprintf(file, " %d %d moveto\n", a.x, a.y); + fprintf(file, " %d %d lineto\n", b.x, a.y); + fprintf(file, " %d %d lineto\n", b.x, b.y); + fprintf(file, " %d %d lineto\n", a.x, b.y); + fprintf(file, " closepath gsave %s grestore stroke\n", pattern); +} + + +static void ps_outlined_text_in_rect(FILE *file, const char *s, + struct coord a, struct coord b) +{ + const char *t; unit_type h, w; - for (s = inst->u.pad.name; *s == ' '; s++); - if (!*s) + for (t = s; *t == ' '; t++); + if (!*t) return; h = a.y-b.y; w = a.x-b.x; @@ -210,16 +218,26 @@ static void ps_pad_name(FILE *file, const struct inst *inst) w = -w; fprintf(file, "0 setgray /Helvetica-Bold findfont dup\n"); fprintf(file, " "); - ps_string(file, inst->u.pad.name); + ps_string(file, s); fprintf(file, " %d %d\n", w/2, h/2); fprintf(file, " boxfont\n"); fprintf(file, " %d %d moveto\n", (a.x+b.x)/2, (a.y+b.y)/2); fprintf(file, " "); - ps_string(file, inst->u.pad.name); + ps_string(file, s); fprintf(file, " center %d showoutlined newpath\n", PS_FONT_OUTLINE); } +/* ----- Items ------------------------------------------------------------- */ + + +static void ps_pad_name(FILE *file, const struct inst *inst) +{ + ps_outlined_text_in_rect(file, inst->u.pad.name, + inst->base, inst->u.pad.other); +} + + static const char *hatch(layer_type layers) { switch (layers_to_pad_type(layers)) { @@ -241,15 +259,7 @@ static const char *hatch(layer_type layers) static void ps_pad(FILE *file, const struct inst *inst, int show_name) { - struct coord a = inst->base; - struct coord b = inst->u.pad.other; - - fprintf(file, "0 setgray %d setlinewidth\n", PS_HATCH_LINE); - fprintf(file, " %d %d moveto\n", a.x, a.y); - fprintf(file, " %d %d lineto\n", b.x, a.y); - fprintf(file, " %d %d lineto\n", b.x, b.y); - fprintf(file, " %d %d lineto\n", a.x, b.y); - fprintf(file, " closepath gsave %s grestore stroke\n", + ps_filled_box(file, inst->base, inst->u.pad.other, hatch(inst->u.pad.layers)); if (show_name && !inst->u.pad.hole)