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

Revision 1575, 6.0 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_reflower.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_reflower.cls.php,v 1.5 2006/07/07 21:31:03 benjcarson Exp $ */
41
42/**
43 * Base reflower class
44 *
45 * Reflower objects are responsible for determining the width and height of
46 * individual frames.  The also create line and page breaks as necessary.
47 *
48 * @access private
49 * @package dompdf
50 */
51abstract class Frame_Reflower {
52  protected $_frame;
53
54  function __construct(Frame $frame) {
55    $this->_frame = $frame;
56  }
57
58  function dispose() {
59    unset($this->_frame);
60  }
61
62  protected function _collapse_margins() {
63    $cb = $this->_frame->get_containing_block();
64    $style = $this->_frame->get_style();
65
66    $t = $style->length_in_pt($style->margin_top, $cb["h"]);
67    $b = $style->length_in_pt($style->margin_bottom, $cb["w"]);
68
69    // Handle 'auto' values
70    if ( $t === "auto" ) {
71      $style->margin_top = "0pt";
72      $t = 0;
73    }
74
75    if ( $b === "auto" ) {
76      $style->margin_bottom = "0pt";
77      $b = 0;
78    }
79
80    // Collapse vertical margins:
81    $n = $this->_frame->get_next_sibling();
82    while ( $n && !in_array($n->get_style()->display, Style::$BLOCK_TYPES) )
83      $n = $n->get_next_sibling();
84
85    if ( $n ) { // && !$n instanceof Page_Frame_Decorator ) {
86
87      $b = max($b, $style->length_in_pt($n->get_style()->margin_top, $cb["w"]));
88
89      $n->get_style()->margin_top = "$b pt";
90      $style->margin_bottom = "0 pt";
91
92    }
93
94    // Collapse our first child's margin
95    $f = $this->_frame->get_first_child();
96    while ( $f && !in_array($f->get_style()->display, Style::$BLOCK_TYPES) )
97      $f = $f->get_next_sibling();
98
99    if ( $f ) {
100      $t = max( $t, $style->length_in_pt($f->get_style()->margin_top, $cb["w"]));
101      $style->margin_top = "$t pt";
102      $f->get_style()->margin_top = "0 pt";
103    }
104
105  }
106
107  // Returns true if a new page is required
108  protected function _check_new_page() {
109    $y = $this->_frame->get_position("y");
110    $h = $style->length_in_pt($style->height);
111    // Check if we need to move to a new page
112    if ( $y + $h >= $this->_frame->get_root()->get_page_height() )
113      return true;
114
115  }
116
117  //........................................................................
118
119  abstract function reflow();
120
121  //........................................................................
122
123  // Required for table layout: Returns an array(0 => min, 1 => max, "min"
124  // => min, "max" => max) of the minimum and maximum widths of this frame.
125  // This provides a basic implementation.  Child classes should override
126  // this if necessary.
127  function get_min_max_width() {
128    $style = $this->_frame->get_style();
129
130    // Account for margins & padding
131    $dims = array($style->padding_left,
132                  $style->padding_right,
133                  $style->border_left_width,
134                  $style->border_right_width,
135                  $style->margin_left,
136                  $style->margin_right);
137
138    $delta = $style->length_in_pt($dims, $this->_frame->get_containing_block("w"));
139
140    // Handle degenerate case
141    if ( !$this->_frame->get_first_child() )
142      return array($delta, $delta,"min" => $delta, "max" => $delta);
143
144    $low = array();
145    $high = array();
146
147    for ( $iter = $this->_frame->get_children()->getIterator();
148          $iter->valid();
149          $iter->next() ) {
150
151      $inline_min = 0;
152      $inline_max = 0;
153
154      // Add all adjacent inline widths together to calculate max width
155      while ( $iter->valid() && in_array( $iter->current()->get_style()->display, Style::$INLINE_TYPES ) ) {
156
157        $child = $iter->current();
158
159        $minmax = $child->get_min_max_width();
160
161        if ( in_array( $iter->current()->get_style()->white_space, array("pre", "nowrap") ) )
162          $inline_min += $minmax["min"];
163        else
164          $low[] = $minmax["min"];
165
166        $inline_max += $minmax["max"];
167        $iter->next();
168
169      }
170
171      if ( $inline_max == 0 && $iter->valid() ) {
172        list($low[], $high[]) = $iter->current()->get_min_max_width();
173        continue;
174      }
175
176      if ( $inline_max > 0 )
177        $high[] = $inline_max;
178
179      if ( $inline_min > 0 )
180        $low[] = $inline_min;
181
182    }
183
184    $min = count($low) ? max($low) : 0;
185    $max = count($high) ? max($high) : 0;
186
187    // Use specified width if it is greater than the minimum defined by the
188    // content.  If the width is a percentage ignore it for now.
189    $width = $style->width;
190    if ( $width !== "auto" && !is_percent($width) ) {
191      $width = $style->length_in_pt($width, $width);
192      if ( $min < $width )
193        $min = $width;
194    }
195
196    $min += $delta;
197    $max += $delta;
198
199    return array($min, $max, "min"=>$min, "max"=>$max);
200  }
201
202}
203
204?>
Note: See TracBrowser for help on using the repository browser.