1<?php 2 3namespace Mpdf\Tag; 4 5use Mpdf\Mpdf; 6 7class Select extends Tag 8{ 9 10 public function open($attr, &$ahtml, &$ihtml) 11 { 12 $this->mpdf->lastoptionaltag = ''; // Save current HTML specified optional endtag 13 $this->mpdf->InlineProperties['SELECT'] = $this->mpdf->saveInlineProperties(); 14 $properties = $this->cssManager->MergeCSS('', 'SELECT', $attr); 15 if (isset($properties['FONT-FAMILY'])) { 16 $this->mpdf->SetFont($properties['FONT-FAMILY'], $this->mpdf->FontStyle, 0, false); 17 } 18 if (isset($properties['FONT-SIZE'])) { 19 $mmsize = $this->sizeConverter->convert($properties['FONT-SIZE'], $this->mpdf->default_font_size / Mpdf::SCALE); 20 $this->mpdf->SetFontSize($mmsize * Mpdf::SCALE, false); 21 } 22 if (isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK']) === 'true') { 23 $this->mpdf->selectoption['SPELLCHECK'] = true; 24 } 25 26 if (isset($properties['COLOR'])) { 27 $this->mpdf->selectoption['COLOR'] = $this->colorConverter->convert($properties['COLOR'], $this->mpdf->PDFAXwarnings); 28 } 29 $this->mpdf->specialcontent = 'type=select'; 30 if (isset($attr['DISABLED'])) { 31 $this->mpdf->selectoption['DISABLED'] = $attr['DISABLED']; 32 } 33 if (isset($attr['READONLY'])) { 34 $this->mpdf->selectoption['READONLY'] = $attr['READONLY']; 35 } 36 if (isset($attr['REQUIRED'])) { 37 $this->mpdf->selectoption['REQUIRED'] = $attr['REQUIRED']; 38 } 39 if (isset($attr['EDITABLE'])) { 40 $this->mpdf->selectoption['EDITABLE'] = $attr['EDITABLE']; 41 } 42 if (isset($attr['TITLE'])) { 43 $this->mpdf->selectoption['TITLE'] = $attr['TITLE']; 44 } 45 if (isset($attr['MULTIPLE'])) { 46 $this->mpdf->selectoption['MULTIPLE'] = $attr['MULTIPLE']; 47 } 48 if (isset($attr['SIZE']) && $attr['SIZE'] > 1) { 49 $this->mpdf->selectoption['SIZE'] = $attr['SIZE']; 50 } 51 if ($this->mpdf->useActiveForms) { 52 if (isset($attr['NAME'])) { 53 $this->mpdf->selectoption['NAME'] = $attr['NAME']; 54 } 55 if (isset($attr['ONCHANGE'])) { 56 $this->mpdf->selectoption['ONCHANGE'] = $attr['ONCHANGE']; 57 } 58 } 59 } 60 61 public function close(&$ahtml, &$ihtml) 62 { 63 $this->mpdf->ignorefollowingspaces = false; 64 $this->mpdf->lastoptionaltag = ''; 65 $texto = ''; 66 $OTLdata = false; 67 if (isset($this->mpdf->selectoption['SELECTED'])) { 68 $texto = $this->mpdf->selectoption['SELECTED']; 69 } 70 if (isset($this->mpdf->selectoption['SELECTED-OTLDATA'])) { 71 $OTLdata = $this->mpdf->selectoption['SELECTED-OTLDATA']; 72 } 73 74 if ($this->mpdf->useActiveForms) { 75 $w = $this->mpdf->selectoption['MAXWIDTH']; 76 } else { 77 $w = $this->mpdf->GetStringWidth($texto, true, $OTLdata); 78 } 79 if ($w == 0) { 80 $w = 5; 81 } 82 $objattr['type'] = 'select'; 83 $objattr['text'] = $texto; 84 $objattr['OTLdata'] = $OTLdata; 85 if (isset($this->mpdf->selectoption['NAME'])) { 86 $objattr['fieldname'] = $this->mpdf->selectoption['NAME']; 87 } 88 if (isset($this->mpdf->selectoption['READONLY'])) { 89 $objattr['readonly'] = true; 90 } 91 if (isset($this->mpdf->selectoption['REQUIRED'])) { 92 $objattr['required'] = true; 93 } 94 if (isset($this->mpdf->selectoption['SPELLCHECK'])) { 95 $objattr['spellcheck'] = true; 96 } 97 if (isset($this->mpdf->selectoption['EDITABLE'])) { 98 $objattr['editable'] = true; 99 } 100 if (isset($this->mpdf->selectoption['ONCHANGE'])) { 101 $objattr['onChange'] = $this->mpdf->selectoption['ONCHANGE']; 102 } 103 if (isset($this->mpdf->selectoption['ITEMS'])) { 104 $objattr['items'] = $this->mpdf->selectoption['ITEMS']; 105 } 106 if (isset($this->mpdf->selectoption['MULTIPLE'])) { 107 $objattr['multiple'] = $this->mpdf->selectoption['MULTIPLE']; 108 } 109 if (isset($this->mpdf->selectoption['DISABLED'])) { 110 $objattr['disabled'] = $this->mpdf->selectoption['DISABLED']; 111 } 112 if (isset($this->mpdf->selectoption['TITLE'])) { 113 $objattr['title'] = $this->mpdf->selectoption['TITLE']; 114 } 115 if (isset($this->mpdf->selectoption['COLOR'])) { 116 $objattr['color'] = $this->mpdf->selectoption['COLOR']; 117 } 118 if (isset($this->mpdf->selectoption['SIZE'])) { 119 $objattr['size'] = $this->mpdf->selectoption['SIZE']; 120 } 121 $rows = 1; 122 if (isset($objattr['size']) && $objattr['size'] > 1) { 123 $rows = $objattr['size']; 124 } 125 126 $objattr['fontfamily'] = $this->mpdf->FontFamily; 127 $objattr['fontsize'] = $this->mpdf->FontSizePt; 128 129 $objattr['width'] = $w + ($this->form->form_element_spacing['select']['outer']['h'] * 2) 130 + ($this->form->form_element_spacing['select']['inner']['h'] * 2) + ($this->mpdf->FontSize * 1.4); 131 132 $objattr['height'] = ($this->mpdf->FontSize * $rows) + ($this->form->form_element_spacing['select']['outer']['v'] * 2) 133 + ($this->form->form_element_spacing['select']['inner']['v'] * 2); 134 135 $e = "\xbb\xa4\xactype=select,objattr=" . serialize($objattr) . "\xbb\xa4\xac"; 136 137 // Output it to buffers 138 if ($this->mpdf->tableLevel) { // *TABLES* 139 $this->mpdf->_saveCellTextBuffer($e, $this->mpdf->HREF); 140 $this->mpdf->cell[$this->mpdf->row][$this->mpdf->col]['s'] += $objattr['width']; // *TABLES* 141 } // *TABLES* 142 else { // *TABLES* 143 $this->mpdf->_saveTextBuffer($e, $this->mpdf->HREF); 144 } // *TABLES* 145 146 $this->mpdf->selectoption = []; 147 $this->mpdf->specialcontent = ''; 148 149 if ($this->mpdf->InlineProperties['SELECT']) { 150 $this->mpdf->restoreInlineProperties($this->mpdf->InlineProperties['SELECT']); 151 } 152 unset($this->mpdf->InlineProperties['SELECT']); 153 } 154} 155