source: sandbox/filemanager/tp/dompdf/include/frame_decorator.cls.php @ 1575

Revision 1575, 10.8 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Implentação, melhorias do modulo gerenciador de arquivos

Line 
1<?php
2/**
3 * DOMPDF - PHP5 HTML to PDF renderer
4 *
5 * File: $RCSfile: frame_decorator.cls.php,v $
6 * Created on: 2004-06-02
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_decorator.cls.php,v 1.13 2006/07/07 21:31:03 benjcarson Exp $ */
41
42/**
43 * Base Frame_Decorator class
44 *
45 * @access private
46 * @package dompdf
47 */
48abstract class Frame_Decorator extends Frame {
49 
50  /**
51   * The root node of the DOM tree
52   *
53   * @var Frame
54   */
55  protected $_root;
56
57  /**
58   * The decorated frame
59   *
60   * @var Frame
61   */
62  protected $_frame;
63
64  /**
65   * Positioner object used to position this frame (Strategy pattern)
66   *
67   * @var Positioner
68   */
69  protected $_positioner;
70
71  /**
72   * Reflower object used to calculate frame dimensions (Strategy pattern)
73   *
74   * @var Frame_Reflower
75   */
76  protected $_reflower;
77 
78  /**
79   * Reference to the current dompdf instance
80   *
81   * @var DOMPDF
82   */
83  protected $_dompdf;
84
85  /**
86   * Class constructor
87   *
88   * @param Frame $frame the decoration target
89   */
90  function __construct(Frame $frame, DOMPDF $dompdf) {
91    $this->_frame = $frame;
92    $this->_root = null;
93    $this->_dompdf = $dompdf;
94    $frame->set_decorator($this);
95  }
96
97  /**
98   * "Destructor": foribly free all references held by this object
99   *
100   * @param bool $recursive if true, call dispose on all children
101   */
102  function dispose($recursive = false) {
103   
104    if ( $recursive ) {
105      while ( $child = $this->get_first_child() )
106        $child->dispose(true);
107    }
108   
109    unset($this->_root);
110    $this->_frame->dispose(false);
111    unset($this->_frame);
112    unset($this->_positioner);
113    unset($this->_reflower);
114
115  }
116
117  // Return a copy of this frame with $node as its node
118  function copy(DomNode $node) {
119    $frame = new Frame($node);
120    $frame->set_style(clone $this->_frame->get_original_style());
121    $deco = Frame_Factory::decorate_frame($frame, $this->_dompdf);
122    $deco->set_root($this->_root);
123    return $deco;
124  }
125
126  /**
127   * Create a deep copy: copy this node and all children
128   *
129   * @return Frame
130   */
131  function deep_copy() {
132    $frame = new Frame($this->get_node()->cloneNode());
133    $frame->set_style(clone $this->_frame->get_original_style());
134    $deco = Frame_Factory::decorate_frame($frame, $this->_dompdf);
135    $deco->set_root($this->_root);
136
137    foreach ($this->get_children() as $child)
138      $deco->append_child($child->deep_copy());
139
140    return $deco;
141  }
142  //........................................................................
143 
144  // Delegate calls to decorated frame object
145  function reset() {
146    $this->_frame->reset();
147
148    // Reset all children
149    foreach ($this->get_children() as $child)
150      $child->reset();
151
152  }
153 
154  function get_node() { return $this->_frame->get_node(); }
155  function get_id() { return $this->_frame->get_id(); }
156  function get_style() { return $this->_frame->get_style(); }
157  function get_original_style() { return $this->_frame->get_original_style(); }
158  function get_containing_block($i = null) { return $this->_frame->get_containing_block($i); }
159  function get_position($i = null) { return $this->_frame->get_position($i); }
160//   function get_decorator() {
161//     if ( isset($this->_decorator) )
162//       return $this->_decorator;
163//     else
164//       return $this;
165//   }
166
167  function get_margin_height() { return $this->_frame->get_margin_height(); }
168  function get_margin_width() { return $this->_frame->get_margin_width(); }
169  function get_padding_box() { return $this->_frame->get_padding_box(); }
170  function get_border_box() { return $this->_frame->get_border_box(); }
171
172  function set_id($id) { $this->_frame->set_id($id); }
173  function set_style(Style $style) { $this->_frame->set_style($style); }
174
175  function set_containing_block($x = null, $y = null, $w = null, $h = null) {
176    $this->_frame->set_containing_block($x, $y, $w, $h);
177  }
178
179  function set_position($x = null, $y = null) {
180    $this->_frame->set_position($x, $y);
181  }
182  function __toString() { return $this->_frame->__toString(); }
183 
184  function prepend_child(Frame $child, $update_node = true) {
185    while ( $child instanceof Frame_Decorator )
186      $child = $child->_frame;
187   
188    $this->_frame->prepend_child($child, $update_node);
189  }
190
191  function append_child(Frame $child, $update_node = true) {
192    while ( $child instanceof Frame_Decorator )
193      $child = $child->_frame;
194
195    $this->_frame->append_child($child, $update_node);
196  }
197
198  function insert_child_before(Frame $new_child, Frame $ref, $update_node = true) {
199    while ( $new_child instanceof Frame_Decorator )
200      $new_child = $new_child->_frame;
201
202    if ( $ref instanceof Frame_Decorator )
203      $ref = $ref->_frame;
204
205    $this->_frame->insert_child_before($new_child, $ref, $update_node);
206  }
207
208  function insert_child_after(Frame $new_child, Frame $ref, $update_node = true) {
209    while ( $new_child instanceof Frame_Decorator )
210      $new_child = $new_child->_frame;
211
212    while ( $ref instanceof Frame_Decorator )
213      $ref = $ref->_frame;
214   
215    $this->_frame->insert_child_after($new_child, $ref, $update_node);
216  }
217
218  function remove_child(Frame $child, $update_node = true) {
219    while  ( $child instanceof Frame_Decorator )
220      $child = $new_child->_frame;
221
222    $this->_frame->remove_child($child, $update_node);
223  }
224 
225  //........................................................................
226
227  function get_parent() {
228
229    $p = $this->_frame->get_parent();
230   
231    if ( $p && $deco = $p->get_decorator() ) {
232      while ( $tmp = $deco->get_decorator() )
233        $deco = $tmp;     
234      return $deco;
235    } else if ( $p )
236      return $p;
237    else
238      return null;
239  }
240
241  function get_first_child() {
242    $c = $this->_frame->get_first_child();
243    if ( $c && $deco = $c->get_decorator() ) {
244      while ( $tmp = $deco->get_decorator() )
245        $deco = $tmp;     
246      return $deco;
247    } else if ( $c )
248      return $c;
249    else
250      return null;
251  }
252
253  function get_last_child() {
254    $c = $this->_frame->get_last_child();
255    if ( $c && $deco = $c->get_decorator() ) {
256      while ( $tmp = $deco->get_decorator() )
257        $deco = $tmp;     
258      return $deco;
259    } else if ( $c )
260      return $c;
261    else
262      return null;
263  }
264
265  function get_prev_sibling() {
266    $s = $this->_frame->get_prev_sibling();
267    if ( $s && $deco = $s->get_decorator() ) {
268      while ( $tmp = $deco->get_decorator() )
269        $deco = $tmp;     
270      return $deco;
271    } else if ( $s )
272      return $s;
273    else
274      return null;
275  }
276 
277  function get_next_sibling() {
278    $s = $this->_frame->get_next_sibling();
279    if ( $s && $deco = $s->get_decorator() ) {
280      while ( $tmp = $deco->get_decorator() )
281        $deco = $tmp;     
282      return $deco;
283    } else if ( $s )
284      return $s;
285    else
286      return null;
287  }
288
289  function get_children() {
290    return new FrameList($this);
291  }
292
293  function get_subtree() {
294    return new FrameTreeList($this);
295  }
296 
297  //........................................................................
298
299  function set_positioner(Positioner $posn) {
300    $this->_positioner = $posn;
301    if ( $this->_frame instanceof Frame_Decorator )
302      $this->_frame->set_positioner($posn);
303  }
304 
305  //........................................................................
306
307  function set_reflower(Frame_Reflower $reflower) {
308    $this->_reflower = $reflower;
309    if ( $this->_frame instanceof Frame_Decorator )
310      $this->_frame->set_reflower( $reflower );
311  }
312 
313  function get_reflower() { return $this->_reflower; }
314 
315  //........................................................................
316 
317  function set_root(Frame $root) {
318    $this->_root = $root;
319      if ( $this->_frame instanceof Frame_Decorator )
320        $this->_frame->set_root($root);
321  }
322 
323  function get_root() { return $this->_root; }
324 
325  //........................................................................
326
327  function find_block_parent() {
328
329    // Find our nearest block level parent
330    $p = $this->get_parent();
331   
332    while ( $p ) {
333      if ( in_array($p->get_style()->display, Style::$BLOCK_TYPES) )
334        break;
335
336      $p = $p->get_parent();
337    }
338
339    return $p;
340  }
341
342  //........................................................................
343
344  /**
345   * split this frame at $child.
346   *
347   * The current frame is cloned and $child and all children following
348   * $child are added to the clone.  The clone is then passed to the
349   * current frame's parent->split() method.
350   *
351   * @param Frame $child
352   */
353  function split($child = null) {
354
355    if ( is_null( $child ) ) {
356      $this->get_parent()->split($this);
357      return;
358    }
359   
360    if ( $child->get_parent() !== $this )
361      throw new DOMPDF_Exception("Unable to split: frame is not a child of this one.");
362
363    $split = $this->copy( $this->_frame->get_node()->cloneNode() );
364    $split->reset();
365    $this->get_parent()->insert_child_after($split, $this);
366
367    // Add $frame and all following siblings to the new split node
368    $iter = $child;
369    while ($iter) {
370      $frame = $iter;     
371      $iter = $iter->get_next_sibling();
372      $frame->reset();
373      $split->append_child($frame);
374    }
375
376    $this->get_parent()->split($split);
377  }
378
379  //........................................................................
380
381  final function position() { $this->_positioner->position();  }
382 
383  final function reflow() {
384    // Uncomment this to see the frames before they're laid out, instead of
385    // during rendering.
386    //echo $this->_frame; flush();
387    $this->_reflower->reflow();
388  }
389
390  final function get_min_max_width() { return $this->get_reflower()->get_min_max_width(); }
391 
392  //........................................................................
393
394
395}
396
397?>
Note: See TracBrowser for help on using the repository browser.