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
/>.
25 pos_entry
*pos_stack
= 0; /* the stack
*/
26 int pos_stack_size
= 0; /* initially empty
*/
27 int pos_stack_used
= 0; /* used entries
*/
30 static void checkpdfsave
(scaledpos pos
)
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
));
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
;
49 static void checkpdfrestore
(scaledpos pos
)
52 if
(pos_stack_used
== 0) {
53 normal_warning
("pdf backend", "'restore' is missing a 'save'");
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
;
68 void pdf_out_save
(PDF pdf
, halfword p
)
71 checkpdfsave
(pdf-
>posstruct-
>pos
);
72 pdf_literal
(pdf
, 'q'
, set_origin
, false
);
76 void pdf_out_restore
(PDF pdf
, halfword p
)
79 checkpdfrestore
(pdf-
>posstruct-
>pos
);
80 pdf_literal
(pdf
, 'Q'
, set_origin
, false
);