@@ -11,524 +11,524 @@ |
||
| 11 | 11 | |
| 12 | 12 | class HTML2PDF_parsingHtml |
| 13 | 13 | { |
| 14 | - protected $_html = ''; // HTML code to parse |
|
| 15 | - protected $_num = 0; // table number |
|
| 16 | - protected $_level = 0; // table level |
|
| 17 | - protected $_encoding = ''; // encoding |
|
| 18 | - public $code = array(); // parsed HTML codfe |
|
| 19 | - |
|
| 20 | - const HTML_TAB = ' '; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * main constructor |
|
| 24 | - * |
|
| 25 | - * @param string encoding |
|
| 26 | - * @access public |
|
| 27 | - */ |
|
| 28 | - public function __construct($encoding = 'UTF-8') |
|
| 29 | - { |
|
| 30 | - $this->_num = 0; |
|
| 31 | - $this->_level = array($this->_num); |
|
| 32 | - $this->_html = ''; |
|
| 33 | - $this->code = array(); |
|
| 34 | - $this->setEncoding($encoding); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * change the encoding |
|
| 39 | - * |
|
| 40 | - * @param string encoding |
|
| 41 | - * @param string $encoding |
|
| 42 | - * @access public |
|
| 43 | - */ |
|
| 44 | - public function setEncoding($encoding) |
|
| 45 | - { |
|
| 46 | - $this->_encoding = $encoding; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Define the HTML code to parse |
|
| 51 | - * |
|
| 52 | - * @param string HTML code |
|
| 53 | - * @access public |
|
| 54 | - */ |
|
| 55 | - public function setHTML($html) |
|
| 56 | - { |
|
| 57 | - // remove the HTML in comment |
|
| 58 | - $html = preg_replace('/<!--(.*)-->/isU', '', $html); |
|
| 59 | - |
|
| 60 | - // save the HTML code |
|
| 61 | - $this->_html = $html; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * parse the HTML code |
|
| 66 | - * |
|
| 67 | - * @access public |
|
| 68 | - */ |
|
| 69 | - public function parse() |
|
| 70 | - { |
|
| 71 | - $parents = array(); |
|
| 72 | - |
|
| 73 | - // flag : are we in a <pre> Tag ? |
|
| 74 | - $tagPreIn = false; |
|
| 75 | - |
|
| 76 | - // action to use for each line of the content of a <pre> Tag |
|
| 77 | - $tagPreBr = array( |
|
| 78 | - 'name' => 'br', |
|
| 79 | - 'close' => false, |
|
| 80 | - 'param' => array( |
|
| 81 | - 'style' => array(), |
|
| 82 | - 'num' => 0 |
|
| 83 | - ) |
|
| 84 | - ); |
|
| 85 | - |
|
| 86 | - // tag that can be not closed |
|
| 87 | - $tagsNotClosed = array( |
|
| 88 | - 'br', 'hr', 'img', 'col', |
|
| 89 | - 'input', 'link', 'option', |
|
| 90 | - 'circle', 'ellipse', 'path', 'rect', 'line', 'polygon', 'polyline' |
|
| 91 | - ); |
|
| 92 | - |
|
| 93 | - // search the HTML tags |
|
| 94 | - $tmp = array(); |
|
| 95 | - $this->_searchCode($tmp); |
|
| 96 | - |
|
| 97 | - // all the actions to do |
|
| 98 | - $actions = array(); |
|
| 99 | - |
|
| 100 | - // foreach part of the HTML code |
|
| 101 | - foreach ($tmp as $part) { |
|
| 102 | - // if it is a tag code |
|
| 103 | - if ($part[0] == 'code') { |
|
| 104 | - // analise the HTML code |
|
| 105 | - $res = $this->_analiseCode($part[1]); |
|
| 14 | + protected $_html = ''; // HTML code to parse |
|
| 15 | + protected $_num = 0; // table number |
|
| 16 | + protected $_level = 0; // table level |
|
| 17 | + protected $_encoding = ''; // encoding |
|
| 18 | + public $code = array(); // parsed HTML codfe |
|
| 19 | + |
|
| 20 | + const HTML_TAB = ' '; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * main constructor |
|
| 24 | + * |
|
| 25 | + * @param string encoding |
|
| 26 | + * @access public |
|
| 27 | + */ |
|
| 28 | + public function __construct($encoding = 'UTF-8') |
|
| 29 | + { |
|
| 30 | + $this->_num = 0; |
|
| 31 | + $this->_level = array($this->_num); |
|
| 32 | + $this->_html = ''; |
|
| 33 | + $this->code = array(); |
|
| 34 | + $this->setEncoding($encoding); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * change the encoding |
|
| 39 | + * |
|
| 40 | + * @param string encoding |
|
| 41 | + * @param string $encoding |
|
| 42 | + * @access public |
|
| 43 | + */ |
|
| 44 | + public function setEncoding($encoding) |
|
| 45 | + { |
|
| 46 | + $this->_encoding = $encoding; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Define the HTML code to parse |
|
| 51 | + * |
|
| 52 | + * @param string HTML code |
|
| 53 | + * @access public |
|
| 54 | + */ |
|
| 55 | + public function setHTML($html) |
|
| 56 | + { |
|
| 57 | + // remove the HTML in comment |
|
| 58 | + $html = preg_replace('/<!--(.*)-->/isU', '', $html); |
|
| 59 | + |
|
| 60 | + // save the HTML code |
|
| 61 | + $this->_html = $html; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * parse the HTML code |
|
| 66 | + * |
|
| 67 | + * @access public |
|
| 68 | + */ |
|
| 69 | + public function parse() |
|
| 70 | + { |
|
| 71 | + $parents = array(); |
|
| 72 | + |
|
| 73 | + // flag : are we in a <pre> Tag ? |
|
| 74 | + $tagPreIn = false; |
|
| 75 | + |
|
| 76 | + // action to use for each line of the content of a <pre> Tag |
|
| 77 | + $tagPreBr = array( |
|
| 78 | + 'name' => 'br', |
|
| 79 | + 'close' => false, |
|
| 80 | + 'param' => array( |
|
| 81 | + 'style' => array(), |
|
| 82 | + 'num' => 0 |
|
| 83 | + ) |
|
| 84 | + ); |
|
| 85 | + |
|
| 86 | + // tag that can be not closed |
|
| 87 | + $tagsNotClosed = array( |
|
| 88 | + 'br', 'hr', 'img', 'col', |
|
| 89 | + 'input', 'link', 'option', |
|
| 90 | + 'circle', 'ellipse', 'path', 'rect', 'line', 'polygon', 'polyline' |
|
| 91 | + ); |
|
| 92 | + |
|
| 93 | + // search the HTML tags |
|
| 94 | + $tmp = array(); |
|
| 95 | + $this->_searchCode($tmp); |
|
| 96 | + |
|
| 97 | + // all the actions to do |
|
| 98 | + $actions = array(); |
|
| 99 | + |
|
| 100 | + // foreach part of the HTML code |
|
| 101 | + foreach ($tmp as $part) { |
|
| 102 | + // if it is a tag code |
|
| 103 | + if ($part[0] == 'code') { |
|
| 104 | + // analise the HTML code |
|
| 105 | + $res = $this->_analiseCode($part[1]); |
|
| 106 | 106 | |
| 107 | 107 | //echo "<pre>"; print_r($tagsNotClosed); exit; |
| 108 | - // if it is a real HTML tag |
|
| 109 | - if ($res) { |
|
| 110 | - // save the current posistion in the HTML code |
|
| 111 | - $res['html_pos'] = $part[2]; |
|
| 112 | - |
|
| 113 | - // if the tag must be closed |
|
| 114 | - if ( ! in_array($res['name'], $tagsNotClosed)) { |
|
| 115 | - // if it is a closure tag |
|
| 116 | - if ($res['close']) { |
|
| 117 | - // HTML validation |
|
| 118 | - if (count($parents) < 1) |
|
| 119 | - throw new HTML2PDF_exception(3, $res['name'], $this->getHtmlErrorCode($res['html_pos'])); |
|
| 120 | - else if ($parents[count($parents) - 1] != $res['name']) |
|
| 121 | - throw new HTML2PDF_exception(4, $parents, $this->getHtmlErrorCode($res['html_pos'])); |
|
| 122 | - else |
|
| 123 | - unset($parents[count($parents) - 1]); |
|
| 124 | - } else { |
|
| 125 | - // if it is a autoclosed tag |
|
| 126 | - if ($res['autoclose']) { |
|
| 127 | - // save the opened tag |
|
| 128 | - $actions[] = $res; |
|
| 129 | - |
|
| 130 | - // prepare the closed tag |
|
| 131 | - $res['params'] = array(); |
|
| 132 | - $res['close'] = true; |
|
| 133 | - } |
|
| 134 | - // else :add a child for validation |
|
| 135 | - else { |
|
| 136 | - $parents[count($parents)] = $res['name']; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // if it is a <pre> tag (or <code> tag) not auclosed => update the flag |
|
| 141 | - if (($res['name'] == 'pre' || $res['name'] == 'code') && ! $res['autoclose']) { |
|
| 142 | - $tagPreIn = ! $res['close']; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - // save the actions to convert |
|
| 147 | - $actions[] = $res; |
|
| 148 | - } else { // else (it is not a real HTML tag => we transform it in Texte |
|
| 149 | - $part[0] = 'txt'; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - // if it is text |
|
| 153 | - if ($part[0] == 'txt') { |
|
| 154 | - // if we are not in a <pre> tag |
|
| 155 | - if ( ! $tagPreIn) { |
|
| 156 | - // save the action |
|
| 157 | - $actions[] = array( |
|
| 158 | - 'name' => 'write', |
|
| 159 | - 'close' => false, |
|
| 160 | - 'param' => array('txt' => $this->_prepareTxt($part[1])), |
|
| 161 | - ); |
|
| 162 | - } else { // else (if we are in a <pre> tag) |
|
| 163 | - // prepare the text |
|
| 164 | - $part[1] = str_replace("\r", '', $part[1]); |
|
| 165 | - $part[1] = explode("\n", $part[1]); |
|
| 166 | - |
|
| 167 | - // foreach line of the text |
|
| 168 | - foreach ($part[1] as $k => $txt) { |
|
| 169 | - // transform the line |
|
| 170 | - $txt = str_replace("\t", self::HTML_TAB, $txt); |
|
| 171 | - $txt = str_replace(' ', ' ', $txt); |
|
| 172 | - |
|
| 173 | - // add a break line |
|
| 174 | - if ($k > 0) $actions[] = $tagPreBr; |
|
| 175 | - |
|
| 176 | - // save the action |
|
| 177 | - $actions[] = array( |
|
| 178 | - 'name' => 'write', |
|
| 179 | - 'close' => false, |
|
| 180 | - 'param' => array('txt' => $this->_prepareTxt($txt, false)), |
|
| 181 | - ); |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - // for each indentified action, we have to clean up the begin and the end of the texte |
|
| 188 | - // based on tags that surround it |
|
| 189 | - |
|
| 190 | - // list of the tags to clean |
|
| 191 | - $tagsToClean = array( |
|
| 192 | - 'page', 'page_header', 'page_footer', 'form', |
|
| 193 | - 'table', 'thead', 'tfoot', 'tr', 'td', 'th', 'br', |
|
| 194 | - 'div', 'hr', 'p', 'ul', 'ol', 'li', |
|
| 195 | - 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', |
|
| 196 | - 'bookmark', 'fieldset', 'legend', |
|
| 197 | - 'draw', 'circle', 'ellipse', 'path', 'rect', 'line', 'g', 'polygon', 'polyline', |
|
| 198 | - 'option' |
|
| 199 | - ); |
|
| 200 | - |
|
| 201 | - // foreach action |
|
| 202 | - $nb = count($actions); |
|
| 203 | - for ($k = 0; $k < $nb; $k++) { |
|
| 204 | - // if it is a Text |
|
| 205 | - if ($actions[$k]['name'] == 'write') { |
|
| 206 | - // if the tag before the text is a tag to clean => ltrim on the text |
|
| 207 | - if ($k > 0 && in_array($actions[$k - 1]['name'], $tagsToClean)) |
|
| 208 | - $actions[$k]['param']['txt'] = ltrim($actions[$k]['param']['txt']); |
|
| 209 | - |
|
| 210 | - // if the tag after the text is a tag to clean => rtrim on the text |
|
| 211 | - if ($k < $nb - 1 && in_array($actions[$k + 1]['name'], $tagsToClean)) |
|
| 212 | - $actions[$k]['param']['txt'] = rtrim($actions[$k]['param']['txt']); |
|
| 213 | - |
|
| 214 | - // if the text is empty => remove the action |
|
| 215 | - if ( ! strlen($actions[$k]['param']['txt'])) |
|
| 216 | - unset($actions[$k]); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - // if we are not on the level 0 => HTML validator ERROR |
|
| 221 | - if (count($parents)) throw new HTML2PDF_exception(5, $parents); |
|
| 222 | - |
|
| 223 | - // save the actions to do |
|
| 224 | - $this->code = array_values($actions); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * prepare the text |
|
| 229 | - * |
|
| 230 | - * @param string texte |
|
| 231 | - * @param boolean true => replace multiple space+\t+\r+\n by a single space |
|
| 232 | - * @return string texte |
|
| 233 | - * @access protected |
|
| 234 | - */ |
|
| 235 | - protected function _prepareTxt($txt, $spaces = true) |
|
| 236 | - { |
|
| 237 | - if ($spaces) { |
|
| 238 | - $txt = preg_replace('/\s+/is', ' ', $txt); |
|
| 239 | - } |
|
| 240 | - $txt = str_replace('€', '€', $txt); |
|
| 241 | - $txt = html_entity_decode($txt, ENT_QUOTES, $this->_encoding); |
|
| 242 | - return $txt; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * parse the HTML code |
|
| 247 | - * |
|
| 248 | - * @param &array array's result |
|
| 249 | - * @return null |
|
| 250 | - */ |
|
| 251 | - protected function _searchCode(&$tmp) |
|
| 252 | - { |
|
| 253 | - // initialise the array |
|
| 254 | - $tmp = array(); |
|
| 255 | - |
|
| 256 | - // regexp to separate the tags from the texts |
|
| 257 | - $reg = '/(<[^>]+>)|([^<]+)+/isU'; |
|
| 258 | - |
|
| 259 | - // last match found |
|
| 260 | - $str = ''; |
|
| 261 | - $offset = 0; |
|
| 262 | - |
|
| 263 | - // As it finds a match |
|
| 264 | - while (preg_match($reg, $this->_html, $parse, PREG_OFFSET_CAPTURE, $offset)) { |
|
| 265 | - // if it is a tag |
|
| 266 | - if ($parse[1][0]) { |
|
| 267 | - // save the previous text if it exists |
|
| 268 | - if ($str !== '') $tmp[] = array('txt', $str); |
|
| 269 | - |
|
| 270 | - // save the tag, with the offset |
|
| 271 | - $tmp[] = array('code', trim($parse[1][0]), $offset); |
|
| 272 | - |
|
| 273 | - // init the current text |
|
| 274 | - $str = ''; |
|
| 275 | - } else { // else (if it is a text) |
|
| 276 | - // add the new text to the current text |
|
| 277 | - $str .= $parse[2][0]; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - // Update offset to the end of the match |
|
| 281 | - $offset = $parse[0][1] + strlen($parse[0][0]); |
|
| 282 | - unset($parse); |
|
| 283 | - } |
|
| 284 | - // if a text is present in the end, we save it |
|
| 285 | - if ($str != '') $tmp[] = array('txt', $str); |
|
| 286 | - unset($str); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * analise a HTML tag |
|
| 291 | - * |
|
| 292 | - * @param string HTML code to analise |
|
| 293 | - * @return array corresponding action |
|
| 294 | - */ |
|
| 295 | - protected function _analiseCode($code) |
|
| 296 | - { |
|
| 297 | - // name of the tag, opening, closure, autoclosure |
|
| 298 | - $tag = '<([\/]{0,1})([_a-z0-9]+)([\/>\s]+)'; |
|
| 299 | - if ( ! preg_match('/'.$tag.'/isU', $code, $match)) return null; |
|
| 300 | - $close = ($match[1] == '/' ? true : false); |
|
| 301 | - $autoclose = preg_match('/\/>$/isU', $code); |
|
| 302 | - $name = strtolower($match[2]); |
|
| 303 | - |
|
| 304 | - // required parameters (depends on the tag name) |
|
| 305 | - $param = array(); |
|
| 306 | - $param['style'] = ''; |
|
| 307 | - if ($name == 'img') { |
|
| 308 | - $param['alt'] = ''; |
|
| 309 | - $param['src'] = ''; |
|
| 310 | - } |
|
| 311 | - if ($name == 'a') { |
|
| 312 | - $param['href'] = ''; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - // read the parameters : nom=valeur |
|
| 316 | - $prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)'; |
|
| 317 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 318 | - for ($k = 0; $k < count($match[0]); $k++) |
|
| 319 | - $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 320 | - |
|
| 321 | - // read the parameters : nom="valeur" |
|
| 322 | - $prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]'; |
|
| 323 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 324 | - for ($k = 0; $k < count($match[0]); $k++) |
|
| 325 | - $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 326 | - |
|
| 327 | - // read the parameters : nom='valeur' |
|
| 328 | - $prop = "([a-zA-Z0-9_]+)=[']([^']*)[']"; |
|
| 329 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 330 | - for ($k = 0; $k < count($match[0]); $k++) |
|
| 331 | - $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 332 | - |
|
| 333 | - // compliance of each parameter |
|
| 334 | - $color = "#000000"; |
|
| 335 | - $border = null; |
|
| 336 | - foreach ($param as $key => $val) { |
|
| 337 | - $key = strtolower($key); |
|
| 338 | - switch ($key) |
|
| 339 | - { |
|
| 340 | - case 'width': |
|
| 341 | - unset($param[$key]); |
|
| 342 | - $param['style'] .= 'width: '.$val.'px; '; |
|
| 343 | - break; |
|
| 344 | - |
|
| 345 | - case 'align': |
|
| 346 | - if ($name === 'img') { |
|
| 347 | - unset($param[$key]); |
|
| 348 | - $param['style'] .= 'float: '.$val.'; '; |
|
| 349 | - } elseif ($name !== 'table') { |
|
| 350 | - unset($param[$key]); |
|
| 351 | - $param['style'] .= 'text-align: '.$val.'; '; |
|
| 352 | - } |
|
| 353 | - break; |
|
| 354 | - |
|
| 355 | - case 'valign': |
|
| 356 | - unset($param[$key]); |
|
| 357 | - $param['style'] .= 'vertical-align: '.$val.'; '; |
|
| 358 | - break; |
|
| 359 | - |
|
| 360 | - case 'height': |
|
| 361 | - unset($param[$key]); |
|
| 362 | - $param['style'] .= 'height: '.$val.'px; '; |
|
| 363 | - break; |
|
| 364 | - |
|
| 365 | - case 'bgcolor': |
|
| 366 | - unset($param[$key]); |
|
| 367 | - $param['style'] .= 'background: '.$val.'; '; |
|
| 368 | - break; |
|
| 369 | - |
|
| 370 | - case 'bordercolor': |
|
| 371 | - unset($param[$key]); |
|
| 372 | - $color = $val; |
|
| 373 | - break; |
|
| 374 | - |
|
| 375 | - case 'border': |
|
| 376 | - unset($param[$key]); |
|
| 377 | - if (preg_match('/^[0-9]+$/isU', $val)) $val = $val.'px'; |
|
| 378 | - $border = $val; |
|
| 379 | - break; |
|
| 380 | - |
|
| 381 | - case 'cellpadding': |
|
| 382 | - case 'cellspacing': |
|
| 383 | - if (preg_match('/^([0-9]+)$/isU', $val)) $param[$key] = $val.'px'; |
|
| 384 | - break; |
|
| 385 | - |
|
| 386 | - case 'colspan': |
|
| 387 | - case 'rowspan': |
|
| 388 | - $val = preg_replace('/[^0-9]/isU', '', $val); |
|
| 389 | - if ( ! $val) $val = 1; |
|
| 390 | - $param[$key] = $val; |
|
| 391 | - break; |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - // compliance of the border |
|
| 396 | - if ($border !== null) { |
|
| 397 | - if ($border) $border = 'border: solid '.$border.' '.$color; |
|
| 398 | - else $border = 'border: none'; |
|
| 399 | - |
|
| 400 | - $param['style'] .= $border.'; '; |
|
| 401 | - $param['border'] = $border; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - // reading styles: decomposition and standardization |
|
| 405 | - $styles = explode(';', $param['style']); |
|
| 406 | - $param['style'] = array(); |
|
| 407 | - foreach ($styles as $style) { |
|
| 408 | - $tmp = explode(':', $style); |
|
| 409 | - if (count($tmp) > 1) { |
|
| 410 | - $cod = $tmp[0]; |
|
| 411 | - unset($tmp[0]); |
|
| 412 | - $tmp = implode(':', $tmp); |
|
| 413 | - $param['style'][trim(strtolower($cod))] = preg_replace('/[\s]+/isU', ' ', trim($tmp)); |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - // determining the level of table opening, with an added level |
|
| 418 | - if (in_array($name, array('ul', 'ol', 'table')) && ! $close) { |
|
| 419 | - $this->_num++; |
|
| 420 | - $this->_level[count($this->_level)] = $this->_num; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - // get the level of the table containing the element |
|
| 424 | - if ( ! isset($param['num'])) { |
|
| 425 | - $param['num'] = $this->_level[count($this->_level) - 1]; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - // for closures table: remove a level |
|
| 429 | - if (in_array($name, array('ul', 'ol', 'table')) && $close) { |
|
| 430 | - unset($this->_level[count($this->_level) - 1]); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - // prepare the parameters |
|
| 434 | - if (isset($param['value'])) { |
|
| 435 | - $param['value'] = $this->_prepareTxt($param['value']); |
|
| 436 | - } |
|
| 437 | - if (isset($param['alt'])) { |
|
| 438 | - $param['alt'] = $this->_prepareTxt($param['alt']); |
|
| 439 | - } |
|
| 440 | - if (isset($param['title'])) { |
|
| 441 | - $param['title'] = $this->_prepareTxt($param['title']); |
|
| 442 | - } |
|
| 443 | - if (isset($param['class'])) { |
|
| 444 | - $param['class'] = $this->_prepareTxt($param['class']); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - // return the new action to do |
|
| 448 | - return array('name' => $name, 'close' => $close ? 1 : 0, 'autoclose' => $autoclose, 'param' => $param); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * get a full level of HTML, between an opening and closing corresponding |
|
| 453 | - * |
|
| 454 | - * @param integer key |
|
| 455 | - * @param integer $k |
|
| 456 | - * @return array actions |
|
| 457 | - */ |
|
| 458 | - public function getLevel($k) |
|
| 459 | - { |
|
| 460 | - // if the code does not exist => return empty |
|
| 461 | - if ( ! isset($this->code[$k])) return array(); |
|
| 462 | - |
|
| 463 | - // the tag to detect |
|
| 464 | - $detect = $this->code[$k]['name']; |
|
| 465 | - |
|
| 466 | - // if it is a text => return |
|
| 467 | - if ($detect == 'write') { |
|
| 468 | - return array($this->code[$k]); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - // |
|
| 472 | - $level = 0; // depth level |
|
| 473 | - $end = false; // end of the search |
|
| 474 | - $code = array(); // extract code |
|
| 475 | - |
|
| 476 | - // while it's not ended |
|
| 477 | - while ( ! $end) { |
|
| 478 | - // current action |
|
| 479 | - $row = $this->code[$k]; |
|
| 480 | - |
|
| 481 | - // if 'write' => we add the text |
|
| 482 | - if ($row['name'] == 'write') { |
|
| 483 | - $code[] = $row; |
|
| 484 | - } else { // else, it is a html tag |
|
| 485 | - $not = false; // flag for not taking into account the current tag |
|
| 486 | - |
|
| 487 | - // if it is the searched tag |
|
| 488 | - if ($row['name'] == $detect) { |
|
| 489 | - // if we are just at the root level => dont take it |
|
| 490 | - if ($level == 0) { |
|
| 491 | - $not = true; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - // update the level |
|
| 495 | - $level += ($row['close'] ? -1 : 1); |
|
| 496 | - |
|
| 497 | - // if we are now at the root level => it is the end, and dont take it |
|
| 498 | - if ($level == 0) { |
|
| 499 | - $not = true; |
|
| 500 | - $end = true; |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - // if we can takin into account the current tag => save it |
|
| 505 | - if ( ! $not) { |
|
| 506 | - if (isset($row['style']['text-align'])) unset($row['style']['text-align']); |
|
| 507 | - $code[] = $row; |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - // it continues as long as there has code to analise |
|
| 512 | - if (isset($this->code[$k + 1])) |
|
| 513 | - $k++; |
|
| 514 | - else |
|
| 515 | - $end = true; |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - // return the extract |
|
| 519 | - return $code; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * return a part of the HTML code, for error message |
|
| 524 | - * |
|
| 525 | - * @param integer position |
|
| 526 | - * @param integer take before |
|
| 527 | - * @param integer take after |
|
| 528 | - * @return string part of the html code |
|
| 529 | - */ |
|
| 530 | - public function getHtmlErrorCode($pos, $before = 30, $after = 40) |
|
| 531 | - { |
|
| 532 | - return substr($this->_html, $pos - $before, $before + $after); |
|
| 533 | - } |
|
| 108 | + // if it is a real HTML tag |
|
| 109 | + if ($res) { |
|
| 110 | + // save the current posistion in the HTML code |
|
| 111 | + $res['html_pos'] = $part[2]; |
|
| 112 | + |
|
| 113 | + // if the tag must be closed |
|
| 114 | + if ( ! in_array($res['name'], $tagsNotClosed)) { |
|
| 115 | + // if it is a closure tag |
|
| 116 | + if ($res['close']) { |
|
| 117 | + // HTML validation |
|
| 118 | + if (count($parents) < 1) |
|
| 119 | + throw new HTML2PDF_exception(3, $res['name'], $this->getHtmlErrorCode($res['html_pos'])); |
|
| 120 | + else if ($parents[count($parents) - 1] != $res['name']) |
|
| 121 | + throw new HTML2PDF_exception(4, $parents, $this->getHtmlErrorCode($res['html_pos'])); |
|
| 122 | + else |
|
| 123 | + unset($parents[count($parents) - 1]); |
|
| 124 | + } else { |
|
| 125 | + // if it is a autoclosed tag |
|
| 126 | + if ($res['autoclose']) { |
|
| 127 | + // save the opened tag |
|
| 128 | + $actions[] = $res; |
|
| 129 | + |
|
| 130 | + // prepare the closed tag |
|
| 131 | + $res['params'] = array(); |
|
| 132 | + $res['close'] = true; |
|
| 133 | + } |
|
| 134 | + // else :add a child for validation |
|
| 135 | + else { |
|
| 136 | + $parents[count($parents)] = $res['name']; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // if it is a <pre> tag (or <code> tag) not auclosed => update the flag |
|
| 141 | + if (($res['name'] == 'pre' || $res['name'] == 'code') && ! $res['autoclose']) { |
|
| 142 | + $tagPreIn = ! $res['close']; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + // save the actions to convert |
|
| 147 | + $actions[] = $res; |
|
| 148 | + } else { // else (it is not a real HTML tag => we transform it in Texte |
|
| 149 | + $part[0] = 'txt'; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + // if it is text |
|
| 153 | + if ($part[0] == 'txt') { |
|
| 154 | + // if we are not in a <pre> tag |
|
| 155 | + if ( ! $tagPreIn) { |
|
| 156 | + // save the action |
|
| 157 | + $actions[] = array( |
|
| 158 | + 'name' => 'write', |
|
| 159 | + 'close' => false, |
|
| 160 | + 'param' => array('txt' => $this->_prepareTxt($part[1])), |
|
| 161 | + ); |
|
| 162 | + } else { // else (if we are in a <pre> tag) |
|
| 163 | + // prepare the text |
|
| 164 | + $part[1] = str_replace("\r", '', $part[1]); |
|
| 165 | + $part[1] = explode("\n", $part[1]); |
|
| 166 | + |
|
| 167 | + // foreach line of the text |
|
| 168 | + foreach ($part[1] as $k => $txt) { |
|
| 169 | + // transform the line |
|
| 170 | + $txt = str_replace("\t", self::HTML_TAB, $txt); |
|
| 171 | + $txt = str_replace(' ', ' ', $txt); |
|
| 172 | + |
|
| 173 | + // add a break line |
|
| 174 | + if ($k > 0) $actions[] = $tagPreBr; |
|
| 175 | + |
|
| 176 | + // save the action |
|
| 177 | + $actions[] = array( |
|
| 178 | + 'name' => 'write', |
|
| 179 | + 'close' => false, |
|
| 180 | + 'param' => array('txt' => $this->_prepareTxt($txt, false)), |
|
| 181 | + ); |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + // for each indentified action, we have to clean up the begin and the end of the texte |
|
| 188 | + // based on tags that surround it |
|
| 189 | + |
|
| 190 | + // list of the tags to clean |
|
| 191 | + $tagsToClean = array( |
|
| 192 | + 'page', 'page_header', 'page_footer', 'form', |
|
| 193 | + 'table', 'thead', 'tfoot', 'tr', 'td', 'th', 'br', |
|
| 194 | + 'div', 'hr', 'p', 'ul', 'ol', 'li', |
|
| 195 | + 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', |
|
| 196 | + 'bookmark', 'fieldset', 'legend', |
|
| 197 | + 'draw', 'circle', 'ellipse', 'path', 'rect', 'line', 'g', 'polygon', 'polyline', |
|
| 198 | + 'option' |
|
| 199 | + ); |
|
| 200 | + |
|
| 201 | + // foreach action |
|
| 202 | + $nb = count($actions); |
|
| 203 | + for ($k = 0; $k < $nb; $k++) { |
|
| 204 | + // if it is a Text |
|
| 205 | + if ($actions[$k]['name'] == 'write') { |
|
| 206 | + // if the tag before the text is a tag to clean => ltrim on the text |
|
| 207 | + if ($k > 0 && in_array($actions[$k - 1]['name'], $tagsToClean)) |
|
| 208 | + $actions[$k]['param']['txt'] = ltrim($actions[$k]['param']['txt']); |
|
| 209 | + |
|
| 210 | + // if the tag after the text is a tag to clean => rtrim on the text |
|
| 211 | + if ($k < $nb - 1 && in_array($actions[$k + 1]['name'], $tagsToClean)) |
|
| 212 | + $actions[$k]['param']['txt'] = rtrim($actions[$k]['param']['txt']); |
|
| 213 | + |
|
| 214 | + // if the text is empty => remove the action |
|
| 215 | + if ( ! strlen($actions[$k]['param']['txt'])) |
|
| 216 | + unset($actions[$k]); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + // if we are not on the level 0 => HTML validator ERROR |
|
| 221 | + if (count($parents)) throw new HTML2PDF_exception(5, $parents); |
|
| 222 | + |
|
| 223 | + // save the actions to do |
|
| 224 | + $this->code = array_values($actions); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * prepare the text |
|
| 229 | + * |
|
| 230 | + * @param string texte |
|
| 231 | + * @param boolean true => replace multiple space+\t+\r+\n by a single space |
|
| 232 | + * @return string texte |
|
| 233 | + * @access protected |
|
| 234 | + */ |
|
| 235 | + protected function _prepareTxt($txt, $spaces = true) |
|
| 236 | + { |
|
| 237 | + if ($spaces) { |
|
| 238 | + $txt = preg_replace('/\s+/is', ' ', $txt); |
|
| 239 | + } |
|
| 240 | + $txt = str_replace('€', '€', $txt); |
|
| 241 | + $txt = html_entity_decode($txt, ENT_QUOTES, $this->_encoding); |
|
| 242 | + return $txt; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * parse the HTML code |
|
| 247 | + * |
|
| 248 | + * @param &array array's result |
|
| 249 | + * @return null |
|
| 250 | + */ |
|
| 251 | + protected function _searchCode(&$tmp) |
|
| 252 | + { |
|
| 253 | + // initialise the array |
|
| 254 | + $tmp = array(); |
|
| 255 | + |
|
| 256 | + // regexp to separate the tags from the texts |
|
| 257 | + $reg = '/(<[^>]+>)|([^<]+)+/isU'; |
|
| 258 | + |
|
| 259 | + // last match found |
|
| 260 | + $str = ''; |
|
| 261 | + $offset = 0; |
|
| 262 | + |
|
| 263 | + // As it finds a match |
|
| 264 | + while (preg_match($reg, $this->_html, $parse, PREG_OFFSET_CAPTURE, $offset)) { |
|
| 265 | + // if it is a tag |
|
| 266 | + if ($parse[1][0]) { |
|
| 267 | + // save the previous text if it exists |
|
| 268 | + if ($str !== '') $tmp[] = array('txt', $str); |
|
| 269 | + |
|
| 270 | + // save the tag, with the offset |
|
| 271 | + $tmp[] = array('code', trim($parse[1][0]), $offset); |
|
| 272 | + |
|
| 273 | + // init the current text |
|
| 274 | + $str = ''; |
|
| 275 | + } else { // else (if it is a text) |
|
| 276 | + // add the new text to the current text |
|
| 277 | + $str .= $parse[2][0]; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + // Update offset to the end of the match |
|
| 281 | + $offset = $parse[0][1] + strlen($parse[0][0]); |
|
| 282 | + unset($parse); |
|
| 283 | + } |
|
| 284 | + // if a text is present in the end, we save it |
|
| 285 | + if ($str != '') $tmp[] = array('txt', $str); |
|
| 286 | + unset($str); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * analise a HTML tag |
|
| 291 | + * |
|
| 292 | + * @param string HTML code to analise |
|
| 293 | + * @return array corresponding action |
|
| 294 | + */ |
|
| 295 | + protected function _analiseCode($code) |
|
| 296 | + { |
|
| 297 | + // name of the tag, opening, closure, autoclosure |
|
| 298 | + $tag = '<([\/]{0,1})([_a-z0-9]+)([\/>\s]+)'; |
|
| 299 | + if ( ! preg_match('/'.$tag.'/isU', $code, $match)) return null; |
|
| 300 | + $close = ($match[1] == '/' ? true : false); |
|
| 301 | + $autoclose = preg_match('/\/>$/isU', $code); |
|
| 302 | + $name = strtolower($match[2]); |
|
| 303 | + |
|
| 304 | + // required parameters (depends on the tag name) |
|
| 305 | + $param = array(); |
|
| 306 | + $param['style'] = ''; |
|
| 307 | + if ($name == 'img') { |
|
| 308 | + $param['alt'] = ''; |
|
| 309 | + $param['src'] = ''; |
|
| 310 | + } |
|
| 311 | + if ($name == 'a') { |
|
| 312 | + $param['href'] = ''; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + // read the parameters : nom=valeur |
|
| 316 | + $prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)'; |
|
| 317 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 318 | + for ($k = 0; $k < count($match[0]); $k++) |
|
| 319 | + $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 320 | + |
|
| 321 | + // read the parameters : nom="valeur" |
|
| 322 | + $prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]'; |
|
| 323 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 324 | + for ($k = 0; $k < count($match[0]); $k++) |
|
| 325 | + $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 326 | + |
|
| 327 | + // read the parameters : nom='valeur' |
|
| 328 | + $prop = "([a-zA-Z0-9_]+)=[']([^']*)[']"; |
|
| 329 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 330 | + for ($k = 0; $k < count($match[0]); $k++) |
|
| 331 | + $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 332 | + |
|
| 333 | + // compliance of each parameter |
|
| 334 | + $color = "#000000"; |
|
| 335 | + $border = null; |
|
| 336 | + foreach ($param as $key => $val) { |
|
| 337 | + $key = strtolower($key); |
|
| 338 | + switch ($key) |
|
| 339 | + { |
|
| 340 | + case 'width': |
|
| 341 | + unset($param[$key]); |
|
| 342 | + $param['style'] .= 'width: '.$val.'px; '; |
|
| 343 | + break; |
|
| 344 | + |
|
| 345 | + case 'align': |
|
| 346 | + if ($name === 'img') { |
|
| 347 | + unset($param[$key]); |
|
| 348 | + $param['style'] .= 'float: '.$val.'; '; |
|
| 349 | + } elseif ($name !== 'table') { |
|
| 350 | + unset($param[$key]); |
|
| 351 | + $param['style'] .= 'text-align: '.$val.'; '; |
|
| 352 | + } |
|
| 353 | + break; |
|
| 354 | + |
|
| 355 | + case 'valign': |
|
| 356 | + unset($param[$key]); |
|
| 357 | + $param['style'] .= 'vertical-align: '.$val.'; '; |
|
| 358 | + break; |
|
| 359 | + |
|
| 360 | + case 'height': |
|
| 361 | + unset($param[$key]); |
|
| 362 | + $param['style'] .= 'height: '.$val.'px; '; |
|
| 363 | + break; |
|
| 364 | + |
|
| 365 | + case 'bgcolor': |
|
| 366 | + unset($param[$key]); |
|
| 367 | + $param['style'] .= 'background: '.$val.'; '; |
|
| 368 | + break; |
|
| 369 | + |
|
| 370 | + case 'bordercolor': |
|
| 371 | + unset($param[$key]); |
|
| 372 | + $color = $val; |
|
| 373 | + break; |
|
| 374 | + |
|
| 375 | + case 'border': |
|
| 376 | + unset($param[$key]); |
|
| 377 | + if (preg_match('/^[0-9]+$/isU', $val)) $val = $val.'px'; |
|
| 378 | + $border = $val; |
|
| 379 | + break; |
|
| 380 | + |
|
| 381 | + case 'cellpadding': |
|
| 382 | + case 'cellspacing': |
|
| 383 | + if (preg_match('/^([0-9]+)$/isU', $val)) $param[$key] = $val.'px'; |
|
| 384 | + break; |
|
| 385 | + |
|
| 386 | + case 'colspan': |
|
| 387 | + case 'rowspan': |
|
| 388 | + $val = preg_replace('/[^0-9]/isU', '', $val); |
|
| 389 | + if ( ! $val) $val = 1; |
|
| 390 | + $param[$key] = $val; |
|
| 391 | + break; |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + // compliance of the border |
|
| 396 | + if ($border !== null) { |
|
| 397 | + if ($border) $border = 'border: solid '.$border.' '.$color; |
|
| 398 | + else $border = 'border: none'; |
|
| 399 | + |
|
| 400 | + $param['style'] .= $border.'; '; |
|
| 401 | + $param['border'] = $border; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + // reading styles: decomposition and standardization |
|
| 405 | + $styles = explode(';', $param['style']); |
|
| 406 | + $param['style'] = array(); |
|
| 407 | + foreach ($styles as $style) { |
|
| 408 | + $tmp = explode(':', $style); |
|
| 409 | + if (count($tmp) > 1) { |
|
| 410 | + $cod = $tmp[0]; |
|
| 411 | + unset($tmp[0]); |
|
| 412 | + $tmp = implode(':', $tmp); |
|
| 413 | + $param['style'][trim(strtolower($cod))] = preg_replace('/[\s]+/isU', ' ', trim($tmp)); |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + // determining the level of table opening, with an added level |
|
| 418 | + if (in_array($name, array('ul', 'ol', 'table')) && ! $close) { |
|
| 419 | + $this->_num++; |
|
| 420 | + $this->_level[count($this->_level)] = $this->_num; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + // get the level of the table containing the element |
|
| 424 | + if ( ! isset($param['num'])) { |
|
| 425 | + $param['num'] = $this->_level[count($this->_level) - 1]; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + // for closures table: remove a level |
|
| 429 | + if (in_array($name, array('ul', 'ol', 'table')) && $close) { |
|
| 430 | + unset($this->_level[count($this->_level) - 1]); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + // prepare the parameters |
|
| 434 | + if (isset($param['value'])) { |
|
| 435 | + $param['value'] = $this->_prepareTxt($param['value']); |
|
| 436 | + } |
|
| 437 | + if (isset($param['alt'])) { |
|
| 438 | + $param['alt'] = $this->_prepareTxt($param['alt']); |
|
| 439 | + } |
|
| 440 | + if (isset($param['title'])) { |
|
| 441 | + $param['title'] = $this->_prepareTxt($param['title']); |
|
| 442 | + } |
|
| 443 | + if (isset($param['class'])) { |
|
| 444 | + $param['class'] = $this->_prepareTxt($param['class']); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + // return the new action to do |
|
| 448 | + return array('name' => $name, 'close' => $close ? 1 : 0, 'autoclose' => $autoclose, 'param' => $param); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * get a full level of HTML, between an opening and closing corresponding |
|
| 453 | + * |
|
| 454 | + * @param integer key |
|
| 455 | + * @param integer $k |
|
| 456 | + * @return array actions |
|
| 457 | + */ |
|
| 458 | + public function getLevel($k) |
|
| 459 | + { |
|
| 460 | + // if the code does not exist => return empty |
|
| 461 | + if ( ! isset($this->code[$k])) return array(); |
|
| 462 | + |
|
| 463 | + // the tag to detect |
|
| 464 | + $detect = $this->code[$k]['name']; |
|
| 465 | + |
|
| 466 | + // if it is a text => return |
|
| 467 | + if ($detect == 'write') { |
|
| 468 | + return array($this->code[$k]); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + // |
|
| 472 | + $level = 0; // depth level |
|
| 473 | + $end = false; // end of the search |
|
| 474 | + $code = array(); // extract code |
|
| 475 | + |
|
| 476 | + // while it's not ended |
|
| 477 | + while ( ! $end) { |
|
| 478 | + // current action |
|
| 479 | + $row = $this->code[$k]; |
|
| 480 | + |
|
| 481 | + // if 'write' => we add the text |
|
| 482 | + if ($row['name'] == 'write') { |
|
| 483 | + $code[] = $row; |
|
| 484 | + } else { // else, it is a html tag |
|
| 485 | + $not = false; // flag for not taking into account the current tag |
|
| 486 | + |
|
| 487 | + // if it is the searched tag |
|
| 488 | + if ($row['name'] == $detect) { |
|
| 489 | + // if we are just at the root level => dont take it |
|
| 490 | + if ($level == 0) { |
|
| 491 | + $not = true; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + // update the level |
|
| 495 | + $level += ($row['close'] ? -1 : 1); |
|
| 496 | + |
|
| 497 | + // if we are now at the root level => it is the end, and dont take it |
|
| 498 | + if ($level == 0) { |
|
| 499 | + $not = true; |
|
| 500 | + $end = true; |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + // if we can takin into account the current tag => save it |
|
| 505 | + if ( ! $not) { |
|
| 506 | + if (isset($row['style']['text-align'])) unset($row['style']['text-align']); |
|
| 507 | + $code[] = $row; |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + // it continues as long as there has code to analise |
|
| 512 | + if (isset($this->code[$k + 1])) |
|
| 513 | + $k++; |
|
| 514 | + else |
|
| 515 | + $end = true; |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + // return the extract |
|
| 519 | + return $code; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * return a part of the HTML code, for error message |
|
| 524 | + * |
|
| 525 | + * @param integer position |
|
| 526 | + * @param integer take before |
|
| 527 | + * @param integer take after |
|
| 528 | + * @return string part of the html code |
|
| 529 | + */ |
|
| 530 | + public function getHtmlErrorCode($pos, $before = 30, $after = 40) |
|
| 531 | + { |
|
| 532 | + return substr($this->_html, $pos - $before, $before + $after); |
|
| 533 | + } |
|
| 534 | 534 | } |
@@ -11,1849 +11,1849 @@ |
||
| 11 | 11 | |
| 12 | 12 | class HTML2PDF_parsingCss |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * reference to the pdf object |
|
| 16 | - * @var TCPDF |
|
| 17 | - */ |
|
| 18 | - protected $_pdf = null; |
|
| 19 | - |
|
| 20 | - protected $_htmlColor = array(); // list of the HTML colors |
|
| 21 | - protected $_onlyLeft = false; // flag if we are in a sub html => only "text-align:left" is used |
|
| 22 | - protected $_defaultFont = null; // default font to use if the asked font does not exist |
|
| 23 | - |
|
| 24 | - public $value = array(); // current values |
|
| 25 | - public $css = array(); // css values |
|
| 26 | - public $cssKeys = array(); // css key, for the execution order |
|
| 27 | - public $table = array(); // level history |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Constructor |
|
| 31 | - * |
|
| 32 | - * @param &HTML2PDF_myPdf reference to the PDF $object |
|
| 33 | - * @param HTML2PDF_myPdf $pdf |
|
| 34 | - * @access public |
|
| 35 | - */ |
|
| 36 | - public function __construct(&$pdf) |
|
| 37 | - { |
|
| 38 | - $this->_init(); |
|
| 39 | - $this->setPdfParent($pdf); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Set the HTML2PDF parent object |
|
| 44 | - * |
|
| 45 | - * @param &HTML2PDF reference to the HTML2PDF parent $object |
|
| 46 | - * @access public |
|
| 47 | - */ |
|
| 48 | - public function setPdfParent(&$pdf) |
|
| 49 | - { |
|
| 50 | - $this->_pdf = &$pdf; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Inform that we want only "test-align:left" because we are in a sub HTML |
|
| 55 | - * |
|
| 56 | - * @access public |
|
| 57 | - */ |
|
| 58 | - public function setOnlyLeft() |
|
| 59 | - { |
|
| 60 | - $this->value['text-align'] = 'left'; |
|
| 61 | - $this->_onlyLeft = true; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Get the vales of the parent, if exist |
|
| 66 | - * |
|
| 67 | - * @return array CSS values |
|
| 68 | - * @access public |
|
| 69 | - */ |
|
| 70 | - public function getOldValues() |
|
| 71 | - { |
|
| 72 | - return isset($this->table[count($this->table) - 1]) ? $this->table[count($this->table) - 1] : $this->value; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * define the Default Font to use, if the font does not exist, or if no font asked |
|
| 77 | - * |
|
| 78 | - * @param string default font-family. If null : Arial for no font asked, and error fot ont does not exist |
|
| 79 | - * @param string $default |
|
| 80 | - * @return string old default font-family |
|
| 81 | - * @access public |
|
| 82 | - */ |
|
| 83 | - public function setDefaultFont($default = null) |
|
| 84 | - { |
|
| 85 | - $old = $this->_defaultFont; |
|
| 86 | - $this->_defaultFont = $default; |
|
| 87 | - if ($default) { |
|
| 88 | - $this->value['font-family'] = $default; |
|
| 89 | - } |
|
| 90 | - return $old; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Init the object |
|
| 95 | - * |
|
| 96 | - * @access protected |
|
| 97 | - */ |
|
| 98 | - protected function _init() |
|
| 99 | - { |
|
| 100 | - // get the Web Colors from TCPDF |
|
| 101 | - require(K_PATH_MAIN.'htmlcolors.php'); |
|
| 102 | - $this->_htmlColor = $webcolor; |
|
| 103 | - |
|
| 104 | - // init the Style |
|
| 105 | - $this->table = array(); |
|
| 106 | - $this->value = array(); |
|
| 107 | - $this->initStyle(); |
|
| 108 | - |
|
| 109 | - // Init the styles without legacy |
|
| 110 | - $this->resetStyle(); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Init the CSS Style |
|
| 115 | - * |
|
| 116 | - * @access public |
|
| 117 | - */ |
|
| 118 | - public function initStyle() |
|
| 119 | - { |
|
| 120 | - $this->value['id_tag'] = 'body'; // tag name |
|
| 121 | - $this->value['id_name'] = null; // tag - attribute name |
|
| 122 | - $this->value['id_id'] = null; // tag - attribute id |
|
| 123 | - $this->value['id_class'] = null; // tag - attribute class |
|
| 124 | - $this->value['id_lst'] = array('*'); // tag - list of legacy |
|
| 125 | - $this->value['mini-size'] = 1.; // specific size report for sup, sub |
|
| 126 | - $this->value['mini-decal'] = 0; // specific position report for sup, sub |
|
| 127 | - $this->value['font-family'] = 'Arial'; |
|
| 128 | - $this->value['font-bold'] = false; |
|
| 129 | - $this->value['font-italic'] = false; |
|
| 130 | - $this->value['font-underline'] = false; |
|
| 131 | - $this->value['font-overline'] = false; |
|
| 132 | - $this->value['font-linethrough'] = false; |
|
| 133 | - $this->value['text-transform'] = 'none'; |
|
| 134 | - $this->value['font-size'] = $this->convertToMM('10pt'); |
|
| 135 | - $this->value['text-indent'] = 0; |
|
| 136 | - $this->value['text-align'] = 'left'; |
|
| 137 | - $this->value['vertical-align'] = 'middle'; |
|
| 138 | - $this->value['line-height'] = 'normal'; |
|
| 139 | - |
|
| 140 | - $this->value['position'] = null; |
|
| 141 | - $this->value['x'] = null; |
|
| 142 | - $this->value['y'] = null; |
|
| 143 | - $this->value['width'] = 0; |
|
| 144 | - $this->value['height'] = 0; |
|
| 145 | - $this->value['top'] = null; |
|
| 146 | - $this->value['right'] = null; |
|
| 147 | - $this->value['bottom'] = null; |
|
| 148 | - $this->value['left'] = null; |
|
| 149 | - $this->value['float'] = null; |
|
| 150 | - $this->value['display'] = null; |
|
| 151 | - $this->value['rotate'] = null; |
|
| 152 | - $this->value['overflow'] = 'visible'; |
|
| 153 | - |
|
| 154 | - $this->value['color'] = array(0, 0, 0); |
|
| 155 | - $this->value['background'] = array('color' => null, 'image' => null, 'position' => null, 'repeat' => null); |
|
| 156 | - $this->value['border'] = array(); |
|
| 157 | - $this->value['padding'] = array(); |
|
| 158 | - $this->value['margin'] = array(); |
|
| 159 | - $this->value['margin-auto'] = false; |
|
| 160 | - |
|
| 161 | - $this->value['list-style-type'] = ''; |
|
| 162 | - $this->value['list-style-image'] = ''; |
|
| 163 | - |
|
| 164 | - $this->value['xc'] = null; |
|
| 165 | - $this->value['yc'] = null; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Init the CSS Style without legacy |
|
| 170 | - * |
|
| 171 | - * @param string tag name |
|
| 172 | - * @access public |
|
| 173 | - */ |
|
| 174 | - public function resetStyle($tagName = '') |
|
| 175 | - { |
|
| 176 | - // prepare somme values |
|
| 177 | - $border = $this->readBorder('solid 1px #000000'); |
|
| 178 | - $units = array( |
|
| 179 | - '1px' => $this->convertToMM('1px'), |
|
| 180 | - '5px' => $this->convertToMM('5px'), |
|
| 181 | - ); |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - // prepare the Collapse attribute |
|
| 185 | - $collapse = isset($this->value['border']['collapse']) ? $this->value['border']['collapse'] : false; |
|
| 186 | - if ( ! in_array($tagName, array('tr', 'td', 'th', 'thead', 'tbody', 'tfoot'))) $collapse = false; |
|
| 187 | - |
|
| 188 | - // set the global css values |
|
| 189 | - $this->value['position'] = null; |
|
| 190 | - $this->value['x'] = null; |
|
| 191 | - $this->value['y'] = null; |
|
| 192 | - $this->value['width'] = 0; |
|
| 193 | - $this->value['height'] = 0; |
|
| 194 | - $this->value['top'] = null; |
|
| 195 | - $this->value['right'] = null; |
|
| 196 | - $this->value['bottom'] = null; |
|
| 197 | - $this->value['left'] = null; |
|
| 198 | - $this->value['float'] = null; |
|
| 199 | - $this->value['display'] = null; |
|
| 200 | - $this->value['rotate'] = null; |
|
| 201 | - $this->value['overflow'] = 'visible'; |
|
| 202 | - $this->value['background'] = array('color' => null, 'image' => null, 'position' => null, 'repeat' => null); |
|
| 203 | - $this->value['border'] = array( |
|
| 204 | - 't' => $this->readBorder('none'), |
|
| 205 | - 'r' => $this->readBorder('none'), |
|
| 206 | - 'b' => $this->readBorder('none'), |
|
| 207 | - 'l' => $this->readBorder('none'), |
|
| 208 | - 'radius' => array( |
|
| 209 | - 'tl' => array(0, 0), |
|
| 210 | - 'tr' => array(0, 0), |
|
| 211 | - 'br' => array(0, 0), |
|
| 212 | - 'bl' => array(0, 0) |
|
| 213 | - ), |
|
| 214 | - 'collapse' => $collapse, |
|
| 215 | - ); |
|
| 216 | - |
|
| 217 | - // specific values for some tags |
|
| 218 | - if ( ! in_array($tagName, array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'))) { |
|
| 219 | - $this->value['margin'] = array('t'=>0, 'r'=>0, 'b'=>0, 'l'=>0); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - if (in_array($tagName, array('input', 'select', 'textarea'))) { |
|
| 223 | - $this->value['border']['t'] = null; |
|
| 224 | - $this->value['border']['r'] = null; |
|
| 225 | - $this->value['border']['b'] = null; |
|
| 226 | - $this->value['border']['l'] = null; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - if ($tagName == 'p') { |
|
| 230 | - $this->value['margin']['t'] = null; |
|
| 231 | - $this->value['margin']['b'] = null; |
|
| 232 | - } |
|
| 233 | - if ($tagName == 'blockquote') { |
|
| 234 | - $this->value['margin']['t'] = 3; |
|
| 235 | - $this->value['margin']['r'] = 3; |
|
| 236 | - $this->value['margin']['b'] = 3; |
|
| 237 | - $this->value['margin']['l'] = 6; |
|
| 238 | - } |
|
| 239 | - $this->value['margin-auto'] = false; |
|
| 240 | - |
|
| 241 | - if (in_array($tagName, array('blockquote', 'div', 'fieldset'))) { |
|
| 242 | - $this->value['vertical-align'] = 'top'; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - if (in_array($tagName, array('fieldset', 'legend'))) { |
|
| 246 | - $this->value['border'] = array( |
|
| 247 | - 't' => $border, |
|
| 248 | - 'r' => $border, |
|
| 249 | - 'b' => $border, |
|
| 250 | - 'l' => $border, |
|
| 251 | - 'radius' => array( |
|
| 252 | - 'tl' => array($units['5px'], $units['5px']), |
|
| 253 | - 'tr' => array($units['5px'], $units['5px']), |
|
| 254 | - 'br' => array($units['5px'], $units['5px']), |
|
| 255 | - 'bl' => array($units['5px'], $units['5px']) |
|
| 256 | - ), |
|
| 257 | - 'collapse' => false, |
|
| 258 | - ); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if (in_array($tagName, array('ul', 'li'))) { |
|
| 262 | - $this->value['list-style-type'] = ''; |
|
| 263 | - $this->value['list-style-image'] = ''; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - if ( ! in_array($tagName, array('tr', 'td'))) { |
|
| 267 | - $this->value['padding'] = array( |
|
| 268 | - 't' => 0, |
|
| 269 | - 'r' => 0, |
|
| 270 | - 'b' => 0, |
|
| 271 | - 'l' => 0 |
|
| 272 | - ); |
|
| 273 | - } else { |
|
| 274 | - $this->value['padding'] = array( |
|
| 275 | - 't' => $units['1px'], |
|
| 276 | - 'r' => $units['1px'], |
|
| 277 | - 'b' => $units['1px'], |
|
| 278 | - 'l' => $units['1px'] |
|
| 279 | - ); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - if ($tagName == 'hr') { |
|
| 283 | - $this->value['border'] = array( |
|
| 284 | - 't' => $border, |
|
| 285 | - 'r' => $border, |
|
| 286 | - 'b' => $border, |
|
| 287 | - 'l' => $border, |
|
| 288 | - 'radius' => array( |
|
| 289 | - 'tl' => array(0, 0), |
|
| 290 | - 'tr' => array(0, 0), |
|
| 291 | - 'br' => array(0, 0), |
|
| 292 | - 'bl' => array(0, 0) |
|
| 293 | - ), |
|
| 294 | - 'collapse' => false, |
|
| 295 | - ); |
|
| 296 | - $this->convertBackground('#FFFFFF', $this->value['background']); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - $this->value['xc'] = null; |
|
| 300 | - $this->value['yc'] = null; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Init the PDF Font |
|
| 305 | - * |
|
| 306 | - * @access public |
|
| 307 | - */ |
|
| 308 | - public function fontSet() |
|
| 309 | - { |
|
| 310 | - $family = strtolower($this->value['font-family']); |
|
| 311 | - |
|
| 312 | - $b = ($this->value['font-bold'] ? 'B' : ''); |
|
| 313 | - $i = ($this->value['font-italic'] ? 'I' : ''); |
|
| 314 | - $u = ($this->value['font-underline'] ? 'U' : ''); |
|
| 315 | - $d = ($this->value['font-linethrough'] ? 'D' : ''); |
|
| 316 | - $o = ($this->value['font-overline'] ? 'O' : ''); |
|
| 317 | - |
|
| 318 | - // font style |
|
| 319 | - $style = $b.$i; |
|
| 320 | - |
|
| 321 | - if ($this->_defaultFont) { |
|
| 322 | - if ($family == 'arial') |
|
| 323 | - $family = 'helvetica'; |
|
| 324 | - elseif ($family == 'symbol' || $family == 'zapfdingbats') |
|
| 325 | - $style = ''; |
|
| 326 | - |
|
| 327 | - $fontkey = $family.$style; |
|
| 328 | - if ( ! $this->_pdf->isLoadedFont($fontkey)) |
|
| 329 | - $family = $this->_defaultFont; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - if ($family == 'arial') |
|
| 333 | - $family = 'helvetica'; |
|
| 334 | - elseif ($family == 'symbol' || $family == 'zapfdingbats') |
|
| 335 | - $style = ''; |
|
| 336 | - |
|
| 337 | - // complete style |
|
| 338 | - $style .= $u.$d.$o; |
|
| 339 | - |
|
| 340 | - // size : mm => pt |
|
| 341 | - $size = $this->value['font-size']; |
|
| 342 | - $size = 72 * $size / 25.4; |
|
| 343 | - |
|
| 344 | - // apply the font |
|
| 345 | - $this->_pdf->SetFont($family, $style, $this->value['mini-size'] * $size); |
|
| 346 | - $this->_pdf->setTextColorArray($this->value['color']); |
|
| 347 | - if ($this->value['background']['color']) { |
|
| 348 | - $this->_pdf->setFillColorArray($this->value['background']['color']); |
|
| 349 | - } else { |
|
| 350 | - $this->_pdf->setFillColor(255); |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * add a level in the CSS history |
|
| 356 | - * |
|
| 357 | - * @access public |
|
| 358 | - */ |
|
| 359 | - public function save() |
|
| 360 | - { |
|
| 361 | - array_push($this->table, $this->value); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * remove a level in the CSS history |
|
| 366 | - * |
|
| 367 | - * @access public |
|
| 368 | - */ |
|
| 369 | - public function load() |
|
| 370 | - { |
|
| 371 | - if (count($this->table)) { |
|
| 372 | - $this->value = array_pop($this->table); |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * restore the Y positiony (used after a span) |
|
| 378 | - * |
|
| 379 | - * @access public |
|
| 380 | - */ |
|
| 381 | - public function restorePosition() |
|
| 382 | - { |
|
| 383 | - if ($this->value['y'] == $this->_pdf->getY()) $this->_pdf->setY($this->value['yc'], false); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * set the New position for the current Tag |
|
| 388 | - * |
|
| 389 | - * @access public |
|
| 390 | - */ |
|
| 391 | - public function setPosition() |
|
| 392 | - { |
|
| 393 | - // get the current position |
|
| 394 | - $currentX = $this->_pdf->getX(); |
|
| 395 | - $currentY = $this->_pdf->getY(); |
|
| 396 | - |
|
| 397 | - // save it |
|
| 398 | - $this->value['xc'] = $currentX; |
|
| 399 | - $this->value['yc'] = $currentY; |
|
| 400 | - |
|
| 401 | - if ($this->value['position'] == 'relative' || $this->value['position'] == 'absolute') { |
|
| 402 | - if ($this->value['right'] !== null) { |
|
| 403 | - $x = $this->getLastWidth(true) - $this->value['right'] - $this->value['width']; |
|
| 404 | - if ($this->value['margin']['r']) $x -= $this->value['margin']['r']; |
|
| 405 | - } else { |
|
| 406 | - $x = $this->value['left']; |
|
| 407 | - if ($this->value['margin']['l']) $x += $this->value['margin']['l']; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - if ($this->value['bottom'] !== null) { |
|
| 411 | - $y = $this->getLastHeight(true) - $this->value['bottom'] - $this->value['height']; |
|
| 412 | - if ($this->value['margin']['b']) $y -= $this->value['margin']['b']; |
|
| 413 | - } else { |
|
| 414 | - $y = $this->value['top']; |
|
| 415 | - if ($this->value['margin']['t']) $y += $this->value['margin']['t']; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - if ($this->value['position'] == 'relative') { |
|
| 419 | - $this->value['x'] = $currentX + $x; |
|
| 420 | - $this->value['y'] = $currentY + $y; |
|
| 421 | - } else { |
|
| 422 | - $this->value['x'] = $this->_getLastAbsoluteX() + $x; |
|
| 423 | - $this->value['y'] = $this->_getLastAbsoluteY() + $y; |
|
| 424 | - } |
|
| 425 | - } else { |
|
| 426 | - $this->value['x'] = $currentX; |
|
| 427 | - $this->value['y'] = $currentY; |
|
| 428 | - if ($this->value['margin']['l']) $this->value['x'] += $this->value['margin']['l']; |
|
| 429 | - if ($this->value['margin']['t']) $this->value['y'] += $this->value['margin']['t']; |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - // save the new position |
|
| 433 | - $this->_pdf->setXY($this->value['x'], $this->value['y']); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Analise the CSS style to convert it into Form style |
|
| 438 | - * |
|
| 439 | - * @access public |
|
| 440 | - * @param array styles |
|
| 441 | - */ |
|
| 442 | - public function getFormStyle() |
|
| 443 | - { |
|
| 444 | - $prop = array(); |
|
| 445 | - |
|
| 446 | - $prop['alignment'] = $this->value['text-align']; |
|
| 447 | - |
|
| 448 | - if (isset($this->value['background']['color']) && is_array($this->value['background']['color'])) { |
|
| 449 | - $prop['fillColor'] = $this->value['background']['color']; |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - if (isset($this->value['border']['t']['color'])) { |
|
| 453 | - $prop['strokeColor'] = $this->value['border']['t']['color']; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - if (isset($this->value['border']['t']['width'])) { |
|
| 457 | - $prop['lineWidth'] = $this->value['border']['t']['width']; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - if (isset($this->value['border']['t']['type'])) { |
|
| 461 | - $prop['borderStyle'] = $this->value['border']['t']['type']; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - if ( ! empty($this->value['color'])) { |
|
| 465 | - $prop['textColor'] = $this->value['color']; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - if ( ! empty($this->value['font-size'])) { |
|
| 469 | - $prop['textSize'] = $this->value['font-size']; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - return $prop; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Analise the CSS style to convert it into SVG style |
|
| 477 | - * |
|
| 478 | - * @access public |
|
| 479 | - * @param string tag name |
|
| 480 | - * @param array styles |
|
| 481 | - * @param string $tagName |
|
| 482 | - */ |
|
| 483 | - public function getSvgStyle($tagName, &$param) |
|
| 484 | - { |
|
| 485 | - // prepare |
|
| 486 | - $tagName = strtolower($tagName); |
|
| 487 | - $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) $id = null; |
|
| 488 | - $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if ( ! $name) $name = null; |
|
| 489 | - |
|
| 490 | - // read the class attribute |
|
| 491 | - $class = array(); |
|
| 492 | - $tmp = isset($param['class']) ? strtolower(trim($param['class'])) : ''; |
|
| 493 | - $tmp = explode(' ', $tmp); |
|
| 494 | - foreach ($tmp as $k => $v) { |
|
| 495 | - $v = trim($v); |
|
| 496 | - if ($v) { |
|
| 497 | - $class[] = $v; |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - // identify the tag, and the direct styles |
|
| 502 | - $this->value['id_tag'] = $tagName; |
|
| 503 | - $this->value['id_name'] = $name; |
|
| 504 | - $this->value['id_id'] = $id; |
|
| 505 | - $this->value['id_class'] = $class; |
|
| 506 | - $this->value['id_lst'] = array(); |
|
| 507 | - $this->value['id_lst'][] = '*'; |
|
| 508 | - $this->value['id_lst'][] = $tagName; |
|
| 509 | - if ( ! isset($this->value['svg'])) { |
|
| 510 | - $this->value['svg'] = array( |
|
| 511 | - 'stroke' => null, |
|
| 512 | - 'stroke-width' => $this->convertToMM('1pt'), |
|
| 513 | - 'fill' => null, |
|
| 514 | - 'fill-opacity' => null, |
|
| 515 | - ); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - if (count($class)) { |
|
| 519 | - foreach ($class as $v) { |
|
| 520 | - $this->value['id_lst'][] = '*.'.$v; |
|
| 521 | - $this->value['id_lst'][] = '.'.$v; |
|
| 522 | - $this->value['id_lst'][] = $tagName.'.'.$v; |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - if ($id) { |
|
| 526 | - $this->value['id_lst'][] = '*#'.$id; |
|
| 527 | - $this->value['id_lst'][] = '#'.$id; |
|
| 528 | - $this->value['id_lst'][] = $tagName.'#'.$id; |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - // CSS style |
|
| 532 | - $styles = $this->_getFromCSS(); |
|
| 533 | - |
|
| 534 | - // adding the style from the tag |
|
| 535 | - $styles = array_merge($styles, $param['style']); |
|
| 536 | - |
|
| 537 | - if (isset($styles['stroke'])) $this->value['svg']['stroke'] = $this->convertToColor($styles['stroke'], $res); |
|
| 538 | - if (isset($styles['stroke-width'])) $this->value['svg']['stroke-width'] = $this->convertToMM($styles['stroke-width']); |
|
| 539 | - if (isset($styles['fill'])) $this->value['svg']['fill'] = $this->convertToColor($styles['fill'], $res); |
|
| 540 | - if (isset($styles['fill-opacity'])) $this->value['svg']['fill-opacity'] = 1. * $styles['fill-opacity']; |
|
| 541 | - |
|
| 542 | - return $this->value['svg']; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * analyse the css properties from the HTML parsing |
|
| 547 | - * |
|
| 548 | - * @access public |
|
| 549 | - * @param string $tagName |
|
| 550 | - * @param array $param |
|
| 551 | - * @param array $legacy |
|
| 552 | - */ |
|
| 553 | - public function analyse($tagName, &$param, $legacy = null) |
|
| 554 | - { |
|
| 555 | - // prepare the informations |
|
| 556 | - $tagName = strtolower($tagName); |
|
| 557 | - $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) $id = null; |
|
| 558 | - $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if ( ! $name) $name = null; |
|
| 559 | - |
|
| 560 | - // get the class names to use |
|
| 561 | - $class = array(); |
|
| 562 | - $tmp = isset($param['class']) ? strtolower(trim($param['class'])) : ''; |
|
| 563 | - $tmp = explode(' ', $tmp); |
|
| 564 | - foreach ($tmp as $k => $v) { |
|
| 565 | - $v = trim($v); |
|
| 566 | - if ($v) { |
|
| 567 | - $class[] = $v; |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - // prepare the values, and the list of css tags to identify |
|
| 572 | - $this->value['id_tag'] = $tagName; |
|
| 573 | - $this->value['id_name'] = $name; |
|
| 574 | - $this->value['id_id'] = $id; |
|
| 575 | - $this->value['id_class'] = $class; |
|
| 576 | - $this->value['id_lst'] = array(); |
|
| 577 | - $this->value['id_lst'][] = '*'; |
|
| 578 | - $this->value['id_lst'][] = $tagName; |
|
| 579 | - if (count($class)) { |
|
| 580 | - foreach ($class as $v) { |
|
| 581 | - $this->value['id_lst'][] = '*.'.$v; |
|
| 582 | - $this->value['id_lst'][] = '.'.$v; |
|
| 583 | - $this->value['id_lst'][] = $tagName.'.'.$v; |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - if ($id) { |
|
| 587 | - $this->value['id_lst'][] = '*#'.$id; |
|
| 588 | - $this->value['id_lst'][] = '#'.$id; |
|
| 589 | - $this->value['id_lst'][] = $tagName.'#'.$id; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - // get the css styles from class |
|
| 593 | - $styles = $this->_getFromCSS(); |
|
| 594 | - |
|
| 595 | - // merge with the css styles from tag |
|
| 596 | - $styles = array_merge($styles, $param['style']); |
|
| 597 | - if (isset($param['allwidth']) && ! isset($styles['width'])) $styles['width'] = '100%'; |
|
| 598 | - |
|
| 599 | - // reset some styles, depending on the tag name |
|
| 600 | - $this->resetStyle($tagName); |
|
| 601 | - |
|
| 602 | - // add the legacy values |
|
| 603 | - if ($legacy) { |
|
| 604 | - foreach ($legacy as $legacyName => $legacyValue) { |
|
| 605 | - if (is_array($legacyValue)) { |
|
| 606 | - foreach ($legacyValue as $legacy2Name => $legacy2Value) |
|
| 607 | - $this->value[$legacyName][$legacy2Name] = $legacy2Value; |
|
| 608 | - } else { |
|
| 609 | - $this->value[$legacyName] = $legacyValue; |
|
| 610 | - } |
|
| 611 | - } |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - // some flags |
|
| 615 | - $correctWidth = false; |
|
| 616 | - $noWidth = true; |
|
| 617 | - |
|
| 618 | - // read all the css styles |
|
| 619 | - foreach ($styles as $nom => $val) { |
|
| 620 | - switch ($nom) |
|
| 621 | - { |
|
| 622 | - case 'font-family': |
|
| 623 | - $val = explode(',', $val); |
|
| 624 | - $val = trim($val[0]); |
|
| 625 | - if ($val) { |
|
| 626 | - $this->value['font-family'] = $val; |
|
| 627 | - } |
|
| 628 | - break; |
|
| 629 | - |
|
| 630 | - case 'font-weight': |
|
| 631 | - $this->value['font-bold'] = ($val == 'bold'); |
|
| 632 | - break; |
|
| 633 | - |
|
| 634 | - case 'font-style': |
|
| 635 | - $this->value['font-italic'] = ($val == 'italic'); |
|
| 636 | - break; |
|
| 637 | - |
|
| 638 | - case 'text-decoration': |
|
| 639 | - $val = explode(' ', $val); |
|
| 640 | - $this->value['font-underline'] = (in_array('underline', $val)); |
|
| 641 | - $this->value['font-overline'] = (in_array('overline', $val)); |
|
| 642 | - $this->value['font-linethrough'] = (in_array('line-through', $val)); |
|
| 643 | - break; |
|
| 644 | - |
|
| 645 | - case 'text-indent': |
|
| 646 | - $this->value['text-indent'] = $this->convertToMM($val); |
|
| 647 | - break; |
|
| 648 | - |
|
| 649 | - case 'text-transform': |
|
| 650 | - if ( ! in_array($val, array('none', 'capitalize', 'uppercase', 'lowercase'))) $val = 'none'; |
|
| 651 | - $this->value['text-transform'] = $val; |
|
| 652 | - break; |
|
| 653 | - |
|
| 654 | - case 'font-size': |
|
| 655 | - $val = $this->convertToMM($val, $this->value['font-size']); |
|
| 656 | - if ($val) $this->value['font-size'] = $val; |
|
| 657 | - break; |
|
| 658 | - |
|
| 659 | - case 'color': |
|
| 660 | - $res = null; |
|
| 661 | - $this->value['color'] = $this->convertToColor($val, $res); |
|
| 662 | - if ($tagName == 'hr') { |
|
| 663 | - $this->value['border']['l']['color'] = $this->value['color']; |
|
| 664 | - $this->value['border']['t']['color'] = $this->value['color']; |
|
| 665 | - $this->value['border']['r']['color'] = $this->value['color']; |
|
| 666 | - $this->value['border']['b']['color'] = $this->value['color']; |
|
| 667 | - } |
|
| 668 | - break; |
|
| 669 | - |
|
| 670 | - case 'text-align': |
|
| 671 | - $val = strtolower($val); |
|
| 672 | - if ( ! in_array($val, array('left', 'right', 'center', 'justify', 'li_right'))) $val = 'left'; |
|
| 673 | - $this->value['text-align'] = $val; |
|
| 674 | - break; |
|
| 675 | - |
|
| 676 | - case 'vertical-align': |
|
| 677 | - $this->value['vertical-align'] = $val; |
|
| 678 | - break; |
|
| 679 | - |
|
| 680 | - case 'width': |
|
| 681 | - $this->value['width'] = $this->convertToMM($val, $this->getLastWidth()); |
|
| 682 | - if ($this->value['width'] && substr($val, -1) == '%') $correctWidth = true; |
|
| 683 | - $noWidth = false; |
|
| 684 | - break; |
|
| 685 | - |
|
| 686 | - case 'height': |
|
| 687 | - $this->value['height'] = $this->convertToMM($val, $this->getLastHeight()); |
|
| 688 | - break; |
|
| 689 | - |
|
| 690 | - case 'line-height': |
|
| 691 | - if (preg_match('/^[0-9\.]+$/isU', $val)) $val = floor($val * 100).'%'; |
|
| 692 | - $this->value['line-height'] = $val; |
|
| 693 | - break; |
|
| 694 | - |
|
| 695 | - case 'rotate': |
|
| 696 | - if ( ! in_array($val, array(0, -90, 90, 180, 270, -180, -270))) $val = null; |
|
| 697 | - if ($val < 0) $val += 360; |
|
| 698 | - $this->value['rotate'] = $val; |
|
| 699 | - break; |
|
| 700 | - |
|
| 701 | - case 'overflow': |
|
| 702 | - if ( ! in_array($val, array('visible', 'hidden'))) $val = 'visible'; |
|
| 703 | - $this->value['overflow'] = $val; |
|
| 704 | - break; |
|
| 705 | - |
|
| 706 | - case 'padding': |
|
| 707 | - $val = explode(' ', $val); |
|
| 708 | - foreach ($val as $k => $v) { |
|
| 709 | - $v = trim($v); |
|
| 710 | - if ($v != '') { |
|
| 711 | - $val[$k] = $v; |
|
| 712 | - } else { |
|
| 713 | - unset($val[$k]); |
|
| 714 | - } |
|
| 715 | - } |
|
| 716 | - $val = array_values($val); |
|
| 717 | - $this->_duplicateBorder($val); |
|
| 718 | - $this->value['padding']['t'] = $this->convertToMM($val[0], 0); |
|
| 719 | - $this->value['padding']['r'] = $this->convertToMM($val[1], 0); |
|
| 720 | - $this->value['padding']['b'] = $this->convertToMM($val[2], 0); |
|
| 721 | - $this->value['padding']['l'] = $this->convertToMM($val[3], 0); |
|
| 722 | - break; |
|
| 723 | - |
|
| 724 | - case 'padding-top': |
|
| 725 | - $this->value['padding']['t'] = $this->convertToMM($val, 0); |
|
| 726 | - break; |
|
| 727 | - |
|
| 728 | - case 'padding-right': |
|
| 729 | - $this->value['padding']['r'] = $this->convertToMM($val, 0); |
|
| 730 | - break; |
|
| 731 | - |
|
| 732 | - case 'padding-bottom': |
|
| 733 | - $this->value['padding']['b'] = $this->convertToMM($val, 0); |
|
| 734 | - break; |
|
| 735 | - |
|
| 736 | - case 'padding-left': |
|
| 737 | - $this->value['padding']['l'] = $this->convertToMM($val, 0); |
|
| 738 | - break; |
|
| 739 | - |
|
| 740 | - case 'margin': |
|
| 741 | - if ($val == 'auto') { |
|
| 742 | - $this->value['margin-auto'] = true; |
|
| 743 | - break; |
|
| 744 | - } |
|
| 745 | - $val = explode(' ', $val); |
|
| 746 | - foreach ($val as $k => $v) { |
|
| 747 | - $v = trim($v); |
|
| 748 | - if ($v != '') { |
|
| 749 | - $val[$k] = $v; |
|
| 750 | - } else { |
|
| 751 | - unset($val[$k]); |
|
| 752 | - } |
|
| 753 | - } |
|
| 754 | - $val = array_values($val); |
|
| 755 | - $this->_duplicateBorder($val); |
|
| 756 | - $this->value['margin']['t'] = $this->convertToMM($val[0], 0); |
|
| 757 | - $this->value['margin']['r'] = $this->convertToMM($val[1], 0); |
|
| 758 | - $this->value['margin']['b'] = $this->convertToMM($val[2], 0); |
|
| 759 | - $this->value['margin']['l'] = $this->convertToMM($val[3], 0); |
|
| 760 | - break; |
|
| 761 | - |
|
| 762 | - case 'margin-top': |
|
| 763 | - $this->value['margin']['t'] = $this->convertToMM($val, 0); |
|
| 764 | - break; |
|
| 765 | - |
|
| 766 | - case 'margin-right': |
|
| 767 | - $this->value['margin']['r'] = $this->convertToMM($val, 0); |
|
| 768 | - break; |
|
| 769 | - |
|
| 770 | - case 'margin-bottom': |
|
| 771 | - $this->value['margin']['b'] = $this->convertToMM($val, 0); |
|
| 772 | - break; |
|
| 773 | - |
|
| 774 | - case 'margin-left': |
|
| 775 | - $this->value['margin']['l'] = $this->convertToMM($val, 0); |
|
| 776 | - break; |
|
| 777 | - |
|
| 778 | - case 'border': |
|
| 779 | - $val = $this->readBorder($val); |
|
| 780 | - $this->value['border']['t'] = $val; |
|
| 781 | - $this->value['border']['r'] = $val; |
|
| 782 | - $this->value['border']['b'] = $val; |
|
| 783 | - $this->value['border']['l'] = $val; |
|
| 784 | - break; |
|
| 785 | - |
|
| 786 | - case 'border-style': |
|
| 787 | - $val = explode(' ', $val); |
|
| 788 | - foreach ($val as $valK => $valV) { |
|
| 789 | - if ( ! in_array($valV, array('solid', 'dotted', 'dashed'))) { |
|
| 790 | - $val[$valK] = null; |
|
| 791 | - } |
|
| 792 | - } |
|
| 793 | - $this->_duplicateBorder($val); |
|
| 794 | - if ($val[0]) { |
|
| 795 | - $this->value['border']['t']['type'] = $val[0]; |
|
| 796 | - } |
|
| 797 | - if ($val[1]) { |
|
| 798 | - $this->value['border']['r']['type'] = $val[1]; |
|
| 799 | - } |
|
| 800 | - if ($val[2]) { |
|
| 801 | - $this->value['border']['b']['type'] = $val[2]; |
|
| 802 | - } |
|
| 803 | - if ($val[3]) { |
|
| 804 | - $this->value['border']['l']['type'] = $val[3]; |
|
| 805 | - } |
|
| 806 | - break; |
|
| 807 | - |
|
| 808 | - case 'border-top-style': |
|
| 809 | - if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 810 | - $this->value['border']['t']['type'] = $val; |
|
| 811 | - } |
|
| 812 | - break; |
|
| 813 | - |
|
| 814 | - case 'border-right-style': |
|
| 815 | - if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 816 | - $this->value['border']['r']['type'] = $val; |
|
| 817 | - } |
|
| 818 | - break; |
|
| 819 | - |
|
| 820 | - case 'border-bottom-style': |
|
| 821 | - if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 822 | - $this->value['border']['b']['type'] = $val; |
|
| 823 | - } |
|
| 824 | - break; |
|
| 825 | - |
|
| 826 | - case 'border-left-style': |
|
| 827 | - if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 828 | - $this->value['border']['l']['type'] = $val; |
|
| 829 | - } |
|
| 830 | - break; |
|
| 831 | - |
|
| 832 | - case 'border-color': |
|
| 833 | - $res = false; |
|
| 834 | - $val = preg_replace('/,[\s]+/', ',', $val); |
|
| 835 | - $val = explode(' ', $val); |
|
| 836 | - foreach ($val as $valK => $valV) { |
|
| 837 | - $val[$valK] = $this->convertToColor($valV, $res); |
|
| 838 | - if ( ! $res) { |
|
| 839 | - $val[$valK] = null; |
|
| 840 | - } |
|
| 841 | - } |
|
| 842 | - $this->_duplicateBorder($val); |
|
| 843 | - if (is_array($val[0])) { |
|
| 844 | - $this->value['border']['t']['color'] = $val[0]; |
|
| 845 | - } |
|
| 846 | - if (is_array($val[1])) { |
|
| 847 | - $this->value['border']['r']['color'] = $val[1]; |
|
| 848 | - } |
|
| 849 | - if (is_array($val[2])) { |
|
| 850 | - $this->value['border']['b']['color'] = $val[2]; |
|
| 851 | - } |
|
| 852 | - if (is_array($val[3])) { |
|
| 853 | - $this->value['border']['l']['color'] = $val[3]; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - break; |
|
| 857 | - |
|
| 858 | - case 'border-top-color': |
|
| 859 | - $res = false; |
|
| 860 | - $val = $this->convertToColor($val, $res); |
|
| 861 | - if ($res) { |
|
| 862 | - $this->value['border']['t']['color'] = $val; |
|
| 863 | - } |
|
| 864 | - break; |
|
| 865 | - |
|
| 866 | - case 'border-right-color': |
|
| 867 | - $res = false; |
|
| 868 | - $val = $this->convertToColor($val, $res); |
|
| 869 | - if ($res) { |
|
| 870 | - $this->value['border']['r']['color'] = $val; |
|
| 871 | - } |
|
| 872 | - break; |
|
| 873 | - |
|
| 874 | - case 'border-bottom-color': |
|
| 875 | - $res = false; |
|
| 876 | - $val = $this->convertToColor($val, $res); |
|
| 877 | - if ($res) { |
|
| 878 | - $this->value['border']['b']['color'] = $val; |
|
| 879 | - } |
|
| 880 | - break; |
|
| 881 | - |
|
| 882 | - case 'border-left-color': |
|
| 883 | - $res = false; |
|
| 884 | - $val = $this->convertToColor($val, $res); |
|
| 885 | - if ($res) { |
|
| 886 | - $this->value['border']['l']['color'] = $val; |
|
| 887 | - } |
|
| 888 | - break; |
|
| 889 | - |
|
| 890 | - case 'border-width': |
|
| 891 | - $val = explode(' ', $val); |
|
| 892 | - foreach ($val as $valK => $valV) { |
|
| 893 | - $val[$valK] = $this->convertToMM($valV, 0); |
|
| 894 | - } |
|
| 895 | - $this->_duplicateBorder($val); |
|
| 896 | - if ($val[0]) $this->value['border']['t']['width'] = $val[0]; |
|
| 897 | - if ($val[1]) $this->value['border']['r']['width'] = $val[1]; |
|
| 898 | - if ($val[2]) $this->value['border']['b']['width'] = $val[2]; |
|
| 899 | - if ($val[3]) $this->value['border']['l']['width'] = $val[3]; |
|
| 900 | - break; |
|
| 901 | - |
|
| 902 | - case 'border-top-width': |
|
| 903 | - $val = $this->convertToMM($val, 0); |
|
| 904 | - if ($val) $this->value['border']['t']['width'] = $val; |
|
| 905 | - break; |
|
| 906 | - |
|
| 907 | - case 'border-right-width': |
|
| 908 | - $val = $this->convertToMM($val, 0); |
|
| 909 | - if ($val) $this->value['border']['r']['width'] = $val; |
|
| 910 | - break; |
|
| 911 | - |
|
| 912 | - case 'border-bottom-width': |
|
| 913 | - $val = $this->convertToMM($val, 0); |
|
| 914 | - if ($val) $this->value['border']['b']['width'] = $val; |
|
| 915 | - break; |
|
| 916 | - |
|
| 917 | - case 'border-left-width': |
|
| 918 | - $val = $this->convertToMM($val, 0); |
|
| 919 | - if ($val) $this->value['border']['l']['width'] = $val; |
|
| 920 | - break; |
|
| 921 | - |
|
| 922 | - case 'border-collapse': |
|
| 923 | - if ($tagName == 'table') $this->value['border']['collapse'] = ($val == 'collapse'); |
|
| 924 | - break; |
|
| 925 | - |
|
| 926 | - case 'border-radius': |
|
| 927 | - $val = explode('/', $val); |
|
| 928 | - if (count($val) > 2) { |
|
| 929 | - break; |
|
| 930 | - } |
|
| 931 | - $valH = $this->convertToRadius(trim($val[0])); |
|
| 932 | - if (count($valH) < 1 || count($valH) > 4) { |
|
| 933 | - break; |
|
| 934 | - } |
|
| 935 | - if ( ! isset($valH[1])) $valH[1] = $valH[0]; |
|
| 936 | - if ( ! isset($valH[2])) $valH = array($valH[0], $valH[0], $valH[1], $valH[1]); |
|
| 937 | - if ( ! isset($valH[3])) $valH[3] = $valH[1]; |
|
| 938 | - if (isset($val[1])) { |
|
| 939 | - $valV = $this->convertToRadius(trim($val[1])); |
|
| 940 | - if (count($valV) < 1 || count($valV) > 4) { |
|
| 941 | - break; |
|
| 942 | - } |
|
| 943 | - if ( ! isset($valV[1])) $valV[1] = $valV[0]; |
|
| 944 | - if ( ! isset($valV[2])) $valV = array($valV[0], $valV[0], $valV[1], $valV[1]); |
|
| 945 | - if ( ! isset($valV[3])) $valV[3] = $valV[1]; |
|
| 946 | - } else { |
|
| 947 | - $valV = $valH; |
|
| 948 | - } |
|
| 949 | - $this->value['border']['radius'] = array( |
|
| 950 | - 'tl' => array($valH[0], $valV[0]), |
|
| 951 | - 'tr' => array($valH[1], $valV[1]), |
|
| 952 | - 'br' => array($valH[2], $valV[2]), |
|
| 953 | - 'bl' => array($valH[3], $valV[3]) |
|
| 954 | - ); |
|
| 955 | - break; |
|
| 956 | - |
|
| 957 | - case 'border-top-left-radius': |
|
| 958 | - $val = $this->convertToRadius($val); |
|
| 959 | - if (count($val) < 1 || count($val) > 2) { |
|
| 960 | - break; |
|
| 961 | - } |
|
| 962 | - $this->value['border']['radius']['tl'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 963 | - break; |
|
| 964 | - |
|
| 965 | - case 'border-top-right-radius': |
|
| 966 | - $val = $this->convertToRadius($val); |
|
| 967 | - if (count($val) < 1 || count($val) > 2) { |
|
| 968 | - break; |
|
| 969 | - } |
|
| 970 | - $this->value['border']['radius']['tr'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 971 | - break; |
|
| 972 | - |
|
| 973 | - case 'border-bottom-right-radius': |
|
| 974 | - $val = $this->convertToRadius($val); |
|
| 975 | - if (count($val) < 1 || count($val) > 2) { |
|
| 976 | - break; |
|
| 977 | - } |
|
| 978 | - $this->value['border']['radius']['br'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 979 | - break; |
|
| 980 | - |
|
| 981 | - case 'border-bottom-left-radius': |
|
| 982 | - $val = $this->convertToRadius($val); |
|
| 983 | - if (count($val) < 1 || count($val) > 2) { |
|
| 984 | - break; |
|
| 985 | - } |
|
| 986 | - $this->value['border']['radius']['bl'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 987 | - break; |
|
| 988 | - |
|
| 989 | - case 'border-top': |
|
| 990 | - $this->value['border']['t'] = $this->readBorder($val); |
|
| 991 | - break; |
|
| 992 | - |
|
| 993 | - case 'border-right': |
|
| 994 | - $this->value['border']['r'] = $this->readBorder($val); |
|
| 995 | - break; |
|
| 996 | - |
|
| 997 | - case 'border-bottom': |
|
| 998 | - $this->value['border']['b'] = $this->readBorder($val); |
|
| 999 | - break; |
|
| 1000 | - |
|
| 1001 | - case 'border-left': |
|
| 1002 | - $this->value['border']['l'] = $this->readBorder($val); |
|
| 1003 | - break; |
|
| 1004 | - |
|
| 1005 | - case 'background-color': |
|
| 1006 | - $this->value['background']['color'] = $this->convertBackgroundColor($val); |
|
| 1007 | - break; |
|
| 1008 | - |
|
| 1009 | - case 'background-image': |
|
| 1010 | - $this->value['background']['image'] = $this->convertBackgroundImage($val); |
|
| 1011 | - break; |
|
| 1012 | - |
|
| 1013 | - case 'background-position': |
|
| 1014 | - $res = null; |
|
| 1015 | - $this->value['background']['position'] = $this->convertBackgroundPosition($val, $res); |
|
| 1016 | - break; |
|
| 1017 | - |
|
| 1018 | - case 'background-repeat': |
|
| 1019 | - $this->value['background']['repeat'] = $this->convertBackgroundRepeat($val); |
|
| 1020 | - break; |
|
| 1021 | - |
|
| 1022 | - case 'background': |
|
| 1023 | - $this->convertBackground($val, $this->value['background']); |
|
| 1024 | - break; |
|
| 1025 | - |
|
| 1026 | - case 'position': |
|
| 1027 | - if ($val == 'absolute') $this->value['position'] = 'absolute'; |
|
| 1028 | - else if ($val == 'relative') $this->value['position'] = 'relative'; |
|
| 1029 | - else $this->value['position'] = null; |
|
| 1030 | - break; |
|
| 1031 | - |
|
| 1032 | - case 'float': |
|
| 1033 | - if ($val == 'left') $this->value['float'] = 'left'; |
|
| 1034 | - else if ($val == 'right') $this->value['float'] = 'right'; |
|
| 1035 | - else $this->value['float'] = null; |
|
| 1036 | - break; |
|
| 1037 | - |
|
| 1038 | - case 'display': |
|
| 1039 | - if ($val == 'inline') $this->value['display'] = 'inline'; |
|
| 1040 | - else if ($val == 'block') $this->value['display'] = 'block'; |
|
| 1041 | - else if ($val == 'none') $this->value['display'] = 'none'; |
|
| 1042 | - else $this->value['display'] = null; |
|
| 1043 | - break; |
|
| 1044 | - |
|
| 1045 | - case 'top': |
|
| 1046 | - case 'bottom': |
|
| 1047 | - case 'left': |
|
| 1048 | - case 'right': |
|
| 1049 | - $this->value[$nom] = $val; |
|
| 1050 | - break; |
|
| 1051 | - |
|
| 1052 | - case 'list-style': |
|
| 1053 | - case 'list-style-type': |
|
| 1054 | - case 'list-style-image': |
|
| 1055 | - if ($nom == 'list-style') $nom = 'list-style-type'; |
|
| 1056 | - $this->value[$nom] = $val; |
|
| 1057 | - break; |
|
| 1058 | - |
|
| 1059 | - default: |
|
| 1060 | - break; |
|
| 1061 | - } |
|
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - $return = true; |
|
| 1065 | - |
|
| 1066 | - // only for P tag |
|
| 1067 | - if ($this->value['margin']['t'] === null) $this->value['margin']['t'] = $this->value['font-size']; |
|
| 1068 | - if ($this->value['margin']['b'] === null) $this->value['margin']['b'] = $this->value['font-size']; |
|
| 1069 | - |
|
| 1070 | - // force the text align to left, if asked by html2pdf |
|
| 1071 | - if ($this->_onlyLeft) $this->value['text-align'] = 'left'; |
|
| 1072 | - |
|
| 1073 | - // correction on the width (quick box) |
|
| 1074 | - if ($noWidth && in_array($tagName, array('div', 'blockquote', 'fieldset')) && $this->value['position'] != 'absolute') { |
|
| 1075 | - $this->value['width'] = $this->getLastWidth(); |
|
| 1076 | - $this->value['width'] -= $this->value['margin']['l'] + $this->value['margin']['r']; |
|
| 1077 | - } else { |
|
| 1078 | - if ($correctWidth) { |
|
| 1079 | - if ( ! in_array($tagName, array('table', 'div', 'blockquote', 'fieldset', 'hr'))) { |
|
| 1080 | - $this->value['width'] -= $this->value['padding']['l'] + $this->value['padding']['r']; |
|
| 1081 | - $this->value['width'] -= $this->value['border']['l']['width'] + $this->value['border']['r']['width']; |
|
| 1082 | - } |
|
| 1083 | - if (in_array($tagName, array('th', 'td'))) { |
|
| 1084 | - $this->value['width'] -= $this->convertToMM(isset($param['cellspacing']) ? $param['cellspacing'] : '2px'); |
|
| 1085 | - $return = false; |
|
| 1086 | - } |
|
| 1087 | - if ($this->value['width'] < 0) $this->value['width'] = 0; |
|
| 1088 | - } else { |
|
| 1089 | - if ($this->value['width']) { |
|
| 1090 | - if ($this->value['border']['l']['width']) $this->value['width'] += $this->value['border']['l']['width']; |
|
| 1091 | - if ($this->value['border']['r']['width']) $this->value['width'] += $this->value['border']['r']['width']; |
|
| 1092 | - if ($this->value['padding']['l']) $this->value['width'] += $this->value['padding']['l']; |
|
| 1093 | - if ($this->value['padding']['r']) $this->value['width'] += $this->value['padding']['r']; |
|
| 1094 | - } |
|
| 1095 | - } |
|
| 1096 | - } |
|
| 1097 | - if ($this->value['height']) { |
|
| 1098 | - if ($this->value['border']['b']['width']) $this->value['height'] += $this->value['border']['b']['width']; |
|
| 1099 | - if ($this->value['border']['t']['width']) $this->value['height'] += $this->value['border']['t']['width']; |
|
| 1100 | - if ($this->value['padding']['b']) $this->value['height'] += $this->value['padding']['b']; |
|
| 1101 | - if ($this->value['padding']['t']) $this->value['height'] += $this->value['padding']['t']; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - if ($this->value['top'] != null) $this->value['top'] = $this->convertToMM($this->value['top'], $this->getLastHeight(true)); |
|
| 1105 | - if ($this->value['bottom'] != null) $this->value['bottom'] = $this->convertToMM($this->value['bottom'], $this->getLastHeight(true)); |
|
| 1106 | - if ($this->value['left'] != null) $this->value['left'] = $this->convertToMM($this->value['left'], $this->getLastWidth(true)); |
|
| 1107 | - if ($this->value['right'] != null) $this->value['right'] = $this->convertToMM($this->value['right'], $this->getLastWidth(true)); |
|
| 1108 | - |
|
| 1109 | - if ($this->value['top'] && $this->value['bottom'] && $this->value['height']) $this->value['bottom'] = null; |
|
| 1110 | - if ($this->value['left'] && $this->value['right'] && $this->value['width']) $this->value['right'] = null; |
|
| 1111 | - |
|
| 1112 | - return $return; |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - /** |
|
| 1116 | - * get the height of the current line |
|
| 1117 | - * |
|
| 1118 | - * @access public |
|
| 1119 | - * @return float $height in mm |
|
| 1120 | - */ |
|
| 1121 | - public function getLineHeight() |
|
| 1122 | - { |
|
| 1123 | - $val = $this->value['line-height']; |
|
| 1124 | - if ($val == 'normal') $val = '108%'; |
|
| 1125 | - return $this->convertToMM($val, $this->value['font-size']); |
|
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - /** |
|
| 1129 | - * get the width of the parent |
|
| 1130 | - * |
|
| 1131 | - * @access public |
|
| 1132 | - * @param boolean $mode true => adding padding and border |
|
| 1133 | - * @return float $width in mm |
|
| 1134 | - */ |
|
| 1135 | - public function getLastWidth($mode = false) |
|
| 1136 | - { |
|
| 1137 | - for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1138 | - if ($this->table[$k]['width']) { |
|
| 1139 | - $w = $this->table[$k]['width']; |
|
| 1140 | - if ($mode) { |
|
| 1141 | - $w += $this->table[$k]['border']['l']['width'] + $this->table[$k]['padding']['l'] + 0.02; |
|
| 1142 | - $w += $this->table[$k]['border']['r']['width'] + $this->table[$k]['padding']['r'] + 0.02; |
|
| 1143 | - } |
|
| 1144 | - return $w; |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - return $this->_pdf->getW() - $this->_pdf->getlMargin() - $this->_pdf->getrMargin(); |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * get the height of the parent |
|
| 1152 | - * |
|
| 1153 | - * @access public |
|
| 1154 | - * @param boolean $mode true => adding padding and border |
|
| 1155 | - * @return float $height in mm |
|
| 1156 | - */ |
|
| 1157 | - public function getLastHeight($mode = false) |
|
| 1158 | - { |
|
| 1159 | - for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1160 | - if ($this->table[$k]['height']) { |
|
| 1161 | - $h = $this->table[$k]['height']; |
|
| 1162 | - if ($mode) { |
|
| 1163 | - $h += $this->table[$k]['border']['t']['width'] + $this->table[$k]['padding']['t'] + 0.02; |
|
| 1164 | - $h += $this->table[$k]['border']['b']['width'] + $this->table[$k]['padding']['b'] + 0.02; |
|
| 1165 | - } |
|
| 1166 | - return $h; |
|
| 1167 | - } |
|
| 1168 | - } |
|
| 1169 | - return $this->_pdf->getH() - $this->_pdf->gettMargin() - $this->_pdf->getbMargin(); |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - /** |
|
| 1173 | - * get the value of the float property |
|
| 1174 | - * |
|
| 1175 | - * @access public |
|
| 1176 | - * @return $float left/right |
|
| 1177 | - */ |
|
| 1178 | - public function getFloat() |
|
| 1179 | - { |
|
| 1180 | - if ($this->value['float'] == 'left') return 'left'; |
|
| 1181 | - if ($this->value['float'] == 'right') return 'right'; |
|
| 1182 | - return null; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - /** |
|
| 1186 | - * get the last value for a specific key |
|
| 1187 | - * |
|
| 1188 | - * @access public |
|
| 1189 | - * @param string $key |
|
| 1190 | - * @return mixed |
|
| 1191 | - */ |
|
| 1192 | - public function getLastValue($key) |
|
| 1193 | - { |
|
| 1194 | - $nb = count($this->table); |
|
| 1195 | - if ($nb > 0) { |
|
| 1196 | - return $this->table[$nb - 1][$key]; |
|
| 1197 | - } else { |
|
| 1198 | - return null; |
|
| 1199 | - } |
|
| 1200 | - } |
|
| 1201 | - |
|
| 1202 | - /** |
|
| 1203 | - * get the last absolute X |
|
| 1204 | - * |
|
| 1205 | - * @access protected |
|
| 1206 | - * @return float $x |
|
| 1207 | - */ |
|
| 1208 | - protected function _getLastAbsoluteX() |
|
| 1209 | - { |
|
| 1210 | - for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1211 | - if ($this->table[$k]['x'] && $this->table[$k]['position']) return $this->table[$k]['x']; |
|
| 1212 | - } |
|
| 1213 | - return $this->_pdf->getlMargin(); |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - /** |
|
| 1217 | - * get the last absolute Y |
|
| 1218 | - * |
|
| 1219 | - * @access protected |
|
| 1220 | - * @return float $y |
|
| 1221 | - */ |
|
| 1222 | - protected function _getLastAbsoluteY() |
|
| 1223 | - { |
|
| 1224 | - for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1225 | - if ($this->table[$k]['y'] && $this->table[$k]['position']) return $this->table[$k]['y']; |
|
| 1226 | - } |
|
| 1227 | - return $this->_pdf->gettMargin(); |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - /** |
|
| 1231 | - * get the CSS properties of the current tag |
|
| 1232 | - * |
|
| 1233 | - * @access protected |
|
| 1234 | - * @return array $styles |
|
| 1235 | - */ |
|
| 1236 | - protected function _getFromCSS() |
|
| 1237 | - { |
|
| 1238 | - // styles to apply |
|
| 1239 | - $styles = array(); |
|
| 1240 | - |
|
| 1241 | - // list of the selectors to get in the CSS files |
|
| 1242 | - $getit = array(); |
|
| 1243 | - |
|
| 1244 | - // get the list of the selectors of each tags |
|
| 1245 | - $lst = array(); |
|
| 1246 | - $lst[] = $this->value['id_lst']; |
|
| 1247 | - for ($i = count($this->table) - 1; $i >= 0; $i--) { |
|
| 1248 | - $lst[] = $this->table[$i]['id_lst']; |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - // foreach selectors in the CSS files, verify if it match with the list of selectors |
|
| 1252 | - foreach ($this->cssKeys as $key => $num) { |
|
| 1253 | - if ($this->_getReccursiveStyle($key, $lst)) { |
|
| 1254 | - $getit[$key] = $num; |
|
| 1255 | - } |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - // if we have selectors |
|
| 1259 | - if (count($getit)) { |
|
| 1260 | - // get them, but in the definition order, because of priority |
|
| 1261 | - asort($getit); |
|
| 1262 | - foreach ($getit as $key => $val) { |
|
| 1263 | - $styles = array_merge($styles, $this->css[$key]); |
|
| 1264 | - } |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - return $styles; |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - /** |
|
| 1271 | - * identify if the selector $key match with the list of tag selectors |
|
| 1272 | - * |
|
| 1273 | - * @access protected |
|
| 1274 | - * @param string $key CSS selector to analyse |
|
| 1275 | - * @param array $lst list of the selectors of each tags |
|
| 1276 | - * @param string $next next step of parsing the selector |
|
| 1277 | - * @return boolean |
|
| 1278 | - */ |
|
| 1279 | - protected function _getReccursiveStyle($key, $lst, $next = null) |
|
| 1280 | - { |
|
| 1281 | - // if next step |
|
| 1282 | - if ($next !== null) { |
|
| 1283 | - // we remove this step |
|
| 1284 | - if ($next) { |
|
| 1285 | - $key = trim(substr($key, 0, -strlen($next))); |
|
| 1286 | - } |
|
| 1287 | - array_shift($lst); |
|
| 1288 | - |
|
| 1289 | - // if no more step to identify => return false |
|
| 1290 | - if ( ! count($lst)) { |
|
| 1291 | - return false; |
|
| 1292 | - } |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - // for each selector of the current step |
|
| 1296 | - foreach ($lst[0] as $name) { |
|
| 1297 | - // if selector = key => ok |
|
| 1298 | - if ($key == $name) { |
|
| 1299 | - return true; |
|
| 1300 | - } |
|
| 1301 | - |
|
| 1302 | - // if the end of the key = the selector and the next step is ok => ok |
|
| 1303 | - if (substr($key, -strlen(' '.$name)) == ' '.$name && $this->_getReccursiveStyle($key, $lst, $name)) { |
|
| 1304 | - return true; |
|
| 1305 | - } |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - // if we are not in the first step, we analyse the sub steps (the pareng tag of the current tag) |
|
| 1309 | - if ($next !== null && $this->_getReccursiveStyle($key, $lst, '')) { |
|
| 1310 | - return true; |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - // no corresponding found |
|
| 1314 | - return false; |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - /** |
|
| 1318 | - * Analyse a border |
|
| 1319 | - * |
|
| 1320 | - * @access public |
|
| 1321 | - * @param string $css css border properties |
|
| 1322 | - * @return array border properties |
|
| 1323 | - */ |
|
| 1324 | - public function readBorder($css) |
|
| 1325 | - { |
|
| 1326 | - // border none |
|
| 1327 | - $none = array('type' => 'none', 'width' => 0, 'color' => array(0, 0, 0)); |
|
| 1328 | - |
|
| 1329 | - // default value |
|
| 1330 | - $type = 'solid'; |
|
| 1331 | - $width = $this->convertToMM('1pt'); |
|
| 1332 | - $color = array(0, 0, 0); |
|
| 1333 | - |
|
| 1334 | - // clean up the values |
|
| 1335 | - $css = explode(' ', $css); |
|
| 1336 | - foreach ($css as $k => $v) { |
|
| 1337 | - $v = trim($v); |
|
| 1338 | - if ($v) { |
|
| 1339 | - $css[$k] = $v; |
|
| 1340 | - } else { |
|
| 1341 | - unset($css[$k]); |
|
| 1342 | - } |
|
| 1343 | - } |
|
| 1344 | - $css = array_values($css); |
|
| 1345 | - |
|
| 1346 | - // read the values |
|
| 1347 | - $res = null; |
|
| 1348 | - foreach ($css as $value) { |
|
| 1349 | - |
|
| 1350 | - // if no border => return none |
|
| 1351 | - if ($value == 'none' || $value == 'hidden') { |
|
| 1352 | - return $none; |
|
| 1353 | - } |
|
| 1354 | - |
|
| 1355 | - // try to convert the value as a distance |
|
| 1356 | - $tmp = $this->convertToMM($value); |
|
| 1357 | - |
|
| 1358 | - // if the convert is ok => it is a width |
|
| 1359 | - if ($tmp !== null) { |
|
| 1360 | - $width = $tmp; |
|
| 1361 | - // else, it could be the type |
|
| 1362 | - } else if (in_array($value, array('solid', 'dotted', 'dashed', 'double'))) { |
|
| 1363 | - $type = $value; |
|
| 1364 | - // else, it could be the color |
|
| 1365 | - } else { |
|
| 1366 | - $tmp = $this->convertToColor($value, $res); |
|
| 1367 | - if ($res) $color = $tmp; |
|
| 1368 | - } |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - // if no witdh => return none |
|
| 1372 | - if ( ! $width) return $none; |
|
| 1373 | - |
|
| 1374 | - // return the border properties |
|
| 1375 | - return array('type' => $type, 'width' => $width, 'color' => $color); |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * duplicate the borders if needed |
|
| 1380 | - * |
|
| 1381 | - * @access protected |
|
| 1382 | - * @param &array $val |
|
| 1383 | - */ |
|
| 1384 | - protected function _duplicateBorder(&$val) |
|
| 1385 | - { |
|
| 1386 | - // 1 value => L => RTB |
|
| 1387 | - if (count($val) == 1) { |
|
| 1388 | - $val[1] = $val[0]; |
|
| 1389 | - $val[2] = $val[0]; |
|
| 1390 | - $val[3] = $val[0]; |
|
| 1391 | - // 2 values => L => R & T => B |
|
| 1392 | - } else if (count($val) == 2) { |
|
| 1393 | - $val[2] = $val[0]; |
|
| 1394 | - $val[3] = $val[1]; |
|
| 1395 | - // 3 values => T => B |
|
| 1396 | - } else if (count($val) == 3) { |
|
| 1397 | - $val[3] = $val[1]; |
|
| 1398 | - } |
|
| 1399 | - } |
|
| 1400 | - |
|
| 1401 | - /** |
|
| 1402 | - * Analyse a background |
|
| 1403 | - * |
|
| 1404 | - * @access public |
|
| 1405 | - * @param string $css css background properties |
|
| 1406 | - * @param &array $value parsed values (by reference, because, ther is a legacy of the parent CSS properties) |
|
| 1407 | - */ |
|
| 1408 | - public function convertBackground($css, &$value) |
|
| 1409 | - { |
|
| 1410 | - // is there a image ? |
|
| 1411 | - $text = '/url\(([^)]*)\)/isU'; |
|
| 1412 | - if (preg_match($text, $css, $match)) { |
|
| 1413 | - // get the image |
|
| 1414 | - $value['image'] = $this->convertBackgroundImage($match[0]); |
|
| 1415 | - |
|
| 1416 | - // remove if from the css properties |
|
| 1417 | - $css = preg_replace($text, '', $css); |
|
| 1418 | - $css = preg_replace('/[\s]+/', ' ', $css); |
|
| 1419 | - } |
|
| 1420 | - |
|
| 1421 | - // protect some spaces |
|
| 1422 | - $css = preg_replace('/,[\s]+/', ',', $css); |
|
| 1423 | - |
|
| 1424 | - // explode the values |
|
| 1425 | - $css = explode(' ', $css); |
|
| 1426 | - |
|
| 1427 | - // background position to parse |
|
| 1428 | - $pos = ''; |
|
| 1429 | - |
|
| 1430 | - // foreach value |
|
| 1431 | - foreach ($css as $val) { |
|
| 1432 | - // try to parse the value as a color |
|
| 1433 | - $ok = false; |
|
| 1434 | - $color = $this->convertToColor($val, $ok); |
|
| 1435 | - |
|
| 1436 | - // if ok => it is a color |
|
| 1437 | - if ($ok) { |
|
| 1438 | - $value['color'] = $color; |
|
| 1439 | - // else if transparent => no coloàr |
|
| 1440 | - } else if ($val == 'transparent') { |
|
| 1441 | - $value['color'] = null; |
|
| 1442 | - // else |
|
| 1443 | - } else { |
|
| 1444 | - // try to parse the value as a repeat |
|
| 1445 | - $repeat = $this->convertBackgroundRepeat($val); |
|
| 1446 | - |
|
| 1447 | - // if ok => it is repeat |
|
| 1448 | - if ($repeat) { |
|
| 1449 | - $value['repeat'] = $repeat; |
|
| 1450 | - // else => it could only be a position |
|
| 1451 | - } else { |
|
| 1452 | - $pos .= ($pos ? ' ' : '').$val; |
|
| 1453 | - } |
|
| 1454 | - } |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - // if we have a position to parse |
|
| 1458 | - if ($pos) { |
|
| 1459 | - // try to read it |
|
| 1460 | - $pos = $this->convertBackgroundPosition($pos, $ok); |
|
| 1461 | - if ($ok) { |
|
| 1462 | - $value['position'] = $pos; |
|
| 1463 | - } |
|
| 1464 | - } |
|
| 1465 | - } |
|
| 1466 | - |
|
| 1467 | - /** |
|
| 1468 | - * parse a background color |
|
| 1469 | - * |
|
| 1470 | - * @access public |
|
| 1471 | - * @param string $css |
|
| 1472 | - * @return string $value |
|
| 1473 | - */ |
|
| 1474 | - public function convertBackgroundColor($css) |
|
| 1475 | - { |
|
| 1476 | - $res = null; |
|
| 1477 | - if ($css == 'transparent') return null; |
|
| 1478 | - else return $this->convertToColor($css, $res); |
|
| 1479 | - } |
|
| 1480 | - |
|
| 1481 | - /** |
|
| 1482 | - * parse a background image |
|
| 1483 | - * |
|
| 1484 | - * @access public |
|
| 1485 | - * @param string $css |
|
| 1486 | - * @return string $value |
|
| 1487 | - */ |
|
| 1488 | - public function convertBackgroundImage($css) |
|
| 1489 | - { |
|
| 1490 | - if ($css == 'none') |
|
| 1491 | - return null; |
|
| 1492 | - else if (preg_match('/^url\(([^)]*)\)$/isU', $css, $match)) |
|
| 1493 | - return $match[1]; |
|
| 1494 | - else |
|
| 1495 | - return null; |
|
| 1496 | - } |
|
| 1497 | - |
|
| 1498 | - /** |
|
| 1499 | - * parse a background position |
|
| 1500 | - * |
|
| 1501 | - * @access public |
|
| 1502 | - * @param string $css |
|
| 1503 | - * @param &boolean $res flag if conver is ok or not |
|
| 1504 | - * @return array ($x, $y) |
|
| 1505 | - */ |
|
| 1506 | - public function convertBackgroundPosition($css, &$res) |
|
| 1507 | - { |
|
| 1508 | - // init the res |
|
| 1509 | - $res = false; |
|
| 1510 | - |
|
| 1511 | - // explode the value |
|
| 1512 | - $css = explode(' ', $css); |
|
| 1513 | - |
|
| 1514 | - // we must have 2 values. if 0 or >2 : error. if 1 => put center for 2 |
|
| 1515 | - if (count($css) < 2) { |
|
| 1516 | - if ( ! $css[0]) return null; |
|
| 1517 | - $css[1] = 'center'; |
|
| 1518 | - } |
|
| 1519 | - if (count($css) > 2) return null; |
|
| 1520 | - |
|
| 1521 | - // prepare the values |
|
| 1522 | - $x = 0; |
|
| 1523 | - $y = 0; |
|
| 1524 | - $res = true; |
|
| 1525 | - |
|
| 1526 | - // convert the first value |
|
| 1527 | - if ($css[0] == 'left') $x = '0%'; |
|
| 1528 | - else if ($css[0] == 'center') $x = '50%'; |
|
| 1529 | - else if ($css[0] == 'right') $x = '100%'; |
|
| 1530 | - else if ($css[0] == 'top') $y = '0%'; |
|
| 1531 | - else if ($css[0] == 'bottom') $y = '100%'; |
|
| 1532 | - else if (preg_match('/^[-]?[0-9\.]+%$/isU', $css[0])) $x = $css[0]; |
|
| 1533 | - else if ($this->convertToMM($css[0])) $x = $this->convertToMM($css[0]); |
|
| 1534 | - else $res = false; |
|
| 1535 | - |
|
| 1536 | - // convert the second value |
|
| 1537 | - if ($css[1] == 'left') $x = '0%'; |
|
| 1538 | - else if ($css[1] == 'right') $x = '100%'; |
|
| 1539 | - else if ($css[1] == 'top') $y = '0%'; |
|
| 1540 | - else if ($css[1] == 'center') $y = '50%'; |
|
| 1541 | - else if ($css[1] == 'bottom') $y = '100%'; |
|
| 1542 | - else if (preg_match('/^[-]?[0-9\.]+%$/isU', $css[1])) $y = $css[1]; |
|
| 1543 | - else if ($this->convertToMM($css[1])) $y = $this->convertToMM($css[1]); |
|
| 1544 | - else $res = false; |
|
| 1545 | - |
|
| 1546 | - // return the values |
|
| 1547 | - return array($x, $y); |
|
| 1548 | - } |
|
| 1549 | - |
|
| 1550 | - /** |
|
| 1551 | - * parse a background repeat |
|
| 1552 | - * |
|
| 1553 | - * @access public |
|
| 1554 | - * @param string $css |
|
| 1555 | - * @return string $value |
|
| 1556 | - */ |
|
| 1557 | - public function convertBackgroundRepeat($css) |
|
| 1558 | - { |
|
| 1559 | - switch ($css) |
|
| 1560 | - { |
|
| 1561 | - case 'repeat': |
|
| 1562 | - return array(true, true); |
|
| 1563 | - case 'repeat-x': |
|
| 1564 | - return array(true, false); |
|
| 1565 | - case 'repeat-y': |
|
| 1566 | - return array(false, true); |
|
| 1567 | - case 'no-repeat': |
|
| 1568 | - return array(false, false); |
|
| 1569 | - } |
|
| 1570 | - return null; |
|
| 1571 | - } |
|
| 1572 | - |
|
| 1573 | - /** |
|
| 1574 | - * convert a distance to mm |
|
| 1575 | - * |
|
| 1576 | - * @access public |
|
| 1577 | - * @param string $css distance to convert |
|
| 1578 | - * @param float $old parent distance |
|
| 1579 | - * @return float $value |
|
| 1580 | - */ |
|
| 1581 | - public function convertToMM($css, $old = 0.) |
|
| 1582 | - { |
|
| 1583 | - $css = trim($css); |
|
| 1584 | - if (preg_match('/^[0-9\.\-]+$/isU', $css)) $css .= 'px'; |
|
| 1585 | - if (preg_match('/^[0-9\.\-]+px$/isU', $css)) $css = 25.4 / 96. * str_replace('px', '', $css); |
|
| 1586 | - else if (preg_match('/^[0-9\.\-]+pt$/isU', $css)) $css = 25.4 / 72. * str_replace('pt', '', $css); |
|
| 1587 | - else if (preg_match('/^[0-9\.\-]+in$/isU', $css)) $css = 25.4 * str_replace('in', '', $css); |
|
| 1588 | - else if (preg_match('/^[0-9\.\-]+mm$/isU', $css)) $css = 1. * str_replace('mm', '', $css); |
|
| 1589 | - else if (preg_match('/^[0-9\.\-]+%$/isU', $css)) $css = 1. * $old * str_replace('%', '', $css) / 100.; |
|
| 1590 | - else $css = null; |
|
| 1591 | - |
|
| 1592 | - return $css; |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - /** |
|
| 1596 | - * convert a css radius |
|
| 1597 | - * |
|
| 1598 | - * @access public |
|
| 1599 | - * @param string $css |
|
| 1600 | - * @return float $value |
|
| 1601 | - */ |
|
| 1602 | - public function convertToRadius($css) |
|
| 1603 | - { |
|
| 1604 | - // explode the value |
|
| 1605 | - $css = explode(' ', $css); |
|
| 1606 | - |
|
| 1607 | - foreach ($css as $k => $v) { |
|
| 1608 | - $v = trim($v); |
|
| 1609 | - if ($v) { |
|
| 1610 | - $v = $this->convertToMM($v, 0); |
|
| 1611 | - if ($v !== null) { |
|
| 1612 | - $css[$k] = $v; |
|
| 1613 | - } else { |
|
| 1614 | - unset($css[$k]); |
|
| 1615 | - } |
|
| 1616 | - } else { |
|
| 1617 | - unset($css[$k]); |
|
| 1618 | - } |
|
| 1619 | - } |
|
| 1620 | - |
|
| 1621 | - return array_values($css); |
|
| 1622 | - } |
|
| 1623 | - |
|
| 1624 | - /** |
|
| 1625 | - * convert a css color |
|
| 1626 | - * |
|
| 1627 | - * @access public |
|
| 1628 | - * @param string $css |
|
| 1629 | - * @param &boolean $res |
|
| 1630 | - * @return array (r,g, b) |
|
| 1631 | - */ |
|
| 1632 | - public function convertToColor($css, &$res) |
|
| 1633 | - { |
|
| 1634 | - // prepare the value |
|
| 1635 | - $css = trim($css); |
|
| 1636 | - $res = true; |
|
| 1637 | - |
|
| 1638 | - // if transparent => return null |
|
| 1639 | - if (strtolower($css) == 'transparent') return array(null, null, null); |
|
| 1640 | - |
|
| 1641 | - // HTML color |
|
| 1642 | - if (isset($this->_htmlColor[strtolower($css)])) { |
|
| 1643 | - $css = $this->_htmlColor[strtolower($css)]; |
|
| 1644 | - $r = floatVal(hexdec(substr($css, 0, 2))); |
|
| 1645 | - $v = floatVal(hexdec(substr($css, 2, 2))); |
|
| 1646 | - $b = floatVal(hexdec(substr($css, 4, 2))); |
|
| 1647 | - return array($r, $v, $b); |
|
| 1648 | - } |
|
| 1649 | - |
|
| 1650 | - // like #FFFFFF |
|
| 1651 | - if (preg_match('/^#[0-9A-Fa-f]{6}$/isU', $css)) { |
|
| 1652 | - $r = floatVal(hexdec(substr($css, 1, 2))); |
|
| 1653 | - $v = floatVal(hexdec(substr($css, 3, 2))); |
|
| 1654 | - $b = floatVal(hexdec(substr($css, 5, 2))); |
|
| 1655 | - return array($r, $v, $b); |
|
| 1656 | - } |
|
| 1657 | - |
|
| 1658 | - // like #FFF |
|
| 1659 | - if (preg_match('/^#[0-9A-F]{3}$/isU', $css)) { |
|
| 1660 | - $r = floatVal(hexdec(substr($css, 1, 1).substr($css, 1, 1))); |
|
| 1661 | - $v = floatVal(hexdec(substr($css, 2, 1).substr($css, 2, 1))); |
|
| 1662 | - $b = floatVal(hexdec(substr($css, 3, 1).substr($css, 3, 1))); |
|
| 1663 | - return array($r, $v, $b); |
|
| 1664 | - } |
|
| 1665 | - |
|
| 1666 | - // like rgb(100, 100, 100) |
|
| 1667 | - if (preg_match('/rgb\([\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*\)/isU', $css, $match)) { |
|
| 1668 | - $r = $this->_convertSubColor($match[1]); |
|
| 1669 | - $v = $this->_convertSubColor($match[2]); |
|
| 1670 | - $b = $this->_convertSubColor($match[3]); |
|
| 1671 | - return array($r * 255., $v * 255., $b * 255.); |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - // like cmyk(100, 100, 100, 100) |
|
| 1675 | - if (preg_match('/cmyk\([\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*\)/isU', $css, $match)) { |
|
| 1676 | - $c = $this->_convertSubColor($match[1]); |
|
| 1677 | - $m = $this->_convertSubColor($match[2]); |
|
| 1678 | - $y = $this->_convertSubColor($match[3]); |
|
| 1679 | - $k = $this->_convertSubColor($match[4]); |
|
| 1680 | - return array($c * 100., $m * 100., $y * 100., $k * 100.); |
|
| 1681 | - } |
|
| 1682 | - |
|
| 1683 | - $res = false; |
|
| 1684 | - return array(0., 0., 0.); |
|
| 1685 | - } |
|
| 1686 | - |
|
| 1687 | - /** |
|
| 1688 | - * color value to convert |
|
| 1689 | - * |
|
| 1690 | - * @access protected |
|
| 1691 | - * @param string $c |
|
| 1692 | - * @return float $c 0.->1. |
|
| 1693 | - */ |
|
| 1694 | - protected function _convertSubColor($c) |
|
| 1695 | - { |
|
| 1696 | - if (substr($c, -1) == '%') { |
|
| 1697 | - $c = floatVal(substr($c, 0, -1)) / 100.; |
|
| 1698 | - } else { |
|
| 1699 | - $c = floatVal($c); |
|
| 1700 | - if ($c > 1) $c = $c / 255.; |
|
| 1701 | - } |
|
| 1702 | - |
|
| 1703 | - return $c; |
|
| 1704 | - } |
|
| 1705 | - |
|
| 1706 | - /** |
|
| 1707 | - * read a css content |
|
| 1708 | - * |
|
| 1709 | - * @access protected |
|
| 1710 | - * @param string $code |
|
| 1711 | - */ |
|
| 1712 | - protected function _analyseStyle(&$code) |
|
| 1713 | - { |
|
| 1714 | - // clean the spaces |
|
| 1715 | - $code = preg_replace('/[\s]+/', ' ', $code); |
|
| 1716 | - |
|
| 1717 | - // remove the comments |
|
| 1718 | - $code = preg_replace('/\/\*.*?\*\//s', '', $code); |
|
| 1719 | - |
|
| 1720 | - // split each CSS code "selector { value }" |
|
| 1721 | - preg_match_all('/([^{}]+){([^}]*)}/isU', $code, $match); |
|
| 1722 | - |
|
| 1723 | - // for each CSS code |
|
| 1724 | - for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1725 | - |
|
| 1726 | - // selectors |
|
| 1727 | - $names = strtolower(trim($match[1][$k])); |
|
| 1728 | - |
|
| 1729 | - // css style |
|
| 1730 | - $styles = trim($match[2][$k]); |
|
| 1731 | - |
|
| 1732 | - // explode each value |
|
| 1733 | - $styles = explode(';', $styles); |
|
| 1734 | - |
|
| 1735 | - // parse each value |
|
| 1736 | - $css = array(); |
|
| 1737 | - foreach ($styles as $style) { |
|
| 1738 | - $tmp = explode(':', $style); |
|
| 1739 | - if (count($tmp) > 1) { |
|
| 1740 | - $cod = $tmp[0]; unset($tmp[0]); $tmp = implode(':', $tmp); |
|
| 1741 | - $css[trim(strtolower($cod))] = trim($tmp); |
|
| 1742 | - } |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - // explode the names |
|
| 1746 | - $names = explode(',', $names); |
|
| 1747 | - |
|
| 1748 | - // save the values for each names |
|
| 1749 | - foreach ($names as $name) { |
|
| 1750 | - // clean the name |
|
| 1751 | - $name = trim($name); |
|
| 1752 | - |
|
| 1753 | - // if a selector with somethink lige :hover => continue |
|
| 1754 | - if (strpos($name, ':') !== false) continue; |
|
| 1755 | - |
|
| 1756 | - // save the value |
|
| 1757 | - if ( ! isset($this->css[$name])) |
|
| 1758 | - $this->css[$name] = $css; |
|
| 1759 | - else |
|
| 1760 | - $this->css[$name] = array_merge($this->css[$name], $css); |
|
| 1761 | - |
|
| 1762 | - } |
|
| 1763 | - } |
|
| 1764 | - |
|
| 1765 | - // get he list of the keys |
|
| 1766 | - $this->cssKeys = array_flip(array_keys($this->css)); |
|
| 1767 | - } |
|
| 1768 | - |
|
| 1769 | - /** |
|
| 1770 | - * Extract the css files from a html code |
|
| 1771 | - * |
|
| 1772 | - * @access public |
|
| 1773 | - * @param string &$html |
|
| 1774 | - * @param string $html |
|
| 1775 | - */ |
|
| 1776 | - public function readStyle(&$html) |
|
| 1777 | - { |
|
| 1778 | - // the CSS content |
|
| 1779 | - $style = ' '; |
|
| 1780 | - |
|
| 1781 | - // extract the link tags, and remove them in the html code |
|
| 1782 | - preg_match_all('/<link([^>]*)>/isU', $html, $match); |
|
| 1783 | - $html = preg_replace('/<link[^>]*>/isU', '', $html); |
|
| 1784 | - $html = preg_replace('/<\/link[^>]*>/isU', '', $html); |
|
| 1785 | - |
|
| 1786 | - // analyse each link tag |
|
| 1787 | - foreach ($match[1] as $code) { |
|
| 1788 | - $tmp = array(); |
|
| 1789 | - |
|
| 1790 | - // read the attributes name=value |
|
| 1791 | - $prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)'; |
|
| 1792 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 1793 | - for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1794 | - $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 1795 | - } |
|
| 1796 | - |
|
| 1797 | - // read the attributes name="value" |
|
| 1798 | - $prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]'; |
|
| 1799 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 1800 | - for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1801 | - $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 1802 | - } |
|
| 1803 | - |
|
| 1804 | - // read the attributes name='value' |
|
| 1805 | - $prop = "([a-zA-Z0-9_]+)=[']([^']*)[']"; |
|
| 1806 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 1807 | - for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1808 | - $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 1809 | - } |
|
| 1810 | - |
|
| 1811 | - // if type text/css => we keep it |
|
| 1812 | - if (isset($tmp['type']) && strtolower($tmp['type']) == 'text/css' && isset($tmp['href'])) { |
|
| 1813 | - |
|
| 1814 | - // get the href |
|
| 1815 | - $url = $tmp['href']; |
|
| 1816 | - |
|
| 1817 | - // get the content of the css file |
|
| 1818 | - $content = @file_get_contents($url); |
|
| 1819 | - |
|
| 1820 | - // if "http://" in the url |
|
| 1821 | - if (strpos($url, 'http://') !== false) { |
|
| 1822 | - |
|
| 1823 | - // get the domain "http://xxx/" |
|
| 1824 | - $url = str_replace('http://', '', $url); |
|
| 1825 | - $url = explode('/', $url); |
|
| 1826 | - $urlMain = 'http://'.$url[0].'/'; |
|
| 1827 | - |
|
| 1828 | - // get the absolute url of the path |
|
| 1829 | - $urlSelf = $url; unset($urlSelf[count($urlSelf) - 1]); $urlSelf = 'http://'.implode('/', $urlSelf).'/'; |
|
| 1830 | - |
|
| 1831 | - // adapt the url in the css content |
|
| 1832 | - $content = preg_replace('/url\(([^\\\\][^)]*)\)/isU', 'url('.$urlSelf.'$1)', $content); |
|
| 1833 | - $content = preg_replace('/url\((\\\\[^)]*)\)/isU', 'url('.$urlMain.'$1)', $content); |
|
| 1834 | - } else { |
|
| 14 | + /** |
|
| 15 | + * reference to the pdf object |
|
| 16 | + * @var TCPDF |
|
| 17 | + */ |
|
| 18 | + protected $_pdf = null; |
|
| 19 | + |
|
| 20 | + protected $_htmlColor = array(); // list of the HTML colors |
|
| 21 | + protected $_onlyLeft = false; // flag if we are in a sub html => only "text-align:left" is used |
|
| 22 | + protected $_defaultFont = null; // default font to use if the asked font does not exist |
|
| 23 | + |
|
| 24 | + public $value = array(); // current values |
|
| 25 | + public $css = array(); // css values |
|
| 26 | + public $cssKeys = array(); // css key, for the execution order |
|
| 27 | + public $table = array(); // level history |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Constructor |
|
| 31 | + * |
|
| 32 | + * @param &HTML2PDF_myPdf reference to the PDF $object |
|
| 33 | + * @param HTML2PDF_myPdf $pdf |
|
| 34 | + * @access public |
|
| 35 | + */ |
|
| 36 | + public function __construct(&$pdf) |
|
| 37 | + { |
|
| 38 | + $this->_init(); |
|
| 39 | + $this->setPdfParent($pdf); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Set the HTML2PDF parent object |
|
| 44 | + * |
|
| 45 | + * @param &HTML2PDF reference to the HTML2PDF parent $object |
|
| 46 | + * @access public |
|
| 47 | + */ |
|
| 48 | + public function setPdfParent(&$pdf) |
|
| 49 | + { |
|
| 50 | + $this->_pdf = &$pdf; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Inform that we want only "test-align:left" because we are in a sub HTML |
|
| 55 | + * |
|
| 56 | + * @access public |
|
| 57 | + */ |
|
| 58 | + public function setOnlyLeft() |
|
| 59 | + { |
|
| 60 | + $this->value['text-align'] = 'left'; |
|
| 61 | + $this->_onlyLeft = true; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Get the vales of the parent, if exist |
|
| 66 | + * |
|
| 67 | + * @return array CSS values |
|
| 68 | + * @access public |
|
| 69 | + */ |
|
| 70 | + public function getOldValues() |
|
| 71 | + { |
|
| 72 | + return isset($this->table[count($this->table) - 1]) ? $this->table[count($this->table) - 1] : $this->value; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * define the Default Font to use, if the font does not exist, or if no font asked |
|
| 77 | + * |
|
| 78 | + * @param string default font-family. If null : Arial for no font asked, and error fot ont does not exist |
|
| 79 | + * @param string $default |
|
| 80 | + * @return string old default font-family |
|
| 81 | + * @access public |
|
| 82 | + */ |
|
| 83 | + public function setDefaultFont($default = null) |
|
| 84 | + { |
|
| 85 | + $old = $this->_defaultFont; |
|
| 86 | + $this->_defaultFont = $default; |
|
| 87 | + if ($default) { |
|
| 88 | + $this->value['font-family'] = $default; |
|
| 89 | + } |
|
| 90 | + return $old; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Init the object |
|
| 95 | + * |
|
| 96 | + * @access protected |
|
| 97 | + */ |
|
| 98 | + protected function _init() |
|
| 99 | + { |
|
| 100 | + // get the Web Colors from TCPDF |
|
| 101 | + require(K_PATH_MAIN.'htmlcolors.php'); |
|
| 102 | + $this->_htmlColor = $webcolor; |
|
| 103 | + |
|
| 104 | + // init the Style |
|
| 105 | + $this->table = array(); |
|
| 106 | + $this->value = array(); |
|
| 107 | + $this->initStyle(); |
|
| 108 | + |
|
| 109 | + // Init the styles without legacy |
|
| 110 | + $this->resetStyle(); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Init the CSS Style |
|
| 115 | + * |
|
| 116 | + * @access public |
|
| 117 | + */ |
|
| 118 | + public function initStyle() |
|
| 119 | + { |
|
| 120 | + $this->value['id_tag'] = 'body'; // tag name |
|
| 121 | + $this->value['id_name'] = null; // tag - attribute name |
|
| 122 | + $this->value['id_id'] = null; // tag - attribute id |
|
| 123 | + $this->value['id_class'] = null; // tag - attribute class |
|
| 124 | + $this->value['id_lst'] = array('*'); // tag - list of legacy |
|
| 125 | + $this->value['mini-size'] = 1.; // specific size report for sup, sub |
|
| 126 | + $this->value['mini-decal'] = 0; // specific position report for sup, sub |
|
| 127 | + $this->value['font-family'] = 'Arial'; |
|
| 128 | + $this->value['font-bold'] = false; |
|
| 129 | + $this->value['font-italic'] = false; |
|
| 130 | + $this->value['font-underline'] = false; |
|
| 131 | + $this->value['font-overline'] = false; |
|
| 132 | + $this->value['font-linethrough'] = false; |
|
| 133 | + $this->value['text-transform'] = 'none'; |
|
| 134 | + $this->value['font-size'] = $this->convertToMM('10pt'); |
|
| 135 | + $this->value['text-indent'] = 0; |
|
| 136 | + $this->value['text-align'] = 'left'; |
|
| 137 | + $this->value['vertical-align'] = 'middle'; |
|
| 138 | + $this->value['line-height'] = 'normal'; |
|
| 139 | + |
|
| 140 | + $this->value['position'] = null; |
|
| 141 | + $this->value['x'] = null; |
|
| 142 | + $this->value['y'] = null; |
|
| 143 | + $this->value['width'] = 0; |
|
| 144 | + $this->value['height'] = 0; |
|
| 145 | + $this->value['top'] = null; |
|
| 146 | + $this->value['right'] = null; |
|
| 147 | + $this->value['bottom'] = null; |
|
| 148 | + $this->value['left'] = null; |
|
| 149 | + $this->value['float'] = null; |
|
| 150 | + $this->value['display'] = null; |
|
| 151 | + $this->value['rotate'] = null; |
|
| 152 | + $this->value['overflow'] = 'visible'; |
|
| 153 | + |
|
| 154 | + $this->value['color'] = array(0, 0, 0); |
|
| 155 | + $this->value['background'] = array('color' => null, 'image' => null, 'position' => null, 'repeat' => null); |
|
| 156 | + $this->value['border'] = array(); |
|
| 157 | + $this->value['padding'] = array(); |
|
| 158 | + $this->value['margin'] = array(); |
|
| 159 | + $this->value['margin-auto'] = false; |
|
| 160 | + |
|
| 161 | + $this->value['list-style-type'] = ''; |
|
| 162 | + $this->value['list-style-image'] = ''; |
|
| 163 | + |
|
| 164 | + $this->value['xc'] = null; |
|
| 165 | + $this->value['yc'] = null; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Init the CSS Style without legacy |
|
| 170 | + * |
|
| 171 | + * @param string tag name |
|
| 172 | + * @access public |
|
| 173 | + */ |
|
| 174 | + public function resetStyle($tagName = '') |
|
| 175 | + { |
|
| 176 | + // prepare somme values |
|
| 177 | + $border = $this->readBorder('solid 1px #000000'); |
|
| 178 | + $units = array( |
|
| 179 | + '1px' => $this->convertToMM('1px'), |
|
| 180 | + '5px' => $this->convertToMM('5px'), |
|
| 181 | + ); |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + // prepare the Collapse attribute |
|
| 185 | + $collapse = isset($this->value['border']['collapse']) ? $this->value['border']['collapse'] : false; |
|
| 186 | + if ( ! in_array($tagName, array('tr', 'td', 'th', 'thead', 'tbody', 'tfoot'))) $collapse = false; |
|
| 187 | + |
|
| 188 | + // set the global css values |
|
| 189 | + $this->value['position'] = null; |
|
| 190 | + $this->value['x'] = null; |
|
| 191 | + $this->value['y'] = null; |
|
| 192 | + $this->value['width'] = 0; |
|
| 193 | + $this->value['height'] = 0; |
|
| 194 | + $this->value['top'] = null; |
|
| 195 | + $this->value['right'] = null; |
|
| 196 | + $this->value['bottom'] = null; |
|
| 197 | + $this->value['left'] = null; |
|
| 198 | + $this->value['float'] = null; |
|
| 199 | + $this->value['display'] = null; |
|
| 200 | + $this->value['rotate'] = null; |
|
| 201 | + $this->value['overflow'] = 'visible'; |
|
| 202 | + $this->value['background'] = array('color' => null, 'image' => null, 'position' => null, 'repeat' => null); |
|
| 203 | + $this->value['border'] = array( |
|
| 204 | + 't' => $this->readBorder('none'), |
|
| 205 | + 'r' => $this->readBorder('none'), |
|
| 206 | + 'b' => $this->readBorder('none'), |
|
| 207 | + 'l' => $this->readBorder('none'), |
|
| 208 | + 'radius' => array( |
|
| 209 | + 'tl' => array(0, 0), |
|
| 210 | + 'tr' => array(0, 0), |
|
| 211 | + 'br' => array(0, 0), |
|
| 212 | + 'bl' => array(0, 0) |
|
| 213 | + ), |
|
| 214 | + 'collapse' => $collapse, |
|
| 215 | + ); |
|
| 216 | + |
|
| 217 | + // specific values for some tags |
|
| 218 | + if ( ! in_array($tagName, array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'))) { |
|
| 219 | + $this->value['margin'] = array('t'=>0, 'r'=>0, 'b'=>0, 'l'=>0); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + if (in_array($tagName, array('input', 'select', 'textarea'))) { |
|
| 223 | + $this->value['border']['t'] = null; |
|
| 224 | + $this->value['border']['r'] = null; |
|
| 225 | + $this->value['border']['b'] = null; |
|
| 226 | + $this->value['border']['l'] = null; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + if ($tagName == 'p') { |
|
| 230 | + $this->value['margin']['t'] = null; |
|
| 231 | + $this->value['margin']['b'] = null; |
|
| 232 | + } |
|
| 233 | + if ($tagName == 'blockquote') { |
|
| 234 | + $this->value['margin']['t'] = 3; |
|
| 235 | + $this->value['margin']['r'] = 3; |
|
| 236 | + $this->value['margin']['b'] = 3; |
|
| 237 | + $this->value['margin']['l'] = 6; |
|
| 238 | + } |
|
| 239 | + $this->value['margin-auto'] = false; |
|
| 240 | + |
|
| 241 | + if (in_array($tagName, array('blockquote', 'div', 'fieldset'))) { |
|
| 242 | + $this->value['vertical-align'] = 'top'; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + if (in_array($tagName, array('fieldset', 'legend'))) { |
|
| 246 | + $this->value['border'] = array( |
|
| 247 | + 't' => $border, |
|
| 248 | + 'r' => $border, |
|
| 249 | + 'b' => $border, |
|
| 250 | + 'l' => $border, |
|
| 251 | + 'radius' => array( |
|
| 252 | + 'tl' => array($units['5px'], $units['5px']), |
|
| 253 | + 'tr' => array($units['5px'], $units['5px']), |
|
| 254 | + 'br' => array($units['5px'], $units['5px']), |
|
| 255 | + 'bl' => array($units['5px'], $units['5px']) |
|
| 256 | + ), |
|
| 257 | + 'collapse' => false, |
|
| 258 | + ); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if (in_array($tagName, array('ul', 'li'))) { |
|
| 262 | + $this->value['list-style-type'] = ''; |
|
| 263 | + $this->value['list-style-image'] = ''; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + if ( ! in_array($tagName, array('tr', 'td'))) { |
|
| 267 | + $this->value['padding'] = array( |
|
| 268 | + 't' => 0, |
|
| 269 | + 'r' => 0, |
|
| 270 | + 'b' => 0, |
|
| 271 | + 'l' => 0 |
|
| 272 | + ); |
|
| 273 | + } else { |
|
| 274 | + $this->value['padding'] = array( |
|
| 275 | + 't' => $units['1px'], |
|
| 276 | + 'r' => $units['1px'], |
|
| 277 | + 'b' => $units['1px'], |
|
| 278 | + 'l' => $units['1px'] |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + if ($tagName == 'hr') { |
|
| 283 | + $this->value['border'] = array( |
|
| 284 | + 't' => $border, |
|
| 285 | + 'r' => $border, |
|
| 286 | + 'b' => $border, |
|
| 287 | + 'l' => $border, |
|
| 288 | + 'radius' => array( |
|
| 289 | + 'tl' => array(0, 0), |
|
| 290 | + 'tr' => array(0, 0), |
|
| 291 | + 'br' => array(0, 0), |
|
| 292 | + 'bl' => array(0, 0) |
|
| 293 | + ), |
|
| 294 | + 'collapse' => false, |
|
| 295 | + ); |
|
| 296 | + $this->convertBackground('#FFFFFF', $this->value['background']); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + $this->value['xc'] = null; |
|
| 300 | + $this->value['yc'] = null; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Init the PDF Font |
|
| 305 | + * |
|
| 306 | + * @access public |
|
| 307 | + */ |
|
| 308 | + public function fontSet() |
|
| 309 | + { |
|
| 310 | + $family = strtolower($this->value['font-family']); |
|
| 311 | + |
|
| 312 | + $b = ($this->value['font-bold'] ? 'B' : ''); |
|
| 313 | + $i = ($this->value['font-italic'] ? 'I' : ''); |
|
| 314 | + $u = ($this->value['font-underline'] ? 'U' : ''); |
|
| 315 | + $d = ($this->value['font-linethrough'] ? 'D' : ''); |
|
| 316 | + $o = ($this->value['font-overline'] ? 'O' : ''); |
|
| 317 | + |
|
| 318 | + // font style |
|
| 319 | + $style = $b.$i; |
|
| 320 | + |
|
| 321 | + if ($this->_defaultFont) { |
|
| 322 | + if ($family == 'arial') |
|
| 323 | + $family = 'helvetica'; |
|
| 324 | + elseif ($family == 'symbol' || $family == 'zapfdingbats') |
|
| 325 | + $style = ''; |
|
| 326 | + |
|
| 327 | + $fontkey = $family.$style; |
|
| 328 | + if ( ! $this->_pdf->isLoadedFont($fontkey)) |
|
| 329 | + $family = $this->_defaultFont; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + if ($family == 'arial') |
|
| 333 | + $family = 'helvetica'; |
|
| 334 | + elseif ($family == 'symbol' || $family == 'zapfdingbats') |
|
| 335 | + $style = ''; |
|
| 336 | + |
|
| 337 | + // complete style |
|
| 338 | + $style .= $u.$d.$o; |
|
| 339 | + |
|
| 340 | + // size : mm => pt |
|
| 341 | + $size = $this->value['font-size']; |
|
| 342 | + $size = 72 * $size / 25.4; |
|
| 343 | + |
|
| 344 | + // apply the font |
|
| 345 | + $this->_pdf->SetFont($family, $style, $this->value['mini-size'] * $size); |
|
| 346 | + $this->_pdf->setTextColorArray($this->value['color']); |
|
| 347 | + if ($this->value['background']['color']) { |
|
| 348 | + $this->_pdf->setFillColorArray($this->value['background']['color']); |
|
| 349 | + } else { |
|
| 350 | + $this->_pdf->setFillColor(255); |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * add a level in the CSS history |
|
| 356 | + * |
|
| 357 | + * @access public |
|
| 358 | + */ |
|
| 359 | + public function save() |
|
| 360 | + { |
|
| 361 | + array_push($this->table, $this->value); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * remove a level in the CSS history |
|
| 366 | + * |
|
| 367 | + * @access public |
|
| 368 | + */ |
|
| 369 | + public function load() |
|
| 370 | + { |
|
| 371 | + if (count($this->table)) { |
|
| 372 | + $this->value = array_pop($this->table); |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * restore the Y positiony (used after a span) |
|
| 378 | + * |
|
| 379 | + * @access public |
|
| 380 | + */ |
|
| 381 | + public function restorePosition() |
|
| 382 | + { |
|
| 383 | + if ($this->value['y'] == $this->_pdf->getY()) $this->_pdf->setY($this->value['yc'], false); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * set the New position for the current Tag |
|
| 388 | + * |
|
| 389 | + * @access public |
|
| 390 | + */ |
|
| 391 | + public function setPosition() |
|
| 392 | + { |
|
| 393 | + // get the current position |
|
| 394 | + $currentX = $this->_pdf->getX(); |
|
| 395 | + $currentY = $this->_pdf->getY(); |
|
| 396 | + |
|
| 397 | + // save it |
|
| 398 | + $this->value['xc'] = $currentX; |
|
| 399 | + $this->value['yc'] = $currentY; |
|
| 400 | + |
|
| 401 | + if ($this->value['position'] == 'relative' || $this->value['position'] == 'absolute') { |
|
| 402 | + if ($this->value['right'] !== null) { |
|
| 403 | + $x = $this->getLastWidth(true) - $this->value['right'] - $this->value['width']; |
|
| 404 | + if ($this->value['margin']['r']) $x -= $this->value['margin']['r']; |
|
| 405 | + } else { |
|
| 406 | + $x = $this->value['left']; |
|
| 407 | + if ($this->value['margin']['l']) $x += $this->value['margin']['l']; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + if ($this->value['bottom'] !== null) { |
|
| 411 | + $y = $this->getLastHeight(true) - $this->value['bottom'] - $this->value['height']; |
|
| 412 | + if ($this->value['margin']['b']) $y -= $this->value['margin']['b']; |
|
| 413 | + } else { |
|
| 414 | + $y = $this->value['top']; |
|
| 415 | + if ($this->value['margin']['t']) $y += $this->value['margin']['t']; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + if ($this->value['position'] == 'relative') { |
|
| 419 | + $this->value['x'] = $currentX + $x; |
|
| 420 | + $this->value['y'] = $currentY + $y; |
|
| 421 | + } else { |
|
| 422 | + $this->value['x'] = $this->_getLastAbsoluteX() + $x; |
|
| 423 | + $this->value['y'] = $this->_getLastAbsoluteY() + $y; |
|
| 424 | + } |
|
| 425 | + } else { |
|
| 426 | + $this->value['x'] = $currentX; |
|
| 427 | + $this->value['y'] = $currentY; |
|
| 428 | + if ($this->value['margin']['l']) $this->value['x'] += $this->value['margin']['l']; |
|
| 429 | + if ($this->value['margin']['t']) $this->value['y'] += $this->value['margin']['t']; |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + // save the new position |
|
| 433 | + $this->_pdf->setXY($this->value['x'], $this->value['y']); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Analise the CSS style to convert it into Form style |
|
| 438 | + * |
|
| 439 | + * @access public |
|
| 440 | + * @param array styles |
|
| 441 | + */ |
|
| 442 | + public function getFormStyle() |
|
| 443 | + { |
|
| 444 | + $prop = array(); |
|
| 445 | + |
|
| 446 | + $prop['alignment'] = $this->value['text-align']; |
|
| 447 | + |
|
| 448 | + if (isset($this->value['background']['color']) && is_array($this->value['background']['color'])) { |
|
| 449 | + $prop['fillColor'] = $this->value['background']['color']; |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + if (isset($this->value['border']['t']['color'])) { |
|
| 453 | + $prop['strokeColor'] = $this->value['border']['t']['color']; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + if (isset($this->value['border']['t']['width'])) { |
|
| 457 | + $prop['lineWidth'] = $this->value['border']['t']['width']; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + if (isset($this->value['border']['t']['type'])) { |
|
| 461 | + $prop['borderStyle'] = $this->value['border']['t']['type']; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + if ( ! empty($this->value['color'])) { |
|
| 465 | + $prop['textColor'] = $this->value['color']; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + if ( ! empty($this->value['font-size'])) { |
|
| 469 | + $prop['textSize'] = $this->value['font-size']; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + return $prop; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Analise the CSS style to convert it into SVG style |
|
| 477 | + * |
|
| 478 | + * @access public |
|
| 479 | + * @param string tag name |
|
| 480 | + * @param array styles |
|
| 481 | + * @param string $tagName |
|
| 482 | + */ |
|
| 483 | + public function getSvgStyle($tagName, &$param) |
|
| 484 | + { |
|
| 485 | + // prepare |
|
| 486 | + $tagName = strtolower($tagName); |
|
| 487 | + $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) $id = null; |
|
| 488 | + $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if ( ! $name) $name = null; |
|
| 489 | + |
|
| 490 | + // read the class attribute |
|
| 491 | + $class = array(); |
|
| 492 | + $tmp = isset($param['class']) ? strtolower(trim($param['class'])) : ''; |
|
| 493 | + $tmp = explode(' ', $tmp); |
|
| 494 | + foreach ($tmp as $k => $v) { |
|
| 495 | + $v = trim($v); |
|
| 496 | + if ($v) { |
|
| 497 | + $class[] = $v; |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + // identify the tag, and the direct styles |
|
| 502 | + $this->value['id_tag'] = $tagName; |
|
| 503 | + $this->value['id_name'] = $name; |
|
| 504 | + $this->value['id_id'] = $id; |
|
| 505 | + $this->value['id_class'] = $class; |
|
| 506 | + $this->value['id_lst'] = array(); |
|
| 507 | + $this->value['id_lst'][] = '*'; |
|
| 508 | + $this->value['id_lst'][] = $tagName; |
|
| 509 | + if ( ! isset($this->value['svg'])) { |
|
| 510 | + $this->value['svg'] = array( |
|
| 511 | + 'stroke' => null, |
|
| 512 | + 'stroke-width' => $this->convertToMM('1pt'), |
|
| 513 | + 'fill' => null, |
|
| 514 | + 'fill-opacity' => null, |
|
| 515 | + ); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + if (count($class)) { |
|
| 519 | + foreach ($class as $v) { |
|
| 520 | + $this->value['id_lst'][] = '*.'.$v; |
|
| 521 | + $this->value['id_lst'][] = '.'.$v; |
|
| 522 | + $this->value['id_lst'][] = $tagName.'.'.$v; |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + if ($id) { |
|
| 526 | + $this->value['id_lst'][] = '*#'.$id; |
|
| 527 | + $this->value['id_lst'][] = '#'.$id; |
|
| 528 | + $this->value['id_lst'][] = $tagName.'#'.$id; |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + // CSS style |
|
| 532 | + $styles = $this->_getFromCSS(); |
|
| 533 | + |
|
| 534 | + // adding the style from the tag |
|
| 535 | + $styles = array_merge($styles, $param['style']); |
|
| 536 | + |
|
| 537 | + if (isset($styles['stroke'])) $this->value['svg']['stroke'] = $this->convertToColor($styles['stroke'], $res); |
|
| 538 | + if (isset($styles['stroke-width'])) $this->value['svg']['stroke-width'] = $this->convertToMM($styles['stroke-width']); |
|
| 539 | + if (isset($styles['fill'])) $this->value['svg']['fill'] = $this->convertToColor($styles['fill'], $res); |
|
| 540 | + if (isset($styles['fill-opacity'])) $this->value['svg']['fill-opacity'] = 1. * $styles['fill-opacity']; |
|
| 541 | + |
|
| 542 | + return $this->value['svg']; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * analyse the css properties from the HTML parsing |
|
| 547 | + * |
|
| 548 | + * @access public |
|
| 549 | + * @param string $tagName |
|
| 550 | + * @param array $param |
|
| 551 | + * @param array $legacy |
|
| 552 | + */ |
|
| 553 | + public function analyse($tagName, &$param, $legacy = null) |
|
| 554 | + { |
|
| 555 | + // prepare the informations |
|
| 556 | + $tagName = strtolower($tagName); |
|
| 557 | + $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) $id = null; |
|
| 558 | + $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if ( ! $name) $name = null; |
|
| 559 | + |
|
| 560 | + // get the class names to use |
|
| 561 | + $class = array(); |
|
| 562 | + $tmp = isset($param['class']) ? strtolower(trim($param['class'])) : ''; |
|
| 563 | + $tmp = explode(' ', $tmp); |
|
| 564 | + foreach ($tmp as $k => $v) { |
|
| 565 | + $v = trim($v); |
|
| 566 | + if ($v) { |
|
| 567 | + $class[] = $v; |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + // prepare the values, and the list of css tags to identify |
|
| 572 | + $this->value['id_tag'] = $tagName; |
|
| 573 | + $this->value['id_name'] = $name; |
|
| 574 | + $this->value['id_id'] = $id; |
|
| 575 | + $this->value['id_class'] = $class; |
|
| 576 | + $this->value['id_lst'] = array(); |
|
| 577 | + $this->value['id_lst'][] = '*'; |
|
| 578 | + $this->value['id_lst'][] = $tagName; |
|
| 579 | + if (count($class)) { |
|
| 580 | + foreach ($class as $v) { |
|
| 581 | + $this->value['id_lst'][] = '*.'.$v; |
|
| 582 | + $this->value['id_lst'][] = '.'.$v; |
|
| 583 | + $this->value['id_lst'][] = $tagName.'.'.$v; |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + if ($id) { |
|
| 587 | + $this->value['id_lst'][] = '*#'.$id; |
|
| 588 | + $this->value['id_lst'][] = '#'.$id; |
|
| 589 | + $this->value['id_lst'][] = $tagName.'#'.$id; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + // get the css styles from class |
|
| 593 | + $styles = $this->_getFromCSS(); |
|
| 594 | + |
|
| 595 | + // merge with the css styles from tag |
|
| 596 | + $styles = array_merge($styles, $param['style']); |
|
| 597 | + if (isset($param['allwidth']) && ! isset($styles['width'])) $styles['width'] = '100%'; |
|
| 598 | + |
|
| 599 | + // reset some styles, depending on the tag name |
|
| 600 | + $this->resetStyle($tagName); |
|
| 601 | + |
|
| 602 | + // add the legacy values |
|
| 603 | + if ($legacy) { |
|
| 604 | + foreach ($legacy as $legacyName => $legacyValue) { |
|
| 605 | + if (is_array($legacyValue)) { |
|
| 606 | + foreach ($legacyValue as $legacy2Name => $legacy2Value) |
|
| 607 | + $this->value[$legacyName][$legacy2Name] = $legacy2Value; |
|
| 608 | + } else { |
|
| 609 | + $this->value[$legacyName] = $legacyValue; |
|
| 610 | + } |
|
| 611 | + } |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + // some flags |
|
| 615 | + $correctWidth = false; |
|
| 616 | + $noWidth = true; |
|
| 617 | + |
|
| 618 | + // read all the css styles |
|
| 619 | + foreach ($styles as $nom => $val) { |
|
| 620 | + switch ($nom) |
|
| 621 | + { |
|
| 622 | + case 'font-family': |
|
| 623 | + $val = explode(',', $val); |
|
| 624 | + $val = trim($val[0]); |
|
| 625 | + if ($val) { |
|
| 626 | + $this->value['font-family'] = $val; |
|
| 627 | + } |
|
| 628 | + break; |
|
| 629 | + |
|
| 630 | + case 'font-weight': |
|
| 631 | + $this->value['font-bold'] = ($val == 'bold'); |
|
| 632 | + break; |
|
| 633 | + |
|
| 634 | + case 'font-style': |
|
| 635 | + $this->value['font-italic'] = ($val == 'italic'); |
|
| 636 | + break; |
|
| 637 | + |
|
| 638 | + case 'text-decoration': |
|
| 639 | + $val = explode(' ', $val); |
|
| 640 | + $this->value['font-underline'] = (in_array('underline', $val)); |
|
| 641 | + $this->value['font-overline'] = (in_array('overline', $val)); |
|
| 642 | + $this->value['font-linethrough'] = (in_array('line-through', $val)); |
|
| 643 | + break; |
|
| 644 | + |
|
| 645 | + case 'text-indent': |
|
| 646 | + $this->value['text-indent'] = $this->convertToMM($val); |
|
| 647 | + break; |
|
| 648 | + |
|
| 649 | + case 'text-transform': |
|
| 650 | + if ( ! in_array($val, array('none', 'capitalize', 'uppercase', 'lowercase'))) $val = 'none'; |
|
| 651 | + $this->value['text-transform'] = $val; |
|
| 652 | + break; |
|
| 653 | + |
|
| 654 | + case 'font-size': |
|
| 655 | + $val = $this->convertToMM($val, $this->value['font-size']); |
|
| 656 | + if ($val) $this->value['font-size'] = $val; |
|
| 657 | + break; |
|
| 658 | + |
|
| 659 | + case 'color': |
|
| 660 | + $res = null; |
|
| 661 | + $this->value['color'] = $this->convertToColor($val, $res); |
|
| 662 | + if ($tagName == 'hr') { |
|
| 663 | + $this->value['border']['l']['color'] = $this->value['color']; |
|
| 664 | + $this->value['border']['t']['color'] = $this->value['color']; |
|
| 665 | + $this->value['border']['r']['color'] = $this->value['color']; |
|
| 666 | + $this->value['border']['b']['color'] = $this->value['color']; |
|
| 667 | + } |
|
| 668 | + break; |
|
| 669 | + |
|
| 670 | + case 'text-align': |
|
| 671 | + $val = strtolower($val); |
|
| 672 | + if ( ! in_array($val, array('left', 'right', 'center', 'justify', 'li_right'))) $val = 'left'; |
|
| 673 | + $this->value['text-align'] = $val; |
|
| 674 | + break; |
|
| 675 | + |
|
| 676 | + case 'vertical-align': |
|
| 677 | + $this->value['vertical-align'] = $val; |
|
| 678 | + break; |
|
| 679 | + |
|
| 680 | + case 'width': |
|
| 681 | + $this->value['width'] = $this->convertToMM($val, $this->getLastWidth()); |
|
| 682 | + if ($this->value['width'] && substr($val, -1) == '%') $correctWidth = true; |
|
| 683 | + $noWidth = false; |
|
| 684 | + break; |
|
| 685 | + |
|
| 686 | + case 'height': |
|
| 687 | + $this->value['height'] = $this->convertToMM($val, $this->getLastHeight()); |
|
| 688 | + break; |
|
| 689 | + |
|
| 690 | + case 'line-height': |
|
| 691 | + if (preg_match('/^[0-9\.]+$/isU', $val)) $val = floor($val * 100).'%'; |
|
| 692 | + $this->value['line-height'] = $val; |
|
| 693 | + break; |
|
| 694 | + |
|
| 695 | + case 'rotate': |
|
| 696 | + if ( ! in_array($val, array(0, -90, 90, 180, 270, -180, -270))) $val = null; |
|
| 697 | + if ($val < 0) $val += 360; |
|
| 698 | + $this->value['rotate'] = $val; |
|
| 699 | + break; |
|
| 700 | + |
|
| 701 | + case 'overflow': |
|
| 702 | + if ( ! in_array($val, array('visible', 'hidden'))) $val = 'visible'; |
|
| 703 | + $this->value['overflow'] = $val; |
|
| 704 | + break; |
|
| 705 | + |
|
| 706 | + case 'padding': |
|
| 707 | + $val = explode(' ', $val); |
|
| 708 | + foreach ($val as $k => $v) { |
|
| 709 | + $v = trim($v); |
|
| 710 | + if ($v != '') { |
|
| 711 | + $val[$k] = $v; |
|
| 712 | + } else { |
|
| 713 | + unset($val[$k]); |
|
| 714 | + } |
|
| 715 | + } |
|
| 716 | + $val = array_values($val); |
|
| 717 | + $this->_duplicateBorder($val); |
|
| 718 | + $this->value['padding']['t'] = $this->convertToMM($val[0], 0); |
|
| 719 | + $this->value['padding']['r'] = $this->convertToMM($val[1], 0); |
|
| 720 | + $this->value['padding']['b'] = $this->convertToMM($val[2], 0); |
|
| 721 | + $this->value['padding']['l'] = $this->convertToMM($val[3], 0); |
|
| 722 | + break; |
|
| 723 | + |
|
| 724 | + case 'padding-top': |
|
| 725 | + $this->value['padding']['t'] = $this->convertToMM($val, 0); |
|
| 726 | + break; |
|
| 727 | + |
|
| 728 | + case 'padding-right': |
|
| 729 | + $this->value['padding']['r'] = $this->convertToMM($val, 0); |
|
| 730 | + break; |
|
| 731 | + |
|
| 732 | + case 'padding-bottom': |
|
| 733 | + $this->value['padding']['b'] = $this->convertToMM($val, 0); |
|
| 734 | + break; |
|
| 735 | + |
|
| 736 | + case 'padding-left': |
|
| 737 | + $this->value['padding']['l'] = $this->convertToMM($val, 0); |
|
| 738 | + break; |
|
| 739 | + |
|
| 740 | + case 'margin': |
|
| 741 | + if ($val == 'auto') { |
|
| 742 | + $this->value['margin-auto'] = true; |
|
| 743 | + break; |
|
| 744 | + } |
|
| 745 | + $val = explode(' ', $val); |
|
| 746 | + foreach ($val as $k => $v) { |
|
| 747 | + $v = trim($v); |
|
| 748 | + if ($v != '') { |
|
| 749 | + $val[$k] = $v; |
|
| 750 | + } else { |
|
| 751 | + unset($val[$k]); |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | + $val = array_values($val); |
|
| 755 | + $this->_duplicateBorder($val); |
|
| 756 | + $this->value['margin']['t'] = $this->convertToMM($val[0], 0); |
|
| 757 | + $this->value['margin']['r'] = $this->convertToMM($val[1], 0); |
|
| 758 | + $this->value['margin']['b'] = $this->convertToMM($val[2], 0); |
|
| 759 | + $this->value['margin']['l'] = $this->convertToMM($val[3], 0); |
|
| 760 | + break; |
|
| 761 | + |
|
| 762 | + case 'margin-top': |
|
| 763 | + $this->value['margin']['t'] = $this->convertToMM($val, 0); |
|
| 764 | + break; |
|
| 765 | + |
|
| 766 | + case 'margin-right': |
|
| 767 | + $this->value['margin']['r'] = $this->convertToMM($val, 0); |
|
| 768 | + break; |
|
| 769 | + |
|
| 770 | + case 'margin-bottom': |
|
| 771 | + $this->value['margin']['b'] = $this->convertToMM($val, 0); |
|
| 772 | + break; |
|
| 773 | + |
|
| 774 | + case 'margin-left': |
|
| 775 | + $this->value['margin']['l'] = $this->convertToMM($val, 0); |
|
| 776 | + break; |
|
| 777 | + |
|
| 778 | + case 'border': |
|
| 779 | + $val = $this->readBorder($val); |
|
| 780 | + $this->value['border']['t'] = $val; |
|
| 781 | + $this->value['border']['r'] = $val; |
|
| 782 | + $this->value['border']['b'] = $val; |
|
| 783 | + $this->value['border']['l'] = $val; |
|
| 784 | + break; |
|
| 785 | + |
|
| 786 | + case 'border-style': |
|
| 787 | + $val = explode(' ', $val); |
|
| 788 | + foreach ($val as $valK => $valV) { |
|
| 789 | + if ( ! in_array($valV, array('solid', 'dotted', 'dashed'))) { |
|
| 790 | + $val[$valK] = null; |
|
| 791 | + } |
|
| 792 | + } |
|
| 793 | + $this->_duplicateBorder($val); |
|
| 794 | + if ($val[0]) { |
|
| 795 | + $this->value['border']['t']['type'] = $val[0]; |
|
| 796 | + } |
|
| 797 | + if ($val[1]) { |
|
| 798 | + $this->value['border']['r']['type'] = $val[1]; |
|
| 799 | + } |
|
| 800 | + if ($val[2]) { |
|
| 801 | + $this->value['border']['b']['type'] = $val[2]; |
|
| 802 | + } |
|
| 803 | + if ($val[3]) { |
|
| 804 | + $this->value['border']['l']['type'] = $val[3]; |
|
| 805 | + } |
|
| 806 | + break; |
|
| 807 | + |
|
| 808 | + case 'border-top-style': |
|
| 809 | + if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 810 | + $this->value['border']['t']['type'] = $val; |
|
| 811 | + } |
|
| 812 | + break; |
|
| 813 | + |
|
| 814 | + case 'border-right-style': |
|
| 815 | + if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 816 | + $this->value['border']['r']['type'] = $val; |
|
| 817 | + } |
|
| 818 | + break; |
|
| 819 | + |
|
| 820 | + case 'border-bottom-style': |
|
| 821 | + if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 822 | + $this->value['border']['b']['type'] = $val; |
|
| 823 | + } |
|
| 824 | + break; |
|
| 825 | + |
|
| 826 | + case 'border-left-style': |
|
| 827 | + if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 828 | + $this->value['border']['l']['type'] = $val; |
|
| 829 | + } |
|
| 830 | + break; |
|
| 831 | + |
|
| 832 | + case 'border-color': |
|
| 833 | + $res = false; |
|
| 834 | + $val = preg_replace('/,[\s]+/', ',', $val); |
|
| 835 | + $val = explode(' ', $val); |
|
| 836 | + foreach ($val as $valK => $valV) { |
|
| 837 | + $val[$valK] = $this->convertToColor($valV, $res); |
|
| 838 | + if ( ! $res) { |
|
| 839 | + $val[$valK] = null; |
|
| 840 | + } |
|
| 841 | + } |
|
| 842 | + $this->_duplicateBorder($val); |
|
| 843 | + if (is_array($val[0])) { |
|
| 844 | + $this->value['border']['t']['color'] = $val[0]; |
|
| 845 | + } |
|
| 846 | + if (is_array($val[1])) { |
|
| 847 | + $this->value['border']['r']['color'] = $val[1]; |
|
| 848 | + } |
|
| 849 | + if (is_array($val[2])) { |
|
| 850 | + $this->value['border']['b']['color'] = $val[2]; |
|
| 851 | + } |
|
| 852 | + if (is_array($val[3])) { |
|
| 853 | + $this->value['border']['l']['color'] = $val[3]; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + break; |
|
| 857 | + |
|
| 858 | + case 'border-top-color': |
|
| 859 | + $res = false; |
|
| 860 | + $val = $this->convertToColor($val, $res); |
|
| 861 | + if ($res) { |
|
| 862 | + $this->value['border']['t']['color'] = $val; |
|
| 863 | + } |
|
| 864 | + break; |
|
| 865 | + |
|
| 866 | + case 'border-right-color': |
|
| 867 | + $res = false; |
|
| 868 | + $val = $this->convertToColor($val, $res); |
|
| 869 | + if ($res) { |
|
| 870 | + $this->value['border']['r']['color'] = $val; |
|
| 871 | + } |
|
| 872 | + break; |
|
| 873 | + |
|
| 874 | + case 'border-bottom-color': |
|
| 875 | + $res = false; |
|
| 876 | + $val = $this->convertToColor($val, $res); |
|
| 877 | + if ($res) { |
|
| 878 | + $this->value['border']['b']['color'] = $val; |
|
| 879 | + } |
|
| 880 | + break; |
|
| 881 | + |
|
| 882 | + case 'border-left-color': |
|
| 883 | + $res = false; |
|
| 884 | + $val = $this->convertToColor($val, $res); |
|
| 885 | + if ($res) { |
|
| 886 | + $this->value['border']['l']['color'] = $val; |
|
| 887 | + } |
|
| 888 | + break; |
|
| 889 | + |
|
| 890 | + case 'border-width': |
|
| 891 | + $val = explode(' ', $val); |
|
| 892 | + foreach ($val as $valK => $valV) { |
|
| 893 | + $val[$valK] = $this->convertToMM($valV, 0); |
|
| 894 | + } |
|
| 895 | + $this->_duplicateBorder($val); |
|
| 896 | + if ($val[0]) $this->value['border']['t']['width'] = $val[0]; |
|
| 897 | + if ($val[1]) $this->value['border']['r']['width'] = $val[1]; |
|
| 898 | + if ($val[2]) $this->value['border']['b']['width'] = $val[2]; |
|
| 899 | + if ($val[3]) $this->value['border']['l']['width'] = $val[3]; |
|
| 900 | + break; |
|
| 901 | + |
|
| 902 | + case 'border-top-width': |
|
| 903 | + $val = $this->convertToMM($val, 0); |
|
| 904 | + if ($val) $this->value['border']['t']['width'] = $val; |
|
| 905 | + break; |
|
| 906 | + |
|
| 907 | + case 'border-right-width': |
|
| 908 | + $val = $this->convertToMM($val, 0); |
|
| 909 | + if ($val) $this->value['border']['r']['width'] = $val; |
|
| 910 | + break; |
|
| 911 | + |
|
| 912 | + case 'border-bottom-width': |
|
| 913 | + $val = $this->convertToMM($val, 0); |
|
| 914 | + if ($val) $this->value['border']['b']['width'] = $val; |
|
| 915 | + break; |
|
| 916 | + |
|
| 917 | + case 'border-left-width': |
|
| 918 | + $val = $this->convertToMM($val, 0); |
|
| 919 | + if ($val) $this->value['border']['l']['width'] = $val; |
|
| 920 | + break; |
|
| 921 | + |
|
| 922 | + case 'border-collapse': |
|
| 923 | + if ($tagName == 'table') $this->value['border']['collapse'] = ($val == 'collapse'); |
|
| 924 | + break; |
|
| 925 | + |
|
| 926 | + case 'border-radius': |
|
| 927 | + $val = explode('/', $val); |
|
| 928 | + if (count($val) > 2) { |
|
| 929 | + break; |
|
| 930 | + } |
|
| 931 | + $valH = $this->convertToRadius(trim($val[0])); |
|
| 932 | + if (count($valH) < 1 || count($valH) > 4) { |
|
| 933 | + break; |
|
| 934 | + } |
|
| 935 | + if ( ! isset($valH[1])) $valH[1] = $valH[0]; |
|
| 936 | + if ( ! isset($valH[2])) $valH = array($valH[0], $valH[0], $valH[1], $valH[1]); |
|
| 937 | + if ( ! isset($valH[3])) $valH[3] = $valH[1]; |
|
| 938 | + if (isset($val[1])) { |
|
| 939 | + $valV = $this->convertToRadius(trim($val[1])); |
|
| 940 | + if (count($valV) < 1 || count($valV) > 4) { |
|
| 941 | + break; |
|
| 942 | + } |
|
| 943 | + if ( ! isset($valV[1])) $valV[1] = $valV[0]; |
|
| 944 | + if ( ! isset($valV[2])) $valV = array($valV[0], $valV[0], $valV[1], $valV[1]); |
|
| 945 | + if ( ! isset($valV[3])) $valV[3] = $valV[1]; |
|
| 946 | + } else { |
|
| 947 | + $valV = $valH; |
|
| 948 | + } |
|
| 949 | + $this->value['border']['radius'] = array( |
|
| 950 | + 'tl' => array($valH[0], $valV[0]), |
|
| 951 | + 'tr' => array($valH[1], $valV[1]), |
|
| 952 | + 'br' => array($valH[2], $valV[2]), |
|
| 953 | + 'bl' => array($valH[3], $valV[3]) |
|
| 954 | + ); |
|
| 955 | + break; |
|
| 956 | + |
|
| 957 | + case 'border-top-left-radius': |
|
| 958 | + $val = $this->convertToRadius($val); |
|
| 959 | + if (count($val) < 1 || count($val) > 2) { |
|
| 960 | + break; |
|
| 961 | + } |
|
| 962 | + $this->value['border']['radius']['tl'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 963 | + break; |
|
| 964 | + |
|
| 965 | + case 'border-top-right-radius': |
|
| 966 | + $val = $this->convertToRadius($val); |
|
| 967 | + if (count($val) < 1 || count($val) > 2) { |
|
| 968 | + break; |
|
| 969 | + } |
|
| 970 | + $this->value['border']['radius']['tr'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 971 | + break; |
|
| 972 | + |
|
| 973 | + case 'border-bottom-right-radius': |
|
| 974 | + $val = $this->convertToRadius($val); |
|
| 975 | + if (count($val) < 1 || count($val) > 2) { |
|
| 976 | + break; |
|
| 977 | + } |
|
| 978 | + $this->value['border']['radius']['br'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 979 | + break; |
|
| 980 | + |
|
| 981 | + case 'border-bottom-left-radius': |
|
| 982 | + $val = $this->convertToRadius($val); |
|
| 983 | + if (count($val) < 1 || count($val) > 2) { |
|
| 984 | + break; |
|
| 985 | + } |
|
| 986 | + $this->value['border']['radius']['bl'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 987 | + break; |
|
| 988 | + |
|
| 989 | + case 'border-top': |
|
| 990 | + $this->value['border']['t'] = $this->readBorder($val); |
|
| 991 | + break; |
|
| 992 | + |
|
| 993 | + case 'border-right': |
|
| 994 | + $this->value['border']['r'] = $this->readBorder($val); |
|
| 995 | + break; |
|
| 996 | + |
|
| 997 | + case 'border-bottom': |
|
| 998 | + $this->value['border']['b'] = $this->readBorder($val); |
|
| 999 | + break; |
|
| 1000 | + |
|
| 1001 | + case 'border-left': |
|
| 1002 | + $this->value['border']['l'] = $this->readBorder($val); |
|
| 1003 | + break; |
|
| 1004 | + |
|
| 1005 | + case 'background-color': |
|
| 1006 | + $this->value['background']['color'] = $this->convertBackgroundColor($val); |
|
| 1007 | + break; |
|
| 1008 | + |
|
| 1009 | + case 'background-image': |
|
| 1010 | + $this->value['background']['image'] = $this->convertBackgroundImage($val); |
|
| 1011 | + break; |
|
| 1012 | + |
|
| 1013 | + case 'background-position': |
|
| 1014 | + $res = null; |
|
| 1015 | + $this->value['background']['position'] = $this->convertBackgroundPosition($val, $res); |
|
| 1016 | + break; |
|
| 1017 | + |
|
| 1018 | + case 'background-repeat': |
|
| 1019 | + $this->value['background']['repeat'] = $this->convertBackgroundRepeat($val); |
|
| 1020 | + break; |
|
| 1021 | + |
|
| 1022 | + case 'background': |
|
| 1023 | + $this->convertBackground($val, $this->value['background']); |
|
| 1024 | + break; |
|
| 1025 | + |
|
| 1026 | + case 'position': |
|
| 1027 | + if ($val == 'absolute') $this->value['position'] = 'absolute'; |
|
| 1028 | + else if ($val == 'relative') $this->value['position'] = 'relative'; |
|
| 1029 | + else $this->value['position'] = null; |
|
| 1030 | + break; |
|
| 1031 | + |
|
| 1032 | + case 'float': |
|
| 1033 | + if ($val == 'left') $this->value['float'] = 'left'; |
|
| 1034 | + else if ($val == 'right') $this->value['float'] = 'right'; |
|
| 1035 | + else $this->value['float'] = null; |
|
| 1036 | + break; |
|
| 1037 | + |
|
| 1038 | + case 'display': |
|
| 1039 | + if ($val == 'inline') $this->value['display'] = 'inline'; |
|
| 1040 | + else if ($val == 'block') $this->value['display'] = 'block'; |
|
| 1041 | + else if ($val == 'none') $this->value['display'] = 'none'; |
|
| 1042 | + else $this->value['display'] = null; |
|
| 1043 | + break; |
|
| 1044 | + |
|
| 1045 | + case 'top': |
|
| 1046 | + case 'bottom': |
|
| 1047 | + case 'left': |
|
| 1048 | + case 'right': |
|
| 1049 | + $this->value[$nom] = $val; |
|
| 1050 | + break; |
|
| 1051 | + |
|
| 1052 | + case 'list-style': |
|
| 1053 | + case 'list-style-type': |
|
| 1054 | + case 'list-style-image': |
|
| 1055 | + if ($nom == 'list-style') $nom = 'list-style-type'; |
|
| 1056 | + $this->value[$nom] = $val; |
|
| 1057 | + break; |
|
| 1058 | + |
|
| 1059 | + default: |
|
| 1060 | + break; |
|
| 1061 | + } |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + $return = true; |
|
| 1065 | + |
|
| 1066 | + // only for P tag |
|
| 1067 | + if ($this->value['margin']['t'] === null) $this->value['margin']['t'] = $this->value['font-size']; |
|
| 1068 | + if ($this->value['margin']['b'] === null) $this->value['margin']['b'] = $this->value['font-size']; |
|
| 1069 | + |
|
| 1070 | + // force the text align to left, if asked by html2pdf |
|
| 1071 | + if ($this->_onlyLeft) $this->value['text-align'] = 'left'; |
|
| 1072 | + |
|
| 1073 | + // correction on the width (quick box) |
|
| 1074 | + if ($noWidth && in_array($tagName, array('div', 'blockquote', 'fieldset')) && $this->value['position'] != 'absolute') { |
|
| 1075 | + $this->value['width'] = $this->getLastWidth(); |
|
| 1076 | + $this->value['width'] -= $this->value['margin']['l'] + $this->value['margin']['r']; |
|
| 1077 | + } else { |
|
| 1078 | + if ($correctWidth) { |
|
| 1079 | + if ( ! in_array($tagName, array('table', 'div', 'blockquote', 'fieldset', 'hr'))) { |
|
| 1080 | + $this->value['width'] -= $this->value['padding']['l'] + $this->value['padding']['r']; |
|
| 1081 | + $this->value['width'] -= $this->value['border']['l']['width'] + $this->value['border']['r']['width']; |
|
| 1082 | + } |
|
| 1083 | + if (in_array($tagName, array('th', 'td'))) { |
|
| 1084 | + $this->value['width'] -= $this->convertToMM(isset($param['cellspacing']) ? $param['cellspacing'] : '2px'); |
|
| 1085 | + $return = false; |
|
| 1086 | + } |
|
| 1087 | + if ($this->value['width'] < 0) $this->value['width'] = 0; |
|
| 1088 | + } else { |
|
| 1089 | + if ($this->value['width']) { |
|
| 1090 | + if ($this->value['border']['l']['width']) $this->value['width'] += $this->value['border']['l']['width']; |
|
| 1091 | + if ($this->value['border']['r']['width']) $this->value['width'] += $this->value['border']['r']['width']; |
|
| 1092 | + if ($this->value['padding']['l']) $this->value['width'] += $this->value['padding']['l']; |
|
| 1093 | + if ($this->value['padding']['r']) $this->value['width'] += $this->value['padding']['r']; |
|
| 1094 | + } |
|
| 1095 | + } |
|
| 1096 | + } |
|
| 1097 | + if ($this->value['height']) { |
|
| 1098 | + if ($this->value['border']['b']['width']) $this->value['height'] += $this->value['border']['b']['width']; |
|
| 1099 | + if ($this->value['border']['t']['width']) $this->value['height'] += $this->value['border']['t']['width']; |
|
| 1100 | + if ($this->value['padding']['b']) $this->value['height'] += $this->value['padding']['b']; |
|
| 1101 | + if ($this->value['padding']['t']) $this->value['height'] += $this->value['padding']['t']; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + if ($this->value['top'] != null) $this->value['top'] = $this->convertToMM($this->value['top'], $this->getLastHeight(true)); |
|
| 1105 | + if ($this->value['bottom'] != null) $this->value['bottom'] = $this->convertToMM($this->value['bottom'], $this->getLastHeight(true)); |
|
| 1106 | + if ($this->value['left'] != null) $this->value['left'] = $this->convertToMM($this->value['left'], $this->getLastWidth(true)); |
|
| 1107 | + if ($this->value['right'] != null) $this->value['right'] = $this->convertToMM($this->value['right'], $this->getLastWidth(true)); |
|
| 1108 | + |
|
| 1109 | + if ($this->value['top'] && $this->value['bottom'] && $this->value['height']) $this->value['bottom'] = null; |
|
| 1110 | + if ($this->value['left'] && $this->value['right'] && $this->value['width']) $this->value['right'] = null; |
|
| 1111 | + |
|
| 1112 | + return $return; |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + /** |
|
| 1116 | + * get the height of the current line |
|
| 1117 | + * |
|
| 1118 | + * @access public |
|
| 1119 | + * @return float $height in mm |
|
| 1120 | + */ |
|
| 1121 | + public function getLineHeight() |
|
| 1122 | + { |
|
| 1123 | + $val = $this->value['line-height']; |
|
| 1124 | + if ($val == 'normal') $val = '108%'; |
|
| 1125 | + return $this->convertToMM($val, $this->value['font-size']); |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + /** |
|
| 1129 | + * get the width of the parent |
|
| 1130 | + * |
|
| 1131 | + * @access public |
|
| 1132 | + * @param boolean $mode true => adding padding and border |
|
| 1133 | + * @return float $width in mm |
|
| 1134 | + */ |
|
| 1135 | + public function getLastWidth($mode = false) |
|
| 1136 | + { |
|
| 1137 | + for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1138 | + if ($this->table[$k]['width']) { |
|
| 1139 | + $w = $this->table[$k]['width']; |
|
| 1140 | + if ($mode) { |
|
| 1141 | + $w += $this->table[$k]['border']['l']['width'] + $this->table[$k]['padding']['l'] + 0.02; |
|
| 1142 | + $w += $this->table[$k]['border']['r']['width'] + $this->table[$k]['padding']['r'] + 0.02; |
|
| 1143 | + } |
|
| 1144 | + return $w; |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + return $this->_pdf->getW() - $this->_pdf->getlMargin() - $this->_pdf->getrMargin(); |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * get the height of the parent |
|
| 1152 | + * |
|
| 1153 | + * @access public |
|
| 1154 | + * @param boolean $mode true => adding padding and border |
|
| 1155 | + * @return float $height in mm |
|
| 1156 | + */ |
|
| 1157 | + public function getLastHeight($mode = false) |
|
| 1158 | + { |
|
| 1159 | + for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1160 | + if ($this->table[$k]['height']) { |
|
| 1161 | + $h = $this->table[$k]['height']; |
|
| 1162 | + if ($mode) { |
|
| 1163 | + $h += $this->table[$k]['border']['t']['width'] + $this->table[$k]['padding']['t'] + 0.02; |
|
| 1164 | + $h += $this->table[$k]['border']['b']['width'] + $this->table[$k]['padding']['b'] + 0.02; |
|
| 1165 | + } |
|
| 1166 | + return $h; |
|
| 1167 | + } |
|
| 1168 | + } |
|
| 1169 | + return $this->_pdf->getH() - $this->_pdf->gettMargin() - $this->_pdf->getbMargin(); |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + /** |
|
| 1173 | + * get the value of the float property |
|
| 1174 | + * |
|
| 1175 | + * @access public |
|
| 1176 | + * @return $float left/right |
|
| 1177 | + */ |
|
| 1178 | + public function getFloat() |
|
| 1179 | + { |
|
| 1180 | + if ($this->value['float'] == 'left') return 'left'; |
|
| 1181 | + if ($this->value['float'] == 'right') return 'right'; |
|
| 1182 | + return null; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + /** |
|
| 1186 | + * get the last value for a specific key |
|
| 1187 | + * |
|
| 1188 | + * @access public |
|
| 1189 | + * @param string $key |
|
| 1190 | + * @return mixed |
|
| 1191 | + */ |
|
| 1192 | + public function getLastValue($key) |
|
| 1193 | + { |
|
| 1194 | + $nb = count($this->table); |
|
| 1195 | + if ($nb > 0) { |
|
| 1196 | + return $this->table[$nb - 1][$key]; |
|
| 1197 | + } else { |
|
| 1198 | + return null; |
|
| 1199 | + } |
|
| 1200 | + } |
|
| 1201 | + |
|
| 1202 | + /** |
|
| 1203 | + * get the last absolute X |
|
| 1204 | + * |
|
| 1205 | + * @access protected |
|
| 1206 | + * @return float $x |
|
| 1207 | + */ |
|
| 1208 | + protected function _getLastAbsoluteX() |
|
| 1209 | + { |
|
| 1210 | + for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1211 | + if ($this->table[$k]['x'] && $this->table[$k]['position']) return $this->table[$k]['x']; |
|
| 1212 | + } |
|
| 1213 | + return $this->_pdf->getlMargin(); |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + /** |
|
| 1217 | + * get the last absolute Y |
|
| 1218 | + * |
|
| 1219 | + * @access protected |
|
| 1220 | + * @return float $y |
|
| 1221 | + */ |
|
| 1222 | + protected function _getLastAbsoluteY() |
|
| 1223 | + { |
|
| 1224 | + for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1225 | + if ($this->table[$k]['y'] && $this->table[$k]['position']) return $this->table[$k]['y']; |
|
| 1226 | + } |
|
| 1227 | + return $this->_pdf->gettMargin(); |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + /** |
|
| 1231 | + * get the CSS properties of the current tag |
|
| 1232 | + * |
|
| 1233 | + * @access protected |
|
| 1234 | + * @return array $styles |
|
| 1235 | + */ |
|
| 1236 | + protected function _getFromCSS() |
|
| 1237 | + { |
|
| 1238 | + // styles to apply |
|
| 1239 | + $styles = array(); |
|
| 1240 | + |
|
| 1241 | + // list of the selectors to get in the CSS files |
|
| 1242 | + $getit = array(); |
|
| 1243 | + |
|
| 1244 | + // get the list of the selectors of each tags |
|
| 1245 | + $lst = array(); |
|
| 1246 | + $lst[] = $this->value['id_lst']; |
|
| 1247 | + for ($i = count($this->table) - 1; $i >= 0; $i--) { |
|
| 1248 | + $lst[] = $this->table[$i]['id_lst']; |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + // foreach selectors in the CSS files, verify if it match with the list of selectors |
|
| 1252 | + foreach ($this->cssKeys as $key => $num) { |
|
| 1253 | + if ($this->_getReccursiveStyle($key, $lst)) { |
|
| 1254 | + $getit[$key] = $num; |
|
| 1255 | + } |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + // if we have selectors |
|
| 1259 | + if (count($getit)) { |
|
| 1260 | + // get them, but in the definition order, because of priority |
|
| 1261 | + asort($getit); |
|
| 1262 | + foreach ($getit as $key => $val) { |
|
| 1263 | + $styles = array_merge($styles, $this->css[$key]); |
|
| 1264 | + } |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + return $styles; |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + /** |
|
| 1271 | + * identify if the selector $key match with the list of tag selectors |
|
| 1272 | + * |
|
| 1273 | + * @access protected |
|
| 1274 | + * @param string $key CSS selector to analyse |
|
| 1275 | + * @param array $lst list of the selectors of each tags |
|
| 1276 | + * @param string $next next step of parsing the selector |
|
| 1277 | + * @return boolean |
|
| 1278 | + */ |
|
| 1279 | + protected function _getReccursiveStyle($key, $lst, $next = null) |
|
| 1280 | + { |
|
| 1281 | + // if next step |
|
| 1282 | + if ($next !== null) { |
|
| 1283 | + // we remove this step |
|
| 1284 | + if ($next) { |
|
| 1285 | + $key = trim(substr($key, 0, -strlen($next))); |
|
| 1286 | + } |
|
| 1287 | + array_shift($lst); |
|
| 1288 | + |
|
| 1289 | + // if no more step to identify => return false |
|
| 1290 | + if ( ! count($lst)) { |
|
| 1291 | + return false; |
|
| 1292 | + } |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + // for each selector of the current step |
|
| 1296 | + foreach ($lst[0] as $name) { |
|
| 1297 | + // if selector = key => ok |
|
| 1298 | + if ($key == $name) { |
|
| 1299 | + return true; |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + // if the end of the key = the selector and the next step is ok => ok |
|
| 1303 | + if (substr($key, -strlen(' '.$name)) == ' '.$name && $this->_getReccursiveStyle($key, $lst, $name)) { |
|
| 1304 | + return true; |
|
| 1305 | + } |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + // if we are not in the first step, we analyse the sub steps (the pareng tag of the current tag) |
|
| 1309 | + if ($next !== null && $this->_getReccursiveStyle($key, $lst, '')) { |
|
| 1310 | + return true; |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + // no corresponding found |
|
| 1314 | + return false; |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + /** |
|
| 1318 | + * Analyse a border |
|
| 1319 | + * |
|
| 1320 | + * @access public |
|
| 1321 | + * @param string $css css border properties |
|
| 1322 | + * @return array border properties |
|
| 1323 | + */ |
|
| 1324 | + public function readBorder($css) |
|
| 1325 | + { |
|
| 1326 | + // border none |
|
| 1327 | + $none = array('type' => 'none', 'width' => 0, 'color' => array(0, 0, 0)); |
|
| 1328 | + |
|
| 1329 | + // default value |
|
| 1330 | + $type = 'solid'; |
|
| 1331 | + $width = $this->convertToMM('1pt'); |
|
| 1332 | + $color = array(0, 0, 0); |
|
| 1333 | + |
|
| 1334 | + // clean up the values |
|
| 1335 | + $css = explode(' ', $css); |
|
| 1336 | + foreach ($css as $k => $v) { |
|
| 1337 | + $v = trim($v); |
|
| 1338 | + if ($v) { |
|
| 1339 | + $css[$k] = $v; |
|
| 1340 | + } else { |
|
| 1341 | + unset($css[$k]); |
|
| 1342 | + } |
|
| 1343 | + } |
|
| 1344 | + $css = array_values($css); |
|
| 1345 | + |
|
| 1346 | + // read the values |
|
| 1347 | + $res = null; |
|
| 1348 | + foreach ($css as $value) { |
|
| 1349 | + |
|
| 1350 | + // if no border => return none |
|
| 1351 | + if ($value == 'none' || $value == 'hidden') { |
|
| 1352 | + return $none; |
|
| 1353 | + } |
|
| 1354 | + |
|
| 1355 | + // try to convert the value as a distance |
|
| 1356 | + $tmp = $this->convertToMM($value); |
|
| 1357 | + |
|
| 1358 | + // if the convert is ok => it is a width |
|
| 1359 | + if ($tmp !== null) { |
|
| 1360 | + $width = $tmp; |
|
| 1361 | + // else, it could be the type |
|
| 1362 | + } else if (in_array($value, array('solid', 'dotted', 'dashed', 'double'))) { |
|
| 1363 | + $type = $value; |
|
| 1364 | + // else, it could be the color |
|
| 1365 | + } else { |
|
| 1366 | + $tmp = $this->convertToColor($value, $res); |
|
| 1367 | + if ($res) $color = $tmp; |
|
| 1368 | + } |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + // if no witdh => return none |
|
| 1372 | + if ( ! $width) return $none; |
|
| 1373 | + |
|
| 1374 | + // return the border properties |
|
| 1375 | + return array('type' => $type, 'width' => $width, 'color' => $color); |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * duplicate the borders if needed |
|
| 1380 | + * |
|
| 1381 | + * @access protected |
|
| 1382 | + * @param &array $val |
|
| 1383 | + */ |
|
| 1384 | + protected function _duplicateBorder(&$val) |
|
| 1385 | + { |
|
| 1386 | + // 1 value => L => RTB |
|
| 1387 | + if (count($val) == 1) { |
|
| 1388 | + $val[1] = $val[0]; |
|
| 1389 | + $val[2] = $val[0]; |
|
| 1390 | + $val[3] = $val[0]; |
|
| 1391 | + // 2 values => L => R & T => B |
|
| 1392 | + } else if (count($val) == 2) { |
|
| 1393 | + $val[2] = $val[0]; |
|
| 1394 | + $val[3] = $val[1]; |
|
| 1395 | + // 3 values => T => B |
|
| 1396 | + } else if (count($val) == 3) { |
|
| 1397 | + $val[3] = $val[1]; |
|
| 1398 | + } |
|
| 1399 | + } |
|
| 1400 | + |
|
| 1401 | + /** |
|
| 1402 | + * Analyse a background |
|
| 1403 | + * |
|
| 1404 | + * @access public |
|
| 1405 | + * @param string $css css background properties |
|
| 1406 | + * @param &array $value parsed values (by reference, because, ther is a legacy of the parent CSS properties) |
|
| 1407 | + */ |
|
| 1408 | + public function convertBackground($css, &$value) |
|
| 1409 | + { |
|
| 1410 | + // is there a image ? |
|
| 1411 | + $text = '/url\(([^)]*)\)/isU'; |
|
| 1412 | + if (preg_match($text, $css, $match)) { |
|
| 1413 | + // get the image |
|
| 1414 | + $value['image'] = $this->convertBackgroundImage($match[0]); |
|
| 1415 | + |
|
| 1416 | + // remove if from the css properties |
|
| 1417 | + $css = preg_replace($text, '', $css); |
|
| 1418 | + $css = preg_replace('/[\s]+/', ' ', $css); |
|
| 1419 | + } |
|
| 1420 | + |
|
| 1421 | + // protect some spaces |
|
| 1422 | + $css = preg_replace('/,[\s]+/', ',', $css); |
|
| 1423 | + |
|
| 1424 | + // explode the values |
|
| 1425 | + $css = explode(' ', $css); |
|
| 1426 | + |
|
| 1427 | + // background position to parse |
|
| 1428 | + $pos = ''; |
|
| 1429 | + |
|
| 1430 | + // foreach value |
|
| 1431 | + foreach ($css as $val) { |
|
| 1432 | + // try to parse the value as a color |
|
| 1433 | + $ok = false; |
|
| 1434 | + $color = $this->convertToColor($val, $ok); |
|
| 1435 | + |
|
| 1436 | + // if ok => it is a color |
|
| 1437 | + if ($ok) { |
|
| 1438 | + $value['color'] = $color; |
|
| 1439 | + // else if transparent => no coloàr |
|
| 1440 | + } else if ($val == 'transparent') { |
|
| 1441 | + $value['color'] = null; |
|
| 1442 | + // else |
|
| 1443 | + } else { |
|
| 1444 | + // try to parse the value as a repeat |
|
| 1445 | + $repeat = $this->convertBackgroundRepeat($val); |
|
| 1446 | + |
|
| 1447 | + // if ok => it is repeat |
|
| 1448 | + if ($repeat) { |
|
| 1449 | + $value['repeat'] = $repeat; |
|
| 1450 | + // else => it could only be a position |
|
| 1451 | + } else { |
|
| 1452 | + $pos .= ($pos ? ' ' : '').$val; |
|
| 1453 | + } |
|
| 1454 | + } |
|
| 1455 | + } |
|
| 1456 | + |
|
| 1457 | + // if we have a position to parse |
|
| 1458 | + if ($pos) { |
|
| 1459 | + // try to read it |
|
| 1460 | + $pos = $this->convertBackgroundPosition($pos, $ok); |
|
| 1461 | + if ($ok) { |
|
| 1462 | + $value['position'] = $pos; |
|
| 1463 | + } |
|
| 1464 | + } |
|
| 1465 | + } |
|
| 1466 | + |
|
| 1467 | + /** |
|
| 1468 | + * parse a background color |
|
| 1469 | + * |
|
| 1470 | + * @access public |
|
| 1471 | + * @param string $css |
|
| 1472 | + * @return string $value |
|
| 1473 | + */ |
|
| 1474 | + public function convertBackgroundColor($css) |
|
| 1475 | + { |
|
| 1476 | + $res = null; |
|
| 1477 | + if ($css == 'transparent') return null; |
|
| 1478 | + else return $this->convertToColor($css, $res); |
|
| 1479 | + } |
|
| 1480 | + |
|
| 1481 | + /** |
|
| 1482 | + * parse a background image |
|
| 1483 | + * |
|
| 1484 | + * @access public |
|
| 1485 | + * @param string $css |
|
| 1486 | + * @return string $value |
|
| 1487 | + */ |
|
| 1488 | + public function convertBackgroundImage($css) |
|
| 1489 | + { |
|
| 1490 | + if ($css == 'none') |
|
| 1491 | + return null; |
|
| 1492 | + else if (preg_match('/^url\(([^)]*)\)$/isU', $css, $match)) |
|
| 1493 | + return $match[1]; |
|
| 1494 | + else |
|
| 1495 | + return null; |
|
| 1496 | + } |
|
| 1497 | + |
|
| 1498 | + /** |
|
| 1499 | + * parse a background position |
|
| 1500 | + * |
|
| 1501 | + * @access public |
|
| 1502 | + * @param string $css |
|
| 1503 | + * @param &boolean $res flag if conver is ok or not |
|
| 1504 | + * @return array ($x, $y) |
|
| 1505 | + */ |
|
| 1506 | + public function convertBackgroundPosition($css, &$res) |
|
| 1507 | + { |
|
| 1508 | + // init the res |
|
| 1509 | + $res = false; |
|
| 1510 | + |
|
| 1511 | + // explode the value |
|
| 1512 | + $css = explode(' ', $css); |
|
| 1513 | + |
|
| 1514 | + // we must have 2 values. if 0 or >2 : error. if 1 => put center for 2 |
|
| 1515 | + if (count($css) < 2) { |
|
| 1516 | + if ( ! $css[0]) return null; |
|
| 1517 | + $css[1] = 'center'; |
|
| 1518 | + } |
|
| 1519 | + if (count($css) > 2) return null; |
|
| 1520 | + |
|
| 1521 | + // prepare the values |
|
| 1522 | + $x = 0; |
|
| 1523 | + $y = 0; |
|
| 1524 | + $res = true; |
|
| 1525 | + |
|
| 1526 | + // convert the first value |
|
| 1527 | + if ($css[0] == 'left') $x = '0%'; |
|
| 1528 | + else if ($css[0] == 'center') $x = '50%'; |
|
| 1529 | + else if ($css[0] == 'right') $x = '100%'; |
|
| 1530 | + else if ($css[0] == 'top') $y = '0%'; |
|
| 1531 | + else if ($css[0] == 'bottom') $y = '100%'; |
|
| 1532 | + else if (preg_match('/^[-]?[0-9\.]+%$/isU', $css[0])) $x = $css[0]; |
|
| 1533 | + else if ($this->convertToMM($css[0])) $x = $this->convertToMM($css[0]); |
|
| 1534 | + else $res = false; |
|
| 1535 | + |
|
| 1536 | + // convert the second value |
|
| 1537 | + if ($css[1] == 'left') $x = '0%'; |
|
| 1538 | + else if ($css[1] == 'right') $x = '100%'; |
|
| 1539 | + else if ($css[1] == 'top') $y = '0%'; |
|
| 1540 | + else if ($css[1] == 'center') $y = '50%'; |
|
| 1541 | + else if ($css[1] == 'bottom') $y = '100%'; |
|
| 1542 | + else if (preg_match('/^[-]?[0-9\.]+%$/isU', $css[1])) $y = $css[1]; |
|
| 1543 | + else if ($this->convertToMM($css[1])) $y = $this->convertToMM($css[1]); |
|
| 1544 | + else $res = false; |
|
| 1545 | + |
|
| 1546 | + // return the values |
|
| 1547 | + return array($x, $y); |
|
| 1548 | + } |
|
| 1549 | + |
|
| 1550 | + /** |
|
| 1551 | + * parse a background repeat |
|
| 1552 | + * |
|
| 1553 | + * @access public |
|
| 1554 | + * @param string $css |
|
| 1555 | + * @return string $value |
|
| 1556 | + */ |
|
| 1557 | + public function convertBackgroundRepeat($css) |
|
| 1558 | + { |
|
| 1559 | + switch ($css) |
|
| 1560 | + { |
|
| 1561 | + case 'repeat': |
|
| 1562 | + return array(true, true); |
|
| 1563 | + case 'repeat-x': |
|
| 1564 | + return array(true, false); |
|
| 1565 | + case 'repeat-y': |
|
| 1566 | + return array(false, true); |
|
| 1567 | + case 'no-repeat': |
|
| 1568 | + return array(false, false); |
|
| 1569 | + } |
|
| 1570 | + return null; |
|
| 1571 | + } |
|
| 1572 | + |
|
| 1573 | + /** |
|
| 1574 | + * convert a distance to mm |
|
| 1575 | + * |
|
| 1576 | + * @access public |
|
| 1577 | + * @param string $css distance to convert |
|
| 1578 | + * @param float $old parent distance |
|
| 1579 | + * @return float $value |
|
| 1580 | + */ |
|
| 1581 | + public function convertToMM($css, $old = 0.) |
|
| 1582 | + { |
|
| 1583 | + $css = trim($css); |
|
| 1584 | + if (preg_match('/^[0-9\.\-]+$/isU', $css)) $css .= 'px'; |
|
| 1585 | + if (preg_match('/^[0-9\.\-]+px$/isU', $css)) $css = 25.4 / 96. * str_replace('px', '', $css); |
|
| 1586 | + else if (preg_match('/^[0-9\.\-]+pt$/isU', $css)) $css = 25.4 / 72. * str_replace('pt', '', $css); |
|
| 1587 | + else if (preg_match('/^[0-9\.\-]+in$/isU', $css)) $css = 25.4 * str_replace('in', '', $css); |
|
| 1588 | + else if (preg_match('/^[0-9\.\-]+mm$/isU', $css)) $css = 1. * str_replace('mm', '', $css); |
|
| 1589 | + else if (preg_match('/^[0-9\.\-]+%$/isU', $css)) $css = 1. * $old * str_replace('%', '', $css) / 100.; |
|
| 1590 | + else $css = null; |
|
| 1591 | + |
|
| 1592 | + return $css; |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + /** |
|
| 1596 | + * convert a css radius |
|
| 1597 | + * |
|
| 1598 | + * @access public |
|
| 1599 | + * @param string $css |
|
| 1600 | + * @return float $value |
|
| 1601 | + */ |
|
| 1602 | + public function convertToRadius($css) |
|
| 1603 | + { |
|
| 1604 | + // explode the value |
|
| 1605 | + $css = explode(' ', $css); |
|
| 1606 | + |
|
| 1607 | + foreach ($css as $k => $v) { |
|
| 1608 | + $v = trim($v); |
|
| 1609 | + if ($v) { |
|
| 1610 | + $v = $this->convertToMM($v, 0); |
|
| 1611 | + if ($v !== null) { |
|
| 1612 | + $css[$k] = $v; |
|
| 1613 | + } else { |
|
| 1614 | + unset($css[$k]); |
|
| 1615 | + } |
|
| 1616 | + } else { |
|
| 1617 | + unset($css[$k]); |
|
| 1618 | + } |
|
| 1619 | + } |
|
| 1620 | + |
|
| 1621 | + return array_values($css); |
|
| 1622 | + } |
|
| 1623 | + |
|
| 1624 | + /** |
|
| 1625 | + * convert a css color |
|
| 1626 | + * |
|
| 1627 | + * @access public |
|
| 1628 | + * @param string $css |
|
| 1629 | + * @param &boolean $res |
|
| 1630 | + * @return array (r,g, b) |
|
| 1631 | + */ |
|
| 1632 | + public function convertToColor($css, &$res) |
|
| 1633 | + { |
|
| 1634 | + // prepare the value |
|
| 1635 | + $css = trim($css); |
|
| 1636 | + $res = true; |
|
| 1637 | + |
|
| 1638 | + // if transparent => return null |
|
| 1639 | + if (strtolower($css) == 'transparent') return array(null, null, null); |
|
| 1640 | + |
|
| 1641 | + // HTML color |
|
| 1642 | + if (isset($this->_htmlColor[strtolower($css)])) { |
|
| 1643 | + $css = $this->_htmlColor[strtolower($css)]; |
|
| 1644 | + $r = floatVal(hexdec(substr($css, 0, 2))); |
|
| 1645 | + $v = floatVal(hexdec(substr($css, 2, 2))); |
|
| 1646 | + $b = floatVal(hexdec(substr($css, 4, 2))); |
|
| 1647 | + return array($r, $v, $b); |
|
| 1648 | + } |
|
| 1649 | + |
|
| 1650 | + // like #FFFFFF |
|
| 1651 | + if (preg_match('/^#[0-9A-Fa-f]{6}$/isU', $css)) { |
|
| 1652 | + $r = floatVal(hexdec(substr($css, 1, 2))); |
|
| 1653 | + $v = floatVal(hexdec(substr($css, 3, 2))); |
|
| 1654 | + $b = floatVal(hexdec(substr($css, 5, 2))); |
|
| 1655 | + return array($r, $v, $b); |
|
| 1656 | + } |
|
| 1657 | + |
|
| 1658 | + // like #FFF |
|
| 1659 | + if (preg_match('/^#[0-9A-F]{3}$/isU', $css)) { |
|
| 1660 | + $r = floatVal(hexdec(substr($css, 1, 1).substr($css, 1, 1))); |
|
| 1661 | + $v = floatVal(hexdec(substr($css, 2, 1).substr($css, 2, 1))); |
|
| 1662 | + $b = floatVal(hexdec(substr($css, 3, 1).substr($css, 3, 1))); |
|
| 1663 | + return array($r, $v, $b); |
|
| 1664 | + } |
|
| 1665 | + |
|
| 1666 | + // like rgb(100, 100, 100) |
|
| 1667 | + if (preg_match('/rgb\([\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*\)/isU', $css, $match)) { |
|
| 1668 | + $r = $this->_convertSubColor($match[1]); |
|
| 1669 | + $v = $this->_convertSubColor($match[2]); |
|
| 1670 | + $b = $this->_convertSubColor($match[3]); |
|
| 1671 | + return array($r * 255., $v * 255., $b * 255.); |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + // like cmyk(100, 100, 100, 100) |
|
| 1675 | + if (preg_match('/cmyk\([\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*\)/isU', $css, $match)) { |
|
| 1676 | + $c = $this->_convertSubColor($match[1]); |
|
| 1677 | + $m = $this->_convertSubColor($match[2]); |
|
| 1678 | + $y = $this->_convertSubColor($match[3]); |
|
| 1679 | + $k = $this->_convertSubColor($match[4]); |
|
| 1680 | + return array($c * 100., $m * 100., $y * 100., $k * 100.); |
|
| 1681 | + } |
|
| 1682 | + |
|
| 1683 | + $res = false; |
|
| 1684 | + return array(0., 0., 0.); |
|
| 1685 | + } |
|
| 1686 | + |
|
| 1687 | + /** |
|
| 1688 | + * color value to convert |
|
| 1689 | + * |
|
| 1690 | + * @access protected |
|
| 1691 | + * @param string $c |
|
| 1692 | + * @return float $c 0.->1. |
|
| 1693 | + */ |
|
| 1694 | + protected function _convertSubColor($c) |
|
| 1695 | + { |
|
| 1696 | + if (substr($c, -1) == '%') { |
|
| 1697 | + $c = floatVal(substr($c, 0, -1)) / 100.; |
|
| 1698 | + } else { |
|
| 1699 | + $c = floatVal($c); |
|
| 1700 | + if ($c > 1) $c = $c / 255.; |
|
| 1701 | + } |
|
| 1702 | + |
|
| 1703 | + return $c; |
|
| 1704 | + } |
|
| 1705 | + |
|
| 1706 | + /** |
|
| 1707 | + * read a css content |
|
| 1708 | + * |
|
| 1709 | + * @access protected |
|
| 1710 | + * @param string $code |
|
| 1711 | + */ |
|
| 1712 | + protected function _analyseStyle(&$code) |
|
| 1713 | + { |
|
| 1714 | + // clean the spaces |
|
| 1715 | + $code = preg_replace('/[\s]+/', ' ', $code); |
|
| 1716 | + |
|
| 1717 | + // remove the comments |
|
| 1718 | + $code = preg_replace('/\/\*.*?\*\//s', '', $code); |
|
| 1719 | + |
|
| 1720 | + // split each CSS code "selector { value }" |
|
| 1721 | + preg_match_all('/([^{}]+){([^}]*)}/isU', $code, $match); |
|
| 1722 | + |
|
| 1723 | + // for each CSS code |
|
| 1724 | + for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1725 | + |
|
| 1726 | + // selectors |
|
| 1727 | + $names = strtolower(trim($match[1][$k])); |
|
| 1728 | + |
|
| 1729 | + // css style |
|
| 1730 | + $styles = trim($match[2][$k]); |
|
| 1731 | + |
|
| 1732 | + // explode each value |
|
| 1733 | + $styles = explode(';', $styles); |
|
| 1734 | + |
|
| 1735 | + // parse each value |
|
| 1736 | + $css = array(); |
|
| 1737 | + foreach ($styles as $style) { |
|
| 1738 | + $tmp = explode(':', $style); |
|
| 1739 | + if (count($tmp) > 1) { |
|
| 1740 | + $cod = $tmp[0]; unset($tmp[0]); $tmp = implode(':', $tmp); |
|
| 1741 | + $css[trim(strtolower($cod))] = trim($tmp); |
|
| 1742 | + } |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + // explode the names |
|
| 1746 | + $names = explode(',', $names); |
|
| 1747 | + |
|
| 1748 | + // save the values for each names |
|
| 1749 | + foreach ($names as $name) { |
|
| 1750 | + // clean the name |
|
| 1751 | + $name = trim($name); |
|
| 1752 | + |
|
| 1753 | + // if a selector with somethink lige :hover => continue |
|
| 1754 | + if (strpos($name, ':') !== false) continue; |
|
| 1755 | + |
|
| 1756 | + // save the value |
|
| 1757 | + if ( ! isset($this->css[$name])) |
|
| 1758 | + $this->css[$name] = $css; |
|
| 1759 | + else |
|
| 1760 | + $this->css[$name] = array_merge($this->css[$name], $css); |
|
| 1761 | + |
|
| 1762 | + } |
|
| 1763 | + } |
|
| 1764 | + |
|
| 1765 | + // get he list of the keys |
|
| 1766 | + $this->cssKeys = array_flip(array_keys($this->css)); |
|
| 1767 | + } |
|
| 1768 | + |
|
| 1769 | + /** |
|
| 1770 | + * Extract the css files from a html code |
|
| 1771 | + * |
|
| 1772 | + * @access public |
|
| 1773 | + * @param string &$html |
|
| 1774 | + * @param string $html |
|
| 1775 | + */ |
|
| 1776 | + public function readStyle(&$html) |
|
| 1777 | + { |
|
| 1778 | + // the CSS content |
|
| 1779 | + $style = ' '; |
|
| 1780 | + |
|
| 1781 | + // extract the link tags, and remove them in the html code |
|
| 1782 | + preg_match_all('/<link([^>]*)>/isU', $html, $match); |
|
| 1783 | + $html = preg_replace('/<link[^>]*>/isU', '', $html); |
|
| 1784 | + $html = preg_replace('/<\/link[^>]*>/isU', '', $html); |
|
| 1785 | + |
|
| 1786 | + // analyse each link tag |
|
| 1787 | + foreach ($match[1] as $code) { |
|
| 1788 | + $tmp = array(); |
|
| 1789 | + |
|
| 1790 | + // read the attributes name=value |
|
| 1791 | + $prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)'; |
|
| 1792 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 1793 | + for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1794 | + $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 1795 | + } |
|
| 1796 | + |
|
| 1797 | + // read the attributes name="value" |
|
| 1798 | + $prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]'; |
|
| 1799 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 1800 | + for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1801 | + $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 1802 | + } |
|
| 1803 | + |
|
| 1804 | + // read the attributes name='value' |
|
| 1805 | + $prop = "([a-zA-Z0-9_]+)=[']([^']*)[']"; |
|
| 1806 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 1807 | + for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1808 | + $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 1809 | + } |
|
| 1810 | + |
|
| 1811 | + // if type text/css => we keep it |
|
| 1812 | + if (isset($tmp['type']) && strtolower($tmp['type']) == 'text/css' && isset($tmp['href'])) { |
|
| 1813 | + |
|
| 1814 | + // get the href |
|
| 1815 | + $url = $tmp['href']; |
|
| 1816 | + |
|
| 1817 | + // get the content of the css file |
|
| 1818 | + $content = @file_get_contents($url); |
|
| 1819 | + |
|
| 1820 | + // if "http://" in the url |
|
| 1821 | + if (strpos($url, 'http://') !== false) { |
|
| 1822 | + |
|
| 1823 | + // get the domain "http://xxx/" |
|
| 1824 | + $url = str_replace('http://', '', $url); |
|
| 1825 | + $url = explode('/', $url); |
|
| 1826 | + $urlMain = 'http://'.$url[0].'/'; |
|
| 1827 | + |
|
| 1828 | + // get the absolute url of the path |
|
| 1829 | + $urlSelf = $url; unset($urlSelf[count($urlSelf) - 1]); $urlSelf = 'http://'.implode('/', $urlSelf).'/'; |
|
| 1830 | + |
|
| 1831 | + // adapt the url in the css content |
|
| 1832 | + $content = preg_replace('/url\(([^\\\\][^)]*)\)/isU', 'url('.$urlSelf.'$1)', $content); |
|
| 1833 | + $content = preg_replace('/url\((\\\\[^)]*)\)/isU', 'url('.$urlMain.'$1)', $content); |
|
| 1834 | + } else { |
|
| 1835 | 1835 | // @TODO correction on url in absolute on a local css content |
| 1836 | - // $content = preg_replace('/url\(([^)]*)\)/isU', 'url('.dirname($url).'/$1)', $content); |
|
| 1837 | - } |
|
| 1838 | - |
|
| 1839 | - // add to the CSS content |
|
| 1840 | - $style .= $content."\n"; |
|
| 1841 | - } |
|
| 1842 | - } |
|
| 1843 | - |
|
| 1844 | - // extract the style tags des tags style, and remove them in the html code |
|
| 1845 | - preg_match_all('/<style[^>]*>(.*)<\/style[^>]*>/isU', $html, $match); |
|
| 1846 | - $html = preg_replace('/<style[^>]*>(.*)<\/style[^>]*>/isU', '', $html); |
|
| 1847 | - |
|
| 1848 | - // analyse each style tags |
|
| 1849 | - foreach ($match[1] as $code) { |
|
| 1850 | - // add to the CSS content |
|
| 1851 | - $code = str_replace('<!--', '', $code); |
|
| 1852 | - $code = str_replace('-->', '', $code); |
|
| 1853 | - $style .= $code."\n"; |
|
| 1854 | - } |
|
| 1855 | - |
|
| 1856 | - //analyse the css content |
|
| 1857 | - $this->_analyseStyle($style); |
|
| 1858 | - } |
|
| 1836 | + // $content = preg_replace('/url\(([^)]*)\)/isU', 'url('.dirname($url).'/$1)', $content); |
|
| 1837 | + } |
|
| 1838 | + |
|
| 1839 | + // add to the CSS content |
|
| 1840 | + $style .= $content."\n"; |
|
| 1841 | + } |
|
| 1842 | + } |
|
| 1843 | + |
|
| 1844 | + // extract the style tags des tags style, and remove them in the html code |
|
| 1845 | + preg_match_all('/<style[^>]*>(.*)<\/style[^>]*>/isU', $html, $match); |
|
| 1846 | + $html = preg_replace('/<style[^>]*>(.*)<\/style[^>]*>/isU', '', $html); |
|
| 1847 | + |
|
| 1848 | + // analyse each style tags |
|
| 1849 | + foreach ($match[1] as $code) { |
|
| 1850 | + // add to the CSS content |
|
| 1851 | + $code = str_replace('<!--', '', $code); |
|
| 1852 | + $code = str_replace('-->', '', $code); |
|
| 1853 | + $style .= $code."\n"; |
|
| 1854 | + } |
|
| 1855 | + |
|
| 1856 | + //analyse the css content |
|
| 1857 | + $this->_analyseStyle($style); |
|
| 1858 | + } |
|
| 1859 | 1859 | } |
| 1860 | 1860 | \ No newline at end of file |
@@ -11,488 +11,487 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | if ( ! defined('__CLASS_HTML2PDF__')) { |
| 13 | 13 | |
| 14 | - define('__CLASS_HTML2PDF__', '4.03'); |
|
| 15 | - define('HTML2PDF_USED_TCPDF_VERSION', '5.0.002'); |
|
| 16 | - |
|
| 17 | - require_once('_class/exception.class.php'); |
|
| 18 | - require_once('_class/locale.class.php'); |
|
| 19 | - require_once('_class/myPdf.class.php'); |
|
| 20 | - require_once('_class/parsingHtml.class.php'); |
|
| 21 | - require_once('_class/parsingCss.class.php'); |
|
| 22 | - |
|
| 23 | - class HTML2PDF |
|
| 24 | - { |
|
| 25 | - /** |
|
| 26 | - * HTML2PDF_myPdf object, extends from TCPDF |
|
| 27 | - * @var HTML2PDF_myPdf |
|
| 28 | - */ |
|
| 29 | - public $pdf = null; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * CSS parsing |
|
| 33 | - * @var HTML2PDF_parsingCss |
|
| 34 | - */ |
|
| 35 | - public $parsingCss = null; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * HTML parsing |
|
| 39 | - * @var HTML2PDF_parsingHtml |
|
| 40 | - */ |
|
| 41 | - public $parsingHtml = null; |
|
| 42 | - |
|
| 43 | - protected $_langue = 'fr'; // locale of the messages |
|
| 44 | - protected $_orientation = 'P'; // page orientation : Portrait ou Landscape |
|
| 45 | - protected $_format = 'A4'; // page format : A4, A3, ... |
|
| 46 | - protected $_encoding = ''; // charset encoding |
|
| 47 | - protected $_unicode = true; // means that the input text is unicode (default = true) |
|
| 48 | - |
|
| 49 | - protected $_testTdInOnepage = true; // test of TD that can not take more than one page |
|
| 50 | - protected $_testIsImage = true; // test if the images exist or not |
|
| 51 | - protected $_testIsDeprecated = false; // test the deprecated functions |
|
| 52 | - |
|
| 53 | - protected $_parsePos = 0; // position in the parsing |
|
| 54 | - protected $_tempPos = 0; // temporary position for complex table |
|
| 55 | - protected $_page = 0; // current page number |
|
| 56 | - |
|
| 57 | - protected $_subHtml = null; // sub html |
|
| 58 | - protected $_subPart = false; // sub HTML2PDF |
|
| 59 | - protected $_subHEADER = array(); // sub action to make the header |
|
| 60 | - protected $_subFOOTER = array(); // sub action to make the footer |
|
| 61 | - protected $_subSTATES = array(); // array to save some parameters |
|
| 62 | - |
|
| 63 | - protected $_isSubPart = false; // flag : in a sub html2pdf |
|
| 64 | - protected $_isInThead = false; // flag : in a thead |
|
| 65 | - protected $_isInTfoot = false; // flag : in a tfoot |
|
| 66 | - protected $_isInOverflow = false; // flag : in a overflow |
|
| 67 | - protected $_isInFooter = false; // flag : in a footer |
|
| 68 | - protected $_isInDraw = null; // flag : in a draw (svg) |
|
| 69 | - protected $_isAfterFloat = false; // flag : is just after a float |
|
| 70 | - protected $_isInForm = false; // flag : is in a float. false / action of the form |
|
| 71 | - protected $_isInLink = ''; // flag : is in a link. empty / href of the link |
|
| 72 | - protected $_isInParagraph = false; // flag : is in a paragraph |
|
| 73 | - protected $_isForOneLine = false; // flag : in a specific sub html2pdf to have the height of the next line |
|
| 74 | - |
|
| 75 | - protected $_maxX = 0; // maximum X of the current zone |
|
| 76 | - protected $_maxY = 0; // maximum Y of the current zone |
|
| 77 | - protected $_maxE = 0; // number of elements in the current zone |
|
| 78 | - protected $_maxH = 0; // maximum height of the line in the current zone |
|
| 79 | - protected $_maxSave = array(); // save the maximums of the current zone |
|
| 80 | - protected $_currentH = 0; // height of the current line |
|
| 81 | - |
|
| 82 | - protected $_defaultLeft = 0; // default marges of the page |
|
| 83 | - protected $_defaultTop = 0; |
|
| 84 | - protected $_defaultRight = 0; |
|
| 85 | - protected $_defaultBottom = 0; |
|
| 86 | - protected $_defaultFont = null; // default font to use, is the asked font does not exist |
|
| 87 | - |
|
| 88 | - protected $_margeLeft = 0; // current marges of the page |
|
| 89 | - protected $_margeTop = 0; |
|
| 90 | - protected $_margeRight = 0; |
|
| 91 | - protected $_margeBottom = 0; |
|
| 92 | - protected $_marges = array(); // save the different marges of the current page |
|
| 93 | - protected $_pageMarges = array(); // float marges of the current page |
|
| 94 | - protected $_background = array(); // background informations |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - protected $_firstPage = true; // flag : first page |
|
| 98 | - protected $_defList = array(); // table to save the stats of the tags UL and OL |
|
| 99 | - |
|
| 100 | - protected $_lstAnchor = array(); // list of the anchors |
|
| 101 | - protected $_lstField = array(); // list of the fields |
|
| 102 | - protected $_lstSelect = array(); // list of the options of the current select |
|
| 103 | - protected $_previousCall = null; // last action called |
|
| 104 | - |
|
| 105 | - protected $_debugActif = false; // flag : mode debug is active |
|
| 106 | - protected $_debugOkUsage = false; // flag : the function memory_get_usage exist |
|
| 107 | - protected $_debugOkPeak = false; // flag : the function memory_get_peak_usage exist |
|
| 108 | - protected $_debugLevel = 0; // level in the debug |
|
| 109 | - protected $_debugStartTime = 0; // debug start time |
|
| 110 | - protected $_debugLastTime = 0; // debug stop time |
|
| 111 | - |
|
| 112 | - static protected $_subobj = null; // object html2pdf prepared in order to accelerate the creation of sub html2pdf |
|
| 113 | - static protected $_tables = array(); // static table to prepare the nested html tables |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * class constructor |
|
| 117 | - * |
|
| 118 | - * @access public |
|
| 119 | - * @param string $orientation page orientation, same as TCPDF |
|
| 120 | - * @param string $format The format used for pages, same as TCPDF |
|
| 121 | - * @param $tring $langue Langue : fr, en, it... |
|
| 122 | - * @param boolean $unicode TRUE means that the input text is unicode (default = true) |
|
| 123 | - * @param String $encoding charset encoding; default is UTF-8 |
|
| 124 | - * @param integer[] $marges Default marges (left, top, right, bottom) |
|
| 125 | - * @return HTML2PDF $this |
|
| 126 | - */ |
|
| 127 | - public function __construct($orientation = 'P', $format = 'A4', $langue = 'en', $unicode = true, $encoding = 'UTF-8', $marges = array(5, 5, 5, 8)) |
|
| 128 | - { |
|
| 129 | - // init the page number |
|
| 130 | - $this->_page = 0; |
|
| 131 | - $this->_firstPage = true; |
|
| 132 | - |
|
| 133 | - // save the parameters |
|
| 134 | - $this->_orientation = $orientation; |
|
| 135 | - $this->_format = $format; |
|
| 136 | - $this->_langue = strtolower($langue); |
|
| 137 | - $this->_unicode = $unicode; |
|
| 138 | - $this->_encoding = $encoding; |
|
| 139 | - |
|
| 140 | - // load the Local |
|
| 141 | - HTML2PDF_locale::load($this->_langue); |
|
| 142 | - |
|
| 143 | - // create the HTML2PDF_myPdf object |
|
| 144 | - $this->pdf = new HTML2PDF_myPdf($orientation, 'mm', $format, $unicode, $encoding); |
|
| 145 | - |
|
| 146 | - // init the CSS parsing object |
|
| 147 | - $this->parsingCss = new HTML2PDF_parsingCss($this->pdf); |
|
| 148 | - $this->parsingCss->fontSet(); |
|
| 149 | - $this->_defList = array(); |
|
| 150 | - |
|
| 151 | - // init some tests |
|
| 152 | - $this->setTestTdInOnePage(true); |
|
| 153 | - $this->setTestIsImage(true); |
|
| 154 | - $this->setTestIsDeprecated(true); |
|
| 155 | - |
|
| 156 | - // init the default font |
|
| 157 | - $this->setDefaultFont(null); |
|
| 158 | - |
|
| 159 | - // init the HTML parsing object |
|
| 160 | - $this->parsingHtml = new HTML2PDF_parsingHtml($this->_encoding); |
|
| 161 | - $this->_subHtml = null; |
|
| 162 | - $this->_subPart = false; |
|
| 163 | - |
|
| 164 | - // init the marges of the page |
|
| 165 | - if ( ! is_array($marges)) $marges = array($marges, $marges, $marges, $marges); |
|
| 166 | - $this->_setDefaultMargins($marges[0], $marges[1], $marges[2], $marges[3]); |
|
| 167 | - $this->_setMargins(); |
|
| 168 | - $this->_marges = array(); |
|
| 169 | - |
|
| 170 | - // init the form's fields |
|
| 171 | - $this->_lstField = array(); |
|
| 172 | - |
|
| 173 | - return $this; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Destructor |
|
| 178 | - * |
|
| 179 | - * @access public |
|
| 180 | - * @return null |
|
| 181 | - */ |
|
| 182 | - public function __destruct() |
|
| 183 | - { |
|
| 184 | - |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Clone to create a sub HTML2PDF from HTML2PDF::$_subobj |
|
| 189 | - * |
|
| 190 | - * @access public |
|
| 191 | - */ |
|
| 192 | - public function __clone() |
|
| 193 | - { |
|
| 194 | - $this->pdf = clone $this->pdf; |
|
| 195 | - $this->parsingHtml = clone $this->parsingHtml; |
|
| 196 | - $this->parsingCss = clone $this->parsingCss; |
|
| 197 | - $this->parsingCss->setPdfParent($this->pdf); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * set the debug mode to On |
|
| 202 | - * |
|
| 203 | - * @access public |
|
| 204 | - * @return HTML2PDF $this |
|
| 205 | - */ |
|
| 206 | - public function setModeDebug() |
|
| 207 | - { |
|
| 208 | - $time = microtime(true); |
|
| 209 | - |
|
| 210 | - $this->_debugActif = true; |
|
| 211 | - $this->_debugOkUsage = function_exists('memory_get_usage'); |
|
| 212 | - $this->_debugOkPeak = function_exists('memory_get_peak_usage'); |
|
| 213 | - $this->_debugStartTime = $time; |
|
| 214 | - $this->_debugLastTime = $time; |
|
| 215 | - |
|
| 216 | - $this->_DEBUG_stepline('step', 'time', 'delta', 'memory', 'peak'); |
|
| 217 | - $this->_DEBUG_add('Init debug'); |
|
| 218 | - |
|
| 219 | - return $this; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Set the test of TD thdat can not take more than one page |
|
| 224 | - * |
|
| 225 | - * @access public |
|
| 226 | - * @param boolean $mode |
|
| 227 | - * @return HTML2PDF $this |
|
| 228 | - */ |
|
| 229 | - public function setTestTdInOnePage($mode = true) |
|
| 230 | - { |
|
| 231 | - $this->_testTdInOnepage = $mode ? true : false; |
|
| 232 | - |
|
| 233 | - return $this; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Set the test if the images exist or not |
|
| 238 | - * |
|
| 239 | - * @access public |
|
| 240 | - * @param boolean $mode |
|
| 241 | - * @return HTML2PDF $this |
|
| 242 | - */ |
|
| 243 | - public function setTestIsImage($mode = true) |
|
| 244 | - { |
|
| 245 | - $this->_testIsImage = $mode ? true : false; |
|
| 246 | - |
|
| 247 | - return $this; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Set the test on deprecated functions |
|
| 252 | - * |
|
| 253 | - * @access public |
|
| 254 | - * @param boolean $mode |
|
| 255 | - * @return HTML2PDF $this |
|
| 256 | - */ |
|
| 257 | - public function setTestIsDeprecated($mode = true) |
|
| 258 | - { |
|
| 259 | - $this->_testIsDeprecated = $mode ? true : false; |
|
| 260 | - |
|
| 261 | - return $this; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Set the default font to use, if no font is specify, or if the asked font does not exist |
|
| 266 | - * |
|
| 267 | - * @access public |
|
| 268 | - * @param string $default name of the default font to use. If null : Arial is no font is specify, and error if the asked font does not exist |
|
| 269 | - * @return HTML2PDF $this |
|
| 270 | - */ |
|
| 271 | - public function setDefaultFont($default = null) |
|
| 272 | - { |
|
| 273 | - $this->_defaultFont = $default; |
|
| 274 | - $this->parsingCss->setDefaultFont($default); |
|
| 275 | - |
|
| 276 | - return $this; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * add a font, see TCPDF function addFont |
|
| 281 | - * |
|
| 282 | - * @access public |
|
| 283 | - * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font. |
|
| 284 | - * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul> |
|
| 285 | - * @return HTML2PDF $this |
|
| 286 | - * @see TCPDF::addFont |
|
| 287 | - */ |
|
| 288 | - public function addFont($family, $style = '', $file = '') |
|
| 289 | - { |
|
| 290 | - $this->pdf->AddFont($family, $style, $file); |
|
| 291 | - |
|
| 292 | - return $this; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * display a automatic index, from the bookmarks |
|
| 297 | - * |
|
| 298 | - * @access public |
|
| 299 | - * @param string $titre index title |
|
| 300 | - * @param int $sizeTitle font size of the index title, in mm |
|
| 301 | - * @param int $sizeBookmark font size of the index, in mm |
|
| 302 | - * @param boolean $bookmarkTitle add a bookmark for the index, at his beginning |
|
| 303 | - * @param boolean $displayPage display the page numbers |
|
| 304 | - * @param int $onPage if null : at the end of the document on a new page, else on the $onPage page |
|
| 305 | - * @param string $fontName font name to use |
|
| 306 | - * @return null |
|
| 307 | - */ |
|
| 308 | - public function createIndex($titre = 'Index', $sizeTitle = 20, $sizeBookmark = 15, $bookmarkTitle = true, $displayPage = true, $onPage = null, $fontName = 'helvetica') |
|
| 309 | - { |
|
| 310 | - $oldPage = $this->_INDEX_NewPage($onPage); |
|
| 311 | - $this->pdf->createIndex($this, $titre, $sizeTitle, $sizeBookmark, $bookmarkTitle, $displayPage, $onPage, $fontName); |
|
| 312 | - if ($oldPage) { |
|
| 313 | - $this->pdf->setPage($oldPage); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * clean up the objects |
|
| 319 | - * |
|
| 320 | - * @access protected |
|
| 321 | - */ |
|
| 322 | - protected function _cleanUp() |
|
| 323 | - { |
|
| 324 | - HTML2PDF::$_subobj = null; |
|
| 325 | - HTML2PDF::$_tables = array(); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Send the document to a given destination: string, local file or browser. |
|
| 330 | - * Dest can be : |
|
| 331 | - * I : send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF. |
|
| 332 | - * D : send to the browser and force a file download with the name given by name. |
|
| 333 | - * F : save to a local server file with the name given by name. |
|
| 334 | - * S : return the document as a string. name is ignored. |
|
| 335 | - * FI: equivalent to F + I option |
|
| 336 | - * FD: equivalent to F + D option |
|
| 337 | - * true => I |
|
| 338 | - * false => S |
|
| 339 | - * |
|
| 340 | - * @param string $name The name of the file when saved. |
|
| 341 | - * @param string $dest Destination where to send the document. |
|
| 342 | - * @return string content of the PDF, if $dest=S |
|
| 343 | - * @see TCPDF::close |
|
| 344 | - * @access public |
|
| 345 | - |
|
| 346 | - */ |
|
| 347 | - public function Output($name = '', $dest = false) |
|
| 348 | - { |
|
| 349 | - // close the pdf and clean up |
|
| 350 | - $this->_cleanUp(); |
|
| 351 | - |
|
| 352 | - // if on debug mode |
|
| 353 | - if ($this->_debugActif) { |
|
| 354 | - $this->_DEBUG_add('Before output'); |
|
| 355 | - $this->pdf->Close(); |
|
| 356 | - exit; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - // complete parameters |
|
| 360 | - if ($dest === false) $dest = 'I'; |
|
| 361 | - if ($dest === true) $dest = 'S'; |
|
| 362 | - if ($dest === '') $dest = 'I'; |
|
| 363 | - if ($name == '') $name = 'document.pdf'; |
|
| 364 | - |
|
| 365 | - // clean up the destination |
|
| 366 | - $dest = strtoupper($dest); |
|
| 367 | - if ( ! in_array($dest, array('I', 'D', 'F', 'S', 'FI', 'FD'))) $dest = 'I'; |
|
| 368 | - |
|
| 369 | - // the name must be a PDF name |
|
| 370 | - if (strtolower(substr($name, -4)) != '.pdf') { |
|
| 371 | - throw new HTML2PDF_exception(0, 'The output document name "'.$name.'" is not a PDF name'); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - // call the output of TCPDF |
|
| 375 | - return $this->pdf->Output($name, $dest); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * convert HTML to PDF |
|
| 380 | - * |
|
| 381 | - * @access public |
|
| 382 | - * @param string $html |
|
| 383 | - * @param boolean $debugVue enable the HTML debug vue |
|
| 384 | - * @return null |
|
| 385 | - */ |
|
| 386 | - public function writeHTML($html, $debugVue = false) |
|
| 387 | - { |
|
| 388 | - // if it is a real html page, we have to convert it |
|
| 389 | - if (preg_match('/<body/isU', $html)) { |
|
| 390 | - $html = $this->getHtmlFromPage($html); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - $html = str_replace('[[date_y]]', date('Y'), $html); |
|
| 394 | - $html = str_replace('[[date_m]]', date('m'), $html); |
|
| 395 | - $html = str_replace('[[date_d]]', date('d'), $html); |
|
| 396 | - |
|
| 397 | - $html = str_replace('[[date_h]]', date('H'), $html); |
|
| 398 | - $html = str_replace('[[date_i]]', date('i'), $html); |
|
| 399 | - $html = str_replace('[[date_s]]', date('s'), $html); |
|
| 400 | - |
|
| 401 | - // If we are in HTML debug vue : display the HTML |
|
| 402 | - if ($debugVue) { |
|
| 403 | - return $this->_vueHTML($html); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - // convert HTMl to PDF |
|
| 407 | - $this->parsingCss->readStyle($html); |
|
| 408 | - $this->parsingHtml->setHTML($html); |
|
| 409 | - $this->parsingHtml->parse(); |
|
| 410 | - $this->_makeHTMLcode(); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * convert the HTML of a real page, to a code adapted to HTML2PDF |
|
| 415 | - * |
|
| 416 | - * @access public |
|
| 417 | - * @param string HTML of a real page |
|
| 418 | - * @param string $html |
|
| 419 | - * @return string HTML adapted to HTML2PDF |
|
| 420 | - */ |
|
| 421 | - public function getHtmlFromPage($html) |
|
| 422 | - { |
|
| 423 | - $html = str_replace('<BODY', '<body', $html); |
|
| 424 | - $html = str_replace('</BODY', '</body', $html); |
|
| 425 | - |
|
| 426 | - // extract the content |
|
| 427 | - $res = explode('<body', $html); |
|
| 428 | - if (count($res) < 2) return $html; |
|
| 429 | - $content = '<page'.$res[1]; |
|
| 430 | - $content = explode('</body', $content); |
|
| 431 | - $content = $content[0].'</page>'; |
|
| 432 | - |
|
| 433 | - // extract the link tags |
|
| 434 | - preg_match_all('/<link([^>]*)>/isU', $html, $match); |
|
| 435 | - foreach ($match[0] as $src) |
|
| 436 | - $content = $src.'</link>'.$content; |
|
| 437 | - |
|
| 438 | - // extract the css style tags |
|
| 439 | - preg_match_all('/<style[^>]*>(.*)<\/style[^>]*>/isU', $html, $match); |
|
| 440 | - foreach ($match[0] as $src) |
|
| 441 | - $content = $src.$content; |
|
| 442 | - |
|
| 443 | - return $content; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * init a sub HTML2PDF. does not use it directly. Only the method createSubHTML must use it |
|
| 448 | - * |
|
| 449 | - * @access public |
|
| 450 | - * @param string $format |
|
| 451 | - * @param string $orientation |
|
| 452 | - * @param array $marge |
|
| 453 | - * @param integer $page |
|
| 454 | - * @param array $defLIST |
|
| 455 | - * @param integer $myLastPageGroup |
|
| 456 | - * @param integer $myLastPageGroupNb |
|
| 457 | - */ |
|
| 458 | - public function initSubHtml($format, $orientation, $marge, $page, $defLIST, $myLastPageGroup, $myLastPageGroupNb) |
|
| 459 | - { |
|
| 460 | - $this->_isSubPart = true; |
|
| 461 | - |
|
| 462 | - $this->parsingCss->setOnlyLeft(); |
|
| 463 | - |
|
| 464 | - $this->_setNewPage($format, $orientation, null, null, ($myLastPageGroup !== null)); |
|
| 465 | - |
|
| 466 | - $this->_saveMargin(0, 0, $marge); |
|
| 467 | - $this->_defList = $defLIST; |
|
| 468 | - |
|
| 469 | - $this->_page = $page; |
|
| 470 | - $this->pdf->setMyLastPageGroup($myLastPageGroup); |
|
| 471 | - $this->pdf->setMyLastPageGroupNb($myLastPageGroupNb); |
|
| 472 | - $this->pdf->setXY(0, 0); |
|
| 473 | - $this->parsingCss->fontSet(); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * display the content in HTML moden for debug |
|
| 478 | - * |
|
| 479 | - * @access protected |
|
| 480 | - * @param string $content |
|
| 481 | - */ |
|
| 482 | - protected function _vueHTML($content) |
|
| 483 | - { |
|
| 484 | - $content = preg_replace('/<page_header([^>]*)>/isU', '<hr>'.HTML2PDF_locale::get('vue01').' : $1<hr><div$1>', $content); |
|
| 485 | - $content = preg_replace('/<page_footer([^>]*)>/isU', '<hr>'.HTML2PDF_locale::get('vue02').' : $1<hr><div$1>', $content); |
|
| 486 | - $content = preg_replace('/<page([^>]*)>/isU', '<hr>'.HTML2PDF_locale::get('vue03').' : $1<hr><div$1>', $content); |
|
| 487 | - $content = preg_replace('/<\/page([^>]*)>/isU', '</div><hr>', $content); |
|
| 488 | - $content = preg_replace('/<bookmark([^>]*)>/isU', '<hr>bookmark : $1<hr>', $content); |
|
| 489 | - $content = preg_replace('/<\/bookmark([^>]*)>/isU', '', $content); |
|
| 490 | - $content = preg_replace('/<barcode([^>]*)>/isU', '<hr>barcode : $1<hr>', $content); |
|
| 491 | - $content = preg_replace('/<\/barcode([^>]*)>/isU', '', $content); |
|
| 492 | - $content = preg_replace('/<qrcode([^>]*)>/isU', '<hr>qrcode : $1<hr>', $content); |
|
| 493 | - $content = preg_replace('/<\/qrcode([^>]*)>/isU', '', $content); |
|
| 494 | - |
|
| 495 | - echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
|
| 14 | + define('__CLASS_HTML2PDF__', '4.03'); |
|
| 15 | + define('HTML2PDF_USED_TCPDF_VERSION', '5.0.002'); |
|
| 16 | + |
|
| 17 | + require_once('_class/exception.class.php'); |
|
| 18 | + require_once('_class/locale.class.php'); |
|
| 19 | + require_once('_class/myPdf.class.php'); |
|
| 20 | + require_once('_class/parsingHtml.class.php'); |
|
| 21 | + require_once('_class/parsingCss.class.php'); |
|
| 22 | + |
|
| 23 | + class HTML2PDF |
|
| 24 | + { |
|
| 25 | + /** |
|
| 26 | + * HTML2PDF_myPdf object, extends from TCPDF |
|
| 27 | + * @var HTML2PDF_myPdf |
|
| 28 | + */ |
|
| 29 | + public $pdf = null; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * CSS parsing |
|
| 33 | + * @var HTML2PDF_parsingCss |
|
| 34 | + */ |
|
| 35 | + public $parsingCss = null; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * HTML parsing |
|
| 39 | + * @var HTML2PDF_parsingHtml |
|
| 40 | + */ |
|
| 41 | + public $parsingHtml = null; |
|
| 42 | + |
|
| 43 | + protected $_langue = 'fr'; // locale of the messages |
|
| 44 | + protected $_orientation = 'P'; // page orientation : Portrait ou Landscape |
|
| 45 | + protected $_format = 'A4'; // page format : A4, A3, ... |
|
| 46 | + protected $_encoding = ''; // charset encoding |
|
| 47 | + protected $_unicode = true; // means that the input text is unicode (default = true) |
|
| 48 | + |
|
| 49 | + protected $_testTdInOnepage = true; // test of TD that can not take more than one page |
|
| 50 | + protected $_testIsImage = true; // test if the images exist or not |
|
| 51 | + protected $_testIsDeprecated = false; // test the deprecated functions |
|
| 52 | + |
|
| 53 | + protected $_parsePos = 0; // position in the parsing |
|
| 54 | + protected $_tempPos = 0; // temporary position for complex table |
|
| 55 | + protected $_page = 0; // current page number |
|
| 56 | + |
|
| 57 | + protected $_subHtml = null; // sub html |
|
| 58 | + protected $_subPart = false; // sub HTML2PDF |
|
| 59 | + protected $_subHEADER = array(); // sub action to make the header |
|
| 60 | + protected $_subFOOTER = array(); // sub action to make the footer |
|
| 61 | + protected $_subSTATES = array(); // array to save some parameters |
|
| 62 | + |
|
| 63 | + protected $_isSubPart = false; // flag : in a sub html2pdf |
|
| 64 | + protected $_isInThead = false; // flag : in a thead |
|
| 65 | + protected $_isInTfoot = false; // flag : in a tfoot |
|
| 66 | + protected $_isInOverflow = false; // flag : in a overflow |
|
| 67 | + protected $_isInFooter = false; // flag : in a footer |
|
| 68 | + protected $_isInDraw = null; // flag : in a draw (svg) |
|
| 69 | + protected $_isAfterFloat = false; // flag : is just after a float |
|
| 70 | + protected $_isInForm = false; // flag : is in a float. false / action of the form |
|
| 71 | + protected $_isInLink = ''; // flag : is in a link. empty / href of the link |
|
| 72 | + protected $_isInParagraph = false; // flag : is in a paragraph |
|
| 73 | + protected $_isForOneLine = false; // flag : in a specific sub html2pdf to have the height of the next line |
|
| 74 | + |
|
| 75 | + protected $_maxX = 0; // maximum X of the current zone |
|
| 76 | + protected $_maxY = 0; // maximum Y of the current zone |
|
| 77 | + protected $_maxE = 0; // number of elements in the current zone |
|
| 78 | + protected $_maxH = 0; // maximum height of the line in the current zone |
|
| 79 | + protected $_maxSave = array(); // save the maximums of the current zone |
|
| 80 | + protected $_currentH = 0; // height of the current line |
|
| 81 | + |
|
| 82 | + protected $_defaultLeft = 0; // default marges of the page |
|
| 83 | + protected $_defaultTop = 0; |
|
| 84 | + protected $_defaultRight = 0; |
|
| 85 | + protected $_defaultBottom = 0; |
|
| 86 | + protected $_defaultFont = null; // default font to use, is the asked font does not exist |
|
| 87 | + |
|
| 88 | + protected $_margeLeft = 0; // current marges of the page |
|
| 89 | + protected $_margeTop = 0; |
|
| 90 | + protected $_margeRight = 0; |
|
| 91 | + protected $_margeBottom = 0; |
|
| 92 | + protected $_marges = array(); // save the different marges of the current page |
|
| 93 | + protected $_pageMarges = array(); // float marges of the current page |
|
| 94 | + protected $_background = array(); // background informations |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + protected $_firstPage = true; // flag : first page |
|
| 98 | + protected $_defList = array(); // table to save the stats of the tags UL and OL |
|
| 99 | + |
|
| 100 | + protected $_lstAnchor = array(); // list of the anchors |
|
| 101 | + protected $_lstField = array(); // list of the fields |
|
| 102 | + protected $_lstSelect = array(); // list of the options of the current select |
|
| 103 | + protected $_previousCall = null; // last action called |
|
| 104 | + |
|
| 105 | + protected $_debugActif = false; // flag : mode debug is active |
|
| 106 | + protected $_debugOkUsage = false; // flag : the function memory_get_usage exist |
|
| 107 | + protected $_debugOkPeak = false; // flag : the function memory_get_peak_usage exist |
|
| 108 | + protected $_debugLevel = 0; // level in the debug |
|
| 109 | + protected $_debugStartTime = 0; // debug start time |
|
| 110 | + protected $_debugLastTime = 0; // debug stop time |
|
| 111 | + |
|
| 112 | + static protected $_subobj = null; // object html2pdf prepared in order to accelerate the creation of sub html2pdf |
|
| 113 | + static protected $_tables = array(); // static table to prepare the nested html tables |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * class constructor |
|
| 117 | + * |
|
| 118 | + * @access public |
|
| 119 | + * @param string $orientation page orientation, same as TCPDF |
|
| 120 | + * @param string $format The format used for pages, same as TCPDF |
|
| 121 | + * @param $tring $langue Langue : fr, en, it... |
|
| 122 | + * @param boolean $unicode TRUE means that the input text is unicode (default = true) |
|
| 123 | + * @param String $encoding charset encoding; default is UTF-8 |
|
| 124 | + * @param integer[] $marges Default marges (left, top, right, bottom) |
|
| 125 | + * @return HTML2PDF $this |
|
| 126 | + */ |
|
| 127 | + public function __construct($orientation = 'P', $format = 'A4', $langue = 'en', $unicode = true, $encoding = 'UTF-8', $marges = array(5, 5, 5, 8)) |
|
| 128 | + { |
|
| 129 | + // init the page number |
|
| 130 | + $this->_page = 0; |
|
| 131 | + $this->_firstPage = true; |
|
| 132 | + |
|
| 133 | + // save the parameters |
|
| 134 | + $this->_orientation = $orientation; |
|
| 135 | + $this->_format = $format; |
|
| 136 | + $this->_langue = strtolower($langue); |
|
| 137 | + $this->_unicode = $unicode; |
|
| 138 | + $this->_encoding = $encoding; |
|
| 139 | + |
|
| 140 | + // load the Local |
|
| 141 | + HTML2PDF_locale::load($this->_langue); |
|
| 142 | + |
|
| 143 | + // create the HTML2PDF_myPdf object |
|
| 144 | + $this->pdf = new HTML2PDF_myPdf($orientation, 'mm', $format, $unicode, $encoding); |
|
| 145 | + |
|
| 146 | + // init the CSS parsing object |
|
| 147 | + $this->parsingCss = new HTML2PDF_parsingCss($this->pdf); |
|
| 148 | + $this->parsingCss->fontSet(); |
|
| 149 | + $this->_defList = array(); |
|
| 150 | + |
|
| 151 | + // init some tests |
|
| 152 | + $this->setTestTdInOnePage(true); |
|
| 153 | + $this->setTestIsImage(true); |
|
| 154 | + $this->setTestIsDeprecated(true); |
|
| 155 | + |
|
| 156 | + // init the default font |
|
| 157 | + $this->setDefaultFont(null); |
|
| 158 | + |
|
| 159 | + // init the HTML parsing object |
|
| 160 | + $this->parsingHtml = new HTML2PDF_parsingHtml($this->_encoding); |
|
| 161 | + $this->_subHtml = null; |
|
| 162 | + $this->_subPart = false; |
|
| 163 | + |
|
| 164 | + // init the marges of the page |
|
| 165 | + if ( ! is_array($marges)) $marges = array($marges, $marges, $marges, $marges); |
|
| 166 | + $this->_setDefaultMargins($marges[0], $marges[1], $marges[2], $marges[3]); |
|
| 167 | + $this->_setMargins(); |
|
| 168 | + $this->_marges = array(); |
|
| 169 | + |
|
| 170 | + // init the form's fields |
|
| 171 | + $this->_lstField = array(); |
|
| 172 | + |
|
| 173 | + return $this; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Destructor |
|
| 178 | + * |
|
| 179 | + * @access public |
|
| 180 | + * @return null |
|
| 181 | + */ |
|
| 182 | + public function __destruct() |
|
| 183 | + { |
|
| 184 | + |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Clone to create a sub HTML2PDF from HTML2PDF::$_subobj |
|
| 189 | + * |
|
| 190 | + * @access public |
|
| 191 | + */ |
|
| 192 | + public function __clone() |
|
| 193 | + { |
|
| 194 | + $this->pdf = clone $this->pdf; |
|
| 195 | + $this->parsingHtml = clone $this->parsingHtml; |
|
| 196 | + $this->parsingCss = clone $this->parsingCss; |
|
| 197 | + $this->parsingCss->setPdfParent($this->pdf); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * set the debug mode to On |
|
| 202 | + * |
|
| 203 | + * @access public |
|
| 204 | + * @return HTML2PDF $this |
|
| 205 | + */ |
|
| 206 | + public function setModeDebug() |
|
| 207 | + { |
|
| 208 | + $time = microtime(true); |
|
| 209 | + |
|
| 210 | + $this->_debugActif = true; |
|
| 211 | + $this->_debugOkUsage = function_exists('memory_get_usage'); |
|
| 212 | + $this->_debugOkPeak = function_exists('memory_get_peak_usage'); |
|
| 213 | + $this->_debugStartTime = $time; |
|
| 214 | + $this->_debugLastTime = $time; |
|
| 215 | + |
|
| 216 | + $this->_DEBUG_stepline('step', 'time', 'delta', 'memory', 'peak'); |
|
| 217 | + $this->_DEBUG_add('Init debug'); |
|
| 218 | + |
|
| 219 | + return $this; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Set the test of TD thdat can not take more than one page |
|
| 224 | + * |
|
| 225 | + * @access public |
|
| 226 | + * @param boolean $mode |
|
| 227 | + * @return HTML2PDF $this |
|
| 228 | + */ |
|
| 229 | + public function setTestTdInOnePage($mode = true) |
|
| 230 | + { |
|
| 231 | + $this->_testTdInOnepage = $mode ? true : false; |
|
| 232 | + |
|
| 233 | + return $this; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Set the test if the images exist or not |
|
| 238 | + * |
|
| 239 | + * @access public |
|
| 240 | + * @param boolean $mode |
|
| 241 | + * @return HTML2PDF $this |
|
| 242 | + */ |
|
| 243 | + public function setTestIsImage($mode = true) |
|
| 244 | + { |
|
| 245 | + $this->_testIsImage = $mode ? true : false; |
|
| 246 | + |
|
| 247 | + return $this; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Set the test on deprecated functions |
|
| 252 | + * |
|
| 253 | + * @access public |
|
| 254 | + * @param boolean $mode |
|
| 255 | + * @return HTML2PDF $this |
|
| 256 | + */ |
|
| 257 | + public function setTestIsDeprecated($mode = true) |
|
| 258 | + { |
|
| 259 | + $this->_testIsDeprecated = $mode ? true : false; |
|
| 260 | + |
|
| 261 | + return $this; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Set the default font to use, if no font is specify, or if the asked font does not exist |
|
| 266 | + * |
|
| 267 | + * @access public |
|
| 268 | + * @param string $default name of the default font to use. If null : Arial is no font is specify, and error if the asked font does not exist |
|
| 269 | + * @return HTML2PDF $this |
|
| 270 | + */ |
|
| 271 | + public function setDefaultFont($default = null) |
|
| 272 | + { |
|
| 273 | + $this->_defaultFont = $default; |
|
| 274 | + $this->parsingCss->setDefaultFont($default); |
|
| 275 | + |
|
| 276 | + return $this; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * add a font, see TCPDF function addFont |
|
| 281 | + * |
|
| 282 | + * @access public |
|
| 283 | + * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font. |
|
| 284 | + * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul> |
|
| 285 | + * @return HTML2PDF $this |
|
| 286 | + * @see TCPDF::addFont |
|
| 287 | + */ |
|
| 288 | + public function addFont($family, $style = '', $file = '') |
|
| 289 | + { |
|
| 290 | + $this->pdf->AddFont($family, $style, $file); |
|
| 291 | + |
|
| 292 | + return $this; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * display a automatic index, from the bookmarks |
|
| 297 | + * |
|
| 298 | + * @access public |
|
| 299 | + * @param string $titre index title |
|
| 300 | + * @param int $sizeTitle font size of the index title, in mm |
|
| 301 | + * @param int $sizeBookmark font size of the index, in mm |
|
| 302 | + * @param boolean $bookmarkTitle add a bookmark for the index, at his beginning |
|
| 303 | + * @param boolean $displayPage display the page numbers |
|
| 304 | + * @param int $onPage if null : at the end of the document on a new page, else on the $onPage page |
|
| 305 | + * @param string $fontName font name to use |
|
| 306 | + * @return null |
|
| 307 | + */ |
|
| 308 | + public function createIndex($titre = 'Index', $sizeTitle = 20, $sizeBookmark = 15, $bookmarkTitle = true, $displayPage = true, $onPage = null, $fontName = 'helvetica') |
|
| 309 | + { |
|
| 310 | + $oldPage = $this->_INDEX_NewPage($onPage); |
|
| 311 | + $this->pdf->createIndex($this, $titre, $sizeTitle, $sizeBookmark, $bookmarkTitle, $displayPage, $onPage, $fontName); |
|
| 312 | + if ($oldPage) { |
|
| 313 | + $this->pdf->setPage($oldPage); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * clean up the objects |
|
| 319 | + * |
|
| 320 | + * @access protected |
|
| 321 | + */ |
|
| 322 | + protected function _cleanUp() |
|
| 323 | + { |
|
| 324 | + HTML2PDF::$_subobj = null; |
|
| 325 | + HTML2PDF::$_tables = array(); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Send the document to a given destination: string, local file or browser. |
|
| 330 | + * Dest can be : |
|
| 331 | + * I : send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF. |
|
| 332 | + * D : send to the browser and force a file download with the name given by name. |
|
| 333 | + * F : save to a local server file with the name given by name. |
|
| 334 | + * S : return the document as a string. name is ignored. |
|
| 335 | + * FI: equivalent to F + I option |
|
| 336 | + * FD: equivalent to F + D option |
|
| 337 | + * true => I |
|
| 338 | + * false => S |
|
| 339 | + * |
|
| 340 | + * @param string $name The name of the file when saved. |
|
| 341 | + * @param string $dest Destination where to send the document. |
|
| 342 | + * @return string content of the PDF, if $dest=S |
|
| 343 | + * @see TCPDF::close |
|
| 344 | + * @access public |
|
| 345 | + */ |
|
| 346 | + public function Output($name = '', $dest = false) |
|
| 347 | + { |
|
| 348 | + // close the pdf and clean up |
|
| 349 | + $this->_cleanUp(); |
|
| 350 | + |
|
| 351 | + // if on debug mode |
|
| 352 | + if ($this->_debugActif) { |
|
| 353 | + $this->_DEBUG_add('Before output'); |
|
| 354 | + $this->pdf->Close(); |
|
| 355 | + exit; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + // complete parameters |
|
| 359 | + if ($dest === false) $dest = 'I'; |
|
| 360 | + if ($dest === true) $dest = 'S'; |
|
| 361 | + if ($dest === '') $dest = 'I'; |
|
| 362 | + if ($name == '') $name = 'document.pdf'; |
|
| 363 | + |
|
| 364 | + // clean up the destination |
|
| 365 | + $dest = strtoupper($dest); |
|
| 366 | + if ( ! in_array($dest, array('I', 'D', 'F', 'S', 'FI', 'FD'))) $dest = 'I'; |
|
| 367 | + |
|
| 368 | + // the name must be a PDF name |
|
| 369 | + if (strtolower(substr($name, -4)) != '.pdf') { |
|
| 370 | + throw new HTML2PDF_exception(0, 'The output document name "'.$name.'" is not a PDF name'); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + // call the output of TCPDF |
|
| 374 | + return $this->pdf->Output($name, $dest); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * convert HTML to PDF |
|
| 379 | + * |
|
| 380 | + * @access public |
|
| 381 | + * @param string $html |
|
| 382 | + * @param boolean $debugVue enable the HTML debug vue |
|
| 383 | + * @return null |
|
| 384 | + */ |
|
| 385 | + public function writeHTML($html, $debugVue = false) |
|
| 386 | + { |
|
| 387 | + // if it is a real html page, we have to convert it |
|
| 388 | + if (preg_match('/<body/isU', $html)) { |
|
| 389 | + $html = $this->getHtmlFromPage($html); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + $html = str_replace('[[date_y]]', date('Y'), $html); |
|
| 393 | + $html = str_replace('[[date_m]]', date('m'), $html); |
|
| 394 | + $html = str_replace('[[date_d]]', date('d'), $html); |
|
| 395 | + |
|
| 396 | + $html = str_replace('[[date_h]]', date('H'), $html); |
|
| 397 | + $html = str_replace('[[date_i]]', date('i'), $html); |
|
| 398 | + $html = str_replace('[[date_s]]', date('s'), $html); |
|
| 399 | + |
|
| 400 | + // If we are in HTML debug vue : display the HTML |
|
| 401 | + if ($debugVue) { |
|
| 402 | + return $this->_vueHTML($html); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + // convert HTMl to PDF |
|
| 406 | + $this->parsingCss->readStyle($html); |
|
| 407 | + $this->parsingHtml->setHTML($html); |
|
| 408 | + $this->parsingHtml->parse(); |
|
| 409 | + $this->_makeHTMLcode(); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * convert the HTML of a real page, to a code adapted to HTML2PDF |
|
| 414 | + * |
|
| 415 | + * @access public |
|
| 416 | + * @param string HTML of a real page |
|
| 417 | + * @param string $html |
|
| 418 | + * @return string HTML adapted to HTML2PDF |
|
| 419 | + */ |
|
| 420 | + public function getHtmlFromPage($html) |
|
| 421 | + { |
|
| 422 | + $html = str_replace('<BODY', '<body', $html); |
|
| 423 | + $html = str_replace('</BODY', '</body', $html); |
|
| 424 | + |
|
| 425 | + // extract the content |
|
| 426 | + $res = explode('<body', $html); |
|
| 427 | + if (count($res) < 2) return $html; |
|
| 428 | + $content = '<page'.$res[1]; |
|
| 429 | + $content = explode('</body', $content); |
|
| 430 | + $content = $content[0].'</page>'; |
|
| 431 | + |
|
| 432 | + // extract the link tags |
|
| 433 | + preg_match_all('/<link([^>]*)>/isU', $html, $match); |
|
| 434 | + foreach ($match[0] as $src) |
|
| 435 | + $content = $src.'</link>'.$content; |
|
| 436 | + |
|
| 437 | + // extract the css style tags |
|
| 438 | + preg_match_all('/<style[^>]*>(.*)<\/style[^>]*>/isU', $html, $match); |
|
| 439 | + foreach ($match[0] as $src) |
|
| 440 | + $content = $src.$content; |
|
| 441 | + |
|
| 442 | + return $content; |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * init a sub HTML2PDF. does not use it directly. Only the method createSubHTML must use it |
|
| 447 | + * |
|
| 448 | + * @access public |
|
| 449 | + * @param string $format |
|
| 450 | + * @param string $orientation |
|
| 451 | + * @param array $marge |
|
| 452 | + * @param integer $page |
|
| 453 | + * @param array $defLIST |
|
| 454 | + * @param integer $myLastPageGroup |
|
| 455 | + * @param integer $myLastPageGroupNb |
|
| 456 | + */ |
|
| 457 | + public function initSubHtml($format, $orientation, $marge, $page, $defLIST, $myLastPageGroup, $myLastPageGroupNb) |
|
| 458 | + { |
|
| 459 | + $this->_isSubPart = true; |
|
| 460 | + |
|
| 461 | + $this->parsingCss->setOnlyLeft(); |
|
| 462 | + |
|
| 463 | + $this->_setNewPage($format, $orientation, null, null, ($myLastPageGroup !== null)); |
|
| 464 | + |
|
| 465 | + $this->_saveMargin(0, 0, $marge); |
|
| 466 | + $this->_defList = $defLIST; |
|
| 467 | + |
|
| 468 | + $this->_page = $page; |
|
| 469 | + $this->pdf->setMyLastPageGroup($myLastPageGroup); |
|
| 470 | + $this->pdf->setMyLastPageGroupNb($myLastPageGroupNb); |
|
| 471 | + $this->pdf->setXY(0, 0); |
|
| 472 | + $this->parsingCss->fontSet(); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * display the content in HTML moden for debug |
|
| 477 | + * |
|
| 478 | + * @access protected |
|
| 479 | + * @param string $content |
|
| 480 | + */ |
|
| 481 | + protected function _vueHTML($content) |
|
| 482 | + { |
|
| 483 | + $content = preg_replace('/<page_header([^>]*)>/isU', '<hr>'.HTML2PDF_locale::get('vue01').' : $1<hr><div$1>', $content); |
|
| 484 | + $content = preg_replace('/<page_footer([^>]*)>/isU', '<hr>'.HTML2PDF_locale::get('vue02').' : $1<hr><div$1>', $content); |
|
| 485 | + $content = preg_replace('/<page([^>]*)>/isU', '<hr>'.HTML2PDF_locale::get('vue03').' : $1<hr><div$1>', $content); |
|
| 486 | + $content = preg_replace('/<\/page([^>]*)>/isU', '</div><hr>', $content); |
|
| 487 | + $content = preg_replace('/<bookmark([^>]*)>/isU', '<hr>bookmark : $1<hr>', $content); |
|
| 488 | + $content = preg_replace('/<\/bookmark([^>]*)>/isU', '', $content); |
|
| 489 | + $content = preg_replace('/<barcode([^>]*)>/isU', '<hr>barcode : $1<hr>', $content); |
|
| 490 | + $content = preg_replace('/<\/barcode([^>]*)>/isU', '', $content); |
|
| 491 | + $content = preg_replace('/<qrcode([^>]*)>/isU', '<hr>qrcode : $1<hr>', $content); |
|
| 492 | + $content = preg_replace('/<\/qrcode([^>]*)>/isU', '', $content); |
|
| 493 | + |
|
| 494 | + echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
|
| 496 | 495 | <html> |
| 497 | 496 | <head> |
| 498 | 497 | <title>'.HTML2PDF_locale::get('vue04').' HTML</title> |
@@ -502,6113 +501,6113 @@ discard block |
||
| 502 | 501 | '.$content.' |
| 503 | 502 | </body> |
| 504 | 503 | </html>'; |
| 505 | - exit; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * set the default margins of the page |
|
| 510 | - * |
|
| 511 | - * @access protected |
|
| 512 | - * @param int $left (mm, left margin) |
|
| 513 | - * @param int $top (mm, top margin) |
|
| 514 | - * @param int $right (mm, right margin, if null => left=right) |
|
| 515 | - * @param int $bottom (mm, bottom margin, if null => bottom=8mm) |
|
| 516 | - */ |
|
| 517 | - protected function _setDefaultMargins($left, $top, $right = null, $bottom = null) |
|
| 518 | - { |
|
| 519 | - if ($right === null) $right = $left; |
|
| 520 | - if ($bottom === null) $bottom = 8; |
|
| 521 | - |
|
| 522 | - $this->_defaultLeft = $this->parsingCss->ConvertToMM($left.'mm'); |
|
| 523 | - $this->_defaultTop = $this->parsingCss->ConvertToMM($top.'mm'); |
|
| 524 | - $this->_defaultRight = $this->parsingCss->ConvertToMM($right.'mm'); |
|
| 525 | - $this->_defaultBottom = $this->parsingCss->ConvertToMM($bottom.'mm'); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * create a new page |
|
| 530 | - * |
|
| 531 | - * @access protected |
|
| 532 | - * @param mixed $format |
|
| 533 | - * @param string $orientation |
|
| 534 | - * @param array $background background information |
|
| 535 | - * @param integer $curr real position in the html parseur (if break line in the write of a text) |
|
| 536 | - * @param boolean $resetPageNumber |
|
| 537 | - */ |
|
| 538 | - protected function _setNewPage($format = null, $orientation = '', $background = null, $curr = null, $resetPageNumber = false) |
|
| 539 | - { |
|
| 540 | - $this->_firstPage = false; |
|
| 541 | - |
|
| 542 | - $this->_format = $format ? $format : $this->_format; |
|
| 543 | - $this->_orientation = $orientation ? $orientation : $this->_orientation; |
|
| 544 | - $this->_background = $background !== null ? $background : $this->_background; |
|
| 545 | - $this->_maxY = 0; |
|
| 546 | - $this->_maxX = 0; |
|
| 547 | - $this->_maxH = 0; |
|
| 548 | - $this->_maxE = 0; |
|
| 549 | - |
|
| 550 | - $this->pdf->SetMargins($this->_defaultLeft, $this->_defaultTop, $this->_defaultRight); |
|
| 551 | - |
|
| 552 | - if ($resetPageNumber) { |
|
| 553 | - $this->pdf->startPageGroup(); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - $this->pdf->AddPage($this->_orientation, $this->_format); |
|
| 557 | - |
|
| 558 | - if ($resetPageNumber) { |
|
| 559 | - $this->pdf->myStartPageGroup(); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - $this->_page++; |
|
| 563 | - |
|
| 564 | - if ( ! $this->_subPart && ! $this->_isSubPart) { |
|
| 565 | - if (is_array($this->_background)) { |
|
| 566 | - if (isset($this->_background['color']) && $this->_background['color']) { |
|
| 567 | - $this->pdf->setFillColorArray($this->_background['color']); |
|
| 568 | - $this->pdf->Rect(0, 0, $this->pdf->getW(), $this->pdf->getH(), 'F'); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - if (isset($this->_background['img']) && $this->_background['img']) { |
|
| 572 | - $this->pdf->Image($this->_background['img'], $this->_background['posX'], $this->_background['posY'], $this->_background['width']); |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - $this->_setPageHeader(); |
|
| 577 | - $this->_setPageFooter(); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - $this->_setMargins(); |
|
| 581 | - $this->pdf->setY($this->_margeTop); |
|
| 582 | - |
|
| 583 | - $this->_setNewPositionForNewLine($curr); |
|
| 584 | - $this->_maxH = 0; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * set the real margin, using the default margins and the page margins |
|
| 589 | - * |
|
| 590 | - * @access protected |
|
| 591 | - */ |
|
| 592 | - protected function _setMargins() |
|
| 593 | - { |
|
| 594 | - // prepare the margins |
|
| 595 | - $this->_margeLeft = $this->_defaultLeft + (isset($this->_background['left']) ? $this->_background['left'] : 0); |
|
| 596 | - $this->_margeRight = $this->_defaultRight + (isset($this->_background['right']) ? $this->_background['right'] : 0); |
|
| 597 | - $this->_margeTop = $this->_defaultTop + (isset($this->_background['top']) ? $this->_background['top'] : 0); |
|
| 598 | - $this->_margeBottom = $this->_defaultBottom + (isset($this->_background['bottom']) ? $this->_background['bottom'] : 0); |
|
| 599 | - |
|
| 600 | - // set the PDF margins |
|
| 601 | - $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight); |
|
| 602 | - $this->pdf->SetAutoPageBreak(false, $this->_margeBottom); |
|
| 603 | - |
|
| 604 | - // set the float Margins |
|
| 605 | - $this->_pageMarges = array(); |
|
| 606 | - if ($this->_isInParagraph !== false) { |
|
| 607 | - $this->_pageMarges[floor($this->_margeTop * 100)] = array($this->_isInParagraph[0], $this->pdf->getW() - $this->_isInParagraph[1]); |
|
| 608 | - } else { |
|
| 609 | - $this->_pageMarges[floor($this->_margeTop * 100)] = array($this->_margeLeft, $this->pdf->getW() - $this->_margeRight); |
|
| 610 | - } |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * add a debug step |
|
| 615 | - * |
|
| 616 | - * @access protected |
|
| 617 | - * @param string $name step name |
|
| 618 | - * @param boolean $level (true=up, false=down, null=nothing to do) |
|
| 619 | - * @return $this |
|
| 620 | - */ |
|
| 621 | - protected function _DEBUG_add($name, $level = null) |
|
| 622 | - { |
|
| 623 | - // if true : UP |
|
| 624 | - if ($level === true) $this->_debugLevel++; |
|
| 625 | - |
|
| 626 | - $name = str_repeat(' ', $this->_debugLevel).$name.($level === true ? ' Begin' : ($level === false ? ' End' : '')); |
|
| 627 | - $time = microtime(true); |
|
| 628 | - $usage = ($this->_debugOkUsage ? memory_get_usage() : 0); |
|
| 629 | - $peak = ($this->_debugOkPeak ? memory_get_peak_usage() : 0); |
|
| 630 | - |
|
| 631 | - $this->_DEBUG_stepline( |
|
| 632 | - $name, |
|
| 633 | - number_format(($time - $this->_debugStartTime) * 1000, 1, '.', ' ').' ms', |
|
| 634 | - number_format(($time - $this->_debugLastTime) * 1000, 1, '.', ' ').' ms', |
|
| 635 | - number_format($usage / 1024, 1, '.', ' ').' Ko', |
|
| 636 | - number_format($peak / 1024, 1, '.', ' ').' Ko' |
|
| 637 | - ); |
|
| 638 | - |
|
| 639 | - $this->_debugLastTime = $time; |
|
| 640 | - |
|
| 641 | - // it false : DOWN |
|
| 642 | - if ($level === false) $this->_debugLevel--; |
|
| 643 | - |
|
| 644 | - return $this; |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * display a debug line |
|
| 649 | - * |
|
| 650 | - * |
|
| 651 | - * @access protected |
|
| 652 | - * @param string $name |
|
| 653 | - * @param string $timeTotal |
|
| 654 | - * @param string $timeStep |
|
| 655 | - * @param string $memoryUsage |
|
| 656 | - * @param string $memoryPeak |
|
| 657 | - */ |
|
| 658 | - protected function _DEBUG_stepline($name, $timeTotal, $timeStep, $memoryUsage, $memoryPeak) |
|
| 659 | - { |
|
| 660 | - $txt = str_pad($name, 30, ' ', STR_PAD_RIGHT). |
|
| 661 | - str_pad($timeTotal, 12, ' ', STR_PAD_LEFT). |
|
| 662 | - str_pad($timeStep, 12, ' ', STR_PAD_LEFT). |
|
| 663 | - str_pad($memoryUsage, 15, ' ', STR_PAD_LEFT). |
|
| 664 | - str_pad($memoryPeak, 15, ' ', STR_PAD_LEFT); |
|
| 665 | - |
|
| 666 | - echo '<pre style="padding:0; margin:0">'.$txt.'</pre>'; |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - /** |
|
| 670 | - * get the Min and Max X, for Y (use the float margins) |
|
| 671 | - * |
|
| 672 | - * @access protected |
|
| 673 | - * @param float $y |
|
| 674 | - * @return array(float, float) |
|
| 675 | - */ |
|
| 676 | - protected function _getMargins($y) |
|
| 677 | - { |
|
| 678 | - $y = floor($y * 100); |
|
| 679 | - $x = array($this->pdf->getlMargin(), $this->pdf->getW() - $this->pdf->getrMargin()); |
|
| 680 | - |
|
| 681 | - foreach ($this->_pageMarges as $mY => $mX) |
|
| 682 | - if ($mY <= $y) $x = $mX; |
|
| 683 | - |
|
| 684 | - return $x; |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - /** |
|
| 688 | - * Add margins, for a float |
|
| 689 | - * |
|
| 690 | - * @access protected |
|
| 691 | - * @param string $float (left / right) |
|
| 692 | - * @param float $xLeft |
|
| 693 | - * @param float $yTop |
|
| 694 | - * @param float $xRight |
|
| 695 | - * @param float $yBottom |
|
| 696 | - */ |
|
| 697 | - protected function _addMargins($float, $xLeft, $yTop, $xRight, $yBottom) |
|
| 698 | - { |
|
| 699 | - // get the current float margins, for top and bottom |
|
| 700 | - $oldTop = $this->_getMargins($yTop); |
|
| 701 | - $oldBottom = $this->_getMargins($yBottom); |
|
| 702 | - |
|
| 703 | - // update the top float margin |
|
| 704 | - if ($float == 'left' && $oldTop[0] < $xRight) $oldTop[0] = $xRight; |
|
| 705 | - if ($float == 'right' && $oldTop[1] > $xLeft) $oldTop[1] = $xLeft; |
|
| 706 | - |
|
| 707 | - $yTop = floor($yTop * 100); |
|
| 708 | - $yBottom = floor($yBottom * 100); |
|
| 709 | - |
|
| 710 | - // erase all the float margins that are smaller than the new one |
|
| 711 | - foreach ($this->_pageMarges as $mY => $mX) { |
|
| 712 | - if ($mY < $yTop) continue; |
|
| 713 | - if ($mY > $yBottom) break; |
|
| 714 | - if ($float == 'left' && $this->_pageMarges[$mY][0] < $xRight) unset($this->_pageMarges[$mY]); |
|
| 715 | - if ($float == 'right' && $this->_pageMarges[$mY][1] > $xLeft) unset($this->_pageMarges[$mY]); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - // save the new Top and Bottom margins |
|
| 719 | - $this->_pageMarges[$yTop] = $oldTop; |
|
| 720 | - $this->_pageMarges[$yBottom] = $oldBottom; |
|
| 721 | - |
|
| 722 | - // sort the margins |
|
| 723 | - ksort($this->_pageMarges); |
|
| 724 | - |
|
| 725 | - // we are just after float |
|
| 726 | - $this->_isAfterFloat = true; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * Save old margins (push), and set new ones |
|
| 731 | - * |
|
| 732 | - * @access protected |
|
| 733 | - * @param float $ml left margin |
|
| 734 | - * @param float $mt top margin |
|
| 735 | - * @param float $mr right margin |
|
| 736 | - */ |
|
| 737 | - protected function _saveMargin($ml, $mt, $mr) |
|
| 738 | - { |
|
| 739 | - // save old margins |
|
| 740 | - $this->_marges[] = array('l' => $this->pdf->getlMargin(), 't' => $this->pdf->gettMargin(), 'r' => $this->pdf->getrMargin(), 'page' => $this->_pageMarges); |
|
| 741 | - |
|
| 742 | - // set new ones |
|
| 743 | - $this->pdf->SetMargins($ml, $mt, $mr); |
|
| 744 | - |
|
| 745 | - // prepare for float margins |
|
| 746 | - $this->_pageMarges = array(); |
|
| 747 | - $this->_pageMarges[floor($mt * 100)] = array($ml, $this->pdf->getW() - $mr); |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * load the last saved margins (pop) |
|
| 752 | - * |
|
| 753 | - * @access protected |
|
| 754 | - */ |
|
| 755 | - protected function _loadMargin() |
|
| 756 | - { |
|
| 757 | - $old = array_pop($this->_marges); |
|
| 758 | - if ($old) { |
|
| 759 | - $ml = $old['l']; |
|
| 760 | - $mt = $old['t']; |
|
| 761 | - $mr = $old['r']; |
|
| 762 | - $mP = $old['page']; |
|
| 763 | - } else { |
|
| 764 | - $ml = $this->_margeLeft; |
|
| 765 | - $mt = 0; |
|
| 766 | - $mr = $this->_margeRight; |
|
| 767 | - $mP = array($mt => array($ml, $this->pdf->getW() - $mr)); |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - $this->pdf->SetMargins($ml, $mt, $mr); |
|
| 771 | - $this->_pageMarges = $mP; |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - /** |
|
| 775 | - * save the current maxs (push) |
|
| 776 | - * |
|
| 777 | - * @access protected |
|
| 778 | - */ |
|
| 779 | - protected function _saveMax() |
|
| 780 | - { |
|
| 781 | - $this->_maxSave[] = array($this->_maxX, $this->_maxY, $this->_maxH, $this->_maxE); |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - /** |
|
| 785 | - * load the last saved current maxs (pop) |
|
| 786 | - * |
|
| 787 | - * @access protected |
|
| 788 | - */ |
|
| 789 | - protected function _loadMax() |
|
| 790 | - { |
|
| 791 | - $old = array_pop($this->_maxSave); |
|
| 792 | - |
|
| 793 | - if ($old) { |
|
| 794 | - $this->_maxX = $old[0]; |
|
| 795 | - $this->_maxY = $old[1]; |
|
| 796 | - $this->_maxH = $old[2]; |
|
| 797 | - $this->_maxE = $old[3]; |
|
| 798 | - } else { |
|
| 799 | - $this->_maxX = 0; |
|
| 800 | - $this->_maxY = 0; |
|
| 801 | - $this->_maxH = 0; |
|
| 802 | - $this->_maxE = 0; |
|
| 803 | - } |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - /** |
|
| 807 | - * draw the PDF header with the HTML in page_header |
|
| 808 | - * |
|
| 809 | - * @access protected |
|
| 810 | - */ |
|
| 811 | - protected function _setPageHeader() |
|
| 812 | - { |
|
| 813 | - if ( ! count($this->_subHEADER)) return false; |
|
| 814 | - |
|
| 815 | - $oldParsePos = $this->_parsePos; |
|
| 816 | - $oldParseCode = $this->parsingHtml->code; |
|
| 817 | - |
|
| 818 | - $this->_parsePos = 0; |
|
| 819 | - $this->parsingHtml->code = $this->_subHEADER; |
|
| 820 | - $this->_makeHTMLcode(); |
|
| 821 | - |
|
| 822 | - $this->_parsePos = $oldParsePos; |
|
| 823 | - $this->parsingHtml->code = $oldParseCode; |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - /** |
|
| 827 | - * draw the PDF footer with the HTML in page_footer |
|
| 828 | - * |
|
| 829 | - * @access protected |
|
| 830 | - */ |
|
| 831 | - protected function _setPageFooter() |
|
| 832 | - { |
|
| 833 | - if ( ! count($this->_subFOOTER)) return false; |
|
| 834 | - |
|
| 835 | - $oldParsePos = $this->_parsePos; |
|
| 836 | - $oldParseCode = $this->parsingHtml->code; |
|
| 837 | - |
|
| 838 | - $this->_parsePos = 0; |
|
| 839 | - $this->parsingHtml->code = $this->_subFOOTER; |
|
| 840 | - $this->_isInFooter = true; |
|
| 841 | - $this->_makeHTMLcode(); |
|
| 842 | - $this->_isInFooter = false; |
|
| 843 | - |
|
| 844 | - $this->_parsePos = $oldParsePos; |
|
| 845 | - $this->parsingHtml->code = $oldParseCode; |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * new line, with a specific height |
|
| 850 | - * |
|
| 851 | - * @access protected |
|
| 852 | - * @param float $h |
|
| 853 | - * @param integer $curr real current position in the text, if new line in the write of a text |
|
| 854 | - */ |
|
| 855 | - protected function _setNewLine($h, $curr = null) |
|
| 856 | - { |
|
| 857 | - $this->pdf->Ln($h); |
|
| 858 | - $this->_setNewPositionForNewLine($curr); |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - /** |
|
| 862 | - * calculate the start position of the next line, depending on the text-align |
|
| 863 | - * |
|
| 864 | - * @access protected |
|
| 865 | - * @param integer $curr real current position in the text, if new line in the write of a text |
|
| 866 | - */ |
|
| 867 | - protected function _setNewPositionForNewLine($curr = null) |
|
| 868 | - { |
|
| 869 | - // get the margins for the current line |
|
| 870 | - list($lx, $rx) = $this->_getMargins($this->pdf->getY()); |
|
| 871 | - $this->pdf->setX($lx); |
|
| 872 | - $wMax = $rx - $lx; |
|
| 873 | - $this->_currentH = 0; |
|
| 874 | - |
|
| 875 | - // if subPart => return because align left |
|
| 876 | - if ($this->_subPart || $this->_isSubPart || $this->_isForOneLine) { |
|
| 877 | - $this->pdf->setWordSpacing(0); |
|
| 878 | - return null; |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - // create the sub object |
|
| 882 | - $sub = null; |
|
| 883 | - $this->_createSubHTML($sub); |
|
| 884 | - $sub->_saveMargin(0, 0, $sub->pdf->getW() - $wMax); |
|
| 885 | - $sub->_isForOneLine = true; |
|
| 886 | - $sub->_parsePos = $this->_parsePos; |
|
| 887 | - $sub->parsingHtml->code = $this->parsingHtml->code; |
|
| 888 | - |
|
| 889 | - // if $curr => adapt the current position of the parsing |
|
| 890 | - if ($curr !== null && $sub->parsingHtml->code[$this->_parsePos]['name'] == 'write') { |
|
| 891 | - $txt = $sub->parsingHtml->code[$this->_parsePos]['param']['txt']; |
|
| 892 | - $txt = str_replace('[[page_cu]]', $sub->pdf->getMyNumPage($this->_page), $txt); |
|
| 893 | - $sub->parsingHtml->code[$this->_parsePos]['param']['txt'] = substr($txt, $curr + 1); |
|
| 894 | - } else |
|
| 895 | - $sub->_parsePos++; |
|
| 896 | - |
|
| 897 | - // for each element of the parsing => load the action |
|
| 898 | - $res = null; |
|
| 899 | - for ($sub->_parsePos; $sub->_parsePos < count($sub->parsingHtml->code); $sub->_parsePos++) { |
|
| 900 | - $action = $sub->parsingHtml->code[$sub->_parsePos]; |
|
| 901 | - $res = $sub->_executeAction($action); |
|
| 902 | - if ( ! $res) break; |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - $w = $sub->_maxX; // max width |
|
| 906 | - $h = $sub->_maxH; // max height |
|
| 907 | - $e = ($res === null ? $sub->_maxE : 0); // maxnumber of elemets on the line |
|
| 908 | - |
|
| 909 | - // destroy the sub HTML |
|
| 910 | - $this->_destroySubHTML($sub); |
|
| 911 | - |
|
| 912 | - // adapt the start of the line, depending on the text-align |
|
| 913 | - if ($this->parsingCss->value['text-align'] == 'center') |
|
| 914 | - $this->pdf->setX(($rx + $this->pdf->getX() - $w) * 0.5 - 0.01); |
|
| 915 | - else if ($this->parsingCss->value['text-align'] == 'right') |
|
| 916 | - $this->pdf->setX($rx - $w - 0.01); |
|
| 917 | - else |
|
| 918 | - $this->pdf->setX($lx); |
|
| 919 | - |
|
| 920 | - // set the height of the line |
|
| 921 | - $this->_currentH = $h; |
|
| 922 | - |
|
| 923 | - // if justify => set the word spacing |
|
| 924 | - if ($this->parsingCss->value['text-align'] == 'justify' && $e > 1) { |
|
| 925 | - $this->pdf->setWordSpacing(($wMax - $w) / ($e - 1)); |
|
| 926 | - } else { |
|
| 927 | - $this->pdf->setWordSpacing(0); |
|
| 928 | - } |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - /** |
|
| 932 | - * prepare HTML2PDF::$_subobj (used for create the sub HTML2PDF objects |
|
| 933 | - * |
|
| 934 | - * @access protected |
|
| 935 | - */ |
|
| 936 | - protected function _prepareSubObj() |
|
| 937 | - { |
|
| 938 | - $pdf = null; |
|
| 939 | - |
|
| 940 | - // create the sub object |
|
| 941 | - HTML2PDF::$_subobj = new HTML2PDF( |
|
| 942 | - $this->_orientation, |
|
| 943 | - $this->_format, |
|
| 944 | - $this->_langue, |
|
| 945 | - $this->_unicode, |
|
| 946 | - $this->_encoding, |
|
| 947 | - array($this->_defaultLeft, $this->_defaultTop, $this->_defaultRight, $this->_defaultBottom) |
|
| 948 | - ); |
|
| 949 | - |
|
| 950 | - // init |
|
| 951 | - HTML2PDF::$_subobj->setTestTdInOnePage($this->_testTdInOnepage); |
|
| 952 | - HTML2PDF::$_subobj->setTestIsImage($this->_testIsImage); |
|
| 953 | - HTML2PDF::$_subobj->setTestIsDeprecated($this->_testIsDeprecated); |
|
| 954 | - HTML2PDF::$_subobj->setDefaultFont($this->_defaultFont); |
|
| 955 | - HTML2PDF::$_subobj->parsingCss->css = &$this->parsingCss->css; |
|
| 956 | - HTML2PDF::$_subobj->parsingCss->cssKeys = &$this->parsingCss->cssKeys; |
|
| 957 | - |
|
| 958 | - // clone font from the original PDF |
|
| 959 | - HTML2PDF::$_subobj->pdf->cloneFontFrom($this->pdf); |
|
| 960 | - |
|
| 961 | - // remove the link to the parent |
|
| 962 | - HTML2PDF::$_subobj->parsingCss->setPdfParent($pdf); |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - /** |
|
| 966 | - * create a sub HTML2PDF, to calculate the multi-tables |
|
| 967 | - * |
|
| 968 | - * @access protected |
|
| 969 | - * @param &HTML2PDF $subHtml sub HTML2PDF to create |
|
| 970 | - * @param integer $cellmargin if in a TD : cellmargin of this td |
|
| 971 | - */ |
|
| 972 | - protected function _createSubHTML(&$subHtml, $cellmargin = 0) |
|
| 973 | - { |
|
| 974 | - // prepare the subObject, if never prepare before |
|
| 975 | - if (HTML2PDF::$_subobj === null) { |
|
| 976 | - $this->_prepareSubObj(); |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - // calculate the width to use |
|
| 980 | - if ($this->parsingCss->value['width']) { |
|
| 981 | - $marge = $cellmargin * 2; |
|
| 982 | - $marge += $this->parsingCss->value['padding']['l'] + $this->parsingCss->value['padding']['r']; |
|
| 983 | - $marge += $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['border']['r']['width']; |
|
| 984 | - $marge = $this->pdf->getW() - $this->parsingCss->value['width'] + $marge; |
|
| 985 | - } else { |
|
| 986 | - $marge = $this->_margeLeft + $this->_margeRight; |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - // BUGFIX : we have to call the method, because of a bug in php 5.1.6 |
|
| 990 | - HTML2PDF::$_subobj->pdf->getPage(); |
|
| 991 | - |
|
| 992 | - // clone the sub oject |
|
| 993 | - $subHtml = clone HTML2PDF::$_subobj; |
|
| 994 | - $subHtml->parsingCss->table = $this->parsingCss->table; |
|
| 995 | - $subHtml->parsingCss->value = $this->parsingCss->value; |
|
| 996 | - $subHtml->initSubHtml( |
|
| 997 | - $this->_format, |
|
| 998 | - $this->_orientation, |
|
| 999 | - $marge, |
|
| 1000 | - $this->_page, |
|
| 1001 | - $this->_defList, |
|
| 1002 | - $this->pdf->getMyLastPageGroup(), |
|
| 1003 | - $this->pdf->getMyLastPageGroupNb() |
|
| 1004 | - ); |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - /** |
|
| 1008 | - * destroy a subHTML2PDF |
|
| 1009 | - * |
|
| 1010 | - * @access protected |
|
| 1011 | - */ |
|
| 1012 | - protected function _destroySubHTML(&$subHtml) |
|
| 1013 | - { |
|
| 1014 | - unset($subHtml); |
|
| 1015 | - $subHtml = null; |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - /** |
|
| 1019 | - * Convert a arabic number in roman number |
|
| 1020 | - * |
|
| 1021 | - * @access protected |
|
| 1022 | - * @param integer $nbArabic |
|
| 1023 | - * @return string $nbRoman |
|
| 1024 | - */ |
|
| 1025 | - protected function _listeArab2Rom($nbArabic) |
|
| 1026 | - { |
|
| 1027 | - $nbBaseTen = array('I', 'X', 'C', 'M'); |
|
| 1028 | - $nbBaseFive = array('V', 'L', 'D'); |
|
| 1029 | - $nbRoman = ''; |
|
| 1030 | - |
|
| 1031 | - if ($nbArabic < 1) return $nbArabic; |
|
| 1032 | - if ($nbArabic > 3999) return $nbArabic; |
|
| 1033 | - |
|
| 1034 | - for ($i = 3; $i >= 0; $i--) { |
|
| 1035 | - $chiffre = floor($nbArabic / pow(10, $i)); |
|
| 1036 | - if ($chiffre >= 1) { |
|
| 1037 | - $nbArabic = $nbArabic - $chiffre * pow(10, $i); |
|
| 1038 | - if ($chiffre <= 3) { |
|
| 1039 | - for ($j = $chiffre; $j >= 1; $j--) { |
|
| 1040 | - $nbRoman = $nbRoman.$nbBaseTen[$i]; |
|
| 1041 | - } |
|
| 1042 | - } else if ($chiffre == 9) { |
|
| 1043 | - $nbRoman = $nbRoman.$nbBaseTen[$i].$nbBaseTen[$i + 1]; |
|
| 1044 | - } else if ($chiffre == 4) { |
|
| 1045 | - $nbRoman = $nbRoman.$nbBaseTen[$i].$nbBaseFive[$i]; |
|
| 1046 | - } else { |
|
| 1047 | - $nbRoman = $nbRoman.$nbBaseFive[$i]; |
|
| 1048 | - for ($j = $chiffre - 5; $j >= 1; $j--) { |
|
| 1049 | - $nbRoman = $nbRoman.$nbBaseTen[$i]; |
|
| 1050 | - } |
|
| 1051 | - } |
|
| 1052 | - } |
|
| 1053 | - } |
|
| 1054 | - return $nbRoman; |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - /** |
|
| 1058 | - * add a LI to the current level |
|
| 1059 | - * |
|
| 1060 | - * @access protected |
|
| 1061 | - */ |
|
| 1062 | - protected function _listeAddLi() |
|
| 1063 | - { |
|
| 1064 | - $this->_defList[count($this->_defList) - 1]['nb']++; |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - /** |
|
| 1068 | - * get the width to use for the column of the list |
|
| 1069 | - * |
|
| 1070 | - * @access protected |
|
| 1071 | - * @return string $width |
|
| 1072 | - */ |
|
| 1073 | - protected function _listeGetWidth() |
|
| 1074 | - { |
|
| 1075 | - return '7mm'; |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - /** |
|
| 1079 | - * get the padding to use for the column of the list |
|
| 1080 | - * |
|
| 1081 | - * @access protected |
|
| 1082 | - * @return string $padding |
|
| 1083 | - */ |
|
| 1084 | - protected function _listeGetPadding() |
|
| 1085 | - { |
|
| 1086 | - return '1mm'; |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - /** |
|
| 1090 | - * get the information of the li on the current level |
|
| 1091 | - * |
|
| 1092 | - * @access protected |
|
| 1093 | - * @return array(fontName, small size, string) |
|
| 1094 | - */ |
|
| 1095 | - protected function _listeGetLi() |
|
| 1096 | - { |
|
| 1097 | - $im = $this->_defList[count($this->_defList) - 1]['img']; |
|
| 1098 | - $st = $this->_defList[count($this->_defList) - 1]['style']; |
|
| 1099 | - $nb = $this->_defList[count($this->_defList) - 1]['nb']; |
|
| 1100 | - $up = (substr($st, 0, 6) == 'upper-'); |
|
| 1101 | - |
|
| 1102 | - if ($im) { |
|
| 1103 | - return array(false, false, $im); |
|
| 1104 | - } |
|
| 1105 | - |
|
| 1106 | - switch ($st) |
|
| 1107 | - { |
|
| 1108 | - case 'none': |
|
| 1109 | - return array('helvetica', true, ' '); |
|
| 1110 | - |
|
| 1111 | - case 'upper-alpha': |
|
| 1112 | - case 'lower-alpha': |
|
| 1113 | - $str = ''; |
|
| 1114 | - while ($nb > 26) { |
|
| 1115 | - $str = chr(96 + $nb % 26).$str; |
|
| 1116 | - $nb = floor($nb / 26); |
|
| 1117 | - } |
|
| 1118 | - $str = chr(96 + $nb).$str; |
|
| 1119 | - |
|
| 1120 | - return array('helvetica', false, ($up ? strtoupper($str) : $str).'.'); |
|
| 1121 | - |
|
| 1122 | - case 'upper-roman': |
|
| 1123 | - case 'lower-roman': |
|
| 1124 | - $str = $this->_listeArab2Rom($nb); |
|
| 1125 | - |
|
| 1126 | - return array('helvetica', false, ($up ? strtoupper($str) : $str).'.'); |
|
| 1127 | - |
|
| 1128 | - case 'decimal': |
|
| 1129 | - return array('helvetica', false, $nb.'.'); |
|
| 1130 | - |
|
| 1131 | - case 'square': |
|
| 1132 | - return array('zapfdingbats', true, chr(110)); |
|
| 1133 | - |
|
| 1134 | - case 'circle': |
|
| 1135 | - return array('zapfdingbats', true, chr(109)); |
|
| 1136 | - |
|
| 1137 | - case 'disc': |
|
| 1138 | - default: |
|
| 1139 | - return array('zapfdingbats', true, chr(108)); |
|
| 1140 | - } |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - /** |
|
| 1144 | - * add a level to the list |
|
| 1145 | - * |
|
| 1146 | - * @access protected |
|
| 1147 | - * @param string $type : ul, ol |
|
| 1148 | - * @param string $style : lower-alpha, ... |
|
| 1149 | - * @param string $img |
|
| 1150 | - */ |
|
| 1151 | - protected function _listeAddLevel($type = 'ul', $style = '', $img = null) |
|
| 1152 | - { |
|
| 1153 | - // get the url of the image, if we want to use a image |
|
| 1154 | - if ($img) { |
|
| 1155 | - if (preg_match('/^url\(([^)]+)\)$/isU', trim($img), $match)) { |
|
| 1156 | - $img = $match[1]; |
|
| 1157 | - } else { |
|
| 1158 | - $img = null; |
|
| 1159 | - } |
|
| 1160 | - } else { |
|
| 1161 | - $img = null; |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - // prepare the datas |
|
| 1165 | - if ( ! in_array($type, array('ul', 'ol'))) $type = 'ul'; |
|
| 1166 | - if ( ! in_array($style, array('lower-alpha', 'upper-alpha', 'upper-roman', 'lower-roman', 'decimal', 'square', 'circle', 'disc', 'none'))) $style = ''; |
|
| 1167 | - |
|
| 1168 | - if ( ! $style) { |
|
| 1169 | - if ($type == 'ul') $style = 'disc'; |
|
| 1170 | - else $style = 'decimal'; |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - // add the new level |
|
| 1174 | - $this->_defList[count($this->_defList)] = array('style' => $style, 'nb' => 0, 'img' => $img); |
|
| 1175 | - } |
|
| 1176 | - |
|
| 1177 | - /** |
|
| 1178 | - * remove a level to the list |
|
| 1179 | - * |
|
| 1180 | - * @access protected |
|
| 1181 | - */ |
|
| 1182 | - protected function _listeDelLevel() |
|
| 1183 | - { |
|
| 1184 | - if (count($this->_defList)) { |
|
| 1185 | - unset($this->_defList[count($this->_defList) - 1]); |
|
| 1186 | - $this->_defList = array_values($this->_defList); |
|
| 1187 | - } |
|
| 1188 | - } |
|
| 1189 | - |
|
| 1190 | - /** |
|
| 1191 | - * execute the actions to convert the html |
|
| 1192 | - * |
|
| 1193 | - * @access protected |
|
| 1194 | - */ |
|
| 1195 | - protected function _makeHTMLcode() |
|
| 1196 | - { |
|
| 1197 | - // foreach elements of the parsing |
|
| 1198 | - for ($this->_parsePos = 0; $this->_parsePos < count($this->parsingHtml->code); $this->_parsePos++) { |
|
| 1199 | - |
|
| 1200 | - // get the action to do |
|
| 1201 | - $action = $this->parsingHtml->code[$this->_parsePos]; |
|
| 1202 | - |
|
| 1203 | - // if it is a opening of table / ul / ol |
|
| 1204 | - if (in_array($action['name'], array('table', 'ul', 'ol')) && ! $action['close']) { |
|
| 1205 | - |
|
| 1206 | - // we will work as a sub HTML to calculate the size of the element |
|
| 1207 | - $this->_subPart = true; |
|
| 1208 | - |
|
| 1209 | - // get the name of the opening tag |
|
| 1210 | - $tagOpen = $action['name']; |
|
| 1211 | - |
|
| 1212 | - // save the actual pos on the parsing |
|
| 1213 | - $this->_tempPos = $this->_parsePos; |
|
| 1214 | - |
|
| 1215 | - // foreach elements, while we are in the opened tag |
|
| 1216 | - while (isset($this->parsingHtml->code[$this->_tempPos]) && ! ($this->parsingHtml->code[$this->_tempPos]['name'] == $tagOpen && $this->parsingHtml->code[$this->_tempPos]['close'])) { |
|
| 1217 | - // make the action |
|
| 1218 | - $this->_executeAction($this->parsingHtml->code[$this->_tempPos]); |
|
| 1219 | - $this->_tempPos++; |
|
| 1220 | - } |
|
| 1221 | - |
|
| 1222 | - // execute the closure of the tag |
|
| 1223 | - if (isset($this->parsingHtml->code[$this->_tempPos])) { |
|
| 1224 | - $this->_executeAction($this->parsingHtml->code[$this->_tempPos]); |
|
| 1225 | - } |
|
| 1226 | - |
|
| 1227 | - // end of the sub part |
|
| 1228 | - $this->_subPart = false; |
|
| 1229 | - } |
|
| 1230 | - |
|
| 1231 | - // execute the action |
|
| 1232 | - $this->_executeAction($action); |
|
| 1233 | - } |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - /** |
|
| 1237 | - * execute the action from the parsing |
|
| 1238 | - * |
|
| 1239 | - * @access protected |
|
| 1240 | - * @param array $action |
|
| 1241 | - */ |
|
| 1242 | - protected function _executeAction($action) |
|
| 1243 | - { |
|
| 1244 | - // name of the action |
|
| 1245 | - $fnc = ($action['close'] ? '_tag_close_' : '_tag_open_').strtoupper($action['name']); |
|
| 1246 | - |
|
| 1247 | - // parameters of the action |
|
| 1248 | - $param = $action['param']; |
|
| 1249 | - |
|
| 1250 | - // if it the first action of the first page, and if it is not a open tag of PAGE => create the new page |
|
| 1251 | - if ($fnc != '_tag_open_PAGE' && $this->_firstPage) { |
|
| 1252 | - $this->_setNewPage(); |
|
| 1253 | - } |
|
| 1254 | - |
|
| 1255 | - // the action must exist |
|
| 1256 | - if ( ! is_callable(array(&$this, $fnc))) { |
|
| 1257 | - throw new HTML2PDF_exception(1, strtoupper($action['name']), $this->parsingHtml->getHtmlErrorCode($action['html_pos'])); |
|
| 1258 | - } |
|
| 1259 | - |
|
| 1260 | - // lauch the action |
|
| 1261 | - $res = $this->{$fnc}($param); |
|
| 1262 | - |
|
| 1263 | - // save the name of the action |
|
| 1264 | - $this->_previousCall = $fnc; |
|
| 1265 | - |
|
| 1266 | - // return the result |
|
| 1267 | - return $res; |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - /** |
|
| 1271 | - * get the position of the element on the current line, depending on his height |
|
| 1272 | - * |
|
| 1273 | - * @access protected |
|
| 1274 | - * @param float $h |
|
| 1275 | - * @return float |
|
| 1276 | - */ |
|
| 1277 | - protected function _getElementY($h) |
|
| 1278 | - { |
|
| 1279 | - if ($this->_subPart || $this->_isSubPart || ! $this->_currentH || $this->_currentH < $h) |
|
| 1280 | - return 0; |
|
| 1281 | - |
|
| 1282 | - return ($this->_currentH - $h) * 0.8; |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - /** |
|
| 1286 | - * make a break line |
|
| 1287 | - * |
|
| 1288 | - * @access protected |
|
| 1289 | - * @param float $h current line height |
|
| 1290 | - * @param integer $curr real current position in the text, if new line in the write of a text |
|
| 1291 | - */ |
|
| 1292 | - protected function _makeBreakLine($h, $curr = null) |
|
| 1293 | - { |
|
| 1294 | - if ($h) { |
|
| 1295 | - if (($this->pdf->getY() + $h < $this->pdf->getH() - $this->pdf->getbMargin()) || $this->_isInOverflow || $this->_isInFooter) |
|
| 1296 | - $this->_setNewLine($h, $curr); |
|
| 1297 | - else |
|
| 1298 | - $this->_setNewPage(null, '', null, $curr); |
|
| 1299 | - } else { |
|
| 1300 | - $this->_setNewPositionForNewLine($curr); |
|
| 1301 | - } |
|
| 1302 | - |
|
| 1303 | - $this->_maxH = 0; |
|
| 1304 | - $this->_maxE = 0; |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - /** |
|
| 1308 | - * display a image |
|
| 1309 | - * |
|
| 1310 | - * @access protected |
|
| 1311 | - * @param string $src |
|
| 1312 | - * @param boolean $subLi if true=image of a list |
|
| 1313 | - * @return boolean depending on "isForOneLine" |
|
| 1314 | - */ |
|
| 1315 | - protected function _drawImage($src, $subLi = false) |
|
| 1316 | - { |
|
| 1317 | - // get the size of the image |
|
| 1318 | - // WARNING : if URL, "allow_url_fopen" must turned to "on" in php.ini |
|
| 1319 | - |
|
| 1320 | - $infos = @getimagesize($src); |
|
| 1321 | - |
|
| 1322 | - // if the image does not exist, or can not be loaded |
|
| 1323 | - if (count($infos) < 2) { |
|
| 1324 | - // if the test is activ => exception |
|
| 1325 | - if ($this->_testIsImage) { |
|
| 1326 | - throw new HTML2PDF_exception(6, $src); |
|
| 1327 | - } |
|
| 1328 | - |
|
| 1329 | - // else, display a gray rectangle |
|
| 1330 | - $src = null; |
|
| 1331 | - $infos = array(16, 16); |
|
| 1332 | - } |
|
| 1333 | - |
|
| 1334 | - // convert the size of the image in the unit of the PDF |
|
| 1335 | - $imageWidth = $infos[0] / $this->pdf->getK(); |
|
| 1336 | - $imageHeight = $infos[1] / $this->pdf->getK(); |
|
| 1337 | - |
|
| 1338 | - // calculate the size from the css style |
|
| 1339 | - if ($this->parsingCss->value['width'] && $this->parsingCss->value['height']) { |
|
| 1340 | - $w = $this->parsingCss->value['width']; |
|
| 1341 | - $h = $this->parsingCss->value['height']; |
|
| 1342 | - } else if ($this->parsingCss->value['width']) { |
|
| 1343 | - $w = $this->parsingCss->value['width']; |
|
| 1344 | - $h = $imageHeight * $w / $imageWidth; |
|
| 1345 | - } else if ($this->parsingCss->value['height']) { |
|
| 1346 | - $h = $this->parsingCss->value['height']; |
|
| 1347 | - $w = $imageWidth * $h / $imageHeight; |
|
| 1348 | - } else { |
|
| 1349 | - // convert px to pt |
|
| 1350 | - $w = 72. / 96. * $imageWidth; |
|
| 1351 | - $h = 72. / 96. * $imageHeight; |
|
| 1352 | - } |
|
| 1353 | - |
|
| 1354 | - // are we in a float |
|
| 1355 | - $float = $this->parsingCss->getFloat(); |
|
| 1356 | - |
|
| 1357 | - // if we are in a float, but if something else if on the line => Break Line |
|
| 1358 | - if ($float && $this->_maxH) { |
|
| 1359 | - // make the break line (false if we are in "_isForOneLine" mode) |
|
| 1360 | - if ( ! $this->_tag_open_BR(array())) { |
|
| 1361 | - return false; |
|
| 1362 | - } |
|
| 1363 | - } |
|
| 1364 | - |
|
| 1365 | - // position of the image |
|
| 1366 | - $x = $this->pdf->getX(); |
|
| 1367 | - $y = $this->pdf->getY(); |
|
| 1368 | - |
|
| 1369 | - // if the image can not be put on the current line => new line |
|
| 1370 | - if ( ! $float && ($x + $w > $this->pdf->getW() - $this->pdf->getrMargin()) && $this->_maxH) { |
|
| 1371 | - if ($this->_isForOneLine) { |
|
| 1372 | - return false; |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - // set the new line |
|
| 1376 | - $hnl = max($this->_maxH, $this->parsingCss->getLineHeight()); |
|
| 1377 | - $this->_setNewLine($hnl); |
|
| 1378 | - |
|
| 1379 | - // get the new position |
|
| 1380 | - $x = $this->pdf->getX(); |
|
| 1381 | - $y = $this->pdf->getY(); |
|
| 1382 | - } |
|
| 1383 | - |
|
| 1384 | - // if the image can not be put on the current page |
|
| 1385 | - if (($y + $h > $this->pdf->getH() - $this->pdf->getbMargin()) && ! $this->_isInOverflow) { |
|
| 1386 | - // new page |
|
| 1387 | - $this->_setNewPage(); |
|
| 1388 | - |
|
| 1389 | - // get the new position |
|
| 1390 | - $x = $this->pdf->getX(); |
|
| 1391 | - $y = $this->pdf->getY(); |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - // correction for display the image of a list |
|
| 1395 | - $hT = 0.80 * $this->parsingCss->value['font-size']; |
|
| 1396 | - if ($subLi && $h < $hT) { |
|
| 1397 | - $y += ($hT - $h); |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - // add the margin top |
|
| 1401 | - $yc = $y - $this->parsingCss->value['margin']['t']; |
|
| 1402 | - |
|
| 1403 | - // get the width and the position of the parent |
|
| 1404 | - $old = $this->parsingCss->getOldValues(); |
|
| 1405 | - if ($old['width']) { |
|
| 1406 | - $parentWidth = $old['width']; |
|
| 1407 | - $parentX = $x; |
|
| 1408 | - } else { |
|
| 1409 | - $parentWidth = $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); |
|
| 1410 | - $parentX = $this->pdf->getlMargin(); |
|
| 1411 | - } |
|
| 1412 | - |
|
| 1413 | - // if we are in a gloat => adapt the parent position and width |
|
| 1414 | - if ($float) { |
|
| 1415 | - list($lx, $rx) = $this->_getMargins($yc); |
|
| 1416 | - $parentX = $lx; |
|
| 1417 | - $parentWidth = $rx - $lx; |
|
| 1418 | - } |
|
| 1419 | - |
|
| 1420 | - // calculate the position of the image, if align to the right |
|
| 1421 | - if ($parentWidth > $w && $float != 'left') { |
|
| 1422 | - if ($float == 'right' || $this->parsingCss->value['text-align'] == 'li_right') $x = $parentX + $parentWidth - $w - $this->parsingCss->value['margin']['r'] - $this->parsingCss->value['margin']['l']; |
|
| 1423 | - } |
|
| 1424 | - |
|
| 1425 | - // display the image |
|
| 1426 | - if ( ! $this->_subPart && ! $this->_isSubPart) { |
|
| 1427 | - if ($src) { |
|
| 1428 | - $this->pdf->Image($src, $x, $y, $w, $h, '', $this->_isInLink); |
|
| 1429 | - } else { |
|
| 1430 | - // rectangle if the image can not be loaded |
|
| 1431 | - $this->pdf->setFillColorArray(array(240, 220, 220)); |
|
| 1432 | - $this->pdf->Rect($x, $y, $w, $h, 'F'); |
|
| 1433 | - } |
|
| 1434 | - } |
|
| 1435 | - |
|
| 1436 | - // apply the margins |
|
| 1437 | - $x -= $this->parsingCss->value['margin']['l']; |
|
| 1438 | - $y -= $this->parsingCss->value['margin']['t']; |
|
| 1439 | - $w += $this->parsingCss->value['margin']['l'] + $this->parsingCss->value['margin']['r']; |
|
| 1440 | - $h += $this->parsingCss->value['margin']['t'] + $this->parsingCss->value['margin']['b']; |
|
| 1441 | - |
|
| 1442 | - if ($float == 'left') { |
|
| 1443 | - // save the current max |
|
| 1444 | - $this->_maxX = max($this->_maxX, $x + $w); |
|
| 1445 | - $this->_maxY = max($this->_maxY, $y + $h); |
|
| 1446 | - |
|
| 1447 | - // add the image to the margins |
|
| 1448 | - $this->_addMargins($float, $x, $y, $x + $w, $y + $h); |
|
| 1449 | - |
|
| 1450 | - // get the new position |
|
| 1451 | - list($lx, $rx) = $this->_getMargins($yc); |
|
| 1452 | - $this->pdf->setXY($lx, $yc); |
|
| 1453 | - } else if ($float == 'right') { |
|
| 1454 | - // save the current max. We don't save the X because it is not the real max of the line |
|
| 1455 | - $this->_maxY = max($this->_maxY, $y + $h); |
|
| 1456 | - |
|
| 1457 | - // add the image to the margins |
|
| 1458 | - $this->_addMargins($float, $x, $y, $x + $w, $y + $h); |
|
| 1459 | - |
|
| 1460 | - // get the new position |
|
| 1461 | - list($lx, $rx) = $this->_getMargins($yc); |
|
| 1462 | - $this->pdf->setXY($lx, $yc); |
|
| 1463 | - } else { |
|
| 1464 | - // set the new position at the end of the image |
|
| 1465 | - $this->pdf->setX($x + $w); |
|
| 1466 | - |
|
| 1467 | - // save the current max |
|
| 1468 | - $this->_maxX = max($this->_maxX, $x + $w); |
|
| 1469 | - $this->_maxY = max($this->_maxY, $y + $h); |
|
| 1470 | - $this->_maxH = max($this->_maxH, $h); |
|
| 1471 | - } |
|
| 1472 | - |
|
| 1473 | - return true; |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - /** |
|
| 1477 | - * draw a rectangle |
|
| 1478 | - * |
|
| 1479 | - * @access protected |
|
| 1480 | - * @param float $x |
|
| 1481 | - * @param float $y |
|
| 1482 | - * @param float $w |
|
| 1483 | - * @param float $h |
|
| 1484 | - * @param array $border |
|
| 1485 | - * @param float $padding - internal marge of the rectanble => not used, but... |
|
| 1486 | - * @param float $margin - external marge of the rectanble |
|
| 1487 | - * @param array $background |
|
| 1488 | - * @return boolean |
|
| 1489 | - */ |
|
| 1490 | - protected function _drawRectangle($x, $y, $w, $h, $border, $padding, $margin, $background) |
|
| 1491 | - { |
|
| 1492 | - // if we are in a subpart or if height is null => return false |
|
| 1493 | - if ($this->_subPart || $this->_isSubPart || $h === null) return false; |
|
| 1494 | - |
|
| 1495 | - // add the margin |
|
| 1496 | - $x += $margin; |
|
| 1497 | - $y += $margin; |
|
| 1498 | - $w -= $margin * 2; |
|
| 1499 | - $h -= $margin * 2; |
|
| 1500 | - |
|
| 1501 | - // get the radius of the border |
|
| 1502 | - $outTL = $border['radius']['tl']; |
|
| 1503 | - $outTR = $border['radius']['tr']; |
|
| 1504 | - $outBR = $border['radius']['br']; |
|
| 1505 | - $outBL = $border['radius']['bl']; |
|
| 1506 | - |
|
| 1507 | - // prepare the out radius |
|
| 1508 | - $outTL = ($outTL[0] && $outTL[1]) ? $outTL : null; |
|
| 1509 | - $outTR = ($outTR[0] && $outTR[1]) ? $outTR : null; |
|
| 1510 | - $outBR = ($outBR[0] && $outBR[1]) ? $outBR : null; |
|
| 1511 | - $outBL = ($outBL[0] && $outBL[1]) ? $outBL : null; |
|
| 1512 | - |
|
| 1513 | - // prepare the in radius |
|
| 1514 | - $inTL = $outTL; |
|
| 1515 | - $inTR = $outTR; |
|
| 1516 | - $inBR = $outBR; |
|
| 1517 | - $inBL = $outBL; |
|
| 1518 | - |
|
| 1519 | - if (is_array($inTL)) { |
|
| 1520 | - $inTL[0] -= $border['l']['width']; |
|
| 1521 | - $inTL[1] -= $border['t']['width']; |
|
| 1522 | - } |
|
| 1523 | - if (is_array($inTR)) { |
|
| 1524 | - $inTR[0] -= $border['r']['width']; |
|
| 1525 | - $inTR[1] -= $border['t']['width']; |
|
| 1526 | - } |
|
| 1527 | - if (is_array($inBR)) { |
|
| 1528 | - $inBR[0] -= $border['r']['width']; |
|
| 1529 | - $inBR[1] -= $border['b']['width']; |
|
| 1530 | - } |
|
| 1531 | - if (is_array($inBL)) { |
|
| 1532 | - $inBL[0] -= $border['l']['width']; |
|
| 1533 | - $inBL[1] -= $border['b']['width']; |
|
| 1534 | - } |
|
| 1535 | - |
|
| 1536 | - if ($inTL[0] <= 0 || $inTL[1] <= 0) $inTL = null; |
|
| 1537 | - if ($inTR[0] <= 0 || $inTR[1] <= 0) $inTR = null; |
|
| 1538 | - if ($inBR[0] <= 0 || $inBR[1] <= 0) $inBR = null; |
|
| 1539 | - if ($inBL[0] <= 0 || $inBL[1] <= 0) $inBL = null; |
|
| 1540 | - |
|
| 1541 | - // prepare the background color |
|
| 1542 | - $pdfStyle = ''; |
|
| 1543 | - if ($background['color']) { |
|
| 1544 | - $this->pdf->setFillColorArray($background['color']); |
|
| 1545 | - $pdfStyle .= 'F'; |
|
| 1546 | - } |
|
| 1547 | - |
|
| 1548 | - // if we have a background to fill => fill it with a path (because of the radius) |
|
| 1549 | - if ($pdfStyle) { |
|
| 1550 | - $this->pdf->clippingPathStart($x, $y, $w, $h, $outTL, $outTR, $outBL, $outBR); |
|
| 1551 | - $this->pdf->Rect($x, $y, $w, $h, $pdfStyle); |
|
| 1552 | - $this->pdf->clippingPathStop(); |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - // prepare the background image |
|
| 1556 | - if ($background['image']) { |
|
| 1557 | - $iName = $background['image']; |
|
| 1558 | - $iPosition = $background['position'] !== null ? $background['position'] : array(0, 0); |
|
| 1559 | - $iRepeat = $background['repeat'] !== null ? $background['repeat'] : array(true, true); |
|
| 1560 | - |
|
| 1561 | - // size of the background without the borders |
|
| 1562 | - $bX = $x; |
|
| 1563 | - $bY = $y; |
|
| 1564 | - $bW = $w; |
|
| 1565 | - $bH = $h; |
|
| 1566 | - |
|
| 1567 | - if ($border['b']['width']) { |
|
| 1568 | - $bH -= $border['b']['width']; |
|
| 1569 | - } |
|
| 1570 | - if ($border['l']['width']) { |
|
| 1571 | - $bW -= $border['l']['width']; |
|
| 1572 | - $bX += $border['l']['width']; |
|
| 1573 | - } |
|
| 1574 | - if ($border['t']['width']) { |
|
| 1575 | - $bH -= $border['t']['width']; |
|
| 1576 | - $bY += $border['t']['width']; |
|
| 1577 | - } |
|
| 1578 | - if ($border['r']['width']) { |
|
| 1579 | - $bW -= $border['r']['width']; |
|
| 1580 | - } |
|
| 1581 | - |
|
| 1582 | - // get the size of the image |
|
| 1583 | - // WARNING : if URL, "allow_url_fopen" must turned to "on" in php.ini |
|
| 1584 | - $imageInfos = @getimagesize($iName); |
|
| 1585 | - |
|
| 1586 | - // if the image can not be loaded |
|
| 1587 | - if (count($imageInfos) < 2) { |
|
| 1588 | - if ($this->_testIsImage) { |
|
| 1589 | - throw new HTML2PDF_exception(6, $iName); |
|
| 1590 | - } |
|
| 1591 | - } else { |
|
| 1592 | - // convert the size of the image from pixel to the unit of the PDF |
|
| 1593 | - $imageWidth = 72. / 96. * $imageInfos[0] / $this->pdf->getK(); |
|
| 1594 | - $imageHeight = 72. / 96. * $imageInfos[1] / $this->pdf->getK(); |
|
| 1595 | - |
|
| 1596 | - // prepare the position of the backgroung |
|
| 1597 | - if ($iRepeat[0]) $iPosition[0] = $bX; |
|
| 1598 | - else if (preg_match('/^([-]?[0-9\.]+)%/isU', $iPosition[0], $match)) $iPosition[0] = $bX + $match[1] * ($bW - $imageWidth) / 100; |
|
| 1599 | - else $iPosition[0] = $bX + $iPosition[0]; |
|
| 1600 | - |
|
| 1601 | - if ($iRepeat[1]) $iPosition[1] = $bY; |
|
| 1602 | - else if (preg_match('/^([-]?[0-9\.]+)%/isU', $iPosition[1], $match)) $iPosition[1] = $bY + $match[1] * ($bH - $imageHeight) / 100; |
|
| 1603 | - else $iPosition[1] = $bY + $iPosition[1]; |
|
| 1604 | - |
|
| 1605 | - $imageXmin = $bX; |
|
| 1606 | - $imageXmax = $bX + $bW; |
|
| 1607 | - $imageYmin = $bY; |
|
| 1608 | - $imageYmax = $bY + $bH; |
|
| 1609 | - |
|
| 1610 | - if ( ! $iRepeat[0] && ! $iRepeat[1]) { |
|
| 1611 | - $imageXmin = $iPosition[0]; $imageXmax = $iPosition[0] + $imageWidth; |
|
| 1612 | - $imageYmin = $iPosition[1]; $imageYmax = $iPosition[1] + $imageHeight; |
|
| 1613 | - } else if ($iRepeat[0] && ! $iRepeat[1]) { |
|
| 1614 | - $imageYmin = $iPosition[1]; $imageYmax = $iPosition[1] + $imageHeight; |
|
| 1615 | - } else if ( ! $iRepeat[0] && $iRepeat[1]) { |
|
| 1616 | - $imageXmin = $iPosition[0]; $imageXmax = $iPosition[0] + $imageWidth; |
|
| 1617 | - } |
|
| 1618 | - |
|
| 1619 | - // build the path to display the image (because of radius) |
|
| 1620 | - $this->pdf->clippingPathStart($bX, $bY, $bW, $bH, $inTL, $inTR, $inBL, $inBR); |
|
| 1621 | - |
|
| 1622 | - // repeat the image |
|
| 1623 | - for ($iY = $imageYmin; $iY < $imageYmax; $iY += $imageHeight) { |
|
| 1624 | - for ($iX = $imageXmin; $iX < $imageXmax; $iX += $imageWidth) { |
|
| 1625 | - $cX = null; |
|
| 1626 | - $cY = null; |
|
| 1627 | - $cW = $imageWidth; |
|
| 1628 | - $cH = $imageHeight; |
|
| 1629 | - if ($imageYmax - $iY < $imageHeight) { |
|
| 1630 | - $cX = $iX; |
|
| 1631 | - $cY = $iY; |
|
| 1632 | - $cH = $imageYmax - $iY; |
|
| 1633 | - } |
|
| 1634 | - if ($imageXmax - $iX < $imageWidth) { |
|
| 1635 | - $cX = $iX; |
|
| 1636 | - $cY = $iY; |
|
| 1637 | - $cW = $imageXmax - $iX; |
|
| 1638 | - } |
|
| 1639 | - |
|
| 1640 | - $this->pdf->Image($iName, $iX, $iY, $imageWidth, $imageHeight, '', ''); |
|
| 1641 | - } |
|
| 1642 | - } |
|
| 1643 | - |
|
| 1644 | - // end of the path |
|
| 1645 | - $this->pdf->clippingPathStop(); |
|
| 1646 | - } |
|
| 1647 | - } |
|
| 1648 | - |
|
| 1649 | - // adding some loose (0.01mm) |
|
| 1650 | - $loose = 0.01; |
|
| 1651 | - $x -= $loose; |
|
| 1652 | - $y -= $loose; |
|
| 1653 | - $w += 2. * $loose; |
|
| 1654 | - $h += 2. * $loose; |
|
| 1655 | - if ($border['l']['width']) $border['l']['width'] += 2. * $loose; |
|
| 1656 | - if ($border['t']['width']) $border['t']['width'] += 2. * $loose; |
|
| 1657 | - if ($border['r']['width']) $border['r']['width'] += 2. * $loose; |
|
| 1658 | - if ($border['b']['width']) $border['b']['width'] += 2. * $loose; |
|
| 1659 | - |
|
| 1660 | - // prepare the test on borders |
|
| 1661 | - $testBl = ($border['l']['width'] && $border['l']['color'][0] !== null); |
|
| 1662 | - $testBt = ($border['t']['width'] && $border['t']['color'][0] !== null); |
|
| 1663 | - $testBr = ($border['r']['width'] && $border['r']['color'][0] !== null); |
|
| 1664 | - $testBb = ($border['b']['width'] && $border['b']['color'][0] !== null); |
|
| 1665 | - |
|
| 1666 | - // draw the radius bottom-left |
|
| 1667 | - if (is_array($outBL) && ($testBb || $testBl)) { |
|
| 1668 | - if ($inBL) { |
|
| 1669 | - $courbe = array(); |
|
| 1670 | - $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h; |
|
| 1671 | - $courbe[] = $x; $courbe[] = $y + $h - $outBL[1]; |
|
| 1672 | - $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h - $border['b']['width']; |
|
| 1673 | - $courbe[] = $x + $border['l']['width']; $courbe[] = $y + $h - $outBL[1]; |
|
| 1674 | - $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h - $outBL[1]; |
|
| 1675 | - } else { |
|
| 1676 | - $courbe = array(); |
|
| 1677 | - $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h; |
|
| 1678 | - $courbe[] = $x; $courbe[] = $y + $h - $outBL[1]; |
|
| 1679 | - $courbe[] = $x + $border['l']['width']; $courbe[] = $y + $h - $border['b']['width']; |
|
| 1680 | - $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h - $outBL[1]; |
|
| 1681 | - } |
|
| 1682 | - $this->_drawCurve($courbe, $border['l']['color']); |
|
| 1683 | - } |
|
| 1684 | - |
|
| 1685 | - // draw the radius left-top |
|
| 1686 | - if (is_array($outTL) && ($testBt || $testBl)) { |
|
| 1687 | - if ($inTL) { |
|
| 1688 | - $courbe = array(); |
|
| 1689 | - $courbe[] = $x; $courbe[] = $y + $outTL[1]; |
|
| 1690 | - $courbe[] = $x + $outTL[0]; $courbe[] = $y; |
|
| 1691 | - $courbe[] = $x + $border['l']['width']; $courbe[] = $y + $outTL[1]; |
|
| 1692 | - $courbe[] = $x + $outTL[0]; $courbe[] = $y + $border['t']['width']; |
|
| 1693 | - $courbe[] = $x + $outTL[0]; $courbe[] = $y + $outTL[1]; |
|
| 1694 | - } else { |
|
| 1695 | - $courbe = array(); |
|
| 1696 | - $courbe[] = $x; $courbe[] = $y + $outTL[1]; |
|
| 1697 | - $courbe[] = $x + $outTL[0]; $courbe[] = $y; |
|
| 1698 | - $courbe[] = $x + $border['l']['width']; $courbe[] = $y + $border['t']['width']; |
|
| 1699 | - $courbe[] = $x + $outTL[0]; $courbe[] = $y + $outTL[1]; |
|
| 1700 | - } |
|
| 1701 | - $this->_drawCurve($courbe, $border['t']['color']); |
|
| 1702 | - } |
|
| 1703 | - |
|
| 1704 | - // draw the radius top-right |
|
| 1705 | - if (is_array($outTR) && ($testBt || $testBr)) { |
|
| 1706 | - if ($inTR) { |
|
| 1707 | - $courbe = array(); |
|
| 1708 | - $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y; |
|
| 1709 | - $courbe[] = $x + $w; $courbe[] = $y + $outTR[1]; |
|
| 1710 | - $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y + $border['t']['width']; |
|
| 1711 | - $courbe[] = $x + $w - $border['r']['width']; $courbe[] = $y + $outTR[1]; |
|
| 1712 | - $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y + $outTR[1]; |
|
| 1713 | - } else { |
|
| 1714 | - $courbe = array(); |
|
| 1715 | - $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y; |
|
| 1716 | - $courbe[] = $x + $w; $courbe[] = $y + $outTR[1]; |
|
| 1717 | - $courbe[] = $x + $w - $border['r']['width']; $courbe[] = $y + $border['t']['width']; |
|
| 1718 | - $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y + $outTR[1]; |
|
| 1719 | - } |
|
| 1720 | - $this->_drawCurve($courbe, $border['r']['color']); |
|
| 1721 | - } |
|
| 1722 | - |
|
| 1723 | - // draw the radius right-bottom |
|
| 1724 | - if (is_array($outBR) && ($testBb || $testBr)) { |
|
| 1725 | - if ($inBR) { |
|
| 1726 | - $courbe = array(); |
|
| 1727 | - $courbe[] = $x + $w; $courbe[] = $y + $h - $outBR[1]; |
|
| 1728 | - $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h; |
|
| 1729 | - $courbe[] = $x + $w - $border['r']['width']; $courbe[] = $y + $h - $outBR[1]; |
|
| 1730 | - $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h - $border['b']['width']; |
|
| 1731 | - $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h - $outBR[1]; |
|
| 1732 | - } else { |
|
| 1733 | - $courbe = array(); |
|
| 1734 | - $courbe[] = $x + $w; $courbe[] = $y + $h - $outBR[1]; |
|
| 1735 | - $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h; |
|
| 1736 | - $courbe[] = $x + $w - $border['r']['width']; $courbe[] = $y + $h - $border['b']['width']; |
|
| 1737 | - $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h - $outBR[1]; |
|
| 1738 | - } |
|
| 1739 | - $this->_drawCurve($courbe, $border['b']['color']); |
|
| 1740 | - } |
|
| 1741 | - |
|
| 1742 | - // draw the left border |
|
| 1743 | - if ($testBl) { |
|
| 1744 | - $pt = array(); |
|
| 1745 | - $pt[] = $x; $pt[] = $y + $h; |
|
| 1746 | - $pt[] = $x; $pt[] = $y + $h - $border['b']['width']; |
|
| 1747 | - $pt[] = $x; $pt[] = $y + $border['t']['width']; |
|
| 1748 | - $pt[] = $x; $pt[] = $y; |
|
| 1749 | - $pt[] = $x + $border['l']['width']; $pt[] = $y + $border['t']['width']; |
|
| 1750 | - $pt[] = $x + $border['l']['width']; $pt[] = $y + $h - $border['b']['width']; |
|
| 1751 | - |
|
| 1752 | - $bord = 3; |
|
| 1753 | - if (is_array($outBL)) { |
|
| 1754 | - $bord -= 1; |
|
| 1755 | - $pt[3] -= $outBL[1] - $border['b']['width']; |
|
| 1756 | - if ($inBL) $pt[11] -= $inBL[1]; |
|
| 1757 | - unset($pt[0]); unset($pt[1]); |
|
| 1758 | - } |
|
| 1759 | - if (is_array($outTL)) { |
|
| 1760 | - $bord -= 2; |
|
| 1761 | - $pt[5] += $outTL[1] - $border['t']['width']; |
|
| 1762 | - if ($inTL) $pt[9] += $inTL[1]; |
|
| 1763 | - unset($pt[6]); unset($pt[7]); |
|
| 1764 | - } |
|
| 1765 | - |
|
| 1766 | - $pt = array_values($pt); |
|
| 1767 | - $this->_drawLine($pt, $border['l']['color'], $border['l']['type'], $border['l']['width'], $bord); |
|
| 1768 | - } |
|
| 1769 | - |
|
| 1770 | - // draw the top border |
|
| 1771 | - if ($testBt) { |
|
| 1772 | - $pt = array(); |
|
| 1773 | - $pt[] = $x; $pt[] = $y; |
|
| 1774 | - $pt[] = $x + $border['l']['width']; $pt[] = $y; |
|
| 1775 | - $pt[] = $x + $w - $border['r']['width']; $pt[] = $y; |
|
| 1776 | - $pt[] = $x + $w; $pt[] = $y; |
|
| 1777 | - $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $border['t']['width']; |
|
| 1778 | - $pt[] = $x + $border['l']['width']; $pt[] = $y + $border['t']['width']; |
|
| 1779 | - |
|
| 1780 | - $bord = 3; |
|
| 1781 | - if (is_array($outTL)) { |
|
| 1782 | - $bord -= 1; |
|
| 1783 | - $pt[2] += $outTL[0] - $border['l']['width']; |
|
| 1784 | - if ($inTL) $pt[10] += $inTL[0]; |
|
| 1785 | - unset($pt[0]); unset($pt[1]); |
|
| 1786 | - } |
|
| 1787 | - if (is_array($outTR)) { |
|
| 1788 | - $bord -= 2; |
|
| 1789 | - $pt[4] -= $outTR[0] - $border['r']['width']; |
|
| 1790 | - if ($inTR) $pt[8] -= $inTR[0]; |
|
| 1791 | - unset($pt[6]); unset($pt[7]); |
|
| 1792 | - } |
|
| 1793 | - |
|
| 1794 | - $pt = array_values($pt); |
|
| 1795 | - $this->_drawLine($pt, $border['t']['color'], $border['t']['type'], $border['t']['width'], $bord); |
|
| 1796 | - } |
|
| 1797 | - |
|
| 1798 | - // draw the right border |
|
| 1799 | - if ($testBr) { |
|
| 1800 | - $pt = array(); |
|
| 1801 | - $pt[] = $x + $w; $pt[] = $y; |
|
| 1802 | - $pt[] = $x + $w; $pt[] = $y + $border['t']['width']; |
|
| 1803 | - $pt[] = $x + $w; $pt[] = $y + $h - $border['b']['width']; |
|
| 1804 | - $pt[] = $x + $w; $pt[] = $y + $h; |
|
| 1805 | - $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $h - $border['b']['width']; |
|
| 1806 | - $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $border['t']['width']; |
|
| 1807 | - |
|
| 1808 | - $bord = 3; |
|
| 1809 | - if (is_array($outTR)) { |
|
| 1810 | - $bord -= 1; |
|
| 1811 | - $pt[3] += $outTR[1] - $border['t']['width']; |
|
| 1812 | - if ($inTR) $pt[11] += $inTR[1]; |
|
| 1813 | - unset($pt[0]); unset($pt[1]); |
|
| 1814 | - } |
|
| 1815 | - if (is_array($outBR)) { |
|
| 1816 | - $bord -= 2; |
|
| 1817 | - $pt[5] -= $outBR[1] - $border['b']['width']; |
|
| 1818 | - if ($inBR) $pt[9] -= $inBR[1]; |
|
| 1819 | - unset($pt[6]); unset($pt[7]); |
|
| 1820 | - } |
|
| 1821 | - |
|
| 1822 | - $pt = array_values($pt); |
|
| 1823 | - $this->_drawLine($pt, $border['r']['color'], $border['r']['type'], $border['r']['width'], $bord); |
|
| 1824 | - } |
|
| 1825 | - |
|
| 1826 | - // draw the bottom border |
|
| 1827 | - if ($testBb) { |
|
| 1828 | - $pt = array(); |
|
| 1829 | - $pt[] = $x + $w; $pt[] = $y + $h; |
|
| 1830 | - $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $h; |
|
| 1831 | - $pt[] = $x + $border['l']['width']; $pt[] = $y + $h; |
|
| 1832 | - $pt[] = $x; $pt[] = $y + $h; |
|
| 1833 | - $pt[] = $x + $border['l']['width']; $pt[] = $y + $h - $border['b']['width']; |
|
| 1834 | - $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $h - $border['b']['width']; |
|
| 1835 | - |
|
| 1836 | - $bord = 3; |
|
| 1837 | - if (is_array($outBL)) { |
|
| 1838 | - $bord -= 2; |
|
| 1839 | - $pt[4] += $outBL[0] - $border['l']['width']; |
|
| 1840 | - if ($inBL) $pt[8] += $inBL[0]; |
|
| 1841 | - unset($pt[6]); unset($pt[7]); |
|
| 1842 | - } |
|
| 1843 | - if (is_array($outBR)) { |
|
| 1844 | - $bord -= 1; |
|
| 1845 | - $pt[2] -= $outBR[0] - $border['r']['width']; |
|
| 1846 | - if ($inBR) $pt[10] -= $inBR[0]; |
|
| 1847 | - unset($pt[0]); unset($pt[1]); |
|
| 1848 | - |
|
| 1849 | - } |
|
| 1850 | - |
|
| 1851 | - $pt = array_values($pt); |
|
| 1852 | - $this->_drawLine($pt, $border['b']['color'], $border['b']['type'], $border['b']['width'], $bord); |
|
| 1853 | - } |
|
| 1854 | - |
|
| 1855 | - if ($background['color']) { |
|
| 1856 | - $this->pdf->setFillColorArray($background['color']); |
|
| 1857 | - } |
|
| 1858 | - |
|
| 1859 | - return true; |
|
| 1860 | - } |
|
| 1861 | - |
|
| 1862 | - /** |
|
| 1863 | - * draw a curve (for border radius) |
|
| 1864 | - * |
|
| 1865 | - * @access protected |
|
| 1866 | - * @param double[] $pt |
|
| 1867 | - * @param array $color |
|
| 1868 | - */ |
|
| 1869 | - protected function _drawCurve($pt, $color) |
|
| 1870 | - { |
|
| 1871 | - $this->pdf->setFillColorArray($color); |
|
| 1872 | - |
|
| 1873 | - if (count($pt) == 10) |
|
| 1874 | - $this->pdf->drawCurve($pt[0], $pt[1], $pt[2], $pt[3], $pt[4], $pt[5], $pt[6], $pt[7], $pt[8], $pt[9]); |
|
| 1875 | - else |
|
| 1876 | - $this->pdf->drawCorner($pt[0], $pt[1], $pt[2], $pt[3], $pt[4], $pt[5], $pt[6], $pt[7]); |
|
| 1877 | - } |
|
| 1878 | - |
|
| 1879 | - /** |
|
| 1880 | - * draw a ligne with a specific type, and specific start and end for radius |
|
| 1881 | - * |
|
| 1882 | - * @access protected |
|
| 1883 | - * @param array $pt |
|
| 1884 | - * @param float $color |
|
| 1885 | - * @param string $type (dashed, dotted, double, solid) |
|
| 1886 | - * @param float $width |
|
| 1887 | - * @param integer $radius (binary from 0 to 3 with 1=>start with a radius, 2=>end with a radius) |
|
| 1888 | - */ |
|
| 1889 | - protected function _drawLine($pt, $color, $type, $width, $radius = 3) |
|
| 1890 | - { |
|
| 1891 | - // set the fill color |
|
| 1892 | - $this->pdf->setFillColorArray($color); |
|
| 1893 | - |
|
| 1894 | - // if dashed or dotted |
|
| 1895 | - if ($type == 'dashed' || $type == 'dotted') { |
|
| 1896 | - |
|
| 1897 | - // clean the end of the line, if radius |
|
| 1898 | - if ($radius == 1) { |
|
| 1899 | - $tmp = array(); $tmp[] = $pt[0]; $tmp[] = $pt[1]; $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[8]; $tmp[] = $pt[9]; |
|
| 1900 | - $this->pdf->Polygon($tmp, 'F'); |
|
| 1901 | - |
|
| 1902 | - $tmp = array(); $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[4]; $tmp[] = $pt[5]; $tmp[] = $pt[6]; $tmp[] = $pt[7]; $tmp[] = $pt[8]; $tmp[] = $pt[9]; |
|
| 1903 | - $pt = $tmp; |
|
| 1904 | - } else if ($radius == 2) { |
|
| 1905 | - $tmp = array(); $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[4]; $tmp[] = $pt[5]; $tmp[] = $pt[6]; $tmp[] = $pt[7]; |
|
| 1906 | - $this->pdf->Polygon($tmp, 'F'); |
|
| 1907 | - |
|
| 1908 | - $tmp = array(); $tmp[] = $pt[0]; $tmp[] = $pt[1]; $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[6]; $tmp[] = $pt[7]; $tmp[] = $pt[8]; $tmp[] = $pt[9]; |
|
| 1909 | - $pt = $tmp; |
|
| 1910 | - } else if ($radius == 3) { |
|
| 1911 | - $tmp = array(); $tmp[] = $pt[0]; $tmp[] = $pt[1]; $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[10]; $tmp[] = $pt[11]; |
|
| 1912 | - $this->pdf->Polygon($tmp, 'F'); |
|
| 1913 | - |
|
| 1914 | - $tmp = array(); $tmp[] = $pt[4]; $tmp[] = $pt[5]; $tmp[] = $pt[6]; $tmp[] = $pt[7]; $tmp[] = $pt[8]; $tmp[] = $pt[9]; |
|
| 1915 | - $this->pdf->Polygon($tmp, 'F'); |
|
| 1916 | - |
|
| 1917 | - $tmp = array(); $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[4]; $tmp[] = $pt[5]; $tmp[] = $pt[8]; $tmp[] = $pt[9]; $tmp[] = $pt[10]; $tmp[] = $pt[11]; |
|
| 1918 | - $pt = $tmp; |
|
| 1919 | - } |
|
| 1920 | - |
|
| 1921 | - // horisontal or vertical line |
|
| 1922 | - if ($pt[2] == $pt[0]) { |
|
| 1923 | - $l = abs(($pt[3] - $pt[1]) * 0.5); |
|
| 1924 | - $px = 0; |
|
| 1925 | - $py = $width; |
|
| 1926 | - $x1 = $pt[0]; $y1 = ($pt[3] + $pt[1]) * 0.5; |
|
| 1927 | - $x2 = $pt[6]; $y2 = ($pt[7] + $pt[5]) * 0.5; |
|
| 1928 | - } else { |
|
| 1929 | - $l = abs(($pt[2] - $pt[0]) * 0.5); |
|
| 1930 | - $px = $width; |
|
| 1931 | - $py = 0; |
|
| 1932 | - $x1 = ($pt[2] + $pt[0]) * 0.5; $y1 = $pt[1]; |
|
| 1933 | - $x2 = ($pt[6] + $pt[4]) * 0.5; $y2 = $pt[7]; |
|
| 1934 | - } |
|
| 1935 | - |
|
| 1936 | - // if dashed : 3x bigger than dotted |
|
| 1937 | - if ($type == 'dashed') { |
|
| 1938 | - $px = $px * 3.; |
|
| 1939 | - $py = $py * 3.; |
|
| 1940 | - } |
|
| 1941 | - $mode = ($l / ($px + $py) < .5); |
|
| 1942 | - |
|
| 1943 | - // display the dotted/dashed line |
|
| 1944 | - for ($i = 0; $l - ($px + $py) * ($i - 0.5) > 0; $i++) { |
|
| 1945 | - if (($i % 2) == $mode) { |
|
| 1946 | - $j = $i - 0.5; |
|
| 1947 | - $lx1 = $px * ($j); if ($lx1 < -$l) $lx1 = -$l; |
|
| 1948 | - $ly1 = $py * ($j); if ($ly1 < -$l) $ly1 = -$l; |
|
| 1949 | - $lx2 = $px * ($j + 1); if ($lx2 > $l) $lx2 = $l; |
|
| 1950 | - $ly2 = $py * ($j + 1); if ($ly2 > $l) $ly2 = $l; |
|
| 1951 | - |
|
| 1952 | - $tmp = array(); |
|
| 1953 | - $tmp[] = $x1 + $lx1; $tmp[] = $y1 + $ly1; |
|
| 1954 | - $tmp[] = $x1 + $lx2; $tmp[] = $y1 + $ly2; |
|
| 1955 | - $tmp[] = $x2 + $lx2; $tmp[] = $y2 + $ly2; |
|
| 1956 | - $tmp[] = $x2 + $lx1; $tmp[] = $y2 + $ly1; |
|
| 1957 | - $this->pdf->Polygon($tmp, 'F'); |
|
| 1958 | - |
|
| 1959 | - if ($j > 0) { |
|
| 1960 | - $tmp = array(); |
|
| 1961 | - $tmp[] = $x1 - $lx1; $tmp[] = $y1 - $ly1; |
|
| 1962 | - $tmp[] = $x1 - $lx2; $tmp[] = $y1 - $ly2; |
|
| 1963 | - $tmp[] = $x2 - $lx2; $tmp[] = $y2 - $ly2; |
|
| 1964 | - $tmp[] = $x2 - $lx1; $tmp[] = $y2 - $ly1; |
|
| 1965 | - $this->pdf->Polygon($tmp, 'F'); |
|
| 1966 | - } |
|
| 1967 | - } |
|
| 1968 | - } |
|
| 1969 | - } else if ($type == 'double') { |
|
| 1970 | - |
|
| 1971 | - // if double, 2 lines : 0=>1/3 and 2/3=>1 |
|
| 1972 | - $pt1 = $pt; |
|
| 1973 | - $pt2 = $pt; |
|
| 1974 | - |
|
| 1975 | - if (count($pt) == 12) { |
|
| 1976 | - // line 1 |
|
| 1977 | - $pt1[0] = ($pt[0] - $pt[10]) * 0.33 + $pt[10]; |
|
| 1978 | - $pt1[1] = ($pt[1] - $pt[11]) * 0.33 + $pt[11]; |
|
| 1979 | - $pt1[2] = ($pt[2] - $pt[10]) * 0.33 + $pt[10]; |
|
| 1980 | - $pt1[3] = ($pt[3] - $pt[11]) * 0.33 + $pt[11]; |
|
| 1981 | - $pt1[4] = ($pt[4] - $pt[8]) * 0.33 + $pt[8]; |
|
| 1982 | - $pt1[5] = ($pt[5] - $pt[9]) * 0.33 + $pt[9]; |
|
| 1983 | - $pt1[6] = ($pt[6] - $pt[8]) * 0.33 + $pt[8]; |
|
| 1984 | - $pt1[7] = ($pt[7] - $pt[9]) * 0.33 + $pt[9]; |
|
| 1985 | - $pt2[10] = ($pt[10] - $pt[0]) * 0.33 + $pt[0]; |
|
| 1986 | - $pt2[11] = ($pt[11] - $pt[1]) * 0.33 + $pt[1]; |
|
| 1987 | - |
|
| 1988 | - // line 2 |
|
| 1989 | - $pt2[2] = ($pt[2] - $pt[0]) * 0.33 + $pt[0]; |
|
| 1990 | - $pt2[3] = ($pt[3] - $pt[1]) * 0.33 + $pt[1]; |
|
| 1991 | - $pt2[4] = ($pt[4] - $pt[6]) * 0.33 + $pt[6]; |
|
| 1992 | - $pt2[5] = ($pt[5] - $pt[7]) * 0.33 + $pt[7]; |
|
| 1993 | - $pt2[8] = ($pt[8] - $pt[6]) * 0.33 + $pt[6]; |
|
| 1994 | - $pt2[9] = ($pt[9] - $pt[7]) * 0.33 + $pt[7]; |
|
| 1995 | - } else { |
|
| 1996 | - // line 1 |
|
| 1997 | - $pt1[0] = ($pt[0] - $pt[6]) * 0.33 + $pt[6]; |
|
| 1998 | - $pt1[1] = ($pt[1] - $pt[7]) * 0.33 + $pt[7]; |
|
| 1999 | - $pt1[2] = ($pt[2] - $pt[4]) * 0.33 + $pt[4]; |
|
| 2000 | - $pt1[3] = ($pt[3] - $pt[5]) * 0.33 + $pt[5]; |
|
| 2001 | - |
|
| 2002 | - // line 2 |
|
| 2003 | - $pt2[6] = ($pt[6] - $pt[0]) * 0.33 + $pt[0]; |
|
| 2004 | - $pt2[7] = ($pt[7] - $pt[1]) * 0.33 + $pt[1]; |
|
| 2005 | - $pt2[4] = ($pt[4] - $pt[2]) * 0.33 + $pt[2]; |
|
| 2006 | - $pt2[5] = ($pt[5] - $pt[3]) * 0.33 + $pt[3]; |
|
| 2007 | - } |
|
| 2008 | - $this->pdf->Polygon($pt1, 'F'); |
|
| 2009 | - $this->pdf->Polygon($pt2, 'F'); |
|
| 2010 | - } else if ($type == 'solid') { |
|
| 2011 | - // solid line : draw directly the polygon |
|
| 2012 | - $this->pdf->Polygon($pt, 'F'); |
|
| 2013 | - } |
|
| 2014 | - } |
|
| 2015 | - |
|
| 2016 | - /** |
|
| 2017 | - * prepare a transform matrix, only for drawing a SVG graphic |
|
| 2018 | - * |
|
| 2019 | - * @access protected |
|
| 2020 | - * @param string $transform |
|
| 2021 | - * @return array $matrix |
|
| 2022 | - */ |
|
| 2023 | - protected function _prepareTransform($transform) |
|
| 2024 | - { |
|
| 2025 | - // it can not be empty |
|
| 2026 | - if ( ! $transform) return null; |
|
| 2027 | - |
|
| 2028 | - // sctions must be like scale(...) |
|
| 2029 | - if ( ! preg_match_all('/([a-z]+)\(([^\)]*)\)/isU', $transform, $match)) return null; |
|
| 2030 | - |
|
| 2031 | - // prepare the list of the actions |
|
| 2032 | - $actions = array(); |
|
| 2033 | - |
|
| 2034 | - // for actions |
|
| 2035 | - for ($k = 0; $k < count($match[0]); $k++) { |
|
| 2036 | - |
|
| 2037 | - // get the name of the action |
|
| 2038 | - $name = strtolower($match[1][$k]); |
|
| 2039 | - |
|
| 2040 | - // get the parameters of the action |
|
| 2041 | - $val = explode(',', trim($match[2][$k])); |
|
| 2042 | - foreach ($val as $i => $j) { |
|
| 2043 | - $val[$i] = trim($j); |
|
| 2044 | - } |
|
| 2045 | - |
|
| 2046 | - // prepare the matrix, depending on the action |
|
| 2047 | - switch ($name) |
|
| 2048 | - { |
|
| 2049 | - case 'scale': |
|
| 2050 | - if ( ! isset($val[0])) $val[0] = 1.; else $val[0] = 1. * $val[0]; |
|
| 2051 | - if ( ! isset($val[1])) $val[1] = $val[0]; else $val[1] = 1. * $val[1]; |
|
| 2052 | - $actions[] = array($val[0], 0, 0, $val[1], 0, 0); |
|
| 2053 | - break; |
|
| 2054 | - |
|
| 2055 | - case 'translate': |
|
| 2056 | - if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $this->parsingCss->ConvertToMM($val[0], $this->_isInDraw['w']); |
|
| 2057 | - if ( ! isset($val[1])) $val[1] = 0.; else $val[1] = $this->parsingCss->ConvertToMM($val[1], $this->_isInDraw['h']); |
|
| 2058 | - $actions[] = array(1, 0, 0, 1, $val[0], $val[1]); |
|
| 2059 | - break; |
|
| 2060 | - |
|
| 2061 | - case 'rotate': |
|
| 2062 | - if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $val[0] * M_PI / 180.; |
|
| 2063 | - if ( ! isset($val[1])) $val[1] = 0.; else $val[1] = $this->parsingCss->ConvertToMM($val[1], $this->_isInDraw['w']); |
|
| 2064 | - if ( ! isset($val[2])) $val[2] = 0.; else $val[2] = $this->parsingCss->ConvertToMM($val[2], $this->_isInDraw['h']); |
|
| 2065 | - if ($val[1] || $val[2]) $actions[] = array(1, 0, 0, 1, -$val[1], -$val[2]); |
|
| 2066 | - $actions[] = array(cos($val[0]), sin($val[0]), -sin($val[0]), cos($val[0]), 0, 0); |
|
| 2067 | - if ($val[1] || $val[2]) $actions[] = array(1, 0, 0, 1, $val[1], $val[2]); |
|
| 2068 | - break; |
|
| 2069 | - |
|
| 2070 | - case 'skewx': |
|
| 2071 | - if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $val[0] * M_PI / 180.; |
|
| 2072 | - $actions[] = array(1, 0, tan($val[0]), 1, 0, 0); |
|
| 2073 | - break; |
|
| 2074 | - |
|
| 2075 | - case 'skewy': |
|
| 2076 | - if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $val[0] * M_PI / 180.; |
|
| 2077 | - $actions[] = array(1, tan($val[0]), 0, 1, 0, 0); |
|
| 2078 | - break; |
|
| 2079 | - case 'matrix': |
|
| 2080 | - if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $val[0] * 1.; |
|
| 2081 | - if ( ! isset($val[1])) $val[1] = 0.; else $val[1] = $val[1] * 1.; |
|
| 2082 | - if ( ! isset($val[2])) $val[2] = 0.; else $val[2] = $val[2] * 1.; |
|
| 2083 | - if ( ! isset($val[3])) $val[3] = 0.; else $val[3] = $val[3] * 1.; |
|
| 2084 | - if ( ! isset($val[4])) $val[4] = 0.; else $val[4] = $this->parsingCss->ConvertToMM($val[4], $this->_isInDraw['w']); |
|
| 2085 | - if ( ! isset($val[5])) $val[5] = 0.; else $val[5] = $this->parsingCss->ConvertToMM($val[5], $this->_isInDraw['h']); |
|
| 2086 | - $actions[] = $val; |
|
| 2087 | - break; |
|
| 2088 | - } |
|
| 2089 | - } |
|
| 2090 | - |
|
| 2091 | - // if ther is no actions => return |
|
| 2092 | - if ( ! $actions) return null; |
|
| 2093 | - |
|
| 2094 | - // get the first matrix |
|
| 2095 | - $m = $actions[0]; unset($actions[0]); |
|
| 2096 | - |
|
| 2097 | - // foreach matrix => multiply to the last matrix |
|
| 2098 | - foreach ($actions as $n) { |
|
| 2099 | - $m = array( |
|
| 2100 | - $m[0] * $n[0] + $m[2] * $n[1], |
|
| 2101 | - $m[1] * $n[0] + $m[3] * $n[1], |
|
| 2102 | - $m[0] * $n[2] + $m[2] * $n[3], |
|
| 2103 | - $m[1] * $n[2] + $m[3] * $n[3], |
|
| 2104 | - $m[0] * $n[4] + $m[2] * $n[5] + $m[4], |
|
| 2105 | - $m[1] * $n[4] + $m[3] * $n[5] + $m[5] |
|
| 2106 | - ); |
|
| 2107 | - } |
|
| 2108 | - |
|
| 2109 | - // return the matrix |
|
| 2110 | - return $m; |
|
| 2111 | - } |
|
| 2112 | - |
|
| 2113 | - /** |
|
| 2114 | - * @access protected |
|
| 2115 | - * @param &array $cases |
|
| 2116 | - * @param &array $corr |
|
| 2117 | - */ |
|
| 2118 | - protected function _calculateTableCellSize(&$cases, &$corr) |
|
| 2119 | - { |
|
| 2120 | - if ( ! isset($corr[0])) return true; |
|
| 2121 | - |
|
| 2122 | - // for each cell without colspan, we get the max width for each column |
|
| 2123 | - $sw = array(); |
|
| 2124 | - for ($x = 0; $x < count($corr[0]); $x++) { |
|
| 2125 | - $m = 0; |
|
| 2126 | - for ($y = 0; $y < count($corr); $y++) { |
|
| 2127 | - if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][2] == 1) { |
|
| 2128 | - $m = max($m, $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w']); |
|
| 2129 | - } |
|
| 2130 | - } |
|
| 2131 | - $sw[$x] = $m; |
|
| 2132 | - } |
|
| 2133 | - |
|
| 2134 | - // for each cell with colspan, we adapt the width of each column |
|
| 2135 | - for ($x = 0; $x < count($corr[0]); $x++) { |
|
| 2136 | - for ($y = 0; $y < count($corr); $y++) { |
|
| 2137 | - if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][2] > 1) { |
|
| 2138 | - |
|
| 2139 | - // sum the max width of each column in colspan |
|
| 2140 | - $s = 0; for ($i = 0; $i < $corr[$y][$x][2]; $i++) $s += $sw[$x + $i]; |
|
| 2141 | - |
|
| 2142 | - // if the max width is < the width of the cell with colspan => we adapt the width of each max width |
|
| 2143 | - if ($s > 0 && $s < $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w']) { |
|
| 2144 | - for ($i = 0; $i < $corr[$y][$x][2]; $i++) { |
|
| 2145 | - $sw[$x + $i] = $sw[$x + $i] / $s * $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w']; |
|
| 2146 | - } |
|
| 2147 | - } |
|
| 2148 | - } |
|
| 2149 | - } |
|
| 2150 | - } |
|
| 2151 | - |
|
| 2152 | - // set the new width, for each cell |
|
| 2153 | - for ($x = 0; $x < count($corr[0]); $x++) { |
|
| 2154 | - for ($y = 0; $y < count($corr); $y++) { |
|
| 2155 | - if (isset($corr[$y][$x]) && is_array($corr[$y][$x])) { |
|
| 2156 | - // without colspan |
|
| 2157 | - if ($corr[$y][$x][2] == 1) { |
|
| 2158 | - $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'] = $sw[$x]; |
|
| 2159 | - // with colspan |
|
| 2160 | - } else { |
|
| 2161 | - $s = 0; |
|
| 2162 | - for ($i = 0; $i < $corr[$y][$x][2]; $i++) { |
|
| 2163 | - $s += $sw[$x + $i]; |
|
| 2164 | - } |
|
| 2165 | - $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'] = $s; |
|
| 2166 | - } |
|
| 2167 | - } |
|
| 2168 | - } |
|
| 2169 | - } |
|
| 2170 | - |
|
| 2171 | - // for each cell without rowspan, we get the max height for each line |
|
| 2172 | - $sh = array(); |
|
| 2173 | - for ($y = 0; $y < count($corr); $y++) { |
|
| 2174 | - $m = 0; |
|
| 2175 | - for ($x = 0; $x < count($corr[0]); $x++) { |
|
| 2176 | - if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][3] == 1) { |
|
| 2177 | - $m = max($m, $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h']); |
|
| 2178 | - } |
|
| 2179 | - } |
|
| 2180 | - $sh[$y] = $m; |
|
| 2181 | - } |
|
| 2182 | - |
|
| 2183 | - // for each cell with rowspan, we adapt the height of each line |
|
| 2184 | - for ($y = 0; $y < count($corr); $y++) { |
|
| 2185 | - for ($x = 0; $x < count($corr[0]); $x++) { |
|
| 2186 | - if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][3] > 1) { |
|
| 2187 | - |
|
| 2188 | - // sum the max height of each line in rowspan |
|
| 2189 | - $s = 0; for ($i = 0; $i < $corr[$y][$x][3]; $i++) $s += $sh[$y + $i]; |
|
| 2190 | - |
|
| 2191 | - // if the max height is < the height of the cell with rowspan => we adapt the height of each max height |
|
| 2192 | - if ($s > 0 && $s < $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h']) { |
|
| 2193 | - for ($i = 0; $i < $corr[$y][$x][3]; $i++) { |
|
| 2194 | - $sh[$y + $i] = $sh[$y + $i] / $s * $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h']; |
|
| 2195 | - } |
|
| 2196 | - } |
|
| 2197 | - } |
|
| 2198 | - } |
|
| 2199 | - } |
|
| 2200 | - |
|
| 2201 | - // set the new height, for each cell |
|
| 2202 | - for ($y = 0; $y < count($corr); $y++) { |
|
| 2203 | - for ($x = 0; $x < count($corr[0]); $x++) { |
|
| 2204 | - if (isset($corr[$y][$x]) && is_array($corr[$y][$x])) { |
|
| 2205 | - // without rowspan |
|
| 2206 | - if ($corr[$y][$x][3] == 1) { |
|
| 2207 | - $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'] = $sh[$y]; |
|
| 2208 | - // with rowspan |
|
| 2209 | - } else { |
|
| 2210 | - $s = 0; |
|
| 2211 | - for ($i = 0; $i < $corr[$y][$x][3]; $i++) { |
|
| 2212 | - $s += $sh[$y + $i]; |
|
| 2213 | - } |
|
| 2214 | - $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'] = $s; |
|
| 2215 | - |
|
| 2216 | - for ($j = 1; $j < $corr[$y][$x][3]; $j++) { |
|
| 2217 | - $tx = $x + 1; |
|
| 2218 | - $ty = $y + $j; |
|
| 2219 | - for (true; isset($corr[$ty][$tx]) && ! is_array($corr[$ty][$tx]); $tx++); |
|
| 2220 | - if (isset($corr[$ty][$tx])) { |
|
| 2221 | - $cases[$corr[$ty][$tx][1]][$corr[$ty][$tx][0]]['dw'] += $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w']; |
|
| 2222 | - } |
|
| 2223 | - } |
|
| 2224 | - } |
|
| 2225 | - } |
|
| 2226 | - } |
|
| 2227 | - } |
|
| 2228 | - } |
|
| 2229 | - |
|
| 2230 | - /** |
|
| 2231 | - * tag : PAGE |
|
| 2232 | - * mode : OPEN |
|
| 2233 | - * |
|
| 2234 | - * @param array $param |
|
| 2235 | - * @return boolean |
|
| 2236 | - */ |
|
| 2237 | - protected function _tag_open_PAGE($param) |
|
| 2238 | - { |
|
| 2239 | - if ($this->_isForOneLine) return false; |
|
| 2240 | - if ($this->_debugActif) $this->_DEBUG_add('PAGE '.($this->_page + 1), true); |
|
| 2241 | - |
|
| 2242 | - $newPageSet = ( ! isset($param['pageset']) || $param['pageset'] != 'old'); |
|
| 2243 | - |
|
| 2244 | - $resetPageNumber = (isset($param['pagegroup']) && $param['pagegroup'] == 'new'); |
|
| 2245 | - |
|
| 2246 | - $this->_maxH = 0; |
|
| 2247 | - |
|
| 2248 | - // if new page set asked |
|
| 2249 | - if ($newPageSet) { |
|
| 2250 | - $this->_subHEADER = array(); |
|
| 2251 | - $this->_subFOOTER = array(); |
|
| 2252 | - |
|
| 2253 | - // orientation |
|
| 2254 | - $orientation = ''; |
|
| 2255 | - if (isset($param['orientation'])) { |
|
| 2256 | - $param['orientation'] = strtolower($param['orientation']); |
|
| 2257 | - if ($param['orientation'] == 'p') $orientation = 'P'; |
|
| 2258 | - if ($param['orientation'] == 'portrait') $orientation = 'P'; |
|
| 2259 | - |
|
| 2260 | - if ($param['orientation'] == 'l') $orientation = 'L'; |
|
| 2261 | - if ($param['orientation'] == 'paysage') $orientation = 'L'; |
|
| 2262 | - if ($param['orientation'] == 'landscape') $orientation = 'L'; |
|
| 2263 | - } |
|
| 2264 | - |
|
| 2265 | - // format |
|
| 2266 | - $format = null; |
|
| 2267 | - if (isset($param['format'])) { |
|
| 2268 | - $format = strtolower($param['format']); |
|
| 2269 | - if (preg_match('/^([0-9]+)x([0-9]+)$/isU', $format, $match)) { |
|
| 2270 | - $format = array(intval($match[1]), intval($match[2])); |
|
| 2271 | - } |
|
| 2272 | - } |
|
| 2273 | - |
|
| 2274 | - // background |
|
| 2275 | - $background = array(); |
|
| 2276 | - if (isset($param['backimg'])) { |
|
| 2277 | - $background['img'] = isset($param['backimg']) ? $param['backimg'] : ''; // src of the image |
|
| 2278 | - $background['posX'] = isset($param['backimgx']) ? $param['backimgx'] : 'center'; // horizontale position of the image |
|
| 2279 | - $background['posY'] = isset($param['backimgy']) ? $param['backimgy'] : 'middle'; // vertical position of the image |
|
| 2280 | - $background['width'] = isset($param['backimgw']) ? $param['backimgw'] : '100%'; // width of the image (100% = page width) |
|
| 2281 | - |
|
| 2282 | - // convert the src of the image, if parameters |
|
| 2283 | - $background['img'] = str_replace('&', '&', $background['img']); |
|
| 2284 | - |
|
| 2285 | - // convert the positions |
|
| 2286 | - if ($background['posX'] == 'left') $background['posX'] = '0%'; |
|
| 2287 | - if ($background['posX'] == 'center') $background['posX'] = '50%'; |
|
| 2288 | - if ($background['posX'] == 'right') $background['posX'] = '100%'; |
|
| 2289 | - if ($background['posY'] == 'top') $background['posY'] = '0%'; |
|
| 2290 | - if ($background['posY'] == 'middle') $background['posY'] = '50%'; |
|
| 2291 | - if ($background['posY'] == 'bottom') $background['posY'] = '100%'; |
|
| 2292 | - |
|
| 2293 | - if ($background['img']) { |
|
| 2294 | - // get the size of the image |
|
| 2295 | - // WARNING : if URL, "allow_url_fopen" must turned to "on" in php.ini |
|
| 2296 | - $infos = @getimagesize($background['img']); |
|
| 2297 | - if (count($infos) > 1) { |
|
| 2298 | - $imageWidth = $this->parsingCss->ConvertToMM($background['width'], $this->pdf->getW()); |
|
| 2299 | - $imageHeight = $imageWidth * $infos[1] / $infos[0]; |
|
| 2300 | - |
|
| 2301 | - $background['width'] = $imageWidth; |
|
| 2302 | - $background['posX'] = $this->parsingCss->ConvertToMM($background['posX'], $this->pdf->getW() - $imageWidth); |
|
| 2303 | - $background['posY'] = $this->parsingCss->ConvertToMM($background['posY'], $this->pdf->getH() - $imageHeight); |
|
| 2304 | - } else { |
|
| 2305 | - $background = array(); |
|
| 2306 | - } |
|
| 2307 | - } else { |
|
| 2308 | - $background = array(); |
|
| 2309 | - } |
|
| 2310 | - } |
|
| 2311 | - |
|
| 2312 | - // margins of the page |
|
| 2313 | - $background['top'] = isset($param['backtop']) ? $param['backtop'] : '0'; |
|
| 2314 | - $background['bottom'] = isset($param['backbottom']) ? $param['backbottom'] : '0'; |
|
| 2315 | - $background['left'] = isset($param['backleft']) ? $param['backleft'] : '0'; |
|
| 2316 | - $background['right'] = isset($param['backright']) ? $param['backright'] : '0'; |
|
| 2317 | - |
|
| 2318 | - // if no unit => mm |
|
| 2319 | - if (preg_match('/^([0-9]*)$/isU', $background['top'])) { |
|
| 2320 | - $background['top'] .= 'mm'; |
|
| 2321 | - } |
|
| 2322 | - if (preg_match('/^([0-9]*)$/isU', $background['bottom'])) { |
|
| 2323 | - $background['bottom'] .= 'mm'; |
|
| 2324 | - } |
|
| 2325 | - if (preg_match('/^([0-9]*)$/isU', $background['left'])) { |
|
| 2326 | - $background['left'] .= 'mm'; |
|
| 2327 | - } |
|
| 2328 | - if (preg_match('/^([0-9]*)$/isU', $background['right'])) { |
|
| 2329 | - $background['right'] .= 'mm'; |
|
| 2330 | - } |
|
| 2331 | - |
|
| 2332 | - // convert to mm |
|
| 2333 | - $background['top'] = $this->parsingCss->ConvertToMM($background['top'], $this->pdf->getH()); |
|
| 2334 | - $background['bottom'] = $this->parsingCss->ConvertToMM($background['bottom'], $this->pdf->getH()); |
|
| 2335 | - $background['left'] = $this->parsingCss->ConvertToMM($background['left'], $this->pdf->getW()); |
|
| 2336 | - $background['right'] = $this->parsingCss->ConvertToMM($background['right'], $this->pdf->getW()); |
|
| 2337 | - |
|
| 2338 | - // get the background color |
|
| 2339 | - $res = false; |
|
| 2340 | - $background['color'] = isset($param['backcolor']) ? $this->parsingCss->convertToColor($param['backcolor'], $res) : null; |
|
| 2341 | - if ( ! $res) $background['color'] = null; |
|
| 2342 | - |
|
| 2343 | - $this->parsingCss->save(); |
|
| 2344 | - $this->parsingCss->analyse('PAGE', $param); |
|
| 2345 | - $this->parsingCss->setPosition(); |
|
| 2346 | - $this->parsingCss->fontSet(); |
|
| 2347 | - |
|
| 2348 | - // new page |
|
| 2349 | - $this->_setNewPage($format, $orientation, $background, null, $resetPageNumber); |
|
| 2350 | - |
|
| 2351 | - // automatic footer |
|
| 2352 | - if (isset($param['footer'])) { |
|
| 2353 | - $lst = explode(';', $param['footer']); |
|
| 2354 | - foreach ($lst as $key => $val) { |
|
| 2355 | - $lst[$key] = trim(strtolower($val)); |
|
| 2356 | - } |
|
| 2357 | - $page = in_array('page', $lst); |
|
| 2358 | - $date = in_array('date', $lst); |
|
| 2359 | - $hour = in_array('heure', $lst); |
|
| 2360 | - $form = in_array('form', $lst); |
|
| 2361 | - } else { |
|
| 2362 | - $page = null; |
|
| 2363 | - $date = null; |
|
| 2364 | - $hour = null; |
|
| 2365 | - $form = null; |
|
| 2366 | - } |
|
| 2367 | - $this->pdf->SetMyFooter($page, $date, $hour, $form); |
|
| 2368 | - // else => we use the last page set used |
|
| 2369 | - } else { |
|
| 2370 | - $this->parsingCss->save(); |
|
| 2371 | - $this->parsingCss->analyse('PAGE', $param); |
|
| 2372 | - $this->parsingCss->setPosition(); |
|
| 2373 | - $this->parsingCss->fontSet(); |
|
| 2374 | - |
|
| 2375 | - $this->_setNewPage(null, null, null, null, $resetPageNumber); |
|
| 2376 | - } |
|
| 2377 | - |
|
| 2378 | - return true; |
|
| 2379 | - } |
|
| 2380 | - |
|
| 2381 | - /** |
|
| 2382 | - * tag : PAGE |
|
| 2383 | - * mode : CLOSE |
|
| 2384 | - * |
|
| 2385 | - * @param array $param |
|
| 2386 | - * @return boolean |
|
| 2387 | - */ |
|
| 2388 | - protected function _tag_close_PAGE($param) |
|
| 2389 | - { |
|
| 2390 | - if ($this->_isForOneLine) { |
|
| 2391 | - return false; |
|
| 2392 | - } |
|
| 2393 | - |
|
| 2394 | - $this->_maxH = 0; |
|
| 2395 | - |
|
| 2396 | - $this->parsingCss->load(); |
|
| 2397 | - $this->parsingCss->fontSet(); |
|
| 2398 | - |
|
| 2399 | - if ($this->_debugActif) { |
|
| 2400 | - $this->_DEBUG_add('PAGE '.$this->_page, false); |
|
| 2401 | - } |
|
| 2402 | - |
|
| 2403 | - return true; |
|
| 2404 | - } |
|
| 2405 | - |
|
| 2406 | - /** |
|
| 2407 | - * tag : PAGE_HEADER |
|
| 2408 | - * mode : OPEN |
|
| 2409 | - * |
|
| 2410 | - * @param array $param |
|
| 2411 | - * @return boolean |
|
| 2412 | - */ |
|
| 2413 | - protected function _tag_open_PAGE_HEADER($param) |
|
| 2414 | - { |
|
| 2415 | - if ($this->_isForOneLine) return false; |
|
| 2416 | - |
|
| 2417 | - $this->_subHEADER = array(); |
|
| 2418 | - for ($this->_parsePos; $this->_parsePos < count($this->parsingHtml->code); $this->_parsePos++) { |
|
| 2419 | - $action = $this->parsingHtml->code[$this->_parsePos]; |
|
| 2420 | - if ($action['name'] == 'page_header') $action['name'] = 'page_header_sub'; |
|
| 2421 | - $this->_subHEADER[] = $action; |
|
| 2422 | - if (strtolower($action['name']) == 'page_header_sub' && $action['close']) break; |
|
| 2423 | - } |
|
| 2424 | - |
|
| 2425 | - $this->_setPageHeader(); |
|
| 2426 | - |
|
| 2427 | - return true; |
|
| 2428 | - } |
|
| 2429 | - |
|
| 2430 | - /** |
|
| 2431 | - * tag : PAGE_FOOTER |
|
| 2432 | - * mode : OPEN |
|
| 2433 | - * |
|
| 2434 | - * @param array $param |
|
| 2435 | - * @return boolean |
|
| 2436 | - */ |
|
| 2437 | - protected function _tag_open_PAGE_FOOTER($param) |
|
| 2438 | - { |
|
| 2439 | - if ($this->_isForOneLine) return false; |
|
| 2440 | - |
|
| 2441 | - $this->_subFOOTER = array(); |
|
| 2442 | - for ($this->_parsePos; $this->_parsePos < count($this->parsingHtml->code); $this->_parsePos++) { |
|
| 2443 | - $action = $this->parsingHtml->code[$this->_parsePos]; |
|
| 2444 | - if ($action['name'] == 'page_footer') $action['name'] = 'page_footer_sub'; |
|
| 2445 | - $this->_subFOOTER[] = $action; |
|
| 2446 | - if (strtolower($action['name']) == 'page_footer_sub' && $action['close']) break; |
|
| 2447 | - } |
|
| 2448 | - |
|
| 2449 | - $this->_setPageFooter(); |
|
| 2450 | - |
|
| 2451 | - return true; |
|
| 2452 | - } |
|
| 2453 | - |
|
| 2454 | - /** |
|
| 2455 | - * It is not a real tag. Does not use it directly |
|
| 2456 | - * |
|
| 2457 | - * @param array $param |
|
| 2458 | - * @return boolean |
|
| 2459 | - */ |
|
| 2460 | - protected function _tag_open_PAGE_HEADER_SUB($param) |
|
| 2461 | - { |
|
| 2462 | - if ($this->_isForOneLine) { |
|
| 2463 | - return false; |
|
| 2464 | - } |
|
| 2465 | - |
|
| 2466 | - // save the current stat |
|
| 2467 | - $this->_subSTATES = array(); |
|
| 2468 | - $this->_subSTATES['x'] = $this->pdf->getX(); |
|
| 2469 | - $this->_subSTATES['y'] = $this->pdf->getY(); |
|
| 2470 | - $this->_subSTATES['s'] = $this->parsingCss->value; |
|
| 2471 | - $this->_subSTATES['t'] = $this->parsingCss->table; |
|
| 2472 | - $this->_subSTATES['ml'] = $this->_margeLeft; |
|
| 2473 | - $this->_subSTATES['mr'] = $this->_margeRight; |
|
| 2474 | - $this->_subSTATES['mt'] = $this->_margeTop; |
|
| 2475 | - $this->_subSTATES['mb'] = $this->_margeBottom; |
|
| 2476 | - $this->_subSTATES['mp'] = $this->_pageMarges; |
|
| 2477 | - |
|
| 2478 | - // new stat for the header |
|
| 2479 | - $this->_pageMarges = array(); |
|
| 2480 | - $this->_margeLeft = $this->_defaultLeft; |
|
| 2481 | - $this->_margeRight = $this->_defaultRight; |
|
| 2482 | - $this->_margeTop = $this->_defaultTop; |
|
| 2483 | - $this->_margeBottom = $this->_defaultBottom; |
|
| 2484 | - $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight); |
|
| 2485 | - $this->pdf->SetAutoPageBreak(false, $this->_margeBottom); |
|
| 2486 | - $this->pdf->setXY($this->_defaultLeft, $this->_defaultTop); |
|
| 2487 | - |
|
| 2488 | - $this->parsingCss->initStyle(); |
|
| 2489 | - $this->parsingCss->resetStyle(); |
|
| 2490 | - $this->parsingCss->value['width'] = $this->pdf->getW() - $this->_defaultLeft - $this->_defaultRight; |
|
| 2491 | - $this->parsingCss->table = array(); |
|
| 2492 | - |
|
| 2493 | - $this->parsingCss->save(); |
|
| 2494 | - $this->parsingCss->analyse('page_header_sub', $param); |
|
| 2495 | - $this->parsingCss->setPosition(); |
|
| 2496 | - $this->parsingCss->fontSet(); |
|
| 2497 | - $this->_setNewPositionForNewLine(); |
|
| 2498 | - return true; |
|
| 2499 | - } |
|
| 2500 | - |
|
| 2501 | - /** |
|
| 2502 | - * It is not a real tag. Does not use it directly |
|
| 2503 | - * |
|
| 2504 | - * @param array $param |
|
| 2505 | - * @return boolean |
|
| 2506 | - */ |
|
| 2507 | - protected function _tag_close_PAGE_HEADER_SUB($param) |
|
| 2508 | - { |
|
| 2509 | - if ($this->_isForOneLine) { |
|
| 2510 | - return false; |
|
| 2511 | - } |
|
| 2512 | - |
|
| 2513 | - $this->parsingCss->load(); |
|
| 2514 | - |
|
| 2515 | - // restore the stat |
|
| 2516 | - $this->parsingCss->value = $this->_subSTATES['s']; |
|
| 2517 | - $this->parsingCss->table = $this->_subSTATES['t']; |
|
| 2518 | - $this->_pageMarges = $this->_subSTATES['mp']; |
|
| 2519 | - $this->_margeLeft = $this->_subSTATES['ml']; |
|
| 2520 | - $this->_margeRight = $this->_subSTATES['mr']; |
|
| 2521 | - $this->_margeTop = $this->_subSTATES['mt']; |
|
| 2522 | - $this->_margeBottom = $this->_subSTATES['mb']; |
|
| 2523 | - $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight); |
|
| 2524 | - $this->pdf->setbMargin($this->_margeBottom); |
|
| 2525 | - $this->pdf->SetAutoPageBreak(false, $this->_margeBottom); |
|
| 2526 | - $this->pdf->setXY($this->_subSTATES['x'], $this->_subSTATES['y']); |
|
| 2527 | - |
|
| 2528 | - $this->parsingCss->fontSet(); |
|
| 2529 | - $this->_maxH = 0; |
|
| 2530 | - |
|
| 2531 | - return true; |
|
| 2532 | - } |
|
| 2533 | - |
|
| 2534 | - /** |
|
| 2535 | - * It is not a real tag. Does not use it directly |
|
| 2536 | - * |
|
| 2537 | - * @param array $param |
|
| 2538 | - * @return boolean |
|
| 2539 | - */ |
|
| 2540 | - protected function _tag_open_PAGE_FOOTER_SUB($param) |
|
| 2541 | - { |
|
| 2542 | - if ($this->_isForOneLine) { |
|
| 2543 | - return false; |
|
| 2544 | - } |
|
| 2545 | - |
|
| 2546 | - // save the current stat |
|
| 2547 | - $this->_subSTATES = array(); |
|
| 2548 | - $this->_subSTATES['x'] = $this->pdf->getX(); |
|
| 2549 | - $this->_subSTATES['y'] = $this->pdf->getY(); |
|
| 2550 | - $this->_subSTATES['s'] = $this->parsingCss->value; |
|
| 2551 | - $this->_subSTATES['t'] = $this->parsingCss->table; |
|
| 2552 | - $this->_subSTATES['ml'] = $this->_margeLeft; |
|
| 2553 | - $this->_subSTATES['mr'] = $this->_margeRight; |
|
| 2554 | - $this->_subSTATES['mt'] = $this->_margeTop; |
|
| 2555 | - $this->_subSTATES['mb'] = $this->_margeBottom; |
|
| 2556 | - $this->_subSTATES['mp'] = $this->_pageMarges; |
|
| 2557 | - |
|
| 2558 | - // new stat for the footer |
|
| 2559 | - $this->_pageMarges = array(); |
|
| 2560 | - $this->_margeLeft = $this->_defaultLeft; |
|
| 2561 | - $this->_margeRight = $this->_defaultRight; |
|
| 2562 | - $this->_margeTop = $this->_defaultTop; |
|
| 2563 | - $this->_margeBottom = $this->_defaultBottom; |
|
| 2564 | - $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight); |
|
| 2565 | - $this->pdf->SetAutoPageBreak(false, $this->_margeBottom); |
|
| 2566 | - $this->pdf->setXY($this->_defaultLeft, $this->_defaultTop); |
|
| 2567 | - |
|
| 2568 | - $this->parsingCss->initStyle(); |
|
| 2569 | - $this->parsingCss->resetStyle(); |
|
| 2570 | - $this->parsingCss->value['width'] = $this->pdf->getW() - $this->_defaultLeft - $this->_defaultRight; |
|
| 2571 | - $this->parsingCss->table = array(); |
|
| 2572 | - |
|
| 2573 | - // we create a sub HTML2PFDF, and we execute on it the content of the footer, to get the height of it |
|
| 2574 | - $sub = null; |
|
| 2575 | - $this->_createSubHTML($sub); |
|
| 2576 | - $sub->parsingHtml->code = $this->parsingHtml->getLevel($this->_parsePos); |
|
| 2577 | - $sub->_makeHTMLcode(); |
|
| 2578 | - $this->pdf->setY($this->pdf->getH() - $sub->_maxY - $this->_defaultBottom - 0.01); |
|
| 2579 | - $this->_destroySubHTML($sub); |
|
| 2580 | - |
|
| 2581 | - $this->parsingCss->save(); |
|
| 2582 | - $this->parsingCss->analyse('page_footer_sub', $param); |
|
| 2583 | - $this->parsingCss->setPosition(); |
|
| 2584 | - $this->parsingCss->fontSet(); |
|
| 2585 | - $this->_setNewPositionForNewLine(); |
|
| 2586 | - |
|
| 2587 | - return true; |
|
| 2588 | - } |
|
| 2589 | - |
|
| 2590 | - /** |
|
| 2591 | - * It is not a real tag. Does not use it directly |
|
| 2592 | - * |
|
| 2593 | - * @param array $param |
|
| 2594 | - * @return boolean |
|
| 2595 | - */ |
|
| 2596 | - protected function _tag_close_PAGE_FOOTER_SUB($param) |
|
| 2597 | - { |
|
| 2598 | - if ($this->_isForOneLine) { |
|
| 2599 | - return false; |
|
| 2600 | - } |
|
| 2601 | - |
|
| 2602 | - $this->parsingCss->load(); |
|
| 2603 | - |
|
| 2604 | - $this->parsingCss->value = $this->_subSTATES['s']; |
|
| 2605 | - $this->parsingCss->table = $this->_subSTATES['t']; |
|
| 2606 | - $this->_pageMarges = $this->_subSTATES['mp']; |
|
| 2607 | - $this->_margeLeft = $this->_subSTATES['ml']; |
|
| 2608 | - $this->_margeRight = $this->_subSTATES['mr']; |
|
| 2609 | - $this->_margeTop = $this->_subSTATES['mt']; |
|
| 2610 | - $this->_margeBottom = $this->_subSTATES['mb']; |
|
| 2611 | - $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight); |
|
| 2612 | - $this->pdf->SetAutoPageBreak(false, $this->_margeBottom); |
|
| 2613 | - $this->pdf->setXY($this->_subSTATES['x'], $this->_subSTATES['y']); |
|
| 2614 | - |
|
| 2615 | - $this->parsingCss->fontSet(); |
|
| 2616 | - $this->_maxH = 0; |
|
| 2617 | - |
|
| 2618 | - return true; |
|
| 2619 | - } |
|
| 2620 | - |
|
| 2621 | - /** |
|
| 2622 | - * tag : NOBREAK |
|
| 2623 | - * mode : OPEN |
|
| 2624 | - * |
|
| 2625 | - * @param array $param |
|
| 2626 | - * @return boolean |
|
| 2627 | - */ |
|
| 2628 | - protected function _tag_open_NOBREAK($param) |
|
| 2629 | - { |
|
| 2630 | - if ($this->_isForOneLine) { |
|
| 2631 | - return false; |
|
| 2632 | - } |
|
| 2633 | - |
|
| 2634 | - $this->_maxH = 0; |
|
| 2635 | - |
|
| 2636 | - // create a sub HTML2PDF to execute the content of the tag, to get the dimensions |
|
| 2637 | - $sub = null; |
|
| 2638 | - $this->_createSubHTML($sub); |
|
| 2639 | - $sub->parsingHtml->code = $this->parsingHtml->getLevel($this->_parsePos); |
|
| 2640 | - $sub->_makeHTMLcode(); |
|
| 2641 | - $y = $this->pdf->getY(); |
|
| 2642 | - |
|
| 2643 | - // if the content does not fit on the page => new page |
|
| 2644 | - if ( |
|
| 2645 | - $sub->_maxY < ($this->pdf->getH() - $this->pdf->gettMargin() - $this->pdf->getbMargin()) && |
|
| 2646 | - $y + $sub->_maxY >= ($this->pdf->getH() - $this->pdf->getbMargin()) |
|
| 2647 | - ) { |
|
| 2648 | - $this->_setNewPage(); |
|
| 2649 | - } |
|
| 2650 | - |
|
| 2651 | - // destroy the sub HTML2PDF |
|
| 2652 | - $this->_destroySubHTML($sub); |
|
| 2653 | - |
|
| 2654 | - return true; |
|
| 2655 | - } |
|
| 2656 | - |
|
| 2657 | - |
|
| 2658 | - /** |
|
| 2659 | - * tag : NOBREAK |
|
| 2660 | - * mode : CLOSE |
|
| 2661 | - * |
|
| 2662 | - * @param array $param |
|
| 2663 | - * @return boolean |
|
| 2664 | - */ |
|
| 2665 | - protected function _tag_close_NOBREAK($param) |
|
| 2666 | - { |
|
| 2667 | - if ($this->_isForOneLine) { |
|
| 2668 | - return false; |
|
| 2669 | - } |
|
| 2670 | - |
|
| 2671 | - $this->_maxH = 0; |
|
| 2672 | - |
|
| 2673 | - return true; |
|
| 2674 | - } |
|
| 2675 | - |
|
| 2676 | - /** |
|
| 2677 | - * tag : DIV |
|
| 2678 | - * mode : OPEN |
|
| 2679 | - * |
|
| 2680 | - * @param array $param |
|
| 2681 | - * @param string $other name of tag that used the div tag |
|
| 2682 | - * @return boolean |
|
| 2683 | - */ |
|
| 2684 | - protected function _tag_open_DIV($param, $other = 'div') |
|
| 2685 | - { |
|
| 2686 | - if ($this->_isForOneLine) { |
|
| 2687 | - return false; |
|
| 2688 | - } |
|
| 2689 | - if ($this->_debugActif) { |
|
| 2690 | - $this->_DEBUG_add(strtoupper($other), true); |
|
| 2691 | - } |
|
| 2692 | - |
|
| 2693 | - $this->parsingCss->save(); |
|
| 2694 | - $this->parsingCss->analyse($other, $param); |
|
| 2695 | - $this->parsingCss->fontSet(); |
|
| 2696 | - |
|
| 2697 | - // for fieldset and legend |
|
| 2698 | - if (in_array($other, array('fieldset', 'legend'))) { |
|
| 2699 | - if (isset($param['moveTop'])) { |
|
| 2700 | - $this->parsingCss->value['margin']['t'] += $param['moveTop']; |
|
| 2701 | - } |
|
| 2702 | - if (isset($param['moveLeft'])) { |
|
| 2703 | - $this->parsingCss->value['margin']['l'] += $param['moveLeft']; |
|
| 2704 | - } |
|
| 2705 | - if (isset($param['moveDown'])) { |
|
| 2706 | - $this->parsingCss->value['margin']['b'] += $param['moveDown']; |
|
| 2707 | - } |
|
| 2708 | - } |
|
| 2709 | - |
|
| 2710 | - $alignObject = null; |
|
| 2711 | - if ($this->parsingCss->value['margin-auto']) { |
|
| 2712 | - $alignObject = 'center'; |
|
| 2713 | - } |
|
| 2714 | - |
|
| 2715 | - $marge = array(); |
|
| 2716 | - $marge['l'] = $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['padding']['l'] + 0.03; |
|
| 2717 | - $marge['r'] = $this->parsingCss->value['border']['r']['width'] + $this->parsingCss->value['padding']['r'] + 0.03; |
|
| 2718 | - $marge['t'] = $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['padding']['t'] + 0.03; |
|
| 2719 | - $marge['b'] = $this->parsingCss->value['border']['b']['width'] + $this->parsingCss->value['padding']['b'] + 0.03; |
|
| 2720 | - |
|
| 2721 | - // extract the content of the div |
|
| 2722 | - $level = $this->parsingHtml->getLevel($this->_parsePos); |
|
| 2723 | - |
|
| 2724 | - // create a sub HTML2PDF to get the dimensions of the content of the div |
|
| 2725 | - $w = 0; $h = 0; |
|
| 2726 | - if (count($level)) { |
|
| 2727 | - $sub = null; |
|
| 2728 | - $this->_createSubHTML($sub); |
|
| 2729 | - $sub->parsingHtml->code = $level; |
|
| 2730 | - $sub->_makeHTMLcode(); |
|
| 2731 | - $w = $sub->_maxX; |
|
| 2732 | - $h = $sub->_maxY; |
|
| 2733 | - $this->_destroySubHTML($sub); |
|
| 2734 | - } |
|
| 2735 | - $wReel = $w; |
|
| 2736 | - $hReel = $h; |
|
| 2737 | - |
|
| 2738 | - $w += $marge['l'] + $marge['r'] + 0.001; |
|
| 2739 | - $h += $marge['t'] + $marge['b'] + 0.001; |
|
| 2740 | - |
|
| 2741 | - if ($this->parsingCss->value['overflow'] == 'hidden') { |
|
| 2742 | - $overW = max($w, $this->parsingCss->value['width']); |
|
| 2743 | - $overH = max($h, $this->parsingCss->value['height']); |
|
| 2744 | - $overflow = true; |
|
| 2745 | - $this->parsingCss->value['old_maxX'] = $this->_maxX; |
|
| 2746 | - $this->parsingCss->value['old_maxY'] = $this->_maxY; |
|
| 2747 | - $this->parsingCss->value['old_maxH'] = $this->_maxH; |
|
| 2748 | - $this->parsingCss->value['old_overflow'] = $this->_isInOverflow; |
|
| 2749 | - $this->_isInOverflow = true; |
|
| 2750 | - } else { |
|
| 2751 | - $overW = null; |
|
| 2752 | - $overH = null; |
|
| 2753 | - $overflow = false; |
|
| 2754 | - $this->parsingCss->value['width'] = max($w, $this->parsingCss->value['width']); |
|
| 2755 | - $this->parsingCss->value['height'] = max($h, $this->parsingCss->value['height']); |
|
| 2756 | - } |
|
| 2757 | - |
|
| 2758 | - switch ($this->parsingCss->value['rotate']) |
|
| 2759 | - { |
|
| 2760 | - case 90: |
|
| 2761 | - $tmp = $overH; $overH = $overW; $overW = $tmp; |
|
| 2762 | - $tmp = $hReel; $hReel = $wReel; $wReel = $tmp; |
|
| 2763 | - unset($tmp); |
|
| 2764 | - $w = $this->parsingCss->value['height']; |
|
| 2765 | - $h = $this->parsingCss->value['width']; |
|
| 2766 | - $tX = -$h; |
|
| 2767 | - $tY = 0; |
|
| 2768 | - break; |
|
| 2769 | - |
|
| 2770 | - case 180: |
|
| 2771 | - $w = $this->parsingCss->value['width']; |
|
| 2772 | - $h = $this->parsingCss->value['height']; |
|
| 2773 | - $tX = -$w; |
|
| 2774 | - $tY = -$h; |
|
| 2775 | - break; |
|
| 2776 | - |
|
| 2777 | - case 270: |
|
| 2778 | - $tmp = $overH; $overH = $overW; $overW = $tmp; |
|
| 2779 | - $tmp = $hReel; $hReel = $wReel; $wReel = $tmp; |
|
| 2780 | - unset($tmp); |
|
| 2781 | - $w = $this->parsingCss->value['height']; |
|
| 2782 | - $h = $this->parsingCss->value['width']; |
|
| 2783 | - $tX = 0; |
|
| 2784 | - $tY = -$w; |
|
| 2785 | - break; |
|
| 2786 | - |
|
| 2787 | - default: |
|
| 2788 | - $w = $this->parsingCss->value['width']; |
|
| 2789 | - $h = $this->parsingCss->value['height']; |
|
| 2790 | - $tX = 0; |
|
| 2791 | - $tY = 0; |
|
| 2792 | - break; |
|
| 2793 | - } |
|
| 2794 | - |
|
| 2795 | - if ( ! $this->parsingCss->value['position']) { |
|
| 2796 | - if ( |
|
| 2797 | - $w < ($this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin()) && |
|
| 2798 | - $this->pdf->getX() + $w >= ($this->pdf->getW() - $this->pdf->getrMargin()) |
|
| 2799 | - ) |
|
| 2800 | - $this->_tag_open_BR(array()); |
|
| 2801 | - |
|
| 2802 | - if ( |
|
| 2803 | - ($h < ($this->pdf->getH() - $this->pdf->gettMargin() - $this->pdf->getbMargin())) && |
|
| 2804 | - ($this->pdf->getY() + $h >= ($this->pdf->getH() - $this->pdf->getbMargin())) && |
|
| 2805 | - ! $this->_isInOverflow |
|
| 2806 | - ) |
|
| 2807 | - $this->_setNewPage(); |
|
| 2808 | - |
|
| 2809 | - $old = $this->parsingCss->getOldValues(); |
|
| 2810 | - $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); |
|
| 2811 | - |
|
| 2812 | - if ($parentWidth > $w) { |
|
| 2813 | - if ($alignObject == 'center') $this->pdf->setX($this->pdf->getX() + ($parentWidth - $w) * 0.5); |
|
| 2814 | - else if ($alignObject == 'right') $this->pdf->setX($this->pdf->getX() + $parentWidth - $w); |
|
| 2815 | - } |
|
| 2816 | - |
|
| 2817 | - $this->parsingCss->setPosition(); |
|
| 2818 | - } else { |
|
| 2819 | - $old = $this->parsingCss->getOldValues(); |
|
| 2820 | - $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); |
|
| 2821 | - |
|
| 2822 | - if ($parentWidth > $w) { |
|
| 2823 | - if ($alignObject == 'center') $this->pdf->setX($this->pdf->getX() + ($parentWidth - $w) * 0.5); |
|
| 2824 | - else if ($alignObject == 'right') $this->pdf->setX($this->pdf->getX() + $parentWidth - $w); |
|
| 2825 | - } |
|
| 2826 | - |
|
| 2827 | - $this->parsingCss->setPosition(); |
|
| 2828 | - $this->_saveMax(); |
|
| 2829 | - $this->_maxX = 0; |
|
| 2830 | - $this->_maxY = 0; |
|
| 2831 | - $this->_maxH = 0; |
|
| 2832 | - $this->_maxE = 0; |
|
| 2833 | - } |
|
| 2834 | - |
|
| 2835 | - if ($this->parsingCss->value['rotate']) { |
|
| 2836 | - $this->pdf->startTransform(); |
|
| 2837 | - $this->pdf->setRotation($this->parsingCss->value['rotate']); |
|
| 2838 | - $this->pdf->setTranslate($tX, $tY); |
|
| 2839 | - } |
|
| 2840 | - |
|
| 2841 | - $this->_drawRectangle( |
|
| 2842 | - $this->parsingCss->value['x'], |
|
| 2843 | - $this->parsingCss->value['y'], |
|
| 2844 | - $this->parsingCss->value['width'], |
|
| 2845 | - $this->parsingCss->value['height'], |
|
| 2846 | - $this->parsingCss->value['border'], |
|
| 2847 | - $this->parsingCss->value['padding'], |
|
| 2848 | - 0, |
|
| 2849 | - $this->parsingCss->value['background'] |
|
| 2850 | - ); |
|
| 2851 | - |
|
| 2852 | - $marge = array(); |
|
| 2853 | - $marge['l'] = $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['padding']['l'] + 0.03; |
|
| 2854 | - $marge['r'] = $this->parsingCss->value['border']['r']['width'] + $this->parsingCss->value['padding']['r'] + 0.03; |
|
| 2855 | - $marge['t'] = $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['padding']['t'] + 0.03; |
|
| 2856 | - $marge['b'] = $this->parsingCss->value['border']['b']['width'] + $this->parsingCss->value['padding']['b'] + 0.03; |
|
| 2857 | - |
|
| 2858 | - $this->parsingCss->value['width'] -= $marge['l'] + $marge['r']; |
|
| 2859 | - $this->parsingCss->value['height'] -= $marge['t'] + $marge['b']; |
|
| 2860 | - |
|
| 2861 | - $xCorr = 0; |
|
| 2862 | - $yCorr = 0; |
|
| 2863 | - if ( ! $this->_subPart && ! $this->_isSubPart) { |
|
| 2864 | - switch ($this->parsingCss->value['text-align']) |
|
| 2865 | - { |
|
| 2866 | - case 'right': |
|
| 2867 | - $xCorr = ($this->parsingCss->value['width'] - $wReel); |
|
| 2868 | - break; |
|
| 2869 | - case 'center': |
|
| 2870 | - $xCorr = ($this->parsingCss->value['width'] - $wReel) * 0.5; |
|
| 2871 | - break; |
|
| 2872 | - } |
|
| 2873 | - if ($xCorr > 0) $xCorr = 0; |
|
| 2874 | - switch ($this->parsingCss->value['vertical-align']) |
|
| 2875 | - { |
|
| 2876 | - case 'bottom': |
|
| 2877 | - $yCorr = ($this->parsingCss->value['height'] - $hReel); |
|
| 2878 | - break; |
|
| 2879 | - case 'middle': |
|
| 2880 | - $yCorr = ($this->parsingCss->value['height'] - $hReel) * 0.5; |
|
| 2881 | - break; |
|
| 2882 | - } |
|
| 2883 | - } |
|
| 2884 | - |
|
| 2885 | - if ($overflow) { |
|
| 2886 | - $overW -= $marge['l'] + $marge['r']; |
|
| 2887 | - $overH -= $marge['t'] + $marge['b']; |
|
| 2888 | - $this->pdf->clippingPathStart( |
|
| 2889 | - $this->parsingCss->value['x'] + $marge['l'], |
|
| 2890 | - $this->parsingCss->value['y'] + $marge['t'], |
|
| 2891 | - $this->parsingCss->value['width'], |
|
| 2892 | - $this->parsingCss->value['height'] |
|
| 2893 | - ); |
|
| 2894 | - |
|
| 2895 | - $this->parsingCss->value['x'] += $xCorr; |
|
| 2896 | - |
|
| 2897 | - // marges from the dimension of the content |
|
| 2898 | - $mL = $this->parsingCss->value['x'] + $marge['l']; |
|
| 2899 | - $mR = $this->pdf->getW() - $mL - $overW; |
|
| 2900 | - } else { |
|
| 2901 | - // marges from the dimension of the div |
|
| 2902 | - $mL = $this->parsingCss->value['x'] + $marge['l']; |
|
| 2903 | - $mR = $this->pdf->getW() - $mL - $this->parsingCss->value['width']; |
|
| 2904 | - } |
|
| 2905 | - |
|
| 2906 | - $x = $this->parsingCss->value['x'] + $marge['l']; |
|
| 2907 | - $y = $this->parsingCss->value['y'] + $marge['t'] + $yCorr; |
|
| 2908 | - $this->_saveMargin($mL, 0, $mR); |
|
| 2909 | - $this->pdf->setXY($x, $y); |
|
| 2910 | - |
|
| 2911 | - $this->_setNewPositionForNewLine(); |
|
| 2912 | - |
|
| 2913 | - return true; |
|
| 2914 | - } |
|
| 2915 | - |
|
| 2916 | - /** |
|
| 2917 | - * tag : BLOCKQUOTE |
|
| 2918 | - * mode : OPEN |
|
| 2919 | - * |
|
| 2920 | - * @param array $param |
|
| 2921 | - * @return boolean |
|
| 2922 | - */ |
|
| 2923 | - protected function _tag_open_BLOCKQUOTE($param) |
|
| 2924 | - { |
|
| 2925 | - return $this->_tag_open_DIV($param, 'blockquote'); |
|
| 2926 | - } |
|
| 2927 | - |
|
| 2928 | - /** |
|
| 2929 | - * tag : LEGEND |
|
| 2930 | - * mode : OPEN |
|
| 2931 | - * |
|
| 2932 | - * @param array $param |
|
| 2933 | - * @return boolean |
|
| 2934 | - */ |
|
| 2935 | - protected function _tag_open_LEGEND($param) |
|
| 2936 | - { |
|
| 2937 | - return $this->_tag_open_DIV($param, 'legend'); |
|
| 2938 | - } |
|
| 2939 | - |
|
| 2940 | - /** |
|
| 2941 | - * tag : FIELDSET |
|
| 2942 | - * mode : OPEN |
|
| 2943 | - * |
|
| 2944 | - * @author Pavel Kochman |
|
| 2945 | - * @param array $param |
|
| 2946 | - * @return boolean |
|
| 2947 | - */ |
|
| 2948 | - protected function _tag_open_FIELDSET($param) |
|
| 2949 | - { |
|
| 2950 | - |
|
| 2951 | - $this->parsingCss->save(); |
|
| 2952 | - $this->parsingCss->analyse('fieldset', $param); |
|
| 2953 | - |
|
| 2954 | - // get height of LEGEND element and make fieldset corrections |
|
| 2955 | - for ($tempPos = $this->_parsePos + 1; $tempPos < count($this->parsingHtml->code); $tempPos++) { |
|
| 2956 | - $action = $this->parsingHtml->code[$tempPos]; |
|
| 2957 | - if ($action['name'] == 'fieldset') break; |
|
| 2958 | - if ($action['name'] == 'legend' && ! $action['close']) { |
|
| 2959 | - $legendOpenPos = $tempPos; |
|
| 2960 | - |
|
| 2961 | - $sub = null; |
|
| 2962 | - $this->_createSubHTML($sub); |
|
| 2963 | - $sub->parsingHtml->code = $this->parsingHtml->getLevel($tempPos - 1); |
|
| 2964 | - |
|
| 2965 | - $res = null; |
|
| 2966 | - for ($sub->_parsePos = 0; $sub->_parsePos < count($sub->parsingHtml->code); $sub->_parsePos++) { |
|
| 2967 | - $action = $sub->parsingHtml->code[$sub->_parsePos]; |
|
| 2968 | - $sub->_executeAction($action); |
|
| 2969 | - |
|
| 2970 | - if ($action['name'] == 'legend' && $action['close']) { |
|
| 2971 | - break; |
|
| 2972 | - } |
|
| 2973 | - } |
|
| 2974 | - |
|
| 2975 | - $legendH = $sub->_maxY; |
|
| 2976 | - $this->_destroySubHTML($sub); |
|
| 2977 | - |
|
| 2978 | - $move = $this->parsingCss->value['padding']['t'] + $this->parsingCss->value['border']['t']['width'] + 0.03; |
|
| 2979 | - |
|
| 2980 | - $param['moveTop'] = $legendH / 2; |
|
| 2981 | - |
|
| 2982 | - $this->parsingHtml->code[$legendOpenPos]['param']['moveTop'] = - ($legendH / 2 + $move); |
|
| 2983 | - $this->parsingHtml->code[$legendOpenPos]['param']['moveLeft'] = 2 - $this->parsingCss->value['border']['l']['width'] - $this->parsingCss->value['padding']['l']; |
|
| 2984 | - $this->parsingHtml->code[$legendOpenPos]['param']['moveDown'] = $move; |
|
| 2985 | - break; |
|
| 2986 | - } |
|
| 2987 | - } |
|
| 2988 | - $this->parsingCss->load(); |
|
| 2989 | - |
|
| 2990 | - return $this->_tag_open_DIV($param, 'fieldset'); |
|
| 2991 | - } |
|
| 2992 | - |
|
| 2993 | - /** |
|
| 2994 | - * tag : DIV |
|
| 2995 | - * mode : CLOSE |
|
| 2996 | - * |
|
| 2997 | - * @param array $param |
|
| 2998 | - * @param string $other name of tag that used the div tag |
|
| 2999 | - * @return boolean |
|
| 3000 | - */ |
|
| 3001 | - protected function _tag_close_DIV($param, $other = 'div') |
|
| 3002 | - { |
|
| 3003 | - if ($this->_isForOneLine) { |
|
| 3004 | - return false; |
|
| 3005 | - } |
|
| 3006 | - |
|
| 3007 | - if ($this->parsingCss->value['overflow'] == 'hidden') { |
|
| 3008 | - $this->_maxX = $this->parsingCss->value['old_maxX']; |
|
| 3009 | - $this->_maxY = $this->parsingCss->value['old_maxY']; |
|
| 3010 | - $this->_maxH = $this->parsingCss->value['old_maxH']; |
|
| 3011 | - $this->_isInOverflow = $this->parsingCss->value['old_overflow']; |
|
| 3012 | - $this->pdf->clippingPathStop(); |
|
| 3013 | - } |
|
| 3014 | - |
|
| 3015 | - if ($this->parsingCss->value['rotate']) { |
|
| 3016 | - $this->pdf->stopTransform(); |
|
| 3017 | - } |
|
| 3018 | - |
|
| 3019 | - $marge = array(); |
|
| 3020 | - $marge['l'] = $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['padding']['l'] + 0.03; |
|
| 3021 | - $marge['r'] = $this->parsingCss->value['border']['r']['width'] + $this->parsingCss->value['padding']['r'] + 0.03; |
|
| 3022 | - $marge['t'] = $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['padding']['t'] + 0.03; |
|
| 3023 | - $marge['b'] = $this->parsingCss->value['border']['b']['width'] + $this->parsingCss->value['padding']['b'] + 0.03; |
|
| 3024 | - |
|
| 3025 | - $x = $this->parsingCss->value['x']; |
|
| 3026 | - $y = $this->parsingCss->value['y']; |
|
| 3027 | - $w = $this->parsingCss->value['width'] + $marge['l'] + $marge['r'] + $this->parsingCss->value['margin']['r']; |
|
| 3028 | - $h = $this->parsingCss->value['height'] + $marge['t'] + $marge['b'] + $this->parsingCss->value['margin']['b']; |
|
| 3029 | - |
|
| 3030 | - switch ($this->parsingCss->value['rotate']) |
|
| 3031 | - { |
|
| 3032 | - case 90: |
|
| 3033 | - $t = $w; $w = $h; $h = $t; |
|
| 3034 | - break; |
|
| 3035 | - |
|
| 3036 | - case 270: |
|
| 3037 | - $t = $w; $w = $h; $h = $t; |
|
| 3038 | - break; |
|
| 3039 | - |
|
| 3040 | - default: |
|
| 3041 | - break; |
|
| 3042 | - } |
|
| 3043 | - |
|
| 3044 | - |
|
| 3045 | - if ($this->parsingCss->value['position'] != 'absolute') { |
|
| 3046 | - $this->pdf->setXY($x + $w, $y); |
|
| 3047 | - |
|
| 3048 | - $this->_maxX = max($this->_maxX, $x + $w); |
|
| 3049 | - $this->_maxY = max($this->_maxY, $y + $h); |
|
| 3050 | - $this->_maxH = max($this->_maxH, $h); |
|
| 3051 | - } else { |
|
| 3052 | - $this->pdf->setXY($this->parsingCss->value['xc'], $this->parsingCss->value['yc']); |
|
| 3053 | - |
|
| 3054 | - $this->_loadMax(); |
|
| 3055 | - } |
|
| 3056 | - |
|
| 3057 | - $block = ($this->parsingCss->value['display'] != 'inline' && $this->parsingCss->value['position'] != 'absolute'); |
|
| 3058 | - |
|
| 3059 | - $this->parsingCss->load(); |
|
| 3060 | - $this->parsingCss->fontSet(); |
|
| 3061 | - $this->_loadMargin(); |
|
| 3062 | - |
|
| 3063 | - if ($block) { |
|
| 3064 | - $this->_tag_open_BR(array()); |
|
| 3065 | - } |
|
| 3066 | - if ($this->_debugActif) { |
|
| 3067 | - $this->_DEBUG_add(strtoupper($other), false); |
|
| 3068 | - } |
|
| 3069 | - |
|
| 3070 | - return true; |
|
| 3071 | - } |
|
| 3072 | - |
|
| 3073 | - /** |
|
| 3074 | - * tag : BLOCKQUOTE |
|
| 3075 | - * mode : CLOSE |
|
| 3076 | - * |
|
| 3077 | - * @param array $param |
|
| 3078 | - * @return boolean |
|
| 3079 | - */ |
|
| 3080 | - protected function _tag_close_BLOCKQUOTE($param) |
|
| 3081 | - { |
|
| 3082 | - return $this->_tag_close_DIV($param, 'blockquote'); |
|
| 3083 | - } |
|
| 3084 | - |
|
| 3085 | - /** |
|
| 3086 | - * tag : FIELDSET |
|
| 3087 | - * mode : CLOSE |
|
| 3088 | - * |
|
| 3089 | - * @param array $param |
|
| 3090 | - * @return boolean |
|
| 3091 | - */ |
|
| 3092 | - protected function _tag_close_FIELDSET($param) |
|
| 3093 | - { |
|
| 3094 | - return $this->_tag_close_DIV($param, 'fieldset'); |
|
| 3095 | - } |
|
| 3096 | - |
|
| 3097 | - /** |
|
| 3098 | - * tag : LEGEND |
|
| 3099 | - * mode : CLOSE |
|
| 3100 | - * |
|
| 3101 | - * @param array $param |
|
| 3102 | - * @return boolean |
|
| 3103 | - */ |
|
| 3104 | - protected function _tag_close_LEGEND($param) |
|
| 3105 | - { |
|
| 3106 | - return $this->_tag_close_DIV($param, 'legend'); |
|
| 3107 | - } |
|
| 3108 | - |
|
| 3109 | - /** |
|
| 3110 | - * tag : BARCODE |
|
| 3111 | - * mode : OPEN |
|
| 3112 | - * |
|
| 3113 | - * @param array $param |
|
| 3114 | - * @return boolean |
|
| 3115 | - */ |
|
| 3116 | - protected function _tag_open_BARCODE($param) |
|
| 3117 | - { |
|
| 3118 | - // for compatibility with old versions < 3.29 |
|
| 3119 | - $lstBarcode = array(); |
|
| 3120 | - $lstBarcode['UPC_A'] = 'UPCA'; |
|
| 3121 | - $lstBarcode['CODE39'] = 'C39'; |
|
| 3122 | - |
|
| 3123 | - if ( ! isset($param['type'])) $param['type'] = 'C39'; |
|
| 3124 | - if ( ! isset($param['value'])) $param['value'] = 0; |
|
| 3125 | - if ( ! isset($param['label'])) $param['label'] = 'label'; |
|
| 3126 | - if ( ! isset($param['style']['color'])) $param['style']['color'] = '#000000'; |
|
| 3127 | - |
|
| 3128 | - if ($this->_testIsDeprecated && (isset($param['bar_h']) || isset($param['bar_w']))) |
|
| 3129 | - throw new HTML2PDF_exception(9, array('BARCODE', 'bar_h, bar_w')); |
|
| 3130 | - |
|
| 3131 | - $param['type'] = strtoupper($param['type']); |
|
| 3132 | - if (isset($lstBarcode[$param['type']])) $param['type'] = $lstBarcode[$param['type']]; |
|
| 3133 | - |
|
| 3134 | - $this->parsingCss->save(); |
|
| 3135 | - $this->parsingCss->analyse('barcode', $param); |
|
| 3136 | - $this->parsingCss->setPosition(); |
|
| 3137 | - $this->parsingCss->fontSet(); |
|
| 3138 | - |
|
| 3139 | - $x = $this->pdf->getX(); |
|
| 3140 | - $y = $this->pdf->getY(); |
|
| 3141 | - $w = $this->parsingCss->value['width']; if ( ! $w) $w = $this->parsingCss->ConvertToMM('50mm'); |
|
| 3142 | - $h = $this->parsingCss->value['height']; if ( ! $h) $h = $this->parsingCss->ConvertToMM('10mm'); |
|
| 3143 | - $txt = ($param['label'] !== 'none' ? $this->parsingCss->value['font-size'] : false); |
|
| 3144 | - $c = $this->parsingCss->value['color']; |
|
| 3145 | - $infos = $this->pdf->myBarcode($param['value'], $param['type'], $x, $y, $w, $h, $txt, $c); |
|
| 3146 | - |
|
| 3147 | - $this->_maxX = max($this->_maxX, $x + $infos[0]); |
|
| 3148 | - $this->_maxY = max($this->_maxY, $y + $infos[1]); |
|
| 3149 | - $this->_maxH = max($this->_maxH, $infos[1]); |
|
| 3150 | - $this->_maxE++; |
|
| 3151 | - |
|
| 3152 | - $this->pdf->setXY($x + $infos[0], $y); |
|
| 3153 | - |
|
| 3154 | - $this->parsingCss->load(); |
|
| 3155 | - $this->parsingCss->fontSet(); |
|
| 3156 | - |
|
| 3157 | - return true; |
|
| 3158 | - } |
|
| 3159 | - |
|
| 3160 | - /** |
|
| 3161 | - * tag : BARCODE |
|
| 3162 | - * mode : CLOSE |
|
| 3163 | - * |
|
| 3164 | - * @param array $param |
|
| 3165 | - * @return boolean |
|
| 3166 | - */ |
|
| 3167 | - protected function _tag_close_BARCODE($param) |
|
| 3168 | - { |
|
| 3169 | - // there is nothing to do here |
|
| 3170 | - |
|
| 3171 | - return true; |
|
| 3172 | - } |
|
| 3173 | - |
|
| 3174 | - /** |
|
| 3175 | - * tag : QRCODE |
|
| 3176 | - * mode : OPEN |
|
| 3177 | - * |
|
| 3178 | - * @param array $param |
|
| 3179 | - * @return boolean |
|
| 3180 | - */ |
|
| 3181 | - protected function _tag_open_QRCODE($param) |
|
| 3182 | - { |
|
| 3183 | - if ($this->_testIsDeprecated && (isset($param['size']) || isset($param['noborder']))) |
|
| 3184 | - throw new HTML2PDF_exception(9, array('QRCODE', 'size, noborder')); |
|
| 3185 | - |
|
| 3186 | - if ($this->_debugActif) $this->_DEBUG_add('QRCODE'); |
|
| 3187 | - |
|
| 3188 | - if ( ! isset($param['value'])) $param['value'] = ''; |
|
| 3189 | - if ( ! isset($param['ec'])) $param['ec'] = 'H'; |
|
| 3190 | - if ( ! isset($param['style']['color'])) $param['style']['color'] = '#000000'; |
|
| 3191 | - if ( ! isset($param['style']['background-color'])) $param['style']['background-color'] = '#FFFFFF'; |
|
| 3192 | - if (isset($param['style']['border'])) { |
|
| 3193 | - $borders = $param['style']['border'] != 'none'; |
|
| 3194 | - unset($param['style']['border']); |
|
| 3195 | - } else { |
|
| 3196 | - $borders = true; |
|
| 3197 | - } |
|
| 3198 | - |
|
| 3199 | - if ($param['value'] === '') return true; |
|
| 3200 | - if ( ! in_array($param['ec'], array('L', 'M', 'Q', 'H'))) $param['ec'] = 'H'; |
|
| 3201 | - |
|
| 3202 | - $this->parsingCss->save(); |
|
| 3203 | - $this->parsingCss->analyse('qrcode', $param); |
|
| 3204 | - $this->parsingCss->setPosition(); |
|
| 3205 | - $this->parsingCss->fontSet(); |
|
| 3206 | - |
|
| 3207 | - $x = $this->pdf->getX(); |
|
| 3208 | - $y = $this->pdf->getY(); |
|
| 3209 | - $w = $this->parsingCss->value['width']; |
|
| 3210 | - $h = $this->parsingCss->value['height']; |
|
| 3211 | - $size = max($w, $h); if ( ! $size) $size = $this->parsingCss->ConvertToMM('50mm'); |
|
| 3212 | - |
|
| 3213 | - $style = array( |
|
| 3214 | - 'fgcolor' => $this->parsingCss->value['color'], |
|
| 3215 | - 'bgcolor' => $this->parsingCss->value['background']['color'], |
|
| 3216 | - ); |
|
| 3217 | - |
|
| 3218 | - if ($borders) { |
|
| 3219 | - $style['border'] = true; |
|
| 3220 | - $style['padding'] = 'auto'; |
|
| 3221 | - } else { |
|
| 3222 | - $style['border'] = false; |
|
| 3223 | - $style['padding'] = 0; |
|
| 3224 | - } |
|
| 3225 | - |
|
| 3226 | - if ( ! $this->_subPart && ! $this->_isSubPart) { |
|
| 3227 | - $this->pdf->write2DBarcode($param['value'], 'QRCODE,'.$param['ec'], $x, $y, $size, $size, $style); |
|
| 3228 | - } |
|
| 3229 | - |
|
| 3230 | - $this->_maxX = max($this->_maxX, $x + $size); |
|
| 3231 | - $this->_maxY = max($this->_maxY, $y + $size); |
|
| 3232 | - $this->_maxH = max($this->_maxH, $size); |
|
| 3233 | - $this->_maxE++; |
|
| 3234 | - |
|
| 3235 | - $this->pdf->setX($x + $size); |
|
| 3236 | - |
|
| 3237 | - $this->parsingCss->load(); |
|
| 3238 | - $this->parsingCss->fontSet(); |
|
| 3239 | - |
|
| 3240 | - return true; |
|
| 3241 | - } |
|
| 3242 | - |
|
| 3243 | - /** |
|
| 3244 | - * tag : QRCODE |
|
| 3245 | - * mode : CLOSE |
|
| 3246 | - * |
|
| 3247 | - * @param array $param |
|
| 3248 | - * @return boolean |
|
| 3249 | - */ |
|
| 3250 | - protected function _tag_close_QRCODE($param) |
|
| 3251 | - { |
|
| 3252 | - // there is nothing to do here |
|
| 3253 | - |
|
| 3254 | - return true; |
|
| 3255 | - } |
|
| 3256 | - |
|
| 3257 | - /** |
|
| 3258 | - * tag : BOOKMARK |
|
| 3259 | - * mode : OPEN |
|
| 3260 | - * |
|
| 3261 | - * @param array $param |
|
| 3262 | - * @return boolean |
|
| 3263 | - */ |
|
| 3264 | - protected function _tag_open_BOOKMARK($param) |
|
| 3265 | - { |
|
| 3266 | - $titre = isset($param['title']) ? trim($param['title']) : ''; |
|
| 3267 | - $level = isset($param['level']) ? floor($param['level']) : 0; |
|
| 3268 | - |
|
| 3269 | - if ($level < 0) $level = 0; |
|
| 3270 | - if ($titre) $this->pdf->Bookmark($titre, $level, -1); |
|
| 3271 | - |
|
| 3272 | - return true; |
|
| 3273 | - } |
|
| 3274 | - |
|
| 3275 | - /** |
|
| 3276 | - * tag : BOOKMARK |
|
| 3277 | - * mode : CLOSE |
|
| 3278 | - * |
|
| 3279 | - * @param array $param |
|
| 3280 | - * @return boolean |
|
| 3281 | - */ |
|
| 3282 | - protected function _tag_close_BOOKMARK($param) |
|
| 3283 | - { |
|
| 3284 | - // there is nothing to do here |
|
| 3285 | - |
|
| 3286 | - return true; |
|
| 3287 | - } |
|
| 3288 | - |
|
| 3289 | - /** |
|
| 3290 | - * this is not a real TAG, it is just to write texts |
|
| 3291 | - * |
|
| 3292 | - * @param array $param |
|
| 3293 | - * @return null|boolean |
|
| 3294 | - */ |
|
| 3295 | - protected function _tag_open_WRITE($param) |
|
| 3296 | - { |
|
| 3297 | - $fill = ($this->parsingCss->value['background']['color'] !== null && $this->parsingCss->value['background']['image'] === null); |
|
| 3298 | - if (in_array($this->parsingCss->value['id_tag'], array('fieldset', 'legend', 'div', 'table', 'tr', 'td', 'th'))) { |
|
| 3299 | - $fill = false; |
|
| 3300 | - } |
|
| 3301 | - |
|
| 3302 | - // get the text to write |
|
| 3303 | - $txt = $param['txt']; |
|
| 3304 | - |
|
| 3305 | - if ($this->_isAfterFloat) { |
|
| 3306 | - $txt = ltrim($txt); |
|
| 3307 | - $this->_isAfterFloat = false; |
|
| 3308 | - } |
|
| 3309 | - |
|
| 3310 | - $txt = str_replace('[[page_nb]]', $this->pdf->getMyAliasNbPages(), $txt); |
|
| 3311 | - $txt = str_replace('[[page_cu]]', $this->pdf->getMyNumPage($this->_page), $txt); |
|
| 3312 | - |
|
| 3313 | - if ($this->parsingCss->value['text-transform'] != 'none') { |
|
| 3314 | - if ($this->parsingCss->value['text-transform'] == 'capitalize') |
|
| 3315 | - $txt = ucwords($txt); |
|
| 3316 | - else if ($this->parsingCss->value['text-transform'] == 'uppercase') |
|
| 3317 | - $txt = strtoupper($txt); |
|
| 3318 | - else if ($this->parsingCss->value['text-transform'] == 'lowercase') |
|
| 3319 | - $txt = strtolower($txt); |
|
| 3320 | - } |
|
| 3321 | - |
|
| 3322 | - // size of the text |
|
| 3323 | - $h = 1.08 * $this->parsingCss->value['font-size']; |
|
| 3324 | - $dh = $h * $this->parsingCss->value['mini-decal']; |
|
| 3325 | - $lh = $this->parsingCss->getLineHeight(); |
|
| 3326 | - |
|
| 3327 | - // identify the align |
|
| 3328 | - $align = 'L'; |
|
| 3329 | - if ($this->parsingCss->value['text-align'] == 'li_right') { |
|
| 3330 | - $w = $this->parsingCss->value['width']; |
|
| 3331 | - $align = 'R'; |
|
| 3332 | - } |
|
| 3333 | - |
|
| 3334 | - // calculate the width of each words, and of all the sentence |
|
| 3335 | - $w = 0; |
|
| 3336 | - $words = explode(' ', $txt); |
|
| 3337 | - foreach ($words as $k => $word) { |
|
| 3338 | - $words[$k] = array($word, $this->pdf->GetStringWidth($word)); |
|
| 3339 | - $w += $words[$k][1]; |
|
| 3340 | - } |
|
| 3341 | - $space = $this->pdf->GetStringWidth(' '); |
|
| 3342 | - $w += $space * (count($words) - 1); |
|
| 3343 | - |
|
| 3344 | - // position in the text |
|
| 3345 | - $currPos = 0; |
|
| 3346 | - |
|
| 3347 | - // the bigger width of the text, after automatic break line |
|
| 3348 | - $maxX = 0; |
|
| 3349 | - |
|
| 3350 | - // position of the text |
|
| 3351 | - $x = $this->pdf->getX(); |
|
| 3352 | - $y = $this->pdf->getY(); |
|
| 3353 | - $dy = $this->_getElementY($lh); |
|
| 3354 | - |
|
| 3355 | - // margins |
|
| 3356 | - list($left, $right) = $this->_getMargins($y); |
|
| 3357 | - |
|
| 3358 | - // number of lines after automatic break line |
|
| 3359 | - $nb = 0; |
|
| 3360 | - |
|
| 3361 | - // while we have words, and the text does not fit on the line => we cut the sentence |
|
| 3362 | - while ($x + $w > $right && $x < $right + $space && count($words)) { |
|
| 3363 | - // adding words 1 by 1 to fit on the line |
|
| 3364 | - $i = 0; |
|
| 3365 | - $old = array('', 0); |
|
| 3366 | - $str = $words[0]; |
|
| 3367 | - $add = false; |
|
| 3368 | - while (($x + $str[1]) < $right) { |
|
| 3369 | - $i++; |
|
| 3370 | - $add = true; |
|
| 3371 | - |
|
| 3372 | - array_shift($words); |
|
| 3373 | - $old = $str; |
|
| 3374 | - |
|
| 3375 | - if ( ! count($words)) break; |
|
| 3376 | - $str[0] .= ' '.$words[0][0]; |
|
| 3377 | - $str[1] += $space + $words[0][1]; |
|
| 3378 | - } |
|
| 3379 | - $str = $old; |
|
| 3380 | - |
|
| 3381 | - // if nothing fit on the line, and if the first word does not fit on the line => the word is too long, we put it |
|
| 3382 | - if ($i == 0 && (($left + $words[0][1]) >= $right)) { |
|
| 3383 | - $str = $words[0]; |
|
| 3384 | - array_shift($words); |
|
| 3385 | - $i++; |
|
| 3386 | - $add = true; |
|
| 3387 | - } |
|
| 3388 | - $currPos += ($currPos ? 1 : 0) + strlen($str[0]); |
|
| 3389 | - |
|
| 3390 | - // write the extract sentence that fit on the page |
|
| 3391 | - $wc = ($align == 'L' ? $str[1] : $this->parsingCss->value['width']); |
|
| 3392 | - if ($right - $left < $wc) $wc = $right - $left; |
|
| 3393 | - |
|
| 3394 | - if (strlen($str[0])) { |
|
| 3395 | - $this->pdf->setXY($this->pdf->getX(), $y + $dh + $dy); |
|
| 3396 | - $this->pdf->Cell($wc, $h, $str[0], 0, 0, $align, $fill, $this->_isInLink); |
|
| 3397 | - $this->pdf->setXY($this->pdf->getX(), $y); |
|
| 3398 | - } |
|
| 3399 | - $this->_maxH = max($this->_maxH, $lh); |
|
| 3400 | - |
|
| 3401 | - // max width |
|
| 3402 | - $maxX = max($maxX, $this->pdf->getX()); |
|
| 3403 | - |
|
| 3404 | - // new position and new width for the "while" |
|
| 3405 | - $w -= $str[1]; |
|
| 3406 | - $y = $this->pdf->getY(); |
|
| 3407 | - $x = $this->pdf->getX(); |
|
| 3408 | - $dy = $this->_getElementY($lh); |
|
| 3409 | - |
|
| 3410 | - // if we have again words to write |
|
| 3411 | - if (count($words)) { |
|
| 3412 | - // remove the space at the end |
|
| 3413 | - if ($add) $w -= $space; |
|
| 3414 | - |
|
| 3415 | - // if we don't add any word, and if the first word is empty => useless space to skip |
|
| 3416 | - if ( ! $add && $words[0][0] === '') { |
|
| 3417 | - array_shift($words); |
|
| 3418 | - } |
|
| 3419 | - |
|
| 3420 | - // if it is just to calculate for one line => adding the number of words |
|
| 3421 | - if ($this->_isForOneLine) { |
|
| 3422 | - $this->_maxE += $i; |
|
| 3423 | - $this->_maxX = max($this->_maxX, $maxX); |
|
| 3424 | - return null; |
|
| 3425 | - } |
|
| 3426 | - |
|
| 3427 | - // automatic line break |
|
| 3428 | - $this->_tag_open_BR(array('style' => ''), $currPos); |
|
| 3429 | - |
|
| 3430 | - // new position |
|
| 3431 | - $y = $this->pdf->getY(); |
|
| 3432 | - $x = $this->pdf->getX(); |
|
| 3433 | - $dy = $this->_getElementY($lh); |
|
| 3434 | - |
|
| 3435 | - // if the next line does not fit on the page => new page |
|
| 3436 | - if ($y + $h >= $this->pdf->getH() - $this->pdf->getbMargin()) { |
|
| 3437 | - if ( ! $this->_isInOverflow && ! $this->_isInFooter) { |
|
| 3438 | - $this->_setNewPage(null, '', null, $currPos); |
|
| 3439 | - $y = $this->pdf->getY(); |
|
| 3440 | - $x = $this->pdf->getX(); |
|
| 3441 | - $dy = $this->_getElementY($lh); |
|
| 3442 | - } |
|
| 3443 | - } |
|
| 3444 | - |
|
| 3445 | - // if more than 10000 line => error |
|
| 3446 | - $nb++; |
|
| 3447 | - if ($nb > 10000) { |
|
| 3448 | - $txt = ''; foreach ($words as $k => $word) $txt .= ($k ? ' ' : '').$word[0]; |
|
| 3449 | - throw new HTML2PDF_exception(2, array($txt, $right - $left, $w)); |
|
| 3450 | - } |
|
| 3451 | - |
|
| 3452 | - // new margins for the new line |
|
| 3453 | - list($left, $right) = $this->_getMargins($y); |
|
| 3454 | - } |
|
| 3455 | - } |
|
| 3456 | - |
|
| 3457 | - // if we have words after automatic cut, it is because they fit on the line => we write the text |
|
| 3458 | - if (count($words)) { |
|
| 3459 | - $txt = ''; foreach ($words as $k => $word) $txt .= ($k ? ' ' : '').$word[0]; |
|
| 3460 | - $w += $this->pdf->getWordSpacing() * (count($words)); |
|
| 3461 | - $this->pdf->setXY($this->pdf->getX(), $y + $dh + $dy); |
|
| 3462 | - $this->pdf->Cell(($align == 'L' ? $w : $this->parsingCss->value['width']), $h, $txt, 0, 0, $align, $fill, $this->_isInLink); |
|
| 3463 | - $this->pdf->setXY($this->pdf->getX(), $y); |
|
| 3464 | - $this->_maxH = max($this->_maxH, $lh); |
|
| 3465 | - $this->_maxE += count($words); |
|
| 3466 | - } |
|
| 3467 | - |
|
| 3468 | - $maxX = max($maxX, $this->pdf->getX()); |
|
| 3469 | - $maxY = $this->pdf->getY() + $h; |
|
| 3470 | - |
|
| 3471 | - $this->_maxX = max($this->_maxX, $maxX); |
|
| 3472 | - $this->_maxY = max($this->_maxY, $maxY); |
|
| 3473 | - |
|
| 3474 | - return true; |
|
| 3475 | - } |
|
| 3476 | - |
|
| 3477 | - /** |
|
| 3478 | - * tag : BR |
|
| 3479 | - * mode : OPEN |
|
| 3480 | - * |
|
| 3481 | - * @param array $param |
|
| 3482 | - * @param integer $curr real position in the html parseur (if break line in the write of a text) |
|
| 3483 | - * @return boolean |
|
| 3484 | - */ |
|
| 3485 | - protected function _tag_open_BR($param, $curr = null) |
|
| 3486 | - { |
|
| 3487 | - if ($this->_isForOneLine) return false; |
|
| 3488 | - |
|
| 3489 | - $h = max($this->_maxH, $this->parsingCss->getLineHeight()); |
|
| 3490 | - |
|
| 3491 | - if ($this->_maxH == 0) $this->_maxY = max($this->_maxY, $this->pdf->getY() + $h); |
|
| 3492 | - |
|
| 3493 | - $this->_makeBreakLine($h, $curr); |
|
| 3494 | - |
|
| 3495 | - $this->_maxH = 0; |
|
| 3496 | - $this->_maxE = 0; |
|
| 3497 | - |
|
| 3498 | - return true; |
|
| 3499 | - } |
|
| 3500 | - |
|
| 3501 | - /** |
|
| 3502 | - * tag : HR |
|
| 3503 | - * mode : OPEN |
|
| 3504 | - * |
|
| 3505 | - * @param array $param |
|
| 3506 | - * @return boolean |
|
| 3507 | - */ |
|
| 3508 | - protected function _tag_open_HR($param) |
|
| 3509 | - { |
|
| 3510 | - if ($this->_isForOneLine) { |
|
| 3511 | - return false; |
|
| 3512 | - } |
|
| 3513 | - $oldAlign = $this->parsingCss->value['text-align']; |
|
| 3514 | - $this->parsingCss->value['text-align'] = 'left'; |
|
| 3515 | - |
|
| 3516 | - if ($this->_maxH) { |
|
| 3517 | - $this->_tag_open_BR($param); |
|
| 3518 | - } |
|
| 3519 | - |
|
| 3520 | - $fontSize = $this->parsingCss->value['font-size']; |
|
| 3521 | - $this->parsingCss->value['font-size'] = $fontSize * 0.5; $this->_tag_open_BR($param); |
|
| 3522 | - $this->parsingCss->value['font-size'] = 0; |
|
| 3523 | - |
|
| 3524 | - $param['style']['width'] = '100%'; |
|
| 3525 | - |
|
| 3526 | - $this->parsingCss->save(); |
|
| 3527 | - $this->parsingCss->value['height'] = $this->parsingCss->ConvertToMM('1mm'); |
|
| 3528 | - |
|
| 3529 | - $this->parsingCss->analyse('hr', $param); |
|
| 3530 | - $this->parsingCss->setPosition(); |
|
| 3531 | - $this->parsingCss->fontSet(); |
|
| 3532 | - |
|
| 3533 | - $h = $this->parsingCss->value['height']; |
|
| 3534 | - if ($h) $h -= $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['border']['b']['width']; |
|
| 3535 | - if ($h <= 0) $h = $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['border']['b']['width']; |
|
| 3536 | - |
|
| 3537 | - $this->_drawRectangle($this->pdf->getX(), $this->pdf->getY(), $this->parsingCss->value['width'], $h, $this->parsingCss->value['border'], 0, 0, $this->parsingCss->value['background']); |
|
| 3538 | - $this->_maxH = $h; |
|
| 3539 | - |
|
| 3540 | - $this->parsingCss->load(); |
|
| 3541 | - $this->parsingCss->fontSet(); |
|
| 3542 | - |
|
| 3543 | - $this->_tag_open_BR($param); |
|
| 3544 | - |
|
| 3545 | - $this->parsingCss->value['font-size'] = $fontSize * 0.5; $this->_tag_open_BR($param); |
|
| 3546 | - $this->parsingCss->value['font-size'] = $fontSize; |
|
| 3547 | - |
|
| 3548 | - $this->parsingCss->value['text-align'] = $oldAlign; |
|
| 3549 | - $this->_setNewPositionForNewLine(); |
|
| 3550 | - |
|
| 3551 | - return true; |
|
| 3552 | - } |
|
| 3553 | - |
|
| 3554 | - /** |
|
| 3555 | - * tag : B |
|
| 3556 | - * mode : OPEN |
|
| 3557 | - * |
|
| 3558 | - * @param array $param |
|
| 3559 | - * @param string $other |
|
| 3560 | - * @return boolean |
|
| 3561 | - */ |
|
| 3562 | - protected function _tag_open_B($param, $other = 'b') |
|
| 3563 | - { |
|
| 3564 | - $this->parsingCss->save(); |
|
| 3565 | - $this->parsingCss->value['font-bold'] = true; |
|
| 3566 | - $this->parsingCss->analyse($other, $param); |
|
| 3567 | - $this->parsingCss->setPosition(); |
|
| 3568 | - $this->parsingCss->fontSet(); |
|
| 3569 | - |
|
| 3570 | - return true; |
|
| 3571 | - } |
|
| 3572 | - |
|
| 3573 | - /** |
|
| 3574 | - * tag : STRONG |
|
| 3575 | - * mode : OPEN |
|
| 3576 | - * |
|
| 3577 | - * @param array $param |
|
| 3578 | - * @return boolean |
|
| 3579 | - */ |
|
| 3580 | - protected function _tag_open_STRONG($param) |
|
| 3581 | - { |
|
| 3582 | - return $this->_tag_open_B($param, 'strong'); |
|
| 3583 | - } |
|
| 3584 | - |
|
| 3585 | - /** |
|
| 3586 | - * tag : B |
|
| 3587 | - * mode : CLOSE |
|
| 3588 | - * |
|
| 3589 | - * @param array $param |
|
| 3590 | - * @return boolean |
|
| 3591 | - */ |
|
| 3592 | - protected function _tag_close_B($param) |
|
| 3593 | - { |
|
| 3594 | - $this->parsingCss->load(); |
|
| 3595 | - $this->parsingCss->fontSet(); |
|
| 3596 | - |
|
| 3597 | - return true; |
|
| 3598 | - } |
|
| 3599 | - |
|
| 3600 | - /** |
|
| 3601 | - * tag : STRONG |
|
| 3602 | - * mode : CLOSE |
|
| 3603 | - * |
|
| 3604 | - * @param array $param |
|
| 3605 | - * @return boolean |
|
| 3606 | - */ |
|
| 3607 | - protected function _tag_close_STRONG($param) |
|
| 3608 | - { |
|
| 3609 | - return $this->_tag_close_B($param); |
|
| 3610 | - } |
|
| 3611 | - |
|
| 3612 | - /** |
|
| 3613 | - * tag : I |
|
| 3614 | - * mode : OPEN |
|
| 3615 | - * |
|
| 3616 | - * @param array $param |
|
| 3617 | - * @param string $other |
|
| 3618 | - * @return boolean |
|
| 3619 | - */ |
|
| 3620 | - protected function _tag_open_I($param, $other = 'i') |
|
| 3621 | - { |
|
| 3622 | - $this->parsingCss->save(); |
|
| 3623 | - $this->parsingCss->value['font-italic'] = true; |
|
| 3624 | - $this->parsingCss->analyse($other, $param); |
|
| 3625 | - $this->parsingCss->setPosition(); |
|
| 3626 | - $this->parsingCss->fontSet(); |
|
| 3627 | - |
|
| 3628 | - return true; |
|
| 3629 | - } |
|
| 3630 | - |
|
| 3631 | - /** |
|
| 3632 | - * tag : ADDRESS |
|
| 3633 | - * mode : OPEN |
|
| 3634 | - * |
|
| 3635 | - * @param array $param |
|
| 3636 | - * @return boolean |
|
| 3637 | - */ |
|
| 3638 | - protected function _tag_open_ADDRESS($param) |
|
| 3639 | - { |
|
| 3640 | - return $this->_tag_open_I($param, 'address'); |
|
| 3641 | - } |
|
| 3642 | - |
|
| 3643 | - /** |
|
| 3644 | - * tag : CITE |
|
| 3645 | - * mode : OPEN |
|
| 3646 | - * |
|
| 3647 | - * @param array $param |
|
| 3648 | - * @return boolean |
|
| 3649 | - */ |
|
| 3650 | - protected function _tag_open_CITE($param) |
|
| 3651 | - { |
|
| 3652 | - return $this->_tag_open_I($param, 'cite'); |
|
| 3653 | - } |
|
| 3654 | - |
|
| 3655 | - /** |
|
| 3656 | - * tag : EM |
|
| 3657 | - * mode : OPEN |
|
| 3658 | - * |
|
| 3659 | - * @param array $param |
|
| 3660 | - * @return boolean |
|
| 3661 | - */ |
|
| 3662 | - protected function _tag_open_EM($param) |
|
| 3663 | - { |
|
| 3664 | - return $this->_tag_open_I($param, 'em'); |
|
| 3665 | - } |
|
| 3666 | - |
|
| 3667 | - /** |
|
| 3668 | - * tag : SAMP |
|
| 3669 | - * mode : OPEN |
|
| 3670 | - * |
|
| 3671 | - * @param array $param |
|
| 3672 | - * @return boolean |
|
| 3673 | - */ |
|
| 3674 | - protected function _tag_open_SAMP($param) |
|
| 3675 | - { |
|
| 3676 | - return $this->_tag_open_I($param, 'samp'); |
|
| 3677 | - } |
|
| 3678 | - |
|
| 3679 | - /** |
|
| 3680 | - * tag : I |
|
| 3681 | - * mode : CLOSE |
|
| 3682 | - * |
|
| 3683 | - * @param array $param |
|
| 3684 | - * @return boolean |
|
| 3685 | - */ |
|
| 3686 | - protected function _tag_close_I($param) |
|
| 3687 | - { |
|
| 3688 | - $this->parsingCss->load(); |
|
| 3689 | - $this->parsingCss->fontSet(); |
|
| 3690 | - |
|
| 3691 | - return true; |
|
| 3692 | - } |
|
| 3693 | - |
|
| 3694 | - /** |
|
| 3695 | - * tag : ADDRESS |
|
| 3696 | - * mode : CLOSE |
|
| 3697 | - * |
|
| 3698 | - * @param array $param |
|
| 3699 | - * @return boolean |
|
| 3700 | - */ |
|
| 3701 | - protected function _tag_close_ADDRESS($param) |
|
| 3702 | - { |
|
| 3703 | - return $this->_tag_close_I($param); |
|
| 3704 | - } |
|
| 3705 | - |
|
| 3706 | - /** |
|
| 3707 | - * tag : CITE |
|
| 3708 | - * mode : CLOSE |
|
| 3709 | - * |
|
| 3710 | - * @param array $param |
|
| 3711 | - * @return boolean |
|
| 3712 | - */ |
|
| 3713 | - protected function _tag_close_CITE($param) |
|
| 3714 | - { |
|
| 3715 | - return $this->_tag_close_I($param); |
|
| 3716 | - } |
|
| 3717 | - |
|
| 3718 | - /** |
|
| 3719 | - * tag : EM |
|
| 3720 | - * mode : CLOSE |
|
| 3721 | - * |
|
| 3722 | - * @param array $param |
|
| 3723 | - * @return boolean |
|
| 3724 | - */ |
|
| 3725 | - protected function _tag_close_EM($param) |
|
| 3726 | - { |
|
| 3727 | - return $this->_tag_close_I($param); |
|
| 3728 | - } |
|
| 3729 | - |
|
| 3730 | - /** |
|
| 3731 | - * tag : SAMP |
|
| 3732 | - * mode : CLOSE |
|
| 3733 | - * |
|
| 3734 | - * @param array $param |
|
| 3735 | - * @return boolean |
|
| 3736 | - */ |
|
| 3737 | - protected function _tag_close_SAMP($param) |
|
| 3738 | - { |
|
| 3739 | - return $this->_tag_close_I($param); |
|
| 3740 | - } |
|
| 3741 | - |
|
| 3742 | - /** |
|
| 3743 | - * tag : S |
|
| 3744 | - * mode : OPEN |
|
| 3745 | - * |
|
| 3746 | - * @param array $param |
|
| 3747 | - * @param string $other |
|
| 3748 | - * @return boolean |
|
| 3749 | - */ |
|
| 3750 | - protected function _tag_open_S($param, $other = 's') |
|
| 3751 | - { |
|
| 3752 | - $this->parsingCss->save(); |
|
| 3753 | - $this->parsingCss->value['font-linethrough'] = true; |
|
| 3754 | - $this->parsingCss->analyse($other, $param); |
|
| 3755 | - $this->parsingCss->setPosition(); |
|
| 3756 | - $this->parsingCss->fontSet(); |
|
| 3757 | - |
|
| 3758 | - return true; |
|
| 3759 | - } |
|
| 3760 | - |
|
| 3761 | - /** |
|
| 3762 | - * tag : DEL |
|
| 3763 | - * mode : OPEN |
|
| 3764 | - * |
|
| 3765 | - * @param array $param |
|
| 3766 | - * @return boolean |
|
| 3767 | - */ |
|
| 3768 | - protected function _tag_open_DEL($param) |
|
| 3769 | - { |
|
| 3770 | - return $this->_tag_open_S($param, 'del'); |
|
| 3771 | - } |
|
| 3772 | - |
|
| 3773 | - /** |
|
| 3774 | - * tag : S |
|
| 3775 | - * mode : CLOSE |
|
| 3776 | - * |
|
| 3777 | - * @param array $param |
|
| 3778 | - * @return boolean |
|
| 3779 | - */ |
|
| 3780 | - protected function _tag_close_S($param) |
|
| 3781 | - { |
|
| 3782 | - $this->parsingCss->load(); |
|
| 3783 | - $this->parsingCss->fontSet(); |
|
| 3784 | - |
|
| 3785 | - return true; |
|
| 3786 | - } |
|
| 3787 | - |
|
| 3788 | - /** |
|
| 3789 | - * tag : DEL |
|
| 3790 | - * mode : CLOSE |
|
| 3791 | - * |
|
| 3792 | - * @param array $param |
|
| 3793 | - * @return boolean |
|
| 3794 | - */ |
|
| 3795 | - protected function _tag_close_DEL($param) |
|
| 3796 | - { |
|
| 3797 | - return $this->_tag_close_S($param); |
|
| 3798 | - } |
|
| 3799 | - |
|
| 3800 | - /** |
|
| 3801 | - * tag : U |
|
| 3802 | - * mode : OPEN |
|
| 3803 | - * |
|
| 3804 | - * @param array $param |
|
| 3805 | - * @param string $other |
|
| 3806 | - * @return boolean |
|
| 3807 | - */ |
|
| 3808 | - protected function _tag_open_U($param, $other = 'u') |
|
| 3809 | - { |
|
| 3810 | - $this->parsingCss->save(); |
|
| 3811 | - $this->parsingCss->value['font-underline'] = true; |
|
| 3812 | - $this->parsingCss->analyse($other, $param); |
|
| 3813 | - $this->parsingCss->setPosition(); |
|
| 3814 | - $this->parsingCss->fontSet(); |
|
| 3815 | - |
|
| 3816 | - return true; |
|
| 3817 | - } |
|
| 3818 | - |
|
| 3819 | - /** |
|
| 3820 | - * tag : INS |
|
| 3821 | - * mode : OPEN |
|
| 3822 | - * |
|
| 3823 | - * @param array $param |
|
| 3824 | - * @return boolean |
|
| 3825 | - */ |
|
| 3826 | - protected function _tag_open_INS($param) |
|
| 3827 | - { |
|
| 3828 | - return $this->_tag_open_U($param, 'ins'); |
|
| 3829 | - } |
|
| 3830 | - |
|
| 3831 | - /** |
|
| 3832 | - * tag : U |
|
| 3833 | - * mode : CLOSE |
|
| 3834 | - * |
|
| 3835 | - * @param array $param |
|
| 3836 | - * @return boolean |
|
| 3837 | - */ |
|
| 3838 | - protected function _tag_close_U($param) |
|
| 3839 | - { |
|
| 3840 | - $this->parsingCss->load(); |
|
| 3841 | - $this->parsingCss->fontSet(); |
|
| 3842 | - |
|
| 3843 | - return true; |
|
| 3844 | - } |
|
| 3845 | - |
|
| 3846 | - /** |
|
| 3847 | - * tag : INS |
|
| 3848 | - * mode : CLOSE |
|
| 3849 | - * |
|
| 3850 | - * @param array $param |
|
| 3851 | - * @return boolean |
|
| 3852 | - */ |
|
| 3853 | - protected function _tag_close_INS($param) |
|
| 3854 | - { |
|
| 3855 | - return $this->_tag_close_U($param); |
|
| 3856 | - } |
|
| 3857 | - |
|
| 3858 | - /** |
|
| 3859 | - * tag : A |
|
| 3860 | - * mode : OPEN |
|
| 3861 | - * |
|
| 3862 | - * @param array $param |
|
| 3863 | - * @return boolean |
|
| 3864 | - */ |
|
| 3865 | - protected function _tag_open_A($param) |
|
| 3866 | - { |
|
| 3867 | - $this->_isInLink = str_replace('&', '&', isset($param['href']) ? $param['href'] : ''); |
|
| 3868 | - |
|
| 3869 | - if (isset($param['name'])) { |
|
| 3870 | - $name = $param['name']; |
|
| 3871 | - if ( ! isset($this->_lstAnchor[$name])) $this->_lstAnchor[$name] = array($this->pdf->AddLink(), false); |
|
| 3872 | - |
|
| 3873 | - if ( ! $this->_lstAnchor[$name][1]) { |
|
| 3874 | - $this->_lstAnchor[$name][1] = true; |
|
| 3875 | - $this->pdf->SetLink($this->_lstAnchor[$name][0], -1, -1); |
|
| 3876 | - } |
|
| 3877 | - } |
|
| 3878 | - |
|
| 3879 | - if (preg_match('/^#([^#]+)$/isU', $this->_isInLink, $match)) { |
|
| 3880 | - $name = $match[1]; |
|
| 3881 | - if ( ! isset($this->_lstAnchor[$name])) $this->_lstAnchor[$name] = array($this->pdf->AddLink(), false); |
|
| 3882 | - |
|
| 3883 | - $this->_isInLink = $this->_lstAnchor[$name][0]; |
|
| 3884 | - } |
|
| 3885 | - |
|
| 3886 | - $this->parsingCss->save(); |
|
| 3887 | - $this->parsingCss->value['font-underline'] = true; |
|
| 3888 | - $this->parsingCss->value['color'] = array(20, 20, 250); |
|
| 3889 | - $this->parsingCss->analyse('a', $param); |
|
| 3890 | - $this->parsingCss->setPosition(); |
|
| 3891 | - $this->parsingCss->fontSet(); |
|
| 3892 | - |
|
| 3893 | - return true; |
|
| 3894 | - } |
|
| 3895 | - |
|
| 3896 | - /** |
|
| 3897 | - * tag : A |
|
| 3898 | - * mode : CLOSE |
|
| 3899 | - * |
|
| 3900 | - * @param array $param |
|
| 3901 | - * @return boolean |
|
| 3902 | - */ |
|
| 3903 | - protected function _tag_close_A($param) |
|
| 3904 | - { |
|
| 3905 | - $this->_isInLink = ''; |
|
| 3906 | - $this->parsingCss->load(); |
|
| 3907 | - $this->parsingCss->fontSet(); |
|
| 3908 | - |
|
| 3909 | - return true; |
|
| 3910 | - } |
|
| 3911 | - |
|
| 3912 | - /** |
|
| 3913 | - * tag : H1 |
|
| 3914 | - * mode : OPEN |
|
| 3915 | - * |
|
| 3916 | - * @param array $param |
|
| 3917 | - * @param string $other |
|
| 3918 | - * @return boolean |
|
| 3919 | - */ |
|
| 3920 | - protected function _tag_open_H1($param, $other = 'h1') |
|
| 3921 | - { |
|
| 3922 | - if ($this->_isForOneLine) { |
|
| 3923 | - return false; |
|
| 3924 | - } |
|
| 3925 | - |
|
| 3926 | - if ($this->_maxH) { |
|
| 3927 | - $this->_tag_open_BR(array()); |
|
| 3928 | - } |
|
| 3929 | - $this->parsingCss->save(); |
|
| 3930 | - $this->parsingCss->value['font-bold'] = true; |
|
| 3931 | - |
|
| 3932 | - $size = array('h1' => '28px', 'h2' => '24px', 'h3' => '20px', 'h4' => '16px', 'h5' => '12px', 'h6' => '9px'); |
|
| 3933 | - $this->parsingCss->value['margin']['l'] = 0; |
|
| 3934 | - $this->parsingCss->value['margin']['r'] = 0; |
|
| 3935 | - $this->parsingCss->value['margin']['t'] = $this->parsingCss->ConvertToMM('16px'); |
|
| 3936 | - $this->parsingCss->value['margin']['b'] = $this->parsingCss->ConvertToMM('16px'); |
|
| 3937 | - $this->parsingCss->value['font-size'] = $this->parsingCss->ConvertToMM($size[$other]); |
|
| 3938 | - |
|
| 3939 | - $this->parsingCss->analyse($other, $param); |
|
| 3940 | - $this->parsingCss->setPosition(); |
|
| 3941 | - $this->parsingCss->fontSet(); |
|
| 3942 | - $this->_setNewPositionForNewLine(); |
|
| 3943 | - |
|
| 3944 | - return true; |
|
| 3945 | - } |
|
| 3946 | - |
|
| 3947 | - /** |
|
| 3948 | - * tag : H2 |
|
| 3949 | - * mode : OPEN |
|
| 3950 | - * |
|
| 3951 | - * @param array $param |
|
| 3952 | - * @return boolean |
|
| 3953 | - */ |
|
| 3954 | - protected function _tag_open_H2($param) |
|
| 3955 | - { |
|
| 3956 | - return $this->_tag_open_H1($param, 'h2'); |
|
| 3957 | - } |
|
| 3958 | - |
|
| 3959 | - /** |
|
| 3960 | - * tag : H3 |
|
| 3961 | - * mode : OPEN |
|
| 3962 | - * |
|
| 3963 | - * @param array $param |
|
| 3964 | - * @return boolean |
|
| 3965 | - */ |
|
| 3966 | - protected function _tag_open_H3($param) |
|
| 3967 | - { |
|
| 3968 | - return $this->_tag_open_H1($param, 'h3'); |
|
| 3969 | - } |
|
| 3970 | - |
|
| 3971 | - /** |
|
| 3972 | - * tag : H4 |
|
| 3973 | - * mode : OPEN |
|
| 3974 | - * |
|
| 3975 | - * @param array $param |
|
| 3976 | - * @return boolean |
|
| 3977 | - */ |
|
| 3978 | - protected function _tag_open_H4($param) |
|
| 3979 | - { |
|
| 3980 | - return $this->_tag_open_H1($param, 'h4'); |
|
| 3981 | - } |
|
| 3982 | - |
|
| 3983 | - /** |
|
| 3984 | - * tag : H5 |
|
| 3985 | - * mode : OPEN |
|
| 3986 | - * |
|
| 3987 | - * @param array $param |
|
| 3988 | - * @return boolean |
|
| 3989 | - */ |
|
| 3990 | - protected function _tag_open_H5($param) |
|
| 3991 | - { |
|
| 3992 | - return $this->_tag_open_H1($param, 'h5'); |
|
| 3993 | - } |
|
| 3994 | - |
|
| 3995 | - /** |
|
| 3996 | - * tag : H6 |
|
| 3997 | - * mode : OPEN |
|
| 3998 | - * |
|
| 3999 | - * @param array $param |
|
| 4000 | - * @return boolean |
|
| 4001 | - */ |
|
| 4002 | - protected function _tag_open_H6($param) |
|
| 4003 | - { |
|
| 4004 | - return $this->_tag_open_H1($param, 'h6'); |
|
| 4005 | - } |
|
| 4006 | - |
|
| 4007 | - /** |
|
| 4008 | - * tag : H1 |
|
| 4009 | - * mode : CLOSE |
|
| 4010 | - * |
|
| 4011 | - * @param array $param |
|
| 4012 | - * @return boolean |
|
| 4013 | - */ |
|
| 4014 | - protected function _tag_close_H1($param) |
|
| 4015 | - { |
|
| 4016 | - if ($this->_isForOneLine) { |
|
| 4017 | - return false; |
|
| 4018 | - } |
|
| 4019 | - |
|
| 4020 | - $this->_maxH += $this->parsingCss->value['margin']['b']; |
|
| 4021 | - $h = max($this->_maxH, $this->parsingCss->getLineHeight()); |
|
| 4022 | - |
|
| 4023 | - $this->parsingCss->load(); |
|
| 4024 | - $this->parsingCss->fontSet(); |
|
| 4025 | - |
|
| 4026 | - $this->_makeBreakLine($h); |
|
| 4027 | - $this->_maxH = 0; |
|
| 4028 | - |
|
| 4029 | - $this->_maxY = max($this->_maxY, $this->pdf->getY()); |
|
| 4030 | - |
|
| 4031 | - return true; |
|
| 4032 | - } |
|
| 4033 | - |
|
| 4034 | - /** |
|
| 4035 | - * tag : H2 |
|
| 4036 | - * mode : CLOSE |
|
| 4037 | - * |
|
| 4038 | - * @param array $param |
|
| 4039 | - * @return boolean |
|
| 4040 | - */ |
|
| 4041 | - protected function _tag_close_H2($param) |
|
| 4042 | - { |
|
| 4043 | - return $this->_tag_close_H1($param); |
|
| 4044 | - } |
|
| 4045 | - |
|
| 4046 | - /** |
|
| 4047 | - * tag : H3 |
|
| 4048 | - * mode : CLOSE |
|
| 4049 | - * |
|
| 4050 | - * @param array $param |
|
| 4051 | - * @return boolean |
|
| 4052 | - */ |
|
| 4053 | - protected function _tag_close_H3($param) |
|
| 4054 | - { |
|
| 4055 | - return $this->_tag_close_H1($param); |
|
| 4056 | - } |
|
| 4057 | - |
|
| 4058 | - /** |
|
| 4059 | - * tag : H4 |
|
| 4060 | - * mode : CLOSE |
|
| 4061 | - * |
|
| 4062 | - * @param array $param |
|
| 4063 | - * @return boolean |
|
| 4064 | - */ |
|
| 4065 | - protected function _tag_close_H4($param) |
|
| 4066 | - { |
|
| 4067 | - return $this->_tag_close_H1($param); |
|
| 4068 | - } |
|
| 4069 | - |
|
| 4070 | - /** |
|
| 4071 | - * tag : H5 |
|
| 4072 | - * mode : CLOSE |
|
| 4073 | - * |
|
| 4074 | - * @param array $param |
|
| 4075 | - * @return boolean |
|
| 4076 | - */ |
|
| 4077 | - protected function _tag_close_H5($param) |
|
| 4078 | - { |
|
| 4079 | - return $this->_tag_close_H1($param); |
|
| 4080 | - } |
|
| 4081 | - |
|
| 4082 | - /** |
|
| 4083 | - * tag : H6 |
|
| 4084 | - * mode : CLOSE |
|
| 4085 | - * |
|
| 4086 | - * @param array $param |
|
| 4087 | - * @return boolean |
|
| 4088 | - */ |
|
| 4089 | - protected function _tag_close_H6($param) |
|
| 4090 | - { |
|
| 4091 | - return $this->_tag_close_H1($param); |
|
| 4092 | - } |
|
| 4093 | - |
|
| 4094 | - /** |
|
| 4095 | - * tag : SPAN |
|
| 4096 | - * mode : OPEN |
|
| 4097 | - * |
|
| 4098 | - * @param array $param |
|
| 4099 | - * @param string $other |
|
| 4100 | - * @return boolean |
|
| 4101 | - */ |
|
| 4102 | - protected function _tag_open_SPAN($param, $other = 'span') |
|
| 4103 | - { |
|
| 4104 | - $this->parsingCss->save(); |
|
| 4105 | - $this->parsingCss->analyse($other, $param); |
|
| 4106 | - $this->parsingCss->setPosition(); |
|
| 4107 | - $this->parsingCss->fontSet(); |
|
| 4108 | - |
|
| 4109 | - return true; |
|
| 4110 | - } |
|
| 4111 | - |
|
| 4112 | - /** |
|
| 4113 | - * tag : FONT |
|
| 4114 | - * mode : OPEN |
|
| 4115 | - * |
|
| 4116 | - * @param array $param |
|
| 4117 | - * @return boolean |
|
| 4118 | - */ |
|
| 4119 | - protected function _tag_open_FONT($param) |
|
| 4120 | - { |
|
| 4121 | - return $this->_tag_open_SPAN($param, 'font'); |
|
| 4122 | - } |
|
| 4123 | - |
|
| 4124 | - /** |
|
| 4125 | - * tag : LABEL |
|
| 4126 | - * mode : OPEN |
|
| 4127 | - * |
|
| 4128 | - * @param array $param |
|
| 4129 | - * @return boolean |
|
| 4130 | - */ |
|
| 4131 | - protected function _tag_open_LABEL($param) |
|
| 4132 | - { |
|
| 4133 | - return $this->_tag_open_SPAN($param, 'label'); |
|
| 4134 | - } |
|
| 4135 | - |
|
| 4136 | - /** |
|
| 4137 | - * tag : SPAN |
|
| 4138 | - * mode : CLOSE |
|
| 4139 | - * |
|
| 4140 | - * @param array $param |
|
| 4141 | - * @return boolean |
|
| 4142 | - */ |
|
| 4143 | - protected function _tag_close_SPAN($param) |
|
| 4144 | - { |
|
| 4145 | - $this->parsingCss->restorePosition(); |
|
| 4146 | - $this->parsingCss->load(); |
|
| 4147 | - $this->parsingCss->fontSet(); |
|
| 4148 | - |
|
| 4149 | - return true; |
|
| 4150 | - } |
|
| 4151 | - |
|
| 4152 | - /** |
|
| 4153 | - * tag : FONT |
|
| 4154 | - * mode : CLOSE |
|
| 4155 | - * |
|
| 4156 | - * @param array $param |
|
| 4157 | - * @return boolean |
|
| 4158 | - */ |
|
| 4159 | - protected function _tag_close_FONT($param) |
|
| 4160 | - { |
|
| 4161 | - return $this->_tag_close_SPAN($param); |
|
| 4162 | - } |
|
| 4163 | - |
|
| 4164 | - /** |
|
| 4165 | - * tag : LABEL |
|
| 4166 | - * mode : CLOSE |
|
| 4167 | - * |
|
| 4168 | - * @param array $param |
|
| 4169 | - * @return boolean |
|
| 4170 | - */ |
|
| 4171 | - protected function _tag_close_LABEL($param) |
|
| 4172 | - { |
|
| 4173 | - return $this->_tag_close_SPAN($param); |
|
| 4174 | - } |
|
| 4175 | - |
|
| 4176 | - /** |
|
| 4177 | - * tag : P |
|
| 4178 | - * mode : OPEN |
|
| 4179 | - * |
|
| 4180 | - * @param array $param |
|
| 4181 | - * @return boolean |
|
| 4182 | - */ |
|
| 4183 | - protected function _tag_open_P($param) |
|
| 4184 | - { |
|
| 4185 | - if ($this->_isForOneLine) return false; |
|
| 4186 | - |
|
| 4187 | - if ( ! in_array($this->_previousCall, array('_tag_close_P', '_tag_close_UL'))) { |
|
| 4188 | - if ($this->_maxH) $this->_tag_open_BR(array()); |
|
| 4189 | - } |
|
| 4190 | - |
|
| 4191 | - $this->parsingCss->save(); |
|
| 4192 | - $this->parsingCss->analyse('p', $param); |
|
| 4193 | - $this->parsingCss->setPosition(); |
|
| 4194 | - $this->parsingCss->fontSet(); |
|
| 4195 | - |
|
| 4196 | - // cancel the effects of the setPosition |
|
| 4197 | - $this->pdf->setXY($this->pdf->getX() - $this->parsingCss->value['margin']['l'], $this->pdf->getY() - $this->parsingCss->value['margin']['t']); |
|
| 4198 | - |
|
| 4199 | - list($mL, $mR) = $this->_getMargins($this->pdf->getY()); |
|
| 4200 | - $mR = $this->pdf->getW() - $mR; |
|
| 4201 | - $mL += $this->parsingCss->value['margin']['l'] + $this->parsingCss->value['padding']['l']; |
|
| 4202 | - $mR += $this->parsingCss->value['margin']['r'] + $this->parsingCss->value['padding']['r']; |
|
| 4203 | - $this->_saveMargin($mL, 0, $mR); |
|
| 4204 | - |
|
| 4205 | - if ($this->parsingCss->value['text-indent'] > 0) { |
|
| 4206 | - $y = $this->pdf->getY() + $this->parsingCss->value['margin']['t'] + $this->parsingCss->value['padding']['t']; |
|
| 4207 | - $this->_pageMarges[floor($y * 100)] = array($mL + $this->parsingCss->value['text-indent'], $this->pdf->getW() - $mR); |
|
| 4208 | - $y += $this->parsingCss->getLineHeight() * 0.1; |
|
| 4209 | - $this->_pageMarges[floor($y * 100)] = array($mL, $this->pdf->getW() - $mR); |
|
| 4210 | - } |
|
| 4211 | - $this->_makeBreakLine($this->parsingCss->value['margin']['t'] + $this->parsingCss->value['padding']['t']); |
|
| 4212 | - $this->_isInParagraph = array($mL, $mR); |
|
| 4213 | - return true; |
|
| 4214 | - } |
|
| 4215 | - |
|
| 4216 | - /** |
|
| 4217 | - * tag : P |
|
| 4218 | - * mode : CLOSE |
|
| 4219 | - * |
|
| 4220 | - * @param array $param |
|
| 4221 | - * @return boolean |
|
| 4222 | - */ |
|
| 4223 | - protected function _tag_close_P($param) |
|
| 4224 | - { |
|
| 4225 | - if ($this->_isForOneLine) { |
|
| 4226 | - return false; |
|
| 4227 | - } |
|
| 4228 | - |
|
| 4229 | - if ($this->_maxH) { |
|
| 4230 | - $this->_tag_open_BR(array()); |
|
| 4231 | - } |
|
| 4232 | - $this->_isInParagraph = false; |
|
| 4233 | - $this->_loadMargin(); |
|
| 4234 | - $h = $this->parsingCss->value['margin']['b'] + $this->parsingCss->value['padding']['b']; |
|
| 4235 | - |
|
| 4236 | - $this->parsingCss->load(); |
|
| 4237 | - $this->parsingCss->fontSet(); |
|
| 4238 | - $this->_makeBreakLine($h); |
|
| 4239 | - |
|
| 4240 | - return true; |
|
| 4241 | - } |
|
| 4242 | - |
|
| 4243 | - /** |
|
| 4244 | - * tag : PRE |
|
| 4245 | - * mode : OPEN |
|
| 4246 | - * |
|
| 4247 | - * @param array $param |
|
| 4248 | - * @param string $other |
|
| 4249 | - * @return boolean |
|
| 4250 | - */ |
|
| 4251 | - protected function _tag_open_PRE($param, $other = 'pre') |
|
| 4252 | - { |
|
| 4253 | - if ($other == 'pre' && $this->_maxH) $this->_tag_open_BR(array()); |
|
| 4254 | - |
|
| 4255 | - $this->parsingCss->save(); |
|
| 4256 | - $this->parsingCss->value['font-family'] = 'courier'; |
|
| 4257 | - $this->parsingCss->analyse($other, $param); |
|
| 4258 | - $this->parsingCss->setPosition(); |
|
| 4259 | - $this->parsingCss->fontSet(); |
|
| 4260 | - |
|
| 4261 | - if ($other == 'pre') return $this->_tag_open_DIV($param, $other); |
|
| 4262 | - |
|
| 4263 | - return true; |
|
| 4264 | - } |
|
| 4265 | - |
|
| 4266 | - /** |
|
| 4267 | - * tag : CODE |
|
| 4268 | - * mode : OPEN |
|
| 4269 | - * |
|
| 4270 | - * @param array $param |
|
| 4271 | - * @return boolean |
|
| 4272 | - */ |
|
| 4273 | - protected function _tag_open_CODE($param) |
|
| 4274 | - { |
|
| 4275 | - return $this->_tag_open_PRE($param, 'code'); |
|
| 4276 | - } |
|
| 4277 | - |
|
| 4278 | - /** |
|
| 4279 | - * tag : PRE |
|
| 4280 | - * mode : CLOSE |
|
| 4281 | - * |
|
| 4282 | - * @param array $param |
|
| 4283 | - * @param string $other |
|
| 4284 | - * @return boolean |
|
| 4285 | - */ |
|
| 4286 | - protected function _tag_close_PRE($param, $other = 'pre') |
|
| 4287 | - { |
|
| 4288 | - if ($other == 'pre') { |
|
| 4289 | - if ($this->_isForOneLine) return false; |
|
| 4290 | - |
|
| 4291 | - $this->_tag_close_DIV($param, $other); |
|
| 4292 | - $this->_tag_open_BR(array()); |
|
| 4293 | - } |
|
| 4294 | - $this->parsingCss->load(); |
|
| 4295 | - $this->parsingCss->fontSet(); |
|
| 4296 | - |
|
| 4297 | - return true; |
|
| 4298 | - } |
|
| 4299 | - |
|
| 4300 | - /** |
|
| 4301 | - * tag : CODE |
|
| 4302 | - * mode : CLOSE |
|
| 4303 | - * |
|
| 4304 | - * @param array $param |
|
| 4305 | - * @return boolean |
|
| 4306 | - */ |
|
| 4307 | - protected function _tag_close_CODE($param) |
|
| 4308 | - { |
|
| 4309 | - return $this->_tag_close_PRE($param, 'code'); |
|
| 4310 | - } |
|
| 4311 | - |
|
| 4312 | - /** |
|
| 4313 | - * tag : BIG |
|
| 4314 | - * mode : OPEN |
|
| 4315 | - * |
|
| 4316 | - * @param array $param |
|
| 4317 | - * @return boolean |
|
| 4318 | - */ |
|
| 4319 | - protected function _tag_open_BIG($param) |
|
| 4320 | - { |
|
| 4321 | - $this->parsingCss->save(); |
|
| 4322 | - $this->parsingCss->value['mini-decal'] -= $this->parsingCss->value['mini-size'] * 0.12; |
|
| 4323 | - $this->parsingCss->value['mini-size'] *= 1.2; |
|
| 4324 | - $this->parsingCss->analyse('big', $param); |
|
| 4325 | - $this->parsingCss->setPosition(); |
|
| 4326 | - $this->parsingCss->fontSet(); |
|
| 4327 | - return true; |
|
| 4328 | - } |
|
| 4329 | - |
|
| 4330 | - /** |
|
| 4331 | - * tag : BIG |
|
| 4332 | - * mode : CLOSE |
|
| 4333 | - * |
|
| 4334 | - * @param array $param |
|
| 4335 | - * @return boolean |
|
| 4336 | - */ |
|
| 4337 | - protected function _tag_close_BIG($param) |
|
| 4338 | - { |
|
| 4339 | - $this->parsingCss->load(); |
|
| 4340 | - $this->parsingCss->fontSet(); |
|
| 4341 | - |
|
| 4342 | - return true; |
|
| 4343 | - } |
|
| 4344 | - |
|
| 4345 | - /** |
|
| 4346 | - * tag : SMALL |
|
| 4347 | - * mode : OPEN |
|
| 4348 | - * |
|
| 4349 | - * @param array $param |
|
| 4350 | - * @return boolean |
|
| 4351 | - */ |
|
| 4352 | - protected function _tag_open_SMALL($param) |
|
| 4353 | - { |
|
| 4354 | - $this->parsingCss->save(); |
|
| 4355 | - $this->parsingCss->value['mini-decal'] += $this->parsingCss->value['mini-size'] * 0.05; |
|
| 4356 | - $this->parsingCss->value['mini-size'] *= 0.82; |
|
| 4357 | - $this->parsingCss->analyse('small', $param); |
|
| 4358 | - $this->parsingCss->setPosition(); |
|
| 4359 | - $this->parsingCss->fontSet(); |
|
| 4360 | - return true; |
|
| 4361 | - } |
|
| 4362 | - |
|
| 4363 | - /** |
|
| 4364 | - * tag : SMALL |
|
| 4365 | - * mode : CLOSE |
|
| 4366 | - * |
|
| 4367 | - * @param array $param |
|
| 4368 | - * @return boolean |
|
| 4369 | - */ |
|
| 4370 | - protected function _tag_close_SMALL($param) |
|
| 4371 | - { |
|
| 4372 | - $this->parsingCss->load(); |
|
| 4373 | - $this->parsingCss->fontSet(); |
|
| 4374 | - |
|
| 4375 | - return true; |
|
| 4376 | - } |
|
| 4377 | - |
|
| 4378 | - /** |
|
| 4379 | - * tag : SUP |
|
| 4380 | - * mode : OPEN |
|
| 4381 | - * |
|
| 4382 | - * @param array $param |
|
| 4383 | - * @return boolean |
|
| 4384 | - */ |
|
| 4385 | - protected function _tag_open_SUP($param) |
|
| 4386 | - { |
|
| 4387 | - $this->parsingCss->save(); |
|
| 4388 | - $this->parsingCss->value['mini-decal'] -= $this->parsingCss->value['mini-size'] * 0.15; |
|
| 4389 | - $this->parsingCss->value['mini-size'] *= 0.75; |
|
| 4390 | - $this->parsingCss->analyse('sup', $param); |
|
| 4391 | - $this->parsingCss->setPosition(); |
|
| 4392 | - $this->parsingCss->fontSet(); |
|
| 4393 | - |
|
| 4394 | - return true; |
|
| 4395 | - } |
|
| 4396 | - |
|
| 4397 | - /** |
|
| 4398 | - * tag : SUP |
|
| 4399 | - * mode : CLOSE |
|
| 4400 | - * |
|
| 4401 | - * @param array $param |
|
| 4402 | - * @return boolean |
|
| 4403 | - */ |
|
| 4404 | - protected function _tag_close_SUP($param) |
|
| 4405 | - { |
|
| 4406 | - $this->parsingCss->load(); |
|
| 4407 | - $this->parsingCss->fontSet(); |
|
| 4408 | - |
|
| 4409 | - return true; |
|
| 4410 | - } |
|
| 4411 | - |
|
| 4412 | - /** |
|
| 4413 | - * tag : SUB |
|
| 4414 | - * mode : OPEN |
|
| 4415 | - * |
|
| 4416 | - * @param array $param |
|
| 4417 | - * @return boolean |
|
| 4418 | - */ |
|
| 4419 | - protected function _tag_open_SUB($param) |
|
| 4420 | - { |
|
| 4421 | - $this->parsingCss->save(); |
|
| 4422 | - $this->parsingCss->value['mini-decal'] += $this->parsingCss->value['mini-size'] * 0.15; |
|
| 4423 | - $this->parsingCss->value['mini-size'] *= 0.75; |
|
| 4424 | - $this->parsingCss->analyse('sub', $param); |
|
| 4425 | - $this->parsingCss->setPosition(); |
|
| 4426 | - $this->parsingCss->fontSet(); |
|
| 4427 | - return true; |
|
| 4428 | - } |
|
| 4429 | - |
|
| 4430 | - /** |
|
| 4431 | - * tag : SUB |
|
| 4432 | - * mode : CLOSE |
|
| 4433 | - * |
|
| 4434 | - * @param array $param |
|
| 4435 | - * @return boolean |
|
| 4436 | - */ |
|
| 4437 | - protected function _tag_close_SUB($param) |
|
| 4438 | - { |
|
| 4439 | - $this->parsingCss->load(); |
|
| 4440 | - $this->parsingCss->fontSet(); |
|
| 4441 | - |
|
| 4442 | - return true; |
|
| 4443 | - } |
|
| 4444 | - |
|
| 4445 | - /** |
|
| 4446 | - * tag : UL |
|
| 4447 | - * mode : OPEN |
|
| 4448 | - * |
|
| 4449 | - * @param array $param |
|
| 4450 | - * @param string $other |
|
| 4451 | - * @return boolean |
|
| 4452 | - */ |
|
| 4453 | - protected function _tag_open_UL($param, $other = 'ul') |
|
| 4454 | - { |
|
| 4455 | - if ($this->_isForOneLine) return false; |
|
| 4456 | - |
|
| 4457 | - if ( ! in_array($this->_previousCall, array('_tag_close_P', '_tag_close_UL'))) { |
|
| 4458 | - if ($this->_maxH) $this->_tag_open_BR(array()); |
|
| 4459 | - if ( ! count($this->_defList)) $this->_tag_open_BR(array()); |
|
| 4460 | - } |
|
| 4461 | - |
|
| 4462 | - if ( ! isset($param['style']['width'])) $param['allwidth'] = true; |
|
| 4463 | - $param['cellspacing'] = 0; |
|
| 4464 | - |
|
| 4465 | - // a list is like a table |
|
| 4466 | - $this->_tag_open_TABLE($param, $other); |
|
| 4467 | - |
|
| 4468 | - // add a level of list |
|
| 4469 | - $this->_listeAddLevel($other, $this->parsingCss->value['list-style-type'], $this->parsingCss->value['list-style-image']); |
|
| 4470 | - |
|
| 4471 | - return true; |
|
| 4472 | - } |
|
| 4473 | - |
|
| 4474 | - /** |
|
| 4475 | - * tag : OL |
|
| 4476 | - * mode : OPEN |
|
| 4477 | - * |
|
| 4478 | - * @param array $param |
|
| 4479 | - * @return boolean |
|
| 4480 | - */ |
|
| 4481 | - protected function _tag_open_OL($param) |
|
| 4482 | - { |
|
| 4483 | - return $this->_tag_open_UL($param, 'ol'); |
|
| 4484 | - } |
|
| 4485 | - |
|
| 4486 | - /** |
|
| 4487 | - * tag : UL |
|
| 4488 | - * mode : CLOSE |
|
| 4489 | - * |
|
| 4490 | - * @param array $param |
|
| 4491 | - * @return boolean |
|
| 4492 | - */ |
|
| 4493 | - protected function _tag_close_UL($param) |
|
| 4494 | - { |
|
| 4495 | - if ($this->_isForOneLine) return false; |
|
| 4496 | - |
|
| 4497 | - $this->_tag_close_TABLE($param); |
|
| 4498 | - |
|
| 4499 | - $this->_listeDelLevel(); |
|
| 4500 | - |
|
| 4501 | - if ( ! $this->_subPart) { |
|
| 4502 | - if ( ! count($this->_defList)) $this->_tag_open_BR(array()); |
|
| 4503 | - } |
|
| 4504 | - |
|
| 4505 | - return true; |
|
| 4506 | - } |
|
| 4507 | - |
|
| 4508 | - /** |
|
| 4509 | - * tag : OL |
|
| 4510 | - * mode : CLOSE |
|
| 4511 | - * |
|
| 4512 | - * @param array $param |
|
| 4513 | - * @return boolean |
|
| 4514 | - */ |
|
| 4515 | - protected function _tag_close_OL($param) |
|
| 4516 | - { |
|
| 4517 | - return $this->_tag_close_UL($param); |
|
| 4518 | - } |
|
| 4519 | - |
|
| 4520 | - /** |
|
| 4521 | - * tag : LI |
|
| 4522 | - * mode : OPEN |
|
| 4523 | - * |
|
| 4524 | - * @param array $param |
|
| 4525 | - * @return boolean |
|
| 4526 | - */ |
|
| 4527 | - protected function _tag_open_LI($param) |
|
| 4528 | - { |
|
| 4529 | - if ($this->_isForOneLine) return false; |
|
| 4530 | - |
|
| 4531 | - $this->_listeAddLi(); |
|
| 4532 | - |
|
| 4533 | - if ( ! isset($param['style']['width'])) $param['style']['width'] = '100%'; |
|
| 4534 | - |
|
| 4535 | - $paramPUCE = $param; |
|
| 4536 | - |
|
| 4537 | - $inf = $this->_listeGetLi(); |
|
| 4538 | - if ($inf[0]) { |
|
| 4539 | - $paramPUCE['style']['font-family'] = $inf[0]; |
|
| 4540 | - $paramPUCE['style']['text-align'] = 'li_right'; |
|
| 4541 | - $paramPUCE['style']['vertical-align'] = 'top'; |
|
| 4542 | - $paramPUCE['style']['width'] = $this->_listeGetWidth(); |
|
| 4543 | - $paramPUCE['style']['padding-right'] = $this->_listeGetPadding(); |
|
| 4544 | - $paramPUCE['txt'] = $inf[2]; |
|
| 4545 | - } else { |
|
| 4546 | - $paramPUCE['style']['text-align'] = 'li_right'; |
|
| 4547 | - $paramPUCE['style']['vertical-align'] = 'top'; |
|
| 4548 | - $paramPUCE['style']['width'] = $this->_listeGetWidth(); |
|
| 4549 | - $paramPUCE['style']['padding-right'] = $this->_listeGetPadding(); |
|
| 4550 | - $paramPUCE['src'] = $inf[2]; |
|
| 4551 | - $paramPUCE['sub_li'] = true; |
|
| 4552 | - } |
|
| 4553 | - |
|
| 4554 | - $this->_tag_open_TR($param, 'li'); |
|
| 4555 | - |
|
| 4556 | - $this->parsingCss->save(); |
|
| 4557 | - |
|
| 4558 | - // if small LI |
|
| 4559 | - if ($inf[1]) { |
|
| 4560 | - $this->parsingCss->value['mini-decal'] += $this->parsingCss->value['mini-size'] * 0.045; |
|
| 4561 | - $this->parsingCss->value['mini-size'] *= 0.75; |
|
| 4562 | - } |
|
| 4563 | - |
|
| 4564 | - // if we are in a sub html => prepare. Else : display |
|
| 4565 | - if ($this->_subPart) { |
|
| 4566 | - // TD for the puce |
|
| 4567 | - $tmpPos = $this->_tempPos; |
|
| 4568 | - $tmpLst1 = $this->parsingHtml->code[$tmpPos + 1]; |
|
| 4569 | - $tmpLst2 = $this->parsingHtml->code[$tmpPos + 2]; |
|
| 4570 | - $this->parsingHtml->code[$tmpPos + 1] = array(); |
|
| 4571 | - $this->parsingHtml->code[$tmpPos + 1]['name'] = (isset($paramPUCE['src'])) ? 'img' : 'write'; |
|
| 4572 | - $this->parsingHtml->code[$tmpPos + 1]['param'] = $paramPUCE; unset($this->parsingHtml->code[$tmpPos + 1]['param']['style']['width']); |
|
| 4573 | - $this->parsingHtml->code[$tmpPos + 1]['close'] = 0; |
|
| 4574 | - $this->parsingHtml->code[$tmpPos + 2] = array(); |
|
| 4575 | - $this->parsingHtml->code[$tmpPos + 2]['name'] = 'li'; |
|
| 4576 | - $this->parsingHtml->code[$tmpPos + 2]['param'] = $paramPUCE; |
|
| 4577 | - $this->parsingHtml->code[$tmpPos + 2]['close'] = 1; |
|
| 4578 | - $this->_tag_open_TD($paramPUCE, 'li_sub'); |
|
| 4579 | - $this->_tag_close_TD($param); |
|
| 4580 | - $this->_tempPos = $tmpPos; |
|
| 4581 | - $this->parsingHtml->code[$tmpPos + 1] = $tmpLst1; |
|
| 4582 | - $this->parsingHtml->code[$tmpPos + 2] = $tmpLst2; |
|
| 4583 | - } else { |
|
| 4584 | - // TD for the puce |
|
| 4585 | - $this->_tag_open_TD($paramPUCE, 'li_sub'); |
|
| 4586 | - unset($paramPUCE['style']['width']); |
|
| 4587 | - if (isset($paramPUCE['src'])) { |
|
| 4588 | - $this->_tag_open_IMG($paramPUCE); |
|
| 4589 | - } else { |
|
| 4590 | - $this->_tag_open_WRITE($paramPUCE); |
|
| 4591 | - } |
|
| 4592 | - $this->_tag_close_TD($paramPUCE); |
|
| 4593 | - } |
|
| 4594 | - $this->parsingCss->load(); |
|
| 4595 | - |
|
| 4596 | - |
|
| 4597 | - // TD for the content |
|
| 4598 | - $this->_tag_open_TD($param, 'li'); |
|
| 4599 | - |
|
| 4600 | - return true; |
|
| 4601 | - } |
|
| 4602 | - |
|
| 4603 | - /** |
|
| 4604 | - * tag : LI |
|
| 4605 | - * mode : CLOSE |
|
| 4606 | - * |
|
| 4607 | - * @param array $param |
|
| 4608 | - * @return boolean |
|
| 4609 | - */ |
|
| 4610 | - protected function _tag_close_LI($param) |
|
| 4611 | - { |
|
| 4612 | - if ($this->_isForOneLine) { |
|
| 4613 | - return false; |
|
| 4614 | - } |
|
| 4615 | - |
|
| 4616 | - $this->_tag_close_TD($param); |
|
| 4617 | - |
|
| 4618 | - $this->_tag_close_TR($param); |
|
| 4619 | - |
|
| 4620 | - return true; |
|
| 4621 | - } |
|
| 4622 | - |
|
| 4623 | - /** |
|
| 4624 | - * tag : TBODY |
|
| 4625 | - * mode : OPEN |
|
| 4626 | - * |
|
| 4627 | - * @param array $param |
|
| 4628 | - * @return boolean |
|
| 4629 | - */ |
|
| 4630 | - protected function _tag_open_TBODY($param) |
|
| 4631 | - { |
|
| 4632 | - if ($this->_isForOneLine) { |
|
| 4633 | - return false; |
|
| 4634 | - } |
|
| 4635 | - |
|
| 4636 | - $this->parsingCss->save(); |
|
| 4637 | - $this->parsingCss->analyse('tbody', $param); |
|
| 4638 | - $this->parsingCss->setPosition(); |
|
| 4639 | - $this->parsingCss->fontSet(); |
|
| 4640 | - |
|
| 4641 | - return true; |
|
| 4642 | - } |
|
| 4643 | - |
|
| 4644 | - /** |
|
| 4645 | - * tag : TBODY |
|
| 4646 | - * mode : CLOSE |
|
| 4647 | - * |
|
| 4648 | - * @param array $param |
|
| 4649 | - * @return boolean |
|
| 4650 | - */ |
|
| 4651 | - protected function _tag_close_TBODY($param) |
|
| 4652 | - { |
|
| 4653 | - if ($this->_isForOneLine) { |
|
| 4654 | - return false; |
|
| 4655 | - } |
|
| 4656 | - |
|
| 4657 | - $this->parsingCss->load(); |
|
| 4658 | - $this->parsingCss->fontSet(); |
|
| 4659 | - |
|
| 4660 | - return true; |
|
| 4661 | - } |
|
| 4662 | - |
|
| 4663 | - /** |
|
| 4664 | - * tag : THEAD |
|
| 4665 | - * mode : OPEN |
|
| 4666 | - * |
|
| 4667 | - * @param array $param |
|
| 4668 | - * @return boolean |
|
| 4669 | - */ |
|
| 4670 | - protected function _tag_open_THEAD($param) |
|
| 4671 | - { |
|
| 4672 | - if ($this->_isForOneLine) { |
|
| 4673 | - return false; |
|
| 4674 | - } |
|
| 4675 | - |
|
| 4676 | - $this->parsingCss->save(); |
|
| 4677 | - $this->parsingCss->analyse('thead', $param); |
|
| 4678 | - $this->parsingCss->setPosition(); |
|
| 4679 | - $this->parsingCss->fontSet(); |
|
| 4680 | - |
|
| 4681 | - // if we are in a sub part, save the number of the first TR in the thead |
|
| 4682 | - if ($this->_subPart) { |
|
| 4683 | - HTML2PDF::$_tables[$param['num']]['thead']['tr'][0] = HTML2PDF::$_tables[$param['num']]['tr_curr']; |
|
| 4684 | - HTML2PDF::$_tables[$param['num']]['thead']['code'] = array(); |
|
| 4685 | - for ($pos = $this->_tempPos; $pos < count($this->parsingHtml->code); $pos++) { |
|
| 4686 | - $action = $this->parsingHtml->code[$pos]; |
|
| 4687 | - if (strtolower($action['name']) == 'thead') $action['name'] = 'thead_sub'; |
|
| 4688 | - HTML2PDF::$_tables[$param['num']]['thead']['code'][] = $action; |
|
| 4689 | - if (strtolower($action['name']) == 'thead_sub' && $action['close']) break; |
|
| 4690 | - } |
|
| 4691 | - } else { |
|
| 4692 | - $level = $this->parsingHtml->getLevel($this->_parsePos); |
|
| 4693 | - $this->_parsePos += count($level); |
|
| 4694 | - HTML2PDF::$_tables[$param['num']]['tr_curr'] += count(HTML2PDF::$_tables[$param['num']]['thead']['tr']); |
|
| 4695 | - } |
|
| 4696 | - |
|
| 4697 | - return true; |
|
| 4698 | - } |
|
| 4699 | - |
|
| 4700 | - /** |
|
| 4701 | - * tag : THEAD |
|
| 4702 | - * mode : CLOSE |
|
| 4703 | - * |
|
| 4704 | - * @param array $param |
|
| 4705 | - * @return boolean |
|
| 4706 | - */ |
|
| 4707 | - protected function _tag_close_THEAD($param) |
|
| 4708 | - { |
|
| 4709 | - if ($this->_isForOneLine) { |
|
| 4710 | - return false; |
|
| 4711 | - } |
|
| 4712 | - |
|
| 4713 | - $this->parsingCss->load(); |
|
| 4714 | - $this->parsingCss->fontSet(); |
|
| 4715 | - |
|
| 4716 | - // if we are in a sub HTM, construct the list of the TR in the thead |
|
| 4717 | - if ($this->_subPart) { |
|
| 4718 | - $min = HTML2PDF::$_tables[$param['num']]['thead']['tr'][0]; |
|
| 4719 | - $max = HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1; |
|
| 4720 | - HTML2PDF::$_tables[$param['num']]['thead']['tr'] = range($min, $max); |
|
| 4721 | - } |
|
| 4722 | - |
|
| 4723 | - return true; |
|
| 4724 | - } |
|
| 4725 | - |
|
| 4726 | - /** |
|
| 4727 | - * tag : TFOOT |
|
| 4728 | - * mode : OPEN |
|
| 4729 | - * |
|
| 4730 | - * @param array $param |
|
| 4731 | - * @return boolean |
|
| 4732 | - */ |
|
| 4733 | - protected function _tag_open_TFOOT($param) |
|
| 4734 | - { |
|
| 4735 | - if ($this->_isForOneLine) { |
|
| 4736 | - return false; |
|
| 4737 | - } |
|
| 4738 | - |
|
| 4739 | - $this->parsingCss->save(); |
|
| 4740 | - $this->parsingCss->analyse('tfoot', $param); |
|
| 4741 | - $this->parsingCss->setPosition(); |
|
| 4742 | - $this->parsingCss->fontSet(); |
|
| 4743 | - |
|
| 4744 | - // if we are in a sub part, save the number of the first TR in the tfoot |
|
| 4745 | - if ($this->_subPart) { |
|
| 4746 | - HTML2PDF::$_tables[$param['num']]['tfoot']['tr'][0] = HTML2PDF::$_tables[$param['num']]['tr_curr']; |
|
| 4747 | - HTML2PDF::$_tables[$param['num']]['tfoot']['code'] = array(); |
|
| 4748 | - for ($pos = $this->_tempPos; $pos < count($this->parsingHtml->code); $pos++) { |
|
| 4749 | - $action = $this->parsingHtml->code[$pos]; |
|
| 4750 | - if (strtolower($action['name']) == 'tfoot') $action['name'] = 'tfoot_sub'; |
|
| 4751 | - HTML2PDF::$_tables[$param['num']]['tfoot']['code'][] = $action; |
|
| 4752 | - if (strtolower($action['name']) == 'tfoot_sub' && $action['close']) break; |
|
| 4753 | - } |
|
| 4754 | - } else { |
|
| 4755 | - $level = $this->parsingHtml->getLevel($this->_parsePos); |
|
| 4756 | - $this->_parsePos += count($level); |
|
| 4757 | - HTML2PDF::$_tables[$param['num']]['tr_curr'] += count(HTML2PDF::$_tables[$param['num']]['tfoot']['tr']); |
|
| 4758 | - } |
|
| 4759 | - |
|
| 4760 | - return true; |
|
| 4761 | - } |
|
| 4762 | - |
|
| 4763 | - /** |
|
| 4764 | - * tag : TFOOT |
|
| 4765 | - * mode : CLOSE |
|
| 4766 | - * |
|
| 4767 | - * @param array $param |
|
| 4768 | - * @return boolean |
|
| 4769 | - */ |
|
| 4770 | - protected function _tag_close_TFOOT($param) |
|
| 4771 | - { |
|
| 4772 | - if ($this->_isForOneLine) { |
|
| 4773 | - return false; |
|
| 4774 | - } |
|
| 4775 | - |
|
| 4776 | - $this->parsingCss->load(); |
|
| 4777 | - $this->parsingCss->fontSet(); |
|
| 4778 | - |
|
| 4779 | - // if we are in a sub HTM, construct the list of the TR in the tfoot |
|
| 4780 | - if ($this->_subPart) { |
|
| 4781 | - $min = HTML2PDF::$_tables[$param['num']]['tfoot']['tr'][0]; |
|
| 4782 | - $max = HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1; |
|
| 4783 | - HTML2PDF::$_tables[$param['num']]['tfoot']['tr'] = range($min, $max); |
|
| 4784 | - } |
|
| 4785 | - |
|
| 4786 | - return true; |
|
| 4787 | - } |
|
| 4788 | - |
|
| 4789 | - /** |
|
| 4790 | - * It is not a real TAG, does not use it ! |
|
| 4791 | - * |
|
| 4792 | - * @param array $param |
|
| 4793 | - * @return boolean |
|
| 4794 | - */ |
|
| 4795 | - protected function _tag_open_THEAD_SUB($param) |
|
| 4796 | - { |
|
| 4797 | - if ($this->_isForOneLine) { |
|
| 4798 | - return false; |
|
| 4799 | - } |
|
| 4800 | - |
|
| 4801 | - $this->parsingCss->save(); |
|
| 4802 | - $this->parsingCss->analyse('thead', $param); |
|
| 4803 | - $this->parsingCss->setPosition(); |
|
| 4804 | - $this->parsingCss->fontSet(); |
|
| 4805 | - |
|
| 4806 | - return true; |
|
| 4807 | - } |
|
| 4808 | - |
|
| 4809 | - /** |
|
| 4810 | - * It is not a real TAG, does not use it ! |
|
| 4811 | - * |
|
| 4812 | - * @param array $param |
|
| 4813 | - * @return boolean |
|
| 4814 | - */ |
|
| 4815 | - protected function _tag_close_THEAD_SUB($param) |
|
| 4816 | - { |
|
| 4817 | - if ($this->_isForOneLine) { |
|
| 4818 | - return false; |
|
| 4819 | - } |
|
| 4820 | - |
|
| 4821 | - $this->parsingCss->load(); |
|
| 4822 | - $this->parsingCss->fontSet(); |
|
| 4823 | - |
|
| 4824 | - return true; |
|
| 4825 | - } |
|
| 4826 | - |
|
| 4827 | - /** |
|
| 4828 | - * It is not a real TAG, does not use it ! |
|
| 4829 | - * |
|
| 4830 | - * @param array $param |
|
| 4831 | - * @return boolean |
|
| 4832 | - */ |
|
| 4833 | - protected function _tag_open_TFOOT_SUB($param) |
|
| 4834 | - { |
|
| 4835 | - if ($this->_isForOneLine) { |
|
| 4836 | - return false; |
|
| 4837 | - } |
|
| 4838 | - |
|
| 4839 | - $this->parsingCss->save(); |
|
| 4840 | - $this->parsingCss->analyse('tfoot', $param); |
|
| 4841 | - $this->parsingCss->setPosition(); |
|
| 4842 | - $this->parsingCss->fontSet(); |
|
| 4843 | - |
|
| 4844 | - return true; |
|
| 4845 | - } |
|
| 4846 | - |
|
| 4847 | - /** |
|
| 4848 | - * It is not a real TAG, does not use it ! |
|
| 4849 | - * |
|
| 4850 | - * @param array $param |
|
| 4851 | - * @return boolean |
|
| 4852 | - */ |
|
| 4853 | - protected function _tag_close_TFOOT_SUB($param) |
|
| 4854 | - { |
|
| 4855 | - if ($this->_isForOneLine) { |
|
| 4856 | - return false; |
|
| 4857 | - } |
|
| 4858 | - |
|
| 4859 | - $this->parsingCss->load(); |
|
| 4860 | - $this->parsingCss->fontSet(); |
|
| 4861 | - |
|
| 4862 | - return true; |
|
| 4863 | - } |
|
| 4864 | - |
|
| 4865 | - /** |
|
| 4866 | - * tag : FORM |
|
| 4867 | - * mode : OPEN |
|
| 4868 | - * |
|
| 4869 | - * @param array $param |
|
| 4870 | - * @return boolean |
|
| 4871 | - */ |
|
| 4872 | - protected function _tag_open_FORM($param) |
|
| 4873 | - { |
|
| 4874 | - $this->parsingCss->save(); |
|
| 4875 | - $this->parsingCss->analyse('form', $param); |
|
| 4876 | - $this->parsingCss->setPosition(); |
|
| 4877 | - $this->parsingCss->fontSet(); |
|
| 4878 | - |
|
| 4879 | - $this->pdf->setFormDefaultProp( |
|
| 4880 | - array( |
|
| 4881 | - 'lineWidth'=>1, |
|
| 4882 | - 'borderStyle'=>'solid', |
|
| 4883 | - 'fillColor'=>array(220, 220, 255), |
|
| 4884 | - 'strokeColor'=>array(128, 128, 200) |
|
| 4885 | - ) |
|
| 4886 | - ); |
|
| 4887 | - |
|
| 4888 | - $this->_isInForm = isset($param['action']) ? $param['action'] : ''; |
|
| 4889 | - |
|
| 4890 | - return true; |
|
| 4891 | - } |
|
| 4892 | - |
|
| 4893 | - /** |
|
| 4894 | - * tag : FORM |
|
| 4895 | - * mode : CLOSE |
|
| 4896 | - * |
|
| 4897 | - * @param array $param |
|
| 4898 | - * @return boolean |
|
| 4899 | - */ |
|
| 4900 | - protected function _tag_close_FORM($param) |
|
| 4901 | - { |
|
| 4902 | - $this->_isInForm = false; |
|
| 4903 | - $this->parsingCss->load(); |
|
| 4904 | - $this->parsingCss->fontSet(); |
|
| 4905 | - |
|
| 4906 | - return true; |
|
| 4907 | - } |
|
| 4908 | - |
|
| 4909 | - /** |
|
| 4910 | - * tag : TABLE |
|
| 4911 | - * mode : OPEN |
|
| 4912 | - * |
|
| 4913 | - * @param array $param |
|
| 4914 | - * @return boolean |
|
| 4915 | - */ |
|
| 4916 | - protected function _tag_open_TABLE($param, $other = 'table') |
|
| 4917 | - { |
|
| 4918 | - if ($this->_maxH) { |
|
| 4919 | - if ($this->_isForOneLine) { |
|
| 4920 | - return false; |
|
| 4921 | - } |
|
| 4922 | - $this->_tag_open_BR(array()); |
|
| 4923 | - } |
|
| 4924 | - |
|
| 4925 | - if ($this->_isForOneLine) { |
|
| 4926 | - $this->_maxX = $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); |
|
| 4927 | - return false; |
|
| 4928 | - } |
|
| 4929 | - |
|
| 4930 | - $this->_maxH = 0; |
|
| 4931 | - |
|
| 4932 | - $alignObject = isset($param['align']) ? strtolower($param['align']) : 'left'; |
|
| 4933 | - if (isset($param['align'])) unset($param['align']); |
|
| 4934 | - if ( ! in_array($alignObject, array('left', 'center', 'right'))) $alignObject = 'left'; |
|
| 4935 | - |
|
| 4936 | - $this->parsingCss->save(); |
|
| 4937 | - $this->parsingCss->analyse($other, $param); |
|
| 4938 | - $this->parsingCss->setPosition(); |
|
| 4939 | - $this->parsingCss->fontSet(); |
|
| 4940 | - |
|
| 4941 | - if ($this->parsingCss->value['margin-auto']) $alignObject = 'center'; |
|
| 4942 | - |
|
| 4943 | - // collapse table ? |
|
| 4944 | - $collapse = false; |
|
| 4945 | - if ($other == 'table') { |
|
| 4946 | - $collapse = isset($this->parsingCss->value['border']['collapse']) ? $this->parsingCss->value['border']['collapse'] : false; |
|
| 4947 | - } |
|
| 4948 | - |
|
| 4949 | - // if collapse => no borders for the table, only for TD |
|
| 4950 | - if ($collapse) { |
|
| 4951 | - $param['style']['border'] = 'none'; |
|
| 4952 | - $param['cellspacing'] = 0; |
|
| 4953 | - $none = $this->parsingCss->readBorder('none'); |
|
| 4954 | - $this->parsingCss->value['border']['t'] = $none; |
|
| 4955 | - $this->parsingCss->value['border']['r'] = $none; |
|
| 4956 | - $this->parsingCss->value['border']['b'] = $none; |
|
| 4957 | - $this->parsingCss->value['border']['l'] = $none; |
|
| 4958 | - } |
|
| 4959 | - |
|
| 4960 | - // if we are in a SUB html => prepare the properties of the table |
|
| 4961 | - if ($this->_subPart) { |
|
| 4962 | - if ($this->_debugActif) { |
|
| 4963 | - $this->_DEBUG_add('Table n'.$param['num'], true); |
|
| 4964 | - } |
|
| 4965 | - HTML2PDF::$_tables[$param['num']] = array(); |
|
| 4966 | - HTML2PDF::$_tables[$param['num']]['border'] = isset($param['border']) ? $this->parsingCss->readBorder($param['border']) : null; |
|
| 4967 | - HTML2PDF::$_tables[$param['num']]['cellpadding'] = $this->parsingCss->ConvertToMM(isset($param['cellpadding']) ? $param['cellpadding'] : '1px'); |
|
| 4968 | - HTML2PDF::$_tables[$param['num']]['cellspacing'] = $this->parsingCss->ConvertToMM(isset($param['cellspacing']) ? $param['cellspacing'] : '2px'); |
|
| 4969 | - HTML2PDF::$_tables[$param['num']]['cases'] = array(); // properties of each TR/TD |
|
| 4970 | - HTML2PDF::$_tables[$param['num']]['corr'] = array(); // link between TR/TD and colspan/rowspan |
|
| 4971 | - HTML2PDF::$_tables[$param['num']]['corr_x'] = 0; // position in 'cases' |
|
| 4972 | - HTML2PDF::$_tables[$param['num']]['corr_y'] = 0; // position in 'cases' |
|
| 4973 | - HTML2PDF::$_tables[$param['num']]['td_curr'] = 0; // current column |
|
| 4974 | - HTML2PDF::$_tables[$param['num']]['tr_curr'] = 0; // current row |
|
| 4975 | - HTML2PDF::$_tables[$param['num']]['curr_x'] = $this->pdf->getX(); |
|
| 4976 | - HTML2PDF::$_tables[$param['num']]['curr_y'] = $this->pdf->getY(); |
|
| 4977 | - HTML2PDF::$_tables[$param['num']]['width'] = 0; // global width |
|
| 4978 | - HTML2PDF::$_tables[$param['num']]['height'] = 0; // global height |
|
| 4979 | - HTML2PDF::$_tables[$param['num']]['align'] = $alignObject; |
|
| 4980 | - HTML2PDF::$_tables[$param['num']]['marge'] = array(); |
|
| 4981 | - HTML2PDF::$_tables[$param['num']]['marge']['t'] = $this->parsingCss->value['padding']['t'] + $this->parsingCss->value['border']['t']['width'] + HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5; |
|
| 4982 | - HTML2PDF::$_tables[$param['num']]['marge']['r'] = $this->parsingCss->value['padding']['r'] + $this->parsingCss->value['border']['r']['width'] + HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5; |
|
| 4983 | - HTML2PDF::$_tables[$param['num']]['marge']['b'] = $this->parsingCss->value['padding']['b'] + $this->parsingCss->value['border']['b']['width'] + HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5; |
|
| 4984 | - HTML2PDF::$_tables[$param['num']]['marge']['l'] = $this->parsingCss->value['padding']['l'] + $this->parsingCss->value['border']['l']['width'] + HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5; |
|
| 4985 | - HTML2PDF::$_tables[$param['num']]['page'] = 0; // number of pages |
|
| 4986 | - HTML2PDF::$_tables[$param['num']]['new_page'] = true; // flag : new page for the current TR |
|
| 4987 | - HTML2PDF::$_tables[$param['num']]['style_value'] = null; // CSS style of the table |
|
| 4988 | - HTML2PDF::$_tables[$param['num']]['thead'] = array(); // properties on the thead |
|
| 4989 | - HTML2PDF::$_tables[$param['num']]['tfoot'] = array(); // properties on the tfoot |
|
| 4990 | - HTML2PDF::$_tables[$param['num']]['thead']['tr'] = array(); // list of the TRs in the thead |
|
| 4991 | - HTML2PDF::$_tables[$param['num']]['tfoot']['tr'] = array(); // list of the TRs in the tfoot |
|
| 4992 | - HTML2PDF::$_tables[$param['num']]['thead']['height'] = 0; // thead height |
|
| 4993 | - HTML2PDF::$_tables[$param['num']]['tfoot']['height'] = 0; // tfoot height |
|
| 4994 | - HTML2PDF::$_tables[$param['num']]['thead']['code'] = array(); // HTML content of the thead |
|
| 4995 | - HTML2PDF::$_tables[$param['num']]['tfoot']['code'] = array(); // HTML content of the tfoot |
|
| 4996 | - HTML2PDF::$_tables[$param['num']]['cols'] = array(); // properties of the COLs |
|
| 4997 | - |
|
| 4998 | - $this->_saveMargin($this->pdf->getlMargin(), $this->pdf->gettMargin(), $this->pdf->getrMargin()); |
|
| 4999 | - |
|
| 5000 | - $this->parsingCss->value['width'] -= HTML2PDF::$_tables[$param['num']]['marge']['l'] + HTML2PDF::$_tables[$param['num']]['marge']['r']; |
|
| 5001 | - } else { |
|
| 5002 | - // we start from the first page and the first page of the table |
|
| 5003 | - HTML2PDF::$_tables[$param['num']]['page'] = 0; |
|
| 5004 | - HTML2PDF::$_tables[$param['num']]['td_curr'] = 0; |
|
| 5005 | - HTML2PDF::$_tables[$param['num']]['tr_curr'] = 0; |
|
| 5006 | - HTML2PDF::$_tables[$param['num']]['td_x'] = HTML2PDF::$_tables[$param['num']]['marge']['l'] + HTML2PDF::$_tables[$param['num']]['curr_x']; |
|
| 5007 | - HTML2PDF::$_tables[$param['num']]['td_y'] = HTML2PDF::$_tables[$param['num']]['marge']['t'] + HTML2PDF::$_tables[$param['num']]['curr_y']; |
|
| 5008 | - |
|
| 5009 | - // draw the borders/background of the first page/part of the table |
|
| 5010 | - $this->_drawRectangle( |
|
| 5011 | - HTML2PDF::$_tables[$param['num']]['curr_x'], |
|
| 5012 | - HTML2PDF::$_tables[$param['num']]['curr_y'], |
|
| 5013 | - HTML2PDF::$_tables[$param['num']]['width'], |
|
| 5014 | - isset(HTML2PDF::$_tables[$param['num']]['height'][0]) ? HTML2PDF::$_tables[$param['num']]['height'][0] : null, |
|
| 5015 | - $this->parsingCss->value['border'], |
|
| 5016 | - $this->parsingCss->value['padding'], |
|
| 5017 | - 0, |
|
| 5018 | - $this->parsingCss->value['background'] |
|
| 5019 | - ); |
|
| 5020 | - |
|
| 5021 | - HTML2PDF::$_tables[$param['num']]['style_value'] = $this->parsingCss->value; |
|
| 5022 | - } |
|
| 5023 | - |
|
| 5024 | - return true; |
|
| 5025 | - } |
|
| 5026 | - |
|
| 5027 | - /** |
|
| 5028 | - * tag : TABLE |
|
| 5029 | - * mode : CLOSE |
|
| 5030 | - * |
|
| 5031 | - * @param array $param |
|
| 5032 | - * @return boolean |
|
| 5033 | - */ |
|
| 5034 | - protected function _tag_close_TABLE($param) |
|
| 5035 | - { |
|
| 5036 | - if ($this->_isForOneLine) { |
|
| 5037 | - return false; |
|
| 5038 | - } |
|
| 5039 | - |
|
| 5040 | - $this->_maxH = 0; |
|
| 5041 | - |
|
| 5042 | - // if we are in a sub HTML |
|
| 5043 | - if ($this->_subPart) { |
|
| 5044 | - // calculate the size of each case |
|
| 5045 | - $this->_calculateTableCellSize(HTML2PDF::$_tables[$param['num']]['cases'], HTML2PDF::$_tables[$param['num']]['corr']); |
|
| 5046 | - |
|
| 5047 | - // calculate the height of the thead and the tfoot |
|
| 5048 | - $lst = array('thead', 'tfoot'); |
|
| 5049 | - foreach ($lst as $mode) { |
|
| 5050 | - HTML2PDF::$_tables[$param['num']][$mode]['height'] = 0; |
|
| 5051 | - foreach (HTML2PDF::$_tables[$param['num']][$mode]['tr'] as $tr) { |
|
| 5052 | - // hauteur de la ligne tr |
|
| 5053 | - $h = 0; |
|
| 5054 | - for ($i = 0; $i < count(HTML2PDF::$_tables[$param['num']]['cases'][$tr]); $i++) |
|
| 5055 | - if (HTML2PDF::$_tables[$param['num']]['cases'][$tr][$i]['rowspan'] == 1) |
|
| 5056 | - $h = max($h, HTML2PDF::$_tables[$param['num']]['cases'][$tr][$i]['h']); |
|
| 5057 | - HTML2PDF::$_tables[$param['num']][$mode]['height'] += $h; |
|
| 5058 | - } |
|
| 5059 | - } |
|
| 5060 | - |
|
| 5061 | - // calculate the width of the table |
|
| 5062 | - HTML2PDF::$_tables[$param['num']]['width'] = HTML2PDF::$_tables[$param['num']]['marge']['l'] + HTML2PDF::$_tables[$param['num']]['marge']['r']; |
|
| 5063 | - if (isset(HTML2PDF::$_tables[$param['num']]['cases'][0])) { |
|
| 5064 | - foreach (HTML2PDF::$_tables[$param['num']]['cases'][0] as $case) { |
|
| 5065 | - HTML2PDF::$_tables[$param['num']]['width'] += $case['w']; |
|
| 5066 | - } |
|
| 5067 | - } |
|
| 5068 | - |
|
| 5069 | - // X position of the table |
|
| 5070 | - $old = $this->parsingCss->getOldValues(); |
|
| 5071 | - $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); |
|
| 5072 | - $x = HTML2PDF::$_tables[$param['num']]['curr_x']; |
|
| 5073 | - $w = HTML2PDF::$_tables[$param['num']]['width']; |
|
| 5074 | - if ($parentWidth > $w) { |
|
| 5075 | - if (HTML2PDF::$_tables[$param['num']]['align'] == 'center') |
|
| 5076 | - $x = $x + ($parentWidth - $w) * 0.5; |
|
| 5077 | - else if (HTML2PDF::$_tables[$param['num']]['align'] == 'right') |
|
| 5078 | - $x = $x + $parentWidth - $w; |
|
| 5079 | - |
|
| 5080 | - HTML2PDF::$_tables[$param['num']]['curr_x'] = $x; |
|
| 5081 | - } |
|
| 5082 | - |
|
| 5083 | - // calculate the height of the table |
|
| 5084 | - HTML2PDF::$_tables[$param['num']]['height'] = array(); |
|
| 5085 | - |
|
| 5086 | - // minimum of the height because of margins, and of the thead and tfoot height |
|
| 5087 | - $h0 = HTML2PDF::$_tables[$param['num']]['marge']['t'] + HTML2PDF::$_tables[$param['num']]['marge']['b']; |
|
| 5088 | - $h0 += HTML2PDF::$_tables[$param['num']]['thead']['height'] + HTML2PDF::$_tables[$param['num']]['tfoot']['height']; |
|
| 5089 | - |
|
| 5090 | - // max height of the page |
|
| 5091 | - $max = $this->pdf->getH() - $this->pdf->getbMargin(); |
|
| 5092 | - |
|
| 5093 | - // current position on the page |
|
| 5094 | - $y = HTML2PDF::$_tables[$param['num']]['curr_y']; |
|
| 5095 | - $height = $h0; |
|
| 5096 | - |
|
| 5097 | - // we get the height of each line |
|
| 5098 | - for ($k = 0; $k < count(HTML2PDF::$_tables[$param['num']]['cases']); $k++) { |
|
| 5099 | - |
|
| 5100 | - // if it is a TR of the thead or of the tfoot => skip |
|
| 5101 | - if (in_array($k, HTML2PDF::$_tables[$param['num']]['thead']['tr'])) { |
|
| 5102 | - continue; |
|
| 5103 | - } |
|
| 5104 | - if (in_array($k, HTML2PDF::$_tables[$param['num']]['tfoot']['tr'])) { |
|
| 5105 | - continue; |
|
| 5106 | - } |
|
| 5107 | - |
|
| 5108 | - // height of the line |
|
| 5109 | - $th = 0; |
|
| 5110 | - $h = 0; |
|
| 5111 | - for ($i = 0; $i < count(HTML2PDF::$_tables[$param['num']]['cases'][$k]); $i++) { |
|
| 5112 | - $h = max($h, HTML2PDF::$_tables[$param['num']]['cases'][$k][$i]['h']); |
|
| 5113 | - |
|
| 5114 | - if (HTML2PDF::$_tables[$param['num']]['cases'][$k][$i]['rowspan'] == 1) |
|
| 5115 | - $th = max($th, HTML2PDF::$_tables[$param['num']]['cases'][$k][$i]['h']); |
|
| 5116 | - } |
|
| 5117 | - |
|
| 5118 | - // if the row does not fit on the page => new page |
|
| 5119 | - if ($y + $h + $height > $max) { |
|
| 5120 | - if ($height == $h0) $height = null; |
|
| 5121 | - HTML2PDF::$_tables[$param['num']]['height'][] = $height; |
|
| 5122 | - $height = $h0; |
|
| 5123 | - $y = $this->_margeTop; |
|
| 5124 | - } |
|
| 5125 | - $height += $th; |
|
| 5126 | - } |
|
| 5127 | - |
|
| 5128 | - // if ther is a height at the end, add it |
|
| 5129 | - if ($height != $h0 || $k == 0) HTML2PDF::$_tables[$param['num']]['height'][] = $height; |
|
| 5130 | - } else { |
|
| 5131 | - // if we have tfoor, draw it |
|
| 5132 | - if (count(HTML2PDF::$_tables[$param['num']]['tfoot']['code'])) { |
|
| 5133 | - $tmpTR = HTML2PDF::$_tables[$param['num']]['tr_curr']; |
|
| 5134 | - $tmpTD = HTML2PDF::$_tables[$param['num']]['td_curr']; |
|
| 5135 | - $oldParsePos = $this->_parsePos; |
|
| 5136 | - $oldParseCode = $this->parsingHtml->code; |
|
| 5137 | - |
|
| 5138 | - HTML2PDF::$_tables[$param['num']]['tr_curr'] = HTML2PDF::$_tables[$param['num']]['tfoot']['tr'][0]; |
|
| 5139 | - HTML2PDF::$_tables[$param['num']]['td_curr'] = 0; |
|
| 5140 | - $this->_parsePos = 0; |
|
| 5141 | - $this->parsingHtml->code = HTML2PDF::$_tables[$param['num']]['tfoot']['code']; |
|
| 5142 | - $this->_isInTfoot = true; |
|
| 5143 | - $this->_makeHTMLcode(); |
|
| 5144 | - $this->_isInTfoot = false; |
|
| 5145 | - |
|
| 5146 | - $this->_parsePos = $oldParsePos; |
|
| 5147 | - $this->parsingHtml->code = $oldParseCode; |
|
| 5148 | - HTML2PDF::$_tables[$param['num']]['tr_curr'] = $tmpTR; |
|
| 5149 | - HTML2PDF::$_tables[$param['num']]['td_curr'] = $tmpTD; |
|
| 5150 | - } |
|
| 5151 | - |
|
| 5152 | - // get the positions of the end of the table |
|
| 5153 | - $x = HTML2PDF::$_tables[$param['num']]['curr_x'] + HTML2PDF::$_tables[$param['num']]['width']; |
|
| 5154 | - if (count(HTML2PDF::$_tables[$param['num']]['height']) > 1) |
|
| 5155 | - $y = $this->_margeTop + HTML2PDF::$_tables[$param['num']]['height'][count(HTML2PDF::$_tables[$param['num']]['height']) - 1]; |
|
| 5156 | - else if (count(HTML2PDF::$_tables[$param['num']]['height']) == 1) |
|
| 5157 | - $y = HTML2PDF::$_tables[$param['num']]['curr_y'] + HTML2PDF::$_tables[$param['num']]['height'][count(HTML2PDF::$_tables[$param['num']]['height']) - 1]; |
|
| 5158 | - else |
|
| 5159 | - $y = HTML2PDF::$_tables[$param['num']]['curr_y']; |
|
| 5160 | - |
|
| 5161 | - $this->_maxX = max($this->_maxX, $x); |
|
| 5162 | - $this->_maxY = max($this->_maxY, $y); |
|
| 5163 | - |
|
| 5164 | - $this->pdf->setXY($this->pdf->getlMargin(), $y); |
|
| 5165 | - |
|
| 5166 | - $this->_loadMargin(); |
|
| 5167 | - |
|
| 5168 | - if ($this->_debugActif) { |
|
| 5169 | - $this->_DEBUG_add('Table '.$param['num'], false); |
|
| 5170 | - } |
|
| 5171 | - } |
|
| 5172 | - |
|
| 5173 | - $this->parsingCss->load(); |
|
| 5174 | - $this->parsingCss->fontSet(); |
|
| 5175 | - |
|
| 5176 | - |
|
| 5177 | - return true; |
|
| 5178 | - } |
|
| 5179 | - |
|
| 5180 | - /** |
|
| 5181 | - * tag : COL |
|
| 5182 | - * mode : OPEN |
|
| 5183 | - * |
|
| 5184 | - * @param array $param |
|
| 5185 | - * @return boolean|null |
|
| 5186 | - */ |
|
| 5187 | - protected function _tag_open_COL($param) |
|
| 5188 | - { |
|
| 5189 | - $span = isset($param['span']) ? $param['span'] : 1; |
|
| 5190 | - for ($k = 0; $k < $span; $k++) |
|
| 5191 | - HTML2PDF::$_tables[$param['num']]['cols'][] = $param; |
|
| 5192 | - } |
|
| 5193 | - |
|
| 5194 | - /** |
|
| 5195 | - * tag : COL |
|
| 5196 | - * mode : CLOSE |
|
| 5197 | - * |
|
| 5198 | - * @param array $param |
|
| 5199 | - * @return boolean |
|
| 5200 | - */ |
|
| 5201 | - protected function _tag_close_COL($param) |
|
| 5202 | - { |
|
| 5203 | - // there is nothing to do here |
|
| 5204 | - |
|
| 5205 | - return true; |
|
| 5206 | - } |
|
| 5207 | - |
|
| 5208 | - /** |
|
| 5209 | - * tag : TR |
|
| 5210 | - * mode : OPEN |
|
| 5211 | - * |
|
| 5212 | - * @param array $param |
|
| 5213 | - * @return boolean |
|
| 5214 | - */ |
|
| 5215 | - protected function _tag_open_TR($param, $other = 'tr') |
|
| 5216 | - { |
|
| 5217 | - if ($this->_isForOneLine) { |
|
| 5218 | - return false; |
|
| 5219 | - } |
|
| 5220 | - |
|
| 5221 | - $this->_maxH = 0; |
|
| 5222 | - |
|
| 5223 | - $this->parsingCss->save(); |
|
| 5224 | - $this->parsingCss->analyse($other, $param); |
|
| 5225 | - $this->parsingCss->setPosition(); |
|
| 5226 | - $this->parsingCss->fontSet(); |
|
| 5227 | - |
|
| 5228 | - // position in the table |
|
| 5229 | - HTML2PDF::$_tables[$param['num']]['tr_curr']++; |
|
| 5230 | - HTML2PDF::$_tables[$param['num']]['td_curr'] = 0; |
|
| 5231 | - |
|
| 5232 | - // if we are not in a sub html |
|
| 5233 | - if ( ! $this->_subPart) { |
|
| 5234 | - |
|
| 5235 | - // Y after the row |
|
| 5236 | - $ty = null; |
|
| 5237 | - for ($ii = 0; $ii < count(HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1]); $ii++) { |
|
| 5238 | - $ty = max($ty, HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][$ii]['h']); |
|
| 5239 | - } |
|
| 5240 | - |
|
| 5241 | - // height of the tfoot |
|
| 5242 | - $hfoot = HTML2PDF::$_tables[$param['num']]['tfoot']['height']; |
|
| 5243 | - |
|
| 5244 | - // if the line does not fit on the page => new page |
|
| 5245 | - if ( ! $this->_isInTfoot && HTML2PDF::$_tables[$param['num']]['td_y'] + HTML2PDF::$_tables[$param['num']]['marge']['b'] + $ty + $hfoot > $this->pdf->getH() - $this->pdf->getbMargin()) { |
|
| 5246 | - |
|
| 5247 | - // fi ther is a tfoot => draw it |
|
| 5248 | - if (count(HTML2PDF::$_tables[$param['num']]['tfoot']['code'])) { |
|
| 5249 | - $tmpTR = HTML2PDF::$_tables[$param['num']]['tr_curr']; |
|
| 5250 | - $tmpTD = HTML2PDF::$_tables[$param['num']]['td_curr']; |
|
| 5251 | - $oldParsePos = $this->_parsePos; |
|
| 5252 | - $oldParseCode = $this->parsingHtml->code; |
|
| 5253 | - |
|
| 5254 | - HTML2PDF::$_tables[$param['num']]['tr_curr'] = HTML2PDF::$_tables[$param['num']]['tfoot']['tr'][0]; |
|
| 5255 | - HTML2PDF::$_tables[$param['num']]['td_curr'] = 0; |
|
| 5256 | - $this->_parsePos = 0; |
|
| 5257 | - $this->parsingHtml->code = HTML2PDF::$_tables[$param['num']]['tfoot']['code']; |
|
| 5258 | - $this->_isInTfoot = true; |
|
| 5259 | - $this->_makeHTMLcode(); |
|
| 5260 | - $this->_isInTfoot = false; |
|
| 5261 | - |
|
| 5262 | - $this->_parsePos = $oldParsePos; |
|
| 5263 | - $this->parsingHtml->code = $oldParseCode; |
|
| 5264 | - HTML2PDF::$_tables[$param['num']]['tr_curr'] = $tmpTR; |
|
| 5265 | - HTML2PDF::$_tables[$param['num']]['td_curr'] = $tmpTD; |
|
| 5266 | - } |
|
| 5267 | - |
|
| 5268 | - // new page |
|
| 5269 | - HTML2PDF::$_tables[$param['num']]['new_page'] = true; |
|
| 5270 | - $this->_setNewPage(); |
|
| 5271 | - |
|
| 5272 | - // new position |
|
| 5273 | - HTML2PDF::$_tables[$param['num']]['page']++; |
|
| 5274 | - HTML2PDF::$_tables[$param['num']]['curr_y'] = $this->pdf->getY(); |
|
| 5275 | - HTML2PDF::$_tables[$param['num']]['td_y'] = HTML2PDF::$_tables[$param['num']]['curr_y'] + HTML2PDF::$_tables[$param['num']]['marge']['t']; |
|
| 5276 | - |
|
| 5277 | - // if we have the height of the tbale on the page => draw borders and background |
|
| 5278 | - if (isset(HTML2PDF::$_tables[$param['num']]['height'][HTML2PDF::$_tables[$param['num']]['page']])) { |
|
| 5279 | - $old = $this->parsingCss->value; |
|
| 5280 | - $this->parsingCss->value = HTML2PDF::$_tables[$param['num']]['style_value']; |
|
| 5281 | - |
|
| 5282 | - $this->_drawRectangle( |
|
| 5283 | - HTML2PDF::$_tables[$param['num']]['curr_x'], |
|
| 5284 | - HTML2PDF::$_tables[$param['num']]['curr_y'], |
|
| 5285 | - HTML2PDF::$_tables[$param['num']]['width'], |
|
| 5286 | - HTML2PDF::$_tables[$param['num']]['height'][HTML2PDF::$_tables[$param['num']]['page']], |
|
| 5287 | - $this->parsingCss->value['border'], |
|
| 5288 | - $this->parsingCss->value['padding'], |
|
| 5289 | - HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5, |
|
| 5290 | - $this->parsingCss->value['background'] |
|
| 5291 | - ); |
|
| 5292 | - |
|
| 5293 | - $this->parsingCss->value = $old; |
|
| 5294 | - } |
|
| 5295 | - } |
|
| 5296 | - |
|
| 5297 | - // if we are in a new page, and if we have a thead => draw it |
|
| 5298 | - if (HTML2PDF::$_tables[$param['num']]['new_page'] && count(HTML2PDF::$_tables[$param['num']]['thead']['code'])) { |
|
| 5299 | - HTML2PDF::$_tables[$param['num']]['new_page'] = false; |
|
| 5300 | - $tmpTR = HTML2PDF::$_tables[$param['num']]['tr_curr']; |
|
| 5301 | - $tmpTD = HTML2PDF::$_tables[$param['num']]['td_curr']; |
|
| 5302 | - $oldParsePos = $this->_parsePos; |
|
| 5303 | - $oldParseCode = $this->parsingHtml->code; |
|
| 5304 | - |
|
| 5305 | - HTML2PDF::$_tables[$param['num']]['tr_curr'] = HTML2PDF::$_tables[$param['num']]['thead']['tr'][0]; |
|
| 5306 | - HTML2PDF::$_tables[$param['num']]['td_curr'] = 0; |
|
| 5307 | - $this->_parsePos = 0; |
|
| 5308 | - $this->parsingHtml->code = HTML2PDF::$_tables[$param['num']]['thead']['code']; |
|
| 5309 | - $this->_isInThead = true; |
|
| 5310 | - $this->_makeHTMLcode(); |
|
| 5311 | - $this->_isInThead = false; |
|
| 5312 | - |
|
| 5313 | - $this->_parsePos = $oldParsePos; |
|
| 5314 | - $this->parsingHtml->code = $oldParseCode; |
|
| 5315 | - HTML2PDF::$_tables[$param['num']]['tr_curr'] = $tmpTR; |
|
| 5316 | - HTML2PDF::$_tables[$param['num']]['td_curr'] = $tmpTD; |
|
| 5317 | - HTML2PDF::$_tables[$param['num']]['new_page'] = true; |
|
| 5318 | - } |
|
| 5319 | - // else (in a sub HTML) |
|
| 5320 | - } else { |
|
| 5321 | - // prepare it |
|
| 5322 | - HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1] = array(); |
|
| 5323 | - if ( ! isset(HTML2PDF::$_tables[$param['num']]['corr'][HTML2PDF::$_tables[$param['num']]['corr_y']])) |
|
| 5324 | - HTML2PDF::$_tables[$param['num']]['corr'][HTML2PDF::$_tables[$param['num']]['corr_y']] = array(); |
|
| 5325 | - |
|
| 5326 | - HTML2PDF::$_tables[$param['num']]['corr_x'] = 0; |
|
| 5327 | - while (isset(HTML2PDF::$_tables[$param['num']]['corr'][HTML2PDF::$_tables[$param['num']]['corr_y']][HTML2PDF::$_tables[$param['num']]['corr_x']])) |
|
| 5328 | - HTML2PDF::$_tables[$param['num']]['corr_x']++; |
|
| 5329 | - } |
|
| 5330 | - |
|
| 5331 | - return true; |
|
| 5332 | - } |
|
| 5333 | - |
|
| 5334 | - /** |
|
| 5335 | - * tag : TR |
|
| 5336 | - * mode : CLOSE |
|
| 5337 | - * |
|
| 5338 | - * @param array $param |
|
| 5339 | - * @return boolean |
|
| 5340 | - */ |
|
| 5341 | - protected function _tag_close_TR($param) |
|
| 5342 | - { |
|
| 5343 | - if ($this->_isForOneLine) { |
|
| 5344 | - return false; |
|
| 5345 | - } |
|
| 5346 | - |
|
| 5347 | - $this->_maxH = 0; |
|
| 5348 | - |
|
| 5349 | - $this->parsingCss->load(); |
|
| 5350 | - $this->parsingCss->fontSet(); |
|
| 5351 | - |
|
| 5352 | - // if we are not in a sub HTML |
|
| 5353 | - if ( ! $this->_subPart) { |
|
| 5354 | - |
|
| 5355 | - // Y of the current line |
|
| 5356 | - $ty = null; |
|
| 5357 | - for ($ii = 0; $ii < count(HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1]); $ii++) { |
|
| 5358 | - if (HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][$ii]['rowspan'] == 1) { |
|
| 5359 | - $ty = HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][$ii]['h']; |
|
| 5360 | - } |
|
| 5361 | - } |
|
| 5362 | - |
|
| 5363 | - // new position |
|
| 5364 | - HTML2PDF::$_tables[$param['num']]['td_x'] = HTML2PDF::$_tables[$param['num']]['curr_x'] + HTML2PDF::$_tables[$param['num']]['marge']['l']; |
|
| 5365 | - HTML2PDF::$_tables[$param['num']]['td_y'] += $ty; |
|
| 5366 | - HTML2PDF::$_tables[$param['num']]['new_page'] = false; |
|
| 5367 | - } else { |
|
| 5368 | - HTML2PDF::$_tables[$param['num']]['corr_y']++; |
|
| 5369 | - } |
|
| 5370 | - |
|
| 5371 | - return true; |
|
| 5372 | - } |
|
| 5373 | - |
|
| 5374 | - /** |
|
| 5375 | - * tag : TD |
|
| 5376 | - * mode : OPEN |
|
| 5377 | - * |
|
| 5378 | - * @param array $param |
|
| 5379 | - * @return boolean |
|
| 5380 | - */ |
|
| 5381 | - protected function _tag_open_TD($param, $other = 'td') |
|
| 5382 | - { |
|
| 5383 | - if ($this->_isForOneLine) { |
|
| 5384 | - return false; |
|
| 5385 | - } |
|
| 5386 | - |
|
| 5387 | - $this->_maxH = 0; |
|
| 5388 | - |
|
| 5389 | - $param['cellpadding'] = HTML2PDF::$_tables[$param['num']]['cellpadding'].'mm'; |
|
| 5390 | - $param['cellspacing'] = HTML2PDF::$_tables[$param['num']]['cellspacing'].'mm'; |
|
| 5391 | - |
|
| 5392 | - // specific style for LI |
|
| 5393 | - if ($other == 'li') { |
|
| 5394 | - $specialLi = true; |
|
| 5395 | - } else { |
|
| 5396 | - $specialLi = false; |
|
| 5397 | - if ($other == 'li_sub') { |
|
| 5398 | - $param['style']['border'] = 'none'; |
|
| 5399 | - $param['style']['background-color'] = 'transparent'; |
|
| 5400 | - $param['style']['background-image'] = 'none'; |
|
| 5401 | - $param['style']['background-position'] = ''; |
|
| 5402 | - $param['style']['background-repeat'] = ''; |
|
| 5403 | - $other = 'li'; |
|
| 5404 | - } |
|
| 5405 | - } |
|
| 5406 | - |
|
| 5407 | - // get the properties of the TD |
|
| 5408 | - $x = HTML2PDF::$_tables[$param['num']]['td_curr']; |
|
| 5409 | - $y = HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1; |
|
| 5410 | - $colspan = isset($param['colspan']) ? $param['colspan'] : 1; |
|
| 5411 | - $rowspan = isset($param['rowspan']) ? $param['rowspan'] : 1; |
|
| 5412 | - |
|
| 5413 | - // flag for collapse table |
|
| 5414 | - $collapse = false; |
|
| 5415 | - |
|
| 5416 | - // specific traitment for TD and TH |
|
| 5417 | - if (in_array($other, array('td', 'th'))) { |
|
| 5418 | - // id of the column |
|
| 5419 | - $numCol = isset(HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Xr']) ? HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Xr'] : HTML2PDF::$_tables[$param['num']]['corr_x']; |
|
| 5420 | - |
|
| 5421 | - // we get the properties of the COL tag, if exist |
|
| 5422 | - if (isset(HTML2PDF::$_tables[$param['num']]['cols'][$numCol])) { |
|
| 5423 | - |
|
| 5424 | - $colParam = HTML2PDF::$_tables[$param['num']]['cols'][$numCol]; |
|
| 5425 | - |
|
| 5426 | - // for colspans => we get all the neede widths |
|
| 5427 | - $colParam['style']['width'] = array(); |
|
| 5428 | - for ($k = 0; $k < $colspan; $k++) { |
|
| 5429 | - if (isset(HTML2PDF::$_tables[$param['num']]['cols'][$numCol + $k]['style']['width'])) { |
|
| 5430 | - $colParam['style']['width'][] = HTML2PDF::$_tables[$param['num']]['cols'][$numCol + $k]['style']['width']; |
|
| 5431 | - } |
|
| 5432 | - } |
|
| 5433 | - |
|
| 5434 | - // calculate the total width of the column |
|
| 5435 | - $total = ''; |
|
| 5436 | - $last = $this->parsingCss->getLastWidth(); |
|
| 5437 | - if (count($colParam['style']['width'])) { |
|
| 5438 | - $total = $colParam['style']['width'][0]; unset($colParam['style']['width'][0]); |
|
| 5439 | - foreach ($colParam['style']['width'] as $width) { |
|
| 5440 | - if (substr($total, -1) == '%' && substr($width, -1) == '%') |
|
| 5441 | - $total = (str_replace('%', '', $total) + str_replace('%', '', $width)).'%'; |
|
| 5442 | - else |
|
| 5443 | - $total = ($this->parsingCss->ConvertToMM($total, $last) + $this->parsingCss->ConvertToMM($width, $last)).'mm'; |
|
| 5444 | - } |
|
| 5445 | - } |
|
| 5446 | - |
|
| 5447 | - // get the final width |
|
| 5448 | - if ($total) { |
|
| 5449 | - $colParam['style']['width'] = $total; |
|
| 5450 | - } else { |
|
| 5451 | - unset($colParam['style']['width']); |
|
| 5452 | - } |
|
| 5453 | - |
|
| 5454 | - |
|
| 5455 | - // merge the styles of the COL and the TD |
|
| 5456 | - $param['style'] = array_merge($colParam['style'], $param['style']); |
|
| 5457 | - |
|
| 5458 | - // merge the class of the COL and the TD |
|
| 5459 | - if (isset($colParam['class'])) { |
|
| 5460 | - $param['class'] = $colParam['class'].(isset($param['class']) ? ' '.$param['class'] : ''); |
|
| 5461 | - } |
|
| 5462 | - } |
|
| 5463 | - |
|
| 5464 | - $collapse = isset($this->parsingCss->value['border']['collapse']) ? $this->parsingCss->value['border']['collapse'] : false; |
|
| 5465 | - } |
|
| 5466 | - |
|
| 5467 | - $this->parsingCss->save(); |
|
| 5468 | - |
|
| 5469 | - // legacy for TD and TH |
|
| 5470 | - $legacy = null; |
|
| 5471 | - if (in_array($other, array('td', 'th'))) { |
|
| 5472 | - $legacy = array(); |
|
| 5473 | - |
|
| 5474 | - $old = $this->parsingCss->getLastValue('background'); |
|
| 5475 | - if ($old && ($old['color'] || $old['image'])) { |
|
| 5476 | - $legacy['background'] = $old; |
|
| 5477 | - } |
|
| 5478 | - |
|
| 5479 | - if (HTML2PDF::$_tables[$param['num']]['border']) { |
|
| 5480 | - $legacy['border'] = array(); |
|
| 5481 | - $legacy['border']['l'] = HTML2PDF::$_tables[$param['num']]['border']; |
|
| 5482 | - $legacy['border']['t'] = HTML2PDF::$_tables[$param['num']]['border']; |
|
| 5483 | - $legacy['border']['r'] = HTML2PDF::$_tables[$param['num']]['border']; |
|
| 5484 | - $legacy['border']['b'] = HTML2PDF::$_tables[$param['num']]['border']; |
|
| 5485 | - } |
|
| 5486 | - } |
|
| 5487 | - $return = $this->parsingCss->analyse($other, $param, $legacy); |
|
| 5488 | - |
|
| 5489 | - if ($specialLi) { |
|
| 5490 | - $this->parsingCss->value['width'] -= $this->parsingCss->ConvertToMM($this->_listeGetWidth()); |
|
| 5491 | - $this->parsingCss->value['width'] -= $this->parsingCss->ConvertToMM($this->_listeGetPadding()); |
|
| 5492 | - } |
|
| 5493 | - $this->parsingCss->setPosition(); |
|
| 5494 | - $this->parsingCss->fontSet(); |
|
| 5495 | - |
|
| 5496 | - // if tale collapse => modify the borders |
|
| 5497 | - if ($collapse) { |
|
| 5498 | - if ( ! $this->_subPart) { |
|
| 5499 | - if ( |
|
| 5500 | - (HTML2PDF::$_tables[$param['num']]['tr_curr'] > 1 && ! HTML2PDF::$_tables[$param['num']]['new_page']) || |
|
| 5501 | - ( ! $this->_isInThead && count(HTML2PDF::$_tables[$param['num']]['thead']['code'])) |
|
| 5502 | - ) { |
|
| 5503 | - $this->parsingCss->value['border']['t'] = $this->parsingCss->readBorder('none'); |
|
| 5504 | - } |
|
| 5505 | - } |
|
| 5506 | - |
|
| 5507 | - if (HTML2PDF::$_tables[$param['num']]['td_curr'] > 0) { |
|
| 5508 | - if ( ! $return) $this->parsingCss->value['width'] += $this->parsingCss->value['border']['l']['width']; |
|
| 5509 | - $this->parsingCss->value['border']['l'] = $this->parsingCss->readBorder('none'); |
|
| 5510 | - } |
|
| 5511 | - } |
|
| 5512 | - |
|
| 5513 | - // margins of the table |
|
| 5514 | - $marge = array(); |
|
| 5515 | - $marge['t'] = $this->parsingCss->value['padding']['t'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['t']['width']; |
|
| 5516 | - $marge['r'] = $this->parsingCss->value['padding']['r'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['r']['width']; |
|
| 5517 | - $marge['b'] = $this->parsingCss->value['padding']['b'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['b']['width']; |
|
| 5518 | - $marge['l'] = $this->parsingCss->value['padding']['l'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['l']['width']; |
|
| 5519 | - |
|
| 5520 | - // if we are in a sub HTML |
|
| 5521 | - if ($this->_subPart) { |
|
| 5522 | - // new position in the table |
|
| 5523 | - HTML2PDF::$_tables[$param['num']]['td_curr']++; |
|
| 5524 | - HTML2PDF::$_tables[$param['num']]['cases'][$y][$x] = array(); |
|
| 5525 | - HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['w'] = 0; |
|
| 5526 | - HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['h'] = 0; |
|
| 5527 | - HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['dw'] = 0; |
|
| 5528 | - HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['colspan'] = $colspan; |
|
| 5529 | - HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['rowspan'] = $rowspan; |
|
| 5530 | - HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Xr'] = HTML2PDF::$_tables[$param['num']]['corr_x']; |
|
| 5531 | - HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Yr'] = HTML2PDF::$_tables[$param['num']]['corr_y']; |
|
| 5532 | - |
|
| 5533 | - // prepare the mapping for rowspan and colspan |
|
| 5534 | - for ($j = 0; $j < $rowspan; $j++) { |
|
| 5535 | - for ($i = 0; $i < $colspan; $i++) { |
|
| 5536 | - HTML2PDF::$_tables[$param['num']]['corr'] |
|
| 5537 | - [HTML2PDF::$_tables[$param['num']]['corr_y'] + $j] |
|
| 5538 | - [HTML2PDF::$_tables[$param['num']]['corr_x'] + $i] = ($i + $j > 0) ? '' : array($x, $y, $colspan, $rowspan); |
|
| 5539 | - } |
|
| 5540 | - } |
|
| 5541 | - HTML2PDF::$_tables[$param['num']]['corr_x'] += $colspan; |
|
| 5542 | - while (isset(HTML2PDF::$_tables[$param['num']]['corr'][HTML2PDF::$_tables[$param['num']]['corr_y']][HTML2PDF::$_tables[$param['num']]['corr_x']])) { |
|
| 5543 | - HTML2PDF::$_tables[$param['num']]['corr_x']++; |
|
| 5544 | - } |
|
| 5545 | - |
|
| 5546 | - // extract the content of the TD, and calculate his size |
|
| 5547 | - $level = $this->parsingHtml->getLevel($this->_tempPos); |
|
| 5548 | - $this->_createSubHTML($this->_subHtml); |
|
| 5549 | - $this->_subHtml->parsingHtml->code = $level; |
|
| 5550 | - $this->_subHtml->_makeHTMLcode(); |
|
| 5551 | - $this->_tempPos += count($level); |
|
| 5552 | - } else { |
|
| 5553 | - // new position in the table |
|
| 5554 | - HTML2PDF::$_tables[$param['num']]['td_curr']++; |
|
| 5555 | - HTML2PDF::$_tables[$param['num']]['td_x'] += HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['dw']; |
|
| 5556 | - |
|
| 5557 | - // borders and background of the TD |
|
| 5558 | - $this->_drawRectangle( |
|
| 5559 | - HTML2PDF::$_tables[$param['num']]['td_x'], |
|
| 5560 | - HTML2PDF::$_tables[$param['num']]['td_y'], |
|
| 5561 | - HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['w'], |
|
| 5562 | - HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['h'], |
|
| 5563 | - $this->parsingCss->value['border'], |
|
| 5564 | - $this->parsingCss->value['padding'], |
|
| 5565 | - HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5, |
|
| 5566 | - $this->parsingCss->value['background'] |
|
| 5567 | - ); |
|
| 5568 | - |
|
| 5569 | - $this->parsingCss->value['width'] = HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['w'] - $marge['l'] - $marge['r']; |
|
| 5570 | - |
|
| 5571 | - // marges = size of the TD |
|
| 5572 | - $mL = HTML2PDF::$_tables[$param['num']]['td_x'] + $marge['l']; |
|
| 5573 | - $mR = $this->pdf->getW() - $mL - $this->parsingCss->value['width']; |
|
| 5574 | - $this->_saveMargin($mL, 0, $mR); |
|
| 5575 | - |
|
| 5576 | - // position of the content, from vertical-align |
|
| 5577 | - $hCorr = HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['h']; |
|
| 5578 | - $hReel = HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['real_h']; |
|
| 5579 | - switch ($this->parsingCss->value['vertical-align']) |
|
| 5580 | - { |
|
| 5581 | - case 'bottom': |
|
| 5582 | - $yCorr = $hCorr - $hReel; |
|
| 5583 | - break; |
|
| 5584 | - |
|
| 5585 | - case 'middle': |
|
| 5586 | - $yCorr = ($hCorr - $hReel) * 0.5; |
|
| 5587 | - break; |
|
| 5588 | - |
|
| 5589 | - case 'top': |
|
| 5590 | - default: |
|
| 5591 | - $yCorr = 0; |
|
| 5592 | - break; |
|
| 5593 | - } |
|
| 5594 | - |
|
| 5595 | - // position of the content |
|
| 5596 | - $x = HTML2PDF::$_tables[$param['num']]['td_x'] + $marge['l']; |
|
| 5597 | - $y = HTML2PDF::$_tables[$param['num']]['td_y'] + $marge['t'] + $yCorr; |
|
| 5598 | - $this->pdf->setXY($x, $y); |
|
| 5599 | - $this->_setNewPositionForNewLine(); |
|
| 5600 | - } |
|
| 5601 | - |
|
| 5602 | - return true; |
|
| 5603 | - } |
|
| 5604 | - |
|
| 5605 | - /** |
|
| 5606 | - * tag : TD |
|
| 5607 | - * mode : CLOSE |
|
| 5608 | - * |
|
| 5609 | - * @param array $param |
|
| 5610 | - * @return boolean |
|
| 5611 | - */ |
|
| 5612 | - protected function _tag_close_TD($param) |
|
| 5613 | - { |
|
| 5614 | - if ($this->_isForOneLine) { |
|
| 5615 | - return false; |
|
| 5616 | - } |
|
| 5617 | - |
|
| 5618 | - $this->_maxH = 0; |
|
| 5619 | - |
|
| 5620 | - // get the margins |
|
| 5621 | - $marge = array(); |
|
| 5622 | - $marge['t'] = $this->parsingCss->value['padding']['t'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['t']['width']; |
|
| 5623 | - $marge['r'] = $this->parsingCss->value['padding']['r'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['r']['width']; |
|
| 5624 | - $marge['b'] = $this->parsingCss->value['padding']['b'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['b']['width']; |
|
| 5625 | - $marge['l'] = $this->parsingCss->value['padding']['l'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['l']['width']; |
|
| 5626 | - $marge['t'] += 0.001; |
|
| 5627 | - $marge['r'] += 0.001; |
|
| 5628 | - $marge['b'] += 0.001; |
|
| 5629 | - $marge['l'] += 0.001; |
|
| 5630 | - |
|
| 5631 | - // if we are in a sub HTML |
|
| 5632 | - if ($this->_subPart) { |
|
| 5633 | - |
|
| 5634 | - // it msut take only one page |
|
| 5635 | - if ($this->_testTdInOnepage && $this->_subHtml->pdf->getPage() > 1) { |
|
| 5636 | - throw new HTML2PDF_exception(7); |
|
| 5637 | - } |
|
| 5638 | - |
|
| 5639 | - // size of the content of the TD |
|
| 5640 | - $w0 = $this->_subHtml->_maxX + $marge['l'] + $marge['r']; |
|
| 5641 | - $h0 = $this->_subHtml->_maxY + $marge['t'] + $marge['b']; |
|
| 5642 | - |
|
| 5643 | - // size from the CSS style |
|
| 5644 | - $w2 = $this->parsingCss->value['width'] + $marge['l'] + $marge['r']; |
|
| 5645 | - $h2 = $this->parsingCss->value['height'] + $marge['t'] + $marge['b']; |
|
| 5646 | - |
|
| 5647 | - // final size of the TD |
|
| 5648 | - HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['w'] = max(array($w0, $w2)); |
|
| 5649 | - HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['h'] = max(array($h0, $h2)); |
|
| 5650 | - |
|
| 5651 | - // real position of the content |
|
| 5652 | - HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['real_w'] = $w0; |
|
| 5653 | - HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['real_h'] = $h0; |
|
| 5654 | - |
|
| 5655 | - // destroy the sub HTML |
|
| 5656 | - $this->_destroySubHTML($this->_subHtml); |
|
| 5657 | - } else { |
|
| 5658 | - $this->_loadMargin(); |
|
| 5659 | - |
|
| 5660 | - HTML2PDF::$_tables[$param['num']]['td_x'] += HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['w']; |
|
| 5661 | - } |
|
| 5662 | - |
|
| 5663 | - $this->parsingCss->load(); |
|
| 5664 | - $this->parsingCss->fontSet(); |
|
| 5665 | - |
|
| 5666 | - return true; |
|
| 5667 | - } |
|
| 5668 | - |
|
| 5669 | - |
|
| 5670 | - /** |
|
| 5671 | - * tag : TH |
|
| 5672 | - * mode : OPEN |
|
| 5673 | - * |
|
| 5674 | - * @param array $param |
|
| 5675 | - * @return boolean |
|
| 5676 | - */ |
|
| 5677 | - protected function _tag_open_TH($param) |
|
| 5678 | - { |
|
| 5679 | - if ($this->_isForOneLine) { |
|
| 5680 | - return false; |
|
| 5681 | - } |
|
| 5682 | - |
|
| 5683 | - $this->parsingCss->save(); |
|
| 5684 | - $this->parsingCss->value['font-bold'] = true; |
|
| 5685 | - |
|
| 5686 | - $this->_tag_open_TD($param, 'th'); |
|
| 5687 | - |
|
| 5688 | - return true; |
|
| 5689 | - } |
|
| 5690 | - |
|
| 5691 | - /** |
|
| 5692 | - * tag : TH |
|
| 5693 | - * mode : CLOSE |
|
| 5694 | - * |
|
| 5695 | - * @param array $param |
|
| 5696 | - * @return boolean |
|
| 5697 | - */ |
|
| 5698 | - protected function _tag_close_TH($param) |
|
| 5699 | - { |
|
| 5700 | - if ($this->_isForOneLine) { |
|
| 5701 | - return false; |
|
| 5702 | - } |
|
| 5703 | - |
|
| 5704 | - $this->_tag_close_TD($param); |
|
| 5705 | - |
|
| 5706 | - $this->parsingCss->load(); |
|
| 5707 | - |
|
| 5708 | - return true; |
|
| 5709 | - } |
|
| 5710 | - |
|
| 5711 | - /** |
|
| 5712 | - * tag : IMG |
|
| 5713 | - * mode : OPEN |
|
| 5714 | - * |
|
| 5715 | - * @param array $param |
|
| 5716 | - * @return boolean |
|
| 5717 | - */ |
|
| 5718 | - protected function _tag_open_IMG($param) |
|
| 5719 | - { |
|
| 5720 | - $src = str_replace('&', '&', $param['src']); |
|
| 5721 | - |
|
| 5722 | - $this->parsingCss->save(); |
|
| 5723 | - $this->parsingCss->value['width'] = 0; |
|
| 5724 | - $this->parsingCss->value['height'] = 0; |
|
| 5725 | - $this->parsingCss->value['border'] = array('type' => 'none', 'width' => 0, 'color' => array(0, 0, 0)); |
|
| 5726 | - $this->parsingCss->value['background'] = array('color' => null, 'image' => null, 'position' => null, 'repeat' => null); |
|
| 5727 | - $this->parsingCss->analyse('img', $param); |
|
| 5728 | - $this->parsingCss->setPosition(); |
|
| 5729 | - $this->parsingCss->fontSet(); |
|
| 5730 | - |
|
| 5731 | - $res = $this->_drawImage($src, isset($param['sub_li'])); |
|
| 5732 | - if ( ! $res) return $res; |
|
| 5733 | - |
|
| 5734 | - $this->parsingCss->load(); |
|
| 5735 | - $this->parsingCss->fontSet(); |
|
| 5736 | - $this->_maxE++; |
|
| 5737 | - |
|
| 5738 | - return true; |
|
| 5739 | - } |
|
| 5740 | - |
|
| 5741 | - /** |
|
| 5742 | - * tag : SELECT |
|
| 5743 | - * mode : OPEN |
|
| 5744 | - * |
|
| 5745 | - * @param array $param |
|
| 5746 | - * @return boolean |
|
| 5747 | - */ |
|
| 5748 | - protected function _tag_open_SELECT($param) |
|
| 5749 | - { |
|
| 5750 | - if ( ! isset($param['name'])) { |
|
| 5751 | - $param['name'] = 'champs_pdf_'.(count($this->_lstField) + 1); |
|
| 5752 | - } |
|
| 5753 | - |
|
| 5754 | - $param['name'] = strtolower($param['name']); |
|
| 5755 | - |
|
| 5756 | - if (isset($this->_lstField[$param['name']])) { |
|
| 5757 | - $this->_lstField[$param['name']]++; |
|
| 5758 | - } else { |
|
| 5759 | - $this->_lstField[$param['name']] = 1; |
|
| 5760 | - } |
|
| 5761 | - |
|
| 5762 | - $this->parsingCss->save(); |
|
| 5763 | - $this->parsingCss->analyse('select', $param); |
|
| 5764 | - $this->parsingCss->setPosition(); |
|
| 5765 | - $this->parsingCss->fontSet(); |
|
| 5766 | - |
|
| 5767 | - $this->_lstSelect = array(); |
|
| 5768 | - $this->_lstSelect['name'] = $param['name']; |
|
| 5769 | - $this->_lstSelect['multi'] = isset($param['multiple']) ? true : false; |
|
| 5770 | - $this->_lstSelect['size'] = isset($param['size']) ? $param['size'] : 1; |
|
| 5771 | - $this->_lstSelect['options'] = array(); |
|
| 5772 | - |
|
| 5773 | - if ($this->_lstSelect['multi'] && $this->_lstSelect['size'] < 3) $this->_lstSelect['size'] = 3; |
|
| 5774 | - |
|
| 5775 | - return true; |
|
| 5776 | - } |
|
| 5777 | - |
|
| 5778 | - /** |
|
| 5779 | - * tag : OPTION |
|
| 5780 | - * mode : OPEN |
|
| 5781 | - * |
|
| 5782 | - * @param array $param |
|
| 5783 | - * @return boolean |
|
| 5784 | - */ |
|
| 5785 | - protected function _tag_open_OPTION($param) |
|
| 5786 | - { |
|
| 5787 | - // get the content of the option : it is the text of the option |
|
| 5788 | - $level = $this->parsingHtml->getLevel($this->_parsePos); |
|
| 5789 | - $this->_parsePos += count($level); |
|
| 5790 | - $value = isset($param['value']) ? $param['value'] : 'aut_tag_open_opt_'.(count($this->_lstSelect) + 1); |
|
| 5791 | - |
|
| 5792 | - $this->_lstSelect['options'][$value] = isset($level[0]['param']['txt']) ? $level[0]['param']['txt'] : ''; |
|
| 5793 | - |
|
| 5794 | - return true; |
|
| 5795 | - } |
|
| 5796 | - |
|
| 5797 | - /** |
|
| 5798 | - * tag : OPTION |
|
| 5799 | - * mode : CLOSE |
|
| 5800 | - * |
|
| 5801 | - * @param array $param |
|
| 5802 | - * @return boolean |
|
| 5803 | - */ |
|
| 5804 | - protected function _tag_close_OPTION($param) |
|
| 5805 | - { |
|
| 5806 | - // nothing to do here |
|
| 5807 | - |
|
| 5808 | - return true; |
|
| 5809 | - } |
|
| 5810 | - |
|
| 5811 | - /** |
|
| 5812 | - * tag : SELECT |
|
| 5813 | - * mode : CLOSE |
|
| 5814 | - * |
|
| 5815 | - * @return boolean |
|
| 5816 | - */ |
|
| 5817 | - protected function _tag_close_SELECT() |
|
| 5818 | - { |
|
| 5819 | - // position of the select |
|
| 5820 | - $x = $this->pdf->getX(); |
|
| 5821 | - $y = $this->pdf->getY(); |
|
| 5822 | - $f = 1.08 * $this->parsingCss->value['font-size']; |
|
| 5823 | - |
|
| 5824 | - // width |
|
| 5825 | - $w = $this->parsingCss->value['width']; if ( ! $w) $w = 50; |
|
| 5826 | - |
|
| 5827 | - // height (automatic) |
|
| 5828 | - $h = ($f * 1.07 * $this->_lstSelect['size'] + 1); |
|
| 5829 | - |
|
| 5830 | - $prop = $this->parsingCss->getFormStyle(); |
|
| 5831 | - |
|
| 5832 | - // multy select |
|
| 5833 | - if ($this->_lstSelect['multi']) { |
|
| 5834 | - $prop['multipleSelection'] = 'true'; |
|
| 5835 | - } |
|
| 5836 | - |
|
| 5837 | - |
|
| 5838 | - // single or multi select |
|
| 5839 | - if ($this->_lstSelect['size'] > 1) { |
|
| 5840 | - $this->pdf->ListBox($this->_lstSelect['name'], $w, $h, $this->_lstSelect['options'], $prop); |
|
| 5841 | - } else { |
|
| 5842 | - $this->pdf->ComboBox($this->_lstSelect['name'], $w, $h, $this->_lstSelect['options'], $prop); |
|
| 5843 | - } |
|
| 5844 | - |
|
| 5845 | - $this->_maxX = max($this->_maxX, $x + $w); |
|
| 5846 | - $this->_maxY = max($this->_maxY, $y + $h); |
|
| 5847 | - $this->_maxH = max($this->_maxH, $h); |
|
| 5848 | - $this->_maxE++; |
|
| 5849 | - $this->pdf->setX($x + $w); |
|
| 5850 | - |
|
| 5851 | - $this->parsingCss->load(); |
|
| 5852 | - $this->parsingCss->fontSet(); |
|
| 5853 | - |
|
| 5854 | - $this->_lstSelect = array(); |
|
| 5855 | - |
|
| 5856 | - return true; |
|
| 5857 | - } |
|
| 5858 | - |
|
| 5859 | - /** |
|
| 5860 | - * tag : TEXTAREA |
|
| 5861 | - * mode : OPEN |
|
| 5862 | - * |
|
| 5863 | - * @param array $param |
|
| 5864 | - * @return boolean |
|
| 5865 | - */ |
|
| 5866 | - protected function _tag_open_TEXTAREA($param) |
|
| 5867 | - { |
|
| 5868 | - if ( ! isset($param['name'])) { |
|
| 5869 | - $param['name'] = 'champs_pdf_'.(count($this->_lstField) + 1); |
|
| 5870 | - } |
|
| 5871 | - |
|
| 5872 | - $param['name'] = strtolower($param['name']); |
|
| 5873 | - |
|
| 5874 | - if (isset($this->_lstField[$param['name']])) { |
|
| 5875 | - $this->_lstField[$param['name']]++; |
|
| 5876 | - } else { |
|
| 5877 | - $this->_lstField[$param['name']] = 1; |
|
| 5878 | - } |
|
| 5879 | - |
|
| 5880 | - $this->parsingCss->save(); |
|
| 5881 | - $this->parsingCss->analyse('textarea', $param); |
|
| 5882 | - $this->parsingCss->setPosition(); |
|
| 5883 | - $this->parsingCss->fontSet(); |
|
| 5884 | - |
|
| 5885 | - $x = $this->pdf->getX(); |
|
| 5886 | - $y = $this->pdf->getY(); |
|
| 5887 | - $fx = 0.65 * $this->parsingCss->value['font-size']; |
|
| 5888 | - $fy = 1.08 * $this->parsingCss->value['font-size']; |
|
| 5889 | - |
|
| 5890 | - // extract the content the textarea : value |
|
| 5891 | - $level = $this->parsingHtml->getLevel($this->_parsePos); |
|
| 5892 | - $this->_parsePos += count($level); |
|
| 5893 | - |
|
| 5894 | - // automatic size, from cols and rows properties |
|
| 5895 | - $w = $fx * (isset($param['cols']) ? $param['cols'] : 22) + 1; |
|
| 5896 | - $h = $fy * 1.07 * (isset($param['rows']) ? $param['rows'] : 3) + 3; |
|
| 5897 | - |
|
| 5898 | - $prop = $this->parsingCss->getFormStyle(); |
|
| 5899 | - |
|
| 5900 | - $prop['multiline'] = true; |
|
| 5901 | - $prop['value'] = isset($level[0]['param']['txt']) ? $level[0]['param']['txt'] : ''; |
|
| 5902 | - |
|
| 5903 | - $this->pdf->TextField($param['name'], $w, $h, $prop, array(), $x, $y); |
|
| 5904 | - |
|
| 5905 | - $this->_maxX = max($this->_maxX, $x + $w); |
|
| 5906 | - $this->_maxY = max($this->_maxY, $y + $h); |
|
| 5907 | - $this->_maxH = max($this->_maxH, $h); |
|
| 5908 | - $this->_maxE++; |
|
| 5909 | - $this->pdf->setX($x + $w); |
|
| 5910 | - |
|
| 5911 | - return true; |
|
| 5912 | - } |
|
| 5913 | - |
|
| 5914 | - /** |
|
| 5915 | - * tag : TEXTAREA |
|
| 5916 | - * mode : CLOSE |
|
| 5917 | - * |
|
| 5918 | - * @return boolean |
|
| 5919 | - */ |
|
| 5920 | - protected function _tag_close_TEXTAREA() |
|
| 5921 | - { |
|
| 5922 | - $this->parsingCss->load(); |
|
| 5923 | - $this->parsingCss->fontSet(); |
|
| 5924 | - |
|
| 5925 | - return true; |
|
| 5926 | - } |
|
| 5927 | - |
|
| 5928 | - /** |
|
| 5929 | - * tag : INPUT |
|
| 5930 | - * mode : OPEN |
|
| 5931 | - * |
|
| 5932 | - * @param array $param |
|
| 5933 | - * @return boolean |
|
| 5934 | - */ |
|
| 5935 | - protected function _tag_open_INPUT($param) |
|
| 5936 | - { |
|
| 5937 | - if ( ! isset($param['name'])) $param['name'] = 'champs_pdf_'.(count($this->_lstField) + 1); |
|
| 5938 | - if ( ! isset($param['value'])) $param['value'] = ''; |
|
| 5939 | - if ( ! isset($param['type'])) $param['type'] = 'text'; |
|
| 5940 | - |
|
| 5941 | - $param['name'] = strtolower($param['name']); |
|
| 5942 | - $param['type'] = strtolower($param['type']); |
|
| 5943 | - |
|
| 5944 | - // the type must be valid |
|
| 5945 | - if ( ! in_array($param['type'], array('text', 'checkbox', 'radio', 'hidden', 'submit', 'reset', 'button'))) { |
|
| 5946 | - $param['type'] = 'text'; |
|
| 5947 | - } |
|
| 5948 | - |
|
| 5949 | - if (isset($this->_lstField[$param['name']])) { |
|
| 5950 | - $this->_lstField[$param['name']]++; |
|
| 5951 | - } else { |
|
| 5952 | - $this->_lstField[$param['name']] = 1; |
|
| 5953 | - } |
|
| 5954 | - |
|
| 5955 | - $this->parsingCss->save(); |
|
| 5956 | - $this->parsingCss->analyse('input', $param); |
|
| 5957 | - $this->parsingCss->setPosition(); |
|
| 5958 | - $this->parsingCss->fontSet(); |
|
| 5959 | - |
|
| 5960 | - $name = $param['name']; |
|
| 5961 | - |
|
| 5962 | - $x = $this->pdf->getX(); |
|
| 5963 | - $y = $this->pdf->getY(); |
|
| 5964 | - $f = 1.08 * $this->parsingCss->value['font-size']; |
|
| 5965 | - |
|
| 5966 | - $prop = $this->parsingCss->getFormStyle(); |
|
| 5967 | - |
|
| 5968 | - switch ($param['type']) |
|
| 5969 | - { |
|
| 5970 | - case 'checkbox': |
|
| 5971 | - $w = 3; |
|
| 5972 | - $h = $w; |
|
| 5973 | - if ($h < $f) $y += ($f - $h) * 0.5; |
|
| 5974 | - $checked = (isset($param['checked']) && $param['checked'] == 'checked'); |
|
| 5975 | - $this->pdf->CheckBox($name, $w, $checked, $prop, array(), ($param['value'] ? $param['value'] : 'Yes'), $x, $y); |
|
| 5976 | - break; |
|
| 5977 | - |
|
| 5978 | - case 'radio': |
|
| 5979 | - $w = 3; |
|
| 5980 | - $h = $w; |
|
| 5981 | - if ($h < $f) $y += ($f - $h) * 0.5; |
|
| 5982 | - $checked = (isset($param['checked']) && $param['checked'] == 'checked'); |
|
| 5983 | - $this->pdf->RadioButton($name, $w, $prop, array(), ($param['value'] ? $param['value'] : 'On'), $checked, $x, $y); |
|
| 5984 | - break; |
|
| 5985 | - |
|
| 5986 | - case 'hidden': |
|
| 5987 | - $w = 0; |
|
| 5988 | - $h = 0; |
|
| 5989 | - $prop['value'] = $param['value']; |
|
| 5990 | - $this->pdf->TextField($name, $w, $h, $prop, array(), $x, $y); |
|
| 5991 | - break; |
|
| 5992 | - |
|
| 5993 | - case 'text': |
|
| 5994 | - $w = $this->parsingCss->value['width']; if ( ! $w) $w = 40; |
|
| 5995 | - $h = $f * 1.3; |
|
| 5996 | - $prop['value'] = $param['value']; |
|
| 5997 | - $this->pdf->TextField($name, $w, $h, $prop, array(), $x, $y); |
|
| 5998 | - break; |
|
| 5999 | - |
|
| 6000 | - case 'submit': |
|
| 6001 | - $w = $this->parsingCss->value['width']; if ( ! $w) $w = 40; |
|
| 6002 | - $h = $this->parsingCss->value['height']; if ( ! $h) $h = $f * 1.3; |
|
| 6003 | - $action = array('S'=>'SubmitForm', 'F'=>$this->_isInForm, 'Flags'=>array('ExportFormat')); |
|
| 6004 | - $this->pdf->Button($name, $w, $h, $param['value'], $action, $prop, array(), $x, $y); |
|
| 6005 | - break; |
|
| 6006 | - |
|
| 6007 | - case 'reset': |
|
| 6008 | - $w = $this->parsingCss->value['width']; if ( ! $w) $w = 40; |
|
| 6009 | - $h = $this->parsingCss->value['height']; if ( ! $h) $h = $f * 1.3; |
|
| 6010 | - $action = array('S'=>'ResetForm'); |
|
| 6011 | - $this->pdf->Button($name, $w, $h, $param['value'], $action, $prop, array(), $x, $y); |
|
| 6012 | - break; |
|
| 6013 | - |
|
| 6014 | - case 'button': |
|
| 6015 | - $w = $this->parsingCss->value['width']; if ( ! $w) $w = 40; |
|
| 6016 | - $h = $this->parsingCss->value['height']; if ( ! $h) $h = $f * 1.3; |
|
| 6017 | - $action = isset($param['onclick']) ? $param['onclick'] : ''; |
|
| 6018 | - $this->pdf->Button($name, $w, $h, $param['value'], $action, $prop, array(), $x, $y); |
|
| 6019 | - break; |
|
| 6020 | - |
|
| 6021 | - default: |
|
| 6022 | - $w = 0; |
|
| 6023 | - $h = 0; |
|
| 6024 | - break; |
|
| 6025 | - } |
|
| 6026 | - |
|
| 6027 | - $this->_maxX = max($this->_maxX, $x + $w); |
|
| 6028 | - $this->_maxY = max($this->_maxY, $y + $h); |
|
| 6029 | - $this->_maxH = max($this->_maxH, $h); |
|
| 6030 | - $this->_maxE++; |
|
| 6031 | - $this->pdf->setX($x + $w); |
|
| 6032 | - |
|
| 6033 | - $this->parsingCss->load(); |
|
| 6034 | - $this->parsingCss->fontSet(); |
|
| 6035 | - |
|
| 6036 | - return true; |
|
| 6037 | - } |
|
| 6038 | - |
|
| 6039 | - /** |
|
| 6040 | - * tag : DRAW |
|
| 6041 | - * mode : OPEN |
|
| 6042 | - * |
|
| 6043 | - * @param array $param |
|
| 6044 | - * @return boolean |
|
| 6045 | - */ |
|
| 6046 | - protected function _tag_open_DRAW($param) |
|
| 6047 | - { |
|
| 6048 | - if ($this->_isForOneLine) { |
|
| 6049 | - return false; |
|
| 6050 | - } |
|
| 6051 | - if ($this->_debugActif) { |
|
| 6052 | - $this->_DEBUG_add('DRAW', true); |
|
| 6053 | - } |
|
| 6054 | - |
|
| 6055 | - $this->parsingCss->save(); |
|
| 6056 | - $this->parsingCss->analyse('draw', $param); |
|
| 6057 | - $this->parsingCss->fontSet(); |
|
| 6058 | - |
|
| 6059 | - $alignObject = null; |
|
| 6060 | - if ($this->parsingCss->value['margin-auto']) { |
|
| 6061 | - $alignObject = 'center'; |
|
| 6062 | - } |
|
| 6063 | - |
|
| 6064 | - $overW = $this->parsingCss->value['width']; |
|
| 6065 | - $overH = $this->parsingCss->value['height']; |
|
| 6066 | - $this->parsingCss->value['old_maxX'] = $this->_maxX; |
|
| 6067 | - $this->parsingCss->value['old_maxY'] = $this->_maxY; |
|
| 6068 | - $this->parsingCss->value['old_maxH'] = $this->_maxH; |
|
| 6069 | - |
|
| 6070 | - $w = $this->parsingCss->value['width']; |
|
| 6071 | - $h = $this->parsingCss->value['height']; |
|
| 6072 | - |
|
| 6073 | - if ( ! $this->parsingCss->value['position']) { |
|
| 6074 | - if ( |
|
| 6075 | - $w < ($this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin()) && |
|
| 6076 | - $this->pdf->getX() + $w >= ($this->pdf->getW() - $this->pdf->getrMargin()) |
|
| 6077 | - ) |
|
| 6078 | - $this->_tag_open_BR(array()); |
|
| 6079 | - |
|
| 6080 | - if ( |
|
| 6081 | - ($h < ($this->pdf->getH() - $this->pdf->gettMargin() - $this->pdf->getbMargin())) && |
|
| 6082 | - ($this->pdf->getY() + $h >= ($this->pdf->getH() - $this->pdf->getbMargin())) && |
|
| 6083 | - ! $this->_isInOverflow |
|
| 6084 | - ) |
|
| 6085 | - $this->_setNewPage(); |
|
| 6086 | - |
|
| 6087 | - $old = $this->parsingCss->getOldValues(); |
|
| 6088 | - $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); |
|
| 6089 | - |
|
| 6090 | - if ($parentWidth > $w) { |
|
| 6091 | - if ($alignObject == 'center') $this->pdf->setX($this->pdf->getX() + ($parentWidth - $w) * 0.5); |
|
| 6092 | - else if ($alignObject == 'right') $this->pdf->setX($this->pdf->getX() + $parentWidth - $w); |
|
| 6093 | - } |
|
| 6094 | - |
|
| 6095 | - $this->parsingCss->setPosition(); |
|
| 6096 | - } else { |
|
| 6097 | - $old = $this->parsingCss->getOldValues(); |
|
| 6098 | - $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); |
|
| 6099 | - |
|
| 6100 | - if ($parentWidth > $w) { |
|
| 6101 | - if ($alignObject == 'center') $this->pdf->setX($this->pdf->getX() + ($parentWidth - $w) * 0.5); |
|
| 6102 | - else if ($alignObject == 'right') $this->pdf->setX($this->pdf->getX() + $parentWidth - $w); |
|
| 6103 | - } |
|
| 6104 | - |
|
| 6105 | - $this->parsingCss->setPosition(); |
|
| 6106 | - $this->_saveMax(); |
|
| 6107 | - $this->_maxX = 0; |
|
| 6108 | - $this->_maxY = 0; |
|
| 6109 | - $this->_maxH = 0; |
|
| 6110 | - $this->_maxE = 0; |
|
| 6111 | - } |
|
| 6112 | - |
|
| 6113 | - $this->_drawRectangle( |
|
| 6114 | - $this->parsingCss->value['x'], |
|
| 6115 | - $this->parsingCss->value['y'], |
|
| 6116 | - $this->parsingCss->value['width'], |
|
| 6117 | - $this->parsingCss->value['height'], |
|
| 6118 | - $this->parsingCss->value['border'], |
|
| 6119 | - $this->parsingCss->value['padding'], |
|
| 6120 | - 0, |
|
| 6121 | - $this->parsingCss->value['background'] |
|
| 6122 | - ); |
|
| 6123 | - |
|
| 6124 | - $marge = array(); |
|
| 6125 | - $marge['l'] = $this->parsingCss->value['border']['l']['width']; |
|
| 6126 | - $marge['r'] = $this->parsingCss->value['border']['r']['width']; |
|
| 6127 | - $marge['t'] = $this->parsingCss->value['border']['t']['width']; |
|
| 6128 | - $marge['b'] = $this->parsingCss->value['border']['b']['width']; |
|
| 6129 | - |
|
| 6130 | - $this->parsingCss->value['width'] -= $marge['l'] + $marge['r']; |
|
| 6131 | - $this->parsingCss->value['height'] -= $marge['t'] + $marge['b']; |
|
| 6132 | - |
|
| 6133 | - $overW -= $marge['l'] + $marge['r']; |
|
| 6134 | - $overH -= $marge['t'] + $marge['b']; |
|
| 6135 | - |
|
| 6136 | - // clipping to draw only in the size opf the DRAW tag |
|
| 6137 | - $this->pdf->clippingPathStart( |
|
| 6138 | - $this->parsingCss->value['x'] + $marge['l'], |
|
| 6139 | - $this->parsingCss->value['y'] + $marge['t'], |
|
| 6140 | - $this->parsingCss->value['width'], |
|
| 6141 | - $this->parsingCss->value['height'] |
|
| 6142 | - ); |
|
| 6143 | - |
|
| 6144 | - // left and right of the DRAW tag |
|
| 6145 | - $mL = $this->parsingCss->value['x'] + $marge['l']; |
|
| 6146 | - $mR = $this->pdf->getW() - $mL - $overW; |
|
| 6147 | - |
|
| 6148 | - // position of the DRAW tag |
|
| 6149 | - $x = $this->parsingCss->value['x'] + $marge['l']; |
|
| 6150 | - $y = $this->parsingCss->value['y'] + $marge['t']; |
|
| 6151 | - |
|
| 6152 | - // prepare the drawing area |
|
| 6153 | - $this->_saveMargin($mL, 0, $mR); |
|
| 6154 | - $this->pdf->setXY($x, $y); |
|
| 6155 | - |
|
| 6156 | - // we are in a draw tag |
|
| 6157 | - $this->_isInDraw = array( |
|
| 6158 | - 'x' => $x, |
|
| 6159 | - 'y' => $y, |
|
| 6160 | - 'w' => $overW, |
|
| 6161 | - 'h' => $overH, |
|
| 6162 | - ); |
|
| 6163 | - |
|
| 6164 | - // init the translate matrix : (0,0) => ($x, $y) |
|
| 6165 | - $this->pdf->doTransform(array(1, 0, 0, 1, $x, $y)); |
|
| 6166 | - $this->pdf->SetAlpha(1.); |
|
| 6167 | - return true; |
|
| 6168 | - } |
|
| 6169 | - |
|
| 6170 | - /** |
|
| 6171 | - * tag : DRAW |
|
| 6172 | - * mode : CLOSE |
|
| 6173 | - * |
|
| 6174 | - * @param array $param |
|
| 6175 | - * @return boolean |
|
| 6176 | - */ |
|
| 6177 | - protected function _tag_close_DRAW($param) |
|
| 6178 | - { |
|
| 6179 | - if ($this->_isForOneLine) { |
|
| 6180 | - return false; |
|
| 6181 | - } |
|
| 6182 | - |
|
| 6183 | - $this->pdf->SetAlpha(1.); |
|
| 6184 | - $this->pdf->undoTransform(); |
|
| 6185 | - $this->pdf->clippingPathStop(); |
|
| 6186 | - |
|
| 6187 | - $this->_maxX = $this->parsingCss->value['old_maxX']; |
|
| 6188 | - $this->_maxY = $this->parsingCss->value['old_maxY']; |
|
| 6189 | - $this->_maxH = $this->parsingCss->value['old_maxH']; |
|
| 6190 | - |
|
| 6191 | - $marge = array(); |
|
| 6192 | - $marge['l'] = $this->parsingCss->value['border']['l']['width']; |
|
| 6193 | - $marge['r'] = $this->parsingCss->value['border']['r']['width']; |
|
| 6194 | - $marge['t'] = $this->parsingCss->value['border']['t']['width']; |
|
| 6195 | - $marge['b'] = $this->parsingCss->value['border']['b']['width']; |
|
| 6196 | - |
|
| 6197 | - $x = $this->parsingCss->value['x']; |
|
| 6198 | - $y = $this->parsingCss->value['y']; |
|
| 6199 | - $w = $this->parsingCss->value['width'] + $marge['l'] + $marge['r']; |
|
| 6200 | - $h = $this->parsingCss->value['height'] + $marge['t'] + $marge['b']; |
|
| 6201 | - |
|
| 6202 | - if ($this->parsingCss->value['position'] != 'absolute') { |
|
| 6203 | - $this->pdf->setXY($x + $w, $y); |
|
| 6204 | - |
|
| 6205 | - $this->_maxX = max($this->_maxX, $x + $w); |
|
| 6206 | - $this->_maxY = max($this->_maxY, $y + $h); |
|
| 6207 | - $this->_maxH = max($this->_maxH, $h); |
|
| 6208 | - $this->_maxE++; |
|
| 6209 | - } else { |
|
| 6210 | - // position |
|
| 6211 | - $this->pdf->setXY($this->parsingCss->value['xc'], $this->parsingCss->value['yc']); |
|
| 6212 | - |
|
| 6213 | - $this->_loadMax(); |
|
| 6214 | - } |
|
| 6215 | - |
|
| 6216 | - $block = ($this->parsingCss->value['display'] != 'inline' && $this->parsingCss->value['position'] != 'absolute'); |
|
| 6217 | - |
|
| 6218 | - $this->parsingCss->load(); |
|
| 6219 | - $this->parsingCss->fontSet(); |
|
| 6220 | - $this->_loadMargin(); |
|
| 6221 | - |
|
| 6222 | - if ($block) { |
|
| 6223 | - $this->_tag_open_BR(array()); |
|
| 6224 | - } |
|
| 6225 | - if ($this->_debugActif) { |
|
| 6226 | - $this->_DEBUG_add('DRAW', false); |
|
| 6227 | - } |
|
| 6228 | - |
|
| 6229 | - $this->_isInDraw = null; |
|
| 6230 | - |
|
| 6231 | - return true; |
|
| 6232 | - } |
|
| 6233 | - |
|
| 6234 | - /** |
|
| 6235 | - * tag : LINE |
|
| 6236 | - * mode : OPEN |
|
| 6237 | - * |
|
| 6238 | - * @param array $param |
|
| 6239 | - * @return boolean|null |
|
| 6240 | - */ |
|
| 6241 | - protected function _tag_open_LINE($param) |
|
| 6242 | - { |
|
| 6243 | - if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'LINE'); |
|
| 6244 | - |
|
| 6245 | - $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6246 | - $this->parsingCss->save(); |
|
| 6247 | - $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6248 | - $styles['fill'] = null; |
|
| 6249 | - $style = $this->pdf->svgSetStyle($styles); |
|
| 6250 | - |
|
| 6251 | - $x1 = isset($param['x1']) ? $this->parsingCss->ConvertToMM($param['x1'], $this->_isInDraw['w']) : 0.; |
|
| 6252 | - $y1 = isset($param['y1']) ? $this->parsingCss->ConvertToMM($param['y1'], $this->_isInDraw['h']) : 0.; |
|
| 6253 | - $x2 = isset($param['x2']) ? $this->parsingCss->ConvertToMM($param['x2'], $this->_isInDraw['w']) : 0.; |
|
| 6254 | - $y2 = isset($param['y2']) ? $this->parsingCss->ConvertToMM($param['y2'], $this->_isInDraw['h']) : 0.; |
|
| 6255 | - $this->pdf->svgLine($x1, $y1, $x2, $y2); |
|
| 6256 | - |
|
| 6257 | - $this->pdf->undoTransform(); |
|
| 6258 | - $this->parsingCss->load(); |
|
| 6259 | - } |
|
| 6260 | - |
|
| 6261 | - /** |
|
| 6262 | - * tag : RECT |
|
| 6263 | - * mode : OPEN |
|
| 6264 | - * |
|
| 6265 | - * @param array $param |
|
| 6266 | - * @return boolean|null |
|
| 6267 | - */ |
|
| 6268 | - protected function _tag_open_RECT($param) |
|
| 6269 | - { |
|
| 6270 | - if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'RECT'); |
|
| 6271 | - |
|
| 6272 | - $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6273 | - $this->parsingCss->save(); |
|
| 6274 | - $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6275 | - $style = $this->pdf->svgSetStyle($styles); |
|
| 6276 | - |
|
| 6277 | - $x = isset($param['x']) ? $this->parsingCss->ConvertToMM($param['x'], $this->_isInDraw['w']) : 0.; |
|
| 6278 | - $y = isset($param['y']) ? $this->parsingCss->ConvertToMM($param['y'], $this->_isInDraw['h']) : 0.; |
|
| 6279 | - $w = isset($param['w']) ? $this->parsingCss->ConvertToMM($param['w'], $this->_isInDraw['w']) : 0.; |
|
| 6280 | - $h = isset($param['h']) ? $this->parsingCss->ConvertToMM($param['h'], $this->_isInDraw['h']) : 0.; |
|
| 6281 | - |
|
| 6282 | - $this->pdf->svgRect($x, $y, $w, $h, $style); |
|
| 6283 | - |
|
| 6284 | - $this->pdf->undoTransform(); |
|
| 6285 | - $this->parsingCss->load(); |
|
| 6286 | - } |
|
| 6287 | - |
|
| 6288 | - /** |
|
| 6289 | - * tag : CIRCLE |
|
| 6290 | - * mode : OPEN |
|
| 6291 | - * |
|
| 6292 | - * @param array $param |
|
| 6293 | - * @return boolean|null |
|
| 6294 | - */ |
|
| 6295 | - protected function _tag_open_CIRCLE($param) |
|
| 6296 | - { |
|
| 6297 | - if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'CIRCLE'); |
|
| 6298 | - |
|
| 6299 | - $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6300 | - $this->parsingCss->save(); |
|
| 6301 | - $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6302 | - $style = $this->pdf->svgSetStyle($styles); |
|
| 6303 | - |
|
| 6304 | - $cx = isset($param['cx']) ? $this->parsingCss->ConvertToMM($param['cx'], $this->_isInDraw['w']) : 0.; |
|
| 6305 | - $cy = isset($param['cy']) ? $this->parsingCss->ConvertToMM($param['cy'], $this->_isInDraw['h']) : 0.; |
|
| 6306 | - $r = isset($param['r']) ? $this->parsingCss->ConvertToMM($param['r'], $this->_isInDraw['w']) : 0.; |
|
| 6307 | - $this->pdf->svgEllipse($cx, $cy, $r, $r, $style); |
|
| 6308 | - |
|
| 6309 | - $this->pdf->undoTransform(); |
|
| 6310 | - $this->parsingCss->load(); |
|
| 6311 | - } |
|
| 6312 | - |
|
| 6313 | - /** |
|
| 6314 | - * tag : ELLIPSE |
|
| 6315 | - * mode : OPEN |
|
| 6316 | - * |
|
| 6317 | - * @param array $param |
|
| 6318 | - * @return boolean|null |
|
| 6319 | - */ |
|
| 6320 | - protected function _tag_open_ELLIPSE($param) |
|
| 6321 | - { |
|
| 6322 | - if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'ELLIPSE'); |
|
| 6323 | - |
|
| 6324 | - $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6325 | - $this->parsingCss->save(); |
|
| 6326 | - $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6327 | - $style = $this->pdf->svgSetStyle($styles); |
|
| 6328 | - |
|
| 6329 | - $cx = isset($param['cx']) ? $this->parsingCss->ConvertToMM($param['cx'], $this->_isInDraw['w']) : 0.; |
|
| 6330 | - $cy = isset($param['cy']) ? $this->parsingCss->ConvertToMM($param['cy'], $this->_isInDraw['h']) : 0.; |
|
| 6331 | - $rx = isset($param['ry']) ? $this->parsingCss->ConvertToMM($param['rx'], $this->_isInDraw['w']) : 0.; |
|
| 6332 | - $ry = isset($param['rx']) ? $this->parsingCss->ConvertToMM($param['ry'], $this->_isInDraw['h']) : 0.; |
|
| 6333 | - $this->pdf->svgEllipse($cx, $cy, $rx, $ry, $style); |
|
| 6334 | - |
|
| 6335 | - $this->pdf->undoTransform(); |
|
| 6336 | - $this->parsingCss->load(); |
|
| 6337 | - } |
|
| 6338 | - |
|
| 6339 | - |
|
| 6340 | - /** |
|
| 6341 | - * tag : POLYLINE |
|
| 6342 | - * mode : OPEN |
|
| 6343 | - * |
|
| 6344 | - * @param array $param |
|
| 6345 | - * @return boolean|null |
|
| 6346 | - */ |
|
| 6347 | - protected function _tag_open_POLYLINE($param) |
|
| 6348 | - { |
|
| 6349 | - if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'POLYGON'); |
|
| 6350 | - |
|
| 6351 | - $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6352 | - $this->parsingCss->save(); |
|
| 6353 | - $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6354 | - $style = $this->pdf->svgSetStyle($styles); |
|
| 6355 | - |
|
| 6356 | - $path = isset($param['points']) ? $param['points'] : null; |
|
| 6357 | - if ($path) { |
|
| 6358 | - $path = str_replace(',', ' ', $path); |
|
| 6359 | - $path = preg_replace('/[\s]+/', ' ', trim($path)); |
|
| 6360 | - |
|
| 6361 | - // prepare the path |
|
| 6362 | - $path = explode(' ', $path); |
|
| 6363 | - foreach ($path as $k => $v) { |
|
| 6364 | - $path[$k] = trim($v); |
|
| 6365 | - if ($path[$k] === '') unset($path[$k]); |
|
| 6366 | - } |
|
| 6367 | - $path = array_values($path); |
|
| 6368 | - |
|
| 6369 | - $actions = array(); |
|
| 6370 | - for ($k = 0; $k < count($path); $k += 2) { |
|
| 6371 | - $actions[] = array( |
|
| 6372 | - ($k ? 'L' : 'M'), |
|
| 6373 | - $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']), |
|
| 6374 | - $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']) |
|
| 6375 | - ); |
|
| 6376 | - } |
|
| 6377 | - |
|
| 6378 | - // drawing |
|
| 6379 | - $this->pdf->svgPolygone($actions, $style); |
|
| 6380 | - } |
|
| 6381 | - |
|
| 6382 | - $this->pdf->undoTransform(); |
|
| 6383 | - $this->parsingCss->load(); |
|
| 6384 | - } |
|
| 6385 | - |
|
| 6386 | - /** |
|
| 6387 | - * tag : POLYGON |
|
| 6388 | - * mode : OPEN |
|
| 6389 | - * |
|
| 6390 | - * @param array $param |
|
| 6391 | - * @return boolean|null |
|
| 6392 | - */ |
|
| 6393 | - protected function _tag_open_POLYGON($param) |
|
| 6394 | - { |
|
| 6395 | - if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'POLYGON'); |
|
| 6396 | - |
|
| 6397 | - $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6398 | - $this->parsingCss->save(); |
|
| 6399 | - $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6400 | - $style = $this->pdf->svgSetStyle($styles); |
|
| 6401 | - |
|
| 6402 | - $path = (isset($param['points']) ? $param['points'] : null); |
|
| 6403 | - if ($path) { |
|
| 6404 | - $path = str_replace(',', ' ', $path); |
|
| 6405 | - $path = preg_replace('/[\s]+/', ' ', trim($path)); |
|
| 6406 | - |
|
| 6407 | - // prepare the path |
|
| 6408 | - $path = explode(' ', $path); |
|
| 6409 | - foreach ($path as $k => $v) { |
|
| 6410 | - $path[$k] = trim($v); |
|
| 6411 | - if ($path[$k] === '') unset($path[$k]); |
|
| 6412 | - } |
|
| 6413 | - $path = array_values($path); |
|
| 6414 | - |
|
| 6415 | - $actions = array(); |
|
| 6416 | - for ($k = 0; $k < count($path); $k += 2) { |
|
| 6417 | - $actions[] = array( |
|
| 6418 | - ($k ? 'L' : 'M'), |
|
| 6419 | - $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']), |
|
| 6420 | - $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']) |
|
| 6421 | - ); |
|
| 6422 | - } |
|
| 6423 | - $actions[] = array('z'); |
|
| 6424 | - |
|
| 6425 | - // drawing |
|
| 6426 | - $this->pdf->svgPolygone($actions, $style); |
|
| 6427 | - } |
|
| 6428 | - |
|
| 6429 | - $this->pdf->undoTransform(); |
|
| 6430 | - $this->parsingCss->load(); |
|
| 6431 | - } |
|
| 6432 | - |
|
| 6433 | - /** |
|
| 6434 | - * tag : PATH |
|
| 6435 | - * mode : OPEN |
|
| 6436 | - * |
|
| 6437 | - * @param array $param |
|
| 6438 | - * @return boolean|null |
|
| 6439 | - */ |
|
| 6440 | - protected function _tag_open_PATH($param) |
|
| 6441 | - { |
|
| 6442 | - if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'PATH'); |
|
| 6443 | - |
|
| 6444 | - $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6445 | - $this->parsingCss->save(); |
|
| 6446 | - $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6447 | - $style = $this->pdf->svgSetStyle($styles); |
|
| 6448 | - |
|
| 6449 | - $path = isset($param['d']) ? $param['d'] : null; |
|
| 6450 | - |
|
| 6451 | - if ($path) { |
|
| 6452 | - // prepare the path |
|
| 6453 | - $path = str_replace(',', ' ', $path); |
|
| 6454 | - $path = preg_replace('/([a-zA-Z])([0-9\.\-])/', '$1 $2', $path); |
|
| 6455 | - $path = preg_replace('/([0-9\.])([a-zA-Z])/', '$1 $2', $path); |
|
| 6456 | - $path = preg_replace('/[\s]+/', ' ', trim($path)); |
|
| 6457 | - $path = preg_replace('/ ([a-z]{2})/', '$1', $path); |
|
| 6458 | - |
|
| 6459 | - $path = explode(' ', $path); |
|
| 6460 | - foreach ($path as $k => $v) { |
|
| 6461 | - $path[$k] = trim($v); |
|
| 6462 | - if ($path[$k] === '') unset($path[$k]); |
|
| 6463 | - } |
|
| 6464 | - $path = array_values($path); |
|
| 6465 | - |
|
| 6466 | - // read each actions in the path |
|
| 6467 | - $actions = array(); |
|
| 6468 | - $action = array(); |
|
| 6469 | - $lastAction = null; // last action found |
|
| 6470 | - for ($k = 0; $k < count($path); true) { |
|
| 6471 | - |
|
| 6472 | - // for this actions, we can not have multi coordonate |
|
| 6473 | - if (in_array($lastAction, array('z', 'Z'))) { |
|
| 6474 | - $lastAction = null; |
|
| 6475 | - } |
|
| 6476 | - |
|
| 6477 | - // read the new action (forcing if no action before) |
|
| 6478 | - if (preg_match('/^[a-z]+$/i', $path[$k]) || $lastAction === null) { |
|
| 6479 | - $lastAction = $path[$k]; |
|
| 6480 | - $k++; |
|
| 6481 | - } |
|
| 6482 | - |
|
| 6483 | - // current action |
|
| 6484 | - $action = array(); |
|
| 6485 | - $action[] = $lastAction; |
|
| 6486 | - switch ($lastAction) |
|
| 6487 | - { |
|
| 6488 | - case 'C': |
|
| 6489 | - case 'c': |
|
| 6490 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // x1 |
|
| 6491 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']); // y1 |
|
| 6492 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 2], $this->_isInDraw['w']); // x2 |
|
| 6493 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 3], $this->_isInDraw['h']); // y2 |
|
| 6494 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 4], $this->_isInDraw['w']); // x |
|
| 6495 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 5], $this->_isInDraw['h']); // y |
|
| 6496 | - $k += 6; |
|
| 6497 | - break; |
|
| 6498 | - |
|
| 6499 | - case 'Q': |
|
| 6500 | - case 'S': |
|
| 6501 | - case 'q': |
|
| 6502 | - case 's': |
|
| 6503 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // x2 |
|
| 6504 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']); // y2 |
|
| 6505 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 2], $this->_isInDraw['w']); // x |
|
| 6506 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 3], $this->_isInDraw['h']); // y |
|
| 6507 | - $k += 4; |
|
| 6508 | - break; |
|
| 6509 | - |
|
| 6510 | - case 'A': |
|
| 6511 | - case 'a': |
|
| 6512 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // rx |
|
| 6513 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']); // ry |
|
| 6514 | - $action[] = 1. * $path[$k + 2]; // angle de deviation de l'axe X |
|
| 6515 | - $action[] = ($path[$k + 3] == '1') ? 1 : 0; // large-arc-flag |
|
| 6516 | - $action[] = ($path[$k + 4] == '1') ? 1 : 0; // sweep-flag |
|
| 6517 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 5], $this->_isInDraw['w']); // x |
|
| 6518 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 6], $this->_isInDraw['h']); // y |
|
| 6519 | - $k += 7; |
|
| 6520 | - break; |
|
| 6521 | - |
|
| 6522 | - case 'M': |
|
| 6523 | - case 'L': |
|
| 6524 | - case 'T': |
|
| 6525 | - case 'm': |
|
| 6526 | - case 'l': |
|
| 6527 | - case 't': |
|
| 6528 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // x |
|
| 6529 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']); // y |
|
| 6530 | - $k += 2; |
|
| 6531 | - break; |
|
| 6532 | - |
|
| 6533 | - case 'H': |
|
| 6534 | - case 'h': |
|
| 6535 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // x |
|
| 6536 | - $k += 1; |
|
| 6537 | - break; |
|
| 6538 | - |
|
| 6539 | - case 'V': |
|
| 6540 | - case 'v': |
|
| 6541 | - $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['h']); // y |
|
| 6542 | - $k += 1; |
|
| 6543 | - break; |
|
| 6544 | - |
|
| 6545 | - case 'z': |
|
| 6546 | - case 'Z': |
|
| 6547 | - default: |
|
| 6548 | - break; |
|
| 6549 | - } |
|
| 6550 | - // add the action |
|
| 6551 | - $actions[] = $action; |
|
| 6552 | - } |
|
| 6553 | - |
|
| 6554 | - // drawing |
|
| 6555 | - $this->pdf->svgPolygone($actions, $style); |
|
| 6556 | - } |
|
| 6557 | - |
|
| 6558 | - $this->pdf->undoTransform(); |
|
| 6559 | - $this->parsingCss->load(); |
|
| 6560 | - } |
|
| 6561 | - |
|
| 6562 | - /** |
|
| 6563 | - * tag : G |
|
| 6564 | - * mode : OPEN |
|
| 6565 | - * |
|
| 6566 | - * @param array $param |
|
| 6567 | - * @return boolean|null |
|
| 6568 | - */ |
|
| 6569 | - protected function _tag_open_G($param) |
|
| 6570 | - { |
|
| 6571 | - if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'G'); |
|
| 6572 | - |
|
| 6573 | - $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6574 | - $this->parsingCss->save(); |
|
| 6575 | - $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6576 | - $style = $this->pdf->svgSetStyle($styles); |
|
| 6577 | - } |
|
| 6578 | - |
|
| 6579 | - /** |
|
| 6580 | - * tag : G |
|
| 6581 | - * mode : CLOSE |
|
| 6582 | - * |
|
| 6583 | - * @param array $param |
|
| 6584 | - * @return boolean|null |
|
| 6585 | - */ |
|
| 6586 | - protected function _tag_close_G($param) |
|
| 6587 | - { |
|
| 6588 | - $this->pdf->undoTransform(); |
|
| 6589 | - $this->parsingCss->load(); |
|
| 6590 | - } |
|
| 6591 | - |
|
| 6592 | - /** |
|
| 6593 | - * new page for the automatic Index, does not use thie method. Only HTML2PDF_myPdf could use it !!!! |
|
| 6594 | - * |
|
| 6595 | - * @param &int $page |
|
| 6596 | - * @return integer $oldPage |
|
| 6597 | - */ |
|
| 6598 | - public function _INDEX_NewPage(&$page) |
|
| 6599 | - { |
|
| 6600 | - if ($page) { |
|
| 6601 | - $oldPage = $this->pdf->getPage(); |
|
| 6602 | - $this->pdf->setPage($page); |
|
| 6603 | - $this->pdf->setXY($this->_margeLeft, $this->_margeTop); |
|
| 6604 | - $this->_maxH = 0; |
|
| 6605 | - $page++; |
|
| 6606 | - return $oldPage; |
|
| 6607 | - } else { |
|
| 6608 | - $this->_setNewPage(); |
|
| 6609 | - return null; |
|
| 6610 | - } |
|
| 6611 | - } |
|
| 6612 | - |
|
| 6613 | - } |
|
| 504 | + exit; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * set the default margins of the page |
|
| 509 | + * |
|
| 510 | + * @access protected |
|
| 511 | + * @param int $left (mm, left margin) |
|
| 512 | + * @param int $top (mm, top margin) |
|
| 513 | + * @param int $right (mm, right margin, if null => left=right) |
|
| 514 | + * @param int $bottom (mm, bottom margin, if null => bottom=8mm) |
|
| 515 | + */ |
|
| 516 | + protected function _setDefaultMargins($left, $top, $right = null, $bottom = null) |
|
| 517 | + { |
|
| 518 | + if ($right === null) $right = $left; |
|
| 519 | + if ($bottom === null) $bottom = 8; |
|
| 520 | + |
|
| 521 | + $this->_defaultLeft = $this->parsingCss->ConvertToMM($left.'mm'); |
|
| 522 | + $this->_defaultTop = $this->parsingCss->ConvertToMM($top.'mm'); |
|
| 523 | + $this->_defaultRight = $this->parsingCss->ConvertToMM($right.'mm'); |
|
| 524 | + $this->_defaultBottom = $this->parsingCss->ConvertToMM($bottom.'mm'); |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * create a new page |
|
| 529 | + * |
|
| 530 | + * @access protected |
|
| 531 | + * @param mixed $format |
|
| 532 | + * @param string $orientation |
|
| 533 | + * @param array $background background information |
|
| 534 | + * @param integer $curr real position in the html parseur (if break line in the write of a text) |
|
| 535 | + * @param boolean $resetPageNumber |
|
| 536 | + */ |
|
| 537 | + protected function _setNewPage($format = null, $orientation = '', $background = null, $curr = null, $resetPageNumber = false) |
|
| 538 | + { |
|
| 539 | + $this->_firstPage = false; |
|
| 540 | + |
|
| 541 | + $this->_format = $format ? $format : $this->_format; |
|
| 542 | + $this->_orientation = $orientation ? $orientation : $this->_orientation; |
|
| 543 | + $this->_background = $background !== null ? $background : $this->_background; |
|
| 544 | + $this->_maxY = 0; |
|
| 545 | + $this->_maxX = 0; |
|
| 546 | + $this->_maxH = 0; |
|
| 547 | + $this->_maxE = 0; |
|
| 548 | + |
|
| 549 | + $this->pdf->SetMargins($this->_defaultLeft, $this->_defaultTop, $this->_defaultRight); |
|
| 550 | + |
|
| 551 | + if ($resetPageNumber) { |
|
| 552 | + $this->pdf->startPageGroup(); |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + $this->pdf->AddPage($this->_orientation, $this->_format); |
|
| 556 | + |
|
| 557 | + if ($resetPageNumber) { |
|
| 558 | + $this->pdf->myStartPageGroup(); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + $this->_page++; |
|
| 562 | + |
|
| 563 | + if ( ! $this->_subPart && ! $this->_isSubPart) { |
|
| 564 | + if (is_array($this->_background)) { |
|
| 565 | + if (isset($this->_background['color']) && $this->_background['color']) { |
|
| 566 | + $this->pdf->setFillColorArray($this->_background['color']); |
|
| 567 | + $this->pdf->Rect(0, 0, $this->pdf->getW(), $this->pdf->getH(), 'F'); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + if (isset($this->_background['img']) && $this->_background['img']) { |
|
| 571 | + $this->pdf->Image($this->_background['img'], $this->_background['posX'], $this->_background['posY'], $this->_background['width']); |
|
| 572 | + } |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + $this->_setPageHeader(); |
|
| 576 | + $this->_setPageFooter(); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + $this->_setMargins(); |
|
| 580 | + $this->pdf->setY($this->_margeTop); |
|
| 581 | + |
|
| 582 | + $this->_setNewPositionForNewLine($curr); |
|
| 583 | + $this->_maxH = 0; |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * set the real margin, using the default margins and the page margins |
|
| 588 | + * |
|
| 589 | + * @access protected |
|
| 590 | + */ |
|
| 591 | + protected function _setMargins() |
|
| 592 | + { |
|
| 593 | + // prepare the margins |
|
| 594 | + $this->_margeLeft = $this->_defaultLeft + (isset($this->_background['left']) ? $this->_background['left'] : 0); |
|
| 595 | + $this->_margeRight = $this->_defaultRight + (isset($this->_background['right']) ? $this->_background['right'] : 0); |
|
| 596 | + $this->_margeTop = $this->_defaultTop + (isset($this->_background['top']) ? $this->_background['top'] : 0); |
|
| 597 | + $this->_margeBottom = $this->_defaultBottom + (isset($this->_background['bottom']) ? $this->_background['bottom'] : 0); |
|
| 598 | + |
|
| 599 | + // set the PDF margins |
|
| 600 | + $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight); |
|
| 601 | + $this->pdf->SetAutoPageBreak(false, $this->_margeBottom); |
|
| 602 | + |
|
| 603 | + // set the float Margins |
|
| 604 | + $this->_pageMarges = array(); |
|
| 605 | + if ($this->_isInParagraph !== false) { |
|
| 606 | + $this->_pageMarges[floor($this->_margeTop * 100)] = array($this->_isInParagraph[0], $this->pdf->getW() - $this->_isInParagraph[1]); |
|
| 607 | + } else { |
|
| 608 | + $this->_pageMarges[floor($this->_margeTop * 100)] = array($this->_margeLeft, $this->pdf->getW() - $this->_margeRight); |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + /** |
|
| 613 | + * add a debug step |
|
| 614 | + * |
|
| 615 | + * @access protected |
|
| 616 | + * @param string $name step name |
|
| 617 | + * @param boolean $level (true=up, false=down, null=nothing to do) |
|
| 618 | + * @return $this |
|
| 619 | + */ |
|
| 620 | + protected function _DEBUG_add($name, $level = null) |
|
| 621 | + { |
|
| 622 | + // if true : UP |
|
| 623 | + if ($level === true) $this->_debugLevel++; |
|
| 624 | + |
|
| 625 | + $name = str_repeat(' ', $this->_debugLevel).$name.($level === true ? ' Begin' : ($level === false ? ' End' : '')); |
|
| 626 | + $time = microtime(true); |
|
| 627 | + $usage = ($this->_debugOkUsage ? memory_get_usage() : 0); |
|
| 628 | + $peak = ($this->_debugOkPeak ? memory_get_peak_usage() : 0); |
|
| 629 | + |
|
| 630 | + $this->_DEBUG_stepline( |
|
| 631 | + $name, |
|
| 632 | + number_format(($time - $this->_debugStartTime) * 1000, 1, '.', ' ').' ms', |
|
| 633 | + number_format(($time - $this->_debugLastTime) * 1000, 1, '.', ' ').' ms', |
|
| 634 | + number_format($usage / 1024, 1, '.', ' ').' Ko', |
|
| 635 | + number_format($peak / 1024, 1, '.', ' ').' Ko' |
|
| 636 | + ); |
|
| 637 | + |
|
| 638 | + $this->_debugLastTime = $time; |
|
| 639 | + |
|
| 640 | + // it false : DOWN |
|
| 641 | + if ($level === false) $this->_debugLevel--; |
|
| 642 | + |
|
| 643 | + return $this; |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * display a debug line |
|
| 648 | + * |
|
| 649 | + * |
|
| 650 | + * @access protected |
|
| 651 | + * @param string $name |
|
| 652 | + * @param string $timeTotal |
|
| 653 | + * @param string $timeStep |
|
| 654 | + * @param string $memoryUsage |
|
| 655 | + * @param string $memoryPeak |
|
| 656 | + */ |
|
| 657 | + protected function _DEBUG_stepline($name, $timeTotal, $timeStep, $memoryUsage, $memoryPeak) |
|
| 658 | + { |
|
| 659 | + $txt = str_pad($name, 30, ' ', STR_PAD_RIGHT). |
|
| 660 | + str_pad($timeTotal, 12, ' ', STR_PAD_LEFT). |
|
| 661 | + str_pad($timeStep, 12, ' ', STR_PAD_LEFT). |
|
| 662 | + str_pad($memoryUsage, 15, ' ', STR_PAD_LEFT). |
|
| 663 | + str_pad($memoryPeak, 15, ' ', STR_PAD_LEFT); |
|
| 664 | + |
|
| 665 | + echo '<pre style="padding:0; margin:0">'.$txt.'</pre>'; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + /** |
|
| 669 | + * get the Min and Max X, for Y (use the float margins) |
|
| 670 | + * |
|
| 671 | + * @access protected |
|
| 672 | + * @param float $y |
|
| 673 | + * @return array(float, float) |
|
| 674 | + */ |
|
| 675 | + protected function _getMargins($y) |
|
| 676 | + { |
|
| 677 | + $y = floor($y * 100); |
|
| 678 | + $x = array($this->pdf->getlMargin(), $this->pdf->getW() - $this->pdf->getrMargin()); |
|
| 679 | + |
|
| 680 | + foreach ($this->_pageMarges as $mY => $mX) |
|
| 681 | + if ($mY <= $y) $x = $mX; |
|
| 682 | + |
|
| 683 | + return $x; |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + /** |
|
| 687 | + * Add margins, for a float |
|
| 688 | + * |
|
| 689 | + * @access protected |
|
| 690 | + * @param string $float (left / right) |
|
| 691 | + * @param float $xLeft |
|
| 692 | + * @param float $yTop |
|
| 693 | + * @param float $xRight |
|
| 694 | + * @param float $yBottom |
|
| 695 | + */ |
|
| 696 | + protected function _addMargins($float, $xLeft, $yTop, $xRight, $yBottom) |
|
| 697 | + { |
|
| 698 | + // get the current float margins, for top and bottom |
|
| 699 | + $oldTop = $this->_getMargins($yTop); |
|
| 700 | + $oldBottom = $this->_getMargins($yBottom); |
|
| 701 | + |
|
| 702 | + // update the top float margin |
|
| 703 | + if ($float == 'left' && $oldTop[0] < $xRight) $oldTop[0] = $xRight; |
|
| 704 | + if ($float == 'right' && $oldTop[1] > $xLeft) $oldTop[1] = $xLeft; |
|
| 705 | + |
|
| 706 | + $yTop = floor($yTop * 100); |
|
| 707 | + $yBottom = floor($yBottom * 100); |
|
| 708 | + |
|
| 709 | + // erase all the float margins that are smaller than the new one |
|
| 710 | + foreach ($this->_pageMarges as $mY => $mX) { |
|
| 711 | + if ($mY < $yTop) continue; |
|
| 712 | + if ($mY > $yBottom) break; |
|
| 713 | + if ($float == 'left' && $this->_pageMarges[$mY][0] < $xRight) unset($this->_pageMarges[$mY]); |
|
| 714 | + if ($float == 'right' && $this->_pageMarges[$mY][1] > $xLeft) unset($this->_pageMarges[$mY]); |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + // save the new Top and Bottom margins |
|
| 718 | + $this->_pageMarges[$yTop] = $oldTop; |
|
| 719 | + $this->_pageMarges[$yBottom] = $oldBottom; |
|
| 720 | + |
|
| 721 | + // sort the margins |
|
| 722 | + ksort($this->_pageMarges); |
|
| 723 | + |
|
| 724 | + // we are just after float |
|
| 725 | + $this->_isAfterFloat = true; |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + /** |
|
| 729 | + * Save old margins (push), and set new ones |
|
| 730 | + * |
|
| 731 | + * @access protected |
|
| 732 | + * @param float $ml left margin |
|
| 733 | + * @param float $mt top margin |
|
| 734 | + * @param float $mr right margin |
|
| 735 | + */ |
|
| 736 | + protected function _saveMargin($ml, $mt, $mr) |
|
| 737 | + { |
|
| 738 | + // save old margins |
|
| 739 | + $this->_marges[] = array('l' => $this->pdf->getlMargin(), 't' => $this->pdf->gettMargin(), 'r' => $this->pdf->getrMargin(), 'page' => $this->_pageMarges); |
|
| 740 | + |
|
| 741 | + // set new ones |
|
| 742 | + $this->pdf->SetMargins($ml, $mt, $mr); |
|
| 743 | + |
|
| 744 | + // prepare for float margins |
|
| 745 | + $this->_pageMarges = array(); |
|
| 746 | + $this->_pageMarges[floor($mt * 100)] = array($ml, $this->pdf->getW() - $mr); |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + /** |
|
| 750 | + * load the last saved margins (pop) |
|
| 751 | + * |
|
| 752 | + * @access protected |
|
| 753 | + */ |
|
| 754 | + protected function _loadMargin() |
|
| 755 | + { |
|
| 756 | + $old = array_pop($this->_marges); |
|
| 757 | + if ($old) { |
|
| 758 | + $ml = $old['l']; |
|
| 759 | + $mt = $old['t']; |
|
| 760 | + $mr = $old['r']; |
|
| 761 | + $mP = $old['page']; |
|
| 762 | + } else { |
|
| 763 | + $ml = $this->_margeLeft; |
|
| 764 | + $mt = 0; |
|
| 765 | + $mr = $this->_margeRight; |
|
| 766 | + $mP = array($mt => array($ml, $this->pdf->getW() - $mr)); |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + $this->pdf->SetMargins($ml, $mt, $mr); |
|
| 770 | + $this->_pageMarges = $mP; |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + /** |
|
| 774 | + * save the current maxs (push) |
|
| 775 | + * |
|
| 776 | + * @access protected |
|
| 777 | + */ |
|
| 778 | + protected function _saveMax() |
|
| 779 | + { |
|
| 780 | + $this->_maxSave[] = array($this->_maxX, $this->_maxY, $this->_maxH, $this->_maxE); |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + /** |
|
| 784 | + * load the last saved current maxs (pop) |
|
| 785 | + * |
|
| 786 | + * @access protected |
|
| 787 | + */ |
|
| 788 | + protected function _loadMax() |
|
| 789 | + { |
|
| 790 | + $old = array_pop($this->_maxSave); |
|
| 791 | + |
|
| 792 | + if ($old) { |
|
| 793 | + $this->_maxX = $old[0]; |
|
| 794 | + $this->_maxY = $old[1]; |
|
| 795 | + $this->_maxH = $old[2]; |
|
| 796 | + $this->_maxE = $old[3]; |
|
| 797 | + } else { |
|
| 798 | + $this->_maxX = 0; |
|
| 799 | + $this->_maxY = 0; |
|
| 800 | + $this->_maxH = 0; |
|
| 801 | + $this->_maxE = 0; |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + /** |
|
| 806 | + * draw the PDF header with the HTML in page_header |
|
| 807 | + * |
|
| 808 | + * @access protected |
|
| 809 | + */ |
|
| 810 | + protected function _setPageHeader() |
|
| 811 | + { |
|
| 812 | + if ( ! count($this->_subHEADER)) return false; |
|
| 813 | + |
|
| 814 | + $oldParsePos = $this->_parsePos; |
|
| 815 | + $oldParseCode = $this->parsingHtml->code; |
|
| 816 | + |
|
| 817 | + $this->_parsePos = 0; |
|
| 818 | + $this->parsingHtml->code = $this->_subHEADER; |
|
| 819 | + $this->_makeHTMLcode(); |
|
| 820 | + |
|
| 821 | + $this->_parsePos = $oldParsePos; |
|
| 822 | + $this->parsingHtml->code = $oldParseCode; |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * draw the PDF footer with the HTML in page_footer |
|
| 827 | + * |
|
| 828 | + * @access protected |
|
| 829 | + */ |
|
| 830 | + protected function _setPageFooter() |
|
| 831 | + { |
|
| 832 | + if ( ! count($this->_subFOOTER)) return false; |
|
| 833 | + |
|
| 834 | + $oldParsePos = $this->_parsePos; |
|
| 835 | + $oldParseCode = $this->parsingHtml->code; |
|
| 836 | + |
|
| 837 | + $this->_parsePos = 0; |
|
| 838 | + $this->parsingHtml->code = $this->_subFOOTER; |
|
| 839 | + $this->_isInFooter = true; |
|
| 840 | + $this->_makeHTMLcode(); |
|
| 841 | + $this->_isInFooter = false; |
|
| 842 | + |
|
| 843 | + $this->_parsePos = $oldParsePos; |
|
| 844 | + $this->parsingHtml->code = $oldParseCode; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + /** |
|
| 848 | + * new line, with a specific height |
|
| 849 | + * |
|
| 850 | + * @access protected |
|
| 851 | + * @param float $h |
|
| 852 | + * @param integer $curr real current position in the text, if new line in the write of a text |
|
| 853 | + */ |
|
| 854 | + protected function _setNewLine($h, $curr = null) |
|
| 855 | + { |
|
| 856 | + $this->pdf->Ln($h); |
|
| 857 | + $this->_setNewPositionForNewLine($curr); |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + /** |
|
| 861 | + * calculate the start position of the next line, depending on the text-align |
|
| 862 | + * |
|
| 863 | + * @access protected |
|
| 864 | + * @param integer $curr real current position in the text, if new line in the write of a text |
|
| 865 | + */ |
|
| 866 | + protected function _setNewPositionForNewLine($curr = null) |
|
| 867 | + { |
|
| 868 | + // get the margins for the current line |
|
| 869 | + list($lx, $rx) = $this->_getMargins($this->pdf->getY()); |
|
| 870 | + $this->pdf->setX($lx); |
|
| 871 | + $wMax = $rx - $lx; |
|
| 872 | + $this->_currentH = 0; |
|
| 873 | + |
|
| 874 | + // if subPart => return because align left |
|
| 875 | + if ($this->_subPart || $this->_isSubPart || $this->_isForOneLine) { |
|
| 876 | + $this->pdf->setWordSpacing(0); |
|
| 877 | + return null; |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + // create the sub object |
|
| 881 | + $sub = null; |
|
| 882 | + $this->_createSubHTML($sub); |
|
| 883 | + $sub->_saveMargin(0, 0, $sub->pdf->getW() - $wMax); |
|
| 884 | + $sub->_isForOneLine = true; |
|
| 885 | + $sub->_parsePos = $this->_parsePos; |
|
| 886 | + $sub->parsingHtml->code = $this->parsingHtml->code; |
|
| 887 | + |
|
| 888 | + // if $curr => adapt the current position of the parsing |
|
| 889 | + if ($curr !== null && $sub->parsingHtml->code[$this->_parsePos]['name'] == 'write') { |
|
| 890 | + $txt = $sub->parsingHtml->code[$this->_parsePos]['param']['txt']; |
|
| 891 | + $txt = str_replace('[[page_cu]]', $sub->pdf->getMyNumPage($this->_page), $txt); |
|
| 892 | + $sub->parsingHtml->code[$this->_parsePos]['param']['txt'] = substr($txt, $curr + 1); |
|
| 893 | + } else |
|
| 894 | + $sub->_parsePos++; |
|
| 895 | + |
|
| 896 | + // for each element of the parsing => load the action |
|
| 897 | + $res = null; |
|
| 898 | + for ($sub->_parsePos; $sub->_parsePos < count($sub->parsingHtml->code); $sub->_parsePos++) { |
|
| 899 | + $action = $sub->parsingHtml->code[$sub->_parsePos]; |
|
| 900 | + $res = $sub->_executeAction($action); |
|
| 901 | + if ( ! $res) break; |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + $w = $sub->_maxX; // max width |
|
| 905 | + $h = $sub->_maxH; // max height |
|
| 906 | + $e = ($res === null ? $sub->_maxE : 0); // maxnumber of elemets on the line |
|
| 907 | + |
|
| 908 | + // destroy the sub HTML |
|
| 909 | + $this->_destroySubHTML($sub); |
|
| 910 | + |
|
| 911 | + // adapt the start of the line, depending on the text-align |
|
| 912 | + if ($this->parsingCss->value['text-align'] == 'center') |
|
| 913 | + $this->pdf->setX(($rx + $this->pdf->getX() - $w) * 0.5 - 0.01); |
|
| 914 | + else if ($this->parsingCss->value['text-align'] == 'right') |
|
| 915 | + $this->pdf->setX($rx - $w - 0.01); |
|
| 916 | + else |
|
| 917 | + $this->pdf->setX($lx); |
|
| 918 | + |
|
| 919 | + // set the height of the line |
|
| 920 | + $this->_currentH = $h; |
|
| 921 | + |
|
| 922 | + // if justify => set the word spacing |
|
| 923 | + if ($this->parsingCss->value['text-align'] == 'justify' && $e > 1) { |
|
| 924 | + $this->pdf->setWordSpacing(($wMax - $w) / ($e - 1)); |
|
| 925 | + } else { |
|
| 926 | + $this->pdf->setWordSpacing(0); |
|
| 927 | + } |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * prepare HTML2PDF::$_subobj (used for create the sub HTML2PDF objects |
|
| 932 | + * |
|
| 933 | + * @access protected |
|
| 934 | + */ |
|
| 935 | + protected function _prepareSubObj() |
|
| 936 | + { |
|
| 937 | + $pdf = null; |
|
| 938 | + |
|
| 939 | + // create the sub object |
|
| 940 | + HTML2PDF::$_subobj = new HTML2PDF( |
|
| 941 | + $this->_orientation, |
|
| 942 | + $this->_format, |
|
| 943 | + $this->_langue, |
|
| 944 | + $this->_unicode, |
|
| 945 | + $this->_encoding, |
|
| 946 | + array($this->_defaultLeft, $this->_defaultTop, $this->_defaultRight, $this->_defaultBottom) |
|
| 947 | + ); |
|
| 948 | + |
|
| 949 | + // init |
|
| 950 | + HTML2PDF::$_subobj->setTestTdInOnePage($this->_testTdInOnepage); |
|
| 951 | + HTML2PDF::$_subobj->setTestIsImage($this->_testIsImage); |
|
| 952 | + HTML2PDF::$_subobj->setTestIsDeprecated($this->_testIsDeprecated); |
|
| 953 | + HTML2PDF::$_subobj->setDefaultFont($this->_defaultFont); |
|
| 954 | + HTML2PDF::$_subobj->parsingCss->css = &$this->parsingCss->css; |
|
| 955 | + HTML2PDF::$_subobj->parsingCss->cssKeys = &$this->parsingCss->cssKeys; |
|
| 956 | + |
|
| 957 | + // clone font from the original PDF |
|
| 958 | + HTML2PDF::$_subobj->pdf->cloneFontFrom($this->pdf); |
|
| 959 | + |
|
| 960 | + // remove the link to the parent |
|
| 961 | + HTML2PDF::$_subobj->parsingCss->setPdfParent($pdf); |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + /** |
|
| 965 | + * create a sub HTML2PDF, to calculate the multi-tables |
|
| 966 | + * |
|
| 967 | + * @access protected |
|
| 968 | + * @param &HTML2PDF $subHtml sub HTML2PDF to create |
|
| 969 | + * @param integer $cellmargin if in a TD : cellmargin of this td |
|
| 970 | + */ |
|
| 971 | + protected function _createSubHTML(&$subHtml, $cellmargin = 0) |
|
| 972 | + { |
|
| 973 | + // prepare the subObject, if never prepare before |
|
| 974 | + if (HTML2PDF::$_subobj === null) { |
|
| 975 | + $this->_prepareSubObj(); |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + // calculate the width to use |
|
| 979 | + if ($this->parsingCss->value['width']) { |
|
| 980 | + $marge = $cellmargin * 2; |
|
| 981 | + $marge += $this->parsingCss->value['padding']['l'] + $this->parsingCss->value['padding']['r']; |
|
| 982 | + $marge += $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['border']['r']['width']; |
|
| 983 | + $marge = $this->pdf->getW() - $this->parsingCss->value['width'] + $marge; |
|
| 984 | + } else { |
|
| 985 | + $marge = $this->_margeLeft + $this->_margeRight; |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + // BUGFIX : we have to call the method, because of a bug in php 5.1.6 |
|
| 989 | + HTML2PDF::$_subobj->pdf->getPage(); |
|
| 990 | + |
|
| 991 | + // clone the sub oject |
|
| 992 | + $subHtml = clone HTML2PDF::$_subobj; |
|
| 993 | + $subHtml->parsingCss->table = $this->parsingCss->table; |
|
| 994 | + $subHtml->parsingCss->value = $this->parsingCss->value; |
|
| 995 | + $subHtml->initSubHtml( |
|
| 996 | + $this->_format, |
|
| 997 | + $this->_orientation, |
|
| 998 | + $marge, |
|
| 999 | + $this->_page, |
|
| 1000 | + $this->_defList, |
|
| 1001 | + $this->pdf->getMyLastPageGroup(), |
|
| 1002 | + $this->pdf->getMyLastPageGroupNb() |
|
| 1003 | + ); |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + /** |
|
| 1007 | + * destroy a subHTML2PDF |
|
| 1008 | + * |
|
| 1009 | + * @access protected |
|
| 1010 | + */ |
|
| 1011 | + protected function _destroySubHTML(&$subHtml) |
|
| 1012 | + { |
|
| 1013 | + unset($subHtml); |
|
| 1014 | + $subHtml = null; |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + /** |
|
| 1018 | + * Convert a arabic number in roman number |
|
| 1019 | + * |
|
| 1020 | + * @access protected |
|
| 1021 | + * @param integer $nbArabic |
|
| 1022 | + * @return string $nbRoman |
|
| 1023 | + */ |
|
| 1024 | + protected function _listeArab2Rom($nbArabic) |
|
| 1025 | + { |
|
| 1026 | + $nbBaseTen = array('I', 'X', 'C', 'M'); |
|
| 1027 | + $nbBaseFive = array('V', 'L', 'D'); |
|
| 1028 | + $nbRoman = ''; |
|
| 1029 | + |
|
| 1030 | + if ($nbArabic < 1) return $nbArabic; |
|
| 1031 | + if ($nbArabic > 3999) return $nbArabic; |
|
| 1032 | + |
|
| 1033 | + for ($i = 3; $i >= 0; $i--) { |
|
| 1034 | + $chiffre = floor($nbArabic / pow(10, $i)); |
|
| 1035 | + if ($chiffre >= 1) { |
|
| 1036 | + $nbArabic = $nbArabic - $chiffre * pow(10, $i); |
|
| 1037 | + if ($chiffre <= 3) { |
|
| 1038 | + for ($j = $chiffre; $j >= 1; $j--) { |
|
| 1039 | + $nbRoman = $nbRoman.$nbBaseTen[$i]; |
|
| 1040 | + } |
|
| 1041 | + } else if ($chiffre == 9) { |
|
| 1042 | + $nbRoman = $nbRoman.$nbBaseTen[$i].$nbBaseTen[$i + 1]; |
|
| 1043 | + } else if ($chiffre == 4) { |
|
| 1044 | + $nbRoman = $nbRoman.$nbBaseTen[$i].$nbBaseFive[$i]; |
|
| 1045 | + } else { |
|
| 1046 | + $nbRoman = $nbRoman.$nbBaseFive[$i]; |
|
| 1047 | + for ($j = $chiffre - 5; $j >= 1; $j--) { |
|
| 1048 | + $nbRoman = $nbRoman.$nbBaseTen[$i]; |
|
| 1049 | + } |
|
| 1050 | + } |
|
| 1051 | + } |
|
| 1052 | + } |
|
| 1053 | + return $nbRoman; |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + /** |
|
| 1057 | + * add a LI to the current level |
|
| 1058 | + * |
|
| 1059 | + * @access protected |
|
| 1060 | + */ |
|
| 1061 | + protected function _listeAddLi() |
|
| 1062 | + { |
|
| 1063 | + $this->_defList[count($this->_defList) - 1]['nb']++; |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + /** |
|
| 1067 | + * get the width to use for the column of the list |
|
| 1068 | + * |
|
| 1069 | + * @access protected |
|
| 1070 | + * @return string $width |
|
| 1071 | + */ |
|
| 1072 | + protected function _listeGetWidth() |
|
| 1073 | + { |
|
| 1074 | + return '7mm'; |
|
| 1075 | + } |
|
| 1076 | + |
|
| 1077 | + /** |
|
| 1078 | + * get the padding to use for the column of the list |
|
| 1079 | + * |
|
| 1080 | + * @access protected |
|
| 1081 | + * @return string $padding |
|
| 1082 | + */ |
|
| 1083 | + protected function _listeGetPadding() |
|
| 1084 | + { |
|
| 1085 | + return '1mm'; |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + /** |
|
| 1089 | + * get the information of the li on the current level |
|
| 1090 | + * |
|
| 1091 | + * @access protected |
|
| 1092 | + * @return array(fontName, small size, string) |
|
| 1093 | + */ |
|
| 1094 | + protected function _listeGetLi() |
|
| 1095 | + { |
|
| 1096 | + $im = $this->_defList[count($this->_defList) - 1]['img']; |
|
| 1097 | + $st = $this->_defList[count($this->_defList) - 1]['style']; |
|
| 1098 | + $nb = $this->_defList[count($this->_defList) - 1]['nb']; |
|
| 1099 | + $up = (substr($st, 0, 6) == 'upper-'); |
|
| 1100 | + |
|
| 1101 | + if ($im) { |
|
| 1102 | + return array(false, false, $im); |
|
| 1103 | + } |
|
| 1104 | + |
|
| 1105 | + switch ($st) |
|
| 1106 | + { |
|
| 1107 | + case 'none': |
|
| 1108 | + return array('helvetica', true, ' '); |
|
| 1109 | + |
|
| 1110 | + case 'upper-alpha': |
|
| 1111 | + case 'lower-alpha': |
|
| 1112 | + $str = ''; |
|
| 1113 | + while ($nb > 26) { |
|
| 1114 | + $str = chr(96 + $nb % 26).$str; |
|
| 1115 | + $nb = floor($nb / 26); |
|
| 1116 | + } |
|
| 1117 | + $str = chr(96 + $nb).$str; |
|
| 1118 | + |
|
| 1119 | + return array('helvetica', false, ($up ? strtoupper($str) : $str).'.'); |
|
| 1120 | + |
|
| 1121 | + case 'upper-roman': |
|
| 1122 | + case 'lower-roman': |
|
| 1123 | + $str = $this->_listeArab2Rom($nb); |
|
| 1124 | + |
|
| 1125 | + return array('helvetica', false, ($up ? strtoupper($str) : $str).'.'); |
|
| 1126 | + |
|
| 1127 | + case 'decimal': |
|
| 1128 | + return array('helvetica', false, $nb.'.'); |
|
| 1129 | + |
|
| 1130 | + case 'square': |
|
| 1131 | + return array('zapfdingbats', true, chr(110)); |
|
| 1132 | + |
|
| 1133 | + case 'circle': |
|
| 1134 | + return array('zapfdingbats', true, chr(109)); |
|
| 1135 | + |
|
| 1136 | + case 'disc': |
|
| 1137 | + default: |
|
| 1138 | + return array('zapfdingbats', true, chr(108)); |
|
| 1139 | + } |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + /** |
|
| 1143 | + * add a level to the list |
|
| 1144 | + * |
|
| 1145 | + * @access protected |
|
| 1146 | + * @param string $type : ul, ol |
|
| 1147 | + * @param string $style : lower-alpha, ... |
|
| 1148 | + * @param string $img |
|
| 1149 | + */ |
|
| 1150 | + protected function _listeAddLevel($type = 'ul', $style = '', $img = null) |
|
| 1151 | + { |
|
| 1152 | + // get the url of the image, if we want to use a image |
|
| 1153 | + if ($img) { |
|
| 1154 | + if (preg_match('/^url\(([^)]+)\)$/isU', trim($img), $match)) { |
|
| 1155 | + $img = $match[1]; |
|
| 1156 | + } else { |
|
| 1157 | + $img = null; |
|
| 1158 | + } |
|
| 1159 | + } else { |
|
| 1160 | + $img = null; |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + // prepare the datas |
|
| 1164 | + if ( ! in_array($type, array('ul', 'ol'))) $type = 'ul'; |
|
| 1165 | + if ( ! in_array($style, array('lower-alpha', 'upper-alpha', 'upper-roman', 'lower-roman', 'decimal', 'square', 'circle', 'disc', 'none'))) $style = ''; |
|
| 1166 | + |
|
| 1167 | + if ( ! $style) { |
|
| 1168 | + if ($type == 'ul') $style = 'disc'; |
|
| 1169 | + else $style = 'decimal'; |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + // add the new level |
|
| 1173 | + $this->_defList[count($this->_defList)] = array('style' => $style, 'nb' => 0, 'img' => $img); |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + /** |
|
| 1177 | + * remove a level to the list |
|
| 1178 | + * |
|
| 1179 | + * @access protected |
|
| 1180 | + */ |
|
| 1181 | + protected function _listeDelLevel() |
|
| 1182 | + { |
|
| 1183 | + if (count($this->_defList)) { |
|
| 1184 | + unset($this->_defList[count($this->_defList) - 1]); |
|
| 1185 | + $this->_defList = array_values($this->_defList); |
|
| 1186 | + } |
|
| 1187 | + } |
|
| 1188 | + |
|
| 1189 | + /** |
|
| 1190 | + * execute the actions to convert the html |
|
| 1191 | + * |
|
| 1192 | + * @access protected |
|
| 1193 | + */ |
|
| 1194 | + protected function _makeHTMLcode() |
|
| 1195 | + { |
|
| 1196 | + // foreach elements of the parsing |
|
| 1197 | + for ($this->_parsePos = 0; $this->_parsePos < count($this->parsingHtml->code); $this->_parsePos++) { |
|
| 1198 | + |
|
| 1199 | + // get the action to do |
|
| 1200 | + $action = $this->parsingHtml->code[$this->_parsePos]; |
|
| 1201 | + |
|
| 1202 | + // if it is a opening of table / ul / ol |
|
| 1203 | + if (in_array($action['name'], array('table', 'ul', 'ol')) && ! $action['close']) { |
|
| 1204 | + |
|
| 1205 | + // we will work as a sub HTML to calculate the size of the element |
|
| 1206 | + $this->_subPart = true; |
|
| 1207 | + |
|
| 1208 | + // get the name of the opening tag |
|
| 1209 | + $tagOpen = $action['name']; |
|
| 1210 | + |
|
| 1211 | + // save the actual pos on the parsing |
|
| 1212 | + $this->_tempPos = $this->_parsePos; |
|
| 1213 | + |
|
| 1214 | + // foreach elements, while we are in the opened tag |
|
| 1215 | + while (isset($this->parsingHtml->code[$this->_tempPos]) && ! ($this->parsingHtml->code[$this->_tempPos]['name'] == $tagOpen && $this->parsingHtml->code[$this->_tempPos]['close'])) { |
|
| 1216 | + // make the action |
|
| 1217 | + $this->_executeAction($this->parsingHtml->code[$this->_tempPos]); |
|
| 1218 | + $this->_tempPos++; |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + // execute the closure of the tag |
|
| 1222 | + if (isset($this->parsingHtml->code[$this->_tempPos])) { |
|
| 1223 | + $this->_executeAction($this->parsingHtml->code[$this->_tempPos]); |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + // end of the sub part |
|
| 1227 | + $this->_subPart = false; |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + // execute the action |
|
| 1231 | + $this->_executeAction($action); |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + /** |
|
| 1236 | + * execute the action from the parsing |
|
| 1237 | + * |
|
| 1238 | + * @access protected |
|
| 1239 | + * @param array $action |
|
| 1240 | + */ |
|
| 1241 | + protected function _executeAction($action) |
|
| 1242 | + { |
|
| 1243 | + // name of the action |
|
| 1244 | + $fnc = ($action['close'] ? '_tag_close_' : '_tag_open_').strtoupper($action['name']); |
|
| 1245 | + |
|
| 1246 | + // parameters of the action |
|
| 1247 | + $param = $action['param']; |
|
| 1248 | + |
|
| 1249 | + // if it the first action of the first page, and if it is not a open tag of PAGE => create the new page |
|
| 1250 | + if ($fnc != '_tag_open_PAGE' && $this->_firstPage) { |
|
| 1251 | + $this->_setNewPage(); |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + // the action must exist |
|
| 1255 | + if ( ! is_callable(array(&$this, $fnc))) { |
|
| 1256 | + throw new HTML2PDF_exception(1, strtoupper($action['name']), $this->parsingHtml->getHtmlErrorCode($action['html_pos'])); |
|
| 1257 | + } |
|
| 1258 | + |
|
| 1259 | + // lauch the action |
|
| 1260 | + $res = $this->{$fnc}($param); |
|
| 1261 | + |
|
| 1262 | + // save the name of the action |
|
| 1263 | + $this->_previousCall = $fnc; |
|
| 1264 | + |
|
| 1265 | + // return the result |
|
| 1266 | + return $res; |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + /** |
|
| 1270 | + * get the position of the element on the current line, depending on his height |
|
| 1271 | + * |
|
| 1272 | + * @access protected |
|
| 1273 | + * @param float $h |
|
| 1274 | + * @return float |
|
| 1275 | + */ |
|
| 1276 | + protected function _getElementY($h) |
|
| 1277 | + { |
|
| 1278 | + if ($this->_subPart || $this->_isSubPart || ! $this->_currentH || $this->_currentH < $h) |
|
| 1279 | + return 0; |
|
| 1280 | + |
|
| 1281 | + return ($this->_currentH - $h) * 0.8; |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + /** |
|
| 1285 | + * make a break line |
|
| 1286 | + * |
|
| 1287 | + * @access protected |
|
| 1288 | + * @param float $h current line height |
|
| 1289 | + * @param integer $curr real current position in the text, if new line in the write of a text |
|
| 1290 | + */ |
|
| 1291 | + protected function _makeBreakLine($h, $curr = null) |
|
| 1292 | + { |
|
| 1293 | + if ($h) { |
|
| 1294 | + if (($this->pdf->getY() + $h < $this->pdf->getH() - $this->pdf->getbMargin()) || $this->_isInOverflow || $this->_isInFooter) |
|
| 1295 | + $this->_setNewLine($h, $curr); |
|
| 1296 | + else |
|
| 1297 | + $this->_setNewPage(null, '', null, $curr); |
|
| 1298 | + } else { |
|
| 1299 | + $this->_setNewPositionForNewLine($curr); |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + $this->_maxH = 0; |
|
| 1303 | + $this->_maxE = 0; |
|
| 1304 | + } |
|
| 1305 | + |
|
| 1306 | + /** |
|
| 1307 | + * display a image |
|
| 1308 | + * |
|
| 1309 | + * @access protected |
|
| 1310 | + * @param string $src |
|
| 1311 | + * @param boolean $subLi if true=image of a list |
|
| 1312 | + * @return boolean depending on "isForOneLine" |
|
| 1313 | + */ |
|
| 1314 | + protected function _drawImage($src, $subLi = false) |
|
| 1315 | + { |
|
| 1316 | + // get the size of the image |
|
| 1317 | + // WARNING : if URL, "allow_url_fopen" must turned to "on" in php.ini |
|
| 1318 | + |
|
| 1319 | + $infos = @getimagesize($src); |
|
| 1320 | + |
|
| 1321 | + // if the image does not exist, or can not be loaded |
|
| 1322 | + if (count($infos) < 2) { |
|
| 1323 | + // if the test is activ => exception |
|
| 1324 | + if ($this->_testIsImage) { |
|
| 1325 | + throw new HTML2PDF_exception(6, $src); |
|
| 1326 | + } |
|
| 1327 | + |
|
| 1328 | + // else, display a gray rectangle |
|
| 1329 | + $src = null; |
|
| 1330 | + $infos = array(16, 16); |
|
| 1331 | + } |
|
| 1332 | + |
|
| 1333 | + // convert the size of the image in the unit of the PDF |
|
| 1334 | + $imageWidth = $infos[0] / $this->pdf->getK(); |
|
| 1335 | + $imageHeight = $infos[1] / $this->pdf->getK(); |
|
| 1336 | + |
|
| 1337 | + // calculate the size from the css style |
|
| 1338 | + if ($this->parsingCss->value['width'] && $this->parsingCss->value['height']) { |
|
| 1339 | + $w = $this->parsingCss->value['width']; |
|
| 1340 | + $h = $this->parsingCss->value['height']; |
|
| 1341 | + } else if ($this->parsingCss->value['width']) { |
|
| 1342 | + $w = $this->parsingCss->value['width']; |
|
| 1343 | + $h = $imageHeight * $w / $imageWidth; |
|
| 1344 | + } else if ($this->parsingCss->value['height']) { |
|
| 1345 | + $h = $this->parsingCss->value['height']; |
|
| 1346 | + $w = $imageWidth * $h / $imageHeight; |
|
| 1347 | + } else { |
|
| 1348 | + // convert px to pt |
|
| 1349 | + $w = 72. / 96. * $imageWidth; |
|
| 1350 | + $h = 72. / 96. * $imageHeight; |
|
| 1351 | + } |
|
| 1352 | + |
|
| 1353 | + // are we in a float |
|
| 1354 | + $float = $this->parsingCss->getFloat(); |
|
| 1355 | + |
|
| 1356 | + // if we are in a float, but if something else if on the line => Break Line |
|
| 1357 | + if ($float && $this->_maxH) { |
|
| 1358 | + // make the break line (false if we are in "_isForOneLine" mode) |
|
| 1359 | + if ( ! $this->_tag_open_BR(array())) { |
|
| 1360 | + return false; |
|
| 1361 | + } |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + // position of the image |
|
| 1365 | + $x = $this->pdf->getX(); |
|
| 1366 | + $y = $this->pdf->getY(); |
|
| 1367 | + |
|
| 1368 | + // if the image can not be put on the current line => new line |
|
| 1369 | + if ( ! $float && ($x + $w > $this->pdf->getW() - $this->pdf->getrMargin()) && $this->_maxH) { |
|
| 1370 | + if ($this->_isForOneLine) { |
|
| 1371 | + return false; |
|
| 1372 | + } |
|
| 1373 | + |
|
| 1374 | + // set the new line |
|
| 1375 | + $hnl = max($this->_maxH, $this->parsingCss->getLineHeight()); |
|
| 1376 | + $this->_setNewLine($hnl); |
|
| 1377 | + |
|
| 1378 | + // get the new position |
|
| 1379 | + $x = $this->pdf->getX(); |
|
| 1380 | + $y = $this->pdf->getY(); |
|
| 1381 | + } |
|
| 1382 | + |
|
| 1383 | + // if the image can not be put on the current page |
|
| 1384 | + if (($y + $h > $this->pdf->getH() - $this->pdf->getbMargin()) && ! $this->_isInOverflow) { |
|
| 1385 | + // new page |
|
| 1386 | + $this->_setNewPage(); |
|
| 1387 | + |
|
| 1388 | + // get the new position |
|
| 1389 | + $x = $this->pdf->getX(); |
|
| 1390 | + $y = $this->pdf->getY(); |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + // correction for display the image of a list |
|
| 1394 | + $hT = 0.80 * $this->parsingCss->value['font-size']; |
|
| 1395 | + if ($subLi && $h < $hT) { |
|
| 1396 | + $y += ($hT - $h); |
|
| 1397 | + } |
|
| 1398 | + |
|
| 1399 | + // add the margin top |
|
| 1400 | + $yc = $y - $this->parsingCss->value['margin']['t']; |
|
| 1401 | + |
|
| 1402 | + // get the width and the position of the parent |
|
| 1403 | + $old = $this->parsingCss->getOldValues(); |
|
| 1404 | + if ($old['width']) { |
|
| 1405 | + $parentWidth = $old['width']; |
|
| 1406 | + $parentX = $x; |
|
| 1407 | + } else { |
|
| 1408 | + $parentWidth = $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); |
|
| 1409 | + $parentX = $this->pdf->getlMargin(); |
|
| 1410 | + } |
|
| 1411 | + |
|
| 1412 | + // if we are in a gloat => adapt the parent position and width |
|
| 1413 | + if ($float) { |
|
| 1414 | + list($lx, $rx) = $this->_getMargins($yc); |
|
| 1415 | + $parentX = $lx; |
|
| 1416 | + $parentWidth = $rx - $lx; |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + // calculate the position of the image, if align to the right |
|
| 1420 | + if ($parentWidth > $w && $float != 'left') { |
|
| 1421 | + if ($float == 'right' || $this->parsingCss->value['text-align'] == 'li_right') $x = $parentX + $parentWidth - $w - $this->parsingCss->value['margin']['r'] - $this->parsingCss->value['margin']['l']; |
|
| 1422 | + } |
|
| 1423 | + |
|
| 1424 | + // display the image |
|
| 1425 | + if ( ! $this->_subPart && ! $this->_isSubPart) { |
|
| 1426 | + if ($src) { |
|
| 1427 | + $this->pdf->Image($src, $x, $y, $w, $h, '', $this->_isInLink); |
|
| 1428 | + } else { |
|
| 1429 | + // rectangle if the image can not be loaded |
|
| 1430 | + $this->pdf->setFillColorArray(array(240, 220, 220)); |
|
| 1431 | + $this->pdf->Rect($x, $y, $w, $h, 'F'); |
|
| 1432 | + } |
|
| 1433 | + } |
|
| 1434 | + |
|
| 1435 | + // apply the margins |
|
| 1436 | + $x -= $this->parsingCss->value['margin']['l']; |
|
| 1437 | + $y -= $this->parsingCss->value['margin']['t']; |
|
| 1438 | + $w += $this->parsingCss->value['margin']['l'] + $this->parsingCss->value['margin']['r']; |
|
| 1439 | + $h += $this->parsingCss->value['margin']['t'] + $this->parsingCss->value['margin']['b']; |
|
| 1440 | + |
|
| 1441 | + if ($float == 'left') { |
|
| 1442 | + // save the current max |
|
| 1443 | + $this->_maxX = max($this->_maxX, $x + $w); |
|
| 1444 | + $this->_maxY = max($this->_maxY, $y + $h); |
|
| 1445 | + |
|
| 1446 | + // add the image to the margins |
|
| 1447 | + $this->_addMargins($float, $x, $y, $x + $w, $y + $h); |
|
| 1448 | + |
|
| 1449 | + // get the new position |
|
| 1450 | + list($lx, $rx) = $this->_getMargins($yc); |
|
| 1451 | + $this->pdf->setXY($lx, $yc); |
|
| 1452 | + } else if ($float == 'right') { |
|
| 1453 | + // save the current max. We don't save the X because it is not the real max of the line |
|
| 1454 | + $this->_maxY = max($this->_maxY, $y + $h); |
|
| 1455 | + |
|
| 1456 | + // add the image to the margins |
|
| 1457 | + $this->_addMargins($float, $x, $y, $x + $w, $y + $h); |
|
| 1458 | + |
|
| 1459 | + // get the new position |
|
| 1460 | + list($lx, $rx) = $this->_getMargins($yc); |
|
| 1461 | + $this->pdf->setXY($lx, $yc); |
|
| 1462 | + } else { |
|
| 1463 | + // set the new position at the end of the image |
|
| 1464 | + $this->pdf->setX($x + $w); |
|
| 1465 | + |
|
| 1466 | + // save the current max |
|
| 1467 | + $this->_maxX = max($this->_maxX, $x + $w); |
|
| 1468 | + $this->_maxY = max($this->_maxY, $y + $h); |
|
| 1469 | + $this->_maxH = max($this->_maxH, $h); |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + return true; |
|
| 1473 | + } |
|
| 1474 | + |
|
| 1475 | + /** |
|
| 1476 | + * draw a rectangle |
|
| 1477 | + * |
|
| 1478 | + * @access protected |
|
| 1479 | + * @param float $x |
|
| 1480 | + * @param float $y |
|
| 1481 | + * @param float $w |
|
| 1482 | + * @param float $h |
|
| 1483 | + * @param array $border |
|
| 1484 | + * @param float $padding - internal marge of the rectanble => not used, but... |
|
| 1485 | + * @param float $margin - external marge of the rectanble |
|
| 1486 | + * @param array $background |
|
| 1487 | + * @return boolean |
|
| 1488 | + */ |
|
| 1489 | + protected function _drawRectangle($x, $y, $w, $h, $border, $padding, $margin, $background) |
|
| 1490 | + { |
|
| 1491 | + // if we are in a subpart or if height is null => return false |
|
| 1492 | + if ($this->_subPart || $this->_isSubPart || $h === null) return false; |
|
| 1493 | + |
|
| 1494 | + // add the margin |
|
| 1495 | + $x += $margin; |
|
| 1496 | + $y += $margin; |
|
| 1497 | + $w -= $margin * 2; |
|
| 1498 | + $h -= $margin * 2; |
|
| 1499 | + |
|
| 1500 | + // get the radius of the border |
|
| 1501 | + $outTL = $border['radius']['tl']; |
|
| 1502 | + $outTR = $border['radius']['tr']; |
|
| 1503 | + $outBR = $border['radius']['br']; |
|
| 1504 | + $outBL = $border['radius']['bl']; |
|
| 1505 | + |
|
| 1506 | + // prepare the out radius |
|
| 1507 | + $outTL = ($outTL[0] && $outTL[1]) ? $outTL : null; |
|
| 1508 | + $outTR = ($outTR[0] && $outTR[1]) ? $outTR : null; |
|
| 1509 | + $outBR = ($outBR[0] && $outBR[1]) ? $outBR : null; |
|
| 1510 | + $outBL = ($outBL[0] && $outBL[1]) ? $outBL : null; |
|
| 1511 | + |
|
| 1512 | + // prepare the in radius |
|
| 1513 | + $inTL = $outTL; |
|
| 1514 | + $inTR = $outTR; |
|
| 1515 | + $inBR = $outBR; |
|
| 1516 | + $inBL = $outBL; |
|
| 1517 | + |
|
| 1518 | + if (is_array($inTL)) { |
|
| 1519 | + $inTL[0] -= $border['l']['width']; |
|
| 1520 | + $inTL[1] -= $border['t']['width']; |
|
| 1521 | + } |
|
| 1522 | + if (is_array($inTR)) { |
|
| 1523 | + $inTR[0] -= $border['r']['width']; |
|
| 1524 | + $inTR[1] -= $border['t']['width']; |
|
| 1525 | + } |
|
| 1526 | + if (is_array($inBR)) { |
|
| 1527 | + $inBR[0] -= $border['r']['width']; |
|
| 1528 | + $inBR[1] -= $border['b']['width']; |
|
| 1529 | + } |
|
| 1530 | + if (is_array($inBL)) { |
|
| 1531 | + $inBL[0] -= $border['l']['width']; |
|
| 1532 | + $inBL[1] -= $border['b']['width']; |
|
| 1533 | + } |
|
| 1534 | + |
|
| 1535 | + if ($inTL[0] <= 0 || $inTL[1] <= 0) $inTL = null; |
|
| 1536 | + if ($inTR[0] <= 0 || $inTR[1] <= 0) $inTR = null; |
|
| 1537 | + if ($inBR[0] <= 0 || $inBR[1] <= 0) $inBR = null; |
|
| 1538 | + if ($inBL[0] <= 0 || $inBL[1] <= 0) $inBL = null; |
|
| 1539 | + |
|
| 1540 | + // prepare the background color |
|
| 1541 | + $pdfStyle = ''; |
|
| 1542 | + if ($background['color']) { |
|
| 1543 | + $this->pdf->setFillColorArray($background['color']); |
|
| 1544 | + $pdfStyle .= 'F'; |
|
| 1545 | + } |
|
| 1546 | + |
|
| 1547 | + // if we have a background to fill => fill it with a path (because of the radius) |
|
| 1548 | + if ($pdfStyle) { |
|
| 1549 | + $this->pdf->clippingPathStart($x, $y, $w, $h, $outTL, $outTR, $outBL, $outBR); |
|
| 1550 | + $this->pdf->Rect($x, $y, $w, $h, $pdfStyle); |
|
| 1551 | + $this->pdf->clippingPathStop(); |
|
| 1552 | + } |
|
| 1553 | + |
|
| 1554 | + // prepare the background image |
|
| 1555 | + if ($background['image']) { |
|
| 1556 | + $iName = $background['image']; |
|
| 1557 | + $iPosition = $background['position'] !== null ? $background['position'] : array(0, 0); |
|
| 1558 | + $iRepeat = $background['repeat'] !== null ? $background['repeat'] : array(true, true); |
|
| 1559 | + |
|
| 1560 | + // size of the background without the borders |
|
| 1561 | + $bX = $x; |
|
| 1562 | + $bY = $y; |
|
| 1563 | + $bW = $w; |
|
| 1564 | + $bH = $h; |
|
| 1565 | + |
|
| 1566 | + if ($border['b']['width']) { |
|
| 1567 | + $bH -= $border['b']['width']; |
|
| 1568 | + } |
|
| 1569 | + if ($border['l']['width']) { |
|
| 1570 | + $bW -= $border['l']['width']; |
|
| 1571 | + $bX += $border['l']['width']; |
|
| 1572 | + } |
|
| 1573 | + if ($border['t']['width']) { |
|
| 1574 | + $bH -= $border['t']['width']; |
|
| 1575 | + $bY += $border['t']['width']; |
|
| 1576 | + } |
|
| 1577 | + if ($border['r']['width']) { |
|
| 1578 | + $bW -= $border['r']['width']; |
|
| 1579 | + } |
|
| 1580 | + |
|
| 1581 | + // get the size of the image |
|
| 1582 | + // WARNING : if URL, "allow_url_fopen" must turned to "on" in php.ini |
|
| 1583 | + $imageInfos = @getimagesize($iName); |
|
| 1584 | + |
|
| 1585 | + // if the image can not be loaded |
|
| 1586 | + if (count($imageInfos) < 2) { |
|
| 1587 | + if ($this->_testIsImage) { |
|
| 1588 | + throw new HTML2PDF_exception(6, $iName); |
|
| 1589 | + } |
|
| 1590 | + } else { |
|
| 1591 | + // convert the size of the image from pixel to the unit of the PDF |
|
| 1592 | + $imageWidth = 72. / 96. * $imageInfos[0] / $this->pdf->getK(); |
|
| 1593 | + $imageHeight = 72. / 96. * $imageInfos[1] / $this->pdf->getK(); |
|
| 1594 | + |
|
| 1595 | + // prepare the position of the backgroung |
|
| 1596 | + if ($iRepeat[0]) $iPosition[0] = $bX; |
|
| 1597 | + else if (preg_match('/^([-]?[0-9\.]+)%/isU', $iPosition[0], $match)) $iPosition[0] = $bX + $match[1] * ($bW - $imageWidth) / 100; |
|
| 1598 | + else $iPosition[0] = $bX + $iPosition[0]; |
|
| 1599 | + |
|
| 1600 | + if ($iRepeat[1]) $iPosition[1] = $bY; |
|
| 1601 | + else if (preg_match('/^([-]?[0-9\.]+)%/isU', $iPosition[1], $match)) $iPosition[1] = $bY + $match[1] * ($bH - $imageHeight) / 100; |
|
| 1602 | + else $iPosition[1] = $bY + $iPosition[1]; |
|
| 1603 | + |
|
| 1604 | + $imageXmin = $bX; |
|
| 1605 | + $imageXmax = $bX + $bW; |
|
| 1606 | + $imageYmin = $bY; |
|
| 1607 | + $imageYmax = $bY + $bH; |
|
| 1608 | + |
|
| 1609 | + if ( ! $iRepeat[0] && ! $iRepeat[1]) { |
|
| 1610 | + $imageXmin = $iPosition[0]; $imageXmax = $iPosition[0] + $imageWidth; |
|
| 1611 | + $imageYmin = $iPosition[1]; $imageYmax = $iPosition[1] + $imageHeight; |
|
| 1612 | + } else if ($iRepeat[0] && ! $iRepeat[1]) { |
|
| 1613 | + $imageYmin = $iPosition[1]; $imageYmax = $iPosition[1] + $imageHeight; |
|
| 1614 | + } else if ( ! $iRepeat[0] && $iRepeat[1]) { |
|
| 1615 | + $imageXmin = $iPosition[0]; $imageXmax = $iPosition[0] + $imageWidth; |
|
| 1616 | + } |
|
| 1617 | + |
|
| 1618 | + // build the path to display the image (because of radius) |
|
| 1619 | + $this->pdf->clippingPathStart($bX, $bY, $bW, $bH, $inTL, $inTR, $inBL, $inBR); |
|
| 1620 | + |
|
| 1621 | + // repeat the image |
|
| 1622 | + for ($iY = $imageYmin; $iY < $imageYmax; $iY += $imageHeight) { |
|
| 1623 | + for ($iX = $imageXmin; $iX < $imageXmax; $iX += $imageWidth) { |
|
| 1624 | + $cX = null; |
|
| 1625 | + $cY = null; |
|
| 1626 | + $cW = $imageWidth; |
|
| 1627 | + $cH = $imageHeight; |
|
| 1628 | + if ($imageYmax - $iY < $imageHeight) { |
|
| 1629 | + $cX = $iX; |
|
| 1630 | + $cY = $iY; |
|
| 1631 | + $cH = $imageYmax - $iY; |
|
| 1632 | + } |
|
| 1633 | + if ($imageXmax - $iX < $imageWidth) { |
|
| 1634 | + $cX = $iX; |
|
| 1635 | + $cY = $iY; |
|
| 1636 | + $cW = $imageXmax - $iX; |
|
| 1637 | + } |
|
| 1638 | + |
|
| 1639 | + $this->pdf->Image($iName, $iX, $iY, $imageWidth, $imageHeight, '', ''); |
|
| 1640 | + } |
|
| 1641 | + } |
|
| 1642 | + |
|
| 1643 | + // end of the path |
|
| 1644 | + $this->pdf->clippingPathStop(); |
|
| 1645 | + } |
|
| 1646 | + } |
|
| 1647 | + |
|
| 1648 | + // adding some loose (0.01mm) |
|
| 1649 | + $loose = 0.01; |
|
| 1650 | + $x -= $loose; |
|
| 1651 | + $y -= $loose; |
|
| 1652 | + $w += 2. * $loose; |
|
| 1653 | + $h += 2. * $loose; |
|
| 1654 | + if ($border['l']['width']) $border['l']['width'] += 2. * $loose; |
|
| 1655 | + if ($border['t']['width']) $border['t']['width'] += 2. * $loose; |
|
| 1656 | + if ($border['r']['width']) $border['r']['width'] += 2. * $loose; |
|
| 1657 | + if ($border['b']['width']) $border['b']['width'] += 2. * $loose; |
|
| 1658 | + |
|
| 1659 | + // prepare the test on borders |
|
| 1660 | + $testBl = ($border['l']['width'] && $border['l']['color'][0] !== null); |
|
| 1661 | + $testBt = ($border['t']['width'] && $border['t']['color'][0] !== null); |
|
| 1662 | + $testBr = ($border['r']['width'] && $border['r']['color'][0] !== null); |
|
| 1663 | + $testBb = ($border['b']['width'] && $border['b']['color'][0] !== null); |
|
| 1664 | + |
|
| 1665 | + // draw the radius bottom-left |
|
| 1666 | + if (is_array($outBL) && ($testBb || $testBl)) { |
|
| 1667 | + if ($inBL) { |
|
| 1668 | + $courbe = array(); |
|
| 1669 | + $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h; |
|
| 1670 | + $courbe[] = $x; $courbe[] = $y + $h - $outBL[1]; |
|
| 1671 | + $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h - $border['b']['width']; |
|
| 1672 | + $courbe[] = $x + $border['l']['width']; $courbe[] = $y + $h - $outBL[1]; |
|
| 1673 | + $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h - $outBL[1]; |
|
| 1674 | + } else { |
|
| 1675 | + $courbe = array(); |
|
| 1676 | + $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h; |
|
| 1677 | + $courbe[] = $x; $courbe[] = $y + $h - $outBL[1]; |
|
| 1678 | + $courbe[] = $x + $border['l']['width']; $courbe[] = $y + $h - $border['b']['width']; |
|
| 1679 | + $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h - $outBL[1]; |
|
| 1680 | + } |
|
| 1681 | + $this->_drawCurve($courbe, $border['l']['color']); |
|
| 1682 | + } |
|
| 1683 | + |
|
| 1684 | + // draw the radius left-top |
|
| 1685 | + if (is_array($outTL) && ($testBt || $testBl)) { |
|
| 1686 | + if ($inTL) { |
|
| 1687 | + $courbe = array(); |
|
| 1688 | + $courbe[] = $x; $courbe[] = $y + $outTL[1]; |
|
| 1689 | + $courbe[] = $x + $outTL[0]; $courbe[] = $y; |
|
| 1690 | + $courbe[] = $x + $border['l']['width']; $courbe[] = $y + $outTL[1]; |
|
| 1691 | + $courbe[] = $x + $outTL[0]; $courbe[] = $y + $border['t']['width']; |
|
| 1692 | + $courbe[] = $x + $outTL[0]; $courbe[] = $y + $outTL[1]; |
|
| 1693 | + } else { |
|
| 1694 | + $courbe = array(); |
|
| 1695 | + $courbe[] = $x; $courbe[] = $y + $outTL[1]; |
|
| 1696 | + $courbe[] = $x + $outTL[0]; $courbe[] = $y; |
|
| 1697 | + $courbe[] = $x + $border['l']['width']; $courbe[] = $y + $border['t']['width']; |
|
| 1698 | + $courbe[] = $x + $outTL[0]; $courbe[] = $y + $outTL[1]; |
|
| 1699 | + } |
|
| 1700 | + $this->_drawCurve($courbe, $border['t']['color']); |
|
| 1701 | + } |
|
| 1702 | + |
|
| 1703 | + // draw the radius top-right |
|
| 1704 | + if (is_array($outTR) && ($testBt || $testBr)) { |
|
| 1705 | + if ($inTR) { |
|
| 1706 | + $courbe = array(); |
|
| 1707 | + $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y; |
|
| 1708 | + $courbe[] = $x + $w; $courbe[] = $y + $outTR[1]; |
|
| 1709 | + $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y + $border['t']['width']; |
|
| 1710 | + $courbe[] = $x + $w - $border['r']['width']; $courbe[] = $y + $outTR[1]; |
|
| 1711 | + $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y + $outTR[1]; |
|
| 1712 | + } else { |
|
| 1713 | + $courbe = array(); |
|
| 1714 | + $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y; |
|
| 1715 | + $courbe[] = $x + $w; $courbe[] = $y + $outTR[1]; |
|
| 1716 | + $courbe[] = $x + $w - $border['r']['width']; $courbe[] = $y + $border['t']['width']; |
|
| 1717 | + $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y + $outTR[1]; |
|
| 1718 | + } |
|
| 1719 | + $this->_drawCurve($courbe, $border['r']['color']); |
|
| 1720 | + } |
|
| 1721 | + |
|
| 1722 | + // draw the radius right-bottom |
|
| 1723 | + if (is_array($outBR) && ($testBb || $testBr)) { |
|
| 1724 | + if ($inBR) { |
|
| 1725 | + $courbe = array(); |
|
| 1726 | + $courbe[] = $x + $w; $courbe[] = $y + $h - $outBR[1]; |
|
| 1727 | + $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h; |
|
| 1728 | + $courbe[] = $x + $w - $border['r']['width']; $courbe[] = $y + $h - $outBR[1]; |
|
| 1729 | + $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h - $border['b']['width']; |
|
| 1730 | + $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h - $outBR[1]; |
|
| 1731 | + } else { |
|
| 1732 | + $courbe = array(); |
|
| 1733 | + $courbe[] = $x + $w; $courbe[] = $y + $h - $outBR[1]; |
|
| 1734 | + $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h; |
|
| 1735 | + $courbe[] = $x + $w - $border['r']['width']; $courbe[] = $y + $h - $border['b']['width']; |
|
| 1736 | + $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h - $outBR[1]; |
|
| 1737 | + } |
|
| 1738 | + $this->_drawCurve($courbe, $border['b']['color']); |
|
| 1739 | + } |
|
| 1740 | + |
|
| 1741 | + // draw the left border |
|
| 1742 | + if ($testBl) { |
|
| 1743 | + $pt = array(); |
|
| 1744 | + $pt[] = $x; $pt[] = $y + $h; |
|
| 1745 | + $pt[] = $x; $pt[] = $y + $h - $border['b']['width']; |
|
| 1746 | + $pt[] = $x; $pt[] = $y + $border['t']['width']; |
|
| 1747 | + $pt[] = $x; $pt[] = $y; |
|
| 1748 | + $pt[] = $x + $border['l']['width']; $pt[] = $y + $border['t']['width']; |
|
| 1749 | + $pt[] = $x + $border['l']['width']; $pt[] = $y + $h - $border['b']['width']; |
|
| 1750 | + |
|
| 1751 | + $bord = 3; |
|
| 1752 | + if (is_array($outBL)) { |
|
| 1753 | + $bord -= 1; |
|
| 1754 | + $pt[3] -= $outBL[1] - $border['b']['width']; |
|
| 1755 | + if ($inBL) $pt[11] -= $inBL[1]; |
|
| 1756 | + unset($pt[0]); unset($pt[1]); |
|
| 1757 | + } |
|
| 1758 | + if (is_array($outTL)) { |
|
| 1759 | + $bord -= 2; |
|
| 1760 | + $pt[5] += $outTL[1] - $border['t']['width']; |
|
| 1761 | + if ($inTL) $pt[9] += $inTL[1]; |
|
| 1762 | + unset($pt[6]); unset($pt[7]); |
|
| 1763 | + } |
|
| 1764 | + |
|
| 1765 | + $pt = array_values($pt); |
|
| 1766 | + $this->_drawLine($pt, $border['l']['color'], $border['l']['type'], $border['l']['width'], $bord); |
|
| 1767 | + } |
|
| 1768 | + |
|
| 1769 | + // draw the top border |
|
| 1770 | + if ($testBt) { |
|
| 1771 | + $pt = array(); |
|
| 1772 | + $pt[] = $x; $pt[] = $y; |
|
| 1773 | + $pt[] = $x + $border['l']['width']; $pt[] = $y; |
|
| 1774 | + $pt[] = $x + $w - $border['r']['width']; $pt[] = $y; |
|
| 1775 | + $pt[] = $x + $w; $pt[] = $y; |
|
| 1776 | + $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $border['t']['width']; |
|
| 1777 | + $pt[] = $x + $border['l']['width']; $pt[] = $y + $border['t']['width']; |
|
| 1778 | + |
|
| 1779 | + $bord = 3; |
|
| 1780 | + if (is_array($outTL)) { |
|
| 1781 | + $bord -= 1; |
|
| 1782 | + $pt[2] += $outTL[0] - $border['l']['width']; |
|
| 1783 | + if ($inTL) $pt[10] += $inTL[0]; |
|
| 1784 | + unset($pt[0]); unset($pt[1]); |
|
| 1785 | + } |
|
| 1786 | + if (is_array($outTR)) { |
|
| 1787 | + $bord -= 2; |
|
| 1788 | + $pt[4] -= $outTR[0] - $border['r']['width']; |
|
| 1789 | + if ($inTR) $pt[8] -= $inTR[0]; |
|
| 1790 | + unset($pt[6]); unset($pt[7]); |
|
| 1791 | + } |
|
| 1792 | + |
|
| 1793 | + $pt = array_values($pt); |
|
| 1794 | + $this->_drawLine($pt, $border['t']['color'], $border['t']['type'], $border['t']['width'], $bord); |
|
| 1795 | + } |
|
| 1796 | + |
|
| 1797 | + // draw the right border |
|
| 1798 | + if ($testBr) { |
|
| 1799 | + $pt = array(); |
|
| 1800 | + $pt[] = $x + $w; $pt[] = $y; |
|
| 1801 | + $pt[] = $x + $w; $pt[] = $y + $border['t']['width']; |
|
| 1802 | + $pt[] = $x + $w; $pt[] = $y + $h - $border['b']['width']; |
|
| 1803 | + $pt[] = $x + $w; $pt[] = $y + $h; |
|
| 1804 | + $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $h - $border['b']['width']; |
|
| 1805 | + $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $border['t']['width']; |
|
| 1806 | + |
|
| 1807 | + $bord = 3; |
|
| 1808 | + if (is_array($outTR)) { |
|
| 1809 | + $bord -= 1; |
|
| 1810 | + $pt[3] += $outTR[1] - $border['t']['width']; |
|
| 1811 | + if ($inTR) $pt[11] += $inTR[1]; |
|
| 1812 | + unset($pt[0]); unset($pt[1]); |
|
| 1813 | + } |
|
| 1814 | + if (is_array($outBR)) { |
|
| 1815 | + $bord -= 2; |
|
| 1816 | + $pt[5] -= $outBR[1] - $border['b']['width']; |
|
| 1817 | + if ($inBR) $pt[9] -= $inBR[1]; |
|
| 1818 | + unset($pt[6]); unset($pt[7]); |
|
| 1819 | + } |
|
| 1820 | + |
|
| 1821 | + $pt = array_values($pt); |
|
| 1822 | + $this->_drawLine($pt, $border['r']['color'], $border['r']['type'], $border['r']['width'], $bord); |
|
| 1823 | + } |
|
| 1824 | + |
|
| 1825 | + // draw the bottom border |
|
| 1826 | + if ($testBb) { |
|
| 1827 | + $pt = array(); |
|
| 1828 | + $pt[] = $x + $w; $pt[] = $y + $h; |
|
| 1829 | + $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $h; |
|
| 1830 | + $pt[] = $x + $border['l']['width']; $pt[] = $y + $h; |
|
| 1831 | + $pt[] = $x; $pt[] = $y + $h; |
|
| 1832 | + $pt[] = $x + $border['l']['width']; $pt[] = $y + $h - $border['b']['width']; |
|
| 1833 | + $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $h - $border['b']['width']; |
|
| 1834 | + |
|
| 1835 | + $bord = 3; |
|
| 1836 | + if (is_array($outBL)) { |
|
| 1837 | + $bord -= 2; |
|
| 1838 | + $pt[4] += $outBL[0] - $border['l']['width']; |
|
| 1839 | + if ($inBL) $pt[8] += $inBL[0]; |
|
| 1840 | + unset($pt[6]); unset($pt[7]); |
|
| 1841 | + } |
|
| 1842 | + if (is_array($outBR)) { |
|
| 1843 | + $bord -= 1; |
|
| 1844 | + $pt[2] -= $outBR[0] - $border['r']['width']; |
|
| 1845 | + if ($inBR) $pt[10] -= $inBR[0]; |
|
| 1846 | + unset($pt[0]); unset($pt[1]); |
|
| 1847 | + |
|
| 1848 | + } |
|
| 1849 | + |
|
| 1850 | + $pt = array_values($pt); |
|
| 1851 | + $this->_drawLine($pt, $border['b']['color'], $border['b']['type'], $border['b']['width'], $bord); |
|
| 1852 | + } |
|
| 1853 | + |
|
| 1854 | + if ($background['color']) { |
|
| 1855 | + $this->pdf->setFillColorArray($background['color']); |
|
| 1856 | + } |
|
| 1857 | + |
|
| 1858 | + return true; |
|
| 1859 | + } |
|
| 1860 | + |
|
| 1861 | + /** |
|
| 1862 | + * draw a curve (for border radius) |
|
| 1863 | + * |
|
| 1864 | + * @access protected |
|
| 1865 | + * @param double[] $pt |
|
| 1866 | + * @param array $color |
|
| 1867 | + */ |
|
| 1868 | + protected function _drawCurve($pt, $color) |
|
| 1869 | + { |
|
| 1870 | + $this->pdf->setFillColorArray($color); |
|
| 1871 | + |
|
| 1872 | + if (count($pt) == 10) |
|
| 1873 | + $this->pdf->drawCurve($pt[0], $pt[1], $pt[2], $pt[3], $pt[4], $pt[5], $pt[6], $pt[7], $pt[8], $pt[9]); |
|
| 1874 | + else |
|
| 1875 | + $this->pdf->drawCorner($pt[0], $pt[1], $pt[2], $pt[3], $pt[4], $pt[5], $pt[6], $pt[7]); |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + /** |
|
| 1879 | + * draw a ligne with a specific type, and specific start and end for radius |
|
| 1880 | + * |
|
| 1881 | + * @access protected |
|
| 1882 | + * @param array $pt |
|
| 1883 | + * @param float $color |
|
| 1884 | + * @param string $type (dashed, dotted, double, solid) |
|
| 1885 | + * @param float $width |
|
| 1886 | + * @param integer $radius (binary from 0 to 3 with 1=>start with a radius, 2=>end with a radius) |
|
| 1887 | + */ |
|
| 1888 | + protected function _drawLine($pt, $color, $type, $width, $radius = 3) |
|
| 1889 | + { |
|
| 1890 | + // set the fill color |
|
| 1891 | + $this->pdf->setFillColorArray($color); |
|
| 1892 | + |
|
| 1893 | + // if dashed or dotted |
|
| 1894 | + if ($type == 'dashed' || $type == 'dotted') { |
|
| 1895 | + |
|
| 1896 | + // clean the end of the line, if radius |
|
| 1897 | + if ($radius == 1) { |
|
| 1898 | + $tmp = array(); $tmp[] = $pt[0]; $tmp[] = $pt[1]; $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[8]; $tmp[] = $pt[9]; |
|
| 1899 | + $this->pdf->Polygon($tmp, 'F'); |
|
| 1900 | + |
|
| 1901 | + $tmp = array(); $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[4]; $tmp[] = $pt[5]; $tmp[] = $pt[6]; $tmp[] = $pt[7]; $tmp[] = $pt[8]; $tmp[] = $pt[9]; |
|
| 1902 | + $pt = $tmp; |
|
| 1903 | + } else if ($radius == 2) { |
|
| 1904 | + $tmp = array(); $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[4]; $tmp[] = $pt[5]; $tmp[] = $pt[6]; $tmp[] = $pt[7]; |
|
| 1905 | + $this->pdf->Polygon($tmp, 'F'); |
|
| 1906 | + |
|
| 1907 | + $tmp = array(); $tmp[] = $pt[0]; $tmp[] = $pt[1]; $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[6]; $tmp[] = $pt[7]; $tmp[] = $pt[8]; $tmp[] = $pt[9]; |
|
| 1908 | + $pt = $tmp; |
|
| 1909 | + } else if ($radius == 3) { |
|
| 1910 | + $tmp = array(); $tmp[] = $pt[0]; $tmp[] = $pt[1]; $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[10]; $tmp[] = $pt[11]; |
|
| 1911 | + $this->pdf->Polygon($tmp, 'F'); |
|
| 1912 | + |
|
| 1913 | + $tmp = array(); $tmp[] = $pt[4]; $tmp[] = $pt[5]; $tmp[] = $pt[6]; $tmp[] = $pt[7]; $tmp[] = $pt[8]; $tmp[] = $pt[9]; |
|
| 1914 | + $this->pdf->Polygon($tmp, 'F'); |
|
| 1915 | + |
|
| 1916 | + $tmp = array(); $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[4]; $tmp[] = $pt[5]; $tmp[] = $pt[8]; $tmp[] = $pt[9]; $tmp[] = $pt[10]; $tmp[] = $pt[11]; |
|
| 1917 | + $pt = $tmp; |
|
| 1918 | + } |
|
| 1919 | + |
|
| 1920 | + // horisontal or vertical line |
|
| 1921 | + if ($pt[2] == $pt[0]) { |
|
| 1922 | + $l = abs(($pt[3] - $pt[1]) * 0.5); |
|
| 1923 | + $px = 0; |
|
| 1924 | + $py = $width; |
|
| 1925 | + $x1 = $pt[0]; $y1 = ($pt[3] + $pt[1]) * 0.5; |
|
| 1926 | + $x2 = $pt[6]; $y2 = ($pt[7] + $pt[5]) * 0.5; |
|
| 1927 | + } else { |
|
| 1928 | + $l = abs(($pt[2] - $pt[0]) * 0.5); |
|
| 1929 | + $px = $width; |
|
| 1930 | + $py = 0; |
|
| 1931 | + $x1 = ($pt[2] + $pt[0]) * 0.5; $y1 = $pt[1]; |
|
| 1932 | + $x2 = ($pt[6] + $pt[4]) * 0.5; $y2 = $pt[7]; |
|
| 1933 | + } |
|
| 1934 | + |
|
| 1935 | + // if dashed : 3x bigger than dotted |
|
| 1936 | + if ($type == 'dashed') { |
|
| 1937 | + $px = $px * 3.; |
|
| 1938 | + $py = $py * 3.; |
|
| 1939 | + } |
|
| 1940 | + $mode = ($l / ($px + $py) < .5); |
|
| 1941 | + |
|
| 1942 | + // display the dotted/dashed line |
|
| 1943 | + for ($i = 0; $l - ($px + $py) * ($i - 0.5) > 0; $i++) { |
|
| 1944 | + if (($i % 2) == $mode) { |
|
| 1945 | + $j = $i - 0.5; |
|
| 1946 | + $lx1 = $px * ($j); if ($lx1 < -$l) $lx1 = -$l; |
|
| 1947 | + $ly1 = $py * ($j); if ($ly1 < -$l) $ly1 = -$l; |
|
| 1948 | + $lx2 = $px * ($j + 1); if ($lx2 > $l) $lx2 = $l; |
|
| 1949 | + $ly2 = $py * ($j + 1); if ($ly2 > $l) $ly2 = $l; |
|
| 1950 | + |
|
| 1951 | + $tmp = array(); |
|
| 1952 | + $tmp[] = $x1 + $lx1; $tmp[] = $y1 + $ly1; |
|
| 1953 | + $tmp[] = $x1 + $lx2; $tmp[] = $y1 + $ly2; |
|
| 1954 | + $tmp[] = $x2 + $lx2; $tmp[] = $y2 + $ly2; |
|
| 1955 | + $tmp[] = $x2 + $lx1; $tmp[] = $y2 + $ly1; |
|
| 1956 | + $this->pdf->Polygon($tmp, 'F'); |
|
| 1957 | + |
|
| 1958 | + if ($j > 0) { |
|
| 1959 | + $tmp = array(); |
|
| 1960 | + $tmp[] = $x1 - $lx1; $tmp[] = $y1 - $ly1; |
|
| 1961 | + $tmp[] = $x1 - $lx2; $tmp[] = $y1 - $ly2; |
|
| 1962 | + $tmp[] = $x2 - $lx2; $tmp[] = $y2 - $ly2; |
|
| 1963 | + $tmp[] = $x2 - $lx1; $tmp[] = $y2 - $ly1; |
|
| 1964 | + $this->pdf->Polygon($tmp, 'F'); |
|
| 1965 | + } |
|
| 1966 | + } |
|
| 1967 | + } |
|
| 1968 | + } else if ($type == 'double') { |
|
| 1969 | + |
|
| 1970 | + // if double, 2 lines : 0=>1/3 and 2/3=>1 |
|
| 1971 | + $pt1 = $pt; |
|
| 1972 | + $pt2 = $pt; |
|
| 1973 | + |
|
| 1974 | + if (count($pt) == 12) { |
|
| 1975 | + // line 1 |
|
| 1976 | + $pt1[0] = ($pt[0] - $pt[10]) * 0.33 + $pt[10]; |
|
| 1977 | + $pt1[1] = ($pt[1] - $pt[11]) * 0.33 + $pt[11]; |
|
| 1978 | + $pt1[2] = ($pt[2] - $pt[10]) * 0.33 + $pt[10]; |
|
| 1979 | + $pt1[3] = ($pt[3] - $pt[11]) * 0.33 + $pt[11]; |
|
| 1980 | + $pt1[4] = ($pt[4] - $pt[8]) * 0.33 + $pt[8]; |
|
| 1981 | + $pt1[5] = ($pt[5] - $pt[9]) * 0.33 + $pt[9]; |
|
| 1982 | + $pt1[6] = ($pt[6] - $pt[8]) * 0.33 + $pt[8]; |
|
| 1983 | + $pt1[7] = ($pt[7] - $pt[9]) * 0.33 + $pt[9]; |
|
| 1984 | + $pt2[10] = ($pt[10] - $pt[0]) * 0.33 + $pt[0]; |
|
| 1985 | + $pt2[11] = ($pt[11] - $pt[1]) * 0.33 + $pt[1]; |
|
| 1986 | + |
|
| 1987 | + // line 2 |
|
| 1988 | + $pt2[2] = ($pt[2] - $pt[0]) * 0.33 + $pt[0]; |
|
| 1989 | + $pt2[3] = ($pt[3] - $pt[1]) * 0.33 + $pt[1]; |
|
| 1990 | + $pt2[4] = ($pt[4] - $pt[6]) * 0.33 + $pt[6]; |
|
| 1991 | + $pt2[5] = ($pt[5] - $pt[7]) * 0.33 + $pt[7]; |
|
| 1992 | + $pt2[8] = ($pt[8] - $pt[6]) * 0.33 + $pt[6]; |
|
| 1993 | + $pt2[9] = ($pt[9] - $pt[7]) * 0.33 + $pt[7]; |
|
| 1994 | + } else { |
|
| 1995 | + // line 1 |
|
| 1996 | + $pt1[0] = ($pt[0] - $pt[6]) * 0.33 + $pt[6]; |
|
| 1997 | + $pt1[1] = ($pt[1] - $pt[7]) * 0.33 + $pt[7]; |
|
| 1998 | + $pt1[2] = ($pt[2] - $pt[4]) * 0.33 + $pt[4]; |
|
| 1999 | + $pt1[3] = ($pt[3] - $pt[5]) * 0.33 + $pt[5]; |
|
| 2000 | + |
|
| 2001 | + // line 2 |
|
| 2002 | + $pt2[6] = ($pt[6] - $pt[0]) * 0.33 + $pt[0]; |
|
| 2003 | + $pt2[7] = ($pt[7] - $pt[1]) * 0.33 + $pt[1]; |
|
| 2004 | + $pt2[4] = ($pt[4] - $pt[2]) * 0.33 + $pt[2]; |
|
| 2005 | + $pt2[5] = ($pt[5] - $pt[3]) * 0.33 + $pt[3]; |
|
| 2006 | + } |
|
| 2007 | + $this->pdf->Polygon($pt1, 'F'); |
|
| 2008 | + $this->pdf->Polygon($pt2, 'F'); |
|
| 2009 | + } else if ($type == 'solid') { |
|
| 2010 | + // solid line : draw directly the polygon |
|
| 2011 | + $this->pdf->Polygon($pt, 'F'); |
|
| 2012 | + } |
|
| 2013 | + } |
|
| 2014 | + |
|
| 2015 | + /** |
|
| 2016 | + * prepare a transform matrix, only for drawing a SVG graphic |
|
| 2017 | + * |
|
| 2018 | + * @access protected |
|
| 2019 | + * @param string $transform |
|
| 2020 | + * @return array $matrix |
|
| 2021 | + */ |
|
| 2022 | + protected function _prepareTransform($transform) |
|
| 2023 | + { |
|
| 2024 | + // it can not be empty |
|
| 2025 | + if ( ! $transform) return null; |
|
| 2026 | + |
|
| 2027 | + // sctions must be like scale(...) |
|
| 2028 | + if ( ! preg_match_all('/([a-z]+)\(([^\)]*)\)/isU', $transform, $match)) return null; |
|
| 2029 | + |
|
| 2030 | + // prepare the list of the actions |
|
| 2031 | + $actions = array(); |
|
| 2032 | + |
|
| 2033 | + // for actions |
|
| 2034 | + for ($k = 0; $k < count($match[0]); $k++) { |
|
| 2035 | + |
|
| 2036 | + // get the name of the action |
|
| 2037 | + $name = strtolower($match[1][$k]); |
|
| 2038 | + |
|
| 2039 | + // get the parameters of the action |
|
| 2040 | + $val = explode(',', trim($match[2][$k])); |
|
| 2041 | + foreach ($val as $i => $j) { |
|
| 2042 | + $val[$i] = trim($j); |
|
| 2043 | + } |
|
| 2044 | + |
|
| 2045 | + // prepare the matrix, depending on the action |
|
| 2046 | + switch ($name) |
|
| 2047 | + { |
|
| 2048 | + case 'scale': |
|
| 2049 | + if ( ! isset($val[0])) $val[0] = 1.; else $val[0] = 1. * $val[0]; |
|
| 2050 | + if ( ! isset($val[1])) $val[1] = $val[0]; else $val[1] = 1. * $val[1]; |
|
| 2051 | + $actions[] = array($val[0], 0, 0, $val[1], 0, 0); |
|
| 2052 | + break; |
|
| 2053 | + |
|
| 2054 | + case 'translate': |
|
| 2055 | + if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $this->parsingCss->ConvertToMM($val[0], $this->_isInDraw['w']); |
|
| 2056 | + if ( ! isset($val[1])) $val[1] = 0.; else $val[1] = $this->parsingCss->ConvertToMM($val[1], $this->_isInDraw['h']); |
|
| 2057 | + $actions[] = array(1, 0, 0, 1, $val[0], $val[1]); |
|
| 2058 | + break; |
|
| 2059 | + |
|
| 2060 | + case 'rotate': |
|
| 2061 | + if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $val[0] * M_PI / 180.; |
|
| 2062 | + if ( ! isset($val[1])) $val[1] = 0.; else $val[1] = $this->parsingCss->ConvertToMM($val[1], $this->_isInDraw['w']); |
|
| 2063 | + if ( ! isset($val[2])) $val[2] = 0.; else $val[2] = $this->parsingCss->ConvertToMM($val[2], $this->_isInDraw['h']); |
|
| 2064 | + if ($val[1] || $val[2]) $actions[] = array(1, 0, 0, 1, -$val[1], -$val[2]); |
|
| 2065 | + $actions[] = array(cos($val[0]), sin($val[0]), -sin($val[0]), cos($val[0]), 0, 0); |
|
| 2066 | + if ($val[1] || $val[2]) $actions[] = array(1, 0, 0, 1, $val[1], $val[2]); |
|
| 2067 | + break; |
|
| 2068 | + |
|
| 2069 | + case 'skewx': |
|
| 2070 | + if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $val[0] * M_PI / 180.; |
|
| 2071 | + $actions[] = array(1, 0, tan($val[0]), 1, 0, 0); |
|
| 2072 | + break; |
|
| 2073 | + |
|
| 2074 | + case 'skewy': |
|
| 2075 | + if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $val[0] * M_PI / 180.; |
|
| 2076 | + $actions[] = array(1, tan($val[0]), 0, 1, 0, 0); |
|
| 2077 | + break; |
|
| 2078 | + case 'matrix': |
|
| 2079 | + if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $val[0] * 1.; |
|
| 2080 | + if ( ! isset($val[1])) $val[1] = 0.; else $val[1] = $val[1] * 1.; |
|
| 2081 | + if ( ! isset($val[2])) $val[2] = 0.; else $val[2] = $val[2] * 1.; |
|
| 2082 | + if ( ! isset($val[3])) $val[3] = 0.; else $val[3] = $val[3] * 1.; |
|
| 2083 | + if ( ! isset($val[4])) $val[4] = 0.; else $val[4] = $this->parsingCss->ConvertToMM($val[4], $this->_isInDraw['w']); |
|
| 2084 | + if ( ! isset($val[5])) $val[5] = 0.; else $val[5] = $this->parsingCss->ConvertToMM($val[5], $this->_isInDraw['h']); |
|
| 2085 | + $actions[] = $val; |
|
| 2086 | + break; |
|
| 2087 | + } |
|
| 2088 | + } |
|
| 2089 | + |
|
| 2090 | + // if ther is no actions => return |
|
| 2091 | + if ( ! $actions) return null; |
|
| 2092 | + |
|
| 2093 | + // get the first matrix |
|
| 2094 | + $m = $actions[0]; unset($actions[0]); |
|
| 2095 | + |
|
| 2096 | + // foreach matrix => multiply to the last matrix |
|
| 2097 | + foreach ($actions as $n) { |
|
| 2098 | + $m = array( |
|
| 2099 | + $m[0] * $n[0] + $m[2] * $n[1], |
|
| 2100 | + $m[1] * $n[0] + $m[3] * $n[1], |
|
| 2101 | + $m[0] * $n[2] + $m[2] * $n[3], |
|
| 2102 | + $m[1] * $n[2] + $m[3] * $n[3], |
|
| 2103 | + $m[0] * $n[4] + $m[2] * $n[5] + $m[4], |
|
| 2104 | + $m[1] * $n[4] + $m[3] * $n[5] + $m[5] |
|
| 2105 | + ); |
|
| 2106 | + } |
|
| 2107 | + |
|
| 2108 | + // return the matrix |
|
| 2109 | + return $m; |
|
| 2110 | + } |
|
| 2111 | + |
|
| 2112 | + /** |
|
| 2113 | + * @access protected |
|
| 2114 | + * @param &array $cases |
|
| 2115 | + * @param &array $corr |
|
| 2116 | + */ |
|
| 2117 | + protected function _calculateTableCellSize(&$cases, &$corr) |
|
| 2118 | + { |
|
| 2119 | + if ( ! isset($corr[0])) return true; |
|
| 2120 | + |
|
| 2121 | + // for each cell without colspan, we get the max width for each column |
|
| 2122 | + $sw = array(); |
|
| 2123 | + for ($x = 0; $x < count($corr[0]); $x++) { |
|
| 2124 | + $m = 0; |
|
| 2125 | + for ($y = 0; $y < count($corr); $y++) { |
|
| 2126 | + if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][2] == 1) { |
|
| 2127 | + $m = max($m, $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w']); |
|
| 2128 | + } |
|
| 2129 | + } |
|
| 2130 | + $sw[$x] = $m; |
|
| 2131 | + } |
|
| 2132 | + |
|
| 2133 | + // for each cell with colspan, we adapt the width of each column |
|
| 2134 | + for ($x = 0; $x < count($corr[0]); $x++) { |
|
| 2135 | + for ($y = 0; $y < count($corr); $y++) { |
|
| 2136 | + if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][2] > 1) { |
|
| 2137 | + |
|
| 2138 | + // sum the max width of each column in colspan |
|
| 2139 | + $s = 0; for ($i = 0; $i < $corr[$y][$x][2]; $i++) $s += $sw[$x + $i]; |
|
| 2140 | + |
|
| 2141 | + // if the max width is < the width of the cell with colspan => we adapt the width of each max width |
|
| 2142 | + if ($s > 0 && $s < $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w']) { |
|
| 2143 | + for ($i = 0; $i < $corr[$y][$x][2]; $i++) { |
|
| 2144 | + $sw[$x + $i] = $sw[$x + $i] / $s * $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w']; |
|
| 2145 | + } |
|
| 2146 | + } |
|
| 2147 | + } |
|
| 2148 | + } |
|
| 2149 | + } |
|
| 2150 | + |
|
| 2151 | + // set the new width, for each cell |
|
| 2152 | + for ($x = 0; $x < count($corr[0]); $x++) { |
|
| 2153 | + for ($y = 0; $y < count($corr); $y++) { |
|
| 2154 | + if (isset($corr[$y][$x]) && is_array($corr[$y][$x])) { |
|
| 2155 | + // without colspan |
|
| 2156 | + if ($corr[$y][$x][2] == 1) { |
|
| 2157 | + $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'] = $sw[$x]; |
|
| 2158 | + // with colspan |
|
| 2159 | + } else { |
|
| 2160 | + $s = 0; |
|
| 2161 | + for ($i = 0; $i < $corr[$y][$x][2]; $i++) { |
|
| 2162 | + $s += $sw[$x + $i]; |
|
| 2163 | + } |
|
| 2164 | + $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'] = $s; |
|
| 2165 | + } |
|
| 2166 | + } |
|
| 2167 | + } |
|
| 2168 | + } |
|
| 2169 | + |
|
| 2170 | + // for each cell without rowspan, we get the max height for each line |
|
| 2171 | + $sh = array(); |
|
| 2172 | + for ($y = 0; $y < count($corr); $y++) { |
|
| 2173 | + $m = 0; |
|
| 2174 | + for ($x = 0; $x < count($corr[0]); $x++) { |
|
| 2175 | + if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][3] == 1) { |
|
| 2176 | + $m = max($m, $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h']); |
|
| 2177 | + } |
|
| 2178 | + } |
|
| 2179 | + $sh[$y] = $m; |
|
| 2180 | + } |
|
| 2181 | + |
|
| 2182 | + // for each cell with rowspan, we adapt the height of each line |
|
| 2183 | + for ($y = 0; $y < count($corr); $y++) { |
|
| 2184 | + for ($x = 0; $x < count($corr[0]); $x++) { |
|
| 2185 | + if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][3] > 1) { |
|
| 2186 | + |
|
| 2187 | + // sum the max height of each line in rowspan |
|
| 2188 | + $s = 0; for ($i = 0; $i < $corr[$y][$x][3]; $i++) $s += $sh[$y + $i]; |
|
| 2189 | + |
|
| 2190 | + // if the max height is < the height of the cell with rowspan => we adapt the height of each max height |
|
| 2191 | + if ($s > 0 && $s < $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h']) { |
|
| 2192 | + for ($i = 0; $i < $corr[$y][$x][3]; $i++) { |
|
| 2193 | + $sh[$y + $i] = $sh[$y + $i] / $s * $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h']; |
|
| 2194 | + } |
|
| 2195 | + } |
|
| 2196 | + } |
|
| 2197 | + } |
|
| 2198 | + } |
|
| 2199 | + |
|
| 2200 | + // set the new height, for each cell |
|
| 2201 | + for ($y = 0; $y < count($corr); $y++) { |
|
| 2202 | + for ($x = 0; $x < count($corr[0]); $x++) { |
|
| 2203 | + if (isset($corr[$y][$x]) && is_array($corr[$y][$x])) { |
|
| 2204 | + // without rowspan |
|
| 2205 | + if ($corr[$y][$x][3] == 1) { |
|
| 2206 | + $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'] = $sh[$y]; |
|
| 2207 | + // with rowspan |
|
| 2208 | + } else { |
|
| 2209 | + $s = 0; |
|
| 2210 | + for ($i = 0; $i < $corr[$y][$x][3]; $i++) { |
|
| 2211 | + $s += $sh[$y + $i]; |
|
| 2212 | + } |
|
| 2213 | + $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'] = $s; |
|
| 2214 | + |
|
| 2215 | + for ($j = 1; $j < $corr[$y][$x][3]; $j++) { |
|
| 2216 | + $tx = $x + 1; |
|
| 2217 | + $ty = $y + $j; |
|
| 2218 | + for (true; isset($corr[$ty][$tx]) && ! is_array($corr[$ty][$tx]); $tx++); |
|
| 2219 | + if (isset($corr[$ty][$tx])) { |
|
| 2220 | + $cases[$corr[$ty][$tx][1]][$corr[$ty][$tx][0]]['dw'] += $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w']; |
|
| 2221 | + } |
|
| 2222 | + } |
|
| 2223 | + } |
|
| 2224 | + } |
|
| 2225 | + } |
|
| 2226 | + } |
|
| 2227 | + } |
|
| 2228 | + |
|
| 2229 | + /** |
|
| 2230 | + * tag : PAGE |
|
| 2231 | + * mode : OPEN |
|
| 2232 | + * |
|
| 2233 | + * @param array $param |
|
| 2234 | + * @return boolean |
|
| 2235 | + */ |
|
| 2236 | + protected function _tag_open_PAGE($param) |
|
| 2237 | + { |
|
| 2238 | + if ($this->_isForOneLine) return false; |
|
| 2239 | + if ($this->_debugActif) $this->_DEBUG_add('PAGE '.($this->_page + 1), true); |
|
| 2240 | + |
|
| 2241 | + $newPageSet = ( ! isset($param['pageset']) || $param['pageset'] != 'old'); |
|
| 2242 | + |
|
| 2243 | + $resetPageNumber = (isset($param['pagegroup']) && $param['pagegroup'] == 'new'); |
|
| 2244 | + |
|
| 2245 | + $this->_maxH = 0; |
|
| 2246 | + |
|
| 2247 | + // if new page set asked |
|
| 2248 | + if ($newPageSet) { |
|
| 2249 | + $this->_subHEADER = array(); |
|
| 2250 | + $this->_subFOOTER = array(); |
|
| 2251 | + |
|
| 2252 | + // orientation |
|
| 2253 | + $orientation = ''; |
|
| 2254 | + if (isset($param['orientation'])) { |
|
| 2255 | + $param['orientation'] = strtolower($param['orientation']); |
|
| 2256 | + if ($param['orientation'] == 'p') $orientation = 'P'; |
|
| 2257 | + if ($param['orientation'] == 'portrait') $orientation = 'P'; |
|
| 2258 | + |
|
| 2259 | + if ($param['orientation'] == 'l') $orientation = 'L'; |
|
| 2260 | + if ($param['orientation'] == 'paysage') $orientation = 'L'; |
|
| 2261 | + if ($param['orientation'] == 'landscape') $orientation = 'L'; |
|
| 2262 | + } |
|
| 2263 | + |
|
| 2264 | + // format |
|
| 2265 | + $format = null; |
|
| 2266 | + if (isset($param['format'])) { |
|
| 2267 | + $format = strtolower($param['format']); |
|
| 2268 | + if (preg_match('/^([0-9]+)x([0-9]+)$/isU', $format, $match)) { |
|
| 2269 | + $format = array(intval($match[1]), intval($match[2])); |
|
| 2270 | + } |
|
| 2271 | + } |
|
| 2272 | + |
|
| 2273 | + // background |
|
| 2274 | + $background = array(); |
|
| 2275 | + if (isset($param['backimg'])) { |
|
| 2276 | + $background['img'] = isset($param['backimg']) ? $param['backimg'] : ''; // src of the image |
|
| 2277 | + $background['posX'] = isset($param['backimgx']) ? $param['backimgx'] : 'center'; // horizontale position of the image |
|
| 2278 | + $background['posY'] = isset($param['backimgy']) ? $param['backimgy'] : 'middle'; // vertical position of the image |
|
| 2279 | + $background['width'] = isset($param['backimgw']) ? $param['backimgw'] : '100%'; // width of the image (100% = page width) |
|
| 2280 | + |
|
| 2281 | + // convert the src of the image, if parameters |
|
| 2282 | + $background['img'] = str_replace('&', '&', $background['img']); |
|
| 2283 | + |
|
| 2284 | + // convert the positions |
|
| 2285 | + if ($background['posX'] == 'left') $background['posX'] = '0%'; |
|
| 2286 | + if ($background['posX'] == 'center') $background['posX'] = '50%'; |
|
| 2287 | + if ($background['posX'] == 'right') $background['posX'] = '100%'; |
|
| 2288 | + if ($background['posY'] == 'top') $background['posY'] = '0%'; |
|
| 2289 | + if ($background['posY'] == 'middle') $background['posY'] = '50%'; |
|
| 2290 | + if ($background['posY'] == 'bottom') $background['posY'] = '100%'; |
|
| 2291 | + |
|
| 2292 | + if ($background['img']) { |
|
| 2293 | + // get the size of the image |
|
| 2294 | + // WARNING : if URL, "allow_url_fopen" must turned to "on" in php.ini |
|
| 2295 | + $infos = @getimagesize($background['img']); |
|
| 2296 | + if (count($infos) > 1) { |
|
| 2297 | + $imageWidth = $this->parsingCss->ConvertToMM($background['width'], $this->pdf->getW()); |
|
| 2298 | + $imageHeight = $imageWidth * $infos[1] / $infos[0]; |
|
| 2299 | + |
|
| 2300 | + $background['width'] = $imageWidth; |
|
| 2301 | + $background['posX'] = $this->parsingCss->ConvertToMM($background['posX'], $this->pdf->getW() - $imageWidth); |
|
| 2302 | + $background['posY'] = $this->parsingCss->ConvertToMM($background['posY'], $this->pdf->getH() - $imageHeight); |
|
| 2303 | + } else { |
|
| 2304 | + $background = array(); |
|
| 2305 | + } |
|
| 2306 | + } else { |
|
| 2307 | + $background = array(); |
|
| 2308 | + } |
|
| 2309 | + } |
|
| 2310 | + |
|
| 2311 | + // margins of the page |
|
| 2312 | + $background['top'] = isset($param['backtop']) ? $param['backtop'] : '0'; |
|
| 2313 | + $background['bottom'] = isset($param['backbottom']) ? $param['backbottom'] : '0'; |
|
| 2314 | + $background['left'] = isset($param['backleft']) ? $param['backleft'] : '0'; |
|
| 2315 | + $background['right'] = isset($param['backright']) ? $param['backright'] : '0'; |
|
| 2316 | + |
|
| 2317 | + // if no unit => mm |
|
| 2318 | + if (preg_match('/^([0-9]*)$/isU', $background['top'])) { |
|
| 2319 | + $background['top'] .= 'mm'; |
|
| 2320 | + } |
|
| 2321 | + if (preg_match('/^([0-9]*)$/isU', $background['bottom'])) { |
|
| 2322 | + $background['bottom'] .= 'mm'; |
|
| 2323 | + } |
|
| 2324 | + if (preg_match('/^([0-9]*)$/isU', $background['left'])) { |
|
| 2325 | + $background['left'] .= 'mm'; |
|
| 2326 | + } |
|
| 2327 | + if (preg_match('/^([0-9]*)$/isU', $background['right'])) { |
|
| 2328 | + $background['right'] .= 'mm'; |
|
| 2329 | + } |
|
| 2330 | + |
|
| 2331 | + // convert to mm |
|
| 2332 | + $background['top'] = $this->parsingCss->ConvertToMM($background['top'], $this->pdf->getH()); |
|
| 2333 | + $background['bottom'] = $this->parsingCss->ConvertToMM($background['bottom'], $this->pdf->getH()); |
|
| 2334 | + $background['left'] = $this->parsingCss->ConvertToMM($background['left'], $this->pdf->getW()); |
|
| 2335 | + $background['right'] = $this->parsingCss->ConvertToMM($background['right'], $this->pdf->getW()); |
|
| 2336 | + |
|
| 2337 | + // get the background color |
|
| 2338 | + $res = false; |
|
| 2339 | + $background['color'] = isset($param['backcolor']) ? $this->parsingCss->convertToColor($param['backcolor'], $res) : null; |
|
| 2340 | + if ( ! $res) $background['color'] = null; |
|
| 2341 | + |
|
| 2342 | + $this->parsingCss->save(); |
|
| 2343 | + $this->parsingCss->analyse('PAGE', $param); |
|
| 2344 | + $this->parsingCss->setPosition(); |
|
| 2345 | + $this->parsingCss->fontSet(); |
|
| 2346 | + |
|
| 2347 | + // new page |
|
| 2348 | + $this->_setNewPage($format, $orientation, $background, null, $resetPageNumber); |
|
| 2349 | + |
|
| 2350 | + // automatic footer |
|
| 2351 | + if (isset($param['footer'])) { |
|
| 2352 | + $lst = explode(';', $param['footer']); |
|
| 2353 | + foreach ($lst as $key => $val) { |
|
| 2354 | + $lst[$key] = trim(strtolower($val)); |
|
| 2355 | + } |
|
| 2356 | + $page = in_array('page', $lst); |
|
| 2357 | + $date = in_array('date', $lst); |
|
| 2358 | + $hour = in_array('heure', $lst); |
|
| 2359 | + $form = in_array('form', $lst); |
|
| 2360 | + } else { |
|
| 2361 | + $page = null; |
|
| 2362 | + $date = null; |
|
| 2363 | + $hour = null; |
|
| 2364 | + $form = null; |
|
| 2365 | + } |
|
| 2366 | + $this->pdf->SetMyFooter($page, $date, $hour, $form); |
|
| 2367 | + // else => we use the last page set used |
|
| 2368 | + } else { |
|
| 2369 | + $this->parsingCss->save(); |
|
| 2370 | + $this->parsingCss->analyse('PAGE', $param); |
|
| 2371 | + $this->parsingCss->setPosition(); |
|
| 2372 | + $this->parsingCss->fontSet(); |
|
| 2373 | + |
|
| 2374 | + $this->_setNewPage(null, null, null, null, $resetPageNumber); |
|
| 2375 | + } |
|
| 2376 | + |
|
| 2377 | + return true; |
|
| 2378 | + } |
|
| 2379 | + |
|
| 2380 | + /** |
|
| 2381 | + * tag : PAGE |
|
| 2382 | + * mode : CLOSE |
|
| 2383 | + * |
|
| 2384 | + * @param array $param |
|
| 2385 | + * @return boolean |
|
| 2386 | + */ |
|
| 2387 | + protected function _tag_close_PAGE($param) |
|
| 2388 | + { |
|
| 2389 | + if ($this->_isForOneLine) { |
|
| 2390 | + return false; |
|
| 2391 | + } |
|
| 2392 | + |
|
| 2393 | + $this->_maxH = 0; |
|
| 2394 | + |
|
| 2395 | + $this->parsingCss->load(); |
|
| 2396 | + $this->parsingCss->fontSet(); |
|
| 2397 | + |
|
| 2398 | + if ($this->_debugActif) { |
|
| 2399 | + $this->_DEBUG_add('PAGE '.$this->_page, false); |
|
| 2400 | + } |
|
| 2401 | + |
|
| 2402 | + return true; |
|
| 2403 | + } |
|
| 2404 | + |
|
| 2405 | + /** |
|
| 2406 | + * tag : PAGE_HEADER |
|
| 2407 | + * mode : OPEN |
|
| 2408 | + * |
|
| 2409 | + * @param array $param |
|
| 2410 | + * @return boolean |
|
| 2411 | + */ |
|
| 2412 | + protected function _tag_open_PAGE_HEADER($param) |
|
| 2413 | + { |
|
| 2414 | + if ($this->_isForOneLine) return false; |
|
| 2415 | + |
|
| 2416 | + $this->_subHEADER = array(); |
|
| 2417 | + for ($this->_parsePos; $this->_parsePos < count($this->parsingHtml->code); $this->_parsePos++) { |
|
| 2418 | + $action = $this->parsingHtml->code[$this->_parsePos]; |
|
| 2419 | + if ($action['name'] == 'page_header') $action['name'] = 'page_header_sub'; |
|
| 2420 | + $this->_subHEADER[] = $action; |
|
| 2421 | + if (strtolower($action['name']) == 'page_header_sub' && $action['close']) break; |
|
| 2422 | + } |
|
| 2423 | + |
|
| 2424 | + $this->_setPageHeader(); |
|
| 2425 | + |
|
| 2426 | + return true; |
|
| 2427 | + } |
|
| 2428 | + |
|
| 2429 | + /** |
|
| 2430 | + * tag : PAGE_FOOTER |
|
| 2431 | + * mode : OPEN |
|
| 2432 | + * |
|
| 2433 | + * @param array $param |
|
| 2434 | + * @return boolean |
|
| 2435 | + */ |
|
| 2436 | + protected function _tag_open_PAGE_FOOTER($param) |
|
| 2437 | + { |
|
| 2438 | + if ($this->_isForOneLine) return false; |
|
| 2439 | + |
|
| 2440 | + $this->_subFOOTER = array(); |
|
| 2441 | + for ($this->_parsePos; $this->_parsePos < count($this->parsingHtml->code); $this->_parsePos++) { |
|
| 2442 | + $action = $this->parsingHtml->code[$this->_parsePos]; |
|
| 2443 | + if ($action['name'] == 'page_footer') $action['name'] = 'page_footer_sub'; |
|
| 2444 | + $this->_subFOOTER[] = $action; |
|
| 2445 | + if (strtolower($action['name']) == 'page_footer_sub' && $action['close']) break; |
|
| 2446 | + } |
|
| 2447 | + |
|
| 2448 | + $this->_setPageFooter(); |
|
| 2449 | + |
|
| 2450 | + return true; |
|
| 2451 | + } |
|
| 2452 | + |
|
| 2453 | + /** |
|
| 2454 | + * It is not a real tag. Does not use it directly |
|
| 2455 | + * |
|
| 2456 | + * @param array $param |
|
| 2457 | + * @return boolean |
|
| 2458 | + */ |
|
| 2459 | + protected function _tag_open_PAGE_HEADER_SUB($param) |
|
| 2460 | + { |
|
| 2461 | + if ($this->_isForOneLine) { |
|
| 2462 | + return false; |
|
| 2463 | + } |
|
| 2464 | + |
|
| 2465 | + // save the current stat |
|
| 2466 | + $this->_subSTATES = array(); |
|
| 2467 | + $this->_subSTATES['x'] = $this->pdf->getX(); |
|
| 2468 | + $this->_subSTATES['y'] = $this->pdf->getY(); |
|
| 2469 | + $this->_subSTATES['s'] = $this->parsingCss->value; |
|
| 2470 | + $this->_subSTATES['t'] = $this->parsingCss->table; |
|
| 2471 | + $this->_subSTATES['ml'] = $this->_margeLeft; |
|
| 2472 | + $this->_subSTATES['mr'] = $this->_margeRight; |
|
| 2473 | + $this->_subSTATES['mt'] = $this->_margeTop; |
|
| 2474 | + $this->_subSTATES['mb'] = $this->_margeBottom; |
|
| 2475 | + $this->_subSTATES['mp'] = $this->_pageMarges; |
|
| 2476 | + |
|
| 2477 | + // new stat for the header |
|
| 2478 | + $this->_pageMarges = array(); |
|
| 2479 | + $this->_margeLeft = $this->_defaultLeft; |
|
| 2480 | + $this->_margeRight = $this->_defaultRight; |
|
| 2481 | + $this->_margeTop = $this->_defaultTop; |
|
| 2482 | + $this->_margeBottom = $this->_defaultBottom; |
|
| 2483 | + $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight); |
|
| 2484 | + $this->pdf->SetAutoPageBreak(false, $this->_margeBottom); |
|
| 2485 | + $this->pdf->setXY($this->_defaultLeft, $this->_defaultTop); |
|
| 2486 | + |
|
| 2487 | + $this->parsingCss->initStyle(); |
|
| 2488 | + $this->parsingCss->resetStyle(); |
|
| 2489 | + $this->parsingCss->value['width'] = $this->pdf->getW() - $this->_defaultLeft - $this->_defaultRight; |
|
| 2490 | + $this->parsingCss->table = array(); |
|
| 2491 | + |
|
| 2492 | + $this->parsingCss->save(); |
|
| 2493 | + $this->parsingCss->analyse('page_header_sub', $param); |
|
| 2494 | + $this->parsingCss->setPosition(); |
|
| 2495 | + $this->parsingCss->fontSet(); |
|
| 2496 | + $this->_setNewPositionForNewLine(); |
|
| 2497 | + return true; |
|
| 2498 | + } |
|
| 2499 | + |
|
| 2500 | + /** |
|
| 2501 | + * It is not a real tag. Does not use it directly |
|
| 2502 | + * |
|
| 2503 | + * @param array $param |
|
| 2504 | + * @return boolean |
|
| 2505 | + */ |
|
| 2506 | + protected function _tag_close_PAGE_HEADER_SUB($param) |
|
| 2507 | + { |
|
| 2508 | + if ($this->_isForOneLine) { |
|
| 2509 | + return false; |
|
| 2510 | + } |
|
| 2511 | + |
|
| 2512 | + $this->parsingCss->load(); |
|
| 2513 | + |
|
| 2514 | + // restore the stat |
|
| 2515 | + $this->parsingCss->value = $this->_subSTATES['s']; |
|
| 2516 | + $this->parsingCss->table = $this->_subSTATES['t']; |
|
| 2517 | + $this->_pageMarges = $this->_subSTATES['mp']; |
|
| 2518 | + $this->_margeLeft = $this->_subSTATES['ml']; |
|
| 2519 | + $this->_margeRight = $this->_subSTATES['mr']; |
|
| 2520 | + $this->_margeTop = $this->_subSTATES['mt']; |
|
| 2521 | + $this->_margeBottom = $this->_subSTATES['mb']; |
|
| 2522 | + $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight); |
|
| 2523 | + $this->pdf->setbMargin($this->_margeBottom); |
|
| 2524 | + $this->pdf->SetAutoPageBreak(false, $this->_margeBottom); |
|
| 2525 | + $this->pdf->setXY($this->_subSTATES['x'], $this->_subSTATES['y']); |
|
| 2526 | + |
|
| 2527 | + $this->parsingCss->fontSet(); |
|
| 2528 | + $this->_maxH = 0; |
|
| 2529 | + |
|
| 2530 | + return true; |
|
| 2531 | + } |
|
| 2532 | + |
|
| 2533 | + /** |
|
| 2534 | + * It is not a real tag. Does not use it directly |
|
| 2535 | + * |
|
| 2536 | + * @param array $param |
|
| 2537 | + * @return boolean |
|
| 2538 | + */ |
|
| 2539 | + protected function _tag_open_PAGE_FOOTER_SUB($param) |
|
| 2540 | + { |
|
| 2541 | + if ($this->_isForOneLine) { |
|
| 2542 | + return false; |
|
| 2543 | + } |
|
| 2544 | + |
|
| 2545 | + // save the current stat |
|
| 2546 | + $this->_subSTATES = array(); |
|
| 2547 | + $this->_subSTATES['x'] = $this->pdf->getX(); |
|
| 2548 | + $this->_subSTATES['y'] = $this->pdf->getY(); |
|
| 2549 | + $this->_subSTATES['s'] = $this->parsingCss->value; |
|
| 2550 | + $this->_subSTATES['t'] = $this->parsingCss->table; |
|
| 2551 | + $this->_subSTATES['ml'] = $this->_margeLeft; |
|
| 2552 | + $this->_subSTATES['mr'] = $this->_margeRight; |
|
| 2553 | + $this->_subSTATES['mt'] = $this->_margeTop; |
|
| 2554 | + $this->_subSTATES['mb'] = $this->_margeBottom; |
|
| 2555 | + $this->_subSTATES['mp'] = $this->_pageMarges; |
|
| 2556 | + |
|
| 2557 | + // new stat for the footer |
|
| 2558 | + $this->_pageMarges = array(); |
|
| 2559 | + $this->_margeLeft = $this->_defaultLeft; |
|
| 2560 | + $this->_margeRight = $this->_defaultRight; |
|
| 2561 | + $this->_margeTop = $this->_defaultTop; |
|
| 2562 | + $this->_margeBottom = $this->_defaultBottom; |
|
| 2563 | + $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight); |
|
| 2564 | + $this->pdf->SetAutoPageBreak(false, $this->_margeBottom); |
|
| 2565 | + $this->pdf->setXY($this->_defaultLeft, $this->_defaultTop); |
|
| 2566 | + |
|
| 2567 | + $this->parsingCss->initStyle(); |
|
| 2568 | + $this->parsingCss->resetStyle(); |
|
| 2569 | + $this->parsingCss->value['width'] = $this->pdf->getW() - $this->_defaultLeft - $this->_defaultRight; |
|
| 2570 | + $this->parsingCss->table = array(); |
|
| 2571 | + |
|
| 2572 | + // we create a sub HTML2PFDF, and we execute on it the content of the footer, to get the height of it |
|
| 2573 | + $sub = null; |
|
| 2574 | + $this->_createSubHTML($sub); |
|
| 2575 | + $sub->parsingHtml->code = $this->parsingHtml->getLevel($this->_parsePos); |
|
| 2576 | + $sub->_makeHTMLcode(); |
|
| 2577 | + $this->pdf->setY($this->pdf->getH() - $sub->_maxY - $this->_defaultBottom - 0.01); |
|
| 2578 | + $this->_destroySubHTML($sub); |
|
| 2579 | + |
|
| 2580 | + $this->parsingCss->save(); |
|
| 2581 | + $this->parsingCss->analyse('page_footer_sub', $param); |
|
| 2582 | + $this->parsingCss->setPosition(); |
|
| 2583 | + $this->parsingCss->fontSet(); |
|
| 2584 | + $this->_setNewPositionForNewLine(); |
|
| 2585 | + |
|
| 2586 | + return true; |
|
| 2587 | + } |
|
| 2588 | + |
|
| 2589 | + /** |
|
| 2590 | + * It is not a real tag. Does not use it directly |
|
| 2591 | + * |
|
| 2592 | + * @param array $param |
|
| 2593 | + * @return boolean |
|
| 2594 | + */ |
|
| 2595 | + protected function _tag_close_PAGE_FOOTER_SUB($param) |
|
| 2596 | + { |
|
| 2597 | + if ($this->_isForOneLine) { |
|
| 2598 | + return false; |
|
| 2599 | + } |
|
| 2600 | + |
|
| 2601 | + $this->parsingCss->load(); |
|
| 2602 | + |
|
| 2603 | + $this->parsingCss->value = $this->_subSTATES['s']; |
|
| 2604 | + $this->parsingCss->table = $this->_subSTATES['t']; |
|
| 2605 | + $this->_pageMarges = $this->_subSTATES['mp']; |
|
| 2606 | + $this->_margeLeft = $this->_subSTATES['ml']; |
|
| 2607 | + $this->_margeRight = $this->_subSTATES['mr']; |
|
| 2608 | + $this->_margeTop = $this->_subSTATES['mt']; |
|
| 2609 | + $this->_margeBottom = $this->_subSTATES['mb']; |
|
| 2610 | + $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight); |
|
| 2611 | + $this->pdf->SetAutoPageBreak(false, $this->_margeBottom); |
|
| 2612 | + $this->pdf->setXY($this->_subSTATES['x'], $this->_subSTATES['y']); |
|
| 2613 | + |
|
| 2614 | + $this->parsingCss->fontSet(); |
|
| 2615 | + $this->_maxH = 0; |
|
| 2616 | + |
|
| 2617 | + return true; |
|
| 2618 | + } |
|
| 2619 | + |
|
| 2620 | + /** |
|
| 2621 | + * tag : NOBREAK |
|
| 2622 | + * mode : OPEN |
|
| 2623 | + * |
|
| 2624 | + * @param array $param |
|
| 2625 | + * @return boolean |
|
| 2626 | + */ |
|
| 2627 | + protected function _tag_open_NOBREAK($param) |
|
| 2628 | + { |
|
| 2629 | + if ($this->_isForOneLine) { |
|
| 2630 | + return false; |
|
| 2631 | + } |
|
| 2632 | + |
|
| 2633 | + $this->_maxH = 0; |
|
| 2634 | + |
|
| 2635 | + // create a sub HTML2PDF to execute the content of the tag, to get the dimensions |
|
| 2636 | + $sub = null; |
|
| 2637 | + $this->_createSubHTML($sub); |
|
| 2638 | + $sub->parsingHtml->code = $this->parsingHtml->getLevel($this->_parsePos); |
|
| 2639 | + $sub->_makeHTMLcode(); |
|
| 2640 | + $y = $this->pdf->getY(); |
|
| 2641 | + |
|
| 2642 | + // if the content does not fit on the page => new page |
|
| 2643 | + if ( |
|
| 2644 | + $sub->_maxY < ($this->pdf->getH() - $this->pdf->gettMargin() - $this->pdf->getbMargin()) && |
|
| 2645 | + $y + $sub->_maxY >= ($this->pdf->getH() - $this->pdf->getbMargin()) |
|
| 2646 | + ) { |
|
| 2647 | + $this->_setNewPage(); |
|
| 2648 | + } |
|
| 2649 | + |
|
| 2650 | + // destroy the sub HTML2PDF |
|
| 2651 | + $this->_destroySubHTML($sub); |
|
| 2652 | + |
|
| 2653 | + return true; |
|
| 2654 | + } |
|
| 2655 | + |
|
| 2656 | + |
|
| 2657 | + /** |
|
| 2658 | + * tag : NOBREAK |
|
| 2659 | + * mode : CLOSE |
|
| 2660 | + * |
|
| 2661 | + * @param array $param |
|
| 2662 | + * @return boolean |
|
| 2663 | + */ |
|
| 2664 | + protected function _tag_close_NOBREAK($param) |
|
| 2665 | + { |
|
| 2666 | + if ($this->_isForOneLine) { |
|
| 2667 | + return false; |
|
| 2668 | + } |
|
| 2669 | + |
|
| 2670 | + $this->_maxH = 0; |
|
| 2671 | + |
|
| 2672 | + return true; |
|
| 2673 | + } |
|
| 2674 | + |
|
| 2675 | + /** |
|
| 2676 | + * tag : DIV |
|
| 2677 | + * mode : OPEN |
|
| 2678 | + * |
|
| 2679 | + * @param array $param |
|
| 2680 | + * @param string $other name of tag that used the div tag |
|
| 2681 | + * @return boolean |
|
| 2682 | + */ |
|
| 2683 | + protected function _tag_open_DIV($param, $other = 'div') |
|
| 2684 | + { |
|
| 2685 | + if ($this->_isForOneLine) { |
|
| 2686 | + return false; |
|
| 2687 | + } |
|
| 2688 | + if ($this->_debugActif) { |
|
| 2689 | + $this->_DEBUG_add(strtoupper($other), true); |
|
| 2690 | + } |
|
| 2691 | + |
|
| 2692 | + $this->parsingCss->save(); |
|
| 2693 | + $this->parsingCss->analyse($other, $param); |
|
| 2694 | + $this->parsingCss->fontSet(); |
|
| 2695 | + |
|
| 2696 | + // for fieldset and legend |
|
| 2697 | + if (in_array($other, array('fieldset', 'legend'))) { |
|
| 2698 | + if (isset($param['moveTop'])) { |
|
| 2699 | + $this->parsingCss->value['margin']['t'] += $param['moveTop']; |
|
| 2700 | + } |
|
| 2701 | + if (isset($param['moveLeft'])) { |
|
| 2702 | + $this->parsingCss->value['margin']['l'] += $param['moveLeft']; |
|
| 2703 | + } |
|
| 2704 | + if (isset($param['moveDown'])) { |
|
| 2705 | + $this->parsingCss->value['margin']['b'] += $param['moveDown']; |
|
| 2706 | + } |
|
| 2707 | + } |
|
| 2708 | + |
|
| 2709 | + $alignObject = null; |
|
| 2710 | + if ($this->parsingCss->value['margin-auto']) { |
|
| 2711 | + $alignObject = 'center'; |
|
| 2712 | + } |
|
| 2713 | + |
|
| 2714 | + $marge = array(); |
|
| 2715 | + $marge['l'] = $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['padding']['l'] + 0.03; |
|
| 2716 | + $marge['r'] = $this->parsingCss->value['border']['r']['width'] + $this->parsingCss->value['padding']['r'] + 0.03; |
|
| 2717 | + $marge['t'] = $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['padding']['t'] + 0.03; |
|
| 2718 | + $marge['b'] = $this->parsingCss->value['border']['b']['width'] + $this->parsingCss->value['padding']['b'] + 0.03; |
|
| 2719 | + |
|
| 2720 | + // extract the content of the div |
|
| 2721 | + $level = $this->parsingHtml->getLevel($this->_parsePos); |
|
| 2722 | + |
|
| 2723 | + // create a sub HTML2PDF to get the dimensions of the content of the div |
|
| 2724 | + $w = 0; $h = 0; |
|
| 2725 | + if (count($level)) { |
|
| 2726 | + $sub = null; |
|
| 2727 | + $this->_createSubHTML($sub); |
|
| 2728 | + $sub->parsingHtml->code = $level; |
|
| 2729 | + $sub->_makeHTMLcode(); |
|
| 2730 | + $w = $sub->_maxX; |
|
| 2731 | + $h = $sub->_maxY; |
|
| 2732 | + $this->_destroySubHTML($sub); |
|
| 2733 | + } |
|
| 2734 | + $wReel = $w; |
|
| 2735 | + $hReel = $h; |
|
| 2736 | + |
|
| 2737 | + $w += $marge['l'] + $marge['r'] + 0.001; |
|
| 2738 | + $h += $marge['t'] + $marge['b'] + 0.001; |
|
| 2739 | + |
|
| 2740 | + if ($this->parsingCss->value['overflow'] == 'hidden') { |
|
| 2741 | + $overW = max($w, $this->parsingCss->value['width']); |
|
| 2742 | + $overH = max($h, $this->parsingCss->value['height']); |
|
| 2743 | + $overflow = true; |
|
| 2744 | + $this->parsingCss->value['old_maxX'] = $this->_maxX; |
|
| 2745 | + $this->parsingCss->value['old_maxY'] = $this->_maxY; |
|
| 2746 | + $this->parsingCss->value['old_maxH'] = $this->_maxH; |
|
| 2747 | + $this->parsingCss->value['old_overflow'] = $this->_isInOverflow; |
|
| 2748 | + $this->_isInOverflow = true; |
|
| 2749 | + } else { |
|
| 2750 | + $overW = null; |
|
| 2751 | + $overH = null; |
|
| 2752 | + $overflow = false; |
|
| 2753 | + $this->parsingCss->value['width'] = max($w, $this->parsingCss->value['width']); |
|
| 2754 | + $this->parsingCss->value['height'] = max($h, $this->parsingCss->value['height']); |
|
| 2755 | + } |
|
| 2756 | + |
|
| 2757 | + switch ($this->parsingCss->value['rotate']) |
|
| 2758 | + { |
|
| 2759 | + case 90: |
|
| 2760 | + $tmp = $overH; $overH = $overW; $overW = $tmp; |
|
| 2761 | + $tmp = $hReel; $hReel = $wReel; $wReel = $tmp; |
|
| 2762 | + unset($tmp); |
|
| 2763 | + $w = $this->parsingCss->value['height']; |
|
| 2764 | + $h = $this->parsingCss->value['width']; |
|
| 2765 | + $tX = -$h; |
|
| 2766 | + $tY = 0; |
|
| 2767 | + break; |
|
| 2768 | + |
|
| 2769 | + case 180: |
|
| 2770 | + $w = $this->parsingCss->value['width']; |
|
| 2771 | + $h = $this->parsingCss->value['height']; |
|
| 2772 | + $tX = -$w; |
|
| 2773 | + $tY = -$h; |
|
| 2774 | + break; |
|
| 2775 | + |
|
| 2776 | + case 270: |
|
| 2777 | + $tmp = $overH; $overH = $overW; $overW = $tmp; |
|
| 2778 | + $tmp = $hReel; $hReel = $wReel; $wReel = $tmp; |
|
| 2779 | + unset($tmp); |
|
| 2780 | + $w = $this->parsingCss->value['height']; |
|
| 2781 | + $h = $this->parsingCss->value['width']; |
|
| 2782 | + $tX = 0; |
|
| 2783 | + $tY = -$w; |
|
| 2784 | + break; |
|
| 2785 | + |
|
| 2786 | + default: |
|
| 2787 | + $w = $this->parsingCss->value['width']; |
|
| 2788 | + $h = $this->parsingCss->value['height']; |
|
| 2789 | + $tX = 0; |
|
| 2790 | + $tY = 0; |
|
| 2791 | + break; |
|
| 2792 | + } |
|
| 2793 | + |
|
| 2794 | + if ( ! $this->parsingCss->value['position']) { |
|
| 2795 | + if ( |
|
| 2796 | + $w < ($this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin()) && |
|
| 2797 | + $this->pdf->getX() + $w >= ($this->pdf->getW() - $this->pdf->getrMargin()) |
|
| 2798 | + ) |
|
| 2799 | + $this->_tag_open_BR(array()); |
|
| 2800 | + |
|
| 2801 | + if ( |
|
| 2802 | + ($h < ($this->pdf->getH() - $this->pdf->gettMargin() - $this->pdf->getbMargin())) && |
|
| 2803 | + ($this->pdf->getY() + $h >= ($this->pdf->getH() - $this->pdf->getbMargin())) && |
|
| 2804 | + ! $this->_isInOverflow |
|
| 2805 | + ) |
|
| 2806 | + $this->_setNewPage(); |
|
| 2807 | + |
|
| 2808 | + $old = $this->parsingCss->getOldValues(); |
|
| 2809 | + $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); |
|
| 2810 | + |
|
| 2811 | + if ($parentWidth > $w) { |
|
| 2812 | + if ($alignObject == 'center') $this->pdf->setX($this->pdf->getX() + ($parentWidth - $w) * 0.5); |
|
| 2813 | + else if ($alignObject == 'right') $this->pdf->setX($this->pdf->getX() + $parentWidth - $w); |
|
| 2814 | + } |
|
| 2815 | + |
|
| 2816 | + $this->parsingCss->setPosition(); |
|
| 2817 | + } else { |
|
| 2818 | + $old = $this->parsingCss->getOldValues(); |
|
| 2819 | + $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); |
|
| 2820 | + |
|
| 2821 | + if ($parentWidth > $w) { |
|
| 2822 | + if ($alignObject == 'center') $this->pdf->setX($this->pdf->getX() + ($parentWidth - $w) * 0.5); |
|
| 2823 | + else if ($alignObject == 'right') $this->pdf->setX($this->pdf->getX() + $parentWidth - $w); |
|
| 2824 | + } |
|
| 2825 | + |
|
| 2826 | + $this->parsingCss->setPosition(); |
|
| 2827 | + $this->_saveMax(); |
|
| 2828 | + $this->_maxX = 0; |
|
| 2829 | + $this->_maxY = 0; |
|
| 2830 | + $this->_maxH = 0; |
|
| 2831 | + $this->_maxE = 0; |
|
| 2832 | + } |
|
| 2833 | + |
|
| 2834 | + if ($this->parsingCss->value['rotate']) { |
|
| 2835 | + $this->pdf->startTransform(); |
|
| 2836 | + $this->pdf->setRotation($this->parsingCss->value['rotate']); |
|
| 2837 | + $this->pdf->setTranslate($tX, $tY); |
|
| 2838 | + } |
|
| 2839 | + |
|
| 2840 | + $this->_drawRectangle( |
|
| 2841 | + $this->parsingCss->value['x'], |
|
| 2842 | + $this->parsingCss->value['y'], |
|
| 2843 | + $this->parsingCss->value['width'], |
|
| 2844 | + $this->parsingCss->value['height'], |
|
| 2845 | + $this->parsingCss->value['border'], |
|
| 2846 | + $this->parsingCss->value['padding'], |
|
| 2847 | + 0, |
|
| 2848 | + $this->parsingCss->value['background'] |
|
| 2849 | + ); |
|
| 2850 | + |
|
| 2851 | + $marge = array(); |
|
| 2852 | + $marge['l'] = $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['padding']['l'] + 0.03; |
|
| 2853 | + $marge['r'] = $this->parsingCss->value['border']['r']['width'] + $this->parsingCss->value['padding']['r'] + 0.03; |
|
| 2854 | + $marge['t'] = $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['padding']['t'] + 0.03; |
|
| 2855 | + $marge['b'] = $this->parsingCss->value['border']['b']['width'] + $this->parsingCss->value['padding']['b'] + 0.03; |
|
| 2856 | + |
|
| 2857 | + $this->parsingCss->value['width'] -= $marge['l'] + $marge['r']; |
|
| 2858 | + $this->parsingCss->value['height'] -= $marge['t'] + $marge['b']; |
|
| 2859 | + |
|
| 2860 | + $xCorr = 0; |
|
| 2861 | + $yCorr = 0; |
|
| 2862 | + if ( ! $this->_subPart && ! $this->_isSubPart) { |
|
| 2863 | + switch ($this->parsingCss->value['text-align']) |
|
| 2864 | + { |
|
| 2865 | + case 'right': |
|
| 2866 | + $xCorr = ($this->parsingCss->value['width'] - $wReel); |
|
| 2867 | + break; |
|
| 2868 | + case 'center': |
|
| 2869 | + $xCorr = ($this->parsingCss->value['width'] - $wReel) * 0.5; |
|
| 2870 | + break; |
|
| 2871 | + } |
|
| 2872 | + if ($xCorr > 0) $xCorr = 0; |
|
| 2873 | + switch ($this->parsingCss->value['vertical-align']) |
|
| 2874 | + { |
|
| 2875 | + case 'bottom': |
|
| 2876 | + $yCorr = ($this->parsingCss->value['height'] - $hReel); |
|
| 2877 | + break; |
|
| 2878 | + case 'middle': |
|
| 2879 | + $yCorr = ($this->parsingCss->value['height'] - $hReel) * 0.5; |
|
| 2880 | + break; |
|
| 2881 | + } |
|
| 2882 | + } |
|
| 2883 | + |
|
| 2884 | + if ($overflow) { |
|
| 2885 | + $overW -= $marge['l'] + $marge['r']; |
|
| 2886 | + $overH -= $marge['t'] + $marge['b']; |
|
| 2887 | + $this->pdf->clippingPathStart( |
|
| 2888 | + $this->parsingCss->value['x'] + $marge['l'], |
|
| 2889 | + $this->parsingCss->value['y'] + $marge['t'], |
|
| 2890 | + $this->parsingCss->value['width'], |
|
| 2891 | + $this->parsingCss->value['height'] |
|
| 2892 | + ); |
|
| 2893 | + |
|
| 2894 | + $this->parsingCss->value['x'] += $xCorr; |
|
| 2895 | + |
|
| 2896 | + // marges from the dimension of the content |
|
| 2897 | + $mL = $this->parsingCss->value['x'] + $marge['l']; |
|
| 2898 | + $mR = $this->pdf->getW() - $mL - $overW; |
|
| 2899 | + } else { |
|
| 2900 | + // marges from the dimension of the div |
|
| 2901 | + $mL = $this->parsingCss->value['x'] + $marge['l']; |
|
| 2902 | + $mR = $this->pdf->getW() - $mL - $this->parsingCss->value['width']; |
|
| 2903 | + } |
|
| 2904 | + |
|
| 2905 | + $x = $this->parsingCss->value['x'] + $marge['l']; |
|
| 2906 | + $y = $this->parsingCss->value['y'] + $marge['t'] + $yCorr; |
|
| 2907 | + $this->_saveMargin($mL, 0, $mR); |
|
| 2908 | + $this->pdf->setXY($x, $y); |
|
| 2909 | + |
|
| 2910 | + $this->_setNewPositionForNewLine(); |
|
| 2911 | + |
|
| 2912 | + return true; |
|
| 2913 | + } |
|
| 2914 | + |
|
| 2915 | + /** |
|
| 2916 | + * tag : BLOCKQUOTE |
|
| 2917 | + * mode : OPEN |
|
| 2918 | + * |
|
| 2919 | + * @param array $param |
|
| 2920 | + * @return boolean |
|
| 2921 | + */ |
|
| 2922 | + protected function _tag_open_BLOCKQUOTE($param) |
|
| 2923 | + { |
|
| 2924 | + return $this->_tag_open_DIV($param, 'blockquote'); |
|
| 2925 | + } |
|
| 2926 | + |
|
| 2927 | + /** |
|
| 2928 | + * tag : LEGEND |
|
| 2929 | + * mode : OPEN |
|
| 2930 | + * |
|
| 2931 | + * @param array $param |
|
| 2932 | + * @return boolean |
|
| 2933 | + */ |
|
| 2934 | + protected function _tag_open_LEGEND($param) |
|
| 2935 | + { |
|
| 2936 | + return $this->_tag_open_DIV($param, 'legend'); |
|
| 2937 | + } |
|
| 2938 | + |
|
| 2939 | + /** |
|
| 2940 | + * tag : FIELDSET |
|
| 2941 | + * mode : OPEN |
|
| 2942 | + * |
|
| 2943 | + * @author Pavel Kochman |
|
| 2944 | + * @param array $param |
|
| 2945 | + * @return boolean |
|
| 2946 | + */ |
|
| 2947 | + protected function _tag_open_FIELDSET($param) |
|
| 2948 | + { |
|
| 2949 | + |
|
| 2950 | + $this->parsingCss->save(); |
|
| 2951 | + $this->parsingCss->analyse('fieldset', $param); |
|
| 2952 | + |
|
| 2953 | + // get height of LEGEND element and make fieldset corrections |
|
| 2954 | + for ($tempPos = $this->_parsePos + 1; $tempPos < count($this->parsingHtml->code); $tempPos++) { |
|
| 2955 | + $action = $this->parsingHtml->code[$tempPos]; |
|
| 2956 | + if ($action['name'] == 'fieldset') break; |
|
| 2957 | + if ($action['name'] == 'legend' && ! $action['close']) { |
|
| 2958 | + $legendOpenPos = $tempPos; |
|
| 2959 | + |
|
| 2960 | + $sub = null; |
|
| 2961 | + $this->_createSubHTML($sub); |
|
| 2962 | + $sub->parsingHtml->code = $this->parsingHtml->getLevel($tempPos - 1); |
|
| 2963 | + |
|
| 2964 | + $res = null; |
|
| 2965 | + for ($sub->_parsePos = 0; $sub->_parsePos < count($sub->parsingHtml->code); $sub->_parsePos++) { |
|
| 2966 | + $action = $sub->parsingHtml->code[$sub->_parsePos]; |
|
| 2967 | + $sub->_executeAction($action); |
|
| 2968 | + |
|
| 2969 | + if ($action['name'] == 'legend' && $action['close']) { |
|
| 2970 | + break; |
|
| 2971 | + } |
|
| 2972 | + } |
|
| 2973 | + |
|
| 2974 | + $legendH = $sub->_maxY; |
|
| 2975 | + $this->_destroySubHTML($sub); |
|
| 2976 | + |
|
| 2977 | + $move = $this->parsingCss->value['padding']['t'] + $this->parsingCss->value['border']['t']['width'] + 0.03; |
|
| 2978 | + |
|
| 2979 | + $param['moveTop'] = $legendH / 2; |
|
| 2980 | + |
|
| 2981 | + $this->parsingHtml->code[$legendOpenPos]['param']['moveTop'] = - ($legendH / 2 + $move); |
|
| 2982 | + $this->parsingHtml->code[$legendOpenPos]['param']['moveLeft'] = 2 - $this->parsingCss->value['border']['l']['width'] - $this->parsingCss->value['padding']['l']; |
|
| 2983 | + $this->parsingHtml->code[$legendOpenPos]['param']['moveDown'] = $move; |
|
| 2984 | + break; |
|
| 2985 | + } |
|
| 2986 | + } |
|
| 2987 | + $this->parsingCss->load(); |
|
| 2988 | + |
|
| 2989 | + return $this->_tag_open_DIV($param, 'fieldset'); |
|
| 2990 | + } |
|
| 2991 | + |
|
| 2992 | + /** |
|
| 2993 | + * tag : DIV |
|
| 2994 | + * mode : CLOSE |
|
| 2995 | + * |
|
| 2996 | + * @param array $param |
|
| 2997 | + * @param string $other name of tag that used the div tag |
|
| 2998 | + * @return boolean |
|
| 2999 | + */ |
|
| 3000 | + protected function _tag_close_DIV($param, $other = 'div') |
|
| 3001 | + { |
|
| 3002 | + if ($this->_isForOneLine) { |
|
| 3003 | + return false; |
|
| 3004 | + } |
|
| 3005 | + |
|
| 3006 | + if ($this->parsingCss->value['overflow'] == 'hidden') { |
|
| 3007 | + $this->_maxX = $this->parsingCss->value['old_maxX']; |
|
| 3008 | + $this->_maxY = $this->parsingCss->value['old_maxY']; |
|
| 3009 | + $this->_maxH = $this->parsingCss->value['old_maxH']; |
|
| 3010 | + $this->_isInOverflow = $this->parsingCss->value['old_overflow']; |
|
| 3011 | + $this->pdf->clippingPathStop(); |
|
| 3012 | + } |
|
| 3013 | + |
|
| 3014 | + if ($this->parsingCss->value['rotate']) { |
|
| 3015 | + $this->pdf->stopTransform(); |
|
| 3016 | + } |
|
| 3017 | + |
|
| 3018 | + $marge = array(); |
|
| 3019 | + $marge['l'] = $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['padding']['l'] + 0.03; |
|
| 3020 | + $marge['r'] = $this->parsingCss->value['border']['r']['width'] + $this->parsingCss->value['padding']['r'] + 0.03; |
|
| 3021 | + $marge['t'] = $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['padding']['t'] + 0.03; |
|
| 3022 | + $marge['b'] = $this->parsingCss->value['border']['b']['width'] + $this->parsingCss->value['padding']['b'] + 0.03; |
|
| 3023 | + |
|
| 3024 | + $x = $this->parsingCss->value['x']; |
|
| 3025 | + $y = $this->parsingCss->value['y']; |
|
| 3026 | + $w = $this->parsingCss->value['width'] + $marge['l'] + $marge['r'] + $this->parsingCss->value['margin']['r']; |
|
| 3027 | + $h = $this->parsingCss->value['height'] + $marge['t'] + $marge['b'] + $this->parsingCss->value['margin']['b']; |
|
| 3028 | + |
|
| 3029 | + switch ($this->parsingCss->value['rotate']) |
|
| 3030 | + { |
|
| 3031 | + case 90: |
|
| 3032 | + $t = $w; $w = $h; $h = $t; |
|
| 3033 | + break; |
|
| 3034 | + |
|
| 3035 | + case 270: |
|
| 3036 | + $t = $w; $w = $h; $h = $t; |
|
| 3037 | + break; |
|
| 3038 | + |
|
| 3039 | + default: |
|
| 3040 | + break; |
|
| 3041 | + } |
|
| 3042 | + |
|
| 3043 | + |
|
| 3044 | + if ($this->parsingCss->value['position'] != 'absolute') { |
|
| 3045 | + $this->pdf->setXY($x + $w, $y); |
|
| 3046 | + |
|
| 3047 | + $this->_maxX = max($this->_maxX, $x + $w); |
|
| 3048 | + $this->_maxY = max($this->_maxY, $y + $h); |
|
| 3049 | + $this->_maxH = max($this->_maxH, $h); |
|
| 3050 | + } else { |
|
| 3051 | + $this->pdf->setXY($this->parsingCss->value['xc'], $this->parsingCss->value['yc']); |
|
| 3052 | + |
|
| 3053 | + $this->_loadMax(); |
|
| 3054 | + } |
|
| 3055 | + |
|
| 3056 | + $block = ($this->parsingCss->value['display'] != 'inline' && $this->parsingCss->value['position'] != 'absolute'); |
|
| 3057 | + |
|
| 3058 | + $this->parsingCss->load(); |
|
| 3059 | + $this->parsingCss->fontSet(); |
|
| 3060 | + $this->_loadMargin(); |
|
| 3061 | + |
|
| 3062 | + if ($block) { |
|
| 3063 | + $this->_tag_open_BR(array()); |
|
| 3064 | + } |
|
| 3065 | + if ($this->_debugActif) { |
|
| 3066 | + $this->_DEBUG_add(strtoupper($other), false); |
|
| 3067 | + } |
|
| 3068 | + |
|
| 3069 | + return true; |
|
| 3070 | + } |
|
| 3071 | + |
|
| 3072 | + /** |
|
| 3073 | + * tag : BLOCKQUOTE |
|
| 3074 | + * mode : CLOSE |
|
| 3075 | + * |
|
| 3076 | + * @param array $param |
|
| 3077 | + * @return boolean |
|
| 3078 | + */ |
|
| 3079 | + protected function _tag_close_BLOCKQUOTE($param) |
|
| 3080 | + { |
|
| 3081 | + return $this->_tag_close_DIV($param, 'blockquote'); |
|
| 3082 | + } |
|
| 3083 | + |
|
| 3084 | + /** |
|
| 3085 | + * tag : FIELDSET |
|
| 3086 | + * mode : CLOSE |
|
| 3087 | + * |
|
| 3088 | + * @param array $param |
|
| 3089 | + * @return boolean |
|
| 3090 | + */ |
|
| 3091 | + protected function _tag_close_FIELDSET($param) |
|
| 3092 | + { |
|
| 3093 | + return $this->_tag_close_DIV($param, 'fieldset'); |
|
| 3094 | + } |
|
| 3095 | + |
|
| 3096 | + /** |
|
| 3097 | + * tag : LEGEND |
|
| 3098 | + * mode : CLOSE |
|
| 3099 | + * |
|
| 3100 | + * @param array $param |
|
| 3101 | + * @return boolean |
|
| 3102 | + */ |
|
| 3103 | + protected function _tag_close_LEGEND($param) |
|
| 3104 | + { |
|
| 3105 | + return $this->_tag_close_DIV($param, 'legend'); |
|
| 3106 | + } |
|
| 3107 | + |
|
| 3108 | + /** |
|
| 3109 | + * tag : BARCODE |
|
| 3110 | + * mode : OPEN |
|
| 3111 | + * |
|
| 3112 | + * @param array $param |
|
| 3113 | + * @return boolean |
|
| 3114 | + */ |
|
| 3115 | + protected function _tag_open_BARCODE($param) |
|
| 3116 | + { |
|
| 3117 | + // for compatibility with old versions < 3.29 |
|
| 3118 | + $lstBarcode = array(); |
|
| 3119 | + $lstBarcode['UPC_A'] = 'UPCA'; |
|
| 3120 | + $lstBarcode['CODE39'] = 'C39'; |
|
| 3121 | + |
|
| 3122 | + if ( ! isset($param['type'])) $param['type'] = 'C39'; |
|
| 3123 | + if ( ! isset($param['value'])) $param['value'] = 0; |
|
| 3124 | + if ( ! isset($param['label'])) $param['label'] = 'label'; |
|
| 3125 | + if ( ! isset($param['style']['color'])) $param['style']['color'] = '#000000'; |
|
| 3126 | + |
|
| 3127 | + if ($this->_testIsDeprecated && (isset($param['bar_h']) || isset($param['bar_w']))) |
|
| 3128 | + throw new HTML2PDF_exception(9, array('BARCODE', 'bar_h, bar_w')); |
|
| 3129 | + |
|
| 3130 | + $param['type'] = strtoupper($param['type']); |
|
| 3131 | + if (isset($lstBarcode[$param['type']])) $param['type'] = $lstBarcode[$param['type']]; |
|
| 3132 | + |
|
| 3133 | + $this->parsingCss->save(); |
|
| 3134 | + $this->parsingCss->analyse('barcode', $param); |
|
| 3135 | + $this->parsingCss->setPosition(); |
|
| 3136 | + $this->parsingCss->fontSet(); |
|
| 3137 | + |
|
| 3138 | + $x = $this->pdf->getX(); |
|
| 3139 | + $y = $this->pdf->getY(); |
|
| 3140 | + $w = $this->parsingCss->value['width']; if ( ! $w) $w = $this->parsingCss->ConvertToMM('50mm'); |
|
| 3141 | + $h = $this->parsingCss->value['height']; if ( ! $h) $h = $this->parsingCss->ConvertToMM('10mm'); |
|
| 3142 | + $txt = ($param['label'] !== 'none' ? $this->parsingCss->value['font-size'] : false); |
|
| 3143 | + $c = $this->parsingCss->value['color']; |
|
| 3144 | + $infos = $this->pdf->myBarcode($param['value'], $param['type'], $x, $y, $w, $h, $txt, $c); |
|
| 3145 | + |
|
| 3146 | + $this->_maxX = max($this->_maxX, $x + $infos[0]); |
|
| 3147 | + $this->_maxY = max($this->_maxY, $y + $infos[1]); |
|
| 3148 | + $this->_maxH = max($this->_maxH, $infos[1]); |
|
| 3149 | + $this->_maxE++; |
|
| 3150 | + |
|
| 3151 | + $this->pdf->setXY($x + $infos[0], $y); |
|
| 3152 | + |
|
| 3153 | + $this->parsingCss->load(); |
|
| 3154 | + $this->parsingCss->fontSet(); |
|
| 3155 | + |
|
| 3156 | + return true; |
|
| 3157 | + } |
|
| 3158 | + |
|
| 3159 | + /** |
|
| 3160 | + * tag : BARCODE |
|
| 3161 | + * mode : CLOSE |
|
| 3162 | + * |
|
| 3163 | + * @param array $param |
|
| 3164 | + * @return boolean |
|
| 3165 | + */ |
|
| 3166 | + protected function _tag_close_BARCODE($param) |
|
| 3167 | + { |
|
| 3168 | + // there is nothing to do here |
|
| 3169 | + |
|
| 3170 | + return true; |
|
| 3171 | + } |
|
| 3172 | + |
|
| 3173 | + /** |
|
| 3174 | + * tag : QRCODE |
|
| 3175 | + * mode : OPEN |
|
| 3176 | + * |
|
| 3177 | + * @param array $param |
|
| 3178 | + * @return boolean |
|
| 3179 | + */ |
|
| 3180 | + protected function _tag_open_QRCODE($param) |
|
| 3181 | + { |
|
| 3182 | + if ($this->_testIsDeprecated && (isset($param['size']) || isset($param['noborder']))) |
|
| 3183 | + throw new HTML2PDF_exception(9, array('QRCODE', 'size, noborder')); |
|
| 3184 | + |
|
| 3185 | + if ($this->_debugActif) $this->_DEBUG_add('QRCODE'); |
|
| 3186 | + |
|
| 3187 | + if ( ! isset($param['value'])) $param['value'] = ''; |
|
| 3188 | + if ( ! isset($param['ec'])) $param['ec'] = 'H'; |
|
| 3189 | + if ( ! isset($param['style']['color'])) $param['style']['color'] = '#000000'; |
|
| 3190 | + if ( ! isset($param['style']['background-color'])) $param['style']['background-color'] = '#FFFFFF'; |
|
| 3191 | + if (isset($param['style']['border'])) { |
|
| 3192 | + $borders = $param['style']['border'] != 'none'; |
|
| 3193 | + unset($param['style']['border']); |
|
| 3194 | + } else { |
|
| 3195 | + $borders = true; |
|
| 3196 | + } |
|
| 3197 | + |
|
| 3198 | + if ($param['value'] === '') return true; |
|
| 3199 | + if ( ! in_array($param['ec'], array('L', 'M', 'Q', 'H'))) $param['ec'] = 'H'; |
|
| 3200 | + |
|
| 3201 | + $this->parsingCss->save(); |
|
| 3202 | + $this->parsingCss->analyse('qrcode', $param); |
|
| 3203 | + $this->parsingCss->setPosition(); |
|
| 3204 | + $this->parsingCss->fontSet(); |
|
| 3205 | + |
|
| 3206 | + $x = $this->pdf->getX(); |
|
| 3207 | + $y = $this->pdf->getY(); |
|
| 3208 | + $w = $this->parsingCss->value['width']; |
|
| 3209 | + $h = $this->parsingCss->value['height']; |
|
| 3210 | + $size = max($w, $h); if ( ! $size) $size = $this->parsingCss->ConvertToMM('50mm'); |
|
| 3211 | + |
|
| 3212 | + $style = array( |
|
| 3213 | + 'fgcolor' => $this->parsingCss->value['color'], |
|
| 3214 | + 'bgcolor' => $this->parsingCss->value['background']['color'], |
|
| 3215 | + ); |
|
| 3216 | + |
|
| 3217 | + if ($borders) { |
|
| 3218 | + $style['border'] = true; |
|
| 3219 | + $style['padding'] = 'auto'; |
|
| 3220 | + } else { |
|
| 3221 | + $style['border'] = false; |
|
| 3222 | + $style['padding'] = 0; |
|
| 3223 | + } |
|
| 3224 | + |
|
| 3225 | + if ( ! $this->_subPart && ! $this->_isSubPart) { |
|
| 3226 | + $this->pdf->write2DBarcode($param['value'], 'QRCODE,'.$param['ec'], $x, $y, $size, $size, $style); |
|
| 3227 | + } |
|
| 3228 | + |
|
| 3229 | + $this->_maxX = max($this->_maxX, $x + $size); |
|
| 3230 | + $this->_maxY = max($this->_maxY, $y + $size); |
|
| 3231 | + $this->_maxH = max($this->_maxH, $size); |
|
| 3232 | + $this->_maxE++; |
|
| 3233 | + |
|
| 3234 | + $this->pdf->setX($x + $size); |
|
| 3235 | + |
|
| 3236 | + $this->parsingCss->load(); |
|
| 3237 | + $this->parsingCss->fontSet(); |
|
| 3238 | + |
|
| 3239 | + return true; |
|
| 3240 | + } |
|
| 3241 | + |
|
| 3242 | + /** |
|
| 3243 | + * tag : QRCODE |
|
| 3244 | + * mode : CLOSE |
|
| 3245 | + * |
|
| 3246 | + * @param array $param |
|
| 3247 | + * @return boolean |
|
| 3248 | + */ |
|
| 3249 | + protected function _tag_close_QRCODE($param) |
|
| 3250 | + { |
|
| 3251 | + // there is nothing to do here |
|
| 3252 | + |
|
| 3253 | + return true; |
|
| 3254 | + } |
|
| 3255 | + |
|
| 3256 | + /** |
|
| 3257 | + * tag : BOOKMARK |
|
| 3258 | + * mode : OPEN |
|
| 3259 | + * |
|
| 3260 | + * @param array $param |
|
| 3261 | + * @return boolean |
|
| 3262 | + */ |
|
| 3263 | + protected function _tag_open_BOOKMARK($param) |
|
| 3264 | + { |
|
| 3265 | + $titre = isset($param['title']) ? trim($param['title']) : ''; |
|
| 3266 | + $level = isset($param['level']) ? floor($param['level']) : 0; |
|
| 3267 | + |
|
| 3268 | + if ($level < 0) $level = 0; |
|
| 3269 | + if ($titre) $this->pdf->Bookmark($titre, $level, -1); |
|
| 3270 | + |
|
| 3271 | + return true; |
|
| 3272 | + } |
|
| 3273 | + |
|
| 3274 | + /** |
|
| 3275 | + * tag : BOOKMARK |
|
| 3276 | + * mode : CLOSE |
|
| 3277 | + * |
|
| 3278 | + * @param array $param |
|
| 3279 | + * @return boolean |
|
| 3280 | + */ |
|
| 3281 | + protected function _tag_close_BOOKMARK($param) |
|
| 3282 | + { |
|
| 3283 | + // there is nothing to do here |
|
| 3284 | + |
|
| 3285 | + return true; |
|
| 3286 | + } |
|
| 3287 | + |
|
| 3288 | + /** |
|
| 3289 | + * this is not a real TAG, it is just to write texts |
|
| 3290 | + * |
|
| 3291 | + * @param array $param |
|
| 3292 | + * @return null|boolean |
|
| 3293 | + */ |
|
| 3294 | + protected function _tag_open_WRITE($param) |
|
| 3295 | + { |
|
| 3296 | + $fill = ($this->parsingCss->value['background']['color'] !== null && $this->parsingCss->value['background']['image'] === null); |
|
| 3297 | + if (in_array($this->parsingCss->value['id_tag'], array('fieldset', 'legend', 'div', 'table', 'tr', 'td', 'th'))) { |
|
| 3298 | + $fill = false; |
|
| 3299 | + } |
|
| 3300 | + |
|
| 3301 | + // get the text to write |
|
| 3302 | + $txt = $param['txt']; |
|
| 3303 | + |
|
| 3304 | + if ($this->_isAfterFloat) { |
|
| 3305 | + $txt = ltrim($txt); |
|
| 3306 | + $this->_isAfterFloat = false; |
|
| 3307 | + } |
|
| 3308 | + |
|
| 3309 | + $txt = str_replace('[[page_nb]]', $this->pdf->getMyAliasNbPages(), $txt); |
|
| 3310 | + $txt = str_replace('[[page_cu]]', $this->pdf->getMyNumPage($this->_page), $txt); |
|
| 3311 | + |
|
| 3312 | + if ($this->parsingCss->value['text-transform'] != 'none') { |
|
| 3313 | + if ($this->parsingCss->value['text-transform'] == 'capitalize') |
|
| 3314 | + $txt = ucwords($txt); |
|
| 3315 | + else if ($this->parsingCss->value['text-transform'] == 'uppercase') |
|
| 3316 | + $txt = strtoupper($txt); |
|
| 3317 | + else if ($this->parsingCss->value['text-transform'] == 'lowercase') |
|
| 3318 | + $txt = strtolower($txt); |
|
| 3319 | + } |
|
| 3320 | + |
|
| 3321 | + // size of the text |
|
| 3322 | + $h = 1.08 * $this->parsingCss->value['font-size']; |
|
| 3323 | + $dh = $h * $this->parsingCss->value['mini-decal']; |
|
| 3324 | + $lh = $this->parsingCss->getLineHeight(); |
|
| 3325 | + |
|
| 3326 | + // identify the align |
|
| 3327 | + $align = 'L'; |
|
| 3328 | + if ($this->parsingCss->value['text-align'] == 'li_right') { |
|
| 3329 | + $w = $this->parsingCss->value['width']; |
|
| 3330 | + $align = 'R'; |
|
| 3331 | + } |
|
| 3332 | + |
|
| 3333 | + // calculate the width of each words, and of all the sentence |
|
| 3334 | + $w = 0; |
|
| 3335 | + $words = explode(' ', $txt); |
|
| 3336 | + foreach ($words as $k => $word) { |
|
| 3337 | + $words[$k] = array($word, $this->pdf->GetStringWidth($word)); |
|
| 3338 | + $w += $words[$k][1]; |
|
| 3339 | + } |
|
| 3340 | + $space = $this->pdf->GetStringWidth(' '); |
|
| 3341 | + $w += $space * (count($words) - 1); |
|
| 3342 | + |
|
| 3343 | + // position in the text |
|
| 3344 | + $currPos = 0; |
|
| 3345 | + |
|
| 3346 | + // the bigger width of the text, after automatic break line |
|
| 3347 | + $maxX = 0; |
|
| 3348 | + |
|
| 3349 | + // position of the text |
|
| 3350 | + $x = $this->pdf->getX(); |
|
| 3351 | + $y = $this->pdf->getY(); |
|
| 3352 | + $dy = $this->_getElementY($lh); |
|
| 3353 | + |
|
| 3354 | + // margins |
|
| 3355 | + list($left, $right) = $this->_getMargins($y); |
|
| 3356 | + |
|
| 3357 | + // number of lines after automatic break line |
|
| 3358 | + $nb = 0; |
|
| 3359 | + |
|
| 3360 | + // while we have words, and the text does not fit on the line => we cut the sentence |
|
| 3361 | + while ($x + $w > $right && $x < $right + $space && count($words)) { |
|
| 3362 | + // adding words 1 by 1 to fit on the line |
|
| 3363 | + $i = 0; |
|
| 3364 | + $old = array('', 0); |
|
| 3365 | + $str = $words[0]; |
|
| 3366 | + $add = false; |
|
| 3367 | + while (($x + $str[1]) < $right) { |
|
| 3368 | + $i++; |
|
| 3369 | + $add = true; |
|
| 3370 | + |
|
| 3371 | + array_shift($words); |
|
| 3372 | + $old = $str; |
|
| 3373 | + |
|
| 3374 | + if ( ! count($words)) break; |
|
| 3375 | + $str[0] .= ' '.$words[0][0]; |
|
| 3376 | + $str[1] += $space + $words[0][1]; |
|
| 3377 | + } |
|
| 3378 | + $str = $old; |
|
| 3379 | + |
|
| 3380 | + // if nothing fit on the line, and if the first word does not fit on the line => the word is too long, we put it |
|
| 3381 | + if ($i == 0 && (($left + $words[0][1]) >= $right)) { |
|
| 3382 | + $str = $words[0]; |
|
| 3383 | + array_shift($words); |
|
| 3384 | + $i++; |
|
| 3385 | + $add = true; |
|
| 3386 | + } |
|
| 3387 | + $currPos += ($currPos ? 1 : 0) + strlen($str[0]); |
|
| 3388 | + |
|
| 3389 | + // write the extract sentence that fit on the page |
|
| 3390 | + $wc = ($align == 'L' ? $str[1] : $this->parsingCss->value['width']); |
|
| 3391 | + if ($right - $left < $wc) $wc = $right - $left; |
|
| 3392 | + |
|
| 3393 | + if (strlen($str[0])) { |
|
| 3394 | + $this->pdf->setXY($this->pdf->getX(), $y + $dh + $dy); |
|
| 3395 | + $this->pdf->Cell($wc, $h, $str[0], 0, 0, $align, $fill, $this->_isInLink); |
|
| 3396 | + $this->pdf->setXY($this->pdf->getX(), $y); |
|
| 3397 | + } |
|
| 3398 | + $this->_maxH = max($this->_maxH, $lh); |
|
| 3399 | + |
|
| 3400 | + // max width |
|
| 3401 | + $maxX = max($maxX, $this->pdf->getX()); |
|
| 3402 | + |
|
| 3403 | + // new position and new width for the "while" |
|
| 3404 | + $w -= $str[1]; |
|
| 3405 | + $y = $this->pdf->getY(); |
|
| 3406 | + $x = $this->pdf->getX(); |
|
| 3407 | + $dy = $this->_getElementY($lh); |
|
| 3408 | + |
|
| 3409 | + // if we have again words to write |
|
| 3410 | + if (count($words)) { |
|
| 3411 | + // remove the space at the end |
|
| 3412 | + if ($add) $w -= $space; |
|
| 3413 | + |
|
| 3414 | + // if we don't add any word, and if the first word is empty => useless space to skip |
|
| 3415 | + if ( ! $add && $words[0][0] === '') { |
|
| 3416 | + array_shift($words); |
|
| 3417 | + } |
|
| 3418 | + |
|
| 3419 | + // if it is just to calculate for one line => adding the number of words |
|
| 3420 | + if ($this->_isForOneLine) { |
|
| 3421 | + $this->_maxE += $i; |
|
| 3422 | + $this->_maxX = max($this->_maxX, $maxX); |
|
| 3423 | + return null; |
|
| 3424 | + } |
|
| 3425 | + |
|
| 3426 | + // automatic line break |
|
| 3427 | + $this->_tag_open_BR(array('style' => ''), $currPos); |
|
| 3428 | + |
|
| 3429 | + // new position |
|
| 3430 | + $y = $this->pdf->getY(); |
|
| 3431 | + $x = $this->pdf->getX(); |
|
| 3432 | + $dy = $this->_getElementY($lh); |
|
| 3433 | + |
|
| 3434 | + // if the next line does not fit on the page => new page |
|
| 3435 | + if ($y + $h >= $this->pdf->getH() - $this->pdf->getbMargin()) { |
|
| 3436 | + if ( ! $this->_isInOverflow && ! $this->_isInFooter) { |
|
| 3437 | + $this->_setNewPage(null, '', null, $currPos); |
|
| 3438 | + $y = $this->pdf->getY(); |
|
| 3439 | + $x = $this->pdf->getX(); |
|
| 3440 | + $dy = $this->_getElementY($lh); |
|
| 3441 | + } |
|
| 3442 | + } |
|
| 3443 | + |
|
| 3444 | + // if more than 10000 line => error |
|
| 3445 | + $nb++; |
|
| 3446 | + if ($nb > 10000) { |
|
| 3447 | + $txt = ''; foreach ($words as $k => $word) $txt .= ($k ? ' ' : '').$word[0]; |
|
| 3448 | + throw new HTML2PDF_exception(2, array($txt, $right - $left, $w)); |
|
| 3449 | + } |
|
| 3450 | + |
|
| 3451 | + // new margins for the new line |
|
| 3452 | + list($left, $right) = $this->_getMargins($y); |
|
| 3453 | + } |
|
| 3454 | + } |
|
| 3455 | + |
|
| 3456 | + // if we have words after automatic cut, it is because they fit on the line => we write the text |
|
| 3457 | + if (count($words)) { |
|
| 3458 | + $txt = ''; foreach ($words as $k => $word) $txt .= ($k ? ' ' : '').$word[0]; |
|
| 3459 | + $w += $this->pdf->getWordSpacing() * (count($words)); |
|
| 3460 | + $this->pdf->setXY($this->pdf->getX(), $y + $dh + $dy); |
|
| 3461 | + $this->pdf->Cell(($align == 'L' ? $w : $this->parsingCss->value['width']), $h, $txt, 0, 0, $align, $fill, $this->_isInLink); |
|
| 3462 | + $this->pdf->setXY($this->pdf->getX(), $y); |
|
| 3463 | + $this->_maxH = max($this->_maxH, $lh); |
|
| 3464 | + $this->_maxE += count($words); |
|
| 3465 | + } |
|
| 3466 | + |
|
| 3467 | + $maxX = max($maxX, $this->pdf->getX()); |
|
| 3468 | + $maxY = $this->pdf->getY() + $h; |
|
| 3469 | + |
|
| 3470 | + $this->_maxX = max($this->_maxX, $maxX); |
|
| 3471 | + $this->_maxY = max($this->_maxY, $maxY); |
|
| 3472 | + |
|
| 3473 | + return true; |
|
| 3474 | + } |
|
| 3475 | + |
|
| 3476 | + /** |
|
| 3477 | + * tag : BR |
|
| 3478 | + * mode : OPEN |
|
| 3479 | + * |
|
| 3480 | + * @param array $param |
|
| 3481 | + * @param integer $curr real position in the html parseur (if break line in the write of a text) |
|
| 3482 | + * @return boolean |
|
| 3483 | + */ |
|
| 3484 | + protected function _tag_open_BR($param, $curr = null) |
|
| 3485 | + { |
|
| 3486 | + if ($this->_isForOneLine) return false; |
|
| 3487 | + |
|
| 3488 | + $h = max($this->_maxH, $this->parsingCss->getLineHeight()); |
|
| 3489 | + |
|
| 3490 | + if ($this->_maxH == 0) $this->_maxY = max($this->_maxY, $this->pdf->getY() + $h); |
|
| 3491 | + |
|
| 3492 | + $this->_makeBreakLine($h, $curr); |
|
| 3493 | + |
|
| 3494 | + $this->_maxH = 0; |
|
| 3495 | + $this->_maxE = 0; |
|
| 3496 | + |
|
| 3497 | + return true; |
|
| 3498 | + } |
|
| 3499 | + |
|
| 3500 | + /** |
|
| 3501 | + * tag : HR |
|
| 3502 | + * mode : OPEN |
|
| 3503 | + * |
|
| 3504 | + * @param array $param |
|
| 3505 | + * @return boolean |
|
| 3506 | + */ |
|
| 3507 | + protected function _tag_open_HR($param) |
|
| 3508 | + { |
|
| 3509 | + if ($this->_isForOneLine) { |
|
| 3510 | + return false; |
|
| 3511 | + } |
|
| 3512 | + $oldAlign = $this->parsingCss->value['text-align']; |
|
| 3513 | + $this->parsingCss->value['text-align'] = 'left'; |
|
| 3514 | + |
|
| 3515 | + if ($this->_maxH) { |
|
| 3516 | + $this->_tag_open_BR($param); |
|
| 3517 | + } |
|
| 3518 | + |
|
| 3519 | + $fontSize = $this->parsingCss->value['font-size']; |
|
| 3520 | + $this->parsingCss->value['font-size'] = $fontSize * 0.5; $this->_tag_open_BR($param); |
|
| 3521 | + $this->parsingCss->value['font-size'] = 0; |
|
| 3522 | + |
|
| 3523 | + $param['style']['width'] = '100%'; |
|
| 3524 | + |
|
| 3525 | + $this->parsingCss->save(); |
|
| 3526 | + $this->parsingCss->value['height'] = $this->parsingCss->ConvertToMM('1mm'); |
|
| 3527 | + |
|
| 3528 | + $this->parsingCss->analyse('hr', $param); |
|
| 3529 | + $this->parsingCss->setPosition(); |
|
| 3530 | + $this->parsingCss->fontSet(); |
|
| 3531 | + |
|
| 3532 | + $h = $this->parsingCss->value['height']; |
|
| 3533 | + if ($h) $h -= $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['border']['b']['width']; |
|
| 3534 | + if ($h <= 0) $h = $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['border']['b']['width']; |
|
| 3535 | + |
|
| 3536 | + $this->_drawRectangle($this->pdf->getX(), $this->pdf->getY(), $this->parsingCss->value['width'], $h, $this->parsingCss->value['border'], 0, 0, $this->parsingCss->value['background']); |
|
| 3537 | + $this->_maxH = $h; |
|
| 3538 | + |
|
| 3539 | + $this->parsingCss->load(); |
|
| 3540 | + $this->parsingCss->fontSet(); |
|
| 3541 | + |
|
| 3542 | + $this->_tag_open_BR($param); |
|
| 3543 | + |
|
| 3544 | + $this->parsingCss->value['font-size'] = $fontSize * 0.5; $this->_tag_open_BR($param); |
|
| 3545 | + $this->parsingCss->value['font-size'] = $fontSize; |
|
| 3546 | + |
|
| 3547 | + $this->parsingCss->value['text-align'] = $oldAlign; |
|
| 3548 | + $this->_setNewPositionForNewLine(); |
|
| 3549 | + |
|
| 3550 | + return true; |
|
| 3551 | + } |
|
| 3552 | + |
|
| 3553 | + /** |
|
| 3554 | + * tag : B |
|
| 3555 | + * mode : OPEN |
|
| 3556 | + * |
|
| 3557 | + * @param array $param |
|
| 3558 | + * @param string $other |
|
| 3559 | + * @return boolean |
|
| 3560 | + */ |
|
| 3561 | + protected function _tag_open_B($param, $other = 'b') |
|
| 3562 | + { |
|
| 3563 | + $this->parsingCss->save(); |
|
| 3564 | + $this->parsingCss->value['font-bold'] = true; |
|
| 3565 | + $this->parsingCss->analyse($other, $param); |
|
| 3566 | + $this->parsingCss->setPosition(); |
|
| 3567 | + $this->parsingCss->fontSet(); |
|
| 3568 | + |
|
| 3569 | + return true; |
|
| 3570 | + } |
|
| 3571 | + |
|
| 3572 | + /** |
|
| 3573 | + * tag : STRONG |
|
| 3574 | + * mode : OPEN |
|
| 3575 | + * |
|
| 3576 | + * @param array $param |
|
| 3577 | + * @return boolean |
|
| 3578 | + */ |
|
| 3579 | + protected function _tag_open_STRONG($param) |
|
| 3580 | + { |
|
| 3581 | + return $this->_tag_open_B($param, 'strong'); |
|
| 3582 | + } |
|
| 3583 | + |
|
| 3584 | + /** |
|
| 3585 | + * tag : B |
|
| 3586 | + * mode : CLOSE |
|
| 3587 | + * |
|
| 3588 | + * @param array $param |
|
| 3589 | + * @return boolean |
|
| 3590 | + */ |
|
| 3591 | + protected function _tag_close_B($param) |
|
| 3592 | + { |
|
| 3593 | + $this->parsingCss->load(); |
|
| 3594 | + $this->parsingCss->fontSet(); |
|
| 3595 | + |
|
| 3596 | + return true; |
|
| 3597 | + } |
|
| 3598 | + |
|
| 3599 | + /** |
|
| 3600 | + * tag : STRONG |
|
| 3601 | + * mode : CLOSE |
|
| 3602 | + * |
|
| 3603 | + * @param array $param |
|
| 3604 | + * @return boolean |
|
| 3605 | + */ |
|
| 3606 | + protected function _tag_close_STRONG($param) |
|
| 3607 | + { |
|
| 3608 | + return $this->_tag_close_B($param); |
|
| 3609 | + } |
|
| 3610 | + |
|
| 3611 | + /** |
|
| 3612 | + * tag : I |
|
| 3613 | + * mode : OPEN |
|
| 3614 | + * |
|
| 3615 | + * @param array $param |
|
| 3616 | + * @param string $other |
|
| 3617 | + * @return boolean |
|
| 3618 | + */ |
|
| 3619 | + protected function _tag_open_I($param, $other = 'i') |
|
| 3620 | + { |
|
| 3621 | + $this->parsingCss->save(); |
|
| 3622 | + $this->parsingCss->value['font-italic'] = true; |
|
| 3623 | + $this->parsingCss->analyse($other, $param); |
|
| 3624 | + $this->parsingCss->setPosition(); |
|
| 3625 | + $this->parsingCss->fontSet(); |
|
| 3626 | + |
|
| 3627 | + return true; |
|
| 3628 | + } |
|
| 3629 | + |
|
| 3630 | + /** |
|
| 3631 | + * tag : ADDRESS |
|
| 3632 | + * mode : OPEN |
|
| 3633 | + * |
|
| 3634 | + * @param array $param |
|
| 3635 | + * @return boolean |
|
| 3636 | + */ |
|
| 3637 | + protected function _tag_open_ADDRESS($param) |
|
| 3638 | + { |
|
| 3639 | + return $this->_tag_open_I($param, 'address'); |
|
| 3640 | + } |
|
| 3641 | + |
|
| 3642 | + /** |
|
| 3643 | + * tag : CITE |
|
| 3644 | + * mode : OPEN |
|
| 3645 | + * |
|
| 3646 | + * @param array $param |
|
| 3647 | + * @return boolean |
|
| 3648 | + */ |
|
| 3649 | + protected function _tag_open_CITE($param) |
|
| 3650 | + { |
|
| 3651 | + return $this->_tag_open_I($param, 'cite'); |
|
| 3652 | + } |
|
| 3653 | + |
|
| 3654 | + /** |
|
| 3655 | + * tag : EM |
|
| 3656 | + * mode : OPEN |
|
| 3657 | + * |
|
| 3658 | + * @param array $param |
|
| 3659 | + * @return boolean |
|
| 3660 | + */ |
|
| 3661 | + protected function _tag_open_EM($param) |
|
| 3662 | + { |
|
| 3663 | + return $this->_tag_open_I($param, 'em'); |
|
| 3664 | + } |
|
| 3665 | + |
|
| 3666 | + /** |
|
| 3667 | + * tag : SAMP |
|
| 3668 | + * mode : OPEN |
|
| 3669 | + * |
|
| 3670 | + * @param array $param |
|
| 3671 | + * @return boolean |
|
| 3672 | + */ |
|
| 3673 | + protected function _tag_open_SAMP($param) |
|
| 3674 | + { |
|
| 3675 | + return $this->_tag_open_I($param, 'samp'); |
|
| 3676 | + } |
|
| 3677 | + |
|
| 3678 | + /** |
|
| 3679 | + * tag : I |
|
| 3680 | + * mode : CLOSE |
|
| 3681 | + * |
|
| 3682 | + * @param array $param |
|
| 3683 | + * @return boolean |
|
| 3684 | + */ |
|
| 3685 | + protected function _tag_close_I($param) |
|
| 3686 | + { |
|
| 3687 | + $this->parsingCss->load(); |
|
| 3688 | + $this->parsingCss->fontSet(); |
|
| 3689 | + |
|
| 3690 | + return true; |
|
| 3691 | + } |
|
| 3692 | + |
|
| 3693 | + /** |
|
| 3694 | + * tag : ADDRESS |
|
| 3695 | + * mode : CLOSE |
|
| 3696 | + * |
|
| 3697 | + * @param array $param |
|
| 3698 | + * @return boolean |
|
| 3699 | + */ |
|
| 3700 | + protected function _tag_close_ADDRESS($param) |
|
| 3701 | + { |
|
| 3702 | + return $this->_tag_close_I($param); |
|
| 3703 | + } |
|
| 3704 | + |
|
| 3705 | + /** |
|
| 3706 | + * tag : CITE |
|
| 3707 | + * mode : CLOSE |
|
| 3708 | + * |
|
| 3709 | + * @param array $param |
|
| 3710 | + * @return boolean |
|
| 3711 | + */ |
|
| 3712 | + protected function _tag_close_CITE($param) |
|
| 3713 | + { |
|
| 3714 | + return $this->_tag_close_I($param); |
|
| 3715 | + } |
|
| 3716 | + |
|
| 3717 | + /** |
|
| 3718 | + * tag : EM |
|
| 3719 | + * mode : CLOSE |
|
| 3720 | + * |
|
| 3721 | + * @param array $param |
|
| 3722 | + * @return boolean |
|
| 3723 | + */ |
|
| 3724 | + protected function _tag_close_EM($param) |
|
| 3725 | + { |
|
| 3726 | + return $this->_tag_close_I($param); |
|
| 3727 | + } |
|
| 3728 | + |
|
| 3729 | + /** |
|
| 3730 | + * tag : SAMP |
|
| 3731 | + * mode : CLOSE |
|
| 3732 | + * |
|
| 3733 | + * @param array $param |
|
| 3734 | + * @return boolean |
|
| 3735 | + */ |
|
| 3736 | + protected function _tag_close_SAMP($param) |
|
| 3737 | + { |
|
| 3738 | + return $this->_tag_close_I($param); |
|
| 3739 | + } |
|
| 3740 | + |
|
| 3741 | + /** |
|
| 3742 | + * tag : S |
|
| 3743 | + * mode : OPEN |
|
| 3744 | + * |
|
| 3745 | + * @param array $param |
|
| 3746 | + * @param string $other |
|
| 3747 | + * @return boolean |
|
| 3748 | + */ |
|
| 3749 | + protected function _tag_open_S($param, $other = 's') |
|
| 3750 | + { |
|
| 3751 | + $this->parsingCss->save(); |
|
| 3752 | + $this->parsingCss->value['font-linethrough'] = true; |
|
| 3753 | + $this->parsingCss->analyse($other, $param); |
|
| 3754 | + $this->parsingCss->setPosition(); |
|
| 3755 | + $this->parsingCss->fontSet(); |
|
| 3756 | + |
|
| 3757 | + return true; |
|
| 3758 | + } |
|
| 3759 | + |
|
| 3760 | + /** |
|
| 3761 | + * tag : DEL |
|
| 3762 | + * mode : OPEN |
|
| 3763 | + * |
|
| 3764 | + * @param array $param |
|
| 3765 | + * @return boolean |
|
| 3766 | + */ |
|
| 3767 | + protected function _tag_open_DEL($param) |
|
| 3768 | + { |
|
| 3769 | + return $this->_tag_open_S($param, 'del'); |
|
| 3770 | + } |
|
| 3771 | + |
|
| 3772 | + /** |
|
| 3773 | + * tag : S |
|
| 3774 | + * mode : CLOSE |
|
| 3775 | + * |
|
| 3776 | + * @param array $param |
|
| 3777 | + * @return boolean |
|
| 3778 | + */ |
|
| 3779 | + protected function _tag_close_S($param) |
|
| 3780 | + { |
|
| 3781 | + $this->parsingCss->load(); |
|
| 3782 | + $this->parsingCss->fontSet(); |
|
| 3783 | + |
|
| 3784 | + return true; |
|
| 3785 | + } |
|
| 3786 | + |
|
| 3787 | + /** |
|
| 3788 | + * tag : DEL |
|
| 3789 | + * mode : CLOSE |
|
| 3790 | + * |
|
| 3791 | + * @param array $param |
|
| 3792 | + * @return boolean |
|
| 3793 | + */ |
|
| 3794 | + protected function _tag_close_DEL($param) |
|
| 3795 | + { |
|
| 3796 | + return $this->_tag_close_S($param); |
|
| 3797 | + } |
|
| 3798 | + |
|
| 3799 | + /** |
|
| 3800 | + * tag : U |
|
| 3801 | + * mode : OPEN |
|
| 3802 | + * |
|
| 3803 | + * @param array $param |
|
| 3804 | + * @param string $other |
|
| 3805 | + * @return boolean |
|
| 3806 | + */ |
|
| 3807 | + protected function _tag_open_U($param, $other = 'u') |
|
| 3808 | + { |
|
| 3809 | + $this->parsingCss->save(); |
|
| 3810 | + $this->parsingCss->value['font-underline'] = true; |
|
| 3811 | + $this->parsingCss->analyse($other, $param); |
|
| 3812 | + $this->parsingCss->setPosition(); |
|
| 3813 | + $this->parsingCss->fontSet(); |
|
| 3814 | + |
|
| 3815 | + return true; |
|
| 3816 | + } |
|
| 3817 | + |
|
| 3818 | + /** |
|
| 3819 | + * tag : INS |
|
| 3820 | + * mode : OPEN |
|
| 3821 | + * |
|
| 3822 | + * @param array $param |
|
| 3823 | + * @return boolean |
|
| 3824 | + */ |
|
| 3825 | + protected function _tag_open_INS($param) |
|
| 3826 | + { |
|
| 3827 | + return $this->_tag_open_U($param, 'ins'); |
|
| 3828 | + } |
|
| 3829 | + |
|
| 3830 | + /** |
|
| 3831 | + * tag : U |
|
| 3832 | + * mode : CLOSE |
|
| 3833 | + * |
|
| 3834 | + * @param array $param |
|
| 3835 | + * @return boolean |
|
| 3836 | + */ |
|
| 3837 | + protected function _tag_close_U($param) |
|
| 3838 | + { |
|
| 3839 | + $this->parsingCss->load(); |
|
| 3840 | + $this->parsingCss->fontSet(); |
|
| 3841 | + |
|
| 3842 | + return true; |
|
| 3843 | + } |
|
| 3844 | + |
|
| 3845 | + /** |
|
| 3846 | + * tag : INS |
|
| 3847 | + * mode : CLOSE |
|
| 3848 | + * |
|
| 3849 | + * @param array $param |
|
| 3850 | + * @return boolean |
|
| 3851 | + */ |
|
| 3852 | + protected function _tag_close_INS($param) |
|
| 3853 | + { |
|
| 3854 | + return $this->_tag_close_U($param); |
|
| 3855 | + } |
|
| 3856 | + |
|
| 3857 | + /** |
|
| 3858 | + * tag : A |
|
| 3859 | + * mode : OPEN |
|
| 3860 | + * |
|
| 3861 | + * @param array $param |
|
| 3862 | + * @return boolean |
|
| 3863 | + */ |
|
| 3864 | + protected function _tag_open_A($param) |
|
| 3865 | + { |
|
| 3866 | + $this->_isInLink = str_replace('&', '&', isset($param['href']) ? $param['href'] : ''); |
|
| 3867 | + |
|
| 3868 | + if (isset($param['name'])) { |
|
| 3869 | + $name = $param['name']; |
|
| 3870 | + if ( ! isset($this->_lstAnchor[$name])) $this->_lstAnchor[$name] = array($this->pdf->AddLink(), false); |
|
| 3871 | + |
|
| 3872 | + if ( ! $this->_lstAnchor[$name][1]) { |
|
| 3873 | + $this->_lstAnchor[$name][1] = true; |
|
| 3874 | + $this->pdf->SetLink($this->_lstAnchor[$name][0], -1, -1); |
|
| 3875 | + } |
|
| 3876 | + } |
|
| 3877 | + |
|
| 3878 | + if (preg_match('/^#([^#]+)$/isU', $this->_isInLink, $match)) { |
|
| 3879 | + $name = $match[1]; |
|
| 3880 | + if ( ! isset($this->_lstAnchor[$name])) $this->_lstAnchor[$name] = array($this->pdf->AddLink(), false); |
|
| 3881 | + |
|
| 3882 | + $this->_isInLink = $this->_lstAnchor[$name][0]; |
|
| 3883 | + } |
|
| 3884 | + |
|
| 3885 | + $this->parsingCss->save(); |
|
| 3886 | + $this->parsingCss->value['font-underline'] = true; |
|
| 3887 | + $this->parsingCss->value['color'] = array(20, 20, 250); |
|
| 3888 | + $this->parsingCss->analyse('a', $param); |
|
| 3889 | + $this->parsingCss->setPosition(); |
|
| 3890 | + $this->parsingCss->fontSet(); |
|
| 3891 | + |
|
| 3892 | + return true; |
|
| 3893 | + } |
|
| 3894 | + |
|
| 3895 | + /** |
|
| 3896 | + * tag : A |
|
| 3897 | + * mode : CLOSE |
|
| 3898 | + * |
|
| 3899 | + * @param array $param |
|
| 3900 | + * @return boolean |
|
| 3901 | + */ |
|
| 3902 | + protected function _tag_close_A($param) |
|
| 3903 | + { |
|
| 3904 | + $this->_isInLink = ''; |
|
| 3905 | + $this->parsingCss->load(); |
|
| 3906 | + $this->parsingCss->fontSet(); |
|
| 3907 | + |
|
| 3908 | + return true; |
|
| 3909 | + } |
|
| 3910 | + |
|
| 3911 | + /** |
|
| 3912 | + * tag : H1 |
|
| 3913 | + * mode : OPEN |
|
| 3914 | + * |
|
| 3915 | + * @param array $param |
|
| 3916 | + * @param string $other |
|
| 3917 | + * @return boolean |
|
| 3918 | + */ |
|
| 3919 | + protected function _tag_open_H1($param, $other = 'h1') |
|
| 3920 | + { |
|
| 3921 | + if ($this->_isForOneLine) { |
|
| 3922 | + return false; |
|
| 3923 | + } |
|
| 3924 | + |
|
| 3925 | + if ($this->_maxH) { |
|
| 3926 | + $this->_tag_open_BR(array()); |
|
| 3927 | + } |
|
| 3928 | + $this->parsingCss->save(); |
|
| 3929 | + $this->parsingCss->value['font-bold'] = true; |
|
| 3930 | + |
|
| 3931 | + $size = array('h1' => '28px', 'h2' => '24px', 'h3' => '20px', 'h4' => '16px', 'h5' => '12px', 'h6' => '9px'); |
|
| 3932 | + $this->parsingCss->value['margin']['l'] = 0; |
|
| 3933 | + $this->parsingCss->value['margin']['r'] = 0; |
|
| 3934 | + $this->parsingCss->value['margin']['t'] = $this->parsingCss->ConvertToMM('16px'); |
|
| 3935 | + $this->parsingCss->value['margin']['b'] = $this->parsingCss->ConvertToMM('16px'); |
|
| 3936 | + $this->parsingCss->value['font-size'] = $this->parsingCss->ConvertToMM($size[$other]); |
|
| 3937 | + |
|
| 3938 | + $this->parsingCss->analyse($other, $param); |
|
| 3939 | + $this->parsingCss->setPosition(); |
|
| 3940 | + $this->parsingCss->fontSet(); |
|
| 3941 | + $this->_setNewPositionForNewLine(); |
|
| 3942 | + |
|
| 3943 | + return true; |
|
| 3944 | + } |
|
| 3945 | + |
|
| 3946 | + /** |
|
| 3947 | + * tag : H2 |
|
| 3948 | + * mode : OPEN |
|
| 3949 | + * |
|
| 3950 | + * @param array $param |
|
| 3951 | + * @return boolean |
|
| 3952 | + */ |
|
| 3953 | + protected function _tag_open_H2($param) |
|
| 3954 | + { |
|
| 3955 | + return $this->_tag_open_H1($param, 'h2'); |
|
| 3956 | + } |
|
| 3957 | + |
|
| 3958 | + /** |
|
| 3959 | + * tag : H3 |
|
| 3960 | + * mode : OPEN |
|
| 3961 | + * |
|
| 3962 | + * @param array $param |
|
| 3963 | + * @return boolean |
|
| 3964 | + */ |
|
| 3965 | + protected function _tag_open_H3($param) |
|
| 3966 | + { |
|
| 3967 | + return $this->_tag_open_H1($param, 'h3'); |
|
| 3968 | + } |
|
| 3969 | + |
|
| 3970 | + /** |
|
| 3971 | + * tag : H4 |
|
| 3972 | + * mode : OPEN |
|
| 3973 | + * |
|
| 3974 | + * @param array $param |
|
| 3975 | + * @return boolean |
|
| 3976 | + */ |
|
| 3977 | + protected function _tag_open_H4($param) |
|
| 3978 | + { |
|
| 3979 | + return $this->_tag_open_H1($param, 'h4'); |
|
| 3980 | + } |
|
| 3981 | + |
|
| 3982 | + /** |
|
| 3983 | + * tag : H5 |
|
| 3984 | + * mode : OPEN |
|
| 3985 | + * |
|
| 3986 | + * @param array $param |
|
| 3987 | + * @return boolean |
|
| 3988 | + */ |
|
| 3989 | + protected function _tag_open_H5($param) |
|
| 3990 | + { |
|
| 3991 | + return $this->_tag_open_H1($param, 'h5'); |
|
| 3992 | + } |
|
| 3993 | + |
|
| 3994 | + /** |
|
| 3995 | + * tag : H6 |
|
| 3996 | + * mode : OPEN |
|
| 3997 | + * |
|
| 3998 | + * @param array $param |
|
| 3999 | + * @return boolean |
|
| 4000 | + */ |
|
| 4001 | + protected function _tag_open_H6($param) |
|
| 4002 | + { |
|
| 4003 | + return $this->_tag_open_H1($param, 'h6'); |
|
| 4004 | + } |
|
| 4005 | + |
|
| 4006 | + /** |
|
| 4007 | + * tag : H1 |
|
| 4008 | + * mode : CLOSE |
|
| 4009 | + * |
|
| 4010 | + * @param array $param |
|
| 4011 | + * @return boolean |
|
| 4012 | + */ |
|
| 4013 | + protected function _tag_close_H1($param) |
|
| 4014 | + { |
|
| 4015 | + if ($this->_isForOneLine) { |
|
| 4016 | + return false; |
|
| 4017 | + } |
|
| 4018 | + |
|
| 4019 | + $this->_maxH += $this->parsingCss->value['margin']['b']; |
|
| 4020 | + $h = max($this->_maxH, $this->parsingCss->getLineHeight()); |
|
| 4021 | + |
|
| 4022 | + $this->parsingCss->load(); |
|
| 4023 | + $this->parsingCss->fontSet(); |
|
| 4024 | + |
|
| 4025 | + $this->_makeBreakLine($h); |
|
| 4026 | + $this->_maxH = 0; |
|
| 4027 | + |
|
| 4028 | + $this->_maxY = max($this->_maxY, $this->pdf->getY()); |
|
| 4029 | + |
|
| 4030 | + return true; |
|
| 4031 | + } |
|
| 4032 | + |
|
| 4033 | + /** |
|
| 4034 | + * tag : H2 |
|
| 4035 | + * mode : CLOSE |
|
| 4036 | + * |
|
| 4037 | + * @param array $param |
|
| 4038 | + * @return boolean |
|
| 4039 | + */ |
|
| 4040 | + protected function _tag_close_H2($param) |
|
| 4041 | + { |
|
| 4042 | + return $this->_tag_close_H1($param); |
|
| 4043 | + } |
|
| 4044 | + |
|
| 4045 | + /** |
|
| 4046 | + * tag : H3 |
|
| 4047 | + * mode : CLOSE |
|
| 4048 | + * |
|
| 4049 | + * @param array $param |
|
| 4050 | + * @return boolean |
|
| 4051 | + */ |
|
| 4052 | + protected function _tag_close_H3($param) |
|
| 4053 | + { |
|
| 4054 | + return $this->_tag_close_H1($param); |
|
| 4055 | + } |
|
| 4056 | + |
|
| 4057 | + /** |
|
| 4058 | + * tag : H4 |
|
| 4059 | + * mode : CLOSE |
|
| 4060 | + * |
|
| 4061 | + * @param array $param |
|
| 4062 | + * @return boolean |
|
| 4063 | + */ |
|
| 4064 | + protected function _tag_close_H4($param) |
|
| 4065 | + { |
|
| 4066 | + return $this->_tag_close_H1($param); |
|
| 4067 | + } |
|
| 4068 | + |
|
| 4069 | + /** |
|
| 4070 | + * tag : H5 |
|
| 4071 | + * mode : CLOSE |
|
| 4072 | + * |
|
| 4073 | + * @param array $param |
|
| 4074 | + * @return boolean |
|
| 4075 | + */ |
|
| 4076 | + protected function _tag_close_H5($param) |
|
| 4077 | + { |
|
| 4078 | + return $this->_tag_close_H1($param); |
|
| 4079 | + } |
|
| 4080 | + |
|
| 4081 | + /** |
|
| 4082 | + * tag : H6 |
|
| 4083 | + * mode : CLOSE |
|
| 4084 | + * |
|
| 4085 | + * @param array $param |
|
| 4086 | + * @return boolean |
|
| 4087 | + */ |
|
| 4088 | + protected function _tag_close_H6($param) |
|
| 4089 | + { |
|
| 4090 | + return $this->_tag_close_H1($param); |
|
| 4091 | + } |
|
| 4092 | + |
|
| 4093 | + /** |
|
| 4094 | + * tag : SPAN |
|
| 4095 | + * mode : OPEN |
|
| 4096 | + * |
|
| 4097 | + * @param array $param |
|
| 4098 | + * @param string $other |
|
| 4099 | + * @return boolean |
|
| 4100 | + */ |
|
| 4101 | + protected function _tag_open_SPAN($param, $other = 'span') |
|
| 4102 | + { |
|
| 4103 | + $this->parsingCss->save(); |
|
| 4104 | + $this->parsingCss->analyse($other, $param); |
|
| 4105 | + $this->parsingCss->setPosition(); |
|
| 4106 | + $this->parsingCss->fontSet(); |
|
| 4107 | + |
|
| 4108 | + return true; |
|
| 4109 | + } |
|
| 4110 | + |
|
| 4111 | + /** |
|
| 4112 | + * tag : FONT |
|
| 4113 | + * mode : OPEN |
|
| 4114 | + * |
|
| 4115 | + * @param array $param |
|
| 4116 | + * @return boolean |
|
| 4117 | + */ |
|
| 4118 | + protected function _tag_open_FONT($param) |
|
| 4119 | + { |
|
| 4120 | + return $this->_tag_open_SPAN($param, 'font'); |
|
| 4121 | + } |
|
| 4122 | + |
|
| 4123 | + /** |
|
| 4124 | + * tag : LABEL |
|
| 4125 | + * mode : OPEN |
|
| 4126 | + * |
|
| 4127 | + * @param array $param |
|
| 4128 | + * @return boolean |
|
| 4129 | + */ |
|
| 4130 | + protected function _tag_open_LABEL($param) |
|
| 4131 | + { |
|
| 4132 | + return $this->_tag_open_SPAN($param, 'label'); |
|
| 4133 | + } |
|
| 4134 | + |
|
| 4135 | + /** |
|
| 4136 | + * tag : SPAN |
|
| 4137 | + * mode : CLOSE |
|
| 4138 | + * |
|
| 4139 | + * @param array $param |
|
| 4140 | + * @return boolean |
|
| 4141 | + */ |
|
| 4142 | + protected function _tag_close_SPAN($param) |
|
| 4143 | + { |
|
| 4144 | + $this->parsingCss->restorePosition(); |
|
| 4145 | + $this->parsingCss->load(); |
|
| 4146 | + $this->parsingCss->fontSet(); |
|
| 4147 | + |
|
| 4148 | + return true; |
|
| 4149 | + } |
|
| 4150 | + |
|
| 4151 | + /** |
|
| 4152 | + * tag : FONT |
|
| 4153 | + * mode : CLOSE |
|
| 4154 | + * |
|
| 4155 | + * @param array $param |
|
| 4156 | + * @return boolean |
|
| 4157 | + */ |
|
| 4158 | + protected function _tag_close_FONT($param) |
|
| 4159 | + { |
|
| 4160 | + return $this->_tag_close_SPAN($param); |
|
| 4161 | + } |
|
| 4162 | + |
|
| 4163 | + /** |
|
| 4164 | + * tag : LABEL |
|
| 4165 | + * mode : CLOSE |
|
| 4166 | + * |
|
| 4167 | + * @param array $param |
|
| 4168 | + * @return boolean |
|
| 4169 | + */ |
|
| 4170 | + protected function _tag_close_LABEL($param) |
|
| 4171 | + { |
|
| 4172 | + return $this->_tag_close_SPAN($param); |
|
| 4173 | + } |
|
| 4174 | + |
|
| 4175 | + /** |
|
| 4176 | + * tag : P |
|
| 4177 | + * mode : OPEN |
|
| 4178 | + * |
|
| 4179 | + * @param array $param |
|
| 4180 | + * @return boolean |
|
| 4181 | + */ |
|
| 4182 | + protected function _tag_open_P($param) |
|
| 4183 | + { |
|
| 4184 | + if ($this->_isForOneLine) return false; |
|
| 4185 | + |
|
| 4186 | + if ( ! in_array($this->_previousCall, array('_tag_close_P', '_tag_close_UL'))) { |
|
| 4187 | + if ($this->_maxH) $this->_tag_open_BR(array()); |
|
| 4188 | + } |
|
| 4189 | + |
|
| 4190 | + $this->parsingCss->save(); |
|
| 4191 | + $this->parsingCss->analyse('p', $param); |
|
| 4192 | + $this->parsingCss->setPosition(); |
|
| 4193 | + $this->parsingCss->fontSet(); |
|
| 4194 | + |
|
| 4195 | + // cancel the effects of the setPosition |
|
| 4196 | + $this->pdf->setXY($this->pdf->getX() - $this->parsingCss->value['margin']['l'], $this->pdf->getY() - $this->parsingCss->value['margin']['t']); |
|
| 4197 | + |
|
| 4198 | + list($mL, $mR) = $this->_getMargins($this->pdf->getY()); |
|
| 4199 | + $mR = $this->pdf->getW() - $mR; |
|
| 4200 | + $mL += $this->parsingCss->value['margin']['l'] + $this->parsingCss->value['padding']['l']; |
|
| 4201 | + $mR += $this->parsingCss->value['margin']['r'] + $this->parsingCss->value['padding']['r']; |
|
| 4202 | + $this->_saveMargin($mL, 0, $mR); |
|
| 4203 | + |
|
| 4204 | + if ($this->parsingCss->value['text-indent'] > 0) { |
|
| 4205 | + $y = $this->pdf->getY() + $this->parsingCss->value['margin']['t'] + $this->parsingCss->value['padding']['t']; |
|
| 4206 | + $this->_pageMarges[floor($y * 100)] = array($mL + $this->parsingCss->value['text-indent'], $this->pdf->getW() - $mR); |
|
| 4207 | + $y += $this->parsingCss->getLineHeight() * 0.1; |
|
| 4208 | + $this->_pageMarges[floor($y * 100)] = array($mL, $this->pdf->getW() - $mR); |
|
| 4209 | + } |
|
| 4210 | + $this->_makeBreakLine($this->parsingCss->value['margin']['t'] + $this->parsingCss->value['padding']['t']); |
|
| 4211 | + $this->_isInParagraph = array($mL, $mR); |
|
| 4212 | + return true; |
|
| 4213 | + } |
|
| 4214 | + |
|
| 4215 | + /** |
|
| 4216 | + * tag : P |
|
| 4217 | + * mode : CLOSE |
|
| 4218 | + * |
|
| 4219 | + * @param array $param |
|
| 4220 | + * @return boolean |
|
| 4221 | + */ |
|
| 4222 | + protected function _tag_close_P($param) |
|
| 4223 | + { |
|
| 4224 | + if ($this->_isForOneLine) { |
|
| 4225 | + return false; |
|
| 4226 | + } |
|
| 4227 | + |
|
| 4228 | + if ($this->_maxH) { |
|
| 4229 | + $this->_tag_open_BR(array()); |
|
| 4230 | + } |
|
| 4231 | + $this->_isInParagraph = false; |
|
| 4232 | + $this->_loadMargin(); |
|
| 4233 | + $h = $this->parsingCss->value['margin']['b'] + $this->parsingCss->value['padding']['b']; |
|
| 4234 | + |
|
| 4235 | + $this->parsingCss->load(); |
|
| 4236 | + $this->parsingCss->fontSet(); |
|
| 4237 | + $this->_makeBreakLine($h); |
|
| 4238 | + |
|
| 4239 | + return true; |
|
| 4240 | + } |
|
| 4241 | + |
|
| 4242 | + /** |
|
| 4243 | + * tag : PRE |
|
| 4244 | + * mode : OPEN |
|
| 4245 | + * |
|
| 4246 | + * @param array $param |
|
| 4247 | + * @param string $other |
|
| 4248 | + * @return boolean |
|
| 4249 | + */ |
|
| 4250 | + protected function _tag_open_PRE($param, $other = 'pre') |
|
| 4251 | + { |
|
| 4252 | + if ($other == 'pre' && $this->_maxH) $this->_tag_open_BR(array()); |
|
| 4253 | + |
|
| 4254 | + $this->parsingCss->save(); |
|
| 4255 | + $this->parsingCss->value['font-family'] = 'courier'; |
|
| 4256 | + $this->parsingCss->analyse($other, $param); |
|
| 4257 | + $this->parsingCss->setPosition(); |
|
| 4258 | + $this->parsingCss->fontSet(); |
|
| 4259 | + |
|
| 4260 | + if ($other == 'pre') return $this->_tag_open_DIV($param, $other); |
|
| 4261 | + |
|
| 4262 | + return true; |
|
| 4263 | + } |
|
| 4264 | + |
|
| 4265 | + /** |
|
| 4266 | + * tag : CODE |
|
| 4267 | + * mode : OPEN |
|
| 4268 | + * |
|
| 4269 | + * @param array $param |
|
| 4270 | + * @return boolean |
|
| 4271 | + */ |
|
| 4272 | + protected function _tag_open_CODE($param) |
|
| 4273 | + { |
|
| 4274 | + return $this->_tag_open_PRE($param, 'code'); |
|
| 4275 | + } |
|
| 4276 | + |
|
| 4277 | + /** |
|
| 4278 | + * tag : PRE |
|
| 4279 | + * mode : CLOSE |
|
| 4280 | + * |
|
| 4281 | + * @param array $param |
|
| 4282 | + * @param string $other |
|
| 4283 | + * @return boolean |
|
| 4284 | + */ |
|
| 4285 | + protected function _tag_close_PRE($param, $other = 'pre') |
|
| 4286 | + { |
|
| 4287 | + if ($other == 'pre') { |
|
| 4288 | + if ($this->_isForOneLine) return false; |
|
| 4289 | + |
|
| 4290 | + $this->_tag_close_DIV($param, $other); |
|
| 4291 | + $this->_tag_open_BR(array()); |
|
| 4292 | + } |
|
| 4293 | + $this->parsingCss->load(); |
|
| 4294 | + $this->parsingCss->fontSet(); |
|
| 4295 | + |
|
| 4296 | + return true; |
|
| 4297 | + } |
|
| 4298 | + |
|
| 4299 | + /** |
|
| 4300 | + * tag : CODE |
|
| 4301 | + * mode : CLOSE |
|
| 4302 | + * |
|
| 4303 | + * @param array $param |
|
| 4304 | + * @return boolean |
|
| 4305 | + */ |
|
| 4306 | + protected function _tag_close_CODE($param) |
|
| 4307 | + { |
|
| 4308 | + return $this->_tag_close_PRE($param, 'code'); |
|
| 4309 | + } |
|
| 4310 | + |
|
| 4311 | + /** |
|
| 4312 | + * tag : BIG |
|
| 4313 | + * mode : OPEN |
|
| 4314 | + * |
|
| 4315 | + * @param array $param |
|
| 4316 | + * @return boolean |
|
| 4317 | + */ |
|
| 4318 | + protected function _tag_open_BIG($param) |
|
| 4319 | + { |
|
| 4320 | + $this->parsingCss->save(); |
|
| 4321 | + $this->parsingCss->value['mini-decal'] -= $this->parsingCss->value['mini-size'] * 0.12; |
|
| 4322 | + $this->parsingCss->value['mini-size'] *= 1.2; |
|
| 4323 | + $this->parsingCss->analyse('big', $param); |
|
| 4324 | + $this->parsingCss->setPosition(); |
|
| 4325 | + $this->parsingCss->fontSet(); |
|
| 4326 | + return true; |
|
| 4327 | + } |
|
| 4328 | + |
|
| 4329 | + /** |
|
| 4330 | + * tag : BIG |
|
| 4331 | + * mode : CLOSE |
|
| 4332 | + * |
|
| 4333 | + * @param array $param |
|
| 4334 | + * @return boolean |
|
| 4335 | + */ |
|
| 4336 | + protected function _tag_close_BIG($param) |
|
| 4337 | + { |
|
| 4338 | + $this->parsingCss->load(); |
|
| 4339 | + $this->parsingCss->fontSet(); |
|
| 4340 | + |
|
| 4341 | + return true; |
|
| 4342 | + } |
|
| 4343 | + |
|
| 4344 | + /** |
|
| 4345 | + * tag : SMALL |
|
| 4346 | + * mode : OPEN |
|
| 4347 | + * |
|
| 4348 | + * @param array $param |
|
| 4349 | + * @return boolean |
|
| 4350 | + */ |
|
| 4351 | + protected function _tag_open_SMALL($param) |
|
| 4352 | + { |
|
| 4353 | + $this->parsingCss->save(); |
|
| 4354 | + $this->parsingCss->value['mini-decal'] += $this->parsingCss->value['mini-size'] * 0.05; |
|
| 4355 | + $this->parsingCss->value['mini-size'] *= 0.82; |
|
| 4356 | + $this->parsingCss->analyse('small', $param); |
|
| 4357 | + $this->parsingCss->setPosition(); |
|
| 4358 | + $this->parsingCss->fontSet(); |
|
| 4359 | + return true; |
|
| 4360 | + } |
|
| 4361 | + |
|
| 4362 | + /** |
|
| 4363 | + * tag : SMALL |
|
| 4364 | + * mode : CLOSE |
|
| 4365 | + * |
|
| 4366 | + * @param array $param |
|
| 4367 | + * @return boolean |
|
| 4368 | + */ |
|
| 4369 | + protected function _tag_close_SMALL($param) |
|
| 4370 | + { |
|
| 4371 | + $this->parsingCss->load(); |
|
| 4372 | + $this->parsingCss->fontSet(); |
|
| 4373 | + |
|
| 4374 | + return true; |
|
| 4375 | + } |
|
| 4376 | + |
|
| 4377 | + /** |
|
| 4378 | + * tag : SUP |
|
| 4379 | + * mode : OPEN |
|
| 4380 | + * |
|
| 4381 | + * @param array $param |
|
| 4382 | + * @return boolean |
|
| 4383 | + */ |
|
| 4384 | + protected function _tag_open_SUP($param) |
|
| 4385 | + { |
|
| 4386 | + $this->parsingCss->save(); |
|
| 4387 | + $this->parsingCss->value['mini-decal'] -= $this->parsingCss->value['mini-size'] * 0.15; |
|
| 4388 | + $this->parsingCss->value['mini-size'] *= 0.75; |
|
| 4389 | + $this->parsingCss->analyse('sup', $param); |
|
| 4390 | + $this->parsingCss->setPosition(); |
|
| 4391 | + $this->parsingCss->fontSet(); |
|
| 4392 | + |
|
| 4393 | + return true; |
|
| 4394 | + } |
|
| 4395 | + |
|
| 4396 | + /** |
|
| 4397 | + * tag : SUP |
|
| 4398 | + * mode : CLOSE |
|
| 4399 | + * |
|
| 4400 | + * @param array $param |
|
| 4401 | + * @return boolean |
|
| 4402 | + */ |
|
| 4403 | + protected function _tag_close_SUP($param) |
|
| 4404 | + { |
|
| 4405 | + $this->parsingCss->load(); |
|
| 4406 | + $this->parsingCss->fontSet(); |
|
| 4407 | + |
|
| 4408 | + return true; |
|
| 4409 | + } |
|
| 4410 | + |
|
| 4411 | + /** |
|
| 4412 | + * tag : SUB |
|
| 4413 | + * mode : OPEN |
|
| 4414 | + * |
|
| 4415 | + * @param array $param |
|
| 4416 | + * @return boolean |
|
| 4417 | + */ |
|
| 4418 | + protected function _tag_open_SUB($param) |
|
| 4419 | + { |
|
| 4420 | + $this->parsingCss->save(); |
|
| 4421 | + $this->parsingCss->value['mini-decal'] += $this->parsingCss->value['mini-size'] * 0.15; |
|
| 4422 | + $this->parsingCss->value['mini-size'] *= 0.75; |
|
| 4423 | + $this->parsingCss->analyse('sub', $param); |
|
| 4424 | + $this->parsingCss->setPosition(); |
|
| 4425 | + $this->parsingCss->fontSet(); |
|
| 4426 | + return true; |
|
| 4427 | + } |
|
| 4428 | + |
|
| 4429 | + /** |
|
| 4430 | + * tag : SUB |
|
| 4431 | + * mode : CLOSE |
|
| 4432 | + * |
|
| 4433 | + * @param array $param |
|
| 4434 | + * @return boolean |
|
| 4435 | + */ |
|
| 4436 | + protected function _tag_close_SUB($param) |
|
| 4437 | + { |
|
| 4438 | + $this->parsingCss->load(); |
|
| 4439 | + $this->parsingCss->fontSet(); |
|
| 4440 | + |
|
| 4441 | + return true; |
|
| 4442 | + } |
|
| 4443 | + |
|
| 4444 | + /** |
|
| 4445 | + * tag : UL |
|
| 4446 | + * mode : OPEN |
|
| 4447 | + * |
|
| 4448 | + * @param array $param |
|
| 4449 | + * @param string $other |
|
| 4450 | + * @return boolean |
|
| 4451 | + */ |
|
| 4452 | + protected function _tag_open_UL($param, $other = 'ul') |
|
| 4453 | + { |
|
| 4454 | + if ($this->_isForOneLine) return false; |
|
| 4455 | + |
|
| 4456 | + if ( ! in_array($this->_previousCall, array('_tag_close_P', '_tag_close_UL'))) { |
|
| 4457 | + if ($this->_maxH) $this->_tag_open_BR(array()); |
|
| 4458 | + if ( ! count($this->_defList)) $this->_tag_open_BR(array()); |
|
| 4459 | + } |
|
| 4460 | + |
|
| 4461 | + if ( ! isset($param['style']['width'])) $param['allwidth'] = true; |
|
| 4462 | + $param['cellspacing'] = 0; |
|
| 4463 | + |
|
| 4464 | + // a list is like a table |
|
| 4465 | + $this->_tag_open_TABLE($param, $other); |
|
| 4466 | + |
|
| 4467 | + // add a level of list |
|
| 4468 | + $this->_listeAddLevel($other, $this->parsingCss->value['list-style-type'], $this->parsingCss->value['list-style-image']); |
|
| 4469 | + |
|
| 4470 | + return true; |
|
| 4471 | + } |
|
| 4472 | + |
|
| 4473 | + /** |
|
| 4474 | + * tag : OL |
|
| 4475 | + * mode : OPEN |
|
| 4476 | + * |
|
| 4477 | + * @param array $param |
|
| 4478 | + * @return boolean |
|
| 4479 | + */ |
|
| 4480 | + protected function _tag_open_OL($param) |
|
| 4481 | + { |
|
| 4482 | + return $this->_tag_open_UL($param, 'ol'); |
|
| 4483 | + } |
|
| 4484 | + |
|
| 4485 | + /** |
|
| 4486 | + * tag : UL |
|
| 4487 | + * mode : CLOSE |
|
| 4488 | + * |
|
| 4489 | + * @param array $param |
|
| 4490 | + * @return boolean |
|
| 4491 | + */ |
|
| 4492 | + protected function _tag_close_UL($param) |
|
| 4493 | + { |
|
| 4494 | + if ($this->_isForOneLine) return false; |
|
| 4495 | + |
|
| 4496 | + $this->_tag_close_TABLE($param); |
|
| 4497 | + |
|
| 4498 | + $this->_listeDelLevel(); |
|
| 4499 | + |
|
| 4500 | + if ( ! $this->_subPart) { |
|
| 4501 | + if ( ! count($this->_defList)) $this->_tag_open_BR(array()); |
|
| 4502 | + } |
|
| 4503 | + |
|
| 4504 | + return true; |
|
| 4505 | + } |
|
| 4506 | + |
|
| 4507 | + /** |
|
| 4508 | + * tag : OL |
|
| 4509 | + * mode : CLOSE |
|
| 4510 | + * |
|
| 4511 | + * @param array $param |
|
| 4512 | + * @return boolean |
|
| 4513 | + */ |
|
| 4514 | + protected function _tag_close_OL($param) |
|
| 4515 | + { |
|
| 4516 | + return $this->_tag_close_UL($param); |
|
| 4517 | + } |
|
| 4518 | + |
|
| 4519 | + /** |
|
| 4520 | + * tag : LI |
|
| 4521 | + * mode : OPEN |
|
| 4522 | + * |
|
| 4523 | + * @param array $param |
|
| 4524 | + * @return boolean |
|
| 4525 | + */ |
|
| 4526 | + protected function _tag_open_LI($param) |
|
| 4527 | + { |
|
| 4528 | + if ($this->_isForOneLine) return false; |
|
| 4529 | + |
|
| 4530 | + $this->_listeAddLi(); |
|
| 4531 | + |
|
| 4532 | + if ( ! isset($param['style']['width'])) $param['style']['width'] = '100%'; |
|
| 4533 | + |
|
| 4534 | + $paramPUCE = $param; |
|
| 4535 | + |
|
| 4536 | + $inf = $this->_listeGetLi(); |
|
| 4537 | + if ($inf[0]) { |
|
| 4538 | + $paramPUCE['style']['font-family'] = $inf[0]; |
|
| 4539 | + $paramPUCE['style']['text-align'] = 'li_right'; |
|
| 4540 | + $paramPUCE['style']['vertical-align'] = 'top'; |
|
| 4541 | + $paramPUCE['style']['width'] = $this->_listeGetWidth(); |
|
| 4542 | + $paramPUCE['style']['padding-right'] = $this->_listeGetPadding(); |
|
| 4543 | + $paramPUCE['txt'] = $inf[2]; |
|
| 4544 | + } else { |
|
| 4545 | + $paramPUCE['style']['text-align'] = 'li_right'; |
|
| 4546 | + $paramPUCE['style']['vertical-align'] = 'top'; |
|
| 4547 | + $paramPUCE['style']['width'] = $this->_listeGetWidth(); |
|
| 4548 | + $paramPUCE['style']['padding-right'] = $this->_listeGetPadding(); |
|
| 4549 | + $paramPUCE['src'] = $inf[2]; |
|
| 4550 | + $paramPUCE['sub_li'] = true; |
|
| 4551 | + } |
|
| 4552 | + |
|
| 4553 | + $this->_tag_open_TR($param, 'li'); |
|
| 4554 | + |
|
| 4555 | + $this->parsingCss->save(); |
|
| 4556 | + |
|
| 4557 | + // if small LI |
|
| 4558 | + if ($inf[1]) { |
|
| 4559 | + $this->parsingCss->value['mini-decal'] += $this->parsingCss->value['mini-size'] * 0.045; |
|
| 4560 | + $this->parsingCss->value['mini-size'] *= 0.75; |
|
| 4561 | + } |
|
| 4562 | + |
|
| 4563 | + // if we are in a sub html => prepare. Else : display |
|
| 4564 | + if ($this->_subPart) { |
|
| 4565 | + // TD for the puce |
|
| 4566 | + $tmpPos = $this->_tempPos; |
|
| 4567 | + $tmpLst1 = $this->parsingHtml->code[$tmpPos + 1]; |
|
| 4568 | + $tmpLst2 = $this->parsingHtml->code[$tmpPos + 2]; |
|
| 4569 | + $this->parsingHtml->code[$tmpPos + 1] = array(); |
|
| 4570 | + $this->parsingHtml->code[$tmpPos + 1]['name'] = (isset($paramPUCE['src'])) ? 'img' : 'write'; |
|
| 4571 | + $this->parsingHtml->code[$tmpPos + 1]['param'] = $paramPUCE; unset($this->parsingHtml->code[$tmpPos + 1]['param']['style']['width']); |
|
| 4572 | + $this->parsingHtml->code[$tmpPos + 1]['close'] = 0; |
|
| 4573 | + $this->parsingHtml->code[$tmpPos + 2] = array(); |
|
| 4574 | + $this->parsingHtml->code[$tmpPos + 2]['name'] = 'li'; |
|
| 4575 | + $this->parsingHtml->code[$tmpPos + 2]['param'] = $paramPUCE; |
|
| 4576 | + $this->parsingHtml->code[$tmpPos + 2]['close'] = 1; |
|
| 4577 | + $this->_tag_open_TD($paramPUCE, 'li_sub'); |
|
| 4578 | + $this->_tag_close_TD($param); |
|
| 4579 | + $this->_tempPos = $tmpPos; |
|
| 4580 | + $this->parsingHtml->code[$tmpPos + 1] = $tmpLst1; |
|
| 4581 | + $this->parsingHtml->code[$tmpPos + 2] = $tmpLst2; |
|
| 4582 | + } else { |
|
| 4583 | + // TD for the puce |
|
| 4584 | + $this->_tag_open_TD($paramPUCE, 'li_sub'); |
|
| 4585 | + unset($paramPUCE['style']['width']); |
|
| 4586 | + if (isset($paramPUCE['src'])) { |
|
| 4587 | + $this->_tag_open_IMG($paramPUCE); |
|
| 4588 | + } else { |
|
| 4589 | + $this->_tag_open_WRITE($paramPUCE); |
|
| 4590 | + } |
|
| 4591 | + $this->_tag_close_TD($paramPUCE); |
|
| 4592 | + } |
|
| 4593 | + $this->parsingCss->load(); |
|
| 4594 | + |
|
| 4595 | + |
|
| 4596 | + // TD for the content |
|
| 4597 | + $this->_tag_open_TD($param, 'li'); |
|
| 4598 | + |
|
| 4599 | + return true; |
|
| 4600 | + } |
|
| 4601 | + |
|
| 4602 | + /** |
|
| 4603 | + * tag : LI |
|
| 4604 | + * mode : CLOSE |
|
| 4605 | + * |
|
| 4606 | + * @param array $param |
|
| 4607 | + * @return boolean |
|
| 4608 | + */ |
|
| 4609 | + protected function _tag_close_LI($param) |
|
| 4610 | + { |
|
| 4611 | + if ($this->_isForOneLine) { |
|
| 4612 | + return false; |
|
| 4613 | + } |
|
| 4614 | + |
|
| 4615 | + $this->_tag_close_TD($param); |
|
| 4616 | + |
|
| 4617 | + $this->_tag_close_TR($param); |
|
| 4618 | + |
|
| 4619 | + return true; |
|
| 4620 | + } |
|
| 4621 | + |
|
| 4622 | + /** |
|
| 4623 | + * tag : TBODY |
|
| 4624 | + * mode : OPEN |
|
| 4625 | + * |
|
| 4626 | + * @param array $param |
|
| 4627 | + * @return boolean |
|
| 4628 | + */ |
|
| 4629 | + protected function _tag_open_TBODY($param) |
|
| 4630 | + { |
|
| 4631 | + if ($this->_isForOneLine) { |
|
| 4632 | + return false; |
|
| 4633 | + } |
|
| 4634 | + |
|
| 4635 | + $this->parsingCss->save(); |
|
| 4636 | + $this->parsingCss->analyse('tbody', $param); |
|
| 4637 | + $this->parsingCss->setPosition(); |
|
| 4638 | + $this->parsingCss->fontSet(); |
|
| 4639 | + |
|
| 4640 | + return true; |
|
| 4641 | + } |
|
| 4642 | + |
|
| 4643 | + /** |
|
| 4644 | + * tag : TBODY |
|
| 4645 | + * mode : CLOSE |
|
| 4646 | + * |
|
| 4647 | + * @param array $param |
|
| 4648 | + * @return boolean |
|
| 4649 | + */ |
|
| 4650 | + protected function _tag_close_TBODY($param) |
|
| 4651 | + { |
|
| 4652 | + if ($this->_isForOneLine) { |
|
| 4653 | + return false; |
|
| 4654 | + } |
|
| 4655 | + |
|
| 4656 | + $this->parsingCss->load(); |
|
| 4657 | + $this->parsingCss->fontSet(); |
|
| 4658 | + |
|
| 4659 | + return true; |
|
| 4660 | + } |
|
| 4661 | + |
|
| 4662 | + /** |
|
| 4663 | + * tag : THEAD |
|
| 4664 | + * mode : OPEN |
|
| 4665 | + * |
|
| 4666 | + * @param array $param |
|
| 4667 | + * @return boolean |
|
| 4668 | + */ |
|
| 4669 | + protected function _tag_open_THEAD($param) |
|
| 4670 | + { |
|
| 4671 | + if ($this->_isForOneLine) { |
|
| 4672 | + return false; |
|
| 4673 | + } |
|
| 4674 | + |
|
| 4675 | + $this->parsingCss->save(); |
|
| 4676 | + $this->parsingCss->analyse('thead', $param); |
|
| 4677 | + $this->parsingCss->setPosition(); |
|
| 4678 | + $this->parsingCss->fontSet(); |
|
| 4679 | + |
|
| 4680 | + // if we are in a sub part, save the number of the first TR in the thead |
|
| 4681 | + if ($this->_subPart) { |
|
| 4682 | + HTML2PDF::$_tables[$param['num']]['thead']['tr'][0] = HTML2PDF::$_tables[$param['num']]['tr_curr']; |
|
| 4683 | + HTML2PDF::$_tables[$param['num']]['thead']['code'] = array(); |
|
| 4684 | + for ($pos = $this->_tempPos; $pos < count($this->parsingHtml->code); $pos++) { |
|
| 4685 | + $action = $this->parsingHtml->code[$pos]; |
|
| 4686 | + if (strtolower($action['name']) == 'thead') $action['name'] = 'thead_sub'; |
|
| 4687 | + HTML2PDF::$_tables[$param['num']]['thead']['code'][] = $action; |
|
| 4688 | + if (strtolower($action['name']) == 'thead_sub' && $action['close']) break; |
|
| 4689 | + } |
|
| 4690 | + } else { |
|
| 4691 | + $level = $this->parsingHtml->getLevel($this->_parsePos); |
|
| 4692 | + $this->_parsePos += count($level); |
|
| 4693 | + HTML2PDF::$_tables[$param['num']]['tr_curr'] += count(HTML2PDF::$_tables[$param['num']]['thead']['tr']); |
|
| 4694 | + } |
|
| 4695 | + |
|
| 4696 | + return true; |
|
| 4697 | + } |
|
| 4698 | + |
|
| 4699 | + /** |
|
| 4700 | + * tag : THEAD |
|
| 4701 | + * mode : CLOSE |
|
| 4702 | + * |
|
| 4703 | + * @param array $param |
|
| 4704 | + * @return boolean |
|
| 4705 | + */ |
|
| 4706 | + protected function _tag_close_THEAD($param) |
|
| 4707 | + { |
|
| 4708 | + if ($this->_isForOneLine) { |
|
| 4709 | + return false; |
|
| 4710 | + } |
|
| 4711 | + |
|
| 4712 | + $this->parsingCss->load(); |
|
| 4713 | + $this->parsingCss->fontSet(); |
|
| 4714 | + |
|
| 4715 | + // if we are in a sub HTM, construct the list of the TR in the thead |
|
| 4716 | + if ($this->_subPart) { |
|
| 4717 | + $min = HTML2PDF::$_tables[$param['num']]['thead']['tr'][0]; |
|
| 4718 | + $max = HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1; |
|
| 4719 | + HTML2PDF::$_tables[$param['num']]['thead']['tr'] = range($min, $max); |
|
| 4720 | + } |
|
| 4721 | + |
|
| 4722 | + return true; |
|
| 4723 | + } |
|
| 4724 | + |
|
| 4725 | + /** |
|
| 4726 | + * tag : TFOOT |
|
| 4727 | + * mode : OPEN |
|
| 4728 | + * |
|
| 4729 | + * @param array $param |
|
| 4730 | + * @return boolean |
|
| 4731 | + */ |
|
| 4732 | + protected function _tag_open_TFOOT($param) |
|
| 4733 | + { |
|
| 4734 | + if ($this->_isForOneLine) { |
|
| 4735 | + return false; |
|
| 4736 | + } |
|
| 4737 | + |
|
| 4738 | + $this->parsingCss->save(); |
|
| 4739 | + $this->parsingCss->analyse('tfoot', $param); |
|
| 4740 | + $this->parsingCss->setPosition(); |
|
| 4741 | + $this->parsingCss->fontSet(); |
|
| 4742 | + |
|
| 4743 | + // if we are in a sub part, save the number of the first TR in the tfoot |
|
| 4744 | + if ($this->_subPart) { |
|
| 4745 | + HTML2PDF::$_tables[$param['num']]['tfoot']['tr'][0] = HTML2PDF::$_tables[$param['num']]['tr_curr']; |
|
| 4746 | + HTML2PDF::$_tables[$param['num']]['tfoot']['code'] = array(); |
|
| 4747 | + for ($pos = $this->_tempPos; $pos < count($this->parsingHtml->code); $pos++) { |
|
| 4748 | + $action = $this->parsingHtml->code[$pos]; |
|
| 4749 | + if (strtolower($action['name']) == 'tfoot') $action['name'] = 'tfoot_sub'; |
|
| 4750 | + HTML2PDF::$_tables[$param['num']]['tfoot']['code'][] = $action; |
|
| 4751 | + if (strtolower($action['name']) == 'tfoot_sub' && $action['close']) break; |
|
| 4752 | + } |
|
| 4753 | + } else { |
|
| 4754 | + $level = $this->parsingHtml->getLevel($this->_parsePos); |
|
| 4755 | + $this->_parsePos += count($level); |
|
| 4756 | + HTML2PDF::$_tables[$param['num']]['tr_curr'] += count(HTML2PDF::$_tables[$param['num']]['tfoot']['tr']); |
|
| 4757 | + } |
|
| 4758 | + |
|
| 4759 | + return true; |
|
| 4760 | + } |
|
| 4761 | + |
|
| 4762 | + /** |
|
| 4763 | + * tag : TFOOT |
|
| 4764 | + * mode : CLOSE |
|
| 4765 | + * |
|
| 4766 | + * @param array $param |
|
| 4767 | + * @return boolean |
|
| 4768 | + */ |
|
| 4769 | + protected function _tag_close_TFOOT($param) |
|
| 4770 | + { |
|
| 4771 | + if ($this->_isForOneLine) { |
|
| 4772 | + return false; |
|
| 4773 | + } |
|
| 4774 | + |
|
| 4775 | + $this->parsingCss->load(); |
|
| 4776 | + $this->parsingCss->fontSet(); |
|
| 4777 | + |
|
| 4778 | + // if we are in a sub HTM, construct the list of the TR in the tfoot |
|
| 4779 | + if ($this->_subPart) { |
|
| 4780 | + $min = HTML2PDF::$_tables[$param['num']]['tfoot']['tr'][0]; |
|
| 4781 | + $max = HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1; |
|
| 4782 | + HTML2PDF::$_tables[$param['num']]['tfoot']['tr'] = range($min, $max); |
|
| 4783 | + } |
|
| 4784 | + |
|
| 4785 | + return true; |
|
| 4786 | + } |
|
| 4787 | + |
|
| 4788 | + /** |
|
| 4789 | + * It is not a real TAG, does not use it ! |
|
| 4790 | + * |
|
| 4791 | + * @param array $param |
|
| 4792 | + * @return boolean |
|
| 4793 | + */ |
|
| 4794 | + protected function _tag_open_THEAD_SUB($param) |
|
| 4795 | + { |
|
| 4796 | + if ($this->_isForOneLine) { |
|
| 4797 | + return false; |
|
| 4798 | + } |
|
| 4799 | + |
|
| 4800 | + $this->parsingCss->save(); |
|
| 4801 | + $this->parsingCss->analyse('thead', $param); |
|
| 4802 | + $this->parsingCss->setPosition(); |
|
| 4803 | + $this->parsingCss->fontSet(); |
|
| 4804 | + |
|
| 4805 | + return true; |
|
| 4806 | + } |
|
| 4807 | + |
|
| 4808 | + /** |
|
| 4809 | + * It is not a real TAG, does not use it ! |
|
| 4810 | + * |
|
| 4811 | + * @param array $param |
|
| 4812 | + * @return boolean |
|
| 4813 | + */ |
|
| 4814 | + protected function _tag_close_THEAD_SUB($param) |
|
| 4815 | + { |
|
| 4816 | + if ($this->_isForOneLine) { |
|
| 4817 | + return false; |
|
| 4818 | + } |
|
| 4819 | + |
|
| 4820 | + $this->parsingCss->load(); |
|
| 4821 | + $this->parsingCss->fontSet(); |
|
| 4822 | + |
|
| 4823 | + return true; |
|
| 4824 | + } |
|
| 4825 | + |
|
| 4826 | + /** |
|
| 4827 | + * It is not a real TAG, does not use it ! |
|
| 4828 | + * |
|
| 4829 | + * @param array $param |
|
| 4830 | + * @return boolean |
|
| 4831 | + */ |
|
| 4832 | + protected function _tag_open_TFOOT_SUB($param) |
|
| 4833 | + { |
|
| 4834 | + if ($this->_isForOneLine) { |
|
| 4835 | + return false; |
|
| 4836 | + } |
|
| 4837 | + |
|
| 4838 | + $this->parsingCss->save(); |
|
| 4839 | + $this->parsingCss->analyse('tfoot', $param); |
|
| 4840 | + $this->parsingCss->setPosition(); |
|
| 4841 | + $this->parsingCss->fontSet(); |
|
| 4842 | + |
|
| 4843 | + return true; |
|
| 4844 | + } |
|
| 4845 | + |
|
| 4846 | + /** |
|
| 4847 | + * It is not a real TAG, does not use it ! |
|
| 4848 | + * |
|
| 4849 | + * @param array $param |
|
| 4850 | + * @return boolean |
|
| 4851 | + */ |
|
| 4852 | + protected function _tag_close_TFOOT_SUB($param) |
|
| 4853 | + { |
|
| 4854 | + if ($this->_isForOneLine) { |
|
| 4855 | + return false; |
|
| 4856 | + } |
|
| 4857 | + |
|
| 4858 | + $this->parsingCss->load(); |
|
| 4859 | + $this->parsingCss->fontSet(); |
|
| 4860 | + |
|
| 4861 | + return true; |
|
| 4862 | + } |
|
| 4863 | + |
|
| 4864 | + /** |
|
| 4865 | + * tag : FORM |
|
| 4866 | + * mode : OPEN |
|
| 4867 | + * |
|
| 4868 | + * @param array $param |
|
| 4869 | + * @return boolean |
|
| 4870 | + */ |
|
| 4871 | + protected function _tag_open_FORM($param) |
|
| 4872 | + { |
|
| 4873 | + $this->parsingCss->save(); |
|
| 4874 | + $this->parsingCss->analyse('form', $param); |
|
| 4875 | + $this->parsingCss->setPosition(); |
|
| 4876 | + $this->parsingCss->fontSet(); |
|
| 4877 | + |
|
| 4878 | + $this->pdf->setFormDefaultProp( |
|
| 4879 | + array( |
|
| 4880 | + 'lineWidth'=>1, |
|
| 4881 | + 'borderStyle'=>'solid', |
|
| 4882 | + 'fillColor'=>array(220, 220, 255), |
|
| 4883 | + 'strokeColor'=>array(128, 128, 200) |
|
| 4884 | + ) |
|
| 4885 | + ); |
|
| 4886 | + |
|
| 4887 | + $this->_isInForm = isset($param['action']) ? $param['action'] : ''; |
|
| 4888 | + |
|
| 4889 | + return true; |
|
| 4890 | + } |
|
| 4891 | + |
|
| 4892 | + /** |
|
| 4893 | + * tag : FORM |
|
| 4894 | + * mode : CLOSE |
|
| 4895 | + * |
|
| 4896 | + * @param array $param |
|
| 4897 | + * @return boolean |
|
| 4898 | + */ |
|
| 4899 | + protected function _tag_close_FORM($param) |
|
| 4900 | + { |
|
| 4901 | + $this->_isInForm = false; |
|
| 4902 | + $this->parsingCss->load(); |
|
| 4903 | + $this->parsingCss->fontSet(); |
|
| 4904 | + |
|
| 4905 | + return true; |
|
| 4906 | + } |
|
| 4907 | + |
|
| 4908 | + /** |
|
| 4909 | + * tag : TABLE |
|
| 4910 | + * mode : OPEN |
|
| 4911 | + * |
|
| 4912 | + * @param array $param |
|
| 4913 | + * @return boolean |
|
| 4914 | + */ |
|
| 4915 | + protected function _tag_open_TABLE($param, $other = 'table') |
|
| 4916 | + { |
|
| 4917 | + if ($this->_maxH) { |
|
| 4918 | + if ($this->_isForOneLine) { |
|
| 4919 | + return false; |
|
| 4920 | + } |
|
| 4921 | + $this->_tag_open_BR(array()); |
|
| 4922 | + } |
|
| 4923 | + |
|
| 4924 | + if ($this->_isForOneLine) { |
|
| 4925 | + $this->_maxX = $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); |
|
| 4926 | + return false; |
|
| 4927 | + } |
|
| 4928 | + |
|
| 4929 | + $this->_maxH = 0; |
|
| 4930 | + |
|
| 4931 | + $alignObject = isset($param['align']) ? strtolower($param['align']) : 'left'; |
|
| 4932 | + if (isset($param['align'])) unset($param['align']); |
|
| 4933 | + if ( ! in_array($alignObject, array('left', 'center', 'right'))) $alignObject = 'left'; |
|
| 4934 | + |
|
| 4935 | + $this->parsingCss->save(); |
|
| 4936 | + $this->parsingCss->analyse($other, $param); |
|
| 4937 | + $this->parsingCss->setPosition(); |
|
| 4938 | + $this->parsingCss->fontSet(); |
|
| 4939 | + |
|
| 4940 | + if ($this->parsingCss->value['margin-auto']) $alignObject = 'center'; |
|
| 4941 | + |
|
| 4942 | + // collapse table ? |
|
| 4943 | + $collapse = false; |
|
| 4944 | + if ($other == 'table') { |
|
| 4945 | + $collapse = isset($this->parsingCss->value['border']['collapse']) ? $this->parsingCss->value['border']['collapse'] : false; |
|
| 4946 | + } |
|
| 4947 | + |
|
| 4948 | + // if collapse => no borders for the table, only for TD |
|
| 4949 | + if ($collapse) { |
|
| 4950 | + $param['style']['border'] = 'none'; |
|
| 4951 | + $param['cellspacing'] = 0; |
|
| 4952 | + $none = $this->parsingCss->readBorder('none'); |
|
| 4953 | + $this->parsingCss->value['border']['t'] = $none; |
|
| 4954 | + $this->parsingCss->value['border']['r'] = $none; |
|
| 4955 | + $this->parsingCss->value['border']['b'] = $none; |
|
| 4956 | + $this->parsingCss->value['border']['l'] = $none; |
|
| 4957 | + } |
|
| 4958 | + |
|
| 4959 | + // if we are in a SUB html => prepare the properties of the table |
|
| 4960 | + if ($this->_subPart) { |
|
| 4961 | + if ($this->_debugActif) { |
|
| 4962 | + $this->_DEBUG_add('Table n'.$param['num'], true); |
|
| 4963 | + } |
|
| 4964 | + HTML2PDF::$_tables[$param['num']] = array(); |
|
| 4965 | + HTML2PDF::$_tables[$param['num']]['border'] = isset($param['border']) ? $this->parsingCss->readBorder($param['border']) : null; |
|
| 4966 | + HTML2PDF::$_tables[$param['num']]['cellpadding'] = $this->parsingCss->ConvertToMM(isset($param['cellpadding']) ? $param['cellpadding'] : '1px'); |
|
| 4967 | + HTML2PDF::$_tables[$param['num']]['cellspacing'] = $this->parsingCss->ConvertToMM(isset($param['cellspacing']) ? $param['cellspacing'] : '2px'); |
|
| 4968 | + HTML2PDF::$_tables[$param['num']]['cases'] = array(); // properties of each TR/TD |
|
| 4969 | + HTML2PDF::$_tables[$param['num']]['corr'] = array(); // link between TR/TD and colspan/rowspan |
|
| 4970 | + HTML2PDF::$_tables[$param['num']]['corr_x'] = 0; // position in 'cases' |
|
| 4971 | + HTML2PDF::$_tables[$param['num']]['corr_y'] = 0; // position in 'cases' |
|
| 4972 | + HTML2PDF::$_tables[$param['num']]['td_curr'] = 0; // current column |
|
| 4973 | + HTML2PDF::$_tables[$param['num']]['tr_curr'] = 0; // current row |
|
| 4974 | + HTML2PDF::$_tables[$param['num']]['curr_x'] = $this->pdf->getX(); |
|
| 4975 | + HTML2PDF::$_tables[$param['num']]['curr_y'] = $this->pdf->getY(); |
|
| 4976 | + HTML2PDF::$_tables[$param['num']]['width'] = 0; // global width |
|
| 4977 | + HTML2PDF::$_tables[$param['num']]['height'] = 0; // global height |
|
| 4978 | + HTML2PDF::$_tables[$param['num']]['align'] = $alignObject; |
|
| 4979 | + HTML2PDF::$_tables[$param['num']]['marge'] = array(); |
|
| 4980 | + HTML2PDF::$_tables[$param['num']]['marge']['t'] = $this->parsingCss->value['padding']['t'] + $this->parsingCss->value['border']['t']['width'] + HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5; |
|
| 4981 | + HTML2PDF::$_tables[$param['num']]['marge']['r'] = $this->parsingCss->value['padding']['r'] + $this->parsingCss->value['border']['r']['width'] + HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5; |
|
| 4982 | + HTML2PDF::$_tables[$param['num']]['marge']['b'] = $this->parsingCss->value['padding']['b'] + $this->parsingCss->value['border']['b']['width'] + HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5; |
|
| 4983 | + HTML2PDF::$_tables[$param['num']]['marge']['l'] = $this->parsingCss->value['padding']['l'] + $this->parsingCss->value['border']['l']['width'] + HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5; |
|
| 4984 | + HTML2PDF::$_tables[$param['num']]['page'] = 0; // number of pages |
|
| 4985 | + HTML2PDF::$_tables[$param['num']]['new_page'] = true; // flag : new page for the current TR |
|
| 4986 | + HTML2PDF::$_tables[$param['num']]['style_value'] = null; // CSS style of the table |
|
| 4987 | + HTML2PDF::$_tables[$param['num']]['thead'] = array(); // properties on the thead |
|
| 4988 | + HTML2PDF::$_tables[$param['num']]['tfoot'] = array(); // properties on the tfoot |
|
| 4989 | + HTML2PDF::$_tables[$param['num']]['thead']['tr'] = array(); // list of the TRs in the thead |
|
| 4990 | + HTML2PDF::$_tables[$param['num']]['tfoot']['tr'] = array(); // list of the TRs in the tfoot |
|
| 4991 | + HTML2PDF::$_tables[$param['num']]['thead']['height'] = 0; // thead height |
|
| 4992 | + HTML2PDF::$_tables[$param['num']]['tfoot']['height'] = 0; // tfoot height |
|
| 4993 | + HTML2PDF::$_tables[$param['num']]['thead']['code'] = array(); // HTML content of the thead |
|
| 4994 | + HTML2PDF::$_tables[$param['num']]['tfoot']['code'] = array(); // HTML content of the tfoot |
|
| 4995 | + HTML2PDF::$_tables[$param['num']]['cols'] = array(); // properties of the COLs |
|
| 4996 | + |
|
| 4997 | + $this->_saveMargin($this->pdf->getlMargin(), $this->pdf->gettMargin(), $this->pdf->getrMargin()); |
|
| 4998 | + |
|
| 4999 | + $this->parsingCss->value['width'] -= HTML2PDF::$_tables[$param['num']]['marge']['l'] + HTML2PDF::$_tables[$param['num']]['marge']['r']; |
|
| 5000 | + } else { |
|
| 5001 | + // we start from the first page and the first page of the table |
|
| 5002 | + HTML2PDF::$_tables[$param['num']]['page'] = 0; |
|
| 5003 | + HTML2PDF::$_tables[$param['num']]['td_curr'] = 0; |
|
| 5004 | + HTML2PDF::$_tables[$param['num']]['tr_curr'] = 0; |
|
| 5005 | + HTML2PDF::$_tables[$param['num']]['td_x'] = HTML2PDF::$_tables[$param['num']]['marge']['l'] + HTML2PDF::$_tables[$param['num']]['curr_x']; |
|
| 5006 | + HTML2PDF::$_tables[$param['num']]['td_y'] = HTML2PDF::$_tables[$param['num']]['marge']['t'] + HTML2PDF::$_tables[$param['num']]['curr_y']; |
|
| 5007 | + |
|
| 5008 | + // draw the borders/background of the first page/part of the table |
|
| 5009 | + $this->_drawRectangle( |
|
| 5010 | + HTML2PDF::$_tables[$param['num']]['curr_x'], |
|
| 5011 | + HTML2PDF::$_tables[$param['num']]['curr_y'], |
|
| 5012 | + HTML2PDF::$_tables[$param['num']]['width'], |
|
| 5013 | + isset(HTML2PDF::$_tables[$param['num']]['height'][0]) ? HTML2PDF::$_tables[$param['num']]['height'][0] : null, |
|
| 5014 | + $this->parsingCss->value['border'], |
|
| 5015 | + $this->parsingCss->value['padding'], |
|
| 5016 | + 0, |
|
| 5017 | + $this->parsingCss->value['background'] |
|
| 5018 | + ); |
|
| 5019 | + |
|
| 5020 | + HTML2PDF::$_tables[$param['num']]['style_value'] = $this->parsingCss->value; |
|
| 5021 | + } |
|
| 5022 | + |
|
| 5023 | + return true; |
|
| 5024 | + } |
|
| 5025 | + |
|
| 5026 | + /** |
|
| 5027 | + * tag : TABLE |
|
| 5028 | + * mode : CLOSE |
|
| 5029 | + * |
|
| 5030 | + * @param array $param |
|
| 5031 | + * @return boolean |
|
| 5032 | + */ |
|
| 5033 | + protected function _tag_close_TABLE($param) |
|
| 5034 | + { |
|
| 5035 | + if ($this->_isForOneLine) { |
|
| 5036 | + return false; |
|
| 5037 | + } |
|
| 5038 | + |
|
| 5039 | + $this->_maxH = 0; |
|
| 5040 | + |
|
| 5041 | + // if we are in a sub HTML |
|
| 5042 | + if ($this->_subPart) { |
|
| 5043 | + // calculate the size of each case |
|
| 5044 | + $this->_calculateTableCellSize(HTML2PDF::$_tables[$param['num']]['cases'], HTML2PDF::$_tables[$param['num']]['corr']); |
|
| 5045 | + |
|
| 5046 | + // calculate the height of the thead and the tfoot |
|
| 5047 | + $lst = array('thead', 'tfoot'); |
|
| 5048 | + foreach ($lst as $mode) { |
|
| 5049 | + HTML2PDF::$_tables[$param['num']][$mode]['height'] = 0; |
|
| 5050 | + foreach (HTML2PDF::$_tables[$param['num']][$mode]['tr'] as $tr) { |
|
| 5051 | + // hauteur de la ligne tr |
|
| 5052 | + $h = 0; |
|
| 5053 | + for ($i = 0; $i < count(HTML2PDF::$_tables[$param['num']]['cases'][$tr]); $i++) |
|
| 5054 | + if (HTML2PDF::$_tables[$param['num']]['cases'][$tr][$i]['rowspan'] == 1) |
|
| 5055 | + $h = max($h, HTML2PDF::$_tables[$param['num']]['cases'][$tr][$i]['h']); |
|
| 5056 | + HTML2PDF::$_tables[$param['num']][$mode]['height'] += $h; |
|
| 5057 | + } |
|
| 5058 | + } |
|
| 5059 | + |
|
| 5060 | + // calculate the width of the table |
|
| 5061 | + HTML2PDF::$_tables[$param['num']]['width'] = HTML2PDF::$_tables[$param['num']]['marge']['l'] + HTML2PDF::$_tables[$param['num']]['marge']['r']; |
|
| 5062 | + if (isset(HTML2PDF::$_tables[$param['num']]['cases'][0])) { |
|
| 5063 | + foreach (HTML2PDF::$_tables[$param['num']]['cases'][0] as $case) { |
|
| 5064 | + HTML2PDF::$_tables[$param['num']]['width'] += $case['w']; |
|
| 5065 | + } |
|
| 5066 | + } |
|
| 5067 | + |
|
| 5068 | + // X position of the table |
|
| 5069 | + $old = $this->parsingCss->getOldValues(); |
|
| 5070 | + $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); |
|
| 5071 | + $x = HTML2PDF::$_tables[$param['num']]['curr_x']; |
|
| 5072 | + $w = HTML2PDF::$_tables[$param['num']]['width']; |
|
| 5073 | + if ($parentWidth > $w) { |
|
| 5074 | + if (HTML2PDF::$_tables[$param['num']]['align'] == 'center') |
|
| 5075 | + $x = $x + ($parentWidth - $w) * 0.5; |
|
| 5076 | + else if (HTML2PDF::$_tables[$param['num']]['align'] == 'right') |
|
| 5077 | + $x = $x + $parentWidth - $w; |
|
| 5078 | + |
|
| 5079 | + HTML2PDF::$_tables[$param['num']]['curr_x'] = $x; |
|
| 5080 | + } |
|
| 5081 | + |
|
| 5082 | + // calculate the height of the table |
|
| 5083 | + HTML2PDF::$_tables[$param['num']]['height'] = array(); |
|
| 5084 | + |
|
| 5085 | + // minimum of the height because of margins, and of the thead and tfoot height |
|
| 5086 | + $h0 = HTML2PDF::$_tables[$param['num']]['marge']['t'] + HTML2PDF::$_tables[$param['num']]['marge']['b']; |
|
| 5087 | + $h0 += HTML2PDF::$_tables[$param['num']]['thead']['height'] + HTML2PDF::$_tables[$param['num']]['tfoot']['height']; |
|
| 5088 | + |
|
| 5089 | + // max height of the page |
|
| 5090 | + $max = $this->pdf->getH() - $this->pdf->getbMargin(); |
|
| 5091 | + |
|
| 5092 | + // current position on the page |
|
| 5093 | + $y = HTML2PDF::$_tables[$param['num']]['curr_y']; |
|
| 5094 | + $height = $h0; |
|
| 5095 | + |
|
| 5096 | + // we get the height of each line |
|
| 5097 | + for ($k = 0; $k < count(HTML2PDF::$_tables[$param['num']]['cases']); $k++) { |
|
| 5098 | + |
|
| 5099 | + // if it is a TR of the thead or of the tfoot => skip |
|
| 5100 | + if (in_array($k, HTML2PDF::$_tables[$param['num']]['thead']['tr'])) { |
|
| 5101 | + continue; |
|
| 5102 | + } |
|
| 5103 | + if (in_array($k, HTML2PDF::$_tables[$param['num']]['tfoot']['tr'])) { |
|
| 5104 | + continue; |
|
| 5105 | + } |
|
| 5106 | + |
|
| 5107 | + // height of the line |
|
| 5108 | + $th = 0; |
|
| 5109 | + $h = 0; |
|
| 5110 | + for ($i = 0; $i < count(HTML2PDF::$_tables[$param['num']]['cases'][$k]); $i++) { |
|
| 5111 | + $h = max($h, HTML2PDF::$_tables[$param['num']]['cases'][$k][$i]['h']); |
|
| 5112 | + |
|
| 5113 | + if (HTML2PDF::$_tables[$param['num']]['cases'][$k][$i]['rowspan'] == 1) |
|
| 5114 | + $th = max($th, HTML2PDF::$_tables[$param['num']]['cases'][$k][$i]['h']); |
|
| 5115 | + } |
|
| 5116 | + |
|
| 5117 | + // if the row does not fit on the page => new page |
|
| 5118 | + if ($y + $h + $height > $max) { |
|
| 5119 | + if ($height == $h0) $height = null; |
|
| 5120 | + HTML2PDF::$_tables[$param['num']]['height'][] = $height; |
|
| 5121 | + $height = $h0; |
|
| 5122 | + $y = $this->_margeTop; |
|
| 5123 | + } |
|
| 5124 | + $height += $th; |
|
| 5125 | + } |
|
| 5126 | + |
|
| 5127 | + // if ther is a height at the end, add it |
|
| 5128 | + if ($height != $h0 || $k == 0) HTML2PDF::$_tables[$param['num']]['height'][] = $height; |
|
| 5129 | + } else { |
|
| 5130 | + // if we have tfoor, draw it |
|
| 5131 | + if (count(HTML2PDF::$_tables[$param['num']]['tfoot']['code'])) { |
|
| 5132 | + $tmpTR = HTML2PDF::$_tables[$param['num']]['tr_curr']; |
|
| 5133 | + $tmpTD = HTML2PDF::$_tables[$param['num']]['td_curr']; |
|
| 5134 | + $oldParsePos = $this->_parsePos; |
|
| 5135 | + $oldParseCode = $this->parsingHtml->code; |
|
| 5136 | + |
|
| 5137 | + HTML2PDF::$_tables[$param['num']]['tr_curr'] = HTML2PDF::$_tables[$param['num']]['tfoot']['tr'][0]; |
|
| 5138 | + HTML2PDF::$_tables[$param['num']]['td_curr'] = 0; |
|
| 5139 | + $this->_parsePos = 0; |
|
| 5140 | + $this->parsingHtml->code = HTML2PDF::$_tables[$param['num']]['tfoot']['code']; |
|
| 5141 | + $this->_isInTfoot = true; |
|
| 5142 | + $this->_makeHTMLcode(); |
|
| 5143 | + $this->_isInTfoot = false; |
|
| 5144 | + |
|
| 5145 | + $this->_parsePos = $oldParsePos; |
|
| 5146 | + $this->parsingHtml->code = $oldParseCode; |
|
| 5147 | + HTML2PDF::$_tables[$param['num']]['tr_curr'] = $tmpTR; |
|
| 5148 | + HTML2PDF::$_tables[$param['num']]['td_curr'] = $tmpTD; |
|
| 5149 | + } |
|
| 5150 | + |
|
| 5151 | + // get the positions of the end of the table |
|
| 5152 | + $x = HTML2PDF::$_tables[$param['num']]['curr_x'] + HTML2PDF::$_tables[$param['num']]['width']; |
|
| 5153 | + if (count(HTML2PDF::$_tables[$param['num']]['height']) > 1) |
|
| 5154 | + $y = $this->_margeTop + HTML2PDF::$_tables[$param['num']]['height'][count(HTML2PDF::$_tables[$param['num']]['height']) - 1]; |
|
| 5155 | + else if (count(HTML2PDF::$_tables[$param['num']]['height']) == 1) |
|
| 5156 | + $y = HTML2PDF::$_tables[$param['num']]['curr_y'] + HTML2PDF::$_tables[$param['num']]['height'][count(HTML2PDF::$_tables[$param['num']]['height']) - 1]; |
|
| 5157 | + else |
|
| 5158 | + $y = HTML2PDF::$_tables[$param['num']]['curr_y']; |
|
| 5159 | + |
|
| 5160 | + $this->_maxX = max($this->_maxX, $x); |
|
| 5161 | + $this->_maxY = max($this->_maxY, $y); |
|
| 5162 | + |
|
| 5163 | + $this->pdf->setXY($this->pdf->getlMargin(), $y); |
|
| 5164 | + |
|
| 5165 | + $this->_loadMargin(); |
|
| 5166 | + |
|
| 5167 | + if ($this->_debugActif) { |
|
| 5168 | + $this->_DEBUG_add('Table '.$param['num'], false); |
|
| 5169 | + } |
|
| 5170 | + } |
|
| 5171 | + |
|
| 5172 | + $this->parsingCss->load(); |
|
| 5173 | + $this->parsingCss->fontSet(); |
|
| 5174 | + |
|
| 5175 | + |
|
| 5176 | + return true; |
|
| 5177 | + } |
|
| 5178 | + |
|
| 5179 | + /** |
|
| 5180 | + * tag : COL |
|
| 5181 | + * mode : OPEN |
|
| 5182 | + * |
|
| 5183 | + * @param array $param |
|
| 5184 | + * @return boolean|null |
|
| 5185 | + */ |
|
| 5186 | + protected function _tag_open_COL($param) |
|
| 5187 | + { |
|
| 5188 | + $span = isset($param['span']) ? $param['span'] : 1; |
|
| 5189 | + for ($k = 0; $k < $span; $k++) |
|
| 5190 | + HTML2PDF::$_tables[$param['num']]['cols'][] = $param; |
|
| 5191 | + } |
|
| 5192 | + |
|
| 5193 | + /** |
|
| 5194 | + * tag : COL |
|
| 5195 | + * mode : CLOSE |
|
| 5196 | + * |
|
| 5197 | + * @param array $param |
|
| 5198 | + * @return boolean |
|
| 5199 | + */ |
|
| 5200 | + protected function _tag_close_COL($param) |
|
| 5201 | + { |
|
| 5202 | + // there is nothing to do here |
|
| 5203 | + |
|
| 5204 | + return true; |
|
| 5205 | + } |
|
| 5206 | + |
|
| 5207 | + /** |
|
| 5208 | + * tag : TR |
|
| 5209 | + * mode : OPEN |
|
| 5210 | + * |
|
| 5211 | + * @param array $param |
|
| 5212 | + * @return boolean |
|
| 5213 | + */ |
|
| 5214 | + protected function _tag_open_TR($param, $other = 'tr') |
|
| 5215 | + { |
|
| 5216 | + if ($this->_isForOneLine) { |
|
| 5217 | + return false; |
|
| 5218 | + } |
|
| 5219 | + |
|
| 5220 | + $this->_maxH = 0; |
|
| 5221 | + |
|
| 5222 | + $this->parsingCss->save(); |
|
| 5223 | + $this->parsingCss->analyse($other, $param); |
|
| 5224 | + $this->parsingCss->setPosition(); |
|
| 5225 | + $this->parsingCss->fontSet(); |
|
| 5226 | + |
|
| 5227 | + // position in the table |
|
| 5228 | + HTML2PDF::$_tables[$param['num']]['tr_curr']++; |
|
| 5229 | + HTML2PDF::$_tables[$param['num']]['td_curr'] = 0; |
|
| 5230 | + |
|
| 5231 | + // if we are not in a sub html |
|
| 5232 | + if ( ! $this->_subPart) { |
|
| 5233 | + |
|
| 5234 | + // Y after the row |
|
| 5235 | + $ty = null; |
|
| 5236 | + for ($ii = 0; $ii < count(HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1]); $ii++) { |
|
| 5237 | + $ty = max($ty, HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][$ii]['h']); |
|
| 5238 | + } |
|
| 5239 | + |
|
| 5240 | + // height of the tfoot |
|
| 5241 | + $hfoot = HTML2PDF::$_tables[$param['num']]['tfoot']['height']; |
|
| 5242 | + |
|
| 5243 | + // if the line does not fit on the page => new page |
|
| 5244 | + if ( ! $this->_isInTfoot && HTML2PDF::$_tables[$param['num']]['td_y'] + HTML2PDF::$_tables[$param['num']]['marge']['b'] + $ty + $hfoot > $this->pdf->getH() - $this->pdf->getbMargin()) { |
|
| 5245 | + |
|
| 5246 | + // fi ther is a tfoot => draw it |
|
| 5247 | + if (count(HTML2PDF::$_tables[$param['num']]['tfoot']['code'])) { |
|
| 5248 | + $tmpTR = HTML2PDF::$_tables[$param['num']]['tr_curr']; |
|
| 5249 | + $tmpTD = HTML2PDF::$_tables[$param['num']]['td_curr']; |
|
| 5250 | + $oldParsePos = $this->_parsePos; |
|
| 5251 | + $oldParseCode = $this->parsingHtml->code; |
|
| 5252 | + |
|
| 5253 | + HTML2PDF::$_tables[$param['num']]['tr_curr'] = HTML2PDF::$_tables[$param['num']]['tfoot']['tr'][0]; |
|
| 5254 | + HTML2PDF::$_tables[$param['num']]['td_curr'] = 0; |
|
| 5255 | + $this->_parsePos = 0; |
|
| 5256 | + $this->parsingHtml->code = HTML2PDF::$_tables[$param['num']]['tfoot']['code']; |
|
| 5257 | + $this->_isInTfoot = true; |
|
| 5258 | + $this->_makeHTMLcode(); |
|
| 5259 | + $this->_isInTfoot = false; |
|
| 5260 | + |
|
| 5261 | + $this->_parsePos = $oldParsePos; |
|
| 5262 | + $this->parsingHtml->code = $oldParseCode; |
|
| 5263 | + HTML2PDF::$_tables[$param['num']]['tr_curr'] = $tmpTR; |
|
| 5264 | + HTML2PDF::$_tables[$param['num']]['td_curr'] = $tmpTD; |
|
| 5265 | + } |
|
| 5266 | + |
|
| 5267 | + // new page |
|
| 5268 | + HTML2PDF::$_tables[$param['num']]['new_page'] = true; |
|
| 5269 | + $this->_setNewPage(); |
|
| 5270 | + |
|
| 5271 | + // new position |
|
| 5272 | + HTML2PDF::$_tables[$param['num']]['page']++; |
|
| 5273 | + HTML2PDF::$_tables[$param['num']]['curr_y'] = $this->pdf->getY(); |
|
| 5274 | + HTML2PDF::$_tables[$param['num']]['td_y'] = HTML2PDF::$_tables[$param['num']]['curr_y'] + HTML2PDF::$_tables[$param['num']]['marge']['t']; |
|
| 5275 | + |
|
| 5276 | + // if we have the height of the tbale on the page => draw borders and background |
|
| 5277 | + if (isset(HTML2PDF::$_tables[$param['num']]['height'][HTML2PDF::$_tables[$param['num']]['page']])) { |
|
| 5278 | + $old = $this->parsingCss->value; |
|
| 5279 | + $this->parsingCss->value = HTML2PDF::$_tables[$param['num']]['style_value']; |
|
| 5280 | + |
|
| 5281 | + $this->_drawRectangle( |
|
| 5282 | + HTML2PDF::$_tables[$param['num']]['curr_x'], |
|
| 5283 | + HTML2PDF::$_tables[$param['num']]['curr_y'], |
|
| 5284 | + HTML2PDF::$_tables[$param['num']]['width'], |
|
| 5285 | + HTML2PDF::$_tables[$param['num']]['height'][HTML2PDF::$_tables[$param['num']]['page']], |
|
| 5286 | + $this->parsingCss->value['border'], |
|
| 5287 | + $this->parsingCss->value['padding'], |
|
| 5288 | + HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5, |
|
| 5289 | + $this->parsingCss->value['background'] |
|
| 5290 | + ); |
|
| 5291 | + |
|
| 5292 | + $this->parsingCss->value = $old; |
|
| 5293 | + } |
|
| 5294 | + } |
|
| 5295 | + |
|
| 5296 | + // if we are in a new page, and if we have a thead => draw it |
|
| 5297 | + if (HTML2PDF::$_tables[$param['num']]['new_page'] && count(HTML2PDF::$_tables[$param['num']]['thead']['code'])) { |
|
| 5298 | + HTML2PDF::$_tables[$param['num']]['new_page'] = false; |
|
| 5299 | + $tmpTR = HTML2PDF::$_tables[$param['num']]['tr_curr']; |
|
| 5300 | + $tmpTD = HTML2PDF::$_tables[$param['num']]['td_curr']; |
|
| 5301 | + $oldParsePos = $this->_parsePos; |
|
| 5302 | + $oldParseCode = $this->parsingHtml->code; |
|
| 5303 | + |
|
| 5304 | + HTML2PDF::$_tables[$param['num']]['tr_curr'] = HTML2PDF::$_tables[$param['num']]['thead']['tr'][0]; |
|
| 5305 | + HTML2PDF::$_tables[$param['num']]['td_curr'] = 0; |
|
| 5306 | + $this->_parsePos = 0; |
|
| 5307 | + $this->parsingHtml->code = HTML2PDF::$_tables[$param['num']]['thead']['code']; |
|
| 5308 | + $this->_isInThead = true; |
|
| 5309 | + $this->_makeHTMLcode(); |
|
| 5310 | + $this->_isInThead = false; |
|
| 5311 | + |
|
| 5312 | + $this->_parsePos = $oldParsePos; |
|
| 5313 | + $this->parsingHtml->code = $oldParseCode; |
|
| 5314 | + HTML2PDF::$_tables[$param['num']]['tr_curr'] = $tmpTR; |
|
| 5315 | + HTML2PDF::$_tables[$param['num']]['td_curr'] = $tmpTD; |
|
| 5316 | + HTML2PDF::$_tables[$param['num']]['new_page'] = true; |
|
| 5317 | + } |
|
| 5318 | + // else (in a sub HTML) |
|
| 5319 | + } else { |
|
| 5320 | + // prepare it |
|
| 5321 | + HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1] = array(); |
|
| 5322 | + if ( ! isset(HTML2PDF::$_tables[$param['num']]['corr'][HTML2PDF::$_tables[$param['num']]['corr_y']])) |
|
| 5323 | + HTML2PDF::$_tables[$param['num']]['corr'][HTML2PDF::$_tables[$param['num']]['corr_y']] = array(); |
|
| 5324 | + |
|
| 5325 | + HTML2PDF::$_tables[$param['num']]['corr_x'] = 0; |
|
| 5326 | + while (isset(HTML2PDF::$_tables[$param['num']]['corr'][HTML2PDF::$_tables[$param['num']]['corr_y']][HTML2PDF::$_tables[$param['num']]['corr_x']])) |
|
| 5327 | + HTML2PDF::$_tables[$param['num']]['corr_x']++; |
|
| 5328 | + } |
|
| 5329 | + |
|
| 5330 | + return true; |
|
| 5331 | + } |
|
| 5332 | + |
|
| 5333 | + /** |
|
| 5334 | + * tag : TR |
|
| 5335 | + * mode : CLOSE |
|
| 5336 | + * |
|
| 5337 | + * @param array $param |
|
| 5338 | + * @return boolean |
|
| 5339 | + */ |
|
| 5340 | + protected function _tag_close_TR($param) |
|
| 5341 | + { |
|
| 5342 | + if ($this->_isForOneLine) { |
|
| 5343 | + return false; |
|
| 5344 | + } |
|
| 5345 | + |
|
| 5346 | + $this->_maxH = 0; |
|
| 5347 | + |
|
| 5348 | + $this->parsingCss->load(); |
|
| 5349 | + $this->parsingCss->fontSet(); |
|
| 5350 | + |
|
| 5351 | + // if we are not in a sub HTML |
|
| 5352 | + if ( ! $this->_subPart) { |
|
| 5353 | + |
|
| 5354 | + // Y of the current line |
|
| 5355 | + $ty = null; |
|
| 5356 | + for ($ii = 0; $ii < count(HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1]); $ii++) { |
|
| 5357 | + if (HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][$ii]['rowspan'] == 1) { |
|
| 5358 | + $ty = HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][$ii]['h']; |
|
| 5359 | + } |
|
| 5360 | + } |
|
| 5361 | + |
|
| 5362 | + // new position |
|
| 5363 | + HTML2PDF::$_tables[$param['num']]['td_x'] = HTML2PDF::$_tables[$param['num']]['curr_x'] + HTML2PDF::$_tables[$param['num']]['marge']['l']; |
|
| 5364 | + HTML2PDF::$_tables[$param['num']]['td_y'] += $ty; |
|
| 5365 | + HTML2PDF::$_tables[$param['num']]['new_page'] = false; |
|
| 5366 | + } else { |
|
| 5367 | + HTML2PDF::$_tables[$param['num']]['corr_y']++; |
|
| 5368 | + } |
|
| 5369 | + |
|
| 5370 | + return true; |
|
| 5371 | + } |
|
| 5372 | + |
|
| 5373 | + /** |
|
| 5374 | + * tag : TD |
|
| 5375 | + * mode : OPEN |
|
| 5376 | + * |
|
| 5377 | + * @param array $param |
|
| 5378 | + * @return boolean |
|
| 5379 | + */ |
|
| 5380 | + protected function _tag_open_TD($param, $other = 'td') |
|
| 5381 | + { |
|
| 5382 | + if ($this->_isForOneLine) { |
|
| 5383 | + return false; |
|
| 5384 | + } |
|
| 5385 | + |
|
| 5386 | + $this->_maxH = 0; |
|
| 5387 | + |
|
| 5388 | + $param['cellpadding'] = HTML2PDF::$_tables[$param['num']]['cellpadding'].'mm'; |
|
| 5389 | + $param['cellspacing'] = HTML2PDF::$_tables[$param['num']]['cellspacing'].'mm'; |
|
| 5390 | + |
|
| 5391 | + // specific style for LI |
|
| 5392 | + if ($other == 'li') { |
|
| 5393 | + $specialLi = true; |
|
| 5394 | + } else { |
|
| 5395 | + $specialLi = false; |
|
| 5396 | + if ($other == 'li_sub') { |
|
| 5397 | + $param['style']['border'] = 'none'; |
|
| 5398 | + $param['style']['background-color'] = 'transparent'; |
|
| 5399 | + $param['style']['background-image'] = 'none'; |
|
| 5400 | + $param['style']['background-position'] = ''; |
|
| 5401 | + $param['style']['background-repeat'] = ''; |
|
| 5402 | + $other = 'li'; |
|
| 5403 | + } |
|
| 5404 | + } |
|
| 5405 | + |
|
| 5406 | + // get the properties of the TD |
|
| 5407 | + $x = HTML2PDF::$_tables[$param['num']]['td_curr']; |
|
| 5408 | + $y = HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1; |
|
| 5409 | + $colspan = isset($param['colspan']) ? $param['colspan'] : 1; |
|
| 5410 | + $rowspan = isset($param['rowspan']) ? $param['rowspan'] : 1; |
|
| 5411 | + |
|
| 5412 | + // flag for collapse table |
|
| 5413 | + $collapse = false; |
|
| 5414 | + |
|
| 5415 | + // specific traitment for TD and TH |
|
| 5416 | + if (in_array($other, array('td', 'th'))) { |
|
| 5417 | + // id of the column |
|
| 5418 | + $numCol = isset(HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Xr']) ? HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Xr'] : HTML2PDF::$_tables[$param['num']]['corr_x']; |
|
| 5419 | + |
|
| 5420 | + // we get the properties of the COL tag, if exist |
|
| 5421 | + if (isset(HTML2PDF::$_tables[$param['num']]['cols'][$numCol])) { |
|
| 5422 | + |
|
| 5423 | + $colParam = HTML2PDF::$_tables[$param['num']]['cols'][$numCol]; |
|
| 5424 | + |
|
| 5425 | + // for colspans => we get all the neede widths |
|
| 5426 | + $colParam['style']['width'] = array(); |
|
| 5427 | + for ($k = 0; $k < $colspan; $k++) { |
|
| 5428 | + if (isset(HTML2PDF::$_tables[$param['num']]['cols'][$numCol + $k]['style']['width'])) { |
|
| 5429 | + $colParam['style']['width'][] = HTML2PDF::$_tables[$param['num']]['cols'][$numCol + $k]['style']['width']; |
|
| 5430 | + } |
|
| 5431 | + } |
|
| 5432 | + |
|
| 5433 | + // calculate the total width of the column |
|
| 5434 | + $total = ''; |
|
| 5435 | + $last = $this->parsingCss->getLastWidth(); |
|
| 5436 | + if (count($colParam['style']['width'])) { |
|
| 5437 | + $total = $colParam['style']['width'][0]; unset($colParam['style']['width'][0]); |
|
| 5438 | + foreach ($colParam['style']['width'] as $width) { |
|
| 5439 | + if (substr($total, -1) == '%' && substr($width, -1) == '%') |
|
| 5440 | + $total = (str_replace('%', '', $total) + str_replace('%', '', $width)).'%'; |
|
| 5441 | + else |
|
| 5442 | + $total = ($this->parsingCss->ConvertToMM($total, $last) + $this->parsingCss->ConvertToMM($width, $last)).'mm'; |
|
| 5443 | + } |
|
| 5444 | + } |
|
| 5445 | + |
|
| 5446 | + // get the final width |
|
| 5447 | + if ($total) { |
|
| 5448 | + $colParam['style']['width'] = $total; |
|
| 5449 | + } else { |
|
| 5450 | + unset($colParam['style']['width']); |
|
| 5451 | + } |
|
| 5452 | + |
|
| 5453 | + |
|
| 5454 | + // merge the styles of the COL and the TD |
|
| 5455 | + $param['style'] = array_merge($colParam['style'], $param['style']); |
|
| 5456 | + |
|
| 5457 | + // merge the class of the COL and the TD |
|
| 5458 | + if (isset($colParam['class'])) { |
|
| 5459 | + $param['class'] = $colParam['class'].(isset($param['class']) ? ' '.$param['class'] : ''); |
|
| 5460 | + } |
|
| 5461 | + } |
|
| 5462 | + |
|
| 5463 | + $collapse = isset($this->parsingCss->value['border']['collapse']) ? $this->parsingCss->value['border']['collapse'] : false; |
|
| 5464 | + } |
|
| 5465 | + |
|
| 5466 | + $this->parsingCss->save(); |
|
| 5467 | + |
|
| 5468 | + // legacy for TD and TH |
|
| 5469 | + $legacy = null; |
|
| 5470 | + if (in_array($other, array('td', 'th'))) { |
|
| 5471 | + $legacy = array(); |
|
| 5472 | + |
|
| 5473 | + $old = $this->parsingCss->getLastValue('background'); |
|
| 5474 | + if ($old && ($old['color'] || $old['image'])) { |
|
| 5475 | + $legacy['background'] = $old; |
|
| 5476 | + } |
|
| 5477 | + |
|
| 5478 | + if (HTML2PDF::$_tables[$param['num']]['border']) { |
|
| 5479 | + $legacy['border'] = array(); |
|
| 5480 | + $legacy['border']['l'] = HTML2PDF::$_tables[$param['num']]['border']; |
|
| 5481 | + $legacy['border']['t'] = HTML2PDF::$_tables[$param['num']]['border']; |
|
| 5482 | + $legacy['border']['r'] = HTML2PDF::$_tables[$param['num']]['border']; |
|
| 5483 | + $legacy['border']['b'] = HTML2PDF::$_tables[$param['num']]['border']; |
|
| 5484 | + } |
|
| 5485 | + } |
|
| 5486 | + $return = $this->parsingCss->analyse($other, $param, $legacy); |
|
| 5487 | + |
|
| 5488 | + if ($specialLi) { |
|
| 5489 | + $this->parsingCss->value['width'] -= $this->parsingCss->ConvertToMM($this->_listeGetWidth()); |
|
| 5490 | + $this->parsingCss->value['width'] -= $this->parsingCss->ConvertToMM($this->_listeGetPadding()); |
|
| 5491 | + } |
|
| 5492 | + $this->parsingCss->setPosition(); |
|
| 5493 | + $this->parsingCss->fontSet(); |
|
| 5494 | + |
|
| 5495 | + // if tale collapse => modify the borders |
|
| 5496 | + if ($collapse) { |
|
| 5497 | + if ( ! $this->_subPart) { |
|
| 5498 | + if ( |
|
| 5499 | + (HTML2PDF::$_tables[$param['num']]['tr_curr'] > 1 && ! HTML2PDF::$_tables[$param['num']]['new_page']) || |
|
| 5500 | + ( ! $this->_isInThead && count(HTML2PDF::$_tables[$param['num']]['thead']['code'])) |
|
| 5501 | + ) { |
|
| 5502 | + $this->parsingCss->value['border']['t'] = $this->parsingCss->readBorder('none'); |
|
| 5503 | + } |
|
| 5504 | + } |
|
| 5505 | + |
|
| 5506 | + if (HTML2PDF::$_tables[$param['num']]['td_curr'] > 0) { |
|
| 5507 | + if ( ! $return) $this->parsingCss->value['width'] += $this->parsingCss->value['border']['l']['width']; |
|
| 5508 | + $this->parsingCss->value['border']['l'] = $this->parsingCss->readBorder('none'); |
|
| 5509 | + } |
|
| 5510 | + } |
|
| 5511 | + |
|
| 5512 | + // margins of the table |
|
| 5513 | + $marge = array(); |
|
| 5514 | + $marge['t'] = $this->parsingCss->value['padding']['t'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['t']['width']; |
|
| 5515 | + $marge['r'] = $this->parsingCss->value['padding']['r'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['r']['width']; |
|
| 5516 | + $marge['b'] = $this->parsingCss->value['padding']['b'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['b']['width']; |
|
| 5517 | + $marge['l'] = $this->parsingCss->value['padding']['l'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['l']['width']; |
|
| 5518 | + |
|
| 5519 | + // if we are in a sub HTML |
|
| 5520 | + if ($this->_subPart) { |
|
| 5521 | + // new position in the table |
|
| 5522 | + HTML2PDF::$_tables[$param['num']]['td_curr']++; |
|
| 5523 | + HTML2PDF::$_tables[$param['num']]['cases'][$y][$x] = array(); |
|
| 5524 | + HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['w'] = 0; |
|
| 5525 | + HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['h'] = 0; |
|
| 5526 | + HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['dw'] = 0; |
|
| 5527 | + HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['colspan'] = $colspan; |
|
| 5528 | + HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['rowspan'] = $rowspan; |
|
| 5529 | + HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Xr'] = HTML2PDF::$_tables[$param['num']]['corr_x']; |
|
| 5530 | + HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Yr'] = HTML2PDF::$_tables[$param['num']]['corr_y']; |
|
| 5531 | + |
|
| 5532 | + // prepare the mapping for rowspan and colspan |
|
| 5533 | + for ($j = 0; $j < $rowspan; $j++) { |
|
| 5534 | + for ($i = 0; $i < $colspan; $i++) { |
|
| 5535 | + HTML2PDF::$_tables[$param['num']]['corr'] |
|
| 5536 | + [HTML2PDF::$_tables[$param['num']]['corr_y'] + $j] |
|
| 5537 | + [HTML2PDF::$_tables[$param['num']]['corr_x'] + $i] = ($i + $j > 0) ? '' : array($x, $y, $colspan, $rowspan); |
|
| 5538 | + } |
|
| 5539 | + } |
|
| 5540 | + HTML2PDF::$_tables[$param['num']]['corr_x'] += $colspan; |
|
| 5541 | + while (isset(HTML2PDF::$_tables[$param['num']]['corr'][HTML2PDF::$_tables[$param['num']]['corr_y']][HTML2PDF::$_tables[$param['num']]['corr_x']])) { |
|
| 5542 | + HTML2PDF::$_tables[$param['num']]['corr_x']++; |
|
| 5543 | + } |
|
| 5544 | + |
|
| 5545 | + // extract the content of the TD, and calculate his size |
|
| 5546 | + $level = $this->parsingHtml->getLevel($this->_tempPos); |
|
| 5547 | + $this->_createSubHTML($this->_subHtml); |
|
| 5548 | + $this->_subHtml->parsingHtml->code = $level; |
|
| 5549 | + $this->_subHtml->_makeHTMLcode(); |
|
| 5550 | + $this->_tempPos += count($level); |
|
| 5551 | + } else { |
|
| 5552 | + // new position in the table |
|
| 5553 | + HTML2PDF::$_tables[$param['num']]['td_curr']++; |
|
| 5554 | + HTML2PDF::$_tables[$param['num']]['td_x'] += HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['dw']; |
|
| 5555 | + |
|
| 5556 | + // borders and background of the TD |
|
| 5557 | + $this->_drawRectangle( |
|
| 5558 | + HTML2PDF::$_tables[$param['num']]['td_x'], |
|
| 5559 | + HTML2PDF::$_tables[$param['num']]['td_y'], |
|
| 5560 | + HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['w'], |
|
| 5561 | + HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['h'], |
|
| 5562 | + $this->parsingCss->value['border'], |
|
| 5563 | + $this->parsingCss->value['padding'], |
|
| 5564 | + HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5, |
|
| 5565 | + $this->parsingCss->value['background'] |
|
| 5566 | + ); |
|
| 5567 | + |
|
| 5568 | + $this->parsingCss->value['width'] = HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['w'] - $marge['l'] - $marge['r']; |
|
| 5569 | + |
|
| 5570 | + // marges = size of the TD |
|
| 5571 | + $mL = HTML2PDF::$_tables[$param['num']]['td_x'] + $marge['l']; |
|
| 5572 | + $mR = $this->pdf->getW() - $mL - $this->parsingCss->value['width']; |
|
| 5573 | + $this->_saveMargin($mL, 0, $mR); |
|
| 5574 | + |
|
| 5575 | + // position of the content, from vertical-align |
|
| 5576 | + $hCorr = HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['h']; |
|
| 5577 | + $hReel = HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['real_h']; |
|
| 5578 | + switch ($this->parsingCss->value['vertical-align']) |
|
| 5579 | + { |
|
| 5580 | + case 'bottom': |
|
| 5581 | + $yCorr = $hCorr - $hReel; |
|
| 5582 | + break; |
|
| 5583 | + |
|
| 5584 | + case 'middle': |
|
| 5585 | + $yCorr = ($hCorr - $hReel) * 0.5; |
|
| 5586 | + break; |
|
| 5587 | + |
|
| 5588 | + case 'top': |
|
| 5589 | + default: |
|
| 5590 | + $yCorr = 0; |
|
| 5591 | + break; |
|
| 5592 | + } |
|
| 5593 | + |
|
| 5594 | + // position of the content |
|
| 5595 | + $x = HTML2PDF::$_tables[$param['num']]['td_x'] + $marge['l']; |
|
| 5596 | + $y = HTML2PDF::$_tables[$param['num']]['td_y'] + $marge['t'] + $yCorr; |
|
| 5597 | + $this->pdf->setXY($x, $y); |
|
| 5598 | + $this->_setNewPositionForNewLine(); |
|
| 5599 | + } |
|
| 5600 | + |
|
| 5601 | + return true; |
|
| 5602 | + } |
|
| 5603 | + |
|
| 5604 | + /** |
|
| 5605 | + * tag : TD |
|
| 5606 | + * mode : CLOSE |
|
| 5607 | + * |
|
| 5608 | + * @param array $param |
|
| 5609 | + * @return boolean |
|
| 5610 | + */ |
|
| 5611 | + protected function _tag_close_TD($param) |
|
| 5612 | + { |
|
| 5613 | + if ($this->_isForOneLine) { |
|
| 5614 | + return false; |
|
| 5615 | + } |
|
| 5616 | + |
|
| 5617 | + $this->_maxH = 0; |
|
| 5618 | + |
|
| 5619 | + // get the margins |
|
| 5620 | + $marge = array(); |
|
| 5621 | + $marge['t'] = $this->parsingCss->value['padding']['t'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['t']['width']; |
|
| 5622 | + $marge['r'] = $this->parsingCss->value['padding']['r'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['r']['width']; |
|
| 5623 | + $marge['b'] = $this->parsingCss->value['padding']['b'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['b']['width']; |
|
| 5624 | + $marge['l'] = $this->parsingCss->value['padding']['l'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['l']['width']; |
|
| 5625 | + $marge['t'] += 0.001; |
|
| 5626 | + $marge['r'] += 0.001; |
|
| 5627 | + $marge['b'] += 0.001; |
|
| 5628 | + $marge['l'] += 0.001; |
|
| 5629 | + |
|
| 5630 | + // if we are in a sub HTML |
|
| 5631 | + if ($this->_subPart) { |
|
| 5632 | + |
|
| 5633 | + // it msut take only one page |
|
| 5634 | + if ($this->_testTdInOnepage && $this->_subHtml->pdf->getPage() > 1) { |
|
| 5635 | + throw new HTML2PDF_exception(7); |
|
| 5636 | + } |
|
| 5637 | + |
|
| 5638 | + // size of the content of the TD |
|
| 5639 | + $w0 = $this->_subHtml->_maxX + $marge['l'] + $marge['r']; |
|
| 5640 | + $h0 = $this->_subHtml->_maxY + $marge['t'] + $marge['b']; |
|
| 5641 | + |
|
| 5642 | + // size from the CSS style |
|
| 5643 | + $w2 = $this->parsingCss->value['width'] + $marge['l'] + $marge['r']; |
|
| 5644 | + $h2 = $this->parsingCss->value['height'] + $marge['t'] + $marge['b']; |
|
| 5645 | + |
|
| 5646 | + // final size of the TD |
|
| 5647 | + HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['w'] = max(array($w0, $w2)); |
|
| 5648 | + HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['h'] = max(array($h0, $h2)); |
|
| 5649 | + |
|
| 5650 | + // real position of the content |
|
| 5651 | + HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['real_w'] = $w0; |
|
| 5652 | + HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['real_h'] = $h0; |
|
| 5653 | + |
|
| 5654 | + // destroy the sub HTML |
|
| 5655 | + $this->_destroySubHTML($this->_subHtml); |
|
| 5656 | + } else { |
|
| 5657 | + $this->_loadMargin(); |
|
| 5658 | + |
|
| 5659 | + HTML2PDF::$_tables[$param['num']]['td_x'] += HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['w']; |
|
| 5660 | + } |
|
| 5661 | + |
|
| 5662 | + $this->parsingCss->load(); |
|
| 5663 | + $this->parsingCss->fontSet(); |
|
| 5664 | + |
|
| 5665 | + return true; |
|
| 5666 | + } |
|
| 5667 | + |
|
| 5668 | + |
|
| 5669 | + /** |
|
| 5670 | + * tag : TH |
|
| 5671 | + * mode : OPEN |
|
| 5672 | + * |
|
| 5673 | + * @param array $param |
|
| 5674 | + * @return boolean |
|
| 5675 | + */ |
|
| 5676 | + protected function _tag_open_TH($param) |
|
| 5677 | + { |
|
| 5678 | + if ($this->_isForOneLine) { |
|
| 5679 | + return false; |
|
| 5680 | + } |
|
| 5681 | + |
|
| 5682 | + $this->parsingCss->save(); |
|
| 5683 | + $this->parsingCss->value['font-bold'] = true; |
|
| 5684 | + |
|
| 5685 | + $this->_tag_open_TD($param, 'th'); |
|
| 5686 | + |
|
| 5687 | + return true; |
|
| 5688 | + } |
|
| 5689 | + |
|
| 5690 | + /** |
|
| 5691 | + * tag : TH |
|
| 5692 | + * mode : CLOSE |
|
| 5693 | + * |
|
| 5694 | + * @param array $param |
|
| 5695 | + * @return boolean |
|
| 5696 | + */ |
|
| 5697 | + protected function _tag_close_TH($param) |
|
| 5698 | + { |
|
| 5699 | + if ($this->_isForOneLine) { |
|
| 5700 | + return false; |
|
| 5701 | + } |
|
| 5702 | + |
|
| 5703 | + $this->_tag_close_TD($param); |
|
| 5704 | + |
|
| 5705 | + $this->parsingCss->load(); |
|
| 5706 | + |
|
| 5707 | + return true; |
|
| 5708 | + } |
|
| 5709 | + |
|
| 5710 | + /** |
|
| 5711 | + * tag : IMG |
|
| 5712 | + * mode : OPEN |
|
| 5713 | + * |
|
| 5714 | + * @param array $param |
|
| 5715 | + * @return boolean |
|
| 5716 | + */ |
|
| 5717 | + protected function _tag_open_IMG($param) |
|
| 5718 | + { |
|
| 5719 | + $src = str_replace('&', '&', $param['src']); |
|
| 5720 | + |
|
| 5721 | + $this->parsingCss->save(); |
|
| 5722 | + $this->parsingCss->value['width'] = 0; |
|
| 5723 | + $this->parsingCss->value['height'] = 0; |
|
| 5724 | + $this->parsingCss->value['border'] = array('type' => 'none', 'width' => 0, 'color' => array(0, 0, 0)); |
|
| 5725 | + $this->parsingCss->value['background'] = array('color' => null, 'image' => null, 'position' => null, 'repeat' => null); |
|
| 5726 | + $this->parsingCss->analyse('img', $param); |
|
| 5727 | + $this->parsingCss->setPosition(); |
|
| 5728 | + $this->parsingCss->fontSet(); |
|
| 5729 | + |
|
| 5730 | + $res = $this->_drawImage($src, isset($param['sub_li'])); |
|
| 5731 | + if ( ! $res) return $res; |
|
| 5732 | + |
|
| 5733 | + $this->parsingCss->load(); |
|
| 5734 | + $this->parsingCss->fontSet(); |
|
| 5735 | + $this->_maxE++; |
|
| 5736 | + |
|
| 5737 | + return true; |
|
| 5738 | + } |
|
| 5739 | + |
|
| 5740 | + /** |
|
| 5741 | + * tag : SELECT |
|
| 5742 | + * mode : OPEN |
|
| 5743 | + * |
|
| 5744 | + * @param array $param |
|
| 5745 | + * @return boolean |
|
| 5746 | + */ |
|
| 5747 | + protected function _tag_open_SELECT($param) |
|
| 5748 | + { |
|
| 5749 | + if ( ! isset($param['name'])) { |
|
| 5750 | + $param['name'] = 'champs_pdf_'.(count($this->_lstField) + 1); |
|
| 5751 | + } |
|
| 5752 | + |
|
| 5753 | + $param['name'] = strtolower($param['name']); |
|
| 5754 | + |
|
| 5755 | + if (isset($this->_lstField[$param['name']])) { |
|
| 5756 | + $this->_lstField[$param['name']]++; |
|
| 5757 | + } else { |
|
| 5758 | + $this->_lstField[$param['name']] = 1; |
|
| 5759 | + } |
|
| 5760 | + |
|
| 5761 | + $this->parsingCss->save(); |
|
| 5762 | + $this->parsingCss->analyse('select', $param); |
|
| 5763 | + $this->parsingCss->setPosition(); |
|
| 5764 | + $this->parsingCss->fontSet(); |
|
| 5765 | + |
|
| 5766 | + $this->_lstSelect = array(); |
|
| 5767 | + $this->_lstSelect['name'] = $param['name']; |
|
| 5768 | + $this->_lstSelect['multi'] = isset($param['multiple']) ? true : false; |
|
| 5769 | + $this->_lstSelect['size'] = isset($param['size']) ? $param['size'] : 1; |
|
| 5770 | + $this->_lstSelect['options'] = array(); |
|
| 5771 | + |
|
| 5772 | + if ($this->_lstSelect['multi'] && $this->_lstSelect['size'] < 3) $this->_lstSelect['size'] = 3; |
|
| 5773 | + |
|
| 5774 | + return true; |
|
| 5775 | + } |
|
| 5776 | + |
|
| 5777 | + /** |
|
| 5778 | + * tag : OPTION |
|
| 5779 | + * mode : OPEN |
|
| 5780 | + * |
|
| 5781 | + * @param array $param |
|
| 5782 | + * @return boolean |
|
| 5783 | + */ |
|
| 5784 | + protected function _tag_open_OPTION($param) |
|
| 5785 | + { |
|
| 5786 | + // get the content of the option : it is the text of the option |
|
| 5787 | + $level = $this->parsingHtml->getLevel($this->_parsePos); |
|
| 5788 | + $this->_parsePos += count($level); |
|
| 5789 | + $value = isset($param['value']) ? $param['value'] : 'aut_tag_open_opt_'.(count($this->_lstSelect) + 1); |
|
| 5790 | + |
|
| 5791 | + $this->_lstSelect['options'][$value] = isset($level[0]['param']['txt']) ? $level[0]['param']['txt'] : ''; |
|
| 5792 | + |
|
| 5793 | + return true; |
|
| 5794 | + } |
|
| 5795 | + |
|
| 5796 | + /** |
|
| 5797 | + * tag : OPTION |
|
| 5798 | + * mode : CLOSE |
|
| 5799 | + * |
|
| 5800 | + * @param array $param |
|
| 5801 | + * @return boolean |
|
| 5802 | + */ |
|
| 5803 | + protected function _tag_close_OPTION($param) |
|
| 5804 | + { |
|
| 5805 | + // nothing to do here |
|
| 5806 | + |
|
| 5807 | + return true; |
|
| 5808 | + } |
|
| 5809 | + |
|
| 5810 | + /** |
|
| 5811 | + * tag : SELECT |
|
| 5812 | + * mode : CLOSE |
|
| 5813 | + * |
|
| 5814 | + * @return boolean |
|
| 5815 | + */ |
|
| 5816 | + protected function _tag_close_SELECT() |
|
| 5817 | + { |
|
| 5818 | + // position of the select |
|
| 5819 | + $x = $this->pdf->getX(); |
|
| 5820 | + $y = $this->pdf->getY(); |
|
| 5821 | + $f = 1.08 * $this->parsingCss->value['font-size']; |
|
| 5822 | + |
|
| 5823 | + // width |
|
| 5824 | + $w = $this->parsingCss->value['width']; if ( ! $w) $w = 50; |
|
| 5825 | + |
|
| 5826 | + // height (automatic) |
|
| 5827 | + $h = ($f * 1.07 * $this->_lstSelect['size'] + 1); |
|
| 5828 | + |
|
| 5829 | + $prop = $this->parsingCss->getFormStyle(); |
|
| 5830 | + |
|
| 5831 | + // multy select |
|
| 5832 | + if ($this->_lstSelect['multi']) { |
|
| 5833 | + $prop['multipleSelection'] = 'true'; |
|
| 5834 | + } |
|
| 5835 | + |
|
| 5836 | + |
|
| 5837 | + // single or multi select |
|
| 5838 | + if ($this->_lstSelect['size'] > 1) { |
|
| 5839 | + $this->pdf->ListBox($this->_lstSelect['name'], $w, $h, $this->_lstSelect['options'], $prop); |
|
| 5840 | + } else { |
|
| 5841 | + $this->pdf->ComboBox($this->_lstSelect['name'], $w, $h, $this->_lstSelect['options'], $prop); |
|
| 5842 | + } |
|
| 5843 | + |
|
| 5844 | + $this->_maxX = max($this->_maxX, $x + $w); |
|
| 5845 | + $this->_maxY = max($this->_maxY, $y + $h); |
|
| 5846 | + $this->_maxH = max($this->_maxH, $h); |
|
| 5847 | + $this->_maxE++; |
|
| 5848 | + $this->pdf->setX($x + $w); |
|
| 5849 | + |
|
| 5850 | + $this->parsingCss->load(); |
|
| 5851 | + $this->parsingCss->fontSet(); |
|
| 5852 | + |
|
| 5853 | + $this->_lstSelect = array(); |
|
| 5854 | + |
|
| 5855 | + return true; |
|
| 5856 | + } |
|
| 5857 | + |
|
| 5858 | + /** |
|
| 5859 | + * tag : TEXTAREA |
|
| 5860 | + * mode : OPEN |
|
| 5861 | + * |
|
| 5862 | + * @param array $param |
|
| 5863 | + * @return boolean |
|
| 5864 | + */ |
|
| 5865 | + protected function _tag_open_TEXTAREA($param) |
|
| 5866 | + { |
|
| 5867 | + if ( ! isset($param['name'])) { |
|
| 5868 | + $param['name'] = 'champs_pdf_'.(count($this->_lstField) + 1); |
|
| 5869 | + } |
|
| 5870 | + |
|
| 5871 | + $param['name'] = strtolower($param['name']); |
|
| 5872 | + |
|
| 5873 | + if (isset($this->_lstField[$param['name']])) { |
|
| 5874 | + $this->_lstField[$param['name']]++; |
|
| 5875 | + } else { |
|
| 5876 | + $this->_lstField[$param['name']] = 1; |
|
| 5877 | + } |
|
| 5878 | + |
|
| 5879 | + $this->parsingCss->save(); |
|
| 5880 | + $this->parsingCss->analyse('textarea', $param); |
|
| 5881 | + $this->parsingCss->setPosition(); |
|
| 5882 | + $this->parsingCss->fontSet(); |
|
| 5883 | + |
|
| 5884 | + $x = $this->pdf->getX(); |
|
| 5885 | + $y = $this->pdf->getY(); |
|
| 5886 | + $fx = 0.65 * $this->parsingCss->value['font-size']; |
|
| 5887 | + $fy = 1.08 * $this->parsingCss->value['font-size']; |
|
| 5888 | + |
|
| 5889 | + // extract the content the textarea : value |
|
| 5890 | + $level = $this->parsingHtml->getLevel($this->_parsePos); |
|
| 5891 | + $this->_parsePos += count($level); |
|
| 5892 | + |
|
| 5893 | + // automatic size, from cols and rows properties |
|
| 5894 | + $w = $fx * (isset($param['cols']) ? $param['cols'] : 22) + 1; |
|
| 5895 | + $h = $fy * 1.07 * (isset($param['rows']) ? $param['rows'] : 3) + 3; |
|
| 5896 | + |
|
| 5897 | + $prop = $this->parsingCss->getFormStyle(); |
|
| 5898 | + |
|
| 5899 | + $prop['multiline'] = true; |
|
| 5900 | + $prop['value'] = isset($level[0]['param']['txt']) ? $level[0]['param']['txt'] : ''; |
|
| 5901 | + |
|
| 5902 | + $this->pdf->TextField($param['name'], $w, $h, $prop, array(), $x, $y); |
|
| 5903 | + |
|
| 5904 | + $this->_maxX = max($this->_maxX, $x + $w); |
|
| 5905 | + $this->_maxY = max($this->_maxY, $y + $h); |
|
| 5906 | + $this->_maxH = max($this->_maxH, $h); |
|
| 5907 | + $this->_maxE++; |
|
| 5908 | + $this->pdf->setX($x + $w); |
|
| 5909 | + |
|
| 5910 | + return true; |
|
| 5911 | + } |
|
| 5912 | + |
|
| 5913 | + /** |
|
| 5914 | + * tag : TEXTAREA |
|
| 5915 | + * mode : CLOSE |
|
| 5916 | + * |
|
| 5917 | + * @return boolean |
|
| 5918 | + */ |
|
| 5919 | + protected function _tag_close_TEXTAREA() |
|
| 5920 | + { |
|
| 5921 | + $this->parsingCss->load(); |
|
| 5922 | + $this->parsingCss->fontSet(); |
|
| 5923 | + |
|
| 5924 | + return true; |
|
| 5925 | + } |
|
| 5926 | + |
|
| 5927 | + /** |
|
| 5928 | + * tag : INPUT |
|
| 5929 | + * mode : OPEN |
|
| 5930 | + * |
|
| 5931 | + * @param array $param |
|
| 5932 | + * @return boolean |
|
| 5933 | + */ |
|
| 5934 | + protected function _tag_open_INPUT($param) |
|
| 5935 | + { |
|
| 5936 | + if ( ! isset($param['name'])) $param['name'] = 'champs_pdf_'.(count($this->_lstField) + 1); |
|
| 5937 | + if ( ! isset($param['value'])) $param['value'] = ''; |
|
| 5938 | + if ( ! isset($param['type'])) $param['type'] = 'text'; |
|
| 5939 | + |
|
| 5940 | + $param['name'] = strtolower($param['name']); |
|
| 5941 | + $param['type'] = strtolower($param['type']); |
|
| 5942 | + |
|
| 5943 | + // the type must be valid |
|
| 5944 | + if ( ! in_array($param['type'], array('text', 'checkbox', 'radio', 'hidden', 'submit', 'reset', 'button'))) { |
|
| 5945 | + $param['type'] = 'text'; |
|
| 5946 | + } |
|
| 5947 | + |
|
| 5948 | + if (isset($this->_lstField[$param['name']])) { |
|
| 5949 | + $this->_lstField[$param['name']]++; |
|
| 5950 | + } else { |
|
| 5951 | + $this->_lstField[$param['name']] = 1; |
|
| 5952 | + } |
|
| 5953 | + |
|
| 5954 | + $this->parsingCss->save(); |
|
| 5955 | + $this->parsingCss->analyse('input', $param); |
|
| 5956 | + $this->parsingCss->setPosition(); |
|
| 5957 | + $this->parsingCss->fontSet(); |
|
| 5958 | + |
|
| 5959 | + $name = $param['name']; |
|
| 5960 | + |
|
| 5961 | + $x = $this->pdf->getX(); |
|
| 5962 | + $y = $this->pdf->getY(); |
|
| 5963 | + $f = 1.08 * $this->parsingCss->value['font-size']; |
|
| 5964 | + |
|
| 5965 | + $prop = $this->parsingCss->getFormStyle(); |
|
| 5966 | + |
|
| 5967 | + switch ($param['type']) |
|
| 5968 | + { |
|
| 5969 | + case 'checkbox': |
|
| 5970 | + $w = 3; |
|
| 5971 | + $h = $w; |
|
| 5972 | + if ($h < $f) $y += ($f - $h) * 0.5; |
|
| 5973 | + $checked = (isset($param['checked']) && $param['checked'] == 'checked'); |
|
| 5974 | + $this->pdf->CheckBox($name, $w, $checked, $prop, array(), ($param['value'] ? $param['value'] : 'Yes'), $x, $y); |
|
| 5975 | + break; |
|
| 5976 | + |
|
| 5977 | + case 'radio': |
|
| 5978 | + $w = 3; |
|
| 5979 | + $h = $w; |
|
| 5980 | + if ($h < $f) $y += ($f - $h) * 0.5; |
|
| 5981 | + $checked = (isset($param['checked']) && $param['checked'] == 'checked'); |
|
| 5982 | + $this->pdf->RadioButton($name, $w, $prop, array(), ($param['value'] ? $param['value'] : 'On'), $checked, $x, $y); |
|
| 5983 | + break; |
|
| 5984 | + |
|
| 5985 | + case 'hidden': |
|
| 5986 | + $w = 0; |
|
| 5987 | + $h = 0; |
|
| 5988 | + $prop['value'] = $param['value']; |
|
| 5989 | + $this->pdf->TextField($name, $w, $h, $prop, array(), $x, $y); |
|
| 5990 | + break; |
|
| 5991 | + |
|
| 5992 | + case 'text': |
|
| 5993 | + $w = $this->parsingCss->value['width']; if ( ! $w) $w = 40; |
|
| 5994 | + $h = $f * 1.3; |
|
| 5995 | + $prop['value'] = $param['value']; |
|
| 5996 | + $this->pdf->TextField($name, $w, $h, $prop, array(), $x, $y); |
|
| 5997 | + break; |
|
| 5998 | + |
|
| 5999 | + case 'submit': |
|
| 6000 | + $w = $this->parsingCss->value['width']; if ( ! $w) $w = 40; |
|
| 6001 | + $h = $this->parsingCss->value['height']; if ( ! $h) $h = $f * 1.3; |
|
| 6002 | + $action = array('S'=>'SubmitForm', 'F'=>$this->_isInForm, 'Flags'=>array('ExportFormat')); |
|
| 6003 | + $this->pdf->Button($name, $w, $h, $param['value'], $action, $prop, array(), $x, $y); |
|
| 6004 | + break; |
|
| 6005 | + |
|
| 6006 | + case 'reset': |
|
| 6007 | + $w = $this->parsingCss->value['width']; if ( ! $w) $w = 40; |
|
| 6008 | + $h = $this->parsingCss->value['height']; if ( ! $h) $h = $f * 1.3; |
|
| 6009 | + $action = array('S'=>'ResetForm'); |
|
| 6010 | + $this->pdf->Button($name, $w, $h, $param['value'], $action, $prop, array(), $x, $y); |
|
| 6011 | + break; |
|
| 6012 | + |
|
| 6013 | + case 'button': |
|
| 6014 | + $w = $this->parsingCss->value['width']; if ( ! $w) $w = 40; |
|
| 6015 | + $h = $this->parsingCss->value['height']; if ( ! $h) $h = $f * 1.3; |
|
| 6016 | + $action = isset($param['onclick']) ? $param['onclick'] : ''; |
|
| 6017 | + $this->pdf->Button($name, $w, $h, $param['value'], $action, $prop, array(), $x, $y); |
|
| 6018 | + break; |
|
| 6019 | + |
|
| 6020 | + default: |
|
| 6021 | + $w = 0; |
|
| 6022 | + $h = 0; |
|
| 6023 | + break; |
|
| 6024 | + } |
|
| 6025 | + |
|
| 6026 | + $this->_maxX = max($this->_maxX, $x + $w); |
|
| 6027 | + $this->_maxY = max($this->_maxY, $y + $h); |
|
| 6028 | + $this->_maxH = max($this->_maxH, $h); |
|
| 6029 | + $this->_maxE++; |
|
| 6030 | + $this->pdf->setX($x + $w); |
|
| 6031 | + |
|
| 6032 | + $this->parsingCss->load(); |
|
| 6033 | + $this->parsingCss->fontSet(); |
|
| 6034 | + |
|
| 6035 | + return true; |
|
| 6036 | + } |
|
| 6037 | + |
|
| 6038 | + /** |
|
| 6039 | + * tag : DRAW |
|
| 6040 | + * mode : OPEN |
|
| 6041 | + * |
|
| 6042 | + * @param array $param |
|
| 6043 | + * @return boolean |
|
| 6044 | + */ |
|
| 6045 | + protected function _tag_open_DRAW($param) |
|
| 6046 | + { |
|
| 6047 | + if ($this->_isForOneLine) { |
|
| 6048 | + return false; |
|
| 6049 | + } |
|
| 6050 | + if ($this->_debugActif) { |
|
| 6051 | + $this->_DEBUG_add('DRAW', true); |
|
| 6052 | + } |
|
| 6053 | + |
|
| 6054 | + $this->parsingCss->save(); |
|
| 6055 | + $this->parsingCss->analyse('draw', $param); |
|
| 6056 | + $this->parsingCss->fontSet(); |
|
| 6057 | + |
|
| 6058 | + $alignObject = null; |
|
| 6059 | + if ($this->parsingCss->value['margin-auto']) { |
|
| 6060 | + $alignObject = 'center'; |
|
| 6061 | + } |
|
| 6062 | + |
|
| 6063 | + $overW = $this->parsingCss->value['width']; |
|
| 6064 | + $overH = $this->parsingCss->value['height']; |
|
| 6065 | + $this->parsingCss->value['old_maxX'] = $this->_maxX; |
|
| 6066 | + $this->parsingCss->value['old_maxY'] = $this->_maxY; |
|
| 6067 | + $this->parsingCss->value['old_maxH'] = $this->_maxH; |
|
| 6068 | + |
|
| 6069 | + $w = $this->parsingCss->value['width']; |
|
| 6070 | + $h = $this->parsingCss->value['height']; |
|
| 6071 | + |
|
| 6072 | + if ( ! $this->parsingCss->value['position']) { |
|
| 6073 | + if ( |
|
| 6074 | + $w < ($this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin()) && |
|
| 6075 | + $this->pdf->getX() + $w >= ($this->pdf->getW() - $this->pdf->getrMargin()) |
|
| 6076 | + ) |
|
| 6077 | + $this->_tag_open_BR(array()); |
|
| 6078 | + |
|
| 6079 | + if ( |
|
| 6080 | + ($h < ($this->pdf->getH() - $this->pdf->gettMargin() - $this->pdf->getbMargin())) && |
|
| 6081 | + ($this->pdf->getY() + $h >= ($this->pdf->getH() - $this->pdf->getbMargin())) && |
|
| 6082 | + ! $this->_isInOverflow |
|
| 6083 | + ) |
|
| 6084 | + $this->_setNewPage(); |
|
| 6085 | + |
|
| 6086 | + $old = $this->parsingCss->getOldValues(); |
|
| 6087 | + $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); |
|
| 6088 | + |
|
| 6089 | + if ($parentWidth > $w) { |
|
| 6090 | + if ($alignObject == 'center') $this->pdf->setX($this->pdf->getX() + ($parentWidth - $w) * 0.5); |
|
| 6091 | + else if ($alignObject == 'right') $this->pdf->setX($this->pdf->getX() + $parentWidth - $w); |
|
| 6092 | + } |
|
| 6093 | + |
|
| 6094 | + $this->parsingCss->setPosition(); |
|
| 6095 | + } else { |
|
| 6096 | + $old = $this->parsingCss->getOldValues(); |
|
| 6097 | + $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); |
|
| 6098 | + |
|
| 6099 | + if ($parentWidth > $w) { |
|
| 6100 | + if ($alignObject == 'center') $this->pdf->setX($this->pdf->getX() + ($parentWidth - $w) * 0.5); |
|
| 6101 | + else if ($alignObject == 'right') $this->pdf->setX($this->pdf->getX() + $parentWidth - $w); |
|
| 6102 | + } |
|
| 6103 | + |
|
| 6104 | + $this->parsingCss->setPosition(); |
|
| 6105 | + $this->_saveMax(); |
|
| 6106 | + $this->_maxX = 0; |
|
| 6107 | + $this->_maxY = 0; |
|
| 6108 | + $this->_maxH = 0; |
|
| 6109 | + $this->_maxE = 0; |
|
| 6110 | + } |
|
| 6111 | + |
|
| 6112 | + $this->_drawRectangle( |
|
| 6113 | + $this->parsingCss->value['x'], |
|
| 6114 | + $this->parsingCss->value['y'], |
|
| 6115 | + $this->parsingCss->value['width'], |
|
| 6116 | + $this->parsingCss->value['height'], |
|
| 6117 | + $this->parsingCss->value['border'], |
|
| 6118 | + $this->parsingCss->value['padding'], |
|
| 6119 | + 0, |
|
| 6120 | + $this->parsingCss->value['background'] |
|
| 6121 | + ); |
|
| 6122 | + |
|
| 6123 | + $marge = array(); |
|
| 6124 | + $marge['l'] = $this->parsingCss->value['border']['l']['width']; |
|
| 6125 | + $marge['r'] = $this->parsingCss->value['border']['r']['width']; |
|
| 6126 | + $marge['t'] = $this->parsingCss->value['border']['t']['width']; |
|
| 6127 | + $marge['b'] = $this->parsingCss->value['border']['b']['width']; |
|
| 6128 | + |
|
| 6129 | + $this->parsingCss->value['width'] -= $marge['l'] + $marge['r']; |
|
| 6130 | + $this->parsingCss->value['height'] -= $marge['t'] + $marge['b']; |
|
| 6131 | + |
|
| 6132 | + $overW -= $marge['l'] + $marge['r']; |
|
| 6133 | + $overH -= $marge['t'] + $marge['b']; |
|
| 6134 | + |
|
| 6135 | + // clipping to draw only in the size opf the DRAW tag |
|
| 6136 | + $this->pdf->clippingPathStart( |
|
| 6137 | + $this->parsingCss->value['x'] + $marge['l'], |
|
| 6138 | + $this->parsingCss->value['y'] + $marge['t'], |
|
| 6139 | + $this->parsingCss->value['width'], |
|
| 6140 | + $this->parsingCss->value['height'] |
|
| 6141 | + ); |
|
| 6142 | + |
|
| 6143 | + // left and right of the DRAW tag |
|
| 6144 | + $mL = $this->parsingCss->value['x'] + $marge['l']; |
|
| 6145 | + $mR = $this->pdf->getW() - $mL - $overW; |
|
| 6146 | + |
|
| 6147 | + // position of the DRAW tag |
|
| 6148 | + $x = $this->parsingCss->value['x'] + $marge['l']; |
|
| 6149 | + $y = $this->parsingCss->value['y'] + $marge['t']; |
|
| 6150 | + |
|
| 6151 | + // prepare the drawing area |
|
| 6152 | + $this->_saveMargin($mL, 0, $mR); |
|
| 6153 | + $this->pdf->setXY($x, $y); |
|
| 6154 | + |
|
| 6155 | + // we are in a draw tag |
|
| 6156 | + $this->_isInDraw = array( |
|
| 6157 | + 'x' => $x, |
|
| 6158 | + 'y' => $y, |
|
| 6159 | + 'w' => $overW, |
|
| 6160 | + 'h' => $overH, |
|
| 6161 | + ); |
|
| 6162 | + |
|
| 6163 | + // init the translate matrix : (0,0) => ($x, $y) |
|
| 6164 | + $this->pdf->doTransform(array(1, 0, 0, 1, $x, $y)); |
|
| 6165 | + $this->pdf->SetAlpha(1.); |
|
| 6166 | + return true; |
|
| 6167 | + } |
|
| 6168 | + |
|
| 6169 | + /** |
|
| 6170 | + * tag : DRAW |
|
| 6171 | + * mode : CLOSE |
|
| 6172 | + * |
|
| 6173 | + * @param array $param |
|
| 6174 | + * @return boolean |
|
| 6175 | + */ |
|
| 6176 | + protected function _tag_close_DRAW($param) |
|
| 6177 | + { |
|
| 6178 | + if ($this->_isForOneLine) { |
|
| 6179 | + return false; |
|
| 6180 | + } |
|
| 6181 | + |
|
| 6182 | + $this->pdf->SetAlpha(1.); |
|
| 6183 | + $this->pdf->undoTransform(); |
|
| 6184 | + $this->pdf->clippingPathStop(); |
|
| 6185 | + |
|
| 6186 | + $this->_maxX = $this->parsingCss->value['old_maxX']; |
|
| 6187 | + $this->_maxY = $this->parsingCss->value['old_maxY']; |
|
| 6188 | + $this->_maxH = $this->parsingCss->value['old_maxH']; |
|
| 6189 | + |
|
| 6190 | + $marge = array(); |
|
| 6191 | + $marge['l'] = $this->parsingCss->value['border']['l']['width']; |
|
| 6192 | + $marge['r'] = $this->parsingCss->value['border']['r']['width']; |
|
| 6193 | + $marge['t'] = $this->parsingCss->value['border']['t']['width']; |
|
| 6194 | + $marge['b'] = $this->parsingCss->value['border']['b']['width']; |
|
| 6195 | + |
|
| 6196 | + $x = $this->parsingCss->value['x']; |
|
| 6197 | + $y = $this->parsingCss->value['y']; |
|
| 6198 | + $w = $this->parsingCss->value['width'] + $marge['l'] + $marge['r']; |
|
| 6199 | + $h = $this->parsingCss->value['height'] + $marge['t'] + $marge['b']; |
|
| 6200 | + |
|
| 6201 | + if ($this->parsingCss->value['position'] != 'absolute') { |
|
| 6202 | + $this->pdf->setXY($x + $w, $y); |
|
| 6203 | + |
|
| 6204 | + $this->_maxX = max($this->_maxX, $x + $w); |
|
| 6205 | + $this->_maxY = max($this->_maxY, $y + $h); |
|
| 6206 | + $this->_maxH = max($this->_maxH, $h); |
|
| 6207 | + $this->_maxE++; |
|
| 6208 | + } else { |
|
| 6209 | + // position |
|
| 6210 | + $this->pdf->setXY($this->parsingCss->value['xc'], $this->parsingCss->value['yc']); |
|
| 6211 | + |
|
| 6212 | + $this->_loadMax(); |
|
| 6213 | + } |
|
| 6214 | + |
|
| 6215 | + $block = ($this->parsingCss->value['display'] != 'inline' && $this->parsingCss->value['position'] != 'absolute'); |
|
| 6216 | + |
|
| 6217 | + $this->parsingCss->load(); |
|
| 6218 | + $this->parsingCss->fontSet(); |
|
| 6219 | + $this->_loadMargin(); |
|
| 6220 | + |
|
| 6221 | + if ($block) { |
|
| 6222 | + $this->_tag_open_BR(array()); |
|
| 6223 | + } |
|
| 6224 | + if ($this->_debugActif) { |
|
| 6225 | + $this->_DEBUG_add('DRAW', false); |
|
| 6226 | + } |
|
| 6227 | + |
|
| 6228 | + $this->_isInDraw = null; |
|
| 6229 | + |
|
| 6230 | + return true; |
|
| 6231 | + } |
|
| 6232 | + |
|
| 6233 | + /** |
|
| 6234 | + * tag : LINE |
|
| 6235 | + * mode : OPEN |
|
| 6236 | + * |
|
| 6237 | + * @param array $param |
|
| 6238 | + * @return boolean|null |
|
| 6239 | + */ |
|
| 6240 | + protected function _tag_open_LINE($param) |
|
| 6241 | + { |
|
| 6242 | + if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'LINE'); |
|
| 6243 | + |
|
| 6244 | + $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6245 | + $this->parsingCss->save(); |
|
| 6246 | + $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6247 | + $styles['fill'] = null; |
|
| 6248 | + $style = $this->pdf->svgSetStyle($styles); |
|
| 6249 | + |
|
| 6250 | + $x1 = isset($param['x1']) ? $this->parsingCss->ConvertToMM($param['x1'], $this->_isInDraw['w']) : 0.; |
|
| 6251 | + $y1 = isset($param['y1']) ? $this->parsingCss->ConvertToMM($param['y1'], $this->_isInDraw['h']) : 0.; |
|
| 6252 | + $x2 = isset($param['x2']) ? $this->parsingCss->ConvertToMM($param['x2'], $this->_isInDraw['w']) : 0.; |
|
| 6253 | + $y2 = isset($param['y2']) ? $this->parsingCss->ConvertToMM($param['y2'], $this->_isInDraw['h']) : 0.; |
|
| 6254 | + $this->pdf->svgLine($x1, $y1, $x2, $y2); |
|
| 6255 | + |
|
| 6256 | + $this->pdf->undoTransform(); |
|
| 6257 | + $this->parsingCss->load(); |
|
| 6258 | + } |
|
| 6259 | + |
|
| 6260 | + /** |
|
| 6261 | + * tag : RECT |
|
| 6262 | + * mode : OPEN |
|
| 6263 | + * |
|
| 6264 | + * @param array $param |
|
| 6265 | + * @return boolean|null |
|
| 6266 | + */ |
|
| 6267 | + protected function _tag_open_RECT($param) |
|
| 6268 | + { |
|
| 6269 | + if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'RECT'); |
|
| 6270 | + |
|
| 6271 | + $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6272 | + $this->parsingCss->save(); |
|
| 6273 | + $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6274 | + $style = $this->pdf->svgSetStyle($styles); |
|
| 6275 | + |
|
| 6276 | + $x = isset($param['x']) ? $this->parsingCss->ConvertToMM($param['x'], $this->_isInDraw['w']) : 0.; |
|
| 6277 | + $y = isset($param['y']) ? $this->parsingCss->ConvertToMM($param['y'], $this->_isInDraw['h']) : 0.; |
|
| 6278 | + $w = isset($param['w']) ? $this->parsingCss->ConvertToMM($param['w'], $this->_isInDraw['w']) : 0.; |
|
| 6279 | + $h = isset($param['h']) ? $this->parsingCss->ConvertToMM($param['h'], $this->_isInDraw['h']) : 0.; |
|
| 6280 | + |
|
| 6281 | + $this->pdf->svgRect($x, $y, $w, $h, $style); |
|
| 6282 | + |
|
| 6283 | + $this->pdf->undoTransform(); |
|
| 6284 | + $this->parsingCss->load(); |
|
| 6285 | + } |
|
| 6286 | + |
|
| 6287 | + /** |
|
| 6288 | + * tag : CIRCLE |
|
| 6289 | + * mode : OPEN |
|
| 6290 | + * |
|
| 6291 | + * @param array $param |
|
| 6292 | + * @return boolean|null |
|
| 6293 | + */ |
|
| 6294 | + protected function _tag_open_CIRCLE($param) |
|
| 6295 | + { |
|
| 6296 | + if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'CIRCLE'); |
|
| 6297 | + |
|
| 6298 | + $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6299 | + $this->parsingCss->save(); |
|
| 6300 | + $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6301 | + $style = $this->pdf->svgSetStyle($styles); |
|
| 6302 | + |
|
| 6303 | + $cx = isset($param['cx']) ? $this->parsingCss->ConvertToMM($param['cx'], $this->_isInDraw['w']) : 0.; |
|
| 6304 | + $cy = isset($param['cy']) ? $this->parsingCss->ConvertToMM($param['cy'], $this->_isInDraw['h']) : 0.; |
|
| 6305 | + $r = isset($param['r']) ? $this->parsingCss->ConvertToMM($param['r'], $this->_isInDraw['w']) : 0.; |
|
| 6306 | + $this->pdf->svgEllipse($cx, $cy, $r, $r, $style); |
|
| 6307 | + |
|
| 6308 | + $this->pdf->undoTransform(); |
|
| 6309 | + $this->parsingCss->load(); |
|
| 6310 | + } |
|
| 6311 | + |
|
| 6312 | + /** |
|
| 6313 | + * tag : ELLIPSE |
|
| 6314 | + * mode : OPEN |
|
| 6315 | + * |
|
| 6316 | + * @param array $param |
|
| 6317 | + * @return boolean|null |
|
| 6318 | + */ |
|
| 6319 | + protected function _tag_open_ELLIPSE($param) |
|
| 6320 | + { |
|
| 6321 | + if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'ELLIPSE'); |
|
| 6322 | + |
|
| 6323 | + $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6324 | + $this->parsingCss->save(); |
|
| 6325 | + $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6326 | + $style = $this->pdf->svgSetStyle($styles); |
|
| 6327 | + |
|
| 6328 | + $cx = isset($param['cx']) ? $this->parsingCss->ConvertToMM($param['cx'], $this->_isInDraw['w']) : 0.; |
|
| 6329 | + $cy = isset($param['cy']) ? $this->parsingCss->ConvertToMM($param['cy'], $this->_isInDraw['h']) : 0.; |
|
| 6330 | + $rx = isset($param['ry']) ? $this->parsingCss->ConvertToMM($param['rx'], $this->_isInDraw['w']) : 0.; |
|
| 6331 | + $ry = isset($param['rx']) ? $this->parsingCss->ConvertToMM($param['ry'], $this->_isInDraw['h']) : 0.; |
|
| 6332 | + $this->pdf->svgEllipse($cx, $cy, $rx, $ry, $style); |
|
| 6333 | + |
|
| 6334 | + $this->pdf->undoTransform(); |
|
| 6335 | + $this->parsingCss->load(); |
|
| 6336 | + } |
|
| 6337 | + |
|
| 6338 | + |
|
| 6339 | + /** |
|
| 6340 | + * tag : POLYLINE |
|
| 6341 | + * mode : OPEN |
|
| 6342 | + * |
|
| 6343 | + * @param array $param |
|
| 6344 | + * @return boolean|null |
|
| 6345 | + */ |
|
| 6346 | + protected function _tag_open_POLYLINE($param) |
|
| 6347 | + { |
|
| 6348 | + if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'POLYGON'); |
|
| 6349 | + |
|
| 6350 | + $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6351 | + $this->parsingCss->save(); |
|
| 6352 | + $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6353 | + $style = $this->pdf->svgSetStyle($styles); |
|
| 6354 | + |
|
| 6355 | + $path = isset($param['points']) ? $param['points'] : null; |
|
| 6356 | + if ($path) { |
|
| 6357 | + $path = str_replace(',', ' ', $path); |
|
| 6358 | + $path = preg_replace('/[\s]+/', ' ', trim($path)); |
|
| 6359 | + |
|
| 6360 | + // prepare the path |
|
| 6361 | + $path = explode(' ', $path); |
|
| 6362 | + foreach ($path as $k => $v) { |
|
| 6363 | + $path[$k] = trim($v); |
|
| 6364 | + if ($path[$k] === '') unset($path[$k]); |
|
| 6365 | + } |
|
| 6366 | + $path = array_values($path); |
|
| 6367 | + |
|
| 6368 | + $actions = array(); |
|
| 6369 | + for ($k = 0; $k < count($path); $k += 2) { |
|
| 6370 | + $actions[] = array( |
|
| 6371 | + ($k ? 'L' : 'M'), |
|
| 6372 | + $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']), |
|
| 6373 | + $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']) |
|
| 6374 | + ); |
|
| 6375 | + } |
|
| 6376 | + |
|
| 6377 | + // drawing |
|
| 6378 | + $this->pdf->svgPolygone($actions, $style); |
|
| 6379 | + } |
|
| 6380 | + |
|
| 6381 | + $this->pdf->undoTransform(); |
|
| 6382 | + $this->parsingCss->load(); |
|
| 6383 | + } |
|
| 6384 | + |
|
| 6385 | + /** |
|
| 6386 | + * tag : POLYGON |
|
| 6387 | + * mode : OPEN |
|
| 6388 | + * |
|
| 6389 | + * @param array $param |
|
| 6390 | + * @return boolean|null |
|
| 6391 | + */ |
|
| 6392 | + protected function _tag_open_POLYGON($param) |
|
| 6393 | + { |
|
| 6394 | + if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'POLYGON'); |
|
| 6395 | + |
|
| 6396 | + $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6397 | + $this->parsingCss->save(); |
|
| 6398 | + $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6399 | + $style = $this->pdf->svgSetStyle($styles); |
|
| 6400 | + |
|
| 6401 | + $path = (isset($param['points']) ? $param['points'] : null); |
|
| 6402 | + if ($path) { |
|
| 6403 | + $path = str_replace(',', ' ', $path); |
|
| 6404 | + $path = preg_replace('/[\s]+/', ' ', trim($path)); |
|
| 6405 | + |
|
| 6406 | + // prepare the path |
|
| 6407 | + $path = explode(' ', $path); |
|
| 6408 | + foreach ($path as $k => $v) { |
|
| 6409 | + $path[$k] = trim($v); |
|
| 6410 | + if ($path[$k] === '') unset($path[$k]); |
|
| 6411 | + } |
|
| 6412 | + $path = array_values($path); |
|
| 6413 | + |
|
| 6414 | + $actions = array(); |
|
| 6415 | + for ($k = 0; $k < count($path); $k += 2) { |
|
| 6416 | + $actions[] = array( |
|
| 6417 | + ($k ? 'L' : 'M'), |
|
| 6418 | + $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']), |
|
| 6419 | + $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']) |
|
| 6420 | + ); |
|
| 6421 | + } |
|
| 6422 | + $actions[] = array('z'); |
|
| 6423 | + |
|
| 6424 | + // drawing |
|
| 6425 | + $this->pdf->svgPolygone($actions, $style); |
|
| 6426 | + } |
|
| 6427 | + |
|
| 6428 | + $this->pdf->undoTransform(); |
|
| 6429 | + $this->parsingCss->load(); |
|
| 6430 | + } |
|
| 6431 | + |
|
| 6432 | + /** |
|
| 6433 | + * tag : PATH |
|
| 6434 | + * mode : OPEN |
|
| 6435 | + * |
|
| 6436 | + * @param array $param |
|
| 6437 | + * @return boolean|null |
|
| 6438 | + */ |
|
| 6439 | + protected function _tag_open_PATH($param) |
|
| 6440 | + { |
|
| 6441 | + if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'PATH'); |
|
| 6442 | + |
|
| 6443 | + $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6444 | + $this->parsingCss->save(); |
|
| 6445 | + $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6446 | + $style = $this->pdf->svgSetStyle($styles); |
|
| 6447 | + |
|
| 6448 | + $path = isset($param['d']) ? $param['d'] : null; |
|
| 6449 | + |
|
| 6450 | + if ($path) { |
|
| 6451 | + // prepare the path |
|
| 6452 | + $path = str_replace(',', ' ', $path); |
|
| 6453 | + $path = preg_replace('/([a-zA-Z])([0-9\.\-])/', '$1 $2', $path); |
|
| 6454 | + $path = preg_replace('/([0-9\.])([a-zA-Z])/', '$1 $2', $path); |
|
| 6455 | + $path = preg_replace('/[\s]+/', ' ', trim($path)); |
|
| 6456 | + $path = preg_replace('/ ([a-z]{2})/', '$1', $path); |
|
| 6457 | + |
|
| 6458 | + $path = explode(' ', $path); |
|
| 6459 | + foreach ($path as $k => $v) { |
|
| 6460 | + $path[$k] = trim($v); |
|
| 6461 | + if ($path[$k] === '') unset($path[$k]); |
|
| 6462 | + } |
|
| 6463 | + $path = array_values($path); |
|
| 6464 | + |
|
| 6465 | + // read each actions in the path |
|
| 6466 | + $actions = array(); |
|
| 6467 | + $action = array(); |
|
| 6468 | + $lastAction = null; // last action found |
|
| 6469 | + for ($k = 0; $k < count($path); true) { |
|
| 6470 | + |
|
| 6471 | + // for this actions, we can not have multi coordonate |
|
| 6472 | + if (in_array($lastAction, array('z', 'Z'))) { |
|
| 6473 | + $lastAction = null; |
|
| 6474 | + } |
|
| 6475 | + |
|
| 6476 | + // read the new action (forcing if no action before) |
|
| 6477 | + if (preg_match('/^[a-z]+$/i', $path[$k]) || $lastAction === null) { |
|
| 6478 | + $lastAction = $path[$k]; |
|
| 6479 | + $k++; |
|
| 6480 | + } |
|
| 6481 | + |
|
| 6482 | + // current action |
|
| 6483 | + $action = array(); |
|
| 6484 | + $action[] = $lastAction; |
|
| 6485 | + switch ($lastAction) |
|
| 6486 | + { |
|
| 6487 | + case 'C': |
|
| 6488 | + case 'c': |
|
| 6489 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // x1 |
|
| 6490 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']); // y1 |
|
| 6491 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 2], $this->_isInDraw['w']); // x2 |
|
| 6492 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 3], $this->_isInDraw['h']); // y2 |
|
| 6493 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 4], $this->_isInDraw['w']); // x |
|
| 6494 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 5], $this->_isInDraw['h']); // y |
|
| 6495 | + $k += 6; |
|
| 6496 | + break; |
|
| 6497 | + |
|
| 6498 | + case 'Q': |
|
| 6499 | + case 'S': |
|
| 6500 | + case 'q': |
|
| 6501 | + case 's': |
|
| 6502 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // x2 |
|
| 6503 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']); // y2 |
|
| 6504 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 2], $this->_isInDraw['w']); // x |
|
| 6505 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 3], $this->_isInDraw['h']); // y |
|
| 6506 | + $k += 4; |
|
| 6507 | + break; |
|
| 6508 | + |
|
| 6509 | + case 'A': |
|
| 6510 | + case 'a': |
|
| 6511 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // rx |
|
| 6512 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']); // ry |
|
| 6513 | + $action[] = 1. * $path[$k + 2]; // angle de deviation de l'axe X |
|
| 6514 | + $action[] = ($path[$k + 3] == '1') ? 1 : 0; // large-arc-flag |
|
| 6515 | + $action[] = ($path[$k + 4] == '1') ? 1 : 0; // sweep-flag |
|
| 6516 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 5], $this->_isInDraw['w']); // x |
|
| 6517 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 6], $this->_isInDraw['h']); // y |
|
| 6518 | + $k += 7; |
|
| 6519 | + break; |
|
| 6520 | + |
|
| 6521 | + case 'M': |
|
| 6522 | + case 'L': |
|
| 6523 | + case 'T': |
|
| 6524 | + case 'm': |
|
| 6525 | + case 'l': |
|
| 6526 | + case 't': |
|
| 6527 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // x |
|
| 6528 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']); // y |
|
| 6529 | + $k += 2; |
|
| 6530 | + break; |
|
| 6531 | + |
|
| 6532 | + case 'H': |
|
| 6533 | + case 'h': |
|
| 6534 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // x |
|
| 6535 | + $k += 1; |
|
| 6536 | + break; |
|
| 6537 | + |
|
| 6538 | + case 'V': |
|
| 6539 | + case 'v': |
|
| 6540 | + $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['h']); // y |
|
| 6541 | + $k += 1; |
|
| 6542 | + break; |
|
| 6543 | + |
|
| 6544 | + case 'z': |
|
| 6545 | + case 'Z': |
|
| 6546 | + default: |
|
| 6547 | + break; |
|
| 6548 | + } |
|
| 6549 | + // add the action |
|
| 6550 | + $actions[] = $action; |
|
| 6551 | + } |
|
| 6552 | + |
|
| 6553 | + // drawing |
|
| 6554 | + $this->pdf->svgPolygone($actions, $style); |
|
| 6555 | + } |
|
| 6556 | + |
|
| 6557 | + $this->pdf->undoTransform(); |
|
| 6558 | + $this->parsingCss->load(); |
|
| 6559 | + } |
|
| 6560 | + |
|
| 6561 | + /** |
|
| 6562 | + * tag : G |
|
| 6563 | + * mode : OPEN |
|
| 6564 | + * |
|
| 6565 | + * @param array $param |
|
| 6566 | + * @return boolean|null |
|
| 6567 | + */ |
|
| 6568 | + protected function _tag_open_G($param) |
|
| 6569 | + { |
|
| 6570 | + if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'G'); |
|
| 6571 | + |
|
| 6572 | + $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null); |
|
| 6573 | + $this->parsingCss->save(); |
|
| 6574 | + $styles = $this->parsingCss->getSvgStyle('path', $param); |
|
| 6575 | + $style = $this->pdf->svgSetStyle($styles); |
|
| 6576 | + } |
|
| 6577 | + |
|
| 6578 | + /** |
|
| 6579 | + * tag : G |
|
| 6580 | + * mode : CLOSE |
|
| 6581 | + * |
|
| 6582 | + * @param array $param |
|
| 6583 | + * @return boolean|null |
|
| 6584 | + */ |
|
| 6585 | + protected function _tag_close_G($param) |
|
| 6586 | + { |
|
| 6587 | + $this->pdf->undoTransform(); |
|
| 6588 | + $this->parsingCss->load(); |
|
| 6589 | + } |
|
| 6590 | + |
|
| 6591 | + /** |
|
| 6592 | + * new page for the automatic Index, does not use thie method. Only HTML2PDF_myPdf could use it !!!! |
|
| 6593 | + * |
|
| 6594 | + * @param &int $page |
|
| 6595 | + * @return integer $oldPage |
|
| 6596 | + */ |
|
| 6597 | + public function _INDEX_NewPage(&$page) |
|
| 6598 | + { |
|
| 6599 | + if ($page) { |
|
| 6600 | + $oldPage = $this->pdf->getPage(); |
|
| 6601 | + $this->pdf->setPage($page); |
|
| 6602 | + $this->pdf->setXY($this->_margeLeft, $this->_margeTop); |
|
| 6603 | + $this->_maxH = 0; |
|
| 6604 | + $page++; |
|
| 6605 | + return $oldPage; |
|
| 6606 | + } else { |
|
| 6607 | + $this->_setNewPage(); |
|
| 6608 | + return null; |
|
| 6609 | + } |
|
| 6610 | + } |
|
| 6611 | + |
|
| 6612 | + } |
|
| 6614 | 6613 | } |
@@ -24,579 +24,579 @@ |
||
| 24 | 24 | |
| 25 | 25 | class Summary extends MX_Controller { |
| 26 | 26 | |
| 27 | - function Summary() { |
|
| 28 | - parent::__construct(); |
|
| 27 | + function Summary() { |
|
| 28 | + parent::__construct(); |
|
| 29 | 29 | |
| 30 | - $this->load->helper('template_inheritance'); |
|
| 30 | + $this->load->helper('template_inheritance'); |
|
| 31 | 31 | |
| 32 | - $this->load->library('session'); |
|
| 33 | - $this->load->library('astpp/form'); |
|
| 34 | - $this->load->library("summary_form"); |
|
| 35 | - $this->load->model('summary_model'); |
|
| 36 | - $this->load->library('fpdf'); |
|
| 37 | - $this->load->library('pdf'); |
|
| 38 | - $this->fpdf = new PDF('P', 'pt'); |
|
| 39 | - $this->fpdf->initialize('P', 'mm', 'A4'); |
|
| 32 | + $this->load->library('session'); |
|
| 33 | + $this->load->library('astpp/form'); |
|
| 34 | + $this->load->library("summary_form"); |
|
| 35 | + $this->load->model('summary_model'); |
|
| 36 | + $this->load->library('fpdf'); |
|
| 37 | + $this->load->library('pdf'); |
|
| 38 | + $this->fpdf = new PDF('P', 'pt'); |
|
| 39 | + $this->fpdf->initialize('P', 'mm', 'A4'); |
|
| 40 | 40 | |
| 41 | - if ($this->session->userdata('user_login') == FALSE) |
|
| 42 | - redirect(base_url().'/astpp/login'); |
|
| 43 | - } |
|
| 44 | - function customer() { |
|
| 45 | - $data['page_title'] = 'Customer Summary Report'; |
|
| 46 | - $data['search_flag'] = true; |
|
| 47 | - $session_info = $this->session->userdata('customersummary_reports_search'); |
|
| 48 | - $accountinfo = $this->session->userdata('accountinfo'); |
|
| 49 | - $reseller_id = $accountinfo['type'] == 1 ? $accountinfo['id'] : 0; |
|
| 50 | - $accountlist = $this->db_model->build_dropdown_deleted('id,IF(`deleted`=1,concat( first_name, " ", last_name, " ", "(", number, ")^" ),concat( first_name, " ", last_name, " ", "(", number, ")" )) as number', 'accounts', 'where_arr', array('reseller_id' => $reseller_id, "type" => "GLOBAL")); |
|
| 51 | - $data['accountlist'] = $accountlist; |
|
| 52 | - $data['session_info'] = $session_info; |
|
| 53 | - $data['search_string_type'] = $this->common->search_string_type(); |
|
| 54 | - $data['search_report'] = $this->common->search_report_in(); |
|
| 55 | - $new_column_arr = $this->summary_column_arr('customer'); |
|
| 56 | - $data['grid_fields'] = $this->summary_form->build_customersummary($new_column_arr); |
|
| 57 | - $data["grid_buttons"] = $this->summary_form->build_grid_buttons_customersummary(); |
|
| 58 | - $data['groupby_field'] = $this->common->set_summarycustomer_groupby(); |
|
| 59 | - $data['groupby_time'] = $this->common->group_by_time(); |
|
| 60 | - $this->load->view('view_customersummary_report', $data); |
|
| 61 | - } |
|
| 41 | + if ($this->session->userdata('user_login') == FALSE) |
|
| 42 | + redirect(base_url().'/astpp/login'); |
|
| 43 | + } |
|
| 44 | + function customer() { |
|
| 45 | + $data['page_title'] = 'Customer Summary Report'; |
|
| 46 | + $data['search_flag'] = true; |
|
| 47 | + $session_info = $this->session->userdata('customersummary_reports_search'); |
|
| 48 | + $accountinfo = $this->session->userdata('accountinfo'); |
|
| 49 | + $reseller_id = $accountinfo['type'] == 1 ? $accountinfo['id'] : 0; |
|
| 50 | + $accountlist = $this->db_model->build_dropdown_deleted('id,IF(`deleted`=1,concat( first_name, " ", last_name, " ", "(", number, ")^" ),concat( first_name, " ", last_name, " ", "(", number, ")" )) as number', 'accounts', 'where_arr', array('reseller_id' => $reseller_id, "type" => "GLOBAL")); |
|
| 51 | + $data['accountlist'] = $accountlist; |
|
| 52 | + $data['session_info'] = $session_info; |
|
| 53 | + $data['search_string_type'] = $this->common->search_string_type(); |
|
| 54 | + $data['search_report'] = $this->common->search_report_in(); |
|
| 55 | + $new_column_arr = $this->summary_column_arr('customer'); |
|
| 56 | + $data['grid_fields'] = $this->summary_form->build_customersummary($new_column_arr); |
|
| 57 | + $data["grid_buttons"] = $this->summary_form->build_grid_buttons_customersummary(); |
|
| 58 | + $data['groupby_field'] = $this->common->set_summarycustomer_groupby(); |
|
| 59 | + $data['groupby_time'] = $this->common->group_by_time(); |
|
| 60 | + $this->load->view('view_customersummary_report', $data); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - function customer_json() { |
|
| 64 | - $search_arr = $this->summary_search_info('customer'); |
|
| 65 | - $count_all = $this->summary_model->get_customersummary_report_list(false, 0, 0, $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], false); |
|
| 66 | - $paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
|
| 67 | - $json_data = $paging_data["json_paging"]; |
|
| 68 | - $query = $this->summary_model->get_customersummary_report_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"], $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], false); |
|
| 69 | - if ($query->num_rows() > 0) { |
|
| 70 | - $json_data['rows'] = $this->summary_report_grid($search_arr, $query, 'customer', 'grid'); |
|
| 71 | - } |
|
| 72 | - $this->session->set_userdata('customersummary_reports_export', $search_arr); |
|
| 73 | - echo json_encode($json_data); |
|
| 74 | - } |
|
| 63 | + function customer_json() { |
|
| 64 | + $search_arr = $this->summary_search_info('customer'); |
|
| 65 | + $count_all = $this->summary_model->get_customersummary_report_list(false, 0, 0, $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], false); |
|
| 66 | + $paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
|
| 67 | + $json_data = $paging_data["json_paging"]; |
|
| 68 | + $query = $this->summary_model->get_customersummary_report_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"], $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], false); |
|
| 69 | + if ($query->num_rows() > 0) { |
|
| 70 | + $json_data['rows'] = $this->summary_report_grid($search_arr, $query, 'customer', 'grid'); |
|
| 71 | + } |
|
| 72 | + $this->session->set_userdata('customersummary_reports_export', $search_arr); |
|
| 73 | + echo json_encode($json_data); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * @param string $entity |
|
| 78 | - */ |
|
| 79 | - function summary_column_arr($entity) { |
|
| 80 | - $new_column_arr = array(); |
|
| 81 | - $total_width = '322'; |
|
| 82 | - $column_name = 'accountid'; |
|
| 83 | - if ($this->session->userdata('advance_search') == '1') { |
|
| 84 | - $search_array = $this->session->userdata($entity.'summary_reports_search'); |
|
| 85 | - if (isset($search_array['time']) && ! empty($search_array['time'])) { |
|
| 86 | - $new_column_arr[] = array(ucfirst(strtolower($search_array['time'])), "58", $search_array['time']."(callstart)", "", "", ""); |
|
| 87 | - } |
|
| 88 | - if (isset($search_array['groupby_1']) && ! empty($search_array['groupby_1'])) { |
|
| 89 | - $first_column_groupby = $search_array['groupby_1']; |
|
| 76 | + /** |
|
| 77 | + * @param string $entity |
|
| 78 | + */ |
|
| 79 | + function summary_column_arr($entity) { |
|
| 80 | + $new_column_arr = array(); |
|
| 81 | + $total_width = '322'; |
|
| 82 | + $column_name = 'accountid'; |
|
| 83 | + if ($this->session->userdata('advance_search') == '1') { |
|
| 84 | + $search_array = $this->session->userdata($entity.'summary_reports_search'); |
|
| 85 | + if (isset($search_array['time']) && ! empty($search_array['time'])) { |
|
| 86 | + $new_column_arr[] = array(ucfirst(strtolower($search_array['time'])), "58", $search_array['time']."(callstart)", "", "", ""); |
|
| 87 | + } |
|
| 88 | + if (isset($search_array['groupby_1']) && ! empty($search_array['groupby_1'])) { |
|
| 89 | + $first_column_groupby = $search_array['groupby_1']; |
|
| 90 | 90 | |
| 91 | - if ($first_column_groupby == 'accountid') { |
|
| 92 | - $new_column_arr[] = array("Account", "105", 'accountid', "first_name,last_name,number", "accounts", "build_concat_string"); |
|
| 93 | - } elseif ($first_column_groupby == 'pattern') { |
|
| 94 | - $new_column_arr[] = array("Code", "45", "pattern", "pattern", "", "get_only_numeric_val"); |
|
| 95 | - $new_column_arr[] = array("Destination", "59", "notes", "", "", ""); |
|
| 96 | - } elseif ($first_column_groupby == 'package_id') { |
|
| 97 | - $new_column_arr[] = array("Package", "105", 'package_id', "package_name", "packages", "get_field_name"); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - if (isset($search_array['groupby_2']) && ! empty($search_array['groupby_2'])) { |
|
| 101 | - $third_column_groupby = $search_array['groupby_2']; |
|
| 102 | - if ($third_column_groupby == 'accountid') { |
|
| 103 | - $new_column_arr[] = array("Account", "105", 'accountid', "first_name,last_name,number", "accounts", "build_concat_string"); |
|
| 104 | - } elseif ($third_column_groupby == 'pattern') { |
|
| 105 | - $new_column_arr[] = array("Code", "45", "pattern", "pattern", "", "get_only_numeric_val"); |
|
| 106 | - $new_column_arr[] = array("Destination", "59", "notes", "", "", ""); |
|
| 107 | - } elseif ($third_column_groupby == 'package_id') { |
|
| 108 | - $new_column_arr[] = array("Package", "105", 'package_id', "package_name", "packages", "get_field_name"); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - if (isset($search_array['groupby_3']) && ! empty($search_array['groupby_3'])) { |
|
| 112 | - $fifth_column_groupby = $search_array['groupby_3']; |
|
| 113 | - if ($fifth_column_groupby == 'accountid') { |
|
| 114 | - $new_column_arr[] = array("Account", "105", 'accountid', "first_name,last_name,number", "accounts", "build_concat_string"); |
|
| 115 | - } elseif ($fifth_column_groupby == 'pattern') { |
|
| 116 | - $new_column_arr[] = array("Code", "45", "pattern", "pattern", "", "get_only_numeric_val"); |
|
| 117 | - $new_column_arr[] = array("Destination", "59", "notes", "", "", ""); |
|
| 118 | - } elseif ($fifth_column_groupby == 'package_id') { |
|
| 119 | - $new_column_arr[] = array("Package", "105", 'package_id', "package_name", "packages", "get_field_name"); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - if (empty($new_column_arr)) { |
|
| 123 | - $new_column_arr[] = array("Account", '322', 'accountid', "first_name,last_name,number", "accounts", "build_concat_string"); |
|
| 124 | - } |
|
| 125 | - } else { |
|
| 126 | - $new_column_arr[] = array("Account", '322', 'accountid', "first_name,last_name,number", "accounts", "build_concat_string"); |
|
| 127 | - } |
|
| 91 | + if ($first_column_groupby == 'accountid') { |
|
| 92 | + $new_column_arr[] = array("Account", "105", 'accountid', "first_name,last_name,number", "accounts", "build_concat_string"); |
|
| 93 | + } elseif ($first_column_groupby == 'pattern') { |
|
| 94 | + $new_column_arr[] = array("Code", "45", "pattern", "pattern", "", "get_only_numeric_val"); |
|
| 95 | + $new_column_arr[] = array("Destination", "59", "notes", "", "", ""); |
|
| 96 | + } elseif ($first_column_groupby == 'package_id') { |
|
| 97 | + $new_column_arr[] = array("Package", "105", 'package_id', "package_name", "packages", "get_field_name"); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + if (isset($search_array['groupby_2']) && ! empty($search_array['groupby_2'])) { |
|
| 101 | + $third_column_groupby = $search_array['groupby_2']; |
|
| 102 | + if ($third_column_groupby == 'accountid') { |
|
| 103 | + $new_column_arr[] = array("Account", "105", 'accountid', "first_name,last_name,number", "accounts", "build_concat_string"); |
|
| 104 | + } elseif ($third_column_groupby == 'pattern') { |
|
| 105 | + $new_column_arr[] = array("Code", "45", "pattern", "pattern", "", "get_only_numeric_val"); |
|
| 106 | + $new_column_arr[] = array("Destination", "59", "notes", "", "", ""); |
|
| 107 | + } elseif ($third_column_groupby == 'package_id') { |
|
| 108 | + $new_column_arr[] = array("Package", "105", 'package_id', "package_name", "packages", "get_field_name"); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + if (isset($search_array['groupby_3']) && ! empty($search_array['groupby_3'])) { |
|
| 112 | + $fifth_column_groupby = $search_array['groupby_3']; |
|
| 113 | + if ($fifth_column_groupby == 'accountid') { |
|
| 114 | + $new_column_arr[] = array("Account", "105", 'accountid', "first_name,last_name,number", "accounts", "build_concat_string"); |
|
| 115 | + } elseif ($fifth_column_groupby == 'pattern') { |
|
| 116 | + $new_column_arr[] = array("Code", "45", "pattern", "pattern", "", "get_only_numeric_val"); |
|
| 117 | + $new_column_arr[] = array("Destination", "59", "notes", "", "", ""); |
|
| 118 | + } elseif ($fifth_column_groupby == 'package_id') { |
|
| 119 | + $new_column_arr[] = array("Package", "105", 'package_id', "package_name", "packages", "get_field_name"); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + if (empty($new_column_arr)) { |
|
| 123 | + $new_column_arr[] = array("Account", '322', 'accountid', "first_name,last_name,number", "accounts", "build_concat_string"); |
|
| 124 | + } |
|
| 125 | + } else { |
|
| 126 | + $new_column_arr[] = array("Account", '322', 'accountid', "first_name,last_name,number", "accounts", "build_concat_string"); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - return $new_column_arr; |
|
| 130 | - } |
|
| 129 | + return $new_column_arr; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * @param string $entity |
|
| 134 | - * @param string $purpose |
|
| 135 | - */ |
|
| 136 | - function summary_report_grid($search_arr, $query, $entity, $purpose) { |
|
| 137 | - $export_arr = array(); |
|
| 138 | - $db_field_name = $entity == 'provider' ? 'provider_id' : 'accountid'; |
|
| 139 | - $show_seconds = ( ! empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes'; |
|
| 140 | - $currency_info = $this->common->get_currency_info(); |
|
| 141 | - foreach ($query->result_array() as $row1) { |
|
| 142 | - $atmpt = $row1['attempts']; |
|
| 143 | - $cmplt = ($row1['completed'] != 0) ? $row1['completed'] : 0; |
|
| 144 | - $acd = ($row1['completed'] > 0) ? round($row1['billable'] / $row1['completed']) : 0; |
|
| 145 | - $mcd = $row1['mcd']; |
|
| 146 | - if ($show_seconds == 'minutes') { |
|
| 147 | - $avgsec = $acd > 0 ? sprintf('%02d', $acd / 60).":".sprintf('%02d', ($acd % 60)) : "00:00"; |
|
| 148 | - $maxsec = $mcd > 0 ? sprintf('%02d', $mcd / 60).":".sprintf('%02d', ($mcd % 60)) : "00:00"; |
|
| 149 | - $duration = ($row1['duration'] > 0) ? sprintf('%02d', $row1['duration'] / 60).":".sprintf('%02d', ($row1['duration'] % 60)) : "00:00"; |
|
| 150 | - $billsec = ($row1['billable'] > 0) ? sprintf('%02d', $row1['billable'] / 60).":".sprintf('%02d', ($row1['billable'] % 60)) : "00:00"; |
|
| 151 | - } else { |
|
| 152 | - $duration = sprintf('%02d', $row1['duration']); |
|
| 153 | - $avgsec = $acd; |
|
| 154 | - $maxsec = $mcd; |
|
| 155 | - $billsec = sprintf('%02d', $row1['billable']); |
|
| 156 | - } |
|
| 157 | - if ($entity != 'provider') { |
|
| 158 | - $profit = $this->common->calculate_currency_manually($currency_info, $row1['debit'] - $row1['cost'], false); |
|
| 159 | - $debit = $this->common->calculate_currency_manually($currency_info, $row1['debit'], false); |
|
| 160 | - } |
|
| 161 | - $cost = $this->common->calculate_currency_manually($currency_info, $row1['cost'], false); |
|
| 162 | - $asr = ($atmpt > 0) ? (round(($cmplt / $atmpt) * 100, 2)) : '0.00'; |
|
| 163 | - $new_arr = array(); |
|
| 164 | - if ($this->session->userdata('advance_search') == 1) { |
|
| 165 | - if ( ! empty($search_arr['groupby_time'])) { |
|
| 166 | - $time = $row1[$search_arr['groupby_time']]; |
|
| 167 | - if ($search_arr['groupby_time'] == "HOUR" || $search_arr['groupby_time'] == "DAY") { |
|
| 132 | + /** |
|
| 133 | + * @param string $entity |
|
| 134 | + * @param string $purpose |
|
| 135 | + */ |
|
| 136 | + function summary_report_grid($search_arr, $query, $entity, $purpose) { |
|
| 137 | + $export_arr = array(); |
|
| 138 | + $db_field_name = $entity == 'provider' ? 'provider_id' : 'accountid'; |
|
| 139 | + $show_seconds = ( ! empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes'; |
|
| 140 | + $currency_info = $this->common->get_currency_info(); |
|
| 141 | + foreach ($query->result_array() as $row1) { |
|
| 142 | + $atmpt = $row1['attempts']; |
|
| 143 | + $cmplt = ($row1['completed'] != 0) ? $row1['completed'] : 0; |
|
| 144 | + $acd = ($row1['completed'] > 0) ? round($row1['billable'] / $row1['completed']) : 0; |
|
| 145 | + $mcd = $row1['mcd']; |
|
| 146 | + if ($show_seconds == 'minutes') { |
|
| 147 | + $avgsec = $acd > 0 ? sprintf('%02d', $acd / 60).":".sprintf('%02d', ($acd % 60)) : "00:00"; |
|
| 148 | + $maxsec = $mcd > 0 ? sprintf('%02d', $mcd / 60).":".sprintf('%02d', ($mcd % 60)) : "00:00"; |
|
| 149 | + $duration = ($row1['duration'] > 0) ? sprintf('%02d', $row1['duration'] / 60).":".sprintf('%02d', ($row1['duration'] % 60)) : "00:00"; |
|
| 150 | + $billsec = ($row1['billable'] > 0) ? sprintf('%02d', $row1['billable'] / 60).":".sprintf('%02d', ($row1['billable'] % 60)) : "00:00"; |
|
| 151 | + } else { |
|
| 152 | + $duration = sprintf('%02d', $row1['duration']); |
|
| 153 | + $avgsec = $acd; |
|
| 154 | + $maxsec = $mcd; |
|
| 155 | + $billsec = sprintf('%02d', $row1['billable']); |
|
| 156 | + } |
|
| 157 | + if ($entity != 'provider') { |
|
| 158 | + $profit = $this->common->calculate_currency_manually($currency_info, $row1['debit'] - $row1['cost'], false); |
|
| 159 | + $debit = $this->common->calculate_currency_manually($currency_info, $row1['debit'], false); |
|
| 160 | + } |
|
| 161 | + $cost = $this->common->calculate_currency_manually($currency_info, $row1['cost'], false); |
|
| 162 | + $asr = ($atmpt > 0) ? (round(($cmplt / $atmpt) * 100, 2)) : '0.00'; |
|
| 163 | + $new_arr = array(); |
|
| 164 | + if ($this->session->userdata('advance_search') == 1) { |
|
| 165 | + if ( ! empty($search_arr['groupby_time'])) { |
|
| 166 | + $time = $row1[$search_arr['groupby_time']]; |
|
| 167 | + if ($search_arr['groupby_time'] == "HOUR" || $search_arr['groupby_time'] == "DAY") { |
|
| 168 | 168 | $time = sprintf('%02d', $time); |
| 169 | - } |
|
| 170 | - if ($search_arr['groupby_time'] == "MONTH") { |
|
| 169 | + } |
|
| 170 | + if ($search_arr['groupby_time'] == "MONTH") { |
|
| 171 | 171 | $dateObj = DateTime::createFromFormat('!m', $time); |
| 172 | 172 | $time = $dateObj->format('F'); |
| 173 | - } |
|
| 174 | - $new_arr[] = $time; |
|
| 175 | - } |
|
| 176 | - if ($search_arr['groupby_1'] == $db_field_name) { |
|
| 177 | - $new_arr[] = $this->common->build_concat_string("first_name,last_name,number", "accounts", $row1[$db_field_name]); |
|
| 178 | - } elseif ($search_arr['groupby_1'] == 'pattern') { |
|
| 179 | - $new_arr[] = filter_var($row1['pattern'], FILTER_SANITIZE_NUMBER_INT); |
|
| 180 | - $new_arr[] = $row1['notes']; |
|
| 181 | - } elseif ($search_arr['groupby_1'] == 'trunk_id') { |
|
| 182 | - $new_arr[] = $this->common->get_field_name('name', 'trunks', $row1['trunk_id']); |
|
| 183 | - } elseif ($search_arr['groupby_1'] == 'package_id') { |
|
| 184 | - $new_arr[] = $this->common->get_field_name('package_name', 'packages', $row1['package_id']); |
|
| 185 | - } |
|
| 173 | + } |
|
| 174 | + $new_arr[] = $time; |
|
| 175 | + } |
|
| 176 | + if ($search_arr['groupby_1'] == $db_field_name) { |
|
| 177 | + $new_arr[] = $this->common->build_concat_string("first_name,last_name,number", "accounts", $row1[$db_field_name]); |
|
| 178 | + } elseif ($search_arr['groupby_1'] == 'pattern') { |
|
| 179 | + $new_arr[] = filter_var($row1['pattern'], FILTER_SANITIZE_NUMBER_INT); |
|
| 180 | + $new_arr[] = $row1['notes']; |
|
| 181 | + } elseif ($search_arr['groupby_1'] == 'trunk_id') { |
|
| 182 | + $new_arr[] = $this->common->get_field_name('name', 'trunks', $row1['trunk_id']); |
|
| 183 | + } elseif ($search_arr['groupby_1'] == 'package_id') { |
|
| 184 | + $new_arr[] = $this->common->get_field_name('package_name', 'packages', $row1['package_id']); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - if ($search_arr['groupby_2'] == $db_field_name) { |
|
| 188 | - $new_arr[] = $this->common->build_concat_string("first_name,last_name,number", "accounts", $row1[$db_field_name]); |
|
| 189 | - } elseif ($search_arr['groupby_2'] == 'pattern') { |
|
| 190 | - $new_arr[] = filter_var($row1['pattern'], FILTER_SANITIZE_NUMBER_INT); |
|
| 191 | - $new_arr[] = $row1['notes']; |
|
| 192 | - } elseif ($search_arr['groupby_2'] == 'trunk_id') { |
|
| 193 | - $new_arr[] = $this->common->get_field_name('name', 'trunks', $row1['trunk_id']); |
|
| 194 | - } elseif ($search_arr['groupby_2'] == 'package_id') { |
|
| 195 | - $new_arr[] = $this->common->get_field_name('package_name', 'packages', $row1['package_id']); |
|
| 196 | - } |
|
| 187 | + if ($search_arr['groupby_2'] == $db_field_name) { |
|
| 188 | + $new_arr[] = $this->common->build_concat_string("first_name,last_name,number", "accounts", $row1[$db_field_name]); |
|
| 189 | + } elseif ($search_arr['groupby_2'] == 'pattern') { |
|
| 190 | + $new_arr[] = filter_var($row1['pattern'], FILTER_SANITIZE_NUMBER_INT); |
|
| 191 | + $new_arr[] = $row1['notes']; |
|
| 192 | + } elseif ($search_arr['groupby_2'] == 'trunk_id') { |
|
| 193 | + $new_arr[] = $this->common->get_field_name('name', 'trunks', $row1['trunk_id']); |
|
| 194 | + } elseif ($search_arr['groupby_2'] == 'package_id') { |
|
| 195 | + $new_arr[] = $this->common->get_field_name('package_name', 'packages', $row1['package_id']); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - if ($search_arr['groupby_3'] == $db_field_name) { |
|
| 199 | - $new_arr[] = $this->common->build_concat_string("first_name,last_name,number", "accounts", $row1[$db_field_name]); |
|
| 200 | - } elseif ($search_arr['groupby_3'] == 'pattern') { |
|
| 201 | - $new_arr[] = filter_var($row1['pattern'], FILTER_SANITIZE_NUMBER_INT); |
|
| 202 | - $new_arr[] = $row1['notes']; |
|
| 203 | - } elseif ($search_arr['groupby_3'] == 'trunk_id') { |
|
| 204 | - $new_arr[] = $this->common->get_field_name('name', 'trunks', $row1['trunk_id']); |
|
| 205 | - } elseif ($search_arr['groupby_3'] == 'package_id') { |
|
| 206 | - $new_arr[] = $this->common->get_field_name('package_name', 'packages', $row1['package_id']); |
|
| 207 | - } |
|
| 208 | - if (empty($new_arr)) { |
|
| 209 | - $new_arr[] = $this->common->build_concat_string("first_name,last_name,number", "accounts", $row1[$db_field_name]); |
|
| 210 | - } |
|
| 211 | - } else { |
|
| 212 | - $new_arr[] = $this->common->build_concat_string("first_name,last_name,number", "accounts", $row1[$db_field_name]); |
|
| 213 | - } |
|
| 214 | - if ($entity != 'provider') { |
|
| 215 | - $custom_array = array( |
|
| 216 | - $atmpt, |
|
| 217 | - $cmplt, |
|
| 218 | - $duration, |
|
| 219 | - round($asr, 2), |
|
| 220 | - $avgsec, |
|
| 221 | - $maxsec, |
|
| 222 | - $billsec, |
|
| 223 | - $debit, |
|
| 224 | - $cost, |
|
| 225 | - $profit); |
|
| 226 | - } else { |
|
| 227 | - $custom_array = array( |
|
| 228 | - $atmpt, |
|
| 229 | - $cmplt, |
|
| 230 | - $duration, |
|
| 231 | - round($asr, 2), |
|
| 232 | - $avgsec, |
|
| 233 | - $maxsec, |
|
| 234 | - $billsec, |
|
| 235 | - $cost |
|
| 236 | - ); |
|
| 237 | - } |
|
| 238 | - $final_array = array_merge($new_arr, $custom_array); |
|
| 239 | - $json_data[] = array('cell' => $final_array); |
|
| 240 | - $export_arr[] = $final_array; |
|
| 241 | - } |
|
| 242 | - $function_name = 'get_'.$entity.'summary_report_list'; |
|
| 243 | - $total_info = $this->summary_model->$function_name(true, '', '', '', $search_arr['select_str'], $search_arr['order_str'], true); |
|
| 244 | - $total_info = $total_info->result_array(); |
|
| 245 | - $total_info = $total_info[0]; |
|
| 246 | - $total_asr = ($total_info['attempts'] > 0) ? round(($total_info['completed'] / $total_info['attempts']) * 100, 2) : 0; |
|
| 247 | - $total_acd = ($total_info['completed'] > 0) ? round($total_info['billable'] / $total_info['completed']) : 0; |
|
| 248 | - if ($show_seconds == 'minutes') { |
|
| 249 | - $total_info['duration'] = $total_info['duration'] > 0 ? sprintf('%02d', $total_info['duration'] / 60).":".sprintf('%02d', ($total_info['duration'] % 60)) : "00:00"; |
|
| 250 | - $total_info['billable'] = $total_info['billable'] > 0 ? sprintf('%02d', $total_info['billable'] / 60).":".sprintf('%02d', ($total_info['billable'] % 60)) : "00:00"; |
|
| 251 | - $total_acd = $total_acd > 0 ? sprintf('%02d', $total_acd / 60).":".sprintf('%02d', ($total_acd % 60)) : "00:00"; |
|
| 252 | - $total_info['mcd'] = $total_info['mcd'] > 0 ? sprintf('%02d', $total_info['mcd'] / 60).":".sprintf('%02d', ($total_info['mcd'] % 60)) : "00:00"; |
|
| 253 | - } |
|
| 254 | - if ($entity != 'provider') { |
|
| 255 | - $total_profit = $this->common->calculate_currency_manually($currency_info, $total_info['debit'] - $total_info['cost'], false); |
|
| 256 | - $total_debit = $this->common->calculate_currency_manually($currency_info, $total_info['debit'], false); |
|
| 257 | - } |
|
| 258 | - $total_cost = $this->common->calculate_currency_manually($currency_info, $total_info['cost'], false); |
|
| 259 | - if ($entity != 'provider') { |
|
| 260 | - $last_array = array( |
|
| 261 | - "<b>".$total_info['attempts']."</b>", |
|
| 262 | - "<b>".$total_info['completed']."</b>", |
|
| 263 | - "<b>".$total_info['duration']."</b>", |
|
| 264 | - "<b>".$total_asr."</b>", |
|
| 198 | + if ($search_arr['groupby_3'] == $db_field_name) { |
|
| 199 | + $new_arr[] = $this->common->build_concat_string("first_name,last_name,number", "accounts", $row1[$db_field_name]); |
|
| 200 | + } elseif ($search_arr['groupby_3'] == 'pattern') { |
|
| 201 | + $new_arr[] = filter_var($row1['pattern'], FILTER_SANITIZE_NUMBER_INT); |
|
| 202 | + $new_arr[] = $row1['notes']; |
|
| 203 | + } elseif ($search_arr['groupby_3'] == 'trunk_id') { |
|
| 204 | + $new_arr[] = $this->common->get_field_name('name', 'trunks', $row1['trunk_id']); |
|
| 205 | + } elseif ($search_arr['groupby_3'] == 'package_id') { |
|
| 206 | + $new_arr[] = $this->common->get_field_name('package_name', 'packages', $row1['package_id']); |
|
| 207 | + } |
|
| 208 | + if (empty($new_arr)) { |
|
| 209 | + $new_arr[] = $this->common->build_concat_string("first_name,last_name,number", "accounts", $row1[$db_field_name]); |
|
| 210 | + } |
|
| 211 | + } else { |
|
| 212 | + $new_arr[] = $this->common->build_concat_string("first_name,last_name,number", "accounts", $row1[$db_field_name]); |
|
| 213 | + } |
|
| 214 | + if ($entity != 'provider') { |
|
| 215 | + $custom_array = array( |
|
| 216 | + $atmpt, |
|
| 217 | + $cmplt, |
|
| 218 | + $duration, |
|
| 219 | + round($asr, 2), |
|
| 220 | + $avgsec, |
|
| 221 | + $maxsec, |
|
| 222 | + $billsec, |
|
| 223 | + $debit, |
|
| 224 | + $cost, |
|
| 225 | + $profit); |
|
| 226 | + } else { |
|
| 227 | + $custom_array = array( |
|
| 228 | + $atmpt, |
|
| 229 | + $cmplt, |
|
| 230 | + $duration, |
|
| 231 | + round($asr, 2), |
|
| 232 | + $avgsec, |
|
| 233 | + $maxsec, |
|
| 234 | + $billsec, |
|
| 235 | + $cost |
|
| 236 | + ); |
|
| 237 | + } |
|
| 238 | + $final_array = array_merge($new_arr, $custom_array); |
|
| 239 | + $json_data[] = array('cell' => $final_array); |
|
| 240 | + $export_arr[] = $final_array; |
|
| 241 | + } |
|
| 242 | + $function_name = 'get_'.$entity.'summary_report_list'; |
|
| 243 | + $total_info = $this->summary_model->$function_name(true, '', '', '', $search_arr['select_str'], $search_arr['order_str'], true); |
|
| 244 | + $total_info = $total_info->result_array(); |
|
| 245 | + $total_info = $total_info[0]; |
|
| 246 | + $total_asr = ($total_info['attempts'] > 0) ? round(($total_info['completed'] / $total_info['attempts']) * 100, 2) : 0; |
|
| 247 | + $total_acd = ($total_info['completed'] > 0) ? round($total_info['billable'] / $total_info['completed']) : 0; |
|
| 248 | + if ($show_seconds == 'minutes') { |
|
| 249 | + $total_info['duration'] = $total_info['duration'] > 0 ? sprintf('%02d', $total_info['duration'] / 60).":".sprintf('%02d', ($total_info['duration'] % 60)) : "00:00"; |
|
| 250 | + $total_info['billable'] = $total_info['billable'] > 0 ? sprintf('%02d', $total_info['billable'] / 60).":".sprintf('%02d', ($total_info['billable'] % 60)) : "00:00"; |
|
| 251 | + $total_acd = $total_acd > 0 ? sprintf('%02d', $total_acd / 60).":".sprintf('%02d', ($total_acd % 60)) : "00:00"; |
|
| 252 | + $total_info['mcd'] = $total_info['mcd'] > 0 ? sprintf('%02d', $total_info['mcd'] / 60).":".sprintf('%02d', ($total_info['mcd'] % 60)) : "00:00"; |
|
| 253 | + } |
|
| 254 | + if ($entity != 'provider') { |
|
| 255 | + $total_profit = $this->common->calculate_currency_manually($currency_info, $total_info['debit'] - $total_info['cost'], false); |
|
| 256 | + $total_debit = $this->common->calculate_currency_manually($currency_info, $total_info['debit'], false); |
|
| 257 | + } |
|
| 258 | + $total_cost = $this->common->calculate_currency_manually($currency_info, $total_info['cost'], false); |
|
| 259 | + if ($entity != 'provider') { |
|
| 260 | + $last_array = array( |
|
| 261 | + "<b>".$total_info['attempts']."</b>", |
|
| 262 | + "<b>".$total_info['completed']."</b>", |
|
| 263 | + "<b>".$total_info['duration']."</b>", |
|
| 264 | + "<b>".$total_asr."</b>", |
|
| 265 | 265 | "<b>".$total_acd."</b>", |
| 266 | 266 | "<b>".$total_info['mcd']."</b>", |
| 267 | 267 | "<b>".$total_info['billable']."</b>", |
| 268 | 268 | "<b>".$total_debit."</b>", |
| 269 | 269 | "<b>".$total_cost."</b>", |
| 270 | 270 | "<b>".$total_profit."</b>" |
| 271 | - ); |
|
| 272 | - } else { |
|
| 273 | - $last_array = array( |
|
| 274 | - "<b>".$total_info['attempts']."</b>", |
|
| 275 | - "<b>".$total_info['completed']."</b>", |
|
| 276 | - "<b>".$total_info['duration']."</b>", |
|
| 277 | - "<b>".$total_asr."</b>", |
|
| 278 | - "<b>".$total_acd."</b>", |
|
| 279 | - "<b>".$total_info['mcd']."</b>", |
|
| 280 | - "<b>".$total_info['billable']."</b>", |
|
| 281 | - "<b>".$total_cost."</b>", |
|
| 282 | - ); |
|
| 283 | - } |
|
| 284 | - if ($purpose == 'export') { |
|
| 285 | - $search_arr['custom_total_array'][0] = "Grand Total"; |
|
| 286 | - } |
|
| 287 | - $new_export_array = array(); |
|
| 288 | - foreach ($last_array as $key=>$value) { |
|
| 271 | + ); |
|
| 272 | + } else { |
|
| 273 | + $last_array = array( |
|
| 274 | + "<b>".$total_info['attempts']."</b>", |
|
| 275 | + "<b>".$total_info['completed']."</b>", |
|
| 276 | + "<b>".$total_info['duration']."</b>", |
|
| 277 | + "<b>".$total_asr."</b>", |
|
| 278 | + "<b>".$total_acd."</b>", |
|
| 279 | + "<b>".$total_info['mcd']."</b>", |
|
| 280 | + "<b>".$total_info['billable']."</b>", |
|
| 281 | + "<b>".$total_cost."</b>", |
|
| 282 | + ); |
|
| 283 | + } |
|
| 284 | + if ($purpose == 'export') { |
|
| 285 | + $search_arr['custom_total_array'][0] = "Grand Total"; |
|
| 286 | + } |
|
| 287 | + $new_export_array = array(); |
|
| 288 | + foreach ($last_array as $key=>$value) { |
|
| 289 | 289 | $value = str_replace("<b>", "", $value); |
| 290 | 290 | $value = str_replace("</b>", '', $value); |
| 291 | 291 | if ($key == 7 || $key == 8 || $key == 9) { |
| 292 | - $value = sprintf("%.".$currency_info['decimalpoints']."f", floatval(preg_replace('/[^\d.]/', '', $value))); |
|
| 292 | + $value = sprintf("%.".$currency_info['decimalpoints']."f", floatval(preg_replace('/[^\d.]/', '', $value))); |
|
| 293 | 293 | } |
| 294 | 294 | $new_export_array[$key] = $value; |
| 295 | - } |
|
| 296 | - $total_array = array_merge($search_arr['custom_total_array'], $last_array); |
|
| 297 | - $custom_export_arr = array_merge($search_arr['custom_total_array'], $new_export_array); |
|
| 298 | - $export_arr[] = $custom_export_arr; |
|
| 299 | - $json_data[] = array('cell' => $total_array); |
|
| 300 | - return $purpose == 'grid' ? $json_data : $export_arr; |
|
| 301 | - } |
|
| 295 | + } |
|
| 296 | + $total_array = array_merge($search_arr['custom_total_array'], $last_array); |
|
| 297 | + $custom_export_arr = array_merge($search_arr['custom_total_array'], $new_export_array); |
|
| 298 | + $export_arr[] = $custom_export_arr; |
|
| 299 | + $json_data[] = array('cell' => $total_array); |
|
| 300 | + return $purpose == 'grid' ? $json_data : $export_arr; |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - function customer_export_csv() { |
|
| 303 | + function customer_export_csv() { |
|
| 304 | 304 | $account_info = $accountinfo = $this->session->userdata('accountinfo'); |
| 305 | 305 | $currency_id = $account_info['currency_id']; |
| 306 | 306 | $currency = $this->common->get_field_name('currency', 'currency', $currency_id); |
| 307 | - $search_arr = $this->session->userdata('customersummary_reports_export'); |
|
| 308 | - $data_arr = array(); |
|
| 309 | - $query = $this->summary_model->get_customersummary_report_list(true, '', '', $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], true); |
|
| 310 | - $search_header = explode(",", $search_arr['export_str']); |
|
| 311 | - ob_clean(); |
|
| 312 | - $fixed_header = array('Attempted Calls', 'Completed Calls', 'Duration', 'ASR', 'ACD', 'MCD', 'Billable', 'Debit('.$currency.')', 'Cost('.$currency.')', 'Profit'); |
|
| 313 | - $header_arr[] = array_merge($search_header, $fixed_header); |
|
| 314 | - if ($query->num_rows() > 0) { |
|
| 315 | - $data_arr = $this->summary_report_grid($search_arr, $query, 'customer', 'export'); |
|
| 316 | - } |
|
| 317 | - $customer_array = array_merge($header_arr, $data_arr); |
|
| 307 | + $search_arr = $this->session->userdata('customersummary_reports_export'); |
|
| 308 | + $data_arr = array(); |
|
| 309 | + $query = $this->summary_model->get_customersummary_report_list(true, '', '', $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], true); |
|
| 310 | + $search_header = explode(",", $search_arr['export_str']); |
|
| 311 | + ob_clean(); |
|
| 312 | + $fixed_header = array('Attempted Calls', 'Completed Calls', 'Duration', 'ASR', 'ACD', 'MCD', 'Billable', 'Debit('.$currency.')', 'Cost('.$currency.')', 'Profit'); |
|
| 313 | + $header_arr[] = array_merge($search_header, $fixed_header); |
|
| 314 | + if ($query->num_rows() > 0) { |
|
| 315 | + $data_arr = $this->summary_report_grid($search_arr, $query, 'customer', 'export'); |
|
| 316 | + } |
|
| 317 | + $customer_array = array_merge($header_arr, $data_arr); |
|
| 318 | 318 | |
| 319 | - $this->load->helper('csv'); |
|
| 320 | - array_to_csv($customer_array, 'Customer_Summary_Report_'.date("Y-m-d").'.csv'); |
|
| 321 | - } |
|
| 319 | + $this->load->helper('csv'); |
|
| 320 | + array_to_csv($customer_array, 'Customer_Summary_Report_'.date("Y-m-d").'.csv'); |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - function customer_search() { |
|
| 324 | - if ($this->input->post('advance_search', TRUE) == 1) { |
|
| 325 | - $this->session->set_userdata('advance_search', $this->input->post('advance_search')); |
|
| 326 | - unset($_POST['action']); |
|
| 327 | - unset($_POST['advance_search']); |
|
| 328 | - $this->session->set_userdata('customersummary_reports_search', $this->input->post()); |
|
| 329 | - } |
|
| 330 | - redirect(base_url() . 'summary/customer/'); |
|
| 331 | - } |
|
| 323 | + function customer_search() { |
|
| 324 | + if ($this->input->post('advance_search', TRUE) == 1) { |
|
| 325 | + $this->session->set_userdata('advance_search', $this->input->post('advance_search')); |
|
| 326 | + unset($_POST['action']); |
|
| 327 | + unset($_POST['advance_search']); |
|
| 328 | + $this->session->set_userdata('customersummary_reports_search', $this->input->post()); |
|
| 329 | + } |
|
| 330 | + redirect(base_url() . 'summary/customer/'); |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | - function customer_clearsearchfilter() { |
|
| 334 | - $this->session->set_userdata('advance_search', 0); |
|
| 335 | - $this->session->set_userdata('customersummary_reports_search', ""); |
|
| 336 | - $this->session->set_userdata('customersummary_reports_export', ""); |
|
| 337 | - redirect(base_url() . 'summary/customer/'); |
|
| 338 | - } |
|
| 333 | + function customer_clearsearchfilter() { |
|
| 334 | + $this->session->set_userdata('advance_search', 0); |
|
| 335 | + $this->session->set_userdata('customersummary_reports_search', ""); |
|
| 336 | + $this->session->set_userdata('customersummary_reports_export', ""); |
|
| 337 | + redirect(base_url() . 'summary/customer/'); |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | - /** |
|
| 341 | - * @param string $entity |
|
| 342 | - */ |
|
| 343 | - function summary_search_info($entity) { |
|
| 344 | - $group_by_str = null; |
|
| 345 | - $select_str = null; |
|
| 346 | - $group_by_time=null; |
|
| 347 | - $group_by_1 = null; |
|
| 348 | - $group_by_2 = null; |
|
| 349 | - $group_by_3 = null; |
|
| 350 | - $order_str=null; |
|
| 351 | - $custom_total_array = array(); |
|
| 352 | - $custom_search = array(); |
|
| 353 | - $export_select_str = null; |
|
| 354 | - $new_arr['search_in'] = 'minutes'; |
|
| 355 | - $i = 0; |
|
| 356 | - $db_field_name = $entity == 'provider' ? 'provider_id' : 'accountid'; |
|
| 357 | - if ($this->session->userdata('advance_search') == 1) { |
|
| 358 | - $custom_search = $this->session->userdata($entity.'summary_reports_search'); |
|
| 359 | - if (isset($custom_search['time']) && ! empty($custom_search['time'])) { |
|
| 360 | - $group_by_str .= $custom_search['time']."(callstart),"; |
|
| 361 | - $select_str .= $custom_search['time']."(callstart) as ".$custom_search['time'].","; |
|
| 362 | - $order_str .= $custom_search['time'].","; |
|
| 363 | - $group_by_time = $custom_search['time']; |
|
| 364 | - $export_select_str .= $custom_search['time'].","; |
|
| 365 | - $custom_total_array[$i] = null; |
|
| 366 | - $i++; |
|
| 367 | - } |
|
| 368 | - if (isset($custom_search['groupby_1']) && ! empty($custom_search['groupby_1'])) { |
|
| 369 | - $group_by_str .= $custom_search['groupby_1'].","; |
|
| 370 | - $select_str .= $custom_search['groupby_1'].","; |
|
| 371 | - $order_str .= $custom_search['groupby_1'].","; |
|
| 372 | - $group_by_1 = $custom_search['groupby_1']; |
|
| 373 | - if ($custom_search['groupby_1'] == $db_field_name) { |
|
| 374 | - $export_select_str .= 'Account,'; |
|
| 375 | - } elseif ($custom_search['groupby_1'] == 'trunk_id') { |
|
| 376 | - $export_select_str .= 'Trunk,'; |
|
| 377 | - } elseif ($custom_search['groupby_1'] == 'pattern') { |
|
| 378 | - $select_str .= 'notes,'; |
|
| 379 | - $order_str .= 'notes,'; |
|
| 380 | - $export_select_str .= "Code,Destination,"; |
|
| 381 | - $custom_total_array[$i] = null; |
|
| 382 | - $i++; |
|
| 383 | - } elseif ($custom_search['groupby_1'] == 'package_id') { |
|
| 384 | - $export_select_str .= 'Package,'; |
|
| 385 | - } |
|
| 386 | - $custom_total_array[$i] = null; |
|
| 387 | - $i++; |
|
| 388 | - } |
|
| 340 | + /** |
|
| 341 | + * @param string $entity |
|
| 342 | + */ |
|
| 343 | + function summary_search_info($entity) { |
|
| 344 | + $group_by_str = null; |
|
| 345 | + $select_str = null; |
|
| 346 | + $group_by_time=null; |
|
| 347 | + $group_by_1 = null; |
|
| 348 | + $group_by_2 = null; |
|
| 349 | + $group_by_3 = null; |
|
| 350 | + $order_str=null; |
|
| 351 | + $custom_total_array = array(); |
|
| 352 | + $custom_search = array(); |
|
| 353 | + $export_select_str = null; |
|
| 354 | + $new_arr['search_in'] = 'minutes'; |
|
| 355 | + $i = 0; |
|
| 356 | + $db_field_name = $entity == 'provider' ? 'provider_id' : 'accountid'; |
|
| 357 | + if ($this->session->userdata('advance_search') == 1) { |
|
| 358 | + $custom_search = $this->session->userdata($entity.'summary_reports_search'); |
|
| 359 | + if (isset($custom_search['time']) && ! empty($custom_search['time'])) { |
|
| 360 | + $group_by_str .= $custom_search['time']."(callstart),"; |
|
| 361 | + $select_str .= $custom_search['time']."(callstart) as ".$custom_search['time'].","; |
|
| 362 | + $order_str .= $custom_search['time'].","; |
|
| 363 | + $group_by_time = $custom_search['time']; |
|
| 364 | + $export_select_str .= $custom_search['time'].","; |
|
| 365 | + $custom_total_array[$i] = null; |
|
| 366 | + $i++; |
|
| 367 | + } |
|
| 368 | + if (isset($custom_search['groupby_1']) && ! empty($custom_search['groupby_1'])) { |
|
| 369 | + $group_by_str .= $custom_search['groupby_1'].","; |
|
| 370 | + $select_str .= $custom_search['groupby_1'].","; |
|
| 371 | + $order_str .= $custom_search['groupby_1'].","; |
|
| 372 | + $group_by_1 = $custom_search['groupby_1']; |
|
| 373 | + if ($custom_search['groupby_1'] == $db_field_name) { |
|
| 374 | + $export_select_str .= 'Account,'; |
|
| 375 | + } elseif ($custom_search['groupby_1'] == 'trunk_id') { |
|
| 376 | + $export_select_str .= 'Trunk,'; |
|
| 377 | + } elseif ($custom_search['groupby_1'] == 'pattern') { |
|
| 378 | + $select_str .= 'notes,'; |
|
| 379 | + $order_str .= 'notes,'; |
|
| 380 | + $export_select_str .= "Code,Destination,"; |
|
| 381 | + $custom_total_array[$i] = null; |
|
| 382 | + $i++; |
|
| 383 | + } elseif ($custom_search['groupby_1'] == 'package_id') { |
|
| 384 | + $export_select_str .= 'Package,'; |
|
| 385 | + } |
|
| 386 | + $custom_total_array[$i] = null; |
|
| 387 | + $i++; |
|
| 388 | + } |
|
| 389 | 389 | |
| 390 | - if (isset($custom_search['groupby_2']) && ! empty($custom_search['groupby_2'])) { |
|
| 391 | - $group_by_str .= $custom_search['groupby_2'].","; |
|
| 392 | - $select_str .= $custom_search['groupby_2'].","; |
|
| 393 | - $order_str .= $custom_search['groupby_2'].","; |
|
| 394 | - $group_by_2 = $custom_search['groupby_2']; |
|
| 395 | - if ($custom_search['groupby_2'] == $db_field_name) { |
|
| 396 | - $export_select_str .= 'Account,'; |
|
| 397 | - } elseif ($custom_search['groupby_2'] == 'trunk_id') { |
|
| 398 | - $export_select_str .= 'Trunk,'; |
|
| 399 | - } elseif ($custom_search['groupby_2'] == 'pattern') { |
|
| 400 | - $select_str .= 'notes,'; |
|
| 401 | - $order_str .= 'notes,'; |
|
| 402 | - $export_select_str .= "Code,Destination,"; |
|
| 403 | - $custom_total_array[$i] = null; |
|
| 404 | - $i++; |
|
| 405 | - } elseif ($custom_search['groupby_2'] == 'package_id') { |
|
| 406 | - $export_select_str .= 'Package,'; |
|
| 407 | - } |
|
| 408 | - $custom_total_array[$i] = null; |
|
| 409 | - $i++; |
|
| 410 | - } |
|
| 390 | + if (isset($custom_search['groupby_2']) && ! empty($custom_search['groupby_2'])) { |
|
| 391 | + $group_by_str .= $custom_search['groupby_2'].","; |
|
| 392 | + $select_str .= $custom_search['groupby_2'].","; |
|
| 393 | + $order_str .= $custom_search['groupby_2'].","; |
|
| 394 | + $group_by_2 = $custom_search['groupby_2']; |
|
| 395 | + if ($custom_search['groupby_2'] == $db_field_name) { |
|
| 396 | + $export_select_str .= 'Account,'; |
|
| 397 | + } elseif ($custom_search['groupby_2'] == 'trunk_id') { |
|
| 398 | + $export_select_str .= 'Trunk,'; |
|
| 399 | + } elseif ($custom_search['groupby_2'] == 'pattern') { |
|
| 400 | + $select_str .= 'notes,'; |
|
| 401 | + $order_str .= 'notes,'; |
|
| 402 | + $export_select_str .= "Code,Destination,"; |
|
| 403 | + $custom_total_array[$i] = null; |
|
| 404 | + $i++; |
|
| 405 | + } elseif ($custom_search['groupby_2'] == 'package_id') { |
|
| 406 | + $export_select_str .= 'Package,'; |
|
| 407 | + } |
|
| 408 | + $custom_total_array[$i] = null; |
|
| 409 | + $i++; |
|
| 410 | + } |
|
| 411 | 411 | |
| 412 | - if (isset($custom_search['groupby_3']) && ! empty($custom_search['groupby_3'])) { |
|
| 413 | - $group_by_str .= $custom_search['groupby_3'].","; |
|
| 414 | - $select_str .= $custom_search['groupby_3'].","; |
|
| 415 | - $order_str .= $custom_search['groupby_3'].","; |
|
| 416 | - $group_by_3 = $custom_search['groupby_3']; |
|
| 417 | - if ($custom_search['groupby_3'] == 'accountid' || $custom_search['groupby_3'] == 'provider_id') { |
|
| 418 | - $export_select_str .= 'Account,'; |
|
| 419 | - } elseif ($custom_search['groupby_3'] == 'trunk_id') { |
|
| 420 | - $export_select_str .= 'Trunk,'; |
|
| 421 | - } elseif ($custom_search['groupby_3'] == 'pattern') { |
|
| 422 | - $select_str .= 'notes,'; |
|
| 423 | - $order_str .= 'notes,'; |
|
| 424 | - $export_select_str .= "Code,Destination,"; |
|
| 425 | - $custom_total_array[$i] = null; |
|
| 426 | - $i++; |
|
| 427 | - } elseif ($custom_search['groupby_3'] == 'package_id') { |
|
| 428 | - $export_select_str .= 'Package,'; |
|
| 429 | - } |
|
| 430 | - $custom_total_array[$i] = null; |
|
| 431 | - $i++; |
|
| 432 | - } |
|
| 433 | - $new_arr['search_in'] = (isset($custom_search['search_in']) && ! empty($custom_search['search_in'])) ? $custom_search['search_in'] : 'minutes'; |
|
| 434 | - unset($custom_search['groupby_1'], $custom_search['groupby_2'], $custom_search['groupby_3'], $custom_search['search_in']); |
|
| 435 | - $this->session->set_userdata('summary_'.$entity.'_search', $custom_search); |
|
| 436 | - } |
|
| 437 | - if ( ! empty($group_by_str)) { |
|
| 438 | - $group_by_str = rtrim($group_by_str, ","); |
|
| 439 | - $select_str = rtrim($select_str, ","); |
|
| 440 | - $order_str = rtrim($order_str, ","); |
|
| 441 | - $export_select_str = rtrim($export_select_str, ","); |
|
| 442 | - } else { |
|
| 443 | - $select_str = $db_field_name; |
|
| 444 | - $order_str = $db_field_name; |
|
| 445 | - $group_by_str = $db_field_name; |
|
| 446 | - $export_select_str = "Account"; |
|
| 447 | - } |
|
| 412 | + if (isset($custom_search['groupby_3']) && ! empty($custom_search['groupby_3'])) { |
|
| 413 | + $group_by_str .= $custom_search['groupby_3'].","; |
|
| 414 | + $select_str .= $custom_search['groupby_3'].","; |
|
| 415 | + $order_str .= $custom_search['groupby_3'].","; |
|
| 416 | + $group_by_3 = $custom_search['groupby_3']; |
|
| 417 | + if ($custom_search['groupby_3'] == 'accountid' || $custom_search['groupby_3'] == 'provider_id') { |
|
| 418 | + $export_select_str .= 'Account,'; |
|
| 419 | + } elseif ($custom_search['groupby_3'] == 'trunk_id') { |
|
| 420 | + $export_select_str .= 'Trunk,'; |
|
| 421 | + } elseif ($custom_search['groupby_3'] == 'pattern') { |
|
| 422 | + $select_str .= 'notes,'; |
|
| 423 | + $order_str .= 'notes,'; |
|
| 424 | + $export_select_str .= "Code,Destination,"; |
|
| 425 | + $custom_total_array[$i] = null; |
|
| 426 | + $i++; |
|
| 427 | + } elseif ($custom_search['groupby_3'] == 'package_id') { |
|
| 428 | + $export_select_str .= 'Package,'; |
|
| 429 | + } |
|
| 430 | + $custom_total_array[$i] = null; |
|
| 431 | + $i++; |
|
| 432 | + } |
|
| 433 | + $new_arr['search_in'] = (isset($custom_search['search_in']) && ! empty($custom_search['search_in'])) ? $custom_search['search_in'] : 'minutes'; |
|
| 434 | + unset($custom_search['groupby_1'], $custom_search['groupby_2'], $custom_search['groupby_3'], $custom_search['search_in']); |
|
| 435 | + $this->session->set_userdata('summary_'.$entity.'_search', $custom_search); |
|
| 436 | + } |
|
| 437 | + if ( ! empty($group_by_str)) { |
|
| 438 | + $group_by_str = rtrim($group_by_str, ","); |
|
| 439 | + $select_str = rtrim($select_str, ","); |
|
| 440 | + $order_str = rtrim($order_str, ","); |
|
| 441 | + $export_select_str = rtrim($export_select_str, ","); |
|
| 442 | + } else { |
|
| 443 | + $select_str = $db_field_name; |
|
| 444 | + $order_str = $db_field_name; |
|
| 445 | + $group_by_str = $db_field_name; |
|
| 446 | + $export_select_str = "Account"; |
|
| 447 | + } |
|
| 448 | 448 | |
| 449 | - array_pop($custom_total_array); |
|
| 450 | - array_unshift($custom_total_array, '<b>Grand Total</b>'); |
|
| 451 | - $new_arr['export_str'] = $export_select_str; |
|
| 452 | - $new_arr['select_str'] = $select_str; |
|
| 453 | - $new_arr['order_str'] = $order_str; |
|
| 454 | - $new_arr['group_by_str'] = $group_by_str; |
|
| 455 | - $new_arr['groupby_1'] = $group_by_1; |
|
| 456 | - $new_arr['groupby_2'] = $group_by_2; |
|
| 457 | - $new_arr['groupby_3'] = $group_by_3; |
|
| 458 | - $new_arr['groupby_time'] = $group_by_time; |
|
| 459 | - $new_arr['custom_total_array'] = $custom_total_array; |
|
| 460 | - return $new_arr; |
|
| 461 | - } |
|
| 449 | + array_pop($custom_total_array); |
|
| 450 | + array_unshift($custom_total_array, '<b>Grand Total</b>'); |
|
| 451 | + $new_arr['export_str'] = $export_select_str; |
|
| 452 | + $new_arr['select_str'] = $select_str; |
|
| 453 | + $new_arr['order_str'] = $order_str; |
|
| 454 | + $new_arr['group_by_str'] = $group_by_str; |
|
| 455 | + $new_arr['groupby_1'] = $group_by_1; |
|
| 456 | + $new_arr['groupby_2'] = $group_by_2; |
|
| 457 | + $new_arr['groupby_3'] = $group_by_3; |
|
| 458 | + $new_arr['groupby_time'] = $group_by_time; |
|
| 459 | + $new_arr['custom_total_array'] = $custom_total_array; |
|
| 460 | + return $new_arr; |
|
| 461 | + } |
|
| 462 | 462 | |
| 463 | - function provider() { |
|
| 464 | - $data['page_title'] = 'Provider Summary Report'; |
|
| 465 | - $data['search_flag'] = true; |
|
| 466 | - $session_info = $this->session->userdata('providersummary_reports_search'); |
|
| 467 | - $accountlist = $this->db_model->build_dropdown_deleted('id,IF(`deleted`=1,concat( first_name, " ", last_name, " ", "(", number, ")^" ),concat( first_name, " ", last_name, " ", "(", number, ")" )) as number', 'accounts', 'where_arr', array("type" => "3")); |
|
| 468 | - $trunklist = $this->db_model->build_dropdown('id,name', 'trunks', '', array()); |
|
| 469 | - $data['trunklist'] = $trunklist; |
|
| 470 | - $data['accountlist'] = $accountlist; |
|
| 471 | - $data['session_info'] = $session_info; |
|
| 472 | - $data['seconds'] = $this->session->userdata('provider_seconds'); |
|
| 473 | - $data['search_report'] = $this->common->search_report_in(); |
|
| 474 | - $data['grid_fields'] = $this->summary_form->build_providersummary(); |
|
| 475 | - $data["grid_buttons"] = $this->summary_form->build_grid_buttons_providersummary(); |
|
| 476 | - $data['search_string_type'] = $this->common->search_string_type(); |
|
| 477 | - $data['groupby_field'] = $this->common->set_summaryprovider_groupby(); |
|
| 478 | - $data['groupby_time'] = $this->common->group_by_time(); |
|
| 479 | - $this->load->view('view_providersummary_report', $data); |
|
| 480 | - } |
|
| 463 | + function provider() { |
|
| 464 | + $data['page_title'] = 'Provider Summary Report'; |
|
| 465 | + $data['search_flag'] = true; |
|
| 466 | + $session_info = $this->session->userdata('providersummary_reports_search'); |
|
| 467 | + $accountlist = $this->db_model->build_dropdown_deleted('id,IF(`deleted`=1,concat( first_name, " ", last_name, " ", "(", number, ")^" ),concat( first_name, " ", last_name, " ", "(", number, ")" )) as number', 'accounts', 'where_arr', array("type" => "3")); |
|
| 468 | + $trunklist = $this->db_model->build_dropdown('id,name', 'trunks', '', array()); |
|
| 469 | + $data['trunklist'] = $trunklist; |
|
| 470 | + $data['accountlist'] = $accountlist; |
|
| 471 | + $data['session_info'] = $session_info; |
|
| 472 | + $data['seconds'] = $this->session->userdata('provider_seconds'); |
|
| 473 | + $data['search_report'] = $this->common->search_report_in(); |
|
| 474 | + $data['grid_fields'] = $this->summary_form->build_providersummary(); |
|
| 475 | + $data["grid_buttons"] = $this->summary_form->build_grid_buttons_providersummary(); |
|
| 476 | + $data['search_string_type'] = $this->common->search_string_type(); |
|
| 477 | + $data['groupby_field'] = $this->common->set_summaryprovider_groupby(); |
|
| 478 | + $data['groupby_time'] = $this->common->group_by_time(); |
|
| 479 | + $this->load->view('view_providersummary_report', $data); |
|
| 480 | + } |
|
| 481 | 481 | |
| 482 | - function provider_json() { |
|
| 483 | - $search_arr = $this->summary_search_info('provider'); |
|
| 484 | - $count_all = $this->summary_model->get_providersummary_report_list(false, '', '', $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], false); |
|
| 485 | - $paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
|
| 486 | - $json_data = $paging_data["json_paging"]; |
|
| 487 | - $query = $this->summary_model->get_providersummary_report_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"], $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], false); |
|
| 488 | - if ($query->num_rows() > 0) { |
|
| 489 | - $json_data['rows'] = $this->summary_report_grid($search_arr, $query, 'provider', 'grid'); |
|
| 490 | - } |
|
| 491 | - $this->session->set_userdata('providersummary_reports_export', $search_arr); |
|
| 492 | - echo json_encode($json_data); |
|
| 493 | - } |
|
| 482 | + function provider_json() { |
|
| 483 | + $search_arr = $this->summary_search_info('provider'); |
|
| 484 | + $count_all = $this->summary_model->get_providersummary_report_list(false, '', '', $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], false); |
|
| 485 | + $paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
|
| 486 | + $json_data = $paging_data["json_paging"]; |
|
| 487 | + $query = $this->summary_model->get_providersummary_report_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"], $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], false); |
|
| 488 | + if ($query->num_rows() > 0) { |
|
| 489 | + $json_data['rows'] = $this->summary_report_grid($search_arr, $query, 'provider', 'grid'); |
|
| 490 | + } |
|
| 491 | + $this->session->set_userdata('providersummary_reports_export', $search_arr); |
|
| 492 | + echo json_encode($json_data); |
|
| 493 | + } |
|
| 494 | 494 | |
| 495 | - function provider_export_csv() { |
|
| 495 | + function provider_export_csv() { |
|
| 496 | 496 | $account_info = $accountinfo = $this->session->userdata('accountinfo'); |
| 497 | 497 | $currency_id = $account_info['currency_id']; |
| 498 | 498 | $currency = $this->common->get_field_name('currency', 'currency', $currency_id); |
| 499 | - $search_arr = $this->session->userdata('providersummary_reports_export'); |
|
| 500 | - $data_arr = array(); |
|
| 501 | - $query = $this->summary_model->get_providersummary_report_list(true, '', '', $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], true); |
|
| 502 | - $search_header = explode(",", $search_arr['export_str']); |
|
| 503 | - ob_clean(); |
|
| 504 | - $fixed_header = array("Attempted Calls", "Completed Calls", "Duration", "ASR", "ACD", "MCD", "Billable", "Cost($currency)"); |
|
| 505 | - $header_arr[] = array_merge($search_header, $fixed_header); |
|
| 506 | - if ($query->num_rows() > 0) { |
|
| 507 | - $data_arr = $this->summary_report_grid($search_arr, $query, 'provider', 'export'); |
|
| 508 | - } |
|
| 509 | - $provider_array = array_merge($header_arr, $data_arr); |
|
| 499 | + $search_arr = $this->session->userdata('providersummary_reports_export'); |
|
| 500 | + $data_arr = array(); |
|
| 501 | + $query = $this->summary_model->get_providersummary_report_list(true, '', '', $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], true); |
|
| 502 | + $search_header = explode(",", $search_arr['export_str']); |
|
| 503 | + ob_clean(); |
|
| 504 | + $fixed_header = array("Attempted Calls", "Completed Calls", "Duration", "ASR", "ACD", "MCD", "Billable", "Cost($currency)"); |
|
| 505 | + $header_arr[] = array_merge($search_header, $fixed_header); |
|
| 506 | + if ($query->num_rows() > 0) { |
|
| 507 | + $data_arr = $this->summary_report_grid($search_arr, $query, 'provider', 'export'); |
|
| 508 | + } |
|
| 509 | + $provider_array = array_merge($header_arr, $data_arr); |
|
| 510 | 510 | |
| 511 | - $this->load->helper('csv'); |
|
| 512 | - array_to_csv($provider_array, 'Provider_Summary_Report_'.date("Y-m-d").'.csv'); |
|
| 513 | - } |
|
| 511 | + $this->load->helper('csv'); |
|
| 512 | + array_to_csv($provider_array, 'Provider_Summary_Report_'.date("Y-m-d").'.csv'); |
|
| 513 | + } |
|
| 514 | 514 | |
| 515 | - function provider_search() { |
|
| 516 | - if ($this->input->post('advance_search', TRUE) == 1) { |
|
| 517 | - $this->session->set_userdata('advance_search', $this->input->post('advance_search')); |
|
| 518 | - unset($_POST['action'], $_POST['advance_search']); |
|
| 519 | - $this->session->set_userdata('providersummary_reports_search', $this->input->post()); |
|
| 520 | - } |
|
| 521 | - redirect(base_url().'summary/provider/'); |
|
| 522 | - } |
|
| 515 | + function provider_search() { |
|
| 516 | + if ($this->input->post('advance_search', TRUE) == 1) { |
|
| 517 | + $this->session->set_userdata('advance_search', $this->input->post('advance_search')); |
|
| 518 | + unset($_POST['action'], $_POST['advance_search']); |
|
| 519 | + $this->session->set_userdata('providersummary_reports_search', $this->input->post()); |
|
| 520 | + } |
|
| 521 | + redirect(base_url().'summary/provider/'); |
|
| 522 | + } |
|
| 523 | 523 | |
| 524 | - function provider_clearsearchfilter() { |
|
| 525 | - $this->session->set_userdata('advance_search', 0); |
|
| 526 | - $this->session->set_userdata('providersummary_reports_search', ""); |
|
| 527 | - $this->session->set_userdata('providersummary_reports_export', ""); |
|
| 528 | - redirect(base_url()."summary/provider/"); |
|
| 529 | - } |
|
| 524 | + function provider_clearsearchfilter() { |
|
| 525 | + $this->session->set_userdata('advance_search', 0); |
|
| 526 | + $this->session->set_userdata('providersummary_reports_search', ""); |
|
| 527 | + $this->session->set_userdata('providersummary_reports_export', ""); |
|
| 528 | + redirect(base_url()."summary/provider/"); |
|
| 529 | + } |
|
| 530 | 530 | |
| 531 | - function reseller() { |
|
| 532 | - $data['username'] = $this->session->userdata('user_name'); |
|
| 533 | - $data['page_title'] = 'Reseller Summary Report'; |
|
| 534 | - $data['search_flag'] = true; |
|
| 535 | - $session_info = $this->session->userdata('resellersummary_reports_search'); |
|
| 536 | - $accountinfo = $this->session->userdata('accountinfo'); |
|
| 537 | - $reseller_id = $accountinfo['type'] == 1 ? $accountinfo['id'] : 0; |
|
| 538 | - $accountlist = $this->db_model->build_dropdown_deleted('id,IF(`deleted`=1,concat( first_name, " ", last_name, " ", "(", number, ")^" ),concat( first_name, " ", last_name, " ", "(", number, ")" )) as number', 'accounts', 'where_arr', array('reseller_id' => $reseller_id, "type" => "1")); |
|
| 539 | - $data['accountlist'] = $accountlist; |
|
| 540 | - $data['seconds'] = $this->session->userdata('reseller_seconds'); |
|
| 541 | - $data['session_info'] = $session_info; |
|
| 542 | - $data['search_report'] = $this->common->search_report_in(); |
|
| 543 | - $data['search_string_type'] = $this->common->search_string_type(); |
|
| 544 | - $new_column_arr = $this->summary_column_arr('reseller'); |
|
| 545 | - $data['grid_fields'] = $this->summary_form->build_resellersummary($new_column_arr); |
|
| 546 | - $data["grid_buttons"] = $this->summary_form->build_grid_buttons_resellersummary(); |
|
| 547 | - $data['groupby_field'] = $this->common->set_summarycustomer_groupby(); |
|
| 548 | - $data['groupby_time'] = $this->common->group_by_time(); |
|
| 549 | - $this->load->view('view_resellersummary_report', $data); |
|
| 550 | - } |
|
| 531 | + function reseller() { |
|
| 532 | + $data['username'] = $this->session->userdata('user_name'); |
|
| 533 | + $data['page_title'] = 'Reseller Summary Report'; |
|
| 534 | + $data['search_flag'] = true; |
|
| 535 | + $session_info = $this->session->userdata('resellersummary_reports_search'); |
|
| 536 | + $accountinfo = $this->session->userdata('accountinfo'); |
|
| 537 | + $reseller_id = $accountinfo['type'] == 1 ? $accountinfo['id'] : 0; |
|
| 538 | + $accountlist = $this->db_model->build_dropdown_deleted('id,IF(`deleted`=1,concat( first_name, " ", last_name, " ", "(", number, ")^" ),concat( first_name, " ", last_name, " ", "(", number, ")" )) as number', 'accounts', 'where_arr', array('reseller_id' => $reseller_id, "type" => "1")); |
|
| 539 | + $data['accountlist'] = $accountlist; |
|
| 540 | + $data['seconds'] = $this->session->userdata('reseller_seconds'); |
|
| 541 | + $data['session_info'] = $session_info; |
|
| 542 | + $data['search_report'] = $this->common->search_report_in(); |
|
| 543 | + $data['search_string_type'] = $this->common->search_string_type(); |
|
| 544 | + $new_column_arr = $this->summary_column_arr('reseller'); |
|
| 545 | + $data['grid_fields'] = $this->summary_form->build_resellersummary($new_column_arr); |
|
| 546 | + $data["grid_buttons"] = $this->summary_form->build_grid_buttons_resellersummary(); |
|
| 547 | + $data['groupby_field'] = $this->common->set_summarycustomer_groupby(); |
|
| 548 | + $data['groupby_time'] = $this->common->group_by_time(); |
|
| 549 | + $this->load->view('view_resellersummary_report', $data); |
|
| 550 | + } |
|
| 551 | 551 | |
| 552 | - function reseller_json() { |
|
| 553 | - $search_arr = $this->summary_search_info('reseller'); |
|
| 554 | - $count_all = $this->summary_model->get_resellersummary_report_list(false, 0, 0, $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], false); |
|
| 555 | - $paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
|
| 556 | - $json_data = $paging_data["json_paging"]; |
|
| 557 | - $query = $this->summary_model->get_resellersummary_report_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"], $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], false); |
|
| 558 | - if ($query->num_rows() > 0) { |
|
| 559 | - $json_data['rows'] = $this->summary_report_grid($search_arr, $query, 'reseller', 'grid'); |
|
| 560 | - } |
|
| 561 | - $this->session->set_userdata('resellersummary_reports_export', $search_arr); |
|
| 562 | - echo json_encode($json_data); |
|
| 563 | - } |
|
| 552 | + function reseller_json() { |
|
| 553 | + $search_arr = $this->summary_search_info('reseller'); |
|
| 554 | + $count_all = $this->summary_model->get_resellersummary_report_list(false, 0, 0, $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], false); |
|
| 555 | + $paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
|
| 556 | + $json_data = $paging_data["json_paging"]; |
|
| 557 | + $query = $this->summary_model->get_resellersummary_report_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"], $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], false); |
|
| 558 | + if ($query->num_rows() > 0) { |
|
| 559 | + $json_data['rows'] = $this->summary_report_grid($search_arr, $query, 'reseller', 'grid'); |
|
| 560 | + } |
|
| 561 | + $this->session->set_userdata('resellersummary_reports_export', $search_arr); |
|
| 562 | + echo json_encode($json_data); |
|
| 563 | + } |
|
| 564 | 564 | |
| 565 | - function reseller_search() { |
|
| 566 | - if ($this->input->post('advance_search', TRUE) == 1) { |
|
| 567 | - $this->session->set_userdata('advance_search', $this->input->post('advance_search')); |
|
| 568 | - unset($_POST['action'], $_POST['advance_search']); |
|
| 569 | - $this->session->set_userdata('resellersummary_reports_search', $this->input->post()); |
|
| 570 | - } |
|
| 571 | - redirect(base_url()."summary/reseller/"); |
|
| 572 | - } |
|
| 565 | + function reseller_search() { |
|
| 566 | + if ($this->input->post('advance_search', TRUE) == 1) { |
|
| 567 | + $this->session->set_userdata('advance_search', $this->input->post('advance_search')); |
|
| 568 | + unset($_POST['action'], $_POST['advance_search']); |
|
| 569 | + $this->session->set_userdata('resellersummary_reports_search', $this->input->post()); |
|
| 570 | + } |
|
| 571 | + redirect(base_url()."summary/reseller/"); |
|
| 572 | + } |
|
| 573 | 573 | |
| 574 | - function reseller_clearsearchfilter() { |
|
| 575 | - $this->session->set_userdata('advance_search', 0); |
|
| 576 | - $this->session->set_userdata('resellersummary_reports_search', ""); |
|
| 577 | - $this->session->set_userdata('resellersummary_reports_export', ""); |
|
| 578 | - redirect(base_url()."summary/reseller/"); |
|
| 579 | - } |
|
| 574 | + function reseller_clearsearchfilter() { |
|
| 575 | + $this->session->set_userdata('advance_search', 0); |
|
| 576 | + $this->session->set_userdata('resellersummary_reports_search', ""); |
|
| 577 | + $this->session->set_userdata('resellersummary_reports_export', ""); |
|
| 578 | + redirect(base_url()."summary/reseller/"); |
|
| 579 | + } |
|
| 580 | 580 | |
| 581 | - function reseller_export_csv() { |
|
| 581 | + function reseller_export_csv() { |
|
| 582 | 582 | $account_info = $accountinfo = $this->session->userdata('accountinfo'); |
| 583 | 583 | $currency_id = $account_info['currency_id']; |
| 584 | 584 | $currency = $this->common->get_field_name('currency', 'currency', $currency_id); |
| 585 | 585 | |
| 586 | - $search_arr = $this->session->userdata('resellersummary_reports_export'); |
|
| 587 | - $data_arr = array(); |
|
| 588 | - $query = $this->summary_model->get_resellersummary_report_list(true, '', '', $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], true); |
|
| 589 | - $search_header = explode(",", $search_arr['export_str']); |
|
| 590 | - ob_clean(); |
|
| 591 | - $fixed_header = array("Attempted Calls", "Completed Calls", "Duration", "ASR", "ACD", "MCD", "Billable", "Debit($currency)", "Cost($currency)", "Profit"); |
|
| 592 | - $header_arr[] = array_merge($search_header, $fixed_header); |
|
| 593 | - if ($query->num_rows() > 0) { |
|
| 594 | - $data_arr = $this->summary_report_grid($search_arr, $query, 'reseller', 'export'); |
|
| 595 | - } |
|
| 596 | - $reseller_array = array_merge($header_arr, $data_arr); |
|
| 597 | - $this->load->helper('csv'); |
|
| 598 | - array_to_csv($reseller_array, 'Reseller_Summary_Report_'.date("Y-m-d").'.csv'); |
|
| 599 | - } |
|
| 586 | + $search_arr = $this->session->userdata('resellersummary_reports_export'); |
|
| 587 | + $data_arr = array(); |
|
| 588 | + $query = $this->summary_model->get_resellersummary_report_list(true, '', '', $search_arr['group_by_str'], $search_arr['select_str'], $search_arr['order_str'], true); |
|
| 589 | + $search_header = explode(",", $search_arr['export_str']); |
|
| 590 | + ob_clean(); |
|
| 591 | + $fixed_header = array("Attempted Calls", "Completed Calls", "Duration", "ASR", "ACD", "MCD", "Billable", "Debit($currency)", "Cost($currency)", "Profit"); |
|
| 592 | + $header_arr[] = array_merge($search_header, $fixed_header); |
|
| 593 | + if ($query->num_rows() > 0) { |
|
| 594 | + $data_arr = $this->summary_report_grid($search_arr, $query, 'reseller', 'export'); |
|
| 595 | + } |
|
| 596 | + $reseller_array = array_merge($header_arr, $data_arr); |
|
| 597 | + $this->load->helper('csv'); |
|
| 598 | + array_to_csv($reseller_array, 'Reseller_Summary_Report_'.date("Y-m-d").'.csv'); |
|
| 599 | + } |
|
| 600 | 600 | |
| 601 | 601 | } |
| 602 | 602 | ?> |
@@ -301,34 +301,34 @@ |
||
| 301 | 301 | 'invoiceid'=>$invoice_id, |
| 302 | 302 | 'description'=>"Your account has been credited due to your customer account recharge done by paypal", |
| 303 | 303 | 'item_type'=>'PAYMENT', |
| 304 | - 'before_balance'=>$account_data['balance'], |
|
| 304 | + 'before_balance'=>$account_data['balance'], |
|
| 305 | 305 | 'after_balance'=>$account_data['balance']+$balance_amt, |
| 306 | 306 | ); |
| 307 | - $this->db->insert("invoice_details", $details_insert); |
|
| 308 | - $this->db_model->update_balance($balance_amt,$account_data["id"],"credit"); |
|
| 307 | + $this->db->insert("invoice_details", $details_insert); |
|
| 308 | + $this->db_model->update_balance($balance_amt,$account_data["id"],"credit"); |
|
| 309 | 309 | } |
| 310 | - } |
|
| 310 | + } |
|
| 311 | 311 | } |
| 312 | 312 | redirect(base_url() . 'user/user/'); |
| 313 | - } |
|
| 314 | - } |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | 315 | redirect(base_url() . 'user/user/'); |
| 316 | - } |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - /** |
|
| 319 | - * @param integer $last_invoice_ID |
|
| 320 | - * @param string $due_date |
|
| 321 | - */ |
|
| 322 | - function generate_receipt($accountid,$amount,$accountinfo,$last_invoice_ID,$invoice_prefix,$due_date){ |
|
| 318 | + /** |
|
| 319 | + * @param integer $last_invoice_ID |
|
| 320 | + * @param string $due_date |
|
| 321 | + */ |
|
| 322 | + function generate_receipt($accountid,$amount,$accountinfo,$last_invoice_ID,$invoice_prefix,$due_date){ |
|
| 323 | 323 | $invoice_data = array("accountid"=>$accountid,"invoice_prefix" =>$invoice_prefix,"invoiceid"=>'0000'.$last_invoice_ID,"reseller_id"=>$accountinfo['reseller_id'],"invoice_date"=>gmdate("Y-m-d H:i:s"),"from_date"=> gmdate("Y-m-d H:i:s"),"to_date"=>gmdate("Y-m-d H:i:s"),"due_date"=>$due_date,"status"=>1,"balance"=>$accountinfo['balance'],"amount"=>$amount,"type"=>'R',"confirm"=>'1'); |
| 324 | - $this->db->insert("invoices",$invoice_data); |
|
| 325 | - $invoiceid = $this->db->insert_id(); |
|
| 326 | - return $invoiceid; |
|
| 327 | - } |
|
| 324 | + $this->db->insert("invoices",$invoice_data); |
|
| 325 | + $invoiceid = $this->db->insert_id(); |
|
| 326 | + return $invoiceid; |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - function get_language_text(){ |
|
| 329 | + function get_language_text(){ |
|
| 330 | 330 | // echo '<pre>'; print_r($_POST); exit; |
| 331 | - echo gettext($_POST['display']); |
|
| 331 | + echo gettext($_POST['display']); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | } |
@@ -1386,35 +1386,35 @@ |
||
| 1386 | 1386 | $invoice_id=$this->invoices->invoices->generate_receipt($reseller_info['id'],$custom_array['credit'],$reseller_info,$last_invoice_ID+1,$invoice_prefix,$due_date); |
| 1387 | 1387 | $account_balance = $this->common->get_field_name('balance', 'accounts', $reseller_info['id']); |
| 1388 | 1388 | $insert_arr = array("accountid" => $reseller_info['id'], |
| 1389 | - "description" => trim($custom_array['notes']), |
|
| 1390 | - "debit" => 0, |
|
| 1391 | - "credit" => $custom_array['credit'], |
|
| 1392 | - "created_date" => gmdate("Y-m-d H:i:s"), |
|
| 1393 | - "invoiceid"=>$invoice_id, |
|
| 1394 | - "reseller_id"=>$reseller_info['reseller_id'], |
|
| 1395 | - "item_type"=>'Refill', |
|
| 1396 | - "item_id"=>'0', |
|
| 1397 | - 'before_balance'=>$account_balance - $custom_array['credit'], |
|
| 1398 | - 'after_balance'=>$account_balance, |
|
| 1399 | - ); |
|
| 1400 | - $this->db->insert("invoice_details", $insert_arr); |
|
| 1389 | + "description" => trim($custom_array['notes']), |
|
| 1390 | + "debit" => 0, |
|
| 1391 | + "credit" => $custom_array['credit'], |
|
| 1392 | + "created_date" => gmdate("Y-m-d H:i:s"), |
|
| 1393 | + "invoiceid"=>$invoice_id, |
|
| 1394 | + "reseller_id"=>$reseller_info['reseller_id'], |
|
| 1395 | + "item_type"=>'Refill', |
|
| 1396 | + "item_id"=>'0', |
|
| 1397 | + 'before_balance'=>$account_balance - $custom_array['credit'], |
|
| 1398 | + 'after_balance'=>$account_balance, |
|
| 1399 | + ); |
|
| 1400 | + $this->db->insert("invoice_details", $insert_arr); |
|
| 1401 | + } |
|
| 1402 | + } |
|
| 1401 | 1403 | } |
| 1402 | - } |
|
| 1403 | - } |
|
| 1404 | 1404 | } |
| 1405 | - $message = $post_array['payment_type'] == 0 ? "Recharge successfully!" : "Post charge applied successfully."; |
|
| 1405 | + $message = $post_array['payment_type'] == 0 ? "Recharge successfully!" : "Post charge applied successfully."; |
|
| 1406 | 1406 | /***********************************************************************************************/ |
| 1407 | - echo json_encode(array("SUCCESS"=> $message)); |
|
| 1408 | - exit; |
|
| 1409 | - // } |
|
| 1410 | - } |
|
| 1411 | - $this->load->view('view_accounts_process_payment', $data); |
|
| 1412 | - } |
|
| 1413 | - |
|
| 1414 | - /** |
|
| 1415 | - * @param string $select |
|
| 1416 | - */ |
|
| 1417 | - function get_invoice_date($select,$accountid){ |
|
| 1407 | + echo json_encode(array("SUCCESS"=> $message)); |
|
| 1408 | + exit; |
|
| 1409 | + // } |
|
| 1410 | + } |
|
| 1411 | + $this->load->view('view_accounts_process_payment', $data); |
|
| 1412 | + } |
|
| 1413 | + |
|
| 1414 | + /** |
|
| 1415 | + * @param string $select |
|
| 1416 | + */ |
|
| 1417 | + function get_invoice_date($select,$accountid){ |
|
| 1418 | 1418 | $query = $this->db_model->select($select, "invoices", '',"id","DESC","1","0"); |
| 1419 | 1419 | if($query->num_rows >0){ |
| 1420 | 1420 | $invoiceid = $query->result_array(); |
@@ -122,236 +122,236 @@ |
||
| 122 | 122 | $this->db_model->build_search('origination_rate_list_search'); |
| 123 | 123 | /***********************/ |
| 124 | 124 | |
| 125 | - if ($flag) { |
|
| 126 | - $query = $this->db_model->select("*", "routes", $where, "id", "ASC", $limit, $start); |
|
| 127 | - } else { |
|
| 128 | - $query = $this->db_model->countQuery("*", "routes", $where); |
|
| 125 | + if ($flag) { |
|
| 126 | + $query = $this->db_model->select("*", "routes", $where, "id", "ASC", $limit, $start); |
|
| 127 | + } else { |
|
| 128 | + $query = $this->db_model->countQuery("*", "routes", $where); |
|
| 129 | 129 | |
| 130 | - } |
|
| 131 | - //echo $this->db->last_query(); |
|
| 132 | - return $query; |
|
| 133 | - } |
|
| 134 | - function getunblocked_pattern_list($accountid, $flag, $start = 0, $limit = 0) { |
|
| 135 | - $this->db_model->build_search('origination_rate_list_search'); |
|
| 136 | - if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
|
| 137 | - $account_data = $this->session->userdata("accountinfo"); |
|
| 138 | - $reseller = $account_data['id']; |
|
| 139 | - $where = array("reseller_id" => $reseller, "status" => "0"); |
|
| 140 | - } else { |
|
| 141 | - $where = array("status" => "0", 'reseller_id'=>'0'); |
|
| 142 | - } |
|
| 143 | - $where1 = '(pattern NOT IN (select blocked_patterns from block_patterns where accountid = "'.$accountid.'"))'; |
|
| 144 | - $this->db->where($where1); |
|
| 145 | - if ($flag) { |
|
| 146 | - $query = $this->db_model->select("*", "routes", $where, "id", "ASC", $limit, $start); |
|
| 130 | + } |
|
| 131 | + //echo $this->db->last_query(); |
|
| 132 | + return $query; |
|
| 133 | + } |
|
| 134 | + function getunblocked_pattern_list($accountid, $flag, $start = 0, $limit = 0) { |
|
| 135 | + $this->db_model->build_search('origination_rate_list_search'); |
|
| 136 | + if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
|
| 137 | + $account_data = $this->session->userdata("accountinfo"); |
|
| 138 | + $reseller = $account_data['id']; |
|
| 139 | + $where = array("reseller_id" => $reseller, "status" => "0"); |
|
| 140 | + } else { |
|
| 141 | + $where = array("status" => "0", 'reseller_id'=>'0'); |
|
| 142 | + } |
|
| 143 | + $where1 = '(pattern NOT IN (select blocked_patterns from block_patterns where accountid = "'.$accountid.'"))'; |
|
| 144 | + $this->db->where($where1); |
|
| 145 | + if ($flag) { |
|
| 146 | + $query = $this->db_model->select("*", "routes", $where, "id", "ASC", $limit, $start); |
|
| 147 | 147 | // echo "<pre>"; print_r($query); exit; |
| 148 | - } else { |
|
| 149 | - $query = $this->db_model->countQuery("*", "routes", $where); |
|
| 150 | - } |
|
| 151 | - return $query; |
|
| 152 | - } |
|
| 153 | - function getunblocked_package_pattern($accountid, $flag, $start = 0, $limit = 0) { |
|
| 154 | - $this->db_model->build_search('origination_rate_list_search'); |
|
| 155 | - if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
|
| 156 | - $account_data = $this->session->userdata("accountinfo"); |
|
| 157 | - $reseller = $account_data['id']; |
|
| 158 | - $where = array("reseller_id" => $reseller, "status" => "0"); |
|
| 159 | - } else { |
|
| 160 | - $where = array("status" => "0", 'reseller_id'=>'0'); |
|
| 161 | - } |
|
| 162 | - $where1 = '(pattern NOT IN (select DISTINCT patterns from package_patterns where package_id = "'.$accountid.'"))'; |
|
| 163 | - $this->db->where($where1); |
|
| 164 | - if ($flag) { |
|
| 165 | - $query = $this->db_model->select("*", "routes", $where, "id", "ASC", $limit, $start); |
|
| 166 | - } else { |
|
| 167 | - $query = $this->db_model->countQuery("*", "routes", $where); |
|
| 168 | - } |
|
| 169 | - return $query; |
|
| 170 | - } |
|
| 148 | + } else { |
|
| 149 | + $query = $this->db_model->countQuery("*", "routes", $where); |
|
| 150 | + } |
|
| 151 | + return $query; |
|
| 152 | + } |
|
| 153 | + function getunblocked_package_pattern($accountid, $flag, $start = 0, $limit = 0) { |
|
| 154 | + $this->db_model->build_search('origination_rate_list_search'); |
|
| 155 | + if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
|
| 156 | + $account_data = $this->session->userdata("accountinfo"); |
|
| 157 | + $reseller = $account_data['id']; |
|
| 158 | + $where = array("reseller_id" => $reseller, "status" => "0"); |
|
| 159 | + } else { |
|
| 160 | + $where = array("status" => "0", 'reseller_id'=>'0'); |
|
| 161 | + } |
|
| 162 | + $where1 = '(pattern NOT IN (select DISTINCT patterns from package_patterns where package_id = "'.$accountid.'"))'; |
|
| 163 | + $this->db->where($where1); |
|
| 164 | + if ($flag) { |
|
| 165 | + $query = $this->db_model->select("*", "routes", $where, "id", "ASC", $limit, $start); |
|
| 166 | + } else { |
|
| 167 | + $query = $this->db_model->countQuery("*", "routes", $where); |
|
| 168 | + } |
|
| 169 | + return $query; |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - function get_origination_rate_list_for_user($flag, $start = 0, $limit = 0) { |
|
| 173 | - $this->db_model->build_search('user_rates_list_search'); |
|
| 172 | + function get_origination_rate_list_for_user($flag, $start = 0, $limit = 0) { |
|
| 173 | + $this->db_model->build_search('user_rates_list_search'); |
|
| 174 | 174 | |
| 175 | - $account_data = $this->session->userdata("accountinfo"); |
|
| 176 | - $where = array("pricelist_id" => $account_data["pricelist_id"], "status" => '0'); |
|
| 175 | + $account_data = $this->session->userdata("accountinfo"); |
|
| 176 | + $where = array("pricelist_id" => $account_data["pricelist_id"], "status" => '0'); |
|
| 177 | 177 | |
| 178 | - $this->db_model->build_search('origination_rate_list_search'); |
|
| 179 | - if ($flag) { |
|
| 180 | - $query = $this->db_model->select("*", "routes", $where, "id", "ASC", $limit, $start); |
|
| 181 | - } else { |
|
| 182 | - $query = $this->db_model->countQuery("*", "routes", $where); |
|
| 183 | - } |
|
| 184 | - return $query; |
|
| 185 | - } |
|
| 178 | + $this->db_model->build_search('origination_rate_list_search'); |
|
| 179 | + if ($flag) { |
|
| 180 | + $query = $this->db_model->select("*", "routes", $where, "id", "ASC", $limit, $start); |
|
| 181 | + } else { |
|
| 182 | + $query = $this->db_model->countQuery("*", "routes", $where); |
|
| 183 | + } |
|
| 184 | + return $query; |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | 187 | |
| 188 | - function add_termination_rate($add_array) { |
|
| 189 | - unset($add_array["action"]); |
|
| 190 | - if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
|
| 191 | - $account_data = $this->session->userdata("accountinfo"); |
|
| 192 | - $reseller = $account_data['id']; |
|
| 193 | - $add_array['reseller_id'] = $reseller; |
|
| 194 | - } |
|
| 195 | - $add_array['pattern'] = "^".$add_array['pattern'].".*"; |
|
| 196 | - $add_array['prepend'] = $add_array['prepend']; |
|
| 197 | - /* |
|
| 188 | + function add_termination_rate($add_array) { |
|
| 189 | + unset($add_array["action"]); |
|
| 190 | + if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
|
| 191 | + $account_data = $this->session->userdata("accountinfo"); |
|
| 192 | + $reseller = $account_data['id']; |
|
| 193 | + $add_array['reseller_id'] = $reseller; |
|
| 194 | + } |
|
| 195 | + $add_array['pattern'] = "^".$add_array['pattern'].".*"; |
|
| 196 | + $add_array['prepend'] = $add_array['prepend']; |
|
| 197 | + /* |
|
| 198 | 198 | ASTPP 3.0 |
| 199 | 199 | add creation date. |
| 200 | 200 | */ |
| 201 | - $add_array['creation_date'] = gmdate('Y-m-d H:i:s'); |
|
| 202 | - /*******************************************************/ |
|
| 203 | - $this->insert_if_not_exitst($add_array, "outbound_routes"); |
|
| 204 | - //$this->db->insert("outbound_routes", $add_array); |
|
| 205 | - return true; |
|
| 206 | - } |
|
| 201 | + $add_array['creation_date'] = gmdate('Y-m-d H:i:s'); |
|
| 202 | + /*******************************************************/ |
|
| 203 | + $this->insert_if_not_exitst($add_array, "outbound_routes"); |
|
| 204 | + //$this->db->insert("outbound_routes", $add_array); |
|
| 205 | + return true; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - function edit_termination_rate($data, $id) { |
|
| 209 | - unset($data["action"]); |
|
| 210 | - /* |
|
| 208 | + function edit_termination_rate($data, $id) { |
|
| 209 | + unset($data["action"]); |
|
| 210 | + /* |
|
| 211 | 211 | ASTPP 3.0 |
| 212 | 212 | Edit time last modified date |
| 213 | 213 | */ |
| 214 | - $data['last_modified_date'] = gmdate('Y-m-d H:i:s'); |
|
| 215 | - /***************************************************/ |
|
| 216 | - $data['pattern'] = "^".$data['pattern'].".*"; |
|
| 217 | - $this->db->where("id", $id); |
|
| 218 | - $this->db->update("outbound_routes", $data); |
|
| 219 | - } |
|
| 214 | + $data['last_modified_date'] = gmdate('Y-m-d H:i:s'); |
|
| 215 | + /***************************************************/ |
|
| 216 | + $data['pattern'] = "^".$data['pattern'].".*"; |
|
| 217 | + $this->db->where("id", $id); |
|
| 218 | + $this->db->update("outbound_routes", $data); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - function remove_termination_rate($id) { |
|
| 222 | - $this->db->where("id", $id); |
|
| 223 | - $this->db->delete("outbound_routes"); |
|
| 224 | - return true; |
|
| 225 | - } |
|
| 221 | + function remove_termination_rate($id) { |
|
| 222 | + $this->db->where("id", $id); |
|
| 223 | + $this->db->delete("outbound_routes"); |
|
| 224 | + return true; |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - function add_origination_rate($add_array) { |
|
| 227 | + function add_origination_rate($add_array) { |
|
| 228 | 228 | |
| 229 | - unset($add_array["action"]); |
|
| 230 | - /* |
|
| 229 | + unset($add_array["action"]); |
|
| 230 | + /* |
|
| 231 | 231 | ASTPP 3.0 |
| 232 | 232 | ADD time put creation date in routes table |
| 233 | 233 | */ |
| 234 | - $add_array['creation_date'] = gmdate('Y-m-d H:i:s'); |
|
| 235 | - /**********************************************/ |
|
| 236 | - if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
|
| 237 | - $account_data = $this->session->userdata("accountinfo"); |
|
| 238 | - $reseller = $account_data['id']; |
|
| 239 | - $add_array['reseller_id'] = $reseller; |
|
| 240 | - } |
|
| 234 | + $add_array['creation_date'] = gmdate('Y-m-d H:i:s'); |
|
| 235 | + /**********************************************/ |
|
| 236 | + if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
|
| 237 | + $account_data = $this->session->userdata("accountinfo"); |
|
| 238 | + $reseller = $account_data['id']; |
|
| 239 | + $add_array['reseller_id'] = $reseller; |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - $add_array['pattern'] = "^".$add_array['pattern'].".*"; |
|
| 242 | + $add_array['pattern'] = "^".$add_array['pattern'].".*"; |
|
| 243 | 243 | /************* |
| 244 | 244 | ASTPP 3.0 |
| 245 | 245 | Rate insert |
| 246 | 246 | *************/ |
| 247 | - $this->insert_if_not_exitst($add_array, "routes"); |
|
| 247 | + $this->insert_if_not_exitst($add_array, "routes"); |
|
| 248 | 248 | // $this->db->insert("routes", $add_array); |
| 249 | 249 | /*******************************/ |
| 250 | - return true; |
|
| 251 | - } |
|
| 250 | + return true; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - function edit_origination_rate($data, $id) { |
|
| 254 | - unset($data["action"]); |
|
| 255 | - /* |
|
| 253 | + function edit_origination_rate($data, $id) { |
|
| 254 | + unset($data["action"]); |
|
| 255 | + /* |
|
| 256 | 256 | ASTPP 3.0 |
| 257 | 257 | Edit tile last modified date update |
| 258 | 258 | */ |
| 259 | - $data['last_modified_date'] = gmdate('Y-m-d H:i:s'); |
|
| 260 | - /********************************************************/ |
|
| 261 | - $data['pattern'] = "^".$data['pattern'].".*"; |
|
| 262 | - $this->db->where("id", $id); |
|
| 263 | - $this->db->update("routes", $data); |
|
| 264 | - } |
|
| 259 | + $data['last_modified_date'] = gmdate('Y-m-d H:i:s'); |
|
| 260 | + /********************************************************/ |
|
| 261 | + $data['pattern'] = "^".$data['pattern'].".*"; |
|
| 262 | + $this->db->where("id", $id); |
|
| 263 | + $this->db->update("routes", $data); |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - function remove_origination_rate($id) { |
|
| 267 | - $this->db->where("id", $id); |
|
| 268 | - $this->db->delete("routes"); |
|
| 269 | - return true; |
|
| 270 | - } |
|
| 266 | + function remove_origination_rate($id) { |
|
| 267 | + $this->db->where("id", $id); |
|
| 268 | + $this->db->delete("routes"); |
|
| 269 | + return true; |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - function get_trunk_name($field_value) { |
|
| 273 | - $this->db->where("name", $field_value); |
|
| 274 | - $query = $this->db->get('trunks'); |
|
| 275 | - $data = $query->result(); |
|
| 276 | - if ($query->num_rows > 0) { |
|
| 277 | - return $data[0]->id; |
|
| 278 | - } else { |
|
| 279 | - return ''; |
|
| 280 | - } |
|
| 281 | - } |
|
| 272 | + function get_trunk_name($field_value) { |
|
| 273 | + $this->db->where("name", $field_value); |
|
| 274 | + $query = $this->db->get('trunks'); |
|
| 275 | + $data = $query->result(); |
|
| 276 | + if ($query->num_rows > 0) { |
|
| 277 | + return $data[0]->id; |
|
| 278 | + } else { |
|
| 279 | + return ''; |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - function bulk_insert_termination_rate($field_value) { |
|
| 284 | - //$this->db->insert_batch('outbound_routes', $field_value); |
|
| 285 | - $this->db->insert_on_duplicate_update_batch('outbound_routes', $field_value); |
|
| 286 | - $affected_row = $this->db->affected_rows(); |
|
| 287 | - return $affected_row; |
|
| 288 | - } |
|
| 283 | + function bulk_insert_termination_rate($field_value) { |
|
| 284 | + //$this->db->insert_batch('outbound_routes', $field_value); |
|
| 285 | + $this->db->insert_on_duplicate_update_batch('outbound_routes', $field_value); |
|
| 286 | + $affected_row = $this->db->affected_rows(); |
|
| 287 | + return $affected_row; |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - function bulk_insert_origination_rate($inserted_array) { |
|
| 291 | - //$this->db->insert_batch('routes', $inserted_array); |
|
| 292 | - $this->db->insert_on_duplicate_update_batch('routes', $inserted_array); |
|
| 293 | - $affected_row = $this->db->affected_rows(); |
|
| 294 | - return $affected_row; |
|
| 295 | - } |
|
| 296 | - function termination_rate_batch_update($update_array) { |
|
| 297 | - $this->db_model->build_search('termination_rates_list_search'); |
|
| 298 | - if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
|
| 299 | - $account_data = $this->session->userdata("accountinfo"); |
|
| 300 | - $this->db->where("reseller_id", $account_data['id']); |
|
| 301 | - } |
|
| 290 | + function bulk_insert_origination_rate($inserted_array) { |
|
| 291 | + //$this->db->insert_batch('routes', $inserted_array); |
|
| 292 | + $this->db->insert_on_duplicate_update_batch('routes', $inserted_array); |
|
| 293 | + $affected_row = $this->db->affected_rows(); |
|
| 294 | + return $affected_row; |
|
| 295 | + } |
|
| 296 | + function termination_rate_batch_update($update_array) { |
|
| 297 | + $this->db_model->build_search('termination_rates_list_search'); |
|
| 298 | + if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
|
| 299 | + $account_data = $this->session->userdata("accountinfo"); |
|
| 300 | + $this->db->where("reseller_id", $account_data['id']); |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - $updateflg = $this->db_model->build_batch_update_array($update_array); |
|
| 304 | - if ($updateflg) |
|
| 305 | - return $this->db->update("outbound_routes"); |
|
| 306 | - else |
|
| 307 | - return false; |
|
| 308 | - } |
|
| 309 | - function origination_rate_batch_update($update_array) { |
|
| 310 | - $this->db_model->build_search('origination_rate_list_search'); |
|
| 311 | - if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
|
| 312 | - $account_data = $this->session->userdata("accountinfo"); |
|
| 313 | - $this->db->where("reseller_id", $account_data['id']); |
|
| 314 | - } |
|
| 315 | - $updateflg = $this->db_model->build_batch_update_array($update_array); |
|
| 316 | - if ($updateflg) |
|
| 317 | - return $this->db->update("routes"); |
|
| 318 | - else |
|
| 319 | - return false; |
|
| 320 | - } |
|
| 321 | - function getreseller_rates_list($flag, $start = 0, $limit = 0, $export = false) { |
|
| 322 | - $this->db_model->build_search('resellerrates_list_search'); |
|
| 323 | - $account_data = $this->session->userdata("accountinfo"); |
|
| 324 | - $where = array("status"=>"0", "pricelist_id" => $account_data["pricelist_id"]); |
|
| 325 | - if ($flag) { |
|
| 326 | - $query = $this->db_model->select("*", "routes", $where, "id", "ASC", $limit, $start); |
|
| 327 | - } else { |
|
| 328 | - $query = $this->db_model->countQuery("*", "routes", $where); |
|
| 329 | - } |
|
| 330 | - return $query; |
|
| 331 | - } |
|
| 303 | + $updateflg = $this->db_model->build_batch_update_array($update_array); |
|
| 304 | + if ($updateflg) |
|
| 305 | + return $this->db->update("outbound_routes"); |
|
| 306 | + else |
|
| 307 | + return false; |
|
| 308 | + } |
|
| 309 | + function origination_rate_batch_update($update_array) { |
|
| 310 | + $this->db_model->build_search('origination_rate_list_search'); |
|
| 311 | + if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
|
| 312 | + $account_data = $this->session->userdata("accountinfo"); |
|
| 313 | + $this->db->where("reseller_id", $account_data['id']); |
|
| 314 | + } |
|
| 315 | + $updateflg = $this->db_model->build_batch_update_array($update_array); |
|
| 316 | + if ($updateflg) |
|
| 317 | + return $this->db->update("routes"); |
|
| 318 | + else |
|
| 319 | + return false; |
|
| 320 | + } |
|
| 321 | + function getreseller_rates_list($flag, $start = 0, $limit = 0, $export = false) { |
|
| 322 | + $this->db_model->build_search('resellerrates_list_search'); |
|
| 323 | + $account_data = $this->session->userdata("accountinfo"); |
|
| 324 | + $where = array("status"=>"0", "pricelist_id" => $account_data["pricelist_id"]); |
|
| 325 | + if ($flag) { |
|
| 326 | + $query = $this->db_model->select("*", "routes", $where, "id", "ASC", $limit, $start); |
|
| 327 | + } else { |
|
| 328 | + $query = $this->db_model->countQuery("*", "routes", $where); |
|
| 329 | + } |
|
| 330 | + return $query; |
|
| 331 | + } |
|
| 332 | 332 | /************* |
| 333 | 333 | ASTPP 3.0 |
| 334 | 334 | Rate insert |
| 335 | 335 | *************/ |
| 336 | - /** |
|
| 337 | - * @param string $table_name |
|
| 338 | - */ |
|
| 339 | - function insert_if_not_exitst($add_array,$table_name){ |
|
| 340 | - $insert_str = "Insert into $table_name ("; |
|
| 341 | - $insert_key = ""; |
|
| 342 | - $insert_value = ""; |
|
| 343 | - $update_str = ""; |
|
| 344 | - foreach($add_array as $key => $value){ |
|
| 345 | - if($key != 'id'){ |
|
| 346 | - $insert_key .= $key.","; |
|
| 347 | - $insert_value .= "'$value',"; |
|
| 348 | - $update_str .= $key." = '$value',"; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - $insert_key = rtrim($insert_key,","); |
|
| 352 | - $insert_value = rtrim($insert_value,","); |
|
| 353 | - $update_str = rtrim($update_str,","); |
|
| 354 | - $insert_str .= $insert_key.") values"."(".$insert_value.") ON DUPLICATE KEY UPDATE $update_str"; |
|
| 355 | - $this->db->query($insert_str); |
|
| 356 | - } |
|
| 336 | + /** |
|
| 337 | + * @param string $table_name |
|
| 338 | + */ |
|
| 339 | + function insert_if_not_exitst($add_array,$table_name){ |
|
| 340 | + $insert_str = "Insert into $table_name ("; |
|
| 341 | + $insert_key = ""; |
|
| 342 | + $insert_value = ""; |
|
| 343 | + $update_str = ""; |
|
| 344 | + foreach($add_array as $key => $value){ |
|
| 345 | + if($key != 'id'){ |
|
| 346 | + $insert_key .= $key.","; |
|
| 347 | + $insert_value .= "'$value',"; |
|
| 348 | + $update_str .= $key." = '$value',"; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + $insert_key = rtrim($insert_key,","); |
|
| 352 | + $insert_value = rtrim($insert_value,","); |
|
| 353 | + $update_str = rtrim($update_str,","); |
|
| 354 | + $insert_str .= $insert_key.") values"."(".$insert_value.") ON DUPLICATE KEY UPDATE $update_str"; |
|
| 355 | + $this->db->query($insert_str); |
|
| 356 | + } |
|
| 357 | 357 | } |
@@ -666,18 +666,18 @@ discard block |
||
| 666 | 666 | $this->invoice_send_notification($response_arr['invoiceid'],$account_data[0],'auto'); |
| 667 | 667 | /***** ***/ |
| 668 | 668 | } |
| 669 | - $this->session->set_flashdata('astpp_errormsg', 'Invoice updated successfully!'); |
|
| 669 | + $this->session->set_flashdata('astpp_errormsg', 'Invoice updated successfully!'); |
|
| 670 | 670 | redirect(base_url() . 'invoices/invoice_list/'); |
| 671 | - } |
|
| 671 | + } |
|
| 672 | 672 | |
| 673 | - /** |
|
| 674 | - * @param string $inv_flag |
|
| 675 | - */ |
|
| 676 | - function invoice_send_notification($invoice_id,$accountdata,$inv_flag){ |
|
| 673 | + /** |
|
| 674 | + * @param string $inv_flag |
|
| 675 | + */ |
|
| 676 | + function invoice_send_notification($invoice_id,$accountdata,$inv_flag){ |
|
| 677 | 677 | $invoicedata = $this->db_model->getSelect("*", "invoices", array("id" => $invoice_id)); |
| 678 | 678 | $invoicedata = $invoicedata->result_array(); |
| 679 | 679 | $invoicedata =$invoicedata[0]; |
| 680 | - //$res = $this->common->get_invoice_template($invoicedata,$accountdata,"False"); |
|
| 680 | + //$res = $this->common->get_invoice_template($invoicedata,$accountdata,"False"); |
|
| 681 | 681 | $invoice_conf = array(); |
| 682 | 682 | if($accountdata['reseller_id'] == 0){ |
| 683 | 683 | $where = array("accountid"=> 1); |
@@ -1478,104 +1478,104 @@ discard block |
||
| 1478 | 1478 | $this->session->set_flashdata('astpp_notification', 'Permission Denied.'); |
| 1479 | 1479 | redirect(base_url()."invoices/invoice_list/"); |
| 1480 | 1480 | } |
| 1481 | - } |
|
| 1481 | + } |
|
| 1482 | 1482 | |
| 1483 | - /** |
|
| 1484 | - * @param string $select |
|
| 1485 | - */ |
|
| 1486 | - function get_invoice_date($select,$accountid=false){ |
|
| 1483 | + /** |
|
| 1484 | + * @param string $select |
|
| 1485 | + */ |
|
| 1486 | + function get_invoice_date($select,$accountid=false){ |
|
| 1487 | 1487 | if($accountid){ |
| 1488 | - $where = array('type'=>"I","accountid"=>$accountid); |
|
| 1489 | - $query = $this->db_model->select($select, "invoices", $where,"to_date","DESC","1","0"); |
|
| 1488 | + $where = array('type'=>"I","accountid"=>$accountid); |
|
| 1489 | + $query = $this->db_model->select($select, "invoices", $where,"to_date","DESC","1","0"); |
|
| 1490 | 1490 | } else{ |
| 1491 | 1491 | $where = array('type'=>"I"); |
| 1492 | - $query = $this->db_model->select($select, "invoices", $where,"id","DESC","1","0"); |
|
| 1492 | + $query = $this->db_model->select($select, "invoices", $where,"id","DESC","1","0"); |
|
| 1493 | 1493 | } |
| 1494 | - if($query->num_rows >0){ |
|
| 1495 | - $invoiceid = $query->result_array(); |
|
| 1496 | - $invoice_date=$invoiceid[0][$select]; |
|
| 1497 | - return $invoice_date; |
|
| 1498 | - } |
|
| 1499 | - return false; |
|
| 1500 | - } |
|
| 1501 | - function invoice_main_download($invoiceid) { |
|
| 1494 | + if($query->num_rows >0){ |
|
| 1495 | + $invoiceid = $query->result_array(); |
|
| 1496 | + $invoice_date=$invoiceid[0][$select]; |
|
| 1497 | + return $invoice_date; |
|
| 1498 | + } |
|
| 1499 | + return false; |
|
| 1500 | + } |
|
| 1501 | + function invoice_main_download($invoiceid) { |
|
| 1502 | 1502 | |
| 1503 | - $invoicedata = $this->db_model->getSelect("*", "invoices", array("id"=> $invoiceid)); |
|
| 1504 | - $invoicedata = $invoicedata->result_array(); |
|
| 1505 | - $invoicedata=$invoicedata[0]; |
|
| 1503 | + $invoicedata = $this->db_model->getSelect("*", "invoices", array("id"=> $invoiceid)); |
|
| 1504 | + $invoicedata = $invoicedata->result_array(); |
|
| 1505 | + $invoicedata=$invoicedata[0]; |
|
| 1506 | 1506 | $invoice_path=''; |
| 1507 | - $accountid = $invoicedata['accountid']; |
|
| 1508 | - $acc_file=$invoice_path.$accountid.'/'.$invoiceid; |
|
| 1509 | - $accountdata = $this->db_model->getSelect("*","accounts",array("id"=>$accountid)); |
|
| 1510 | - $accountdata = $accountdata->result_array(); |
|
| 1511 | - $accountdata = $accountdata[0]; |
|
| 1507 | + $accountid = $invoicedata['accountid']; |
|
| 1508 | + $acc_file=$invoice_path.$accountid.'/'.$invoiceid; |
|
| 1509 | + $accountdata = $this->db_model->getSelect("*","accounts",array("id"=>$accountid)); |
|
| 1510 | + $accountdata = $accountdata->result_array(); |
|
| 1511 | + $accountdata = $accountdata[0]; |
|
| 1512 | 1512 | |
| 1513 | - $login_type = $this->session->userdata['userlevel_logintype']; |
|
| 1514 | - $query="select item_type,credit from invoice_details where invoiceid = ".$invoicedata['id']." and item_type='INVPAY' Group By id order by item_type desc"; |
|
| 1515 | - // echo $query; exit; |
|
| 1516 | - $invoice_total_query=$this->db->query($query); |
|
| 1517 | - if($invoice_total_query->num_rows() > 0){ |
|
| 1518 | - $total=$invoice_total_query->result_array(); |
|
| 1519 | - foreach($total as $key => $value){ |
|
| 1520 | - $debit=$value['credit']; |
|
| 1521 | - } |
|
| 1522 | - if($debit){ |
|
| 1523 | - // echo 'debit'; exit; |
|
| 1524 | - $invoice_path=$this->config->item('invoices_path'); |
|
| 1525 | - $download_path = $invoice_path.$accountdata["id"].'/'.$invoicedata['invoice_prefix'].$invoicedata['invoiceid']."_invoice.pdf"; |
|
| 1526 | - unlink($download_path); |
|
| 1527 | - $res = $this->common->get_invoice_template($invoicedata,$accountdata,"TRUE"); |
|
| 1528 | - } |
|
| 1529 | - } |
|
| 1530 | - $invoice_path=$this->config->item('invoices_path'); |
|
| 1531 | - $download_path = $invoice_path.$accountdata["id"].'/'.$invoicedata['invoice_prefix'].$invoicedata['invoiceid']."_invoice.pdf"; |
|
| 1532 | - $res = $this->common->get_invoice_template($invoicedata,$accountdata,"TRUE"); |
|
| 1533 | - } |
|
| 1513 | + $login_type = $this->session->userdata['userlevel_logintype']; |
|
| 1514 | + $query="select item_type,credit from invoice_details where invoiceid = ".$invoicedata['id']." and item_type='INVPAY' Group By id order by item_type desc"; |
|
| 1515 | + // echo $query; exit; |
|
| 1516 | + $invoice_total_query=$this->db->query($query); |
|
| 1517 | + if($invoice_total_query->num_rows() > 0){ |
|
| 1518 | + $total=$invoice_total_query->result_array(); |
|
| 1519 | + foreach($total as $key => $value){ |
|
| 1520 | + $debit=$value['credit']; |
|
| 1521 | + } |
|
| 1522 | + if($debit){ |
|
| 1523 | + // echo 'debit'; exit; |
|
| 1524 | + $invoice_path=$this->config->item('invoices_path'); |
|
| 1525 | + $download_path = $invoice_path.$accountdata["id"].'/'.$invoicedata['invoice_prefix'].$invoicedata['invoiceid']."_invoice.pdf"; |
|
| 1526 | + unlink($download_path); |
|
| 1527 | + $res = $this->common->get_invoice_template($invoicedata,$accountdata,"TRUE"); |
|
| 1528 | + } |
|
| 1529 | + } |
|
| 1530 | + $invoice_path=$this->config->item('invoices_path'); |
|
| 1531 | + $download_path = $invoice_path.$accountdata["id"].'/'.$invoicedata['invoice_prefix'].$invoicedata['invoiceid']."_invoice.pdf"; |
|
| 1532 | + $res = $this->common->get_invoice_template($invoicedata,$accountdata,"TRUE"); |
|
| 1533 | + } |
|
| 1534 | 1534 | function Sec2Minutes( $seconds ) |
| 1535 | 1535 | { |
| 1536 | - return sprintf( "%02.2d:%02.2d", floor( $seconds / 60 ), $seconds % 60 ); |
|
| 1536 | + return sprintf( "%02.2d:%02.2d", floor( $seconds / 60 ), $seconds % 60 ); |
|
| 1537 | 1537 | } |
| 1538 | 1538 | function receipt_download($invoiceid) { |
| 1539 | - $login_info = $this->session->userdata('accountinfo'); |
|
| 1540 | - ob_start(); |
|
| 1541 | - $this->load->library('/html2pdf/html2pdf'); |
|
| 1542 | - $template_config=$this->config->item('invoice_template'); |
|
| 1543 | - include($template_config.'invoice_template_receipt.php'); |
|
| 1544 | - $content = ob_get_clean(); |
|
| 1545 | - ob_clean(); |
|
| 1546 | - $accountid = $this->common->get_field_name('accountid', 'invoices', $invoiceid); |
|
| 1547 | - $accountdata = $this->db_model->getSelect("*","accounts",array("id"=>$accountid)); |
|
| 1548 | - $accountdata = $accountdata->result_array(); |
|
| 1549 | - $accountdata = $accountdata[0]; |
|
| 1539 | + $login_info = $this->session->userdata('accountinfo'); |
|
| 1540 | + ob_start(); |
|
| 1541 | + $this->load->library('/html2pdf/html2pdf'); |
|
| 1542 | + $template_config=$this->config->item('invoice_template'); |
|
| 1543 | + include($template_config.'invoice_template_receipt.php'); |
|
| 1544 | + $content = ob_get_clean(); |
|
| 1545 | + ob_clean(); |
|
| 1546 | + $accountid = $this->common->get_field_name('accountid', 'invoices', $invoiceid); |
|
| 1547 | + $accountdata = $this->db_model->getSelect("*","accounts",array("id"=>$accountid)); |
|
| 1548 | + $accountdata = $accountdata->result_array(); |
|
| 1549 | + $accountdata = $accountdata[0]; |
|
| 1550 | 1550 | // $accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $accountdata["currency_id"]); |
| 1551 | 1551 | //$currency = $accountdata["currency_id"]; |
| 1552 | - if($login_info['type'] == -1){ |
|
| 1552 | + if($login_info['type'] == -1){ |
|
| 1553 | 1553 | $data["to_currency"] = Common_model::$global_config['system_config']['base_currency']; |
| 1554 | - $currency = $data["to_currency"]; |
|
| 1555 | - } elseif($login_info['type'] == 1){ |
|
| 1554 | + $currency = $data["to_currency"]; |
|
| 1555 | + } elseif($login_info['type'] == 1){ |
|
| 1556 | 1556 | $accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $login_info["currency_id"]); |
| 1557 | - $currency = $accountdata["currency_id"]; |
|
| 1558 | - } else{ |
|
| 1557 | + $currency = $accountdata["currency_id"]; |
|
| 1558 | + } else{ |
|
| 1559 | 1559 | $accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $login_info["currency_id"]); |
| 1560 | - $currency = $accountdata["currency_id"]; |
|
| 1561 | - } |
|
| 1562 | - $invoice_cdr_list = array(); |
|
| 1563 | - $invoicedata = $this->db_model->getSelect("*", "invoices", array("id"=> $invoiceid)); |
|
| 1564 | - $invoicedata = $invoicedata->result_array(); |
|
| 1565 | - $invoicedata=$invoicedata[0]; |
|
| 1560 | + $currency = $accountdata["currency_id"]; |
|
| 1561 | + } |
|
| 1562 | + $invoice_cdr_list = array(); |
|
| 1563 | + $invoicedata = $this->db_model->getSelect("*", "invoices", array("id"=> $invoiceid)); |
|
| 1564 | + $invoicedata = $invoicedata->result_array(); |
|
| 1565 | + $invoicedata=$invoicedata[0]; |
|
| 1566 | 1566 | |
| 1567 | - $data['invoiceid'] = @$invoicedata[0]['id']; |
|
| 1568 | - $data['id'] = @$invoicedata['invoiceid']; |
|
| 1567 | + $data['invoiceid'] = @$invoicedata[0]['id']; |
|
| 1568 | + $data['id'] = @$invoicedata['invoiceid']; |
|
| 1569 | 1569 | |
| 1570 | - $data['invoice_date'] = @$invoicedata[0]['invoice_date']; |
|
| 1571 | - $data['accountid'] = @$invoicedata[0]['accountid']; |
|
| 1570 | + $data['invoice_date'] = @$invoicedata[0]['invoice_date']; |
|
| 1571 | + $data['accountid'] = @$invoicedata[0]['accountid']; |
|
| 1572 | 1572 | $data['from_date'] = @$invoicedata[0]['from_date']; |
| 1573 | 1573 | $data['to_date'] = @$invoicedata[0]['to_date']; |
| 1574 | - $total_list = array(); |
|
| 1575 | - $data['description']=''; |
|
| 1576 | - $data['item_type']=''; |
|
| 1577 | - $data['debit']=''; |
|
| 1578 | - $invoice_total_list = array(); |
|
| 1574 | + $total_list = array(); |
|
| 1575 | + $data['description']=''; |
|
| 1576 | + $data['item_type']=''; |
|
| 1577 | + $data['debit']=''; |
|
| 1578 | + $invoice_total_list = array(); |
|
| 1579 | 1579 | $query="select item_type,description,created_date,invoiceid,debit,credit from invoice_details where invoiceid = ".$invoiceid." And ( item_type='POSTCHARG' Or item_type='Refill') Group By item_type"; |
| 1580 | 1580 | $invoice_total_query=$this->db->query($query); |
| 1581 | 1581 | if($invoice_total_query ->num_rows() > 0) { |
@@ -136,14 +136,14 @@ discard block |
||
| 136 | 136 | // -------------------------------------------------------------------- |
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | - * Fetch an item from the GET array |
|
| 140 | - * |
|
| 141 | - * @access public |
|
| 142 | - * @param string |
|
| 143 | - * @param bool |
|
| 144 | - * @param string $index |
|
| 145 | - * @return string |
|
| 146 | - */ |
|
| 139 | + * Fetch an item from the GET array |
|
| 140 | + * |
|
| 141 | + * @access public |
|
| 142 | + * @param string |
|
| 143 | + * @param bool |
|
| 144 | + * @param string $index |
|
| 145 | + * @return string |
|
| 146 | + */ |
|
| 147 | 147 | function get($index = NULL, $xss_clean = FALSE) |
| 148 | 148 | { |
| 149 | 149 | // Check if a field has been provided |
@@ -165,14 +165,14 @@ discard block |
||
| 165 | 165 | // -------------------------------------------------------------------- |
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | - * Fetch an item from the POST array |
|
| 169 | - * |
|
| 170 | - * @access public |
|
| 171 | - * @param string |
|
| 172 | - * @param bool |
|
| 173 | - * @param string $index |
|
| 174 | - * @return string |
|
| 175 | - */ |
|
| 168 | + * Fetch an item from the POST array |
|
| 169 | + * |
|
| 170 | + * @access public |
|
| 171 | + * @param string |
|
| 172 | + * @param bool |
|
| 173 | + * @param string $index |
|
| 174 | + * @return string |
|
| 175 | + */ |
|
| 176 | 176 | function post($index = NULL, $xss_clean = FALSE) |
| 177 | 177 | { |
| 178 | 178 | // Check if a field has been provided |
@@ -361,14 +361,14 @@ discard block |
||
| 361 | 361 | // -------------------------------------------------------------------- |
| 362 | 362 | |
| 363 | 363 | /** |
| 364 | - * Validate IP Address |
|
| 365 | - * |
|
| 366 | - * Updated version suggested by Geert De Deckere |
|
| 367 | - * |
|
| 368 | - * @access public |
|
| 369 | - * @param string |
|
| 370 | - * @return boolean |
|
| 371 | - */ |
|
| 364 | + * Validate IP Address |
|
| 365 | + * |
|
| 366 | + * Updated version suggested by Geert De Deckere |
|
| 367 | + * |
|
| 368 | + * @access public |
|
| 369 | + * @param string |
|
| 370 | + * @return boolean |
|
| 371 | + */ |
|
| 372 | 372 | function valid_ip($ip) |
| 373 | 373 | { |
| 374 | 374 | $ip_segments = explode('.', $ip); |