beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / pdf / pdfrule.w
blob2f75b4c761e951485a6b4381d1079783c6830a96
1 % pdfrule.w
3 % Copyright 2010-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
26 /* maybe we should have an extra callback on normal rules or on any rule in 2.0+ */
28 void pdf_place_rule(PDF pdf, halfword q, scaledpos size, int callback_id)
30 pdfpos dim;
31 pdfstructure *p = pdf->pstruct;
32 scaledpos pos = pdf->posstruct->pos;
33 /* (void) q; */
34 if (subtype(q) == box_rule) {
35 pdf_place_form(pdf,q);
36 } else if (subtype(q) == image_rule) {
37 pdf_place_image(pdf,q);
38 } else if (subtype(q) == empty_rule) {
39 /* place nothing, only take space */
40 } else if (subtype(q) == user_rule) {
41 if (callback_id != 0) {
42 pdf_goto_pagemode(pdf);
43 pdf_puts(pdf, "q\n");
44 pdf_set_pos_temp(pdf, pos);
45 run_callback(callback_id, "Ndd->",q,size.h,size.v);
46 pdf_puts(pdf, "\nQ\n");
48 } else {
49 /* normal_rule or >= 100 being a leader rule */
50 pdf_goto_pagemode(pdf);
51 dim.h.m = i64round(size.h * p->k1);
52 dim.h.e = p->pdf.h.e;
53 dim.v.m = i64round(size.v * p->k1);
54 dim.v.e = p->pdf.v.e;
55 pdf_puts(pdf, "q\n");
56 if (size.v <= one_bp) {
57 pos.v += i64round(0.5 * size.v);
58 pdf_set_pos_temp(pdf, pos);
59 pdf_puts(pdf, "[]0 d 0 J ");
60 print_pdffloat(pdf, dim.v);
61 pdf_puts(pdf, " w 0 0 m ");
62 print_pdffloat(pdf, dim.h);
63 pdf_puts(pdf, " 0 l S\n");
64 } else if (size.h <= one_bp) {
65 pos.h += i64round(0.5 * size.h);
66 pdf_set_pos_temp(pdf, pos);
67 pdf_puts(pdf, "[]0 d 0 J ");
68 print_pdffloat(pdf, dim.h);
69 pdf_puts(pdf, " w 0 0 m 0 ");
70 print_pdffloat(pdf, dim.v);
71 pdf_puts(pdf, " l S\n");
72 } else {
73 pdf_set_pos_temp(pdf, pos);
74 pdf_puts(pdf, "0 0 ");
75 print_pdffloat(pdf, dim.h);
76 pdf_out(pdf, ' ');
77 print_pdffloat(pdf, dim.v);
78 pdf_puts(pdf, " re f\n");
80 pdf_puts(pdf, "Q\n");