1 | <?php |
---|
2 | /** |
---|
3 | * DOMPDF - PHP5 HTML to PDF renderer |
---|
4 | * |
---|
5 | * File: $RCSfile: inline_renderer.cls.php,v $ |
---|
6 | * Created on: 2004-06-30 |
---|
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: inline_renderer.cls.php 186 2009-10-19 22:42:06Z eclecticgeek@gmail.com $ */ |
---|
41 | |
---|
42 | /** |
---|
43 | * Renders inline frames |
---|
44 | * |
---|
45 | * @access private |
---|
46 | * @package dompdf |
---|
47 | */ |
---|
48 | class Inline_Renderer extends Abstract_Renderer { |
---|
49 | |
---|
50 | //........................................................................ |
---|
51 | |
---|
52 | function render(Frame $frame) { |
---|
53 | $style = $frame->get_style(); |
---|
54 | |
---|
55 | if ( !$frame->get_first_child() ) |
---|
56 | return; // No children, no service |
---|
57 | |
---|
58 | // Draw the left border if applicable |
---|
59 | $bp = $style->get_border_properties(); |
---|
60 | $widths = array($style->length_in_pt($bp["top"]["width"]), |
---|
61 | $style->length_in_pt($bp["right"]["width"]), |
---|
62 | $style->length_in_pt($bp["bottom"]["width"]), |
---|
63 | $style->length_in_pt($bp["left"]["width"])); |
---|
64 | |
---|
65 | // Draw the background & border behind each child. To do this we need |
---|
66 | // to figure out just how much space each child takes: |
---|
67 | list($x, $y) = $frame->get_first_child()->get_position(); |
---|
68 | $w = null; |
---|
69 | $h = 0; |
---|
70 | // $x += $widths[3]; |
---|
71 | // $y += $widths[0]; |
---|
72 | |
---|
73 | $first_row = true; |
---|
74 | |
---|
75 | foreach ($frame->get_children() as $child) { |
---|
76 | list($child_x, $child_y, $child_w, $child_h) = $child->get_padding_box(); |
---|
77 | $child_h += $widths[2]; |
---|
78 | |
---|
79 | if ( !is_null($w) && $child_x < $x + $w ) { |
---|
80 | //This branch seems to be supposed to being called on the first part |
---|
81 | //of an inline html element, and the part after the if clause for the |
---|
82 | //parts after a line break. |
---|
83 | //But because $w initially mostly is 0, and gets updated only on the next |
---|
84 | //round, this seem to be never executed and the common close always. |
---|
85 | |
---|
86 | // The next child is on another line. Draw the background & |
---|
87 | // borders on this line. |
---|
88 | |
---|
89 | // Background: |
---|
90 | if ( ($bg = $style->background_color) !== "transparent" ) |
---|
91 | $this->_canvas->filled_rectangle( $x, $y, $w, $h, $style->background_color); |
---|
92 | |
---|
93 | if ( ($url = $style->background_image) && $url !== "none" ) { |
---|
94 | $this->_background_image($url, $x, $y, $w, $h, $style); |
---|
95 | } |
---|
96 | |
---|
97 | // If this is the first row, draw the left border |
---|
98 | if ( $first_row ) { |
---|
99 | |
---|
100 | if ( $bp["left"]["style"] != "none" && $bp["left"]["width"] > 0 ) { |
---|
101 | $method = "_border_" . $bp["left"]["style"]; |
---|
102 | $this->$method($x, $y, $h + $widths[0] + $widths[2], $bp["left"]["color"], $widths, "left"); |
---|
103 | } |
---|
104 | $first_row = false; |
---|
105 | } |
---|
106 | |
---|
107 | // Draw the top & bottom borders |
---|
108 | if ( $bp["top"]["style"] != "none" && $bp["top"]["width"] > 0 ) { |
---|
109 | $method = "_border_" . $bp["top"]["style"]; |
---|
110 | $this->$method($x, $y, $w + $widths[1] + $widths[3], $bp["top"]["color"], $widths, "top"); |
---|
111 | } |
---|
112 | |
---|
113 | if ( $bp["bottom"]["style"] != "none" && $bp["bottom"]["width"] > 0 ) { |
---|
114 | $method = "_border_" . $bp["bottom"]["style"]; |
---|
115 | $this->$method($x, $y + $h + $widths[0] + $widths[2], $w + $widths[1] + $widths[3], $bp["bottom"]["color"], $widths, "bottom"); |
---|
116 | } |
---|
117 | |
---|
118 | // Handle anchors & links |
---|
119 | if ( $frame->get_node()->nodeName == "a" ) { |
---|
120 | |
---|
121 | if ( $href = $frame->get_node()->getAttribute("href") ) |
---|
122 | $this->_canvas->add_link($href, $x, $y, $w, $h); |
---|
123 | |
---|
124 | } |
---|
125 | |
---|
126 | $x = $child_x; |
---|
127 | $y = $child_y; |
---|
128 | $w = $child_w; |
---|
129 | $h = $child_h; |
---|
130 | continue; |
---|
131 | } |
---|
132 | |
---|
133 | if ( is_null($w) ) |
---|
134 | $w = $child_w; |
---|
135 | else |
---|
136 | $w += $child_w; |
---|
137 | |
---|
138 | $h = max($h, $child_h); |
---|
139 | } |
---|
140 | |
---|
141 | |
---|
142 | // Handle the last child |
---|
143 | if ( ($bg = $style->background_color) !== "transparent" ) |
---|
144 | $this->_canvas->filled_rectangle( $x + $widths[3], $y + $widths[0], $w, $h, $style->background_color); |
---|
145 | |
---|
146 | //On continuation lines (after line break) of inline elements, the style got copied. |
---|
147 | //But a non repeatable background image should not be repeated on the next line. |
---|
148 | //But removing the background image above has never an effect, and removing it below |
---|
149 | //removes it always, even on the initial line. |
---|
150 | //Need to handle it elsewhere, e.g. on certain ...clone()... usages. |
---|
151 | // Repeat not given: default is Style::__construct |
---|
152 | // ... && (!($repeat = $style->background_repeat) || $repeat === "repeat" ... |
---|
153 | //different position? $this->_background_image($url, $x, $y, $w, $h, $style); |
---|
154 | if ( ($url = $style->background_image) && $url !== "none" ) |
---|
155 | $this->_background_image($url, $x + $widths[3], $y + $widths[0], $w, $h, $style); |
---|
156 | |
---|
157 | // Add the border widths |
---|
158 | $w += $widths[1] + $widths[3]; |
---|
159 | $h += $widths[0] + $widths[2]; |
---|
160 | |
---|
161 | // make sure the border and background start inside the left margin |
---|
162 | $left_margin = $style->length_in_pt($style->margin_left); |
---|
163 | $x += $left_margin; |
---|
164 | |
---|
165 | // If this is the first row, draw the left border too |
---|
166 | if ( $first_row && $bp["left"]["style"] != "none" && $widths[3] > 0 ) { |
---|
167 | $method = "_border_" . $bp["left"]["style"]; |
---|
168 | $this->$method($x, $y, $h, $bp["left"]["color"], $widths, "left"); |
---|
169 | } |
---|
170 | |
---|
171 | // Draw the top & bottom borders |
---|
172 | if ( $bp["top"]["style"] != "none" && $widths[0] > 0 ) { |
---|
173 | $method = "_border_" . $bp["top"]["style"]; |
---|
174 | $this->$method($x, $y, $w, $bp["top"]["color"], $widths, "top"); |
---|
175 | } |
---|
176 | |
---|
177 | if ( $bp["bottom"]["style"] != "none" && $widths[2] > 0 ) { |
---|
178 | $method = "_border_" . $bp["bottom"]["style"]; |
---|
179 | $this->$method($x, $y + $h, $w, $bp["bottom"]["color"], $widths, "bottom"); |
---|
180 | } |
---|
181 | |
---|
182 | // pre_var_dump(get_class($frame->get_next_sibling())); |
---|
183 | // $last_row = get_class($frame->get_next_sibling()) != 'Inline_Frame_Decorator'; |
---|
184 | // Draw the right border if this is the last row |
---|
185 | if ( $bp["right"]["style"] != "none" && $widths[1] > 0 ) { |
---|
186 | $method = "_border_" . $bp["right"]["style"]; |
---|
187 | $this->$method($x + $w, $y, $h, $bp["right"]["color"], $widths, "right"); |
---|
188 | } |
---|
189 | |
---|
190 | // Handle anchors & links |
---|
191 | if ( $frame->get_node()->nodeName == "a" ) { |
---|
192 | |
---|
193 | if ( $name = $frame->get_node()->getAttribute("name") ) |
---|
194 | $this->_canvas->add_named_dest($name); |
---|
195 | |
---|
196 | if ( $href = $frame->get_node()->getAttribute("href") ) |
---|
197 | $this->_canvas->add_link($href, $x, $y, $w, $h); |
---|
198 | } |
---|
199 | } |
---|
200 | } |
---|
201 | ?> |
---|