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 / FrameDecorator / Inline.php

Inline.php in MBE eShip trunk, at lib/dompdf/src/FrameDecorator/Inline.php

122 lines 3.7 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\FrameDecorator;
8
9 use Dompdf\Dompdf;
10 use Dompdf\Frame;
11 use Dompdf\Exception;
12
13 /**
14 * Decorates frames for inline layout
15 *
16 * @package dompdf
17 */
18 class Inline extends AbstractFrameDecorator
19 {
20
21 /**
22 * Inline constructor.
23 * @param Frame $frame
24 * @param Dompdf $dompdf
25 */
26 function __construct(Frame $frame, Dompdf $dompdf)
27 {
28 parent::__construct($frame, $dompdf);
29 }
30
31 /**
32 * Vertical padding, border, and margin do not apply when determining the
33 * height for inline frames.
34 *
35 * http://www.w3.org/TR/CSS21/visudet.html#inline-non-replaced
36 *
37 * The vertical padding, border and margin of an inline, non-replaced box
38 * start at the top and bottom of the content area, not the
39 * 'line-height'. But only the 'line-height' is used to calculate the
40 * height of the line box.
41 *
42 * @return float
43 */
44 public function get_margin_height(): float
45 {
46 $style = $this->get_style();
47 $font = $style->font_family;
48 $size = $style->font_size;
49 $fontHeight = $this->_dompdf->getFontMetrics()->getFontHeight($font, $size);
50
51 return ($style->line_height / ($size > 0 ? $size : 1)) * $fontHeight;
52 }
53
54 public function split(?Frame $child = null, bool $page_break = false, bool $forced = false): void
55 {
56 if (is_null($child)) {
57 $this->get_parent()->split($this, $page_break, $forced);
58 return;
59 }
60
61 if ($child->get_parent() !== $this) {
62 throw new Exception("Unable to split: frame is not a child of this one.");
63 }
64
65 $this->revert_counter_increment();
66 $node = $this->_frame->get_node();
67 $split = $this->copy($node->cloneNode());
68
69 $style = $this->_frame->get_style();
70 $split_style = $split->get_style();
71
72 // Unset the current node's right style properties
73 $style->margin_right = 0.0;
74 $style->padding_right = 0.0;
75 $style->border_right_width = 0.0;
76 $style->border_top_right_radius = 0.0;
77 $style->border_bottom_right_radius = 0.0;
78
79 // Unset the split node's left style properties since we don't want them
80 // to propagate
81 $split_style->margin_left = 0.0;
82 $split_style->padding_left = 0.0;
83 $split_style->border_left_width = 0.0;
84 $split_style->border_top_left_radius = 0.0;
85 $split_style->border_bottom_left_radius = 0.0;
86
87 // If this is a generated node don't propagate the content style
88 if ($split->get_node()->nodeName == "dompdf_generated") {
89 $split_style->content = "normal";
90 }
91
92 //On continuation of inline element on next line,
93 //don't repeat non-horizontally repeatable background images
94 //See e.g. in testcase image_variants, long descriptions
95 if (($url = $style->background_image) && $url !== "none"
96 && ($repeat = $style->background_repeat) && $repeat !== "repeat" && $repeat !== "repeat-x"
97 ) {
98 $split_style->background_image = "none";
99 }
100
101 $this->get_parent()->insert_child_after($split, $this);
102
103 // Add $child and all following siblings to the new split node
104 $iter = $child;
105 while ($iter) {
106 $frame = $iter;
107 $iter = $iter->get_next_sibling();
108 $frame->reset();
109 $split->append_child($frame);
110 }
111
112 $parent = $this->get_parent();
113
114 if ($page_break) {
115 $parent->split($split, $page_break, $forced);
116 } elseif ($parent instanceof Inline) {
117 $parent->split($split);
118 }
119 }
120
121 }
122