composer package updates
[openemr.git] / vendor / dompdf / dompdf / src / FrameReflower / TableCell.php
blob87c5cf81843337b5f49c664a8cbaf8c7807e6b26
1 <?php
2 /**
3 * @package dompdf
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
7 */
8 namespace Dompdf\FrameReflower;
10 use Dompdf\FrameDecorator\Block as BlockFrameDecorator;
11 use Dompdf\FrameDecorator\Table as TableFrameDecorator;
13 /**
14 * Reflows table cells
16 * @package dompdf
18 class TableCell extends Block
20 /**
21 * TableCell constructor.
22 * @param BlockFrameDecorator $frame
24 function __construct(BlockFrameDecorator $frame)
26 parent::__construct($frame);
29 /**
30 * @param BlockFrameDecorator|null $block
32 function reflow(BlockFrameDecorator $block = null)
34 $style = $this->_frame->get_style();
36 $table = TableFrameDecorator::find_parent_table($this->_frame);
37 $cellmap = $table->get_cellmap();
39 list($x, $y) = $cellmap->get_frame_position($this->_frame);
40 $this->_frame->set_position($x, $y);
42 $cells = $cellmap->get_spanned_cells($this->_frame);
44 $w = 0;
45 foreach ($cells["columns"] as $i) {
46 $col = $cellmap->get_column($i);
47 $w += $col["used-width"];
50 //FIXME?
51 $h = $this->_frame->get_containing_block("h");
53 $left_space = (float)$style->length_in_pt(array($style->margin_left,
54 $style->padding_left,
55 $style->border_left_width),
56 $w);
58 $right_space = (float)$style->length_in_pt(array($style->padding_right,
59 $style->margin_right,
60 $style->border_right_width),
61 $w);
63 $top_space = (float)$style->length_in_pt(array($style->margin_top,
64 $style->padding_top,
65 $style->border_top_width),
66 $h);
67 $bottom_space = (float)$style->length_in_pt(array($style->margin_bottom,
68 $style->padding_bottom,
69 $style->border_bottom_width),
70 $h);
72 $style->width = $cb_w = $w - $left_space - $right_space;
74 $content_x = $x + $left_space;
75 $content_y = $line_y = $y + $top_space;
77 // Adjust the first line based on the text-indent property
78 $indent = (float)$style->length_in_pt($style->text_indent, $w);
79 $this->_frame->increase_line_width($indent);
81 $page = $this->_frame->get_root();
83 // Set the y position of the first line in the cell
84 $line_box = $this->_frame->get_current_line_box();
85 $line_box->y = $line_y;
87 // Set the containing blocks and reflow each child
88 foreach ($this->_frame->get_children() as $child) {
89 if ($page->is_full()) {
90 break;
93 $child->set_containing_block($content_x, $content_y, $cb_w, $h);
94 $this->process_clear($child);
95 $child->reflow($this->_frame);
96 $this->process_float($child, $x + $left_space, $w - $right_space - $left_space);
99 // Determine our height
100 $style_height = (float)$style->length_in_pt($style->height, $h);
102 $this->_frame->set_content_height($this->_calculate_content_height());
104 $height = max($style_height, (float)$this->_frame->get_content_height());
106 // Let the cellmap know our height
107 $cell_height = $height / count($cells["rows"]);
109 if ($style_height <= $height) {
110 $cell_height += $top_space + $bottom_space;
113 foreach ($cells["rows"] as $i) {
114 $cellmap->set_row_height($i, $cell_height);
117 $style->height = $height;
118 $this->_text_align();
119 $this->vertical_align();