PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.21
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.21
1.10.22 1.10.21 1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 All 166 releases
woocommerce-pos / vendor_prefixed / dompdf / dompdf / src / Renderer / TableCell.php

TableCell.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.21, at vendor_prefixed/dompdf/dompdf/src/Renderer/TableCell.php

138 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @package dompdf
5 * @link https://github.com/dompdf/dompdf
6 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
7 */
8 namespace WCPOS\Vendor\Dompdf\Renderer;
9
10 use WCPOS\Vendor\Dompdf\Exception;
11 use WCPOS\Vendor\Dompdf\Frame;
12 use WCPOS\Vendor\Dompdf\FrameDecorator\Table;
13 /**
14 * Renders table cells
15 *
16 * @package dompdf
17 */
18 class TableCell extends Block
19 {
20 /**
21 * @param Frame $frame
22 */
23 function render(Frame $frame)
24 {
25 $style = $frame->get_style();
26 $node = $frame->get_node();
27 if (\trim($node->nodeValue) === "" && $style->empty_cells === "hide") {
28 return;
29 }
30 $this->_set_opacity($frame->get_opacity($style->opacity));
31 $border_box = $frame->get_border_box();
32 $table = Table::find_parent_table($frame);
33 if ($table === null) {
34 throw new Exception("Parent table not found for table cell");
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 $cells = $table->get_cellmap()->get_spanned_cells($frame);
43 if (\is_null($cells)) {
44 return;
45 }
46 // Render the background to the padding box, as the cells are
47 // rendered individually one after another, and we don't want the
48 // background to overlap an adjacent border
49 $padding_box = $frame->get_padding_box();
50 $this->_render_background($frame, $padding_box);
51 $this->_render_collapsed_border($frame, $table);
52 // FIXME: Outline should be drawn over other cells
53 $this->_render_outline($frame, $border_box);
54 }
55 $this->addNamedDest($node);
56 $this->addHyperlink($node, $border_box);
57 $this->debugBlockLayout($frame, "red", \false);
58 }
59 /**
60 * @param Frame $frame
61 * @param Table $table
62 */
63 protected function _render_collapsed_border(Frame $frame, Table $table) : void
64 {
65 $cellmap = $table->get_cellmap();
66 $cells = $cellmap->get_spanned_cells($frame);
67 $num_rows = $cellmap->get_num_rows();
68 $num_cols = $cellmap->get_num_cols();
69 [$table_x, $table_y] = $table->get_position();
70 // Determine the top row spanned by this cell
71 $i = $cells["rows"][0];
72 $top_row = $cellmap->get_row($i);
73 // Determine if this cell borders on the bottom of the table. If so,
74 // then we draw its bottom border. Otherwise the next row down will
75 // draw its top border instead.
76 if (\in_array($num_rows - 1, $cells["rows"])) {
77 $draw_bottom = \true;
78 $bottom_row = $cellmap->get_row($num_rows - 1);
79 } else {
80 $draw_bottom = \false;
81 }
82 // Draw the horizontal borders
83 foreach ($cells["columns"] as $j) {
84 $bp = $cellmap->get_border_properties($i, $j);
85 $col = $cellmap->get_column($j);
86 $x = $table_x + $col["x"] - $bp["left"]["width"] / 2;
87 $y = $table_y + $top_row["y"] - $bp["top"]["width"] / 2;
88 $w = $col["used-width"] + ($bp["left"]["width"] + $bp["right"]["width"]) / 2;
89 if ($bp["top"]["width"] > 0) {
90 $widths = [(float) $bp["top"]["width"], (float) $bp["right"]["width"], (float) $bp["bottom"]["width"], (float) $bp["left"]["width"]];
91 $method = "_border_" . $bp["top"]["style"];
92 $this->{$method}($x, $y, $w, $bp["top"]["color"], $widths, "top", "square");
93 }
94 if ($draw_bottom) {
95 $bp = $cellmap->get_border_properties($num_rows - 1, $j);
96 if ($bp["bottom"]["width"] <= 0) {
97 continue;
98 }
99 $widths = [(float) $bp["top"]["width"], (float) $bp["right"]["width"], (float) $bp["bottom"]["width"], (float) $bp["left"]["width"]];
100 $y = $table_y + $bottom_row["y"] + $bottom_row["height"] + $bp["bottom"]["width"] / 2;
101 $method = "_border_" . $bp["bottom"]["style"];
102 $this->{$method}($x, $y, $w, $bp["bottom"]["color"], $widths, "bottom", "square");
103 }
104 }
105 $j = $cells["columns"][0];
106 $left_col = $cellmap->get_column($j);
107 if (\in_array($num_cols - 1, $cells["columns"])) {
108 $draw_right = \true;
109 $right_col = $cellmap->get_column($num_cols - 1);
110 } else {
111 $draw_right = \false;
112 }
113 // Draw the vertical borders
114 foreach ($cells["rows"] as $i) {
115 $bp = $cellmap->get_border_properties($i, $j);
116 $row = $cellmap->get_row($i);
117 $x = $table_x + $left_col["x"] - $bp["left"]["width"] / 2;
118 $y = $table_y + $row["y"] - $bp["top"]["width"] / 2;
119 $h = $row["height"] + ($bp["top"]["width"] + $bp["bottom"]["width"]) / 2;
120 if ($bp["left"]["width"] > 0) {
121 $widths = [(float) $bp["top"]["width"], (float) $bp["right"]["width"], (float) $bp["bottom"]["width"], (float) $bp["left"]["width"]];
122 $method = "_border_" . $bp["left"]["style"];
123 $this->{$method}($x, $y, $h, $bp["left"]["color"], $widths, "left", "square");
124 }
125 if ($draw_right) {
126 $bp = $cellmap->get_border_properties($i, $num_cols - 1);
127 if ($bp["right"]["width"] <= 0) {
128 continue;
129 }
130 $widths = [(float) $bp["top"]["width"], (float) $bp["right"]["width"], (float) $bp["bottom"]["width"], (float) $bp["left"]["width"]];
131 $x = $table_x + $right_col["x"] + $right_col["used-width"] + $bp["right"]["width"] / 2;
132 $method = "_border_" . $bp["right"]["style"];
133 $this->{$method}($x, $y, $h, $bp["right"]["color"], $widths, "right", "square");
134 }
135 }
136 }
137 }
138