| 1 |
/* |
| 2 |
|
| 3 |
Copyright 2010-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 |
void pdf_place_rule(PDF pdf, halfword q, scaledpos size, int callback_id) |
| 26 |
{ |
| 27 |
pdfpos dim; |
| 28 |
pdfstructure *p = pdf->pstruct; |
| 29 |
scaledpos pos = pdf->posstruct->pos; |
| 30 |
halfword s = subtype(q); |
| 31 |
if (s >= math_over_rule && s <= math_radical_rule) { |
| 32 |
if (callback_id == 0) { |
| 33 |
s = normal_rule; |
| 34 |
} else { |
| 35 |
s = user_rule; |
| 36 |
} |
| 37 |
} |
| 38 |
if (s == box_rule) { |
| 39 |
pdf_place_form(pdf,q); |
| 40 |
} else if (s == image_rule) { |
| 41 |
pdf_place_image(pdf,q); |
| 42 |
} else if (s == empty_rule) { |
| 43 |
/*tex Place nothing, only take space. */ |
| 44 |
} else if (s == user_rule) { |
| 45 |
if (callback_id != 0) { |
| 46 |
pdf_goto_pagemode(pdf); |
| 47 |
pdf_puts(pdf, "q\n"); |
| 48 |
pdf_set_pos_temp(pdf, pos); |
| 49 |
run_callback(callback_id, "Ndd->",q,size.h,size.v); |
| 50 |
pdf_puts(pdf, "\nQ\n"); |
| 51 |
} |
| 52 |
} else { |
| 53 |
/*tex |normal_rule| or >= 100 being a leader rule */ |
| 54 |
pdf_goto_pagemode(pdf); |
| 55 |
dim.h.m = i64round(size.h * p->k1); |
| 56 |
dim.h.e = p->pdf.h.e; |
| 57 |
dim.v.m = i64round(size.v * p->k1); |
| 58 |
dim.v.e = p->pdf.v.e; |
| 59 |
pdf_puts(pdf, "q\n"); |
| 60 |
if (size.v <= one_bp) { |
| 61 |
pos.v += i64round(0.5 * size.v); |
| 62 |
pdf_set_pos_temp(pdf, pos); |
| 63 |
pdf_puts(pdf, "[] 0 d 0 J "); |
| 64 |
print_pdffloat(pdf, dim.v); |
| 65 |
pdf_puts(pdf, " w 0 0 m "); |
| 66 |
print_pdffloat(pdf, dim.h); |
| 67 |
pdf_puts(pdf, " 0 l S\n"); |
| 68 |
} else if (size.h <= one_bp) { |
| 69 |
pos.h += i64round(0.5 * size.h); |
| 70 |
pdf_set_pos_temp(pdf, pos); |
| 71 |
pdf_puts(pdf, "[] 0 d 0 J "); |
| 72 |
print_pdffloat(pdf, dim.h); |
| 73 |
pdf_puts(pdf, " w 0 0 m 0 "); |
| 74 |
print_pdffloat(pdf, dim.v); |
| 75 |
pdf_puts(pdf, " l S\n"); |
| 76 |
} else { |
| 77 |
pdf_set_pos_temp(pdf, pos); |
| 78 |
if (s == outline_rule) { |
| 79 |
pdf_puts(pdf, "[] 0 d 0 J "); |
| 80 |
if (rule_transform(q) > 0) { |
| 81 |
pdfpos temp ; |
| 82 |
temp.h.m = i64round(rule_transform(q) * p->k1); |
| 83 |
temp.h.e = p->pdf.h.e; |
| 84 |
print_pdffloat(pdf, temp.h); |
| 85 |
pdf_puts(pdf, " w "); |
| 86 |
} |
| 87 |
} |
| 88 |
pdf_puts(pdf, "0 0 "); |
| 89 |
print_pdffloat(pdf, dim.h); |
| 90 |
pdf_out(pdf, ' '); |
| 91 |
print_pdffloat(pdf, dim.v); |
| 92 |
if (s == outline_rule) { |
| 93 |
pdf_puts(pdf, " re S\n"); |
| 94 |
} else { |
| 95 |
pdf_puts(pdf, " re f\n"); |
| 96 |
} |
| 97 |
} |
| 98 |
pdf_puts(pdf, "Q\n"); |
| 99 |
} |
| 100 |
} |