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

Revision 1575, 6.3 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: 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,v 1.6 2006/07/07 21:31:03 benjcarson Exp $ */
41
42/**
43 * Renders inline frames
44 *
45 * @access private
46 * @package dompdf
47 */
48class 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
81        // The next child is on another line.  Draw the background &
82        // borders on this line.
83
84        // Background:
85        if ( ($bg = $style->background_color) !== "transparent" )
86          $this->_canvas->filled_rectangle( $x, $y, $w, $h, $style->background_color);
87
88        if ( ($url = $style->background_image) && $url !== "none" ) {
89          $this->_background_image($url, $x, $y, $w, $h, $style);
90        }
91       
92        // If this is the first row, draw the left border
93        if ( $first_row ) {
94
95          if ( $bp["left"]["style"] != "none" && $bp["left"]["width"] > 0 ) {
96            $method = "_border_" . $bp["left"]["style"];           
97            $this->$method($x, $y, $h + $widths[0] + $widths[2], $bp["left"]["color"], $widths, "left");
98          }
99          $first_row = false;
100        }
101
102        // Draw the top & bottom borders
103        if ( $bp["top"]["style"] != "none" && $bp["top"]["width"] > 0 ) {
104          $method = "_border_" . $bp["top"]["style"];
105          $this->$method($x, $y, $w + $widths[1] + $widths[3], $bp["top"]["color"], $widths, "top");
106        }
107       
108        if ( $bp["bottom"]["style"] != "none" && $bp["bottom"]["width"] > 0 ) {
109          $method = "_border_" . $bp["bottom"]["style"];
110          $this->$method($x, $y + $h + $widths[0] + $widths[2], $w + $widths[1] + $widths[3], $bp["bottom"]["color"], $widths, "bottom");
111        }
112
113        // Handle anchors & links
114        if ( $frame->get_node()->nodeName == "a" ) {
115                   
116          if ( $href = $frame->get_node()->getAttribute("href") )
117            $this->_canvas->add_link($href, $x, $y, $w, $h);
118
119        }
120
121        $x = $child_x;
122        $y = $child_y;
123        $w = $child_w;
124        $h = $child_h;
125        continue;
126      }
127
128      if ( is_null($w) )
129        $w = $child_w;
130      else
131        $w += $child_w;
132     
133      $h = max($h, $child_h);
134    }
135
136   
137    // Handle the last child
138    if ( ($bg = $style->background_color) !== "transparent" )
139      $this->_canvas->filled_rectangle( $x + $widths[3], $y + $widths[0], $w, $h, $style->background_color);
140
141    if ( ($url = $style->background_image) && $url !== "none" )           
142      $this->_background_image($url, $x + $widths[3], $y + $widths[0], $w, $h, $style);
143
144       
145    // Add the border widths
146    $w += $widths[1] + $widths[3];
147    $h += $widths[0] + $widths[2];
148
149    // If this is the first row, draw the left border too
150    if ( $first_row && $bp["left"]["style"] != "none" && $widths[3] > 0 ) {
151      $method = "_border_" . $bp["left"]["style"];
152      $this->$method($x, $y, $h, $bp["left"]["color"], $widths, "left");
153    }
154   
155    // Draw the top & bottom borders
156    if ( $bp["top"]["style"] != "none" && $widths[0] > 0 ) {
157      $method = "_border_" . $bp["top"]["style"];
158      $this->$method($x, $y, $w, $bp["top"]["color"], $widths, "top");
159    }
160   
161    if ( $bp["bottom"]["style"] != "none" && $widths[2] > 0 ) {
162      $method = "_border_" . $bp["bottom"]["style"];
163      $this->$method($x, $y + $h, $w, $bp["bottom"]["color"], $widths, "bottom");
164    }
165   
166    // Draw the right border
167    if ( $bp["right"]["style"] != "none" && $widths[1] > 0 ) {
168      $method = "_border_" . $bp["right"]["style"];
169      $this->$method($x + $w, $y, $h, $bp["right"]["color"], $widths, "right");
170    }
171
172    // Handle anchors & links
173    if ( $frame->get_node()->nodeName == "a" ) {
174
175      if ( $name = $frame->get_node()->getAttribute("name") )
176        $this->_canvas->add_named_dest($name);
177
178      if ( $href = $frame->get_node()->getAttribute("href") )
179        $this->_canvas->add_link($href, $x, $y, $w, $h);
180    }
181  }
182}
183?>
Note: See TracBrowser for help on using the repository browser.