Date:2012-07-12 04:31:25 (11 years 8 months ago)
Author:Werner Almesberger
Commit:605585ffdb66709600560011d2ae3dc493be648f
Message: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.
Files: gencat/pdf.c (5 diffs)

Change Details

gencat/pdf.c
7373/* ----- Utility functions ------------------------------------------------- */
7474
7575
76static char *sanitize_name(const char *s)
77{
78    char *t, *tmp;
79
80    tmp = alloc_size(strlen(s)+1);
81    for (t = tmp; *s; s++) {
82        if (*s <= ' ' || *s > '~')
83            continue;
84        /* PDF reference 3rd ed., 3.2.2 ASCII Encoding */
85        if (strchr("()<>[]{}/%", *s))
86            continue;
87        *t++ = *s;
88    }
89    *t = 0;
90    return tmp;
91}
92
93
9476static void ps_string(FILE *file, const char *s)
9577{
9678    fputc('(', file);
...... 
139121    const char **idx = NULL, **p;
140122    int n = 0;
141123    int line = 0, col = 0;
142    char *s;
143124
144125    collect_names(node, &idx, &n);
145126    qsort(idx, n, sizeof(char *), comp);
...... 
165146            format.left+col*format.index_column_skip,
166147            format.index.y+line*format.index_line_skip);
167148
168        s = sanitize_name(*p);
169149        fprintf(file, "[ /Rect [ ");
170150        ps_string(file, *p);
171151        fprintf(file, " false charpath flattenpath pathbbox ]\n");
172152        fprintf(file, " /Subtype /Link\n");
173153        fprintf(file, " /Border [ 0 0 0 ]\n");
174        fprintf(file, " /Action << /Subtype /GoTo /Dest /%s >>\n", s);
154        fprintf(file, " /Action << /Subtype /GoTo /Dest /%p >>\n", *p);
175155        fprintf(file, " /ANN pdfmark\n");
176        free(s);
177156
178157        fprintf(file, "moveto ");
179158        ps_string(file, *p);
...... 
215194static void make_title(FILE *file, const struct node *node, int unit)
216195{
217196    const struct name *name;
218    char *s;
219197
220198    fprintf(file, "gsave %s 0 setgray\n", format.overlay_setup);
221199
...... 
227205            fprintf(file, "(, ) show 0.5 setgray\n");
228206        ps_string(file, name->s);
229207        fprintf(file, " show\n");
230        s = sanitize_name(name->s);
231208        if (!unit)
232            fprintf(file, "[ /Dest /%s /DEST pdfmark\n", s);
233        free(s);
209            fprintf(file, "[ /Dest /%p /DEST pdfmark\n", name->s);
234210    }
235211    fprintf(file, "0 setgray\n");
236212    if (node->e->units > 1)

Archive Download the corresponding diff file

Branches:
master



interactive