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