Date:2012-07-19 01:24:00 (7 years 4 months ago)
Author:Werner Almesberger
Commit:238830c02d01e0e408155ea5d89f974ed0af54f9
Message:postscript.c: move drawing part of ps_pad_name and ps_pad to separate functions

For sharing.
Files: postscript.c (3 diffs)

Change Details

postscript.c
189189}
190190
191191
192/* ----- Items ------------------------------------------------------------- */
192static void ps_filled_box(FILE *file, struct coord a, struct coord b,
193    const char *pattern)
194{
195    fprintf(file, "0 setgray %d setlinewidth\n", PS_HATCH_LINE);
196    fprintf(file, " %d %d moveto\n", a.x, a.y);
197    fprintf(file, " %d %d lineto\n", b.x, a.y);
198    fprintf(file, " %d %d lineto\n", b.x, b.y);
199    fprintf(file, " %d %d lineto\n", a.x, b.y);
200    fprintf(file, " closepath gsave %s grestore stroke\n", pattern);
201}
193202
194203
195static void ps_pad_name(FILE *file, const struct inst *inst)
204static void ps_outlined_text_in_rect(FILE *file, const char *s,
205    struct coord a, struct coord b)
196206{
197    struct coord a = inst->base;
198    struct coord b = inst->u.pad.other;
199    const char *s;
207    const char *t;
200208    unit_type h, w;
201209
202    for (s = inst->u.pad.name; *s == ' '; s++);
203    if (!*s)
210    for (t = s; *t == ' '; t++);
211    if (!*t)
204212        return;
205213    h = a.y-b.y;
206214    w = a.x-b.x;
...... 
210218        w = -w;
211219    fprintf(file, "0 setgray /Helvetica-Bold findfont dup\n");
212220    fprintf(file, " ");
213    ps_string(file, inst->u.pad.name);
221    ps_string(file, s);
214222    fprintf(file, " %d %d\n", w/2, h/2);
215223    fprintf(file, " boxfont\n");
216224    fprintf(file, " %d %d moveto\n", (a.x+b.x)/2, (a.y+b.y)/2);
217225    fprintf(file, " ");
218    ps_string(file, inst->u.pad.name);
226    ps_string(file, s);
219227    fprintf(file, " center %d showoutlined newpath\n", PS_FONT_OUTLINE);
220228}
221229
222230
231/* ----- Items ------------------------------------------------------------- */
232
233
234static void ps_pad_name(FILE *file, const struct inst *inst)
235{
236    ps_outlined_text_in_rect(file, inst->u.pad.name,
237        inst->base, inst->u.pad.other);
238}
239
240
223241static const char *hatch(layer_type layers)
224242{
225243    switch (layers_to_pad_type(layers)) {
...... 
241259
242260static void ps_pad(FILE *file, const struct inst *inst, int show_name)
243261{
244    struct coord a = inst->base;
245    struct coord b = inst->u.pad.other;
246
247    fprintf(file, "0 setgray %d setlinewidth\n", PS_HATCH_LINE);
248    fprintf(file, " %d %d moveto\n", a.x, a.y);
249    fprintf(file, " %d %d lineto\n", b.x, a.y);
250    fprintf(file, " %d %d lineto\n", b.x, b.y);
251    fprintf(file, " %d %d lineto\n", a.x, b.y);
252    fprintf(file, " closepath gsave %s grestore stroke\n",
262    ps_filled_box(file, inst->base, inst->u.pad.other,
253263        hatch(inst->u.pad.layers));
254264
255265    if (show_name && !inst->u.pad.hole)

Archive Download the corresponding diff file

Branches:
master



interactive