| 1 |
/* |
| 2 |
|
| 3 |
Copyright 2009-2011 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 |
#include "pdf/pdfpage.h" |
| 24 |
|
| 25 |
/*tex The form being output: */ |
| 26 |
|
| 27 |
int pdf_cur_form; |
| 28 |
|
| 29 |
void pdf_place_form(PDF pdf, halfword p) |
| 30 |
{ |
| 31 |
scaled_whd nat, tex; |
| 32 |
scaled x, y; |
| 33 |
pdffloat cm[6]; |
| 34 |
pdfstructure *q = pdf->pstruct; |
| 35 |
int r = 6; |
| 36 |
int objnum = rule_index(p); |
| 37 |
nat.wd = obj_xform_width(pdf, objnum); |
| 38 |
nat.ht = obj_xform_height(pdf, objnum); |
| 39 |
nat.dp = obj_xform_depth(pdf, objnum); |
| 40 |
/*tex No transform yet: */ |
| 41 |
tex.wd = width(p); |
| 42 |
tex.ht = height(p); |
| 43 |
tex.dp = depth(p); |
| 44 |
if (nat.wd != tex.wd || nat.ht != tex.ht || nat.dp != tex.dp) { |
| 45 |
x = ext_xn_over_d(ten_pow[r], tex.wd, nat.wd); |
| 46 |
y = ext_xn_over_d(ten_pow[r], tex.dp + tex.ht, nat.dp + nat.ht); |
| 47 |
} else |
| 48 |
x = y = ten_pow[r]; |
| 49 |
setpdffloat(cm[0], x, r); |
| 50 |
setpdffloat(cm[1], 0, r); |
| 51 |
setpdffloat(cm[2], 0, r); |
| 52 |
setpdffloat(cm[3], y, r); |
| 53 |
pdf_goto_pagemode(pdf); |
| 54 |
(void) calc_pdfpos(q, pdf->posstruct->pos); |
| 55 |
cm[4] = q->cm[4]; |
| 56 |
cm[5] = q->cm[5]; |
| 57 |
pdf_puts(pdf, "q\n"); |
| 58 |
pdf_print_cm(pdf, cm); |
| 59 |
pdf_printf(pdf, "/Fm%d", (int) obj_info(pdf, objnum)); |
| 60 |
pdf_print_resname_prefix(pdf); |
| 61 |
pdf_puts(pdf, " Do\nQ\n"); |
| 62 |
addto_page_resources(pdf, obj_type_xform, objnum); |
| 63 |
} |
| 64 |
|
| 65 |
/*tex We will store token lists as strings too. */ |
| 66 |
|
| 67 |
void scan_pdfxform(PDF pdf) |
| 68 |
{ |
| 69 |
int k; |
| 70 |
halfword p; |
| 71 |
pdf->xform_count++; |
| 72 |
k = pdf_create_obj(pdf, obj_type_xform, pdf->xform_count); |
| 73 |
set_obj_data_ptr(pdf, k, pdf_get_mem(pdf, pdfmem_xform_size)); |
| 74 |
if (scan_keyword("type")) { |
| 75 |
scan_int(); |
| 76 |
set_obj_xform_type(pdf, k, cur_val); |
| 77 |
} else { |
| 78 |
set_obj_xform_type(pdf, k, 0); |
| 79 |
} |
| 80 |
if (scan_keyword("attr")) { |
| 81 |
scan_toks(false, true); |
| 82 |
set_obj_xform_attr(pdf, k, def_ref); |
| 83 |
} else { |
| 84 |
set_obj_xform_attr(pdf, k, null); |
| 85 |
} |
| 86 |
set_obj_xform_attr_str(pdf, k, null); |
| 87 |
if (scan_keyword("resources")) { |
| 88 |
scan_toks(false, true); |
| 89 |
set_obj_xform_resources(pdf, k, def_ref); |
| 90 |
} else { |
| 91 |
set_obj_xform_resources(pdf, k, null); |
| 92 |
} |
| 93 |
if (scan_keyword("margin")) { |
| 94 |
scan_int(); |
| 95 |
set_obj_xform_margin(pdf, k, cur_val); |
| 96 |
} else { |
| 97 |
set_obj_xform_margin(pdf, k, pdf_xform_margin); |
| 98 |
} |
| 99 |
set_obj_xform_resources_str(pdf, k, null); |
| 100 |
scan_int(); |
| 101 |
p = box(cur_val); |
| 102 |
if (p == null) |
| 103 |
normal_error("pdf backend", "xforms cannot be used with a void box"); |
| 104 |
/*tex Save the pointer to the box: */ |
| 105 |
set_obj_xform_box(pdf, k, p); |
| 106 |
set_obj_xform_width(pdf, k, width(p)); |
| 107 |
set_obj_xform_height(pdf, k, height(p)); |
| 108 |
set_obj_xform_depth(pdf, k, depth(p)); |
| 109 |
box(cur_val) = null; |
| 110 |
last_saved_box_index = k; |
| 111 |
} |
| 112 |
|
| 113 |
void scan_pdfrefxform(PDF pdf) |
| 114 |
{ |
| 115 |
scaled_whd alt_rule, dim, nat; |
| 116 |
alt_rule = scan_alt_rule(); |
| 117 |
scan_int(); |
| 118 |
check_obj_type(pdf, obj_type_xform, cur_val); |
| 119 |
tail_append(new_rule(box_rule)); |
| 120 |
nat.wd = obj_xform_width(pdf, cur_val); |
| 121 |
nat.ht = obj_xform_height(pdf, cur_val); |
| 122 |
nat.dp = obj_xform_depth(pdf, cur_val); |
| 123 |
if (alt_rule.wd != null_flag || alt_rule.ht != null_flag || alt_rule.dp != null_flag) { |
| 124 |
dim = tex_scale(nat, alt_rule); |
| 125 |
} else { |
| 126 |
dim = nat; |
| 127 |
} |
| 128 |
width(tail_par) = dim.wd; |
| 129 |
height(tail_par) = dim.ht; |
| 130 |
depth(tail_par) = dim.dp; |
| 131 |
rule_index(tail_par) = cur_val; |
| 132 |
} |