Blame view
sources/3rdparty/phpdocx/pdf/include/table_cell_renderer.cls.php
6.19 KB
|
31b7f2792
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
<?php
/**
* DOMPDF - PHP5 HTML to PDF renderer
*
* File: $RCSfile: table_cell_renderer.cls.php,v $
* Created on: 2004-06-09
*
* Copyright (c) 2004 - Benj Carson <benjcarson@digitaljunkies.ca>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library in the file LICENSE.LGPL; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*
* Alternatively, you may distribute this software under the terms of the
* PHP License, version 3.0 or later. A copy of this license should have
* been distributed with this file in the file LICENSE.PHP . If this is not
* the case, you can obtain a copy at http://www.php.net/license/3_0.txt.
*
* The latest version of DOMPDF might be available at:
* http://www.dompdf.com/
*
* @link http://www.dompdf.com/
* @copyright 2004 Benj Carson
* @author Benj Carson <benjcarson@digitaljunkies.ca>
* @package dompdf
*/
/* $Id: table_cell_renderer.cls.php 311 2010-09-05 20:02:01Z fabien.menager $ */
/**
* Renders table cells
*
* @access private
* @package dompdf
*/
class Table_Cell_Renderer extends Block_Renderer {
//........................................................................
function render(Frame $frame) {
$style = $frame->get_style();
$this->_set_opacity( $frame->get_opacity( $style->opacity ) );
// Draw our background, border and content
if ( ($bg = $style->background_color) !== "transparent" ) {
list($x, $y, $w, $h) = $frame->get_padding_box();
$this->_canvas->filled_rectangle( $x, $y, $w, $h, $bg );
}
else {
list($x, $y, $w, $h) = $frame->get_padding_box();
}
if ( ($url = $style->background_image) && $url !== "none" ) {
$this->_background_image($url, $x, $y, $w, $h, $style);
}
if ( $style->border_collapse !== "collapse" ) {
$this->_render_border($frame, "bevel");
$this->_render_outline($frame, "bevel");
return;
}
// The collapsed case is slightly complicated...
// @todo Add support for outlines here
$cellmap = Table_Frame_Decorator::find_parent_table($frame)->get_cellmap();
$cells = $cellmap->get_spanned_cells($frame);
$num_rows = $cellmap->get_num_rows();
$num_cols = $cellmap->get_num_cols();
// Determine the top row spanned by this cell
$i = $cells["rows"][0];
$top_row = $cellmap->get_row($i);
// Determine if this cell borders on the bottom of the table. If so,
// then we draw its bottom border. Otherwise the next row down will
// draw its top border instead.
if (in_array( $num_rows - 1, $cells["rows"])) {
$draw_bottom = true;
$bottom_row = $cellmap->get_row($num_rows - 1);
} else
$draw_bottom = false;
// Draw the horizontal borders
foreach ( $cells["columns"] as $j ) {
$bp = $cellmap->get_border_properties($i, $j);
$y = $top_row["y"] - $bp["top"]["width"] / 2;
$col = $cellmap->get_column($j);
$x = $col["x"] - $bp["left"]["width"] / 2;
$w = $col["used-width"] + ($bp["left"]["width"] + $bp["right"]["width"] ) / 2;
if ( $bp["top"]["style"] !== "none" && $bp["top"]["width"] > 0 ) {
$widths = array($bp["top"]["width"],
$bp["right"]["width"],
$bp["bottom"]["width"],
$bp["left"]["width"]);
$method = "_border_". $bp["top"]["style"];
$this->$method($x, $y, $w, $bp["top"]["color"], $widths, "top", "square");
}
if ( $draw_bottom ) {
$bp = $cellmap->get_border_properties($num_rows - 1, $j);
if ( $bp["bottom"]["style"] === "none" || $bp["bottom"]["width"] <= 0 )
continue;
$y = $bottom_row["y"] + $bottom_row["height"] + $bp["bottom"]["width"] / 2;
$widths = array($bp["top"]["width"],
$bp["right"]["width"],
$bp["bottom"]["width"],
$bp["left"]["width"]);
$method = "_border_". $bp["bottom"]["style"];
$this->$method($x, $y, $w, $bp["bottom"]["color"], $widths, "bottom", "square");
}
}
$j = $cells["columns"][0];
$left_col = $cellmap->get_column($j);
if (in_array($num_cols - 1, $cells["columns"])) {
$draw_right = true;
$right_col = $cellmap->get_column($num_cols - 1);
} else
$draw_right = false;
// Draw the vertical borders
foreach ( $cells["rows"] as $i ) {
$bp = $cellmap->get_border_properties($i, $j);
$x = $left_col["x"] - $bp["left"]["width"] / 2;
$row = $cellmap->get_row($i);
$y = $row["y"] - $bp["top"]["width"] / 2;
$h = $row["height"] + ($bp["top"]["width"] + $bp["bottom"]["width"])/ 2;
if ( $bp["left"]["style"] !== "none" && $bp["left"]["width"] > 0 ) {
$widths = array($bp["top"]["width"],
$bp["right"]["width"],
$bp["bottom"]["width"],
$bp["left"]["width"]);
$method = "_border_" . $bp["left"]["style"];
$this->$method($x, $y, $h, $bp["left"]["color"], $widths, "left", "square");
}
if ( $draw_right ) {
$bp = $cellmap->get_border_properties($i, $num_cols - 1);
if ( $bp["right"]["style"] === "none" || $bp["right"]["width"] <= 0 )
continue;
$x = $right_col["x"] + $right_col["used-width"] + $bp["right"]["width"] / 2;
$widths = array($bp["top"]["width"],
$bp["right"]["width"],
$bp["bottom"]["width"],
$bp["left"]["width"]);
$method = "_border_" . $bp["right"]["style"];
$this->$method($x, $y, $h, $bp["right"]["color"], $widths, "right", "square");
}
}
}
}
|