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

Revision 2000, 6.1 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: table_cell_renderer.cls.php,v $
6 * Created on: 2004-06-09
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: table_cell_renderer.cls.php 186 2009-10-19 22:42:06Z eclecticgeek@gmail.com $ */
41
42/**
43 * Renders table cells
44 *
45 * @access private
46 * @package dompdf
47 */
48class Table_Cell_Renderer extends Block_Renderer {
49
50  //........................................................................
51
52  function render(Frame $frame) {
53    $style = $frame->get_style();
54    list($x, $y, $w, $h) = $frame->get_padding_box();
55
56    // Draw our background, border and content
57    if ( ($bg = $style->background_color) !== "transparent" ) {
58      list($x, $y, $w, $h) = $frame->get_padding_box();
59      $this->_canvas->filled_rectangle( $x, $y, $w, $h, $style->background_color );
60    }
61
62    if ( ($url = $style->background_image) && $url !== "none" ) {
63      $this->_background_image($url, $x, $y, $w, $h, $style);
64    }
65
66    if ( $style->border_collapse != "collapse" ) {
67      $this->_render_border($frame, "bevel");
68      return;
69    }
70
71    // The collapsed case is slightly complicated...
72
73    $cellmap = Table_Frame_Decorator::find_parent_table($frame)->get_cellmap();
74    $cells = $cellmap->get_spanned_cells($frame);
75    $num_rows = $cellmap->get_num_rows();
76    $num_cols = $cellmap->get_num_cols();
77
78    // Determine the top row spanned by this cell
79    $i = $cells["rows"][0];
80    $top_row = $cellmap->get_row($i);
81
82    // Determine if this cell borders on the bottom of the table.  If so,
83    // then we draw its bottom border.  Otherwise the next row down will
84    // draw its top border instead.
85    if (in_array( $num_rows - 1, $cells["rows"])) {
86      $draw_bottom = true;
87      $bottom_row = $cellmap->get_row($num_rows - 1);
88    } else
89      $draw_bottom = false;
90
91
92    // Draw the horizontal borders
93    foreach ( $cells["columns"] as $j ) {
94      $bp = $cellmap->get_border_properties($i, $j);
95
96      $y = $top_row["y"] - $bp["top"]["width"] / 2;
97
98      $col = $cellmap->get_column($j);
99      $x = $col["x"] - $bp["left"]["width"] / 2;
100      $w = $col["used-width"] + ($bp["left"]["width"] + $bp["right"]["width"] ) / 2;
101
102      if ( $bp["top"]["style"] != "none" && $bp["top"]["width"] > 0 ) {
103        $widths = array($bp["top"]["width"],
104                        $bp["right"]["width"],
105                        $bp["bottom"]["width"],
106                        $bp["left"]["width"]);
107        $method = "_border_". $bp["top"]["style"];
108        $this->$method($x, $y, $w, $bp["top"]["color"], $widths, "top", "square");
109      }
110
111      if ( $draw_bottom ) {
112        $bp = $cellmap->get_border_properties($num_rows - 1, $j);
113        if ( $bp["bottom"]["style"] == "none" || $bp["bottom"]["width"] <= 0 )
114          continue;
115
116        $y = $bottom_row["y"] + $bottom_row["height"] + $bp["bottom"]["width"] / 2;
117
118        $widths = array($bp["top"]["width"],
119                        $bp["right"]["width"],
120                        $bp["bottom"]["width"],
121                        $bp["left"]["width"]);
122        $method = "_border_". $bp["bottom"]["style"];
123        $this->$method($x, $y, $w, $bp["bottom"]["color"], $widths, "bottom", "square");
124
125      }
126    }
127
128    $j = $cells["columns"][0];
129
130    $left_col = $cellmap->get_column($j);
131
132    if (in_array($num_cols - 1, $cells["columns"])) {
133      $draw_right = true;
134      $right_col = $cellmap->get_column($num_cols - 1);
135    } else
136      $draw_right = false;
137
138    // Draw the vertical borders
139    foreach ( $cells["rows"] as $i ) {
140      $bp = $cellmap->get_border_properties($i, $j);
141
142      $x = $left_col["x"] - $bp["left"]["width"] / 2;
143
144      $row = $cellmap->get_row($i);
145
146      $y = $row["y"] - $bp["top"]["width"] / 2;
147      $h = $row["height"] + ($bp["top"]["width"] + $bp["bottom"]["width"])/ 2;
148
149      if ( $bp["left"]["style"] != "none" && $bp["left"]["width"] > 0 ) {
150
151        $widths = array($bp["top"]["width"],
152                        $bp["right"]["width"],
153                        $bp["bottom"]["width"],
154                        $bp["left"]["width"]);
155
156        $method = "_border_" . $bp["left"]["style"];
157        $this->$method($x, $y, $h, $bp["left"]["color"], $widths, "left", "square");
158      }
159
160      if ( $draw_right ) {
161        $bp = $cellmap->get_border_properties($i, $num_cols - 1);
162        if ( $bp["right"]["style"] == "none" || $bp["right"]["width"] <= 0 )
163          continue;
164
165        $x = $right_col["x"] + $right_col["used-width"] + $bp["right"]["width"] / 2;
166
167        $widths = array($bp["top"]["width"],
168                        $bp["right"]["width"],
169                        $bp["bottom"]["width"],
170                        $bp["left"]["width"]);
171
172        $method = "_border_" . $bp["right"]["style"];
173        $this->$method($x, $y, $h, $bp["right"]["color"], $widths, "right", "square");
174
175      }
176    }
177
178  }
179}
180?>
Note: See TracBrowser for help on using the repository browser.