1<?php
2
3namespace Mpdf\Tag;
4
5use Mpdf\Mpdf;
6
7class TextArea extends Tag
8{
9
10	public function open($attr, &$ahtml, &$ihtml)
11	{
12		$objattr = [];
13		$objattr['margin_top'] = 0;
14		$objattr['margin_bottom'] = 0;
15		$objattr['margin_left'] = 0;
16		$objattr['margin_right'] = 0;
17		$objattr['width'] = 0;
18		$objattr['height'] = 0;
19		$objattr['border_top']['w'] = 0;
20		$objattr['border_bottom']['w'] = 0;
21		$objattr['border_left']['w'] = 0;
22		$objattr['border_right']['w'] = 0;
23		if (isset($attr['DISABLED'])) {
24			$objattr['disabled'] = true;
25		}
26		if (isset($attr['READONLY'])) {
27			$objattr['readonly'] = true;
28		}
29		if (isset($attr['REQUIRED'])) {
30			$objattr['required'] = true;
31		}
32		if (isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK']) === 'true') {
33			$objattr['spellcheck'] = true;
34		}
35		if (isset($attr['TITLE'])) {
36			$objattr['title'] = $attr['TITLE'];
37			if ($this->mpdf->onlyCoreFonts) {
38				$objattr['title'] = mb_convert_encoding($objattr['title'], $this->mpdf->mb_enc, 'UTF-8');
39			}
40		}
41		if ($this->mpdf->useActiveForms) {
42			if (isset($attr['NAME'])) {
43				$objattr['fieldname'] = $attr['NAME'];
44			}
45			$this->form->form_element_spacing['textarea']['outer']['v'] = 0;
46			$this->form->form_element_spacing['textarea']['inner']['v'] = 0;
47			if (isset($attr['ONCALCULATE'])) {
48				$objattr['onCalculate'] = $attr['ONCALCULATE'];
49			} elseif (isset($attr['ONCHANGE'])) {
50				$objattr['onCalculate'] = $attr['ONCHANGE'];
51			}
52			if (isset($attr['ONVALIDATE'])) {
53				$objattr['onValidate'] = $attr['ONVALIDATE'];
54			}
55			if (isset($attr['ONKEYSTROKE'])) {
56				$objattr['onKeystroke'] = $attr['ONKEYSTROKE'];
57			}
58			if (isset($attr['ONFORMAT'])) {
59				$objattr['onFormat'] = $attr['ONFORMAT'];
60			}
61		}
62		$this->mpdf->InlineProperties['TEXTAREA'] = $this->mpdf->saveInlineProperties();
63		$properties = $this->cssManager->MergeCSS('', 'TEXTAREA', $attr);
64		if (isset($properties['FONT-FAMILY'])) {
65			$this->mpdf->SetFont($properties['FONT-FAMILY'], '', 0, false);
66		}
67		if (isset($properties['FONT-SIZE'])) {
68			$mmsize = $this->sizeConverter->convert($properties['FONT-SIZE'], $this->mpdf->default_font_size / Mpdf::SCALE);
69			$this->mpdf->SetFontSize($mmsize * Mpdf::SCALE, false);
70		}
71		if (isset($properties['COLOR'])) {
72			$objattr['color'] = $this->colorConverter->convert($properties['COLOR'], $this->mpdf->PDFAXwarnings);
73		}
74		$objattr['fontfamily'] = $this->mpdf->FontFamily;
75		$objattr['fontsize'] = $this->mpdf->FontSizePt;
76		if ($this->mpdf->useActiveForms) {
77			if (isset($properties['TEXT-ALIGN'])) {
78				$objattr['text_align'] = $this->getAlign($properties['TEXT-ALIGN']);
79			} elseif (isset($attr['ALIGN'])) {
80				$objattr['text_align'] = $this->getAlign($attr['ALIGN']);
81			}
82			if (isset($properties['OVERFLOW']) && strtolower($properties['OVERFLOW']) === 'hidden') {
83				$objattr['donotscroll'] = true;
84			}
85			if (isset($properties['BORDER-TOP-COLOR'])) {
86				$objattr['border-col'] = $this->colorConverter->convert($properties['BORDER-TOP-COLOR'], $this->mpdf->PDFAXwarnings);
87			}
88			if (isset($properties['BACKGROUND-COLOR'])) {
89				$objattr['background-col'] = $this->colorConverter->convert($properties['BACKGROUND-COLOR'], $this->mpdf->PDFAXwarnings);
90			}
91		}
92		$this->mpdf->SetLineHeight('', $this->form->textarea_lineheight);
93
94		$w = 0;
95		$h = 0;
96		if (isset($properties['WIDTH'])) {
97			$w = $this->sizeConverter->convert(
98				$properties['WIDTH'],
99				$this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
100				$this->mpdf->FontSize,
101				false
102			);
103		}
104		if (isset($properties['HEIGHT'])) {
105			$h = $this->sizeConverter->convert(
106				$properties['HEIGHT'],
107				$this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
108				$this->mpdf->FontSize,
109				false
110			);
111		}
112		if (isset($properties['VERTICAL-ALIGN'])) {
113			$objattr['vertical-align'] = $this->getAlign($properties['VERTICAL-ALIGN']);
114		}
115
116		$colsize = 20; //HTML default value
117		$rowsize = 2; //HTML default value
118		if (isset($attr['COLS'])) {
119			$colsize = (int) $attr['COLS'];
120		}
121		if (isset($attr['ROWS'])) {
122			$rowsize = (int) $attr['ROWS'];
123		}
124
125		$charsize = $this->mpdf->GetCharWidth('w', false);
126		if ($w) {
127			$colsize = round(($w - ($this->form->form_element_spacing['textarea']['outer']['h'] * 2)
128					- ($this->form->form_element_spacing['textarea']['inner']['h'] * 2)) / $charsize);
129		}
130		if ($h) {
131			$rowsize = round(($h - ($this->form->form_element_spacing['textarea']['outer']['v'] * 2)
132					- ($this->form->form_element_spacing['textarea']['inner']['v'] * 2)) / $this->mpdf->lineheight);
133		}
134
135		$objattr['type'] = 'textarea';
136		$objattr['width'] = ($colsize * $charsize) + ($this->form->form_element_spacing['textarea']['outer']['h'] * 2)
137			+ ($this->form->form_element_spacing['textarea']['inner']['h'] * 2);
138
139		$objattr['height'] = ($rowsize * $this->mpdf->lineheight)
140			+ ($this->form->form_element_spacing['textarea']['outer']['v'] * 2)
141			+ ($this->form->form_element_spacing['textarea']['inner']['v'] * 2);
142
143		$objattr['rows'] = $rowsize;
144		$objattr['cols'] = $colsize;
145
146		$this->mpdf->specialcontent = serialize($objattr);
147
148		if ($this->mpdf->tableLevel) { // *TABLES*
149			$this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['s'] += $objattr['width']; // *TABLES*
150		} // *TABLES*
151	}
152
153	public function close(&$ahtml, &$ihtml)
154	{
155		$this->mpdf->ignorefollowingspaces = false;
156		$this->mpdf->specialcontent = '';
157		if ($this->mpdf->InlineProperties['TEXTAREA']) {
158			$this->mpdf->restoreInlineProperties($this->mpdf->InlineProperties['TEXTAREA']);
159		}
160		unset($this->mpdf->InlineProperties['TEXTAREA']);
161	}
162}
163