/src/ghostpdl/pdf/pdf_array.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2018-2022 Artifex Software, Inc. |
2 | | All Rights Reserved. |
3 | | |
4 | | This software is provided AS-IS with no warranty, either express or |
5 | | implied. |
6 | | |
7 | | This software is distributed under license and may not be copied, |
8 | | modified or distributed except as expressly authorized under the terms |
9 | | of the license contained in the file LICENSE in this distribution. |
10 | | |
11 | | Refer to licensing information at http://www.artifex.com or contact |
12 | | Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato, |
13 | | CA 94945, U.S.A., +1(415)492-9861, for further information. |
14 | | */ |
15 | | |
16 | | /* array handling for the PDF interpreter */ |
17 | | |
18 | | #include "ghostpdf.h" |
19 | | #include "pdf_types.h" |
20 | | #include "pdf_stack.h" |
21 | | #include "pdf_deref.h" |
22 | | #include "pdf_array.h" |
23 | | #include "pdf_loop_detect.h" |
24 | | |
25 | | /* NOTE: I think this should take a pdf_context param, but it's not available where it's |
26 | | * called, would require some surgery. |
27 | | */ |
28 | | void pdfi_free_array(pdf_obj *o) |
29 | 7.39M | { |
30 | 7.39M | pdf_array *a = (pdf_array *)o; |
31 | 7.39M | int i; |
32 | | |
33 | 72.9M | for (i=0;i < a->size;i++) { |
34 | 65.6M | if (a->values[i] != NULL) |
35 | 65.5M | pdfi_countdown(a->values[i]); |
36 | 65.6M | } |
37 | 7.39M | gs_free_object(OBJ_MEMORY(a), a->values, "pdf interpreter free array contents"); |
38 | 7.39M | gs_free_object(OBJ_MEMORY(a), a, "pdf interpreter free array"); |
39 | 7.39M | } |
40 | | |
41 | | int pdfi_array_alloc(pdf_context *ctx, uint64_t size, pdf_array **a) |
42 | 7.36M | { |
43 | 7.36M | int code, i; |
44 | | |
45 | 7.36M | *a = NULL; |
46 | 7.36M | code = pdfi_object_alloc(ctx, PDF_ARRAY, size, (pdf_obj **)a); |
47 | 7.36M | if (code < 0) |
48 | 0 | return code; |
49 | | |
50 | 7.36M | (*a)->size = size; |
51 | | |
52 | 7.36M | if (size > 0) { |
53 | | /* Start all the array entries pointing to null. |
54 | | * array_put will replace tehm. This ensures we always have a valid |
55 | | * object for every entry. pdfi_array_from_stack() doesn't do this |
56 | | * initialisation because we know how many obejcts there are in the array |
57 | | * and we have valid objects for each entry on the stack already created. |
58 | | */ |
59 | 71.8M | for (i=0;i<size;i++){ |
60 | 64.6M | (*a)->values[i] = PDF_NULL_OBJ; |
61 | 64.6M | } |
62 | 7.13M | } |
63 | 7.36M | return 0; |
64 | 7.36M | } |
65 | | |
66 | | /* This was defined in pdf_int.c until we moved the equivalent pdfi_dict_from_stack() into |
67 | | * pdf_dict.c, because we needed to be able to create dictionaries for images. We don't have |
68 | | * that need, but its less confusing to have the array_from_stack function defined in |
69 | | * here, similarly to the dictionary routine. |
70 | | */ |
71 | | int pdfi_array_from_stack(pdf_context *ctx, uint32_t indirect_num, uint32_t indirect_gen) |
72 | 7.36M | { |
73 | 7.36M | uint64_t index = 0; |
74 | 7.36M | pdf_array *a = NULL; |
75 | 7.36M | pdf_obj *o; |
76 | 7.36M | int code; |
77 | | |
78 | 7.36M | code = pdfi_count_to_mark(ctx, &index); |
79 | 7.36M | if (code < 0) |
80 | 82.1k | return code; |
81 | | |
82 | 7.28M | code = pdfi_array_alloc(ctx, index, &a); |
83 | 7.28M | if (code < 0) |
84 | 0 | return code; |
85 | | |
86 | 54.7M | while (index) { |
87 | 47.4M | o = ctx->stack_top[-1]; |
88 | 47.4M | code = pdfi_array_put(ctx, a, --index, o); |
89 | 47.4M | if (code < 0) { |
90 | 0 | (void)pdfi_clear_to_mark(ctx); |
91 | 0 | return code; |
92 | 0 | } |
93 | 47.4M | pdfi_pop(ctx, 1); |
94 | 47.4M | } |
95 | | |
96 | 7.28M | code = pdfi_clear_to_mark(ctx); |
97 | 7.28M | if (code < 0) |
98 | 0 | return code; |
99 | | |
100 | 7.28M | if (ctx->args.pdfdebug) |
101 | 7.28M | dmprintf (ctx->memory, " ]\n"); |
102 | | |
103 | 7.28M | a->indirect_num = indirect_num; |
104 | 7.28M | a->indirect_gen = indirect_gen; |
105 | | |
106 | 7.28M | code = pdfi_push(ctx, (pdf_obj *)a); |
107 | 7.28M | if (code < 0) |
108 | 0 | pdfi_free_array((pdf_obj *)a); |
109 | | |
110 | 7.28M | return code; |
111 | 7.28M | } |
112 | | |
113 | | int pdfi_array_fetch_recursing(pdf_context *ctx, pdf_array *a, uint64_t index, pdf_obj **o, bool setref, bool cache) |
114 | 319k | { |
115 | 319k | int code; |
116 | 319k | pdf_obj *obj; |
117 | | |
118 | 319k | *o = NULL; |
119 | | |
120 | 319k | if (pdfi_type_of(a) != PDF_ARRAY) |
121 | 0 | return_error(gs_error_typecheck); |
122 | | |
123 | 319k | if (index >= a->size) |
124 | 0 | return_error(gs_error_rangecheck); |
125 | 319k | obj = a->values[index]; |
126 | | |
127 | 319k | if (pdfi_type_of(obj) == PDF_INDIRECT) { |
128 | 120 | pdf_obj *o1 = NULL; |
129 | 120 | pdf_indirect_ref *r = (pdf_indirect_ref *)obj; |
130 | | |
131 | 120 | if (r->ref_object_num == a->object_num) |
132 | 2 | return_error(gs_error_circular_reference); |
133 | | |
134 | 118 | if (cache) |
135 | 118 | code = pdfi_deref_loop_detect(ctx, r->ref_object_num, r->ref_generation_num, &o1); |
136 | 0 | else |
137 | 0 | code = pdfi_deref_loop_detect_nocache(ctx, r->ref_object_num, r->ref_generation_num, &o1); |
138 | 118 | if (code < 0) |
139 | 23 | return code; |
140 | | |
141 | 95 | if (setref) |
142 | 95 | (void)pdfi_array_put(ctx, a, index, o1); |
143 | 95 | obj = o1; |
144 | 319k | } else { |
145 | 319k | if (ctx->loop_detection != NULL && (uintptr_t)obj > TOKEN__LAST_KEY && obj->object_num != 0) |
146 | 40 | if (pdfi_loop_detector_check_object(ctx, obj->object_num)) |
147 | 0 | return gs_note_error(gs_error_circular_reference); |
148 | 319k | pdfi_countup(obj); |
149 | 319k | } |
150 | | |
151 | 319k | *o = obj; |
152 | 319k | return 0; |
153 | 319k | } |
154 | | |
155 | | /* Fetch object from array, resolving indirect reference if needed |
156 | | * setref -- indicates whether to replace indirect ref with the object |
157 | | */ |
158 | | int pdfi_array_fetch(pdf_context *ctx, pdf_array *a, uint64_t index, pdf_obj **o, bool setref, bool cache) |
159 | 106M | { |
160 | 106M | int code; |
161 | 106M | pdf_obj *obj; |
162 | | |
163 | 106M | *o = NULL; |
164 | | |
165 | 106M | if (pdfi_type_of(a) != PDF_ARRAY) |
166 | 723 | return_error(gs_error_typecheck); |
167 | | |
168 | 106M | if (index >= a->size) |
169 | 11.7k | return_error(gs_error_rangecheck); |
170 | 106M | obj = a->values[index]; |
171 | | |
172 | 106M | if (pdfi_type_of(obj) == PDF_INDIRECT) { |
173 | 765k | pdf_obj *o1 = NULL; |
174 | 765k | pdf_indirect_ref *r = (pdf_indirect_ref *)obj; |
175 | | |
176 | 765k | if (r->ref_object_num == a->object_num) |
177 | 15 | return_error(gs_error_circular_reference); |
178 | | |
179 | 765k | if (cache) |
180 | 753k | code = pdfi_deref_loop_detect(ctx, r->ref_object_num, r->ref_generation_num, &o1); |
181 | 11.1k | else |
182 | 11.1k | code = pdfi_deref_loop_detect_nocache(ctx, r->ref_object_num, r->ref_generation_num, &o1); |
183 | 765k | if (code < 0) |
184 | 207k | return code; |
185 | | |
186 | 557k | if (setref) |
187 | 550k | (void)pdfi_array_put(ctx, a, index, o1); |
188 | 557k | obj = o1; |
189 | 105M | } else { |
190 | 105M | pdfi_countup(obj); |
191 | 105M | } |
192 | | |
193 | 106M | *o = obj; |
194 | 106M | return 0; |
195 | 106M | } |
196 | | |
197 | | /* Get element from array without resolving PDF_INDIRECT dereferences. |
198 | | * It looks to me like some usages need to do the checking themselves to |
199 | | * avoid circular references? Can remove this if not really needed. |
200 | | */ |
201 | | int pdfi_array_get_no_deref(pdf_context *ctx, pdf_array *a, uint64_t index, pdf_obj **o) |
202 | 1.17M | { |
203 | 1.17M | if (pdfi_type_of(a) != PDF_ARRAY) |
204 | 0 | return_error(gs_error_typecheck); |
205 | | |
206 | 1.17M | if (index >= a->size) |
207 | 0 | return_error(gs_error_rangecheck); |
208 | | |
209 | 1.17M | *o = a->values[index]; |
210 | 1.17M | pdfi_countup(*o); |
211 | 1.17M | return 0; |
212 | 1.17M | } |
213 | | |
214 | | /* Same as pdfi_array_get() but doesn't replace indirect ref with a new object. |
215 | | */ |
216 | | int pdfi_array_get_no_store_R(pdf_context *ctx, pdf_array *a, uint64_t index, pdf_obj **o) |
217 | 670k | { |
218 | 670k | int code; |
219 | | |
220 | 670k | code = pdfi_array_fetch(ctx, a, index, o, false, false); |
221 | 670k | if (code < 0) return code; |
222 | | |
223 | 670k | return 0; |
224 | 670k | } |
225 | | |
226 | | /* Get value from pdfi_array. |
227 | | * Handles type-checking and resolving indirect references. |
228 | | */ |
229 | | int pdfi_array_get_type(pdf_context *ctx, pdf_array *a, uint64_t index, |
230 | | pdf_obj_type type, pdf_obj **o) |
231 | 25.9M | { |
232 | 25.9M | int code; |
233 | | |
234 | 25.9M | code = pdfi_array_get(ctx, a, index, o); |
235 | 25.9M | if (code < 0) |
236 | 92.5k | return code; |
237 | | |
238 | 25.8M | if (pdfi_type_of(*o) != type) { |
239 | 16.4k | pdfi_countdown(*o); |
240 | 16.4k | *o = NULL; |
241 | 16.4k | return_error(gs_error_typecheck); |
242 | 16.4k | } |
243 | 25.8M | return 0; |
244 | 25.8M | } |
245 | | |
246 | | int pdfi_array_get_int(pdf_context *ctx, pdf_array *a, uint64_t index, int64_t *i) |
247 | 33.1k | { |
248 | 33.1k | int code; |
249 | 33.1k | pdf_obj *n; |
250 | | |
251 | 33.1k | code = pdfi_array_get(ctx, a, index, &n); |
252 | 33.1k | if (code < 0) |
253 | 10 | return code; |
254 | 33.1k | code = pdfi_obj_to_int(ctx, n, i); |
255 | 33.1k | pdfi_countdown(n); |
256 | 33.1k | return code; |
257 | 33.1k | } |
258 | | |
259 | | int pdfi_array_get_number(pdf_context *ctx, pdf_array *a, uint64_t index, double *d) |
260 | 9.08M | { |
261 | 9.08M | int code; |
262 | 9.08M | pdf_obj *n; |
263 | | |
264 | 9.08M | code = pdfi_array_get(ctx, a, index, &n); |
265 | 9.08M | if (code < 0) |
266 | 10 | return code; |
267 | | |
268 | 9.08M | code = pdfi_obj_to_real(ctx, n, d); |
269 | 9.08M | pdfi_countdown(n); |
270 | | |
271 | 9.08M | return code; |
272 | 9.08M | } |
273 | | |
274 | | /* Check whether a particular object is in an array. |
275 | | * If index is not NULL, fill it in with the index of the object. |
276 | | * Note that this will resolve indirect references if needed. |
277 | | */ |
278 | | bool pdfi_array_known(pdf_context *ctx, pdf_array *a, pdf_obj *o, int *index) |
279 | 16.0k | { |
280 | 16.0k | int i; |
281 | | |
282 | 16.0k | if (pdfi_type_of(a) != PDF_ARRAY) |
283 | 0 | return_error(gs_error_typecheck); |
284 | | |
285 | 7.25M | for (i=0; i < a->size; i++) { |
286 | 7.25M | pdf_obj *val; |
287 | 7.25M | int code; |
288 | | |
289 | 7.25M | code = pdfi_array_fetch(ctx, a, i, &val, true, true); |
290 | 7.25M | if (code < 0) |
291 | 112k | continue; |
292 | 7.13M | if (pdf_object_num(val) == pdf_object_num(o)) { |
293 | 15.7k | if (index != NULL) *index = i; |
294 | 15.7k | pdfi_countdown(val); |
295 | 15.7k | return true; |
296 | 15.7k | } |
297 | 7.12M | pdfi_countdown(val); |
298 | 7.12M | } |
299 | 255 | return false; |
300 | 16.0k | } |
301 | | |
302 | | int pdfi_array_put(pdf_context *ctx, pdf_array *a, uint64_t index, pdf_obj *o) |
303 | 67.4M | { |
304 | 67.4M | if (pdfi_type_of(a) != PDF_ARRAY) |
305 | 0 | return_error(gs_error_typecheck); |
306 | | |
307 | 67.4M | if (index >= a->size) |
308 | 0 | return_error(gs_error_rangecheck); |
309 | | |
310 | 67.4M | pdfi_countdown(a->values[index]); |
311 | 67.4M | a->values[index] = o; |
312 | 67.4M | pdfi_countup(o); |
313 | 67.4M | return 0; |
314 | 67.4M | } |
315 | | |
316 | | int pdfi_array_put_int(pdf_context *ctx, pdf_array *a, uint64_t index, int64_t val) |
317 | 1 | { |
318 | 1 | int code; |
319 | 1 | pdf_num *obj; |
320 | | |
321 | 1 | if (pdfi_type_of(a) != PDF_ARRAY) |
322 | 0 | return_error(gs_error_typecheck); |
323 | | |
324 | 1 | code = pdfi_object_alloc(ctx, PDF_INT, 0, (pdf_obj **)&obj); |
325 | 1 | obj->value.i = val; |
326 | 1 | if (code < 0) |
327 | 0 | return code; |
328 | | |
329 | 1 | return pdfi_array_put(ctx, a, index, (pdf_obj *)obj); |
330 | 1 | } |
331 | | |
332 | | int pdfi_array_put_real(pdf_context *ctx, pdf_array *a, uint64_t index, double val) |
333 | 1.52k | { |
334 | 1.52k | int code; |
335 | 1.52k | pdf_num *obj; |
336 | | |
337 | 1.52k | if (pdfi_type_of(a) != PDF_ARRAY) |
338 | 0 | return_error(gs_error_typecheck); |
339 | | |
340 | 1.52k | code = pdfi_object_alloc(ctx, PDF_REAL, 0, (pdf_obj **)&obj); |
341 | 1.52k | obj->value.d = val; |
342 | 1.52k | if (code < 0) |
343 | 0 | return code; |
344 | | |
345 | 1.52k | return pdfi_array_put(ctx, a, index, (pdf_obj *)obj); |
346 | 1.52k | } |
347 | | |
348 | | /* Strictly speaking the normalize_rect isn't really part of the PDF array |
349 | | * processing, but its very likely that any time we want to use it, the |
350 | | * rectangle will have come from a PDF array in a PDF file so it makes |
351 | | * sense to have it here. |
352 | | */ |
353 | | |
354 | | /* Normalize rectangle */ |
355 | | void pdfi_normalize_rect(pdf_context *ctx, gs_rect *rect) |
356 | 205k | { |
357 | 205k | double temp; |
358 | | |
359 | | /* Normalize the rectangle */ |
360 | 205k | if (rect->p.x > rect->q.x) { |
361 | 357 | temp = rect->p.x; |
362 | 357 | rect->p.x = rect->q.x; |
363 | 357 | rect->q.x = temp; |
364 | 357 | } |
365 | 205k | if (rect->p.y > rect->q.y) { |
366 | 113 | temp = rect->p.y; |
367 | 113 | rect->p.y = rect->q.y; |
368 | 113 | rect->q.y = temp; |
369 | 113 | } |
370 | 205k | } |
371 | | |
372 | | /* |
373 | | * Turn an Array into a gs_rect. If Array is NULL, makes a tiny rect |
374 | | */ |
375 | | int pdfi_array_to_gs_rect(pdf_context *ctx, pdf_array *array, gs_rect *rect) |
376 | 572k | { |
377 | 572k | double number; |
378 | 572k | int code = 0; |
379 | | |
380 | | /* Init to tiny rect to allow sane continuation on errors */ |
381 | 572k | rect->p.x = 0.0; |
382 | 572k | rect->p.y = 0.0; |
383 | 572k | rect->q.x = 1.0; |
384 | 572k | rect->q.y = 1.0; |
385 | | |
386 | | /* Identity matrix if no array */ |
387 | 572k | if (array == NULL || pdfi_type_of(array) != PDF_ARRAY) { |
388 | 1.27k | return 0; |
389 | 1.27k | } |
390 | 570k | if (pdfi_array_size(array) != 4) { |
391 | 57 | return_error(gs_error_rangecheck); |
392 | 57 | } |
393 | 570k | code = pdfi_array_get_number(ctx, array, 0, &number); |
394 | 570k | if (code < 0) goto errorExit; |
395 | 570k | rect->p.x = (float)number; |
396 | 570k | code = pdfi_array_get_number(ctx, array, 1, &number); |
397 | 570k | if (code < 0) goto errorExit; |
398 | 570k | rect->p.y = (float)number; |
399 | 570k | code = pdfi_array_get_number(ctx, array, 2, &number); |
400 | 570k | if (code < 0) goto errorExit; |
401 | 570k | rect->q.x = (float)number; |
402 | 570k | code = pdfi_array_get_number(ctx, array, 3, &number); |
403 | 570k | if (code < 0) goto errorExit; |
404 | 570k | rect->q.y = (float)number; |
405 | | |
406 | 570k | return 0; |
407 | | |
408 | 8 | errorExit: |
409 | 8 | return code; |
410 | 570k | } |
411 | | |
412 | | /* Create a new PDF array object with 4 entires, and store the values from a |
413 | | * gs_rect to it. |
414 | | */ |
415 | | int pdfi_gs_rect_to_array(pdf_context *ctx, gs_rect *rect, pdf_array **new_array) |
416 | 4.56k | { |
417 | 4.56k | pdf_num *num = NULL; |
418 | 4.56k | int code = 0; |
419 | | |
420 | 4.56k | code = pdfi_array_alloc(ctx, 4, new_array); |
421 | 4.56k | if (code < 0) |
422 | 0 | return code; |
423 | | |
424 | 4.56k | pdfi_countup(*new_array); |
425 | | |
426 | 4.56k | code = pdfi_num_alloc(ctx, rect->p.x, &num); |
427 | 4.56k | if (code < 0) |
428 | 0 | goto error; |
429 | | |
430 | 4.56k | code = pdfi_array_put(ctx, *new_array, 0, (pdf_obj *)num); |
431 | 4.56k | if (code < 0) |
432 | 0 | goto error; |
433 | | |
434 | 4.56k | code = pdfi_num_alloc(ctx, rect->p.y, &num); |
435 | 4.56k | if (code < 0) |
436 | 0 | goto error; |
437 | | |
438 | 4.56k | code = pdfi_array_put(ctx, *new_array, 1, (pdf_obj *)num); |
439 | 4.56k | if (code < 0) |
440 | 0 | goto error; |
441 | | |
442 | 4.56k | code = pdfi_num_alloc(ctx, rect->q.x, &num); |
443 | 4.56k | if (code < 0) |
444 | 0 | goto error; |
445 | | |
446 | 4.56k | code = pdfi_array_put(ctx, *new_array, 2, (pdf_obj *)num); |
447 | 4.56k | if (code < 0) |
448 | 0 | goto error; |
449 | | |
450 | 4.56k | code = pdfi_num_alloc(ctx, rect->q.y, &num); |
451 | 4.56k | if (code < 0) |
452 | 0 | goto error; |
453 | | |
454 | 4.56k | code = pdfi_array_put(ctx, *new_array, 3, (pdf_obj *)num); |
455 | 4.56k | if (code < 0) |
456 | 0 | goto error; |
457 | | |
458 | 4.56k | return 0; |
459 | | |
460 | 0 | error: |
461 | 0 | pdfi_countdown(new_array); |
462 | 0 | return code; |
463 | 4.56k | } |
464 | | |
465 | | /* Turn a /Matrix Array into a gs_matrix. If Array is NULL, makes an identity matrix */ |
466 | | int pdfi_array_to_gs_matrix(pdf_context *ctx, pdf_array *array, gs_matrix *mat) |
467 | 373k | { |
468 | 373k | double number; |
469 | 373k | int code = 0; |
470 | | |
471 | | /* Init to identity matrix to allow sane continuation on errors */ |
472 | 373k | mat->xx = 1.0; |
473 | 373k | mat->xy = 0.0; |
474 | 373k | mat->yx = 0.0; |
475 | 373k | mat->yy = 1.0; |
476 | 373k | mat->tx = 0.0; |
477 | 373k | mat->ty = 0.0; |
478 | | |
479 | | /* Identity matrix if no array */ |
480 | 373k | if (array == NULL || pdfi_type_of(array) != PDF_ARRAY) { |
481 | 294k | return 0; |
482 | 294k | } |
483 | 79.9k | if (pdfi_array_size(array) != 6) { |
484 | 33 | return_error(gs_error_rangecheck); |
485 | 33 | } |
486 | 79.8k | code = pdfi_array_get_number(ctx, array, 0, &number); |
487 | 79.8k | if (code < 0) goto errorExit; |
488 | 79.8k | mat->xx = (float)number; |
489 | 79.8k | code = pdfi_array_get_number(ctx, array, 1, &number); |
490 | 79.8k | if (code < 0) goto errorExit; |
491 | 79.8k | mat->xy = (float)number; |
492 | 79.8k | code = pdfi_array_get_number(ctx, array, 2, &number); |
493 | 79.8k | if (code < 0) goto errorExit; |
494 | 79.8k | mat->yx = (float)number; |
495 | 79.8k | code = pdfi_array_get_number(ctx, array, 3, &number); |
496 | 79.8k | if (code < 0) goto errorExit; |
497 | 79.8k | mat->yy = (float)number; |
498 | 79.8k | code = pdfi_array_get_number(ctx, array, 4, &number); |
499 | 79.8k | if (code < 0) goto errorExit; |
500 | 79.8k | mat->tx = (float)number; |
501 | 79.8k | code = pdfi_array_get_number(ctx, array, 5, &number); |
502 | 79.8k | if (code < 0) goto errorExit; |
503 | 79.8k | mat->ty = (float)number; |
504 | 79.8k | return 0; |
505 | | |
506 | 3 | errorExit: |
507 | 3 | return code; |
508 | 79.8k | } |
509 | | |
510 | | /* Turn a pdf_array into a double array of specified size */ |
511 | | int pdfi_array_to_num_array(pdf_context *ctx, pdf_array *array, double *out, int offset, int size) |
512 | 13.4k | { |
513 | 13.4k | int i; |
514 | 13.4k | int code; |
515 | 13.4k | double num; |
516 | | |
517 | 63.1k | for (i=0; i<size; i++) { |
518 | 49.7k | code = pdfi_array_get_number(ctx, array, offset+i, &num); |
519 | 49.7k | if (code < 0) |
520 | 0 | return code; |
521 | 49.7k | out[i] = num; |
522 | 49.7k | } |
523 | 13.4k | return 0; |
524 | 13.4k | } |
525 | | |
526 | | /* Transform a BBox by a matrix (from zmatrix.c/zbbox_transform())*/ |
527 | | void |
528 | | pdfi_bbox_transform(pdf_context *ctx, gs_rect *bbox, gs_matrix *matrix) |
529 | 157k | { |
530 | 157k | gs_point aa, az, za, zz; |
531 | 157k | double temp; |
532 | | |
533 | 157k | gs_point_transform(bbox->p.x, bbox->p.y, matrix, &aa); |
534 | 157k | gs_point_transform(bbox->p.x, bbox->q.y, matrix, &az); |
535 | 157k | gs_point_transform(bbox->q.x, bbox->p.y, matrix, &za); |
536 | 157k | gs_point_transform(bbox->q.x, bbox->q.y, matrix, &zz); |
537 | | |
538 | 157k | if ( aa.x > az.x) |
539 | 320 | temp = aa.x, aa.x = az.x, az.x = temp; |
540 | 157k | if ( za.x > zz.x) |
541 | 320 | temp = za.x, za.x = zz.x, zz.x = temp; |
542 | 157k | if ( za.x < aa.x) |
543 | 32 | aa.x = za.x; /* min */ |
544 | 157k | if ( az.x > zz.x) |
545 | 32 | zz.x = az.x; /* max */ |
546 | | |
547 | 157k | if ( aa.y > az.y) |
548 | 328 | temp = aa.y, aa.y = az.y, az.y = temp; |
549 | 157k | if ( za.y > zz.y) |
550 | 328 | temp = za.y, za.y = zz.y, zz.y = temp; |
551 | 157k | if ( za.y < aa.y) |
552 | 19 | aa.y = za.y; /* min */ |
553 | 157k | if ( az.y > zz.y) |
554 | 19 | zz.y = az.y; /* max */ |
555 | | |
556 | 157k | bbox->p.x = aa.x; |
557 | 157k | bbox->p.y = aa.y; |
558 | 157k | bbox->q.x = zz.x; |
559 | 157k | bbox->q.y = zz.y; |
560 | 157k | } |