beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / pdf / pdfsaverestore.w
blob0d91de54496842f74dd8d6b66e97308be81428c3
1 % pdfsaverestore.w
3 % Copyright 2010 Taco Hoekwater <taco@@luatex.org>
5 % This file is part of LuaTeX.
7 % LuaTeX is free software; you can redistribute it and/or modify it under
8 % the terms of the GNU General Public License as published by the Free
9 % Software Foundation; either version 2 of the License, or (at your
10 % option) any later version.
12 % LuaTeX is distributed in the hope that it will be useful, but WITHOUT
13 % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 % FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 % License for more details.
17 % You should have received a copy of the GNU General Public License along
18 % with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
20 @ @c
22 #include "ptexlib.h"
24 @ @c
25 pos_entry *pos_stack = 0; /* the stack */
26 int pos_stack_size = 0; /* initially empty */
27 int pos_stack_used = 0; /* used entries */
29 @ @c
30 static void checkpdfsave(scaledpos pos)
32 pos_entry *new_stack;
33 if (pos_stack_used >= pos_stack_size) {
34 pos_stack_size += STACK_INCREMENT;
35 new_stack = xtalloc((unsigned) pos_stack_size, pos_entry);
36 memcpy((void *) new_stack, (void *) pos_stack, (unsigned) pos_stack_used * sizeof(pos_entry));
37 xfree(pos_stack);
38 pos_stack = new_stack;
40 pos_stack[pos_stack_used].pos.h = pos.h;
41 pos_stack[pos_stack_used].pos.v = pos.v;
42 if (global_shipping_mode == SHIPPING_PAGE) {
43 pos_stack[pos_stack_used].matrix_stack = matrix_stack_used;
45 pos_stack_used++;
48 @ @c
49 static void checkpdfrestore(scaledpos pos)
51 scaledpos diff;
52 if (pos_stack_used == 0) {
53 normal_warning("pdf backend", "'restore' is missing a 'save'");
54 return;
56 pos_stack_used--;
57 diff.h = pos.h - pos_stack[pos_stack_used].pos.h;
58 diff.v = pos.v - pos_stack[pos_stack_used].pos.v;
59 if (diff.h != 0 || diff.v != 0) {
60 formatted_warning("pdf backend","misplaced 'restore' by (%dsp, %dsp)", (int) diff.h, (int) diff.v);
62 if (global_shipping_mode == SHIPPING_PAGE) {
63 matrix_stack_used = pos_stack[pos_stack_used].matrix_stack;
67 @ @c
68 void pdf_out_save(PDF pdf, halfword p)
70 (void) p;
71 checkpdfsave(pdf->posstruct->pos);
72 pdf_literal(pdf, 'q', set_origin, false);
75 @ @c
76 void pdf_out_restore(PDF pdf, halfword p)
78 (void) p;
79 checkpdfrestore(pdf->posstruct->pos);
80 pdf_literal(pdf, 'Q', set_origin, false);