4 * @link http://dompdf.github.com/
5 * @author Benj Carson <benjcarson@digitaljunkies.ca>
6 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
8 namespace Dompdf\Renderer
;
11 use Dompdf\FrameDecorator\Table
;
18 class TableCell
extends Block
24 function render(Frame
$frame)
26 $style = $frame->get_style();
28 if (trim($frame->get_node()->nodeValue
) === "" && $style->empty_cells
=== "hide") {
32 $this->_set_opacity($frame->get_opacity($style->opacity
));
33 list($x, $y, $w, $h) = $frame->get_border_box();
35 // Draw our background, border and content
36 if (($bg = $style->background_color
) !== "transparent") {
37 $this->_canvas
->filled_rectangle($x, $y, (float)$w, (float)$h, $bg);
40 if (($url = $style->background_image
) && $url !== "none") {
41 $this->_background_image($url, $x, $y, $w, $h, $style);
44 $table = Table
::find_parent_table($frame);
46 if ($table->get_style()->border_collapse
!== "collapse") {
47 $this->_render_border($frame);
48 $this->_render_outline($frame);
52 // The collapsed case is slightly complicated...
53 // @todo Add support for outlines here
55 $cellmap = $table->get_cellmap();
56 $cells = $cellmap->get_spanned_cells($frame);
58 if (is_null($cells)) {
62 $num_rows = $cellmap->get_num_rows();
63 $num_cols = $cellmap->get_num_cols();
65 // Determine the top row spanned by this cell
66 $i = $cells["rows"][0];
67 $top_row = $cellmap->get_row($i);
69 // Determine if this cell borders on the bottom of the table. If so,
70 // then we draw its bottom border. Otherwise the next row down will
71 // draw its top border instead.
72 if (in_array($num_rows - 1, $cells["rows"])) {
74 $bottom_row = $cellmap->get_row($num_rows - 1);
79 // Draw the horizontal borders
80 foreach ($cells["columns"] as $j) {
81 $bp = $cellmap->get_border_properties($i, $j);
83 $y = $top_row["y"] - $bp["top"]["width"] / 2;
85 $col = $cellmap->get_column($j);
86 $x = $col["x"] - $bp["left"]["width"] / 2;
87 $w = $col["used-width"] +
($bp["left"]["width"] +
$bp["right"]["width"]) / 2;
89 if ($bp["top"]["style"] !== "none" && $bp["top"]["width"] > 0) {
91 (float)$bp["top"]["width"],
92 (float)$bp["right"]["width"],
93 (float)$bp["bottom"]["width"],
94 (float)$bp["left"]["width"]
96 $method = "_border_" . $bp["top"]["style"];
97 $this->$method($x, $y, $w, $bp["top"]["color"], $widths, "top", "square");
101 $bp = $cellmap->get_border_properties($num_rows - 1, $j);
102 if ($bp["bottom"]["style"] === "none" ||
$bp["bottom"]["width"] <= 0) {
106 $y = $bottom_row["y"] +
$bottom_row["height"] +
$bp["bottom"]["width"] / 2;
109 (float)$bp["top"]["width"],
110 (float)$bp["right"]["width"],
111 (float)$bp["bottom"]["width"],
112 (float)$bp["left"]["width"]
114 $method = "_border_" . $bp["bottom"]["style"];
115 $this->$method($x, $y, $w, $bp["bottom"]["color"], $widths, "bottom", "square");
120 $j = $cells["columns"][0];
122 $left_col = $cellmap->get_column($j);
124 if (in_array($num_cols - 1, $cells["columns"])) {
126 $right_col = $cellmap->get_column($num_cols - 1);
131 // Draw the vertical borders
132 foreach ($cells["rows"] as $i) {
133 $bp = $cellmap->get_border_properties($i, $j);
135 $x = $left_col["x"] - $bp["left"]["width"] / 2;
137 $row = $cellmap->get_row($i);
139 $y = $row["y"] - $bp["top"]["width"] / 2;
140 $h = $row["height"] +
($bp["top"]["width"] +
$bp["bottom"]["width"]) / 2;
142 if ($bp["left"]["style"] !== "none" && $bp["left"]["width"] > 0) {
144 (float)$bp["top"]["width"],
145 (float)$bp["right"]["width"],
146 (float)$bp["bottom"]["width"],
147 (float)$bp["left"]["width"]
150 $method = "_border_" . $bp["left"]["style"];
151 $this->$method($x, $y, $h, $bp["left"]["color"], $widths, "left", "square");
155 $bp = $cellmap->get_border_properties($i, $num_cols - 1);
156 if ($bp["right"]["style"] === "none" ||
$bp["right"]["width"] <= 0) {
160 $x = $right_col["x"] +
$right_col["used-width"] +
$bp["right"]["width"] / 2;
163 (float)$bp["top"]["width"],
164 (float)$bp["right"]["width"],
165 (float)$bp["bottom"]["width"],
166 (float)$bp["left"]["width"]
169 $method = "_border_" . $bp["right"]["style"];
170 $this->$method($x, $y, $h, $bp["right"]["color"], $widths, "right", "square");
174 $id = $frame->get_node()->getAttribute("id");
175 if (strlen($id) > 0) {
176 $this->_canvas
->add_named_dest($id);