PluginProbe
MBE eShip / trunk
MBE eShip vtrunk
2.8.1 trunk 1.0.0 1.1.0 1.1.3 1.2.1 1.2.2 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.7.1 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.0 2.1.1 2.1.2 2.2.1 All 37 releases
mail-boxes-etc / lib / dompdf / src / Renderer / TableCell.php

TableCell.php in MBE eShip trunk, at lib/dompdf/src/Renderer/TableCell.php

189 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package dompdf
4 * @link https://github.com/dompdf/dompdf
5 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
6 */
7 namespace Dompdf\Renderer;
8
9 use Dompdf\Frame;
10 use Dompdf\FrameDecorator\Table;
11
12 /**
13 * Renders table cells
14 *
15 * @package dompdf
16 */
17 class TableCell extends Block
18 {
19
20 /**
21 * @param Frame $frame
22 */
23 function render(Frame $frame)
24 {
25 $style = $frame->get_style();
26
27 if (trim($frame->get_node()->nodeValue) === "" && $style->empty_cells === "hide") {
28 return;
29 }
30
31 $this->_set_opacity($frame->get_opacity($style->opacity));
32
33 $border_box = $frame->get_border_box();
34 $table = Table::find_parent_table($frame);
35
36 if ($table->get_style()->border_collapse !== "collapse") {
37 $this->_render_background($frame, $border_box);
38 $this->_render_border($frame, $border_box);
39 $this->_render_outline($frame, $border_box);
40 } else {
41 // The collapsed case is slightly complicated...
42
43 $cells = $table->get_cellmap()->get_spanned_cells($frame);
44
45 if (is_null($cells)) {
46 return;
47 }
48
49 // Render the background to the padding box, as the cells are
50 // rendered individually one after another, and we don't want the
51 // background to overlap an adjacent border
52 $padding_box = $frame->get_padding_box();
53
54 $this->_render_background($frame, $padding_box);
55 $this->_render_collapsed_border($frame, $table);
56
57 // FIXME: Outline should be drawn over other cells
58 $this->_render_outline($frame, $border_box);
59 }
60
61 $id = $frame->get_node()->getAttribute("id");
62 if (strlen($id) > 0) {
63 $this->_canvas->add_named_dest($id);
64 }
65
66 // $this->debugBlockLayout($frame, "red", false);
67 }
68
69 /**
70 * @param Frame $frame
71 * @param Table $table
72 */
73 protected function _render_collapsed_border(Frame $frame, Table $table): void
74 {
75 $cellmap = $table->get_cellmap();
76 $cells = $cellmap->get_spanned_cells($frame);
77 $num_rows = $cellmap->get_num_rows();
78 $num_cols = $cellmap->get_num_cols();
79
80 [$table_x, $table_y] = $table->get_position();
81
82 // Determine the top row spanned by this cell
83 $i = $cells["rows"][0];
84 $top_row = $cellmap->get_row($i);
85
86 // Determine if this cell borders on the bottom of the table. If so,
87 // then we draw its bottom border. Otherwise the next row down will
88 // draw its top border instead.
89 if (in_array($num_rows - 1, $cells["rows"])) {
90 $draw_bottom = true;
91 $bottom_row = $cellmap->get_row($num_rows - 1);
92 } else {
93 $draw_bottom = false;
94 }
95
96 // Draw the horizontal borders
97 foreach ($cells["columns"] as $j) {
98 $bp = $cellmap->get_border_properties($i, $j);
99 $col = $cellmap->get_column($j);
100
101 $x = $table_x + $col["x"] - $bp["left"]["width"] / 2;
102 $y = $table_y + $top_row["y"] - $bp["top"]["width"] / 2;
103 $w = $col["used-width"] + ($bp["left"]["width"] + $bp["right"]["width"]) / 2;
104
105 if ($bp["top"]["width"] > 0) {
106 $widths = [
107 (float)$bp["top"]["width"],
108 (float)$bp["right"]["width"],
109 (float)$bp["bottom"]["width"],
110 (float)$bp["left"]["width"]
111 ];
112
113 $method = "_border_" . $bp["top"]["style"];
114 $this->$method($x, $y, $w, $bp["top"]["color"], $widths, "top", "square");
115 }
116
117 if ($draw_bottom) {
118 $bp = $cellmap->get_border_properties($num_rows - 1, $j);
119 if ($bp["bottom"]["width"] <= 0) {
120 continue;
121 }
122
123 $widths = [
124 (float)$bp["top"]["width"],
125 (float)$bp["right"]["width"],
126 (float)$bp["bottom"]["width"],
127 (float)$bp["left"]["width"]
128 ];
129
130 $y = $table_y + $bottom_row["y"] + $bottom_row["height"] + $bp["bottom"]["width"] / 2;
131
132 $method = "_border_" . $bp["bottom"]["style"];
133 $this->$method($x, $y, $w, $bp["bottom"]["color"], $widths, "bottom", "square");
134 }
135 }
136
137 $j = $cells["columns"][0];
138 $left_col = $cellmap->get_column($j);
139
140 if (in_array($num_cols - 1, $cells["columns"])) {
141 $draw_right = true;
142 $right_col = $cellmap->get_column($num_cols - 1);
143 } else {
144 $draw_right = false;
145 }
146
147 // Draw the vertical borders
148 foreach ($cells["rows"] as $i) {
149 $bp = $cellmap->get_border_properties($i, $j);
150 $row = $cellmap->get_row($i);
151
152 $x = $table_x + $left_col["x"] - $bp["left"]["width"] / 2;
153 $y = $table_y + $row["y"] - $bp["top"]["width"] / 2;
154 $h = $row["height"] + ($bp["top"]["width"] + $bp["bottom"]["width"]) / 2;
155
156 if ($bp["left"]["width"] > 0) {
157 $widths = [
158 (float)$bp["top"]["width"],
159 (float)$bp["right"]["width"],
160 (float)$bp["bottom"]["width"],
161 (float)$bp["left"]["width"]
162 ];
163
164 $method = "_border_" . $bp["left"]["style"];
165 $this->$method($x, $y, $h, $bp["left"]["color"], $widths, "left", "square");
166 }
167
168 if ($draw_right) {
169 $bp = $cellmap->get_border_properties($i, $num_cols - 1);
170 if ($bp["right"]["width"] <= 0) {
171 continue;
172 }
173
174 $widths = [
175 (float)$bp["top"]["width"],
176 (float)$bp["right"]["width"],
177 (float)$bp["bottom"]["width"],
178 (float)$bp["left"]["width"]
179 ];
180
181 $x = $table_x + $right_col["x"] + $right_col["used-width"] + $bp["right"]["width"] / 2;
182
183 $method = "_border_" . $bp["right"]["style"];
184 $this->$method($x, $y, $h, $bp["right"]["color"], $widths, "right", "square");
185 }
186 }
187 }
188 }
189