| 1 |
/* |
| 2 |
|
| 3 |
Copyright 2010 Taco Hoekwater <[email protected]> |
| 4 |
|
| 5 |
This file is part of LuaTeX. |
| 6 |
|
| 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. |
| 11 |
|
| 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. |
| 16 |
|
| 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/>. |
| 19 |
|
| 20 |
*/ |
| 21 |
|
| 22 |
#include "ptexlib.h" |
| 23 |
|
| 24 |
pos_entry *pos_stack = 0; |
| 25 |
int pos_stack_size = 0; |
| 26 |
int pos_stack_used = 0; |
| 27 |
|
| 28 |
static void checkpdfsave(scaledpos pos) |
| 29 |
{ |
| 30 |
pos_entry *new_stack; |
| 31 |
if (pos_stack_used >= pos_stack_size) { |
| 32 |
pos_stack_size += STACK_INCREMENT; |
| 33 |
new_stack = xtalloc((unsigned) pos_stack_size, pos_entry); |
| 34 |
memcpy((void *) new_stack, (void *) pos_stack, (unsigned) pos_stack_used * sizeof(pos_entry)); |
| 35 |
xfree(pos_stack); |
| 36 |
pos_stack = new_stack; |
| 37 |
} |
| 38 |
pos_stack[pos_stack_used].pos.h = pos.h; |
| 39 |
pos_stack[pos_stack_used].pos.v = pos.v; |
| 40 |
if (global_shipping_mode == SHIPPING_PAGE) { |
| 41 |
pos_stack[pos_stack_used].matrix_stack = matrix_stack_used; |
| 42 |
} |
| 43 |
pos_stack_used++; |
| 44 |
} |
| 45 |
|
| 46 |
static void checkpdfrestore(scaledpos pos) |
| 47 |
{ |
| 48 |
scaledpos diff; |
| 49 |
if (pos_stack_used == 0) { |
| 50 |
normal_warning("pdf backend", "'restore' is missing a 'save'"); |
| 51 |
return; |
| 52 |
} |
| 53 |
pos_stack_used--; |
| 54 |
diff.h = pos.h - pos_stack[pos_stack_used].pos.h; |
| 55 |
diff.v = pos.v - pos_stack[pos_stack_used].pos.v; |
| 56 |
if (diff.h != 0 || diff.v != 0) { |
| 57 |
formatted_warning("pdf backend","misplaced 'restore' by (%dsp, %dsp)", (int) diff.h, (int) diff.v); |
| 58 |
} |
| 59 |
if (global_shipping_mode == SHIPPING_PAGE) { |
| 60 |
matrix_stack_used = pos_stack[pos_stack_used].matrix_stack; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
void pdf_out_save(PDF pdf, halfword p) |
| 65 |
{ |
| 66 |
(void) p; |
| 67 |
checkpdfsave(pdf->posstruct->pos); |
| 68 |
pdf_literal(pdf, 'q', set_origin, false); |
| 69 |
} |
| 70 |
|
| 71 |
void pdf_out_restore(PDF pdf, halfword p) |
| 72 |
{ |
| 73 |
(void) p; |
| 74 |
checkpdfrestore(pdf->posstruct->pos); |
| 75 |
pdf_literal(pdf, 'Q', set_origin, false); |
| 76 |
} |