1 | <?php |
---|
2 | /** |
---|
3 | * DOMPDF - PHP5 HTML to PDF renderer |
---|
4 | * |
---|
5 | * File: $RCSfile: renderer.cls.php,v $ |
---|
6 | * Created on: 2004-06-03 |
---|
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: renderer.cls.php,v 1.7 2006/07/07 21:31:04 benjcarson Exp $ */ |
---|
41 | |
---|
42 | /** |
---|
43 | * Concrete renderer |
---|
44 | * |
---|
45 | * Instantiates several specific renderers in order to render any given |
---|
46 | * frame. |
---|
47 | * |
---|
48 | * @access private |
---|
49 | * @package dompdf |
---|
50 | */ |
---|
51 | class Renderer extends Abstract_Renderer { |
---|
52 | |
---|
53 | /** |
---|
54 | * Array of renderers for specific frame types |
---|
55 | * |
---|
56 | * @var array |
---|
57 | */ |
---|
58 | protected $_renderers; |
---|
59 | |
---|
60 | /** |
---|
61 | * Advance the canvas to the next page |
---|
62 | */ |
---|
63 | function new_page() { |
---|
64 | $this->_canvas->new_page(); |
---|
65 | } |
---|
66 | |
---|
67 | /** |
---|
68 | * Render frames recursively |
---|
69 | * |
---|
70 | * @param Frame $frame the frame to render |
---|
71 | */ |
---|
72 | function render(Frame $frame) { |
---|
73 | global $_dompdf_debug; |
---|
74 | |
---|
75 | if ( $_dompdf_debug ) { |
---|
76 | echo $frame; |
---|
77 | flush(); |
---|
78 | } |
---|
79 | |
---|
80 | $display = $frame->get_style()->display; |
---|
81 | |
---|
82 | switch ($display) { |
---|
83 | |
---|
84 | case "block": |
---|
85 | case "inline-block": |
---|
86 | case "table": |
---|
87 | case "table-row-group": |
---|
88 | case "table-header-group": |
---|
89 | case "table-footer-group": |
---|
90 | case "inline-table": |
---|
91 | $this->_render_frame("block", $frame); |
---|
92 | break; |
---|
93 | |
---|
94 | case "inline": |
---|
95 | if ( $frame->get_node()->nodeName == "#text" ) |
---|
96 | $this->_render_frame("text", $frame); |
---|
97 | else |
---|
98 | $this->_render_frame("inline", $frame); |
---|
99 | break; |
---|
100 | |
---|
101 | case "table-cell": |
---|
102 | $this->_render_frame("table-cell", $frame); |
---|
103 | break; |
---|
104 | |
---|
105 | case "-dompdf-list-bullet": |
---|
106 | $this->_render_frame("list-bullet", $frame); |
---|
107 | break; |
---|
108 | |
---|
109 | case "-dompdf-image": |
---|
110 | $this->_render_frame("image", $frame); |
---|
111 | break; |
---|
112 | |
---|
113 | case "none": |
---|
114 | $node = $frame->get_node(); |
---|
115 | |
---|
116 | if ( $node->nodeName == "script" && |
---|
117 | ( $node->getAttribute("type") == "text/php" || |
---|
118 | $node->getAttribute("language") == "php" ) ) { |
---|
119 | // Evaluate embedded php scripts |
---|
120 | $this->_render_frame("php", $frame); |
---|
121 | } |
---|
122 | |
---|
123 | // Don't render children, so skip to next iter |
---|
124 | return; |
---|
125 | |
---|
126 | default: |
---|
127 | break; |
---|
128 | |
---|
129 | } |
---|
130 | |
---|
131 | foreach ($frame->get_children() as $child) |
---|
132 | $this->render($child); |
---|
133 | |
---|
134 | } |
---|
135 | |
---|
136 | /** |
---|
137 | * Render a single frame |
---|
138 | * |
---|
139 | * Creates Renderer objects on demand |
---|
140 | * |
---|
141 | * @param string $type type of renderer to use |
---|
142 | * @param Frame $frame the frame to render |
---|
143 | */ |
---|
144 | protected function _render_frame($type, $frame) { |
---|
145 | |
---|
146 | if ( !isset($this->_renderers[$type]) ) { |
---|
147 | |
---|
148 | switch ($type) { |
---|
149 | case "block": |
---|
150 | $this->_renderers["block"] = new Block_Renderer($this->_dompdf); |
---|
151 | break; |
---|
152 | |
---|
153 | case "inline": |
---|
154 | $this->_renderers["inline"] = new Inline_Renderer($this->_dompdf); |
---|
155 | break; |
---|
156 | |
---|
157 | case "text": |
---|
158 | $this->_renderers["text"] = new Text_Renderer($this->_dompdf); |
---|
159 | break; |
---|
160 | |
---|
161 | case "image": |
---|
162 | $this->_renderers["image"] = new Image_Renderer($this->_dompdf); |
---|
163 | break; |
---|
164 | |
---|
165 | case "table-cell": |
---|
166 | $this->_renderers["table-cell"] = new Table_Cell_Renderer($this->_dompdf); |
---|
167 | break; |
---|
168 | |
---|
169 | case "list-bullet": |
---|
170 | $this->_renderers["list-bullet"] = new List_Bullet_Renderer($this->_dompdf); |
---|
171 | break; |
---|
172 | |
---|
173 | case "php": |
---|
174 | $this->_renderers["php"] = new PHP_Evaluator($this->_canvas); |
---|
175 | break; |
---|
176 | |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | $this->_renderers[$type]->render($frame); |
---|
181 | |
---|
182 | } |
---|
183 | } |
---|
184 | |
---|
185 | ?> |
---|