source: trunk/filemanager/tp/dompdf/include/frame_factory.cls.php @ 2000

Revision 2000, 6.0 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Implementação do módulo gerenciador de arquivos

Line 
1<?php
2/**
3 * DOMPDF - PHP5 HTML to PDF renderer
4 *
5 * File: $RCSfile: frame_factory.cls.php,v $
6 * Created on: 2004-06-17
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: frame_factory.cls.php 186 2009-10-19 22:42:06Z eclecticgeek@gmail.com $ */
41
42/**
43 * Contains frame decorating logic
44 *
45 * This class is responsible for assigning the correct {@link Frame_Decorator},
46 * {@link Positioner}, and {@link Frame_Reflower} objects to {@link Frame}
47 * objects.  This is determined primarily by the Frame's display type, but
48 * also by the Frame's node's type (e.g. DomElement vs. #text)
49 *
50 * @access private
51 * @package dompdf
52 */
53class Frame_Factory {
54
55  static function decorate_root(Frame $root, DOMPDF $dompdf) {
56    $frame = new Page_Frame_Decorator($root, $dompdf);
57    $frame->set_reflower( new Page_Frame_Reflower($frame) );
58    $root->set_decorator($frame);
59    return $frame;
60  }
61
62  // FIXME: this is admittedly a little smelly...
63  static function decorate_frame(Frame $frame, $dompdf) {
64    if ( is_null($dompdf) )
65      throw new Exception("foo");
66    switch ($frame->get_style()->display) {
67     
68    case "block":
69      $positioner = "Block";       
70      $decorator = "Block";
71      $reflower = "Block";
72      break;
73   
74    case "inline-block":
75      $positioner = "Inline";
76      $decorator = "Block";
77      $reflower = "Block";
78      break;
79
80    case "inline":
81      $positioner = "Inline";
82      if ( $frame->get_node()->nodeName == "#text" ) {
83        $decorator = "Text";
84        $reflower = "Text";
85      } else {
86        $decorator = "Inline";
87        $reflower = "Inline";
88      }
89      break;   
90
91    case "table":
92      $positioner = "Block";
93      $decorator = "Table";
94      $reflower = "Table";
95      break;
96     
97    case "inline-table":
98      $positioner = "Inline";
99      $decorator = "Table";
100      $reflower = "Table";
101      break;
102
103    case "table-row-group":
104    case "table-header-group":
105    case "table-footer-group":
106      $positioner = "Null";
107      $decorator = "Table_Row_Group";
108      $reflower = "Table_Row_Group";
109      break;
110     
111    case "table-row":
112      $positioner = "Null";
113      $decorator = "Table_Row";
114      $reflower = "Table_Row";
115      break;
116
117    case "table-cell":
118      $positioner = "Table_Cell";
119      $decorator = "Table_Cell";
120      $reflower = "Table_Cell";
121      break;
122       
123    case "list-item":
124      $positioner = "Block";
125      $decorator  = "Block";
126      $reflower   = "Block";
127      break;
128
129    case "-dompdf-list-bullet":
130      if ( $frame->get_style()->list_style_position == "inside" )
131        $positioner = "Inline";
132      else       
133        $positioner = "List_Bullet";
134
135      if ( $frame->get_style()->list_style_image != "none" )
136        $decorator = "List_Bullet_Image";
137      else
138        $decorator = "List_Bullet";
139     
140      $reflower = "List_Bullet";
141      break;
142
143    case "-dompdf-image":
144      $positioner = "Inline";
145      $decorator = "Image";
146      $reflower = "Image";
147      break;
148     
149    case "-dompdf-br":
150      $positioner = "Inline";
151      $decorator = "Inline";
152      $reflower = "Inline";
153      break;
154
155    default:
156      // FIXME: should throw some sort of warning or something?
157    case "none":
158      $positioner = "Null";
159      $decorator = "Null";
160      $reflower = "Null";
161      break;
162
163    }
164
165    if ( $frame->get_style()->position == "absolute" ||
166         $frame->get_style()->position == "fixed" )
167      $positioner = "Absolute";
168   
169    $positioner .= "_Positioner";
170    $decorator .= "_Frame_Decorator";
171    $reflower .= "_Frame_Reflower";
172
173    $deco = new $decorator($frame, $dompdf);
174    $deco->set_positioner( new $positioner($deco) );
175    $reflow = new $reflower($deco);
176   
177    // Generated content is a special case
178    if ( $frame->get_node()->nodeName == "_dompdf_generated" ) {
179      // Decorate the reflower
180      $gen = new Generated_Frame_Reflower( $deco );
181      $gen->set_reflower( $reflow );
182      $reflow = $gen;
183    }
184   
185    $deco->set_reflower( $reflow );
186
187    // Images are a special case
188//    if ( $frame->get_node()->nodeName == "img" ) {
189
190//       // FIXME: This is a hack
191//       $node =$frame->get_node()->ownerDocument->createElement("img_sub");
192//       $node->setAttribute("src", $frame->get_node()->getAttribute("src"));
193     
194//       $img_frame = new Frame( $node );
195
196//       $style = $frame->get_style()->get_stylesheet()->create_style();
197//       $style->inherit($frame->get_style());
198//       $img_frame->set_style( $style );
199
200//       $img_deco = new Image_Frame_Decorator($img_frame, $dompdf);
201//       $img_deco->set_reflower( new Image_Frame_Reflower($img_deco) );
202//       $deco->append_child($img_deco);
203
204//     }   
205   
206    return $deco;
207  }
208 
209}
210?>
Note: See TracBrowser for help on using the repository browser.