PageRenderTime 54ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/application/third_party/vendor/mpdf/mpdf/src/Tag/Input.php

https://gitlab.com/devdoblea/factutextil.local
PHP | 425 lines | 377 code | 30 blank | 18 comment | 94 complexity | c46fe8a5c6a83e37b3889972621536b7 MD5 | raw file
  1. <?php
  2. namespace Mpdf\Tag;
  3. use Mpdf\Mpdf;
  4. use Mpdf\Utils\UtfString;
  5. class Input extends Tag
  6. {
  7. public function open($attr, &$ahtml, &$ihtml)
  8. {
  9. $tag = $this->getTagName();
  10. $this->mpdf->ignorefollowingspaces = false;
  11. if (!isset($attr['TYPE'])) {
  12. $attr['TYPE'] = 'TEXT';
  13. }
  14. $objattr = [];
  15. $objattr['margin_top'] = 0;
  16. $objattr['margin_bottom'] = 0;
  17. $objattr['margin_left'] = 0;
  18. $objattr['margin_right'] = 0;
  19. $objattr['width'] = 0;
  20. $objattr['height'] = 0;
  21. $objattr['border_top']['w'] = 0;
  22. $objattr['border_bottom']['w'] = 0;
  23. $objattr['border_left']['w'] = 0;
  24. $objattr['border_right']['w'] = 0;
  25. $objattr['type'] = 'input';
  26. if (isset($attr['DISABLED'])) {
  27. $objattr['disabled'] = true;
  28. }
  29. if (isset($attr['READONLY'])) {
  30. $objattr['readonly'] = true;
  31. }
  32. if (isset($attr['REQUIRED'])) {
  33. $objattr['required'] = true;
  34. }
  35. if (isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK']) === 'true') {
  36. $objattr['spellcheck'] = true;
  37. }
  38. if (isset($attr['TITLE'])) {
  39. $objattr['title'] = $attr['TITLE'];
  40. } elseif (isset($attr['ALT'])) {
  41. $objattr['title'] = $attr['ALT'];
  42. } else {
  43. $objattr['title'] = '';
  44. }
  45. $objattr['title'] = UtfString::strcode2utf($objattr['title']);
  46. $objattr['title'] = $this->mpdf->lesser_entity_decode($objattr['title']);
  47. if ($this->mpdf->onlyCoreFonts) {
  48. $objattr['title'] = mb_convert_encoding($objattr['title'], $this->mpdf->mb_enc, 'UTF-8');
  49. }
  50. if ($this->mpdf->useActiveForms && isset($attr['NAME'])) {
  51. $objattr['fieldname'] = $attr['NAME'];
  52. }
  53. if (isset($attr['VALUE'])) {
  54. $attr['VALUE'] = UtfString::strcode2utf($attr['VALUE']);
  55. $attr['VALUE'] = $this->mpdf->lesser_entity_decode($attr['VALUE']);
  56. if ($this->mpdf->onlyCoreFonts) {
  57. $attr['VALUE'] = mb_convert_encoding($attr['VALUE'], $this->mpdf->mb_enc, 'UTF-8');
  58. }
  59. $objattr['value'] = $attr['VALUE'];
  60. }
  61. $this->mpdf->InlineProperties['INPUT'] = $this->mpdf->saveInlineProperties();
  62. $properties = $this->cssManager->MergeCSS('', 'INPUT', $attr);
  63. $objattr['vertical-align'] = '';
  64. if (isset($properties['FONT-FAMILY'])) {
  65. $this->mpdf->SetFont($properties['FONT-FAMILY'], $this->mpdf->FontStyle, 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($attr['ALIGN'])) {
  78. $objattr['text_align'] = self::ALIGN[strtolower($attr['ALIGN'])];
  79. } elseif (isset($properties['TEXT-ALIGN'])) {
  80. $objattr['text_align'] = self::ALIGN[strtolower($properties['TEXT-ALIGN'])];
  81. }
  82. if (isset($properties['BORDER-TOP-COLOR'])) {
  83. $objattr['border-col'] = $this->colorConverter->convert($properties['BORDER-TOP-COLOR'], $this->mpdf->PDFAXwarnings);
  84. }
  85. if (isset($properties['BACKGROUND-COLOR'])) {
  86. $objattr['background-col'] = $this->colorConverter->convert($properties['BACKGROUND-COLOR'], $this->mpdf->PDFAXwarnings);
  87. }
  88. }
  89. $type = '';
  90. $texto = '';
  91. $height = $this->mpdf->FontSize;
  92. $width = 0;
  93. $spacesize = $this->mpdf->GetCharWidth(' ', false);
  94. $w = 0;
  95. if (isset($properties['WIDTH'])) {
  96. $w = $this->sizeConverter->convert($properties['WIDTH'], $this->mpdf->blk[$this->mpdf->blklvl]['inner_width']);
  97. }
  98. if ($properties['VERTICAL-ALIGN']) {
  99. $objattr['vertical-align'] = self::ALIGN[strtolower($properties['VERTICAL-ALIGN'])];
  100. }
  101. switch (strtoupper($attr['TYPE'])) {
  102. case 'HIDDEN':
  103. $this->mpdf->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  104. if ($this->mpdf->useActiveForms) {
  105. $this->form->SetFormText(0, 0, $objattr['fieldname'], $objattr['value'], $objattr['value'], '', 0, '', true);
  106. }
  107. if ($this->mpdf->InlineProperties[$tag]) {
  108. $this->mpdf->restoreInlineProperties($this->mpdf->InlineProperties[$tag]);
  109. }
  110. unset($this->mpdf->InlineProperties[$tag]);
  111. return;
  112. case 'CHECKBOX': //Draw Checkbox
  113. $type = 'CHECKBOX';
  114. if (isset($attr['CHECKED'])) {
  115. $objattr['checked'] = true;
  116. } else {
  117. $objattr['checked'] = false;
  118. }
  119. $width = $this->mpdf->FontSize;
  120. $height = $this->mpdf->FontSize;
  121. break;
  122. case 'RADIO': //Draw Radio button
  123. $type = 'RADIO';
  124. if (isset($attr['CHECKED'])) {
  125. $objattr['checked'] = true;
  126. }
  127. $width = $this->mpdf->FontSize;
  128. $height = $this->mpdf->FontSize;
  129. break;
  130. /* -- IMAGES-CORE -- */
  131. case 'IMAGE': // Draw an Image button
  132. if (isset($attr['SRC'])) {
  133. $type = 'IMAGE';
  134. $srcpath = $attr['SRC'];
  135. $orig_srcpath = $attr['ORIG_SRC'];
  136. // VSPACE and HSPACE converted to margins in MergeCSS
  137. if (isset($properties['MARGIN-TOP'])) {
  138. $objattr['margin_top'] = $this->sizeConverter->convert(
  139. $properties['MARGIN-TOP'],
  140. $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
  141. $this->mpdf->FontSize,
  142. false
  143. );
  144. }
  145. if (isset($properties['MARGIN-BOTTOM'])) {
  146. $objattr['margin_bottom'] = $this->sizeConverter->convert(
  147. $properties['MARGIN-BOTTOM'],
  148. $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
  149. $this->mpdf->FontSize,
  150. false
  151. );
  152. }
  153. if (isset($properties['MARGIN-LEFT'])) {
  154. $objattr['margin_left'] = $this->sizeConverter->convert(
  155. $properties['MARGIN-LEFT'],
  156. $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
  157. $this->mpdf->FontSize,
  158. false
  159. );
  160. }
  161. if (isset($properties['MARGIN-RIGHT'])) {
  162. $objattr['margin_right'] = $this->sizeConverter->convert(
  163. $properties['MARGIN-RIGHT'],
  164. $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],
  165. $this->mpdf->FontSize,
  166. false
  167. );
  168. }
  169. if (isset($properties['BORDER-TOP'])) {
  170. $objattr['border_top'] = $this->mpdf->border_details($properties['BORDER-TOP']);
  171. }
  172. if (isset($properties['BORDER-BOTTOM'])) {
  173. $objattr['border_bottom'] = $this->mpdf->border_details($properties['BORDER-BOTTOM']);
  174. }
  175. if (isset($properties['BORDER-LEFT'])) {
  176. $objattr['border_left'] = $this->mpdf->border_details($properties['BORDER-LEFT']);
  177. }
  178. if (isset($properties['BORDER-RIGHT'])) {
  179. $objattr['border_right'] = $this->mpdf->border_details($properties['BORDER-RIGHT']);
  180. }
  181. $objattr['padding_top'] = 0;
  182. $objattr['padding_bottom'] = 0;
  183. $objattr['padding_left'] = 0;
  184. $objattr['padding_right'] = 0;
  185. if (isset($properties['VERTICAL-ALIGN'])) {
  186. $objattr['vertical-align'] = self::ALIGN[strtolower($properties['VERTICAL-ALIGN'])];
  187. }
  188. $w = 0;
  189. $h = 0;
  190. if (isset($properties['WIDTH'])) {
  191. $w = $this->sizeConverter->convert($properties['WIDTH'], $this->mpdf->blk[$this->mpdf->blklvl]['inner_width']);
  192. }
  193. if (isset($properties['HEIGHT'])) {
  194. $h = $this->sizeConverter->convert($properties['HEIGHT'], $this->mpdf->blk[$this->mpdf->blklvl]['inner_width']);
  195. }
  196. $extraheight = $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  197. $extrawidth = $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  198. // Image file
  199. $info = $this->imageProcessor->getImage($srcpath, true, true, $orig_srcpath);
  200. if (!$info) {
  201. $info = $this->imageProcessor->getImage($this->mpdf->noImageFile);
  202. if ($info) {
  203. $srcpath = $this->mpdf->noImageFile;
  204. $w = ($info['w'] * (25.4 / $this->mpdf->img_dpi));
  205. $h = ($info['h'] * (25.4 / $this->mpdf->img_dpi));
  206. }
  207. }
  208. if (!$info) {
  209. break;
  210. }
  211. if ($info['cs'] === 'Indexed') {
  212. $objattr['Indexed'] = true;
  213. }
  214. $objattr['file'] = $srcpath;
  215. //Default width and height calculation if needed
  216. if ($w == 0 && $h == 0) {
  217. /* -- IMAGES-WMF -- */
  218. if ($info['type'] === 'wmf') {
  219. // WMF units are twips (1/20pt)
  220. // divide by 20 to get points
  221. // divide by k to get user units
  222. $w = abs($info['w']) / (20 * Mpdf::SCALE);
  223. $h = abs($info['h']) / (20 * Mpdf::SCALE);
  224. } else { /* -- END IMAGES-WMF -- */
  225. if ($info['type'] === 'svg') {
  226. // SVG units are pixels
  227. $w = abs($info['w']) / Mpdf::SCALE;
  228. $h = abs($info['h']) / Mpdf::SCALE;
  229. } else {
  230. //Put image at default image dpi
  231. $w = ($info['w'] / Mpdf::SCALE) * (72 / $this->mpdf->img_dpi);
  232. $h = ($info['h'] / Mpdf::SCALE) * (72 / $this->mpdf->img_dpi);
  233. }
  234. }
  235. if (isset($properties['IMAGE-RESOLUTION'])) {
  236. if (preg_match('/from-image/i', $properties['IMAGE-RESOLUTION']) && isset($info['set-dpi']) && $info['set-dpi'] > 0) {
  237. $w *= $this->mpdf->img_dpi / $info['set-dpi'];
  238. $h *= $this->mpdf->img_dpi / $info['set-dpi'];
  239. } elseif (preg_match('/(\d+)dpi/i', $properties['IMAGE-RESOLUTION'], $m)) {
  240. $dpi = $m[1];
  241. if ($dpi > 0) {
  242. $w *= $this->mpdf->img_dpi / $dpi;
  243. $h *= $this->mpdf->img_dpi / $dpi;
  244. }
  245. }
  246. }
  247. }
  248. // IF WIDTH OR HEIGHT SPECIFIED
  249. if ($w == 0) {
  250. $w = $h * $info['w'] / $info['h'];
  251. }
  252. if ($h == 0) {
  253. $h = $w * $info['h'] / $info['w'];
  254. }
  255. // Resize to maximum dimensions of page
  256. $maxWidth = $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'];
  257. $maxHeight = $this->mpdf->h - ($this->mpdf->tMargin + $this->mpdf->bMargin + 10);
  258. if ($this->mpdf->fullImageHeight) {
  259. $maxHeight = $this->mpdf->fullImageHeight;
  260. }
  261. if (($w + $extrawidth) > ($maxWidth + 0.0001)) { // mPDF 5.7.4 0.0001 to allow for rounding errors when w==maxWidth
  262. $w = $maxWidth - $extrawidth;
  263. $h = $w * $info['h'] / $info['w'];
  264. }
  265. if ($h + $extraheight > $maxHeight) {
  266. $h = $maxHeight - $extraheight;
  267. $w = $h * $info['w'] / $info['h'];
  268. }
  269. $height = $h + $extraheight;
  270. $width = $w + $extrawidth;
  271. $objattr['type'] = 'image';
  272. $objattr['itype'] = $info['type'];
  273. $objattr['orig_h'] = $info['h'];
  274. $objattr['orig_w'] = $info['w'];
  275. /* -- IMAGES-WMF -- */
  276. if ($info['type'] === 'wmf') {
  277. $objattr['wmf_x'] = $info['x'];
  278. $objattr['wmf_y'] = $info['y'];
  279. /* -- END IMAGES-WMF -- */
  280. } else {
  281. if ($info['type'] === 'svg') {
  282. $objattr['wmf_x'] = $info['x'];
  283. $objattr['wmf_y'] = $info['y'];
  284. }
  285. }
  286. $objattr['height'] = $h + $extraheight;
  287. $objattr['width'] = $w + $extrawidth;
  288. $objattr['image_height'] = $h;
  289. $objattr['image_width'] = $w;
  290. $objattr['ID'] = $info['i'];
  291. $texto = 'X';
  292. if ($this->mpdf->useActiveForms) {
  293. if (isset($attr['ONCLICK'])) {
  294. $objattr['onClick'] = $attr['ONCLICK'];
  295. }
  296. $objattr['type'] = 'input';
  297. $type = 'IMAGE';
  298. }
  299. break;
  300. }
  301. /* -- END IMAGES-CORE -- */
  302. case 'BUTTON': // Draw a button
  303. case 'SUBMIT':
  304. case 'RESET':
  305. $type = strtoupper($attr['TYPE']);
  306. if ($type === 'IMAGE') {
  307. $type = 'BUTTON';
  308. } // src path not found
  309. if (isset($attr['NOPRINT'])) {
  310. $objattr['noprint'] = true;
  311. }
  312. if (!isset($attr['VALUE'])) {
  313. $objattr['value'] = ucfirst(strtolower($type));
  314. }
  315. $texto = ' ' . $objattr['value'] . ' ';
  316. $width = $this->mpdf->GetStringWidth($texto) + ($this->form->form_element_spacing['button']['outer']['h'] * 2)
  317. + ($this->form->form_element_spacing['button']['inner']['h'] * 2);
  318. $height = $this->mpdf->FontSize + ($this->form->form_element_spacing['button']['outer']['v'] * 2)
  319. + ($this->form->form_element_spacing['button']['inner']['v'] * 2);
  320. if ($this->mpdf->useActiveForms && isset($attr['ONCLICK'])) {
  321. $objattr['onClick'] = $attr['ONCLICK'];
  322. }
  323. break;
  324. case 'PASSWORD':
  325. case 'TEXT':
  326. default:
  327. if ($type == '') {
  328. $type = 'TEXT';
  329. }
  330. if (strtoupper($attr['TYPE']) === 'PASSWORD') {
  331. $type = 'PASSWORD';
  332. }
  333. if (isset($attr['VALUE'])) {
  334. if ($type === 'PASSWORD') {
  335. $num_stars = mb_strlen($attr['VALUE'], $this->mpdf->mb_enc);
  336. $texto = str_repeat('*', $num_stars);
  337. } else {
  338. $texto = $attr['VALUE'];
  339. }
  340. }
  341. $xw = ($this->form->form_element_spacing['input']['outer']['h'] * 2) + ($this->form->form_element_spacing['input']['inner']['h'] * 2);
  342. $xh = ($this->form->form_element_spacing['input']['outer']['v'] * 2) + ($this->form->form_element_spacing['input']['inner']['v'] * 2);
  343. if ($w) {
  344. $width = $w + $xw;
  345. } else {
  346. $width = (20 * $spacesize) + $xw;
  347. } // Default width in chars
  348. if (isset($attr['SIZE']) && ctype_digit($attr['SIZE'])) {
  349. $width = ($attr['SIZE'] * $spacesize) + $xw;
  350. }
  351. $height = $this->mpdf->FontSize + $xh;
  352. if (isset($attr['MAXLENGTH']) && ctype_digit($attr['MAXLENGTH'])) {
  353. $objattr['maxlength'] = $attr['MAXLENGTH'];
  354. }
  355. if ($this->mpdf->useActiveForms) {
  356. if (isset($attr['ONCALCULATE'])) {
  357. $objattr['onCalculate'] = $attr['ONCALCULATE'];
  358. } elseif (isset($attr['ONCHANGE'])) {
  359. $objattr['onCalculate'] = $attr['ONCHANGE'];
  360. }
  361. if (isset($attr['ONVALIDATE'])) {
  362. $objattr['onValidate'] = $attr['ONVALIDATE'];
  363. }
  364. if (isset($attr['ONKEYSTROKE'])) {
  365. $objattr['onKeystroke'] = $attr['ONKEYSTROKE'];
  366. }
  367. if (isset($attr['ONFORMAT'])) {
  368. $objattr['onFormat'] = $attr['ONFORMAT'];
  369. }
  370. }
  371. break;
  372. }
  373. $objattr['subtype'] = $type;
  374. $objattr['text'] = $texto;
  375. $objattr['width'] = $width;
  376. $objattr['height'] = $height;
  377. $e = "\xbb\xa4\xactype=input,objattr=" . serialize($objattr) . "\xbb\xa4\xac";
  378. /* -- TABLES -- */
  379. // Output it to buffers
  380. if ($this->mpdf->tableLevel) {
  381. $this->mpdf->_saveCellTextBuffer($e, $this->mpdf->HREF);
  382. $this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['s'] += $objattr['width'];
  383. } else {
  384. /* -- END TABLES -- */
  385. $this->mpdf->_saveTextBuffer($e, $this->mpdf->HREF);
  386. } // *TABLES*
  387. if ($this->mpdf->InlineProperties[$tag]) {
  388. $this->mpdf->restoreInlineProperties($this->mpdf->InlineProperties[$tag]);
  389. }
  390. unset($this->mpdf->InlineProperties[$tag]);
  391. }
  392. public function close(&$ahtml, &$ihtml)
  393. {
  394. }
  395. }