beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / pdf / pdfxform.w
blob962acb0f031a9e7a3630143b476d56e204c8d921
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 #define box(A) eqtb[box_base+(A)].hh.rh
27 int pdf_cur_form; /* the form being output */
29 void pdf_place_form(PDF pdf, halfword p)
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 /* 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);
65 /* we will store token lists as strings too */
67 @ @c
68 void scan_pdfxform(PDF pdf)
70 int k;
71 halfword p;
72 pdf->xform_count++;
73 k = pdf_create_obj(pdf, obj_type_xform, pdf->xform_count);
74 set_obj_data_ptr(pdf, k, pdf_get_mem(pdf, pdfmem_xform_size));
75 if (scan_keyword("attr")) {
76 scan_toks(false, true);
77 set_obj_xform_attr(pdf, k, def_ref);
78 } else {
79 set_obj_xform_attr(pdf, k, null);
81 set_obj_xform_attr_str(pdf, k, null);
82 if (scan_keyword("resources")) {
83 scan_toks(false, true);
84 set_obj_xform_resources(pdf, k, def_ref);
85 } else {
86 set_obj_xform_resources(pdf, k, null);
88 set_obj_xform_resources_str(pdf, k, null);
89 scan_int();
90 p = box(cur_val);
91 if (p == null)
92 normal_error("pdf backend", "xforms cannot be used with a void box");
93 set_obj_xform_box(pdf, k, p); /* save pointer to the box */
94 set_obj_xform_width(pdf, k, width(p));
95 set_obj_xform_height(pdf, k, height(p));
96 set_obj_xform_depth(pdf, k, depth(p));
97 box(cur_val) = null;
98 last_saved_box_index = k;
101 @ @c
102 #define tail cur_list.tail_field
104 void scan_pdfrefxform(PDF pdf)
106 scaled_whd alt_rule, dim, nat;
107 alt_rule = scan_alt_rule(); /* scans |<rule spec>| to |alt_rule| */
108 scan_int();
109 check_obj_type(pdf, obj_type_xform, cur_val);
110 tail_append(new_rule(box_rule));
111 nat.wd = obj_xform_width(pdf, cur_val);
112 nat.ht = obj_xform_height(pdf, cur_val);
113 nat.dp = obj_xform_depth(pdf, cur_val);
114 if (alt_rule.wd != null_flag || alt_rule.ht != null_flag || alt_rule.dp != null_flag) {
115 dim = tex_scale(nat, alt_rule);
116 } else {
117 dim = nat;
119 width(tail) = dim.wd;
120 height(tail) = dim.ht;
121 depth(tail) = dim.dp;
122 rule_index(tail) = cur_val;