1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-23 00:13:09 +02:00

gencat/pdf.c: use internal pointer as destination key

This allows us to simplify a number of things and opens the path to further
improvements.
This commit is contained in:
Werner Almesberger 2012-07-11 23:31:25 -03:00
parent acf0d0af89
commit 605585ffdb

View File

@ -73,24 +73,6 @@ static int total, done = 0;
/* ----- Utility functions ------------------------------------------------- */
static char *sanitize_name(const char *s)
{
char *t, *tmp;
tmp = alloc_size(strlen(s)+1);
for (t = tmp; *s; s++) {
if (*s <= ' ' || *s > '~')
continue;
/* PDF reference 3rd ed., 3.2.2 ASCII Encoding */
if (strchr("()<>[]{}/%", *s))
continue;
*t++ = *s;
}
*t = 0;
return tmp;
}
static void ps_string(FILE *file, const char *s)
{
fputc('(', file);
@ -139,7 +121,6 @@ static void make_index(FILE *file, const struct node *node)
const char **idx = NULL, **p;
int n = 0;
int line = 0, col = 0;
char *s;
collect_names(node, &idx, &n);
qsort(idx, n, sizeof(char *), comp);
@ -165,15 +146,13 @@ static void make_index(FILE *file, const struct node *node)
format.left+col*format.index_column_skip,
format.index.y+line*format.index_line_skip);
s = sanitize_name(*p);
fprintf(file, "[ /Rect [ ");
ps_string(file, *p);
fprintf(file, " false charpath flattenpath pathbbox ]\n");
fprintf(file, " /Subtype /Link\n");
fprintf(file, " /Border [ 0 0 0 ]\n");
fprintf(file, " /Action << /Subtype /GoTo /Dest /%s >>\n", s);
fprintf(file, " /Action << /Subtype /GoTo /Dest /%p >>\n", *p);
fprintf(file, " /ANN pdfmark\n");
free(s);
fprintf(file, "moveto ");
ps_string(file, *p);
@ -215,7 +194,6 @@ static void print_path(FILE *file, const struct node *node)
static void make_title(FILE *file, const struct node *node, int unit)
{
const struct name *name;
char *s;
fprintf(file, "gsave %s 0 setgray\n", format.overlay_setup);
@ -227,10 +205,8 @@ static void make_title(FILE *file, const struct node *node, int unit)
fprintf(file, "(, ) show 0.5 setgray\n");
ps_string(file, name->s);
fprintf(file, " show\n");
s = sanitize_name(name->s);
if (!unit)
fprintf(file, "[ /Dest /%s /DEST pdfmark\n", s);
free(s);
fprintf(file, "[ /Dest /%p /DEST pdfmark\n", name->s);
}
fprintf(file, "0 setgray\n");
if (node->e->units > 1)