Date: | 2012-07-12 04:52:54 (11 years 8 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 463e8dcac4a2f724a58dae7ea57dd600b8f8a2ef |
Message: | gencat/pdf.c: key index entries by the tree node, to distinguish
duplicates Before, duplicate names in the tree always pointed to the same page. Now they point to the respective locations. Note that this does not affect handling of duplicate names in libraries, where still only one "wins" while the other is completely ignored. |
Files: |
gencat/pdf.c (5 diffs) |
Change Details
gencat/pdf.c | ||
---|---|---|
89 | 89 | /* ----- Alphabetic index -------------------------------------------------- */ |
90 | 90 | |
91 | 91 | |
92 | static void collect_names(const struct node *node, const char ***idx, int *n) | |
92 | struct index { | |
93 | const char *s; | |
94 | const struct node *node; | |
95 | }; | |
96 | ||
97 | ||
98 | static void collect_names(const struct node *node, struct index **idx, int *n) | |
93 | 99 | { |
94 | 100 | const struct name *name; |
95 | 101 | |
... | ... | |
99 | 105 | else { |
100 | 106 | for (name = node->e->names; name; name = name->next) { |
101 | 107 | (*n)++; |
102 | *idx = realloc(*idx, *n*sizeof(char *)); | |
108 | *idx = realloc(*idx, *n*sizeof(struct entry)); | |
103 | 109 | if (!*idx) |
104 | 110 | abort(); |
105 | (*idx)[*n-1] = name->s; | |
111 | (*idx)[*n-1].s = name->s; | |
112 | (*idx)[*n-1].node = node; | |
106 | 113 | } |
107 | 114 | } |
108 | 115 | node = node->next; |
... | ... | |
112 | 119 | |
113 | 120 | static int comp(const void *a, const void *b) |
114 | 121 | { |
115 | return strcmp(*(const char **) a, *(const char **) b); | |
122 | const struct index *ai = a; | |
123 | const struct index *bi = b; | |
124 | ||
125 | return strcmp(ai->s, bi->s); | |
116 | 126 | } |
117 | 127 | |
118 | 128 | |
119 | 129 | static void make_index(FILE *file, const struct node *node) |
120 | 130 | { |
121 | const char **idx = NULL, **p; | |
131 | struct index *idx = NULL; | |
132 | const struct index *p; | |
122 | 133 | int n = 0; |
123 | 134 | int line = 0, col = 0; |
124 | 135 | |
125 | 136 | collect_names(node, &idx, &n); |
126 | qsort(idx, n, sizeof(char *), comp); | |
137 | qsort(idx, n, sizeof(struct index), comp); | |
127 | 138 | |
128 | 139 | fprintf(file, "[ /Title (Index) /Count 0 /OUT pdfmark\n"); |
129 | 140 | |
... | ... | |
147 | 158 | format.index.y+line*format.index_line_skip); |
148 | 159 | |
149 | 160 | fprintf(file, "[ /Rect [ "); |
150 | ps_string(file, *p); | |
161 | ps_string(file, p->s); | |
151 | 162 | fprintf(file, " false charpath flattenpath pathbbox ]\n"); |
152 | 163 | fprintf(file, " /Subtype /Link\n"); |
153 | 164 | fprintf(file, " /Border [ 0 0 0 ]\n"); |
154 | fprintf(file, " /Action << /Subtype /GoTo /Dest /%p >>\n", *p); | |
165 | fprintf(file, " /Action << /Subtype /GoTo /Dest /%p%p >>\n", | |
166 | p->node, p->s); | |
155 | 167 | fprintf(file, " /ANN pdfmark\n"); |
156 | 168 | |
157 | 169 | fprintf(file, "moveto "); |
158 | ps_string(file, *p); | |
170 | ps_string(file, p->s); | |
159 | 171 | fprintf(file, " show\n"); |
160 | 172 | line++; |
161 | 173 | } |
... | ... | |
206 | 218 | ps_string(file, name->s); |
207 | 219 | fprintf(file, " show\n"); |
208 | 220 | if (!unit) |
209 | fprintf(file, "[ /Dest /%p /DEST pdfmark\n", name->s); | |
221 | fprintf(file, "[ /Dest /%p%p /DEST pdfmark\n", | |
222 | node, name->s); | |
210 | 223 | } |
211 | 224 | fprintf(file, "0 setgray\n"); |
212 | 225 | if (node->e->units > 1) |
Branches:
master