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 | ||
---|---|---|
73 | 73 | /* ----- Utility functions ------------------------------------------------- */ |
74 | 74 | |
75 | 75 | |
76 | static 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 | ||
94 | 76 | static void ps_string(FILE *file, const char *s) |
95 | 77 | { |
96 | 78 | fputc('(', file); |
... | ... | |
139 | 121 | const char **idx = NULL, **p; |
140 | 122 | int n = 0; |
141 | 123 | int line = 0, col = 0; |
142 | char *s; | |
143 | 124 | |
144 | 125 | collect_names(node, &idx, &n); |
145 | 126 | qsort(idx, n, sizeof(char *), comp); |
... | ... | |
165 | 146 | format.left+col*format.index_column_skip, |
166 | 147 | format.index.y+line*format.index_line_skip); |
167 | 148 | |
168 | s = sanitize_name(*p); | |
169 | 149 | fprintf(file, "[ /Rect [ "); |
170 | 150 | ps_string(file, *p); |
171 | 151 | fprintf(file, " false charpath flattenpath pathbbox ]\n"); |
172 | 152 | fprintf(file, " /Subtype /Link\n"); |
173 | 153 | 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); | |
175 | 155 | fprintf(file, " /ANN pdfmark\n"); |
176 | free(s); | |
177 | 156 | |
178 | 157 | fprintf(file, "moveto "); |
179 | 158 | ps_string(file, *p); |
... | ... | |
215 | 194 | static void make_title(FILE *file, const struct node *node, int unit) |
216 | 195 | { |
217 | 196 | const struct name *name; |
218 | char *s; | |
219 | 197 | |
220 | 198 | fprintf(file, "gsave %s 0 setgray\n", format.overlay_setup); |
221 | 199 | |
... | ... | |
227 | 205 | fprintf(file, "(, ) show 0.5 setgray\n"); |
228 | 206 | ps_string(file, name->s); |
229 | 207 | fprintf(file, " show\n"); |
230 | s = sanitize_name(name->s); | |
231 | 208 | if (!unit) |
232 | fprintf(file, "[ /Dest /%s /DEST pdfmark\n", s); | |
233 | free(s); | |
209 | fprintf(file, "[ /Dest /%p /DEST pdfmark\n", name->s); | |
234 | 210 | } |
235 | 211 | fprintf(file, "0 setgray\n"); |
236 | 212 | if (node->e->units > 1) |
Branches:
master