1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-18 06:59:43 +02:00

Removed an old bug: parentheses and backslash are meta-characters in Postscript

strings but weren't escaped until now.

- postscript.c: output all Postscript strings with ps_string, which correctly
  escapes parentheses and backslashes
- TODO: removed the bug entry



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5952 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
werner 2010-04-29 21:34:29 +00:00
parent dbace0b2fa
commit 24011c74d6
2 changed files with 55 additions and 19 deletions

1
TODO
View File

@ -32,7 +32,6 @@ Bugs:
- focus should return to canvas if nobody else wants it - focus should return to canvas if nobody else wants it
- whenever we call parse_* for input parsing, we may leak lots of expressions - whenever we call parse_* for input parsing, we may leak lots of expressions
- can't edit measurement labels through the GUI - can't edit measurement labels through the GUI
- unbalanced parentheses in text throw off Postscript syntax
Code cleanup: Code cleanup:
- merge edit_unique with edit_name - merge edit_unique with edit_name

View File

@ -166,6 +166,22 @@ static int get_box(unit_type x, unit_type y, unit_type *xa, unit_type *ya)
} }
/* ----- Helper functions -------------------------------------------------- */
static void ps_string(FILE *file, const char *s)
{
fputc('(', file);
while (*s) {
if (*s == '(' || *s == ')' || *s == '\\')
fputc('\\', file);
fputc(*s, file);
s++;
}
fputc(')', file);
}
/* ----- Items ------------------------------------------------------------- */ /* ----- Items ------------------------------------------------------------- */
@ -184,11 +200,14 @@ static void ps_pad_name(FILE *file, const struct inst *inst)
if (w < 0) if (w < 0)
w = -w; w = -w;
fprintf(file, "0 setgray /Helvetica-Bold findfont dup\n"); fprintf(file, "0 setgray /Helvetica-Bold findfont dup\n");
fprintf(file, " (%s) %d %d\n", inst->u.pad.name, w/2, h/2); fprintf(file, " ");
ps_string(file, inst->u.pad.name);
fprintf(file, " %d %d\n", w/2, h/2);
fprintf(file, " boxfont\n"); fprintf(file, " boxfont\n");
fprintf(file, " %d %d moveto\n", (a.x+b.x)/2, (a.y+b.y)/2); fprintf(file, " %d %d moveto\n", (a.x+b.x)/2, (a.y+b.y)/2);
fprintf(file, " (%s) center %d showoutlined newpath\n", fprintf(file, " ");
inst->u.pad.name, PS_FONT_OUTLINE); ps_string(file, inst->u.pad.name);
fprintf(file, " center %d showoutlined newpath\n", PS_FONT_OUTLINE);
} }
@ -372,13 +391,16 @@ static void ps_vec(FILE *file, const struct inst *inst)
d = sub_vec(b, a); d = sub_vec(b, a);
fprintf(file, "gsave %d %d moveto\n", c.x/2, c.y/2); fprintf(file, "gsave %d %d moveto\n", c.x/2, c.y/2);
fprintf(file, " /Helvetica-Bold findfont dup\n"); fprintf(file, " /Helvetica-Bold findfont dup\n");
fprintf(file, " (%s) %d %d realsize\n", s, fprintf(file, " ");
ps_string(file, s);
fprintf(file, " %d %d realsize\n",
(int) (dist_point(a, b)-2*PS_VEC_ARROW_LEN), (int) (dist_point(a, b)-2*PS_VEC_ARROW_LEN),
PS_VEC_TEXT_HEIGHT); PS_VEC_TEXT_HEIGHT);
fprintf(file, " boxfont\n"); fprintf(file, " boxfont\n");
fprintf(file, " %f rotate\n", atan2(d.y, d.x)/M_PI*180); fprintf(file, " %f rotate\n", atan2(d.y, d.x)/M_PI*180);
fprintf(file, " (%s) %d realsize pop 0 hcenter\n", fprintf(file, " ");
s, PS_VEC_BASE_OFFSET); ps_string(file, s);
fprintf(file, " %d realsize pop 0 hcenter\n", PS_VEC_BASE_OFFSET);
fprintf(file, " show grestore\n"); fprintf(file, " show grestore\n");
free(s); free(s);
} }
@ -450,20 +472,26 @@ fprintf(stderr, "%s -> width %d height %d vs. %d\n",
if (height) { if (height) {
fprintf(file, "gsave %d %d moveto\n", c.x/2, c.y/2); fprintf(file, "gsave %d %d moveto\n", c.x/2, c.y/2);
fprintf(file, " /Helvetica-Bold findfont dup\n"); fprintf(file, " /Helvetica-Bold findfont dup\n");
fprintf(file, " (%s) %d realsize %d realsize\n", fprintf(file, " ");
s, width, height); ps_string(file, s);
fprintf(file, " %d realsize %d realsize\n", width, height);
fprintf(file, " boxfont\n"); fprintf(file, " boxfont\n");
fprintf(file, " %f rotate\n", atan2(d.y, d.x)/M_PI*180); fprintf(file, " %f rotate\n", atan2(d.y, d.x)/M_PI*180);
fprintf(file, " (%s) %d realsize hcenter\n", s, offset); fprintf(file, " ");
ps_string(file, s);
fprintf(file, " %d realsize hcenter\n", offset);
fprintf(file, " show grestore\n"); fprintf(file, " show grestore\n");
} else { } else {
fprintf(file, "gsave %d %d moveto\n", c.x/2, c.y/2); fprintf(file, "gsave %d %d moveto\n", c.x/2, c.y/2);
fprintf(file, " /Helvetica-Bold findfont dup\n"); fprintf(file, " /Helvetica-Bold findfont dup\n");
fprintf(file, " (%s) %d %d realsize\n", s, width, fprintf(file, " ");
PS_MEAS_TEXT_HEIGHT); ps_string(file, s);
fprintf(file, " %d %d realsize\n", width, PS_MEAS_TEXT_HEIGHT);
fprintf(file, " boxfont\n"); fprintf(file, " boxfont\n");
fprintf(file, " %f rotate\n", atan2(d.y, d.x)/M_PI*180); fprintf(file, " %f rotate\n", atan2(d.y, d.x)/M_PI*180);
fprintf(file, " (%s) %d realsize hcenter\n", s, offset); fprintf(file, " ");
ps_string(file, s);
fprintf(file, " %d realsize hcenter\n", offset);
fprintf(file, " show grestore\n"); fprintf(file, " show grestore\n");
} }
free(s); free(s);
@ -694,10 +722,13 @@ static void ps_header(FILE *file, const struct pkg *pkg)
fprintf(file, "gsave %d %d moveto\n", fprintf(file, "gsave %d %d moveto\n",
-PAGE_HALF_WIDTH, PAGE_HALF_HEIGHT-PS_HEADER_HEIGHT); -PAGE_HALF_WIDTH, PAGE_HALF_HEIGHT-PS_HEADER_HEIGHT);
fprintf(file, " /Helvetica-Bold findfont dup\n"); fprintf(file, " /Helvetica-Bold findfont dup\n");
fprintf(file, " (%s) %d %d\n", fprintf(file, " ");
pkg->name, PAGE_HALF_WIDTH, PS_HEADER_HEIGHT); ps_string(file, pkg->name);
fprintf(file, " %d %d\n", PAGE_HALF_WIDTH, PS_HEADER_HEIGHT);
fprintf(file, " boxfont\n"); fprintf(file, " boxfont\n");
fprintf(file, " (%s) show grestore\n", pkg->name); fprintf(file, " ");
ps_string(file, pkg->name);
fprintf(file, " show grestore\n");
ps_hline(file, PAGE_HALF_HEIGHT-PS_HEADER_HEIGHT-PS_DIVIDER_BORDER); ps_hline(file, PAGE_HALF_HEIGHT-PS_HEADER_HEIGHT-PS_DIVIDER_BORDER);
} }
@ -716,7 +747,9 @@ static void ps_page(FILE *file, int page, const struct pkg *pkg)
" 72 %d div 1000 div dup scale\n", " 72 %d div 1000 div dup scale\n",
(int) MIL_UNITS); (int) MIL_UNITS);
fprintf(file, "%%%%EndPageSetup\n"); fprintf(file, "%%%%EndPageSetup\n");
fprintf(file, "[ /Title (%s) /OUT pdfmark\n", pkg->name); fprintf(file, "[ /Title ");
ps_string(file, pkg->name);
fprintf(file, " /OUT pdfmark\n");
} }
@ -740,9 +773,13 @@ static void ps_unit(FILE *file,
fprintf(file, "gsave %d %d moveto\n", x, y); fprintf(file, "gsave %d %d moveto\n", x, y);
fprintf(file, " /Helvetica findfont dup\n"); fprintf(file, " /Helvetica findfont dup\n");
fprintf(file, " (%s) %d %d\n", s, w, h); fprintf(file, " ");
ps_string(file, s);
fprintf(file, " %d %d\n", w, h);
fprintf(file, " boxfont\n"); fprintf(file, " boxfont\n");
fprintf(file, " (%s) show grestore\n", s); fprintf(file, " ");
ps_string(file, s);
fprintf(file, " show grestore\n");
} }