1% pdfxform.w 2% 3% Copyright 2009-2011 Taco Hoekwater <taco@@luatex.org> 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@ @c 21 22 23#include "ptexlib.h" 24 25@ @c 26#include "pdf/pdfpage.h" 27 28@ @c 29#define box(A) eqtb[box_base+(A)].hh.rh 30 31int pdf_cur_form; /* the form being output */ 32 33void pdf_place_form(PDF pdf, halfword p) 34{ 35 scaled_whd nat, tex; 36 scaled x, y; 37 pdffloat cm[6]; 38 pdfstructure *q = pdf->pstruct; 39 int r = 6, objnum = pdf_xform_objnum(p); 40 nat.wd = obj_xform_width(pdf, objnum); 41 nat.ht = obj_xform_height(pdf, objnum); 42 nat.dp = obj_xform_depth(pdf, objnum); 43 /* no transform yet */ 44 tex.wd = width(p); 45 tex.ht = height(p); 46 tex.dp = depth(p); 47 if (nat.wd != tex.wd || nat.ht != tex.ht || nat.dp != tex.dp) { 48 x = ext_xn_over_d(ten_pow[r], tex.wd, nat.wd); 49 y = ext_xn_over_d(ten_pow[r], tex.dp + tex.ht, nat.dp + nat.ht); 50 } else 51 x = y = ten_pow[r]; 52 setpdffloat(cm[0], x, r); 53 setpdffloat(cm[1], 0, r); 54 setpdffloat(cm[2], 0, r); 55 setpdffloat(cm[3], y, r); 56 pdf_goto_pagemode(pdf); 57 (void) calc_pdfpos(q, pdf->posstruct->pos); 58 cm[4] = q->cm[4]; 59 cm[5] = q->cm[5]; 60 pdf_puts(pdf, "q\n"); 61 pdf_print_cm(pdf, cm); 62 pdf_printf(pdf, "/Fm%d", (int) obj_info(pdf, objnum)); 63 pdf_print_resname_prefix(pdf); 64 pdf_puts(pdf, " Do\nQ\n"); 65 addto_page_resources(pdf, obj_type_xform, objnum); 66} 67 68@ @c 69void scan_pdfxform(PDF pdf) 70{ 71 int k; 72 halfword p; 73 pdf->xform_count++; 74 k = pdf_create_obj(pdf, obj_type_xform, pdf->xform_count); 75 set_obj_data_ptr(pdf, k, pdf_get_mem(pdf, pdfmem_xform_size)); 76 if (scan_keyword("attr")) { 77 scan_pdf_ext_toks(); 78 set_obj_xform_attr(pdf, k, def_ref); 79 } else { 80 set_obj_xform_attr(pdf, k, null); 81 } 82 if (scan_keyword("resources")) { 83 scan_pdf_ext_toks(); 84 set_obj_xform_resources(pdf, k, def_ref); 85 } else { 86 set_obj_xform_resources(pdf, k, null); 87 } 88 scan_int(); 89 p = box(cur_val); 90 if (p == null) 91 pdf_error("ext1", "\\pdfxform cannot be used with a void box"); 92 set_obj_xform_box(pdf, k, p); /* save pointer to the box */ 93 set_obj_xform_width(pdf, k, width(p)); 94 set_obj_xform_height(pdf, k, height(p)); 95 set_obj_xform_depth(pdf, k, depth(p)); 96 box(cur_val) = null; 97 pdf_last_xform = k; 98} 99 100@ @c 101#define tail cur_list.tail_field 102 103void scan_pdfrefxform(PDF pdf) 104{ 105 int transform = 0; 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 new_whatsit(pdf_refxform_node); 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 115 || alt_rule.dp != null_flag) { 116 dim = tex_scale(nat, alt_rule); 117 } else { 118 dim = nat; 119 } 120 width(tail) = dim.wd; 121 height(tail) = dim.ht; 122 depth(tail) = dim.dp; 123 pdf_xform_transform(tail) = transform; /* not implemented yet */ 124 pdf_xform_objnum(tail) = cur_val; 125} 126