PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.22
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.22
1.10.24 1.10.23 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 All 168 releases
woocommerce-pos / vendor_prefixed / dompdf / dompdf / src / Renderer / Text.php

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

129 lines 5.1 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\Adapter\CPDF;
11 use WCPOS\Vendor\Dompdf\Frame;
12 /**
13 * Renders text frames
14 *
15 * @package dompdf
16 */
17 class Text extends AbstractRenderer
18 {
19 /** Thickness of underline. Screen: 0.08, print: better less, e.g. 0.04 */
20 const DECO_THICKNESS = 0.02;
21 //Tweaking if $base and $descent are not accurate.
22 //Check method_exists( $this->_canvas, "get_cpdf" )
23 //- For cpdf these can and must stay 0, because font metrics are used directly.
24 //- For other renderers, if different values are wanted, separate the parameter sets.
25 // But $size and $size-$height seem to be accurate enough
26 /** Relative to bottom of text, as fraction of height */
27 const UNDERLINE_OFFSET = 0.0;
28 /** Relative to top of text */
29 const OVERLINE_OFFSET = 0.0;
30 /** Relative to centre of text. */
31 const LINETHROUGH_OFFSET = 0.0;
32 /** How far to extend lines past either end, in pt */
33 const DECO_EXTENSION = 0.0;
34 /**
35 * @param \Dompdf\FrameDecorator\Text $frame
36 */
37 function render(Frame $frame)
38 {
39 $style = $frame->get_style();
40 $text = $frame->get_text();
41 if ($text === "") {
42 return;
43 }
44 $this->_set_opacity($frame->get_opacity($style->opacity));
45 [$x, $y] = $frame->get_position();
46 $cb = $frame->get_containing_block();
47 $ml = $style->margin_left;
48 $pl = $style->padding_left;
49 $bl = $style->border_left_width;
50 $x += (float) $style->length_in_pt([$ml, $pl, $bl], $cb["w"]);
51 $font = $style->font_family;
52 $size = $style->font_size;
53 $frame_font_size = $frame->get_dompdf()->getFontMetrics()->getFontHeight($font, $size);
54 $word_spacing = $frame->get_text_spacing() + $style->word_spacing;
55 $letter_spacing = $style->letter_spacing;
56 $width = (float) $style->width;
57 /*$text = str_replace(
58 array("{PAGE_NUM}"),
59 array($this->_canvas->get_page_number()),
60 $text
61 );*/
62 $this->_canvas->text($x, $y, $text, $font, $size, $style->color, $word_spacing, $letter_spacing);
63 $line = $frame->get_containing_line();
64 // FIXME Instead of using the tallest frame to position,
65 // the decoration, the text should be well placed
66 if (\false && $line->tallest_frame) {
67 $base_frame = $line->tallest_frame;
68 $style = $base_frame->get_style();
69 $size = $style->font_size;
70 }
71 $line_thickness = $size * self::DECO_THICKNESS;
72 $underline_offset = $size * self::UNDERLINE_OFFSET;
73 $overline_offset = $size * self::OVERLINE_OFFSET;
74 $linethrough_offset = $size * self::LINETHROUGH_OFFSET;
75 $underline_position = -0.08;
76 if ($this->_canvas instanceof CPDF) {
77 $cpdf_font = $this->_canvas->get_cpdf()->fonts[$style->font_family];
78 if (isset($cpdf_font["UnderlinePosition"])) {
79 $underline_position = $cpdf_font["UnderlinePosition"] / 1000;
80 }
81 if (isset($cpdf_font["UnderlineThickness"])) {
82 $line_thickness = $size * ($cpdf_font["UnderlineThickness"] / 1000);
83 }
84 }
85 $descent = $size * $underline_position;
86 $base = $frame_font_size;
87 // Handle text decoration:
88 // http://www.w3.org/TR/CSS21/text.html#propdef-text-decoration
89 // Draw all applicable text-decorations. Start with the root and work our way down.
90 $p = $frame;
91 $stack = [];
92 while ($p = $p->get_parent()) {
93 $stack[] = $p;
94 }
95 while (isset($stack[0])) {
96 $f = \array_pop($stack);
97 if (($text_deco = $f->get_style()->text_decoration) === "none") {
98 continue;
99 }
100 $deco_y = $y;
101 //$line->y;
102 $color = $f->get_style()->color;
103 switch ($text_deco) {
104 default:
105 continue 2;
106 case "underline":
107 $deco_y += $base - $descent + $underline_offset + $line_thickness / 2;
108 break;
109 case "overline":
110 $deco_y += $overline_offset + $line_thickness / 2;
111 break;
112 case "line-through":
113 $deco_y += $base * 0.7 + $linethrough_offset;
114 break;
115 }
116 $dx = 0;
117 $x1 = $x - self::DECO_EXTENSION;
118 $x2 = $x + $width + $dx + self::DECO_EXTENSION;
119 $this->_canvas->line($x1, $deco_y, $x2, $deco_y, $color, $line_thickness);
120 }
121 $options = $this->_dompdf->getOptions();
122 if ($options->getDebugLayout() && $options->getDebugLayoutLines()) {
123 $fontMetrics = $this->_dompdf->getFontMetrics();
124 $textWidth = $fontMetrics->getTextWidth($text, $font, $size, $word_spacing, $letter_spacing);
125 $this->debugLayout([$x, $y, $textWidth, $frame_font_size], "orange", [0.5, 0.5]);
126 }
127 }
128 }
129