1<?php
2
3namespace Mpdf\Tag;
4
5use Mpdf\Utils\NumericString;
6
7class Hr extends Tag
8{
9
10	public function open($attr, &$ahtml, &$ihtml)
11	{
12
13		// Added mPDF 3.0 Float DIV - CLEAR
14		if (isset($attr['STYLE'])) {
15			$properties = $this->cssManager->readInlineCSS($attr['STYLE']);
16			if (isset($properties['CLEAR'])) {
17				$this->mpdf->ClearFloats(strtoupper($properties['CLEAR']), $this->mpdf->blklvl);
18			} // *CSS-FLOAT*
19		}
20
21		$this->mpdf->ignorefollowingspaces = true;
22
23		$objattr = [];
24		$objattr['margin_top'] = 0;
25		$objattr['margin_bottom'] = 0;
26		$objattr['margin_left'] = 0;
27		$objattr['margin_right'] = 0;
28		$objattr['width'] = 0;
29		$objattr['height'] = 0;
30		$objattr['border_top']['w'] = 0;
31		$objattr['border_bottom']['w'] = 0;
32		$objattr['border_left']['w'] = 0;
33		$objattr['border_right']['w'] = 0;
34		$properties = $this->cssManager->MergeCSS('', 'HR', $attr);
35		if (isset($properties['MARGIN-TOP'])) {
36			$objattr['margin_top'] = $this->sizeConverter->convert(
37				$properties['MARGIN-TOP'],
38				$this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
39				$this->mpdf->FontSize,
40				false
41			);
42		}
43		if (isset($properties['MARGIN-BOTTOM'])) {
44			$objattr['margin_bottom'] = $this->sizeConverter->convert(
45				$properties['MARGIN-BOTTOM'],
46				$this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
47				$this->mpdf->FontSize,
48				false
49			);
50		}
51		if (isset($properties['WIDTH'])) {
52			$objattr['width'] = $this->sizeConverter->convert($properties['WIDTH'], $this->mpdf->blk[$this->mpdf->blklvl]['inner_width']);
53		} elseif (isset($attr['WIDTH']) && $attr['WIDTH'] != '') {
54			$objattr['width'] = $this->sizeConverter->convert($attr['WIDTH'], $this->mpdf->blk[$this->mpdf->blklvl]['inner_width']);
55		}
56		if (isset($properties['TEXT-ALIGN'])) {
57			$objattr['align'] = $this->getAlign($properties['TEXT-ALIGN']);
58		} elseif (isset($attr['ALIGN']) && $attr['ALIGN'] != '') {
59			$objattr['align'] = $this->getAlign($attr['ALIGN']);
60		}
61
62		if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT']) === 'auto') {
63			$objattr['align'] = 'R';
64		}
65		if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT']) === 'auto') {
66			$objattr['align'] = 'L';
67			if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT']) === 'auto'
68				&& isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT']) === 'auto') {
69				$objattr['align'] = 'C';
70			}
71		}
72		if (isset($properties['COLOR'])) {
73			$objattr['color'] = $this->colorConverter->convert($properties['COLOR'], $this->mpdf->PDFAXwarnings);
74		} elseif (isset($attr['COLOR']) && $attr['COLOR'] != '') {
75			$objattr['color'] = $this->colorConverter->convert($attr['COLOR'], $this->mpdf->PDFAXwarnings);
76		}
77		if (isset($properties['HEIGHT'])) {
78			$objattr['linewidth'] = $this->sizeConverter->convert(
79				$properties['HEIGHT'],
80				$this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
81				$this->mpdf->FontSize,
82				false
83			);
84		}
85
86
87		/* -- TABLES -- */
88		if ($this->mpdf->tableLevel) {
89			$objattr['W-PERCENT'] = 100;
90			if (isset($properties['WIDTH']) && NumericString::containsPercentChar($properties['WIDTH'])) {
91				$properties['WIDTH'] = NumericString::removePercentChar($properties['WIDTH']); // make "90%" become simply "90"
92				$objattr['W-PERCENT'] = $properties['WIDTH'];
93			}
94			if (isset($attr['WIDTH']) && NumericString::containsPercentChar($attr['WIDTH'])) {
95				$attr['WIDTH'] = NumericString::removePercentChar($attr['WIDTH']); // make "90%" become simply "90"
96				$objattr['W-PERCENT'] = $attr['WIDTH'];
97			}
98		}
99		/* -- END TABLES -- */
100
101		$objattr['type'] = 'hr';
102		$objattr['height'] = $objattr['linewidth'] + $objattr['margin_top'] + $objattr['margin_bottom'];
103		$e = "\xbb\xa4\xactype=image,objattr=" . serialize($objattr) . "\xbb\xa4\xac";
104
105		/* -- TABLES -- */
106		// Output it to buffers
107		if ($this->mpdf->tableLevel) {
108			if ($this->mpdf->cell) {
109				if (!isset($this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['maxs'])) {
110					$this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['maxs'] = $this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['s'];
111				} elseif ($this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['maxs'] < $this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['s']) {
112					$this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['maxs'] = $this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['s'];
113				}
114				$this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['s'] = 0; // reset
115				$this->mpdf->_saveCellTextBuffer($e, $this->mpdf->HREF);
116			}
117		} else {
118			/* -- END TABLES -- */
119			$this->mpdf->_saveTextBuffer($e, $this->mpdf->HREF);
120		} // *TABLES*
121	}
122
123	public function close(&$ahtml, &$ihtml)
124	{
125	}
126}
127