1 | <?php |
---|
2 | /** |
---|
3 | * DOMPDF - PHP5 HTML to PDF renderer |
---|
4 | * |
---|
5 | * File: $RCSfile: text_frame_decorator.cls.php,v $ |
---|
6 | * Created on: 2004-06-04 |
---|
7 | * |
---|
8 | * Copyright (c) 2004 - Benj Carson <benjcarson@digitaljunkies.ca> |
---|
9 | * |
---|
10 | * This library is free software; you can redistribute it and/or |
---|
11 | * modify it under the terms of the GNU Lesser General Public |
---|
12 | * License as published by the Free Software Foundation; either |
---|
13 | * version 2.1 of the License, or (at your option) any later version. |
---|
14 | * |
---|
15 | * This library is distributed in the hope that it will be useful, |
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | * Lesser General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU Lesser General Public License |
---|
21 | * along with this library in the file LICENSE.LGPL; if not, write to the |
---|
22 | * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
---|
23 | * 02111-1307 USA |
---|
24 | * |
---|
25 | * Alternatively, you may distribute this software under the terms of the |
---|
26 | * PHP License, version 3.0 or later. A copy of this license should have |
---|
27 | * been distributed with this file in the file LICENSE.PHP . If this is not |
---|
28 | * the case, you can obtain a copy at http://www.php.net/license/3_0.txt. |
---|
29 | * |
---|
30 | * The latest version of DOMPDF might be available at: |
---|
31 | * http://www.digitaljunkies.ca/dompdf |
---|
32 | * |
---|
33 | * @link http://www.digitaljunkies.ca/dompdf |
---|
34 | * @copyright 2004 Benj Carson |
---|
35 | * @author Benj Carson <benjcarson@digitaljunkies.ca> |
---|
36 | * @package dompdf |
---|
37 | * @version 0.5.1 |
---|
38 | */ |
---|
39 | |
---|
40 | /* $Id: text_frame_decorator.cls.php,v 1.4 2006/07/07 21:31:04 benjcarson Exp $ */ |
---|
41 | |
---|
42 | /** |
---|
43 | * Decorates Frame objects for text layout |
---|
44 | * |
---|
45 | * @access private |
---|
46 | * @package dompdf |
---|
47 | */ |
---|
48 | class Text_Frame_Decorator extends Frame_Decorator { |
---|
49 | |
---|
50 | // protected members |
---|
51 | protected $_text_spacing; |
---|
52 | |
---|
53 | function __construct(Frame $frame, DOMPDF $dompdf) { |
---|
54 | if ( $frame->get_node()->nodeName != "#text" ) |
---|
55 | throw new DOMPDF_Exception("Text_Decorator can only be applied to #text nodes."); |
---|
56 | |
---|
57 | parent::__construct($frame, $dompdf); |
---|
58 | $this->_text_spacing = null; |
---|
59 | } |
---|
60 | |
---|
61 | //........................................................................ |
---|
62 | |
---|
63 | function reset() { |
---|
64 | parent::reset(); |
---|
65 | $this->_text_spacing = null; |
---|
66 | } |
---|
67 | |
---|
68 | //........................................................................ |
---|
69 | |
---|
70 | // Accessor methods |
---|
71 | function get_text_spacing() { return $this->_text_spacing; } |
---|
72 | |
---|
73 | function get_text() { |
---|
74 | // FIXME: this should be in a child class (and is incorrect) |
---|
75 | if ( $this->_frame->get_style()->content !== "normal" ) { |
---|
76 | $this->_frame->get_node()->data = $this->_frame->get_style()->content; |
---|
77 | $this->_frame->get_style()->content = "normal"; |
---|
78 | } |
---|
79 | |
---|
80 | return $this->_frame->get_node()->data; |
---|
81 | } |
---|
82 | |
---|
83 | //........................................................................ |
---|
84 | |
---|
85 | // Vertical margins & padding do not apply to text frames |
---|
86 | |
---|
87 | // http://www.w3.org/TR/CSS21/visudet.html#inline-non-replaced: |
---|
88 | // |
---|
89 | // The vertical padding, border and margin of an inline, non-replaced box |
---|
90 | // start at the top and bottom of the content area, not the |
---|
91 | // 'line-height'. But only the 'line-height' is used to calculate the |
---|
92 | // height of the line box. |
---|
93 | function get_margin_height() { |
---|
94 | // This function is called in add_frame_to_line() and is used to |
---|
95 | // determine the line height, so we actually want to return the |
---|
96 | // 'line-height' property, not the actual margin box |
---|
97 | $style = $this->get_style(); |
---|
98 | $font = $style->font_family; |
---|
99 | $size = $style->font_size; |
---|
100 | |
---|
101 | return ($style->line_height / $size) * Font_Metrics::get_font_height($font, $size); |
---|
102 | |
---|
103 | } |
---|
104 | |
---|
105 | function get_padding_box() { |
---|
106 | $pb = $this->_frame->get_padding_box(); |
---|
107 | $pb["h"] = $this->_frame->get_style()->height; |
---|
108 | return $pb; |
---|
109 | } |
---|
110 | //........................................................................ |
---|
111 | |
---|
112 | // Set method |
---|
113 | function set_text_spacing($spacing) { |
---|
114 | $this->_text_spacing = $spacing; |
---|
115 | |
---|
116 | $style = $this->_frame->get_style(); |
---|
117 | // Re-adjust our width to account for the change in spacing |
---|
118 | $style->width = Font_Metrics::get_text_width($this->get_text(), $style->font_family, $style->font_size, $spacing); |
---|
119 | } |
---|
120 | |
---|
121 | //........................................................................ |
---|
122 | |
---|
123 | // Text manipulation methods |
---|
124 | |
---|
125 | // split the text in this frame at the offset specified. The remaining |
---|
126 | // text is added a sibling frame following this one and is returned. |
---|
127 | function split_text($offset) { |
---|
128 | if ( $offset == 0 ) |
---|
129 | return; |
---|
130 | |
---|
131 | $split = $this->_frame->get_node()->splitText($offset); |
---|
132 | $deco = $this->copy($split); |
---|
133 | |
---|
134 | $p = $this->get_parent(); |
---|
135 | $p->insert_child_after($deco, $this, false); |
---|
136 | |
---|
137 | if ( $p instanceof Inline_Frame_Decorator ) |
---|
138 | $p->split($deco); |
---|
139 | |
---|
140 | } |
---|
141 | |
---|
142 | //........................................................................ |
---|
143 | |
---|
144 | function delete_text($offset, $count) { |
---|
145 | $this->_frame->get_node()->deleteData($offset, $count); |
---|
146 | } |
---|
147 | |
---|
148 | //........................................................................ |
---|
149 | |
---|
150 | function set_text($text) { |
---|
151 | $this->_frame->get_node()->data = $text; |
---|
152 | } |
---|
153 | |
---|
154 | } |
---|
155 | ?> |
---|