PageRenderTime 31ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/abu-saleh77/termsCondition/vendor/mpdf/mpdf/classes/cssmgr.php

https://gitlab.com/cserobiul/Bitm-PHP-CRUD-Practice
PHP | 1364 lines | 1207 code | 56 blank | 101 comment | 602 complexity | d4d5cbda3d146989a4c9667d20d88c4b MD5 | raw file
  1. <?php
  2. class cssmgr
  3. {
  4. var $mpdf = null;
  5. var $tablecascadeCSS;
  6. var $cascadeCSS;
  7. var $CSS;
  8. var $tbCSSlvl;
  9. public function __construct(mPDF $mpdf)
  10. {
  11. $this->mpdf = $mpdf;
  12. $this->tablecascadeCSS = array();
  13. $this->CSS = array();
  14. $this->cascadeCSS = array();
  15. $this->tbCSSlvl = 0;
  16. }
  17. function ReadCSS($html)
  18. {
  19. preg_match_all('/<style[^>]*media=["\']([^"\'>]*)["\'].*?<\/style>/is', $html, $m);
  20. for ($i = 0; $i < count($m[0]); $i++) {
  21. if ($this->mpdf->CSSselectMedia && !preg_match('/(' . trim($this->mpdf->CSSselectMedia) . '|all)/i', $m[1][$i])) {
  22. $html = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', '', $html);
  23. }
  24. }
  25. preg_match_all('/<link[^>]*media=["\']([^"\'>]*)["\'].*?>/is', $html, $m);
  26. for ($i = 0; $i < count($m[0]); $i++) {
  27. if ($this->mpdf->CSSselectMedia && !preg_match('/(' . trim($this->mpdf->CSSselectMedia) . '|all)/i', $m[1][$i])) {
  28. $html = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', '', $html);
  29. }
  30. }
  31. // mPDF 5.5.02
  32. // Remove Comment tags <!-- ... --> inside CSS as <style> in HTML document
  33. // Remove Comment tags /* ... */ inside CSS as <style> in HTML document
  34. // But first, we replace upper and mixed case closing style tag with lower
  35. // case so we can use str_replace later.
  36. preg_match_all('/<style.*?>(.*?)<\/style>/si',$html,$m);
  37. if (count($m[1])) {
  38. for ($i = 0; $i < count($m[1]); $i++) {
  39. // Remove comment tags
  40. $sub = preg_replace('/(<\!\-\-|\-\->)/s',' ',$m[1][$i]);
  41. $sub = '>'.preg_replace('|/\*.*?\*/|s',' ',$sub).'</style>';
  42. $html = str_replace('>'.$m[1][$i].'</style>', $sub, $html);
  43. }
  44. }
  45. $html = preg_replace('/<!--mpdf/i', '', $html);
  46. $html = preg_replace('/mpdf-->/i', '', $html);
  47. $html = preg_replace('/<\!\-\-.*?\-\->/s', ' ', $html);
  48. $match = 0; // no match for instance
  49. $regexp = ''; // This helps debugging: showing what is the REAL string being processed
  50. $CSSext = array();
  51. //CSS inside external files
  52. $regexp = '/<link[^>]*rel=["\']stylesheet["\'][^>]*href=["\']([^>"\']*)["\'].*?>/si';
  53. $x = preg_match_all($regexp, $html, $cxt);
  54. if ($x) {
  55. $match += $x;
  56. $CSSext = $cxt[1];
  57. }
  58. $regexp = '/<link[^>]*href=["\']([^>"\']*)["\'][^>]*?rel=["\']stylesheet["\'].*?>/si';
  59. $x = preg_match_all($regexp, $html, $cxt);
  60. if ($x) {
  61. $match += $x;
  62. $CSSext = array_merge($CSSext, $cxt[1]);
  63. }
  64. // look for @import stylesheets
  65. //$regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css)[\'\"]{0,1}\)/si';
  66. $regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css(\?\S+)?)[\'\"]{0,1}\)/si';
  67. $x = preg_match_all($regexp, $html, $cxt);
  68. if ($x) {
  69. $match += $x;
  70. $CSSext = array_merge($CSSext, $cxt[1]);
  71. }
  72. // look for @import without the url()
  73. //$regexp = '/@import [\'\"]{0,1}([^;]*?\.css)[\'\"]{0,1}/si';
  74. $regexp = '/@import [\'\"]{0,1}([^;]*?\.css(\?\S+)?)[\'\"]{0,1}/si';
  75. $x = preg_match_all($regexp, $html, $cxt);
  76. if ($x) {
  77. $match += $x;
  78. $CSSext = array_merge($CSSext, $cxt[1]);
  79. }
  80. $ind = 0;
  81. $CSSstr = '';
  82. if (!is_array($this->cascadeCSS))
  83. $this->cascadeCSS = array();
  84. while ($match) {
  85. $path = $CSSext[$ind];
  86. $path = htmlspecialchars_decode($path); // mPDF 6
  87. $this->mpdf->GetFullPath($path);
  88. $CSSextblock = $this->mpdf->_get_file($path);
  89. if ($CSSextblock) {
  90. // look for embedded @import stylesheets in other stylesheets
  91. // and fix url paths (including background-images) relative to stylesheet
  92. //$regexpem = '/@import url\([\'\"]{0,1}(.*?\.css)[\'\"]{0,1}\)/si';
  93. $regexpem = '/@import url\([\'\"]{0,1}(.*?\.css(\?\S+)?)[\'\"]{0,1}\)/si';
  94. $xem = preg_match_all($regexpem, $CSSextblock, $cxtem);
  95. $cssBasePath = preg_replace('/\/[^\/]*$/', '', $path) . '/';
  96. if ($xem) {
  97. foreach ($cxtem[1] AS $cxtembedded) {
  98. // path is relative to original stlyesheet!!
  99. $this->mpdf->GetFullPath($cxtembedded, $cssBasePath);
  100. $match++;
  101. $CSSext[] = $cxtembedded;
  102. }
  103. }
  104. $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
  105. $xem = preg_match_all($regexpem, $CSSextblock, $cxtem);
  106. if ($xem) {
  107. for ($i = 0; $i < count($cxtem[0]); $i++) {
  108. // path is relative to original stlyesheet!!
  109. $embedded = $cxtem[2][$i];
  110. if (!preg_match('/^data:image/i', $embedded)) { // mPDF 5.5.13
  111. $this->mpdf->GetFullPath($embedded, $cssBasePath);
  112. $CSSextblock = preg_replace('/' . preg_quote($cxtem[0][$i], '/') . '/', ($cxtem[1][$i] . $embedded . $cxtem[3][$i]), $CSSextblock);
  113. }
  114. }
  115. }
  116. $CSSstr .= ' ' . $CSSextblock;
  117. }
  118. $match--;
  119. $ind++;
  120. } //end of match
  121. $match = 0; // reset value, if needed
  122. // CSS as <style> in HTML document
  123. $regexp = '/<style.*?>(.*?)<\/style>/si';
  124. $match = preg_match_all($regexp, $html, $CSSblock);
  125. if ($match) {
  126. $tmpCSSstr = implode(' ', $CSSblock[1]);
  127. $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
  128. $xem = preg_match_all($regexpem, $tmpCSSstr, $cxtem);
  129. if ($xem) {
  130. for ($i = 0; $i < count($cxtem[0]); $i++) {
  131. $embedded = $cxtem[2][$i];
  132. if (!preg_match('/^data:image/i', $embedded)) { // mPDF 5.5.13
  133. $this->mpdf->GetFullPath($embedded);
  134. $tmpCSSstr = preg_replace('/' . preg_quote($cxtem[0][$i], '/') . '/', ($cxtem[1][$i] . $embedded . $cxtem[3][$i]), $tmpCSSstr);
  135. }
  136. }
  137. }
  138. $CSSstr .= ' ' . $tmpCSSstr;
  139. }
  140. // Remove comments
  141. $CSSstr = preg_replace('|/\*.*?\*/|s', ' ', $CSSstr);
  142. $CSSstr = preg_replace('/[\s\n\r\t\f]/s', ' ', $CSSstr);
  143. if (preg_match('/@media/', $CSSstr)) {
  144. preg_match_all('/@media(.*?)\{(([^\{\}]*\{[^\{\}]*\})+)\s*\}/is', $CSSstr, $m);
  145. for ($i = 0; $i < count($m[0]); $i++) {
  146. if ($this->mpdf->CSSselectMedia && !preg_match('/(' . trim($this->mpdf->CSSselectMedia) . '|all)/i', $m[1][$i])) {
  147. $CSSstr = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', '', $CSSstr);
  148. } else {
  149. $CSSstr = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', ' ' . $m[2][$i] . ' ', $CSSstr);
  150. }
  151. }
  152. }
  153. // Replace any background: url(data:image... with temporary image file reference
  154. preg_match_all("/(url\(data:image\/(jpeg|gif|png);base64,(.*?)\))/si", $CSSstr, $idata); // mPDF 5.7.2
  155. if (count($idata[0])) {
  156. for ($i = 0; $i < count($idata[0]); $i++) {
  157. $file = _MPDF_TEMP_PATH . '_tempCSSidata' . RAND(1, 10000) . '_' . $i . '.' . $idata[2][$i];
  158. //Save to local file
  159. file_put_contents($file, base64_decode($idata[3][$i]));
  160. // $this->mpdf->GetFullPath($file); // ? is this needed - NO mPDF 5.6.03
  161. $CSSstr = str_replace($idata[0][$i], 'url("' . $file . '")', $CSSstr); // mPDF 5.5.17
  162. }
  163. }
  164. $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s', ' ', $CSSstr);
  165. // mPDF 5.7.4 URLs
  166. // Characters "(" ")" and ";" in url() e.g. background-image, cause problems parsing the CSS string
  167. // URLencode ( and ), but change ";" to a code which can be converted back after parsing (so as not to confuse ;
  168. // with a segment delimiter in the URI)
  169. $tempmarker = '%ZZ';
  170. if (strpos($CSSstr, 'url(') !== false) {
  171. preg_match_all('/url\(\"(.*?)\"\)/', $CSSstr, $m);
  172. for ($i = 0; $i < count($m[1]); $i++) {
  173. $tmp = str_replace(array('(', ')', ';'), array('%28', '%29', $tempmarker), $m[1][$i]);
  174. $CSSstr = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', 'url(\'' . $tmp . '\')', $CSSstr);
  175. }
  176. preg_match_all('/url\(\'(.*?)\'\)/', $CSSstr, $m);
  177. for ($i = 0; $i < count($m[1]); $i++) {
  178. $tmp = str_replace(array('(', ')', ';'), array('%28', '%29', $tempmarker), $m[1][$i]);
  179. $CSSstr = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', 'url(\'' . $tmp . '\')', $CSSstr);
  180. }
  181. preg_match_all('/url\(([^\'\"].*?[^\'\"])\)/', $CSSstr, $m);
  182. for ($i = 0; $i < count($m[1]); $i++) {
  183. $tmp = str_replace(array('(', ')', ';'), array('%28', '%29', $tempmarker), $m[1][$i]);
  184. $CSSstr = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', 'url(\'' . $tmp . '\')', $CSSstr);
  185. }
  186. }
  187. if ($CSSstr) {
  188. $classproperties = array(); // mPDF 6
  189. preg_match_all('/(.*?)\{(.*?)\}/', $CSSstr, $styles);
  190. for ($i = 0; $i < count($styles[1]); $i++) {
  191. // SET array e.g. $classproperties['COLOR'] = '#ffffff';
  192. $stylestr = trim($styles[2][$i]);
  193. $stylearr = explode(';', $stylestr);
  194. foreach ($stylearr AS $sta) {
  195. if (trim($sta)) {
  196. // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')"
  197. $tmp = explode(':', $sta, 2);
  198. $property = $tmp[0];
  199. if (isset($tmp[1])) {
  200. $value = $tmp[1];
  201. } else {
  202. $value = '';
  203. }
  204. $value = str_replace($tempmarker, ';', $value); // mPDF 5.7.4 URLs
  205. $property = trim($property);
  206. $value = preg_replace('/\s*!important/i', '', $value);
  207. $value = trim($value);
  208. if ($property && ($value || $value === '0')) {
  209. // Ignores -webkit-gradient so doesn't override -moz-
  210. if ((strtoupper($property) == 'BACKGROUND-IMAGE' || strtoupper($property) == 'BACKGROUND') && preg_match('/-webkit-gradient/i', $value)) {
  211. continue;
  212. }
  213. $classproperties[strtoupper($property)] = $value;
  214. }
  215. }
  216. }
  217. $classproperties = $this->fixCSS($classproperties);
  218. $tagstr = strtoupper(trim($styles[1][$i]));
  219. $tagarr = explode(',', $tagstr);
  220. $pageselectors = false; // used to turn on $this->mpdf->mirrorMargins
  221. foreach ($tagarr AS $tg) {
  222. // mPDF 5.7.4
  223. if (preg_match('/NTH-CHILD\((\s*(([\-+]?\d*)N(\s*[\-+]\s*\d+)?|[\-+]?\d+|ODD|EVEN)\s*)\)/', $tg, $m)) {
  224. $tg = preg_replace('/NTH-CHILD\(.*\)/', 'NTH-CHILD(' . str_replace(' ', '', $m[1]) . ')', $tg);
  225. }
  226. $tags = preg_split('/\s+/', trim($tg));
  227. $level = count($tags);
  228. $t = '';
  229. $t2 = '';
  230. $t3 = '';
  231. if (trim($tags[0]) == '@PAGE') {
  232. if (isset($tags[0])) {
  233. $t = trim($tags[0]);
  234. }
  235. if (isset($tags[1])) {
  236. $t2 = trim($tags[1]);
  237. }
  238. if (isset($tags[2])) {
  239. $t3 = trim($tags[2]);
  240. }
  241. $tag = '';
  242. if ($level == 1) {
  243. $tag = $t;
  244. } else if ($level == 2 && preg_match('/^[:](.*)$/', $t2, $m)) {
  245. $tag = $t . '>>PSEUDO>>' . $m[1];
  246. if ($m[1] == 'LEFT' || $m[1] == 'RIGHT') {
  247. $pageselectors = true;
  248. } // used to turn on $this->mpdf->mirrorMargins
  249. } else if ($level == 2) {
  250. $tag = $t . '>>NAMED>>' . $t2;
  251. } else if ($level == 3 && preg_match('/^[:](.*)$/', $t3, $m)) {
  252. $tag = $t . '>>NAMED>>' . $t2 . '>>PSEUDO>>' . $m[1];
  253. if ($m[1] == 'LEFT' || $m[1] == 'RIGHT') {
  254. $pageselectors = true;
  255. } // used to turn on $this->mpdf->mirrorMargins
  256. }
  257. if (isset($this->CSS[$tag]) && $tag) {
  258. $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties);
  259. } else if ($tag) {
  260. $this->CSS[$tag] = $classproperties;
  261. }
  262. } else if ($level == 1) { // e.g. p or .class or #id or p.class or p#id
  263. if (isset($tags[0])) {
  264. $t = trim($tags[0]);
  265. }
  266. if ($t) {
  267. $tag = '';
  268. if (preg_match('/^[.](.*)$/', $t, $m)) {
  269. $tag = 'CLASS>>' . $m[1];
  270. } else if (preg_match('/^[#](.*)$/', $t, $m)) {
  271. $tag = 'ID>>' . $m[1];
  272. } else if (preg_match('/^\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/', $t, $m)) {
  273. $tag = 'LANG>>' . strtolower($m[1]);
  274. } // mPDF 6 Special case for lang as attribute selector
  275. else if (preg_match('/^:LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/', $t, $m)) {
  276. $tag = 'LANG>>' . strtolower($m[1]);
  277. } // mPDF 6 Special case for lang as attribute selector
  278. else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')[.](.*)$/', $t, $m)) {
  279. $tag = $m[1] . '>>CLASS>>' . $m[2];
  280. } else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')\s*:NTH-CHILD\((.*)\)$/', $t, $m)) {
  281. $tag = $m[1] . '>>SELECTORNTHCHILD>>' . $m[2];
  282. } else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')[#](.*)$/', $t, $m)) {
  283. $tag = $m[1] . '>>ID>>' . $m[2];
  284. } else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/', $t, $m)) {
  285. $tag = $m[1] . '>>LANG>>' . strtolower($m[2]);
  286. } // mPDF 6 Special case for lang as attribute selector
  287. else if (preg_match('/^(' . $this->mpdf->allowedCSStags . '):LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/', $t, $m)) {
  288. $tag = $m[1] . '>>LANG>>' . strtolower($m[2]);
  289. } // mPDF 6 Special case for lang as attribute selector
  290. else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')$/', $t)) {
  291. $tag = $t;
  292. }
  293. if (isset($this->CSS[$tag]) && $tag) {
  294. $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties);
  295. } else if ($tag) {
  296. $this->CSS[$tag] = $classproperties;
  297. }
  298. }
  299. } else {
  300. $tmp = array();
  301. for ($n = 0; $n < $level; $n++) {
  302. if (isset($tags[$n])) {
  303. $t = trim($tags[$n]);
  304. } else {
  305. $t = '';
  306. }
  307. if ($t) {
  308. $tag = '';
  309. if (preg_match('/^[.](.*)$/', $t, $m)) {
  310. $tag = 'CLASS>>' . $m[1];
  311. } else if (preg_match('/^[#](.*)$/', $t, $m)) {
  312. $tag = 'ID>>' . $m[1];
  313. } else if (preg_match('/^\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/', $t, $m)) {
  314. $tag = 'LANG>>' . strtolower($m[1]);
  315. } // mPDF 6 Special case for lang as attribute selector
  316. else if (preg_match('/^:LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/', $t, $m)) {
  317. $tag = 'LANG>>' . strtolower($m[1]);
  318. } // mPDF 6 Special case for lang as attribute selector
  319. else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')[.](.*)$/', $t, $m)) {
  320. $tag = $m[1] . '>>CLASS>>' . $m[2];
  321. } else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')\s*:NTH-CHILD\((.*)\)$/', $t, $m)) {
  322. $tag = $m[1] . '>>SELECTORNTHCHILD>>' . $m[2];
  323. } else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')[#](.*)$/', $t, $m)) {
  324. $tag = $m[1] . '>>ID>>' . $m[2];
  325. } else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/', $t, $m)) {
  326. $tag = $m[1] . '>>LANG>>' . strtolower($m[2]);
  327. } // mPDF 6 Special case for lang as attribute selector
  328. else if (preg_match('/^(' . $this->mpdf->allowedCSStags . '):LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/', $t, $m)) {
  329. $tag = $m[1] . '>>LANG>>' . strtolower($m[2]);
  330. } // mPDF 6 Special case for lang as attribute selector
  331. else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')$/', $t)) {
  332. $tag = $t;
  333. }
  334. if ($tag)
  335. $tmp[] = $tag;
  336. else {
  337. break;
  338. }
  339. }
  340. }
  341. if ($tag) {
  342. $x = &$this->cascadeCSS;
  343. foreach ($tmp AS $tp) {
  344. $x = &$x[$tp];
  345. }
  346. $x = $this->array_merge_recursive_unique($x, $classproperties);
  347. $x['depth'] = $level;
  348. }
  349. }
  350. }
  351. if ($pageselectors) {
  352. $this->mpdf->mirrorMargins = true;
  353. }
  354. $properties = array();
  355. $values = array();
  356. $classproperties = array();
  357. }
  358. } // end of if
  359. //Remove CSS (tags and content), if any
  360. $regexp = '/<style.*?>(.*?)<\/style>/si'; // it can be <style> or <style type="txt/css">
  361. $html = preg_replace($regexp, '', $html);
  362. //print_r($this->CSS); exit;
  363. //print_r($this->cascadeCSS); exit;
  364. return $html;
  365. }
  366. function readInlineCSS($html)
  367. {
  368. $html = htmlspecialchars_decode($html); // mPDF 5.7.4 URLs
  369. // mPDF 5.7.4 URLs
  370. // Characters "(" ")" and ";" in url() e.g. background-image, cause probems parsing the CSS string
  371. // URLencode ( and ), but change ";" to a code which can be converted back after parsing (so as not to confuse ;
  372. // with a segment delimiter in the URI)
  373. $tempmarker = '%ZZ';
  374. if (strpos($html, 'url(') !== false) {
  375. preg_match_all('/url\(\"(.*?)\"\)/', $html, $m);
  376. for ($i = 0; $i < count($m[1]); $i++) {
  377. $tmp = str_replace(array('(', ')', ';'), array('%28', '%29', $tempmarker), $m[1][$i]);
  378. $html = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', 'url(\'' . $tmp . '\')', $html);
  379. }
  380. preg_match_all('/url\(\'(.*?)\'\)/', $html, $m);
  381. for ($i = 0; $i < count($m[1]); $i++) {
  382. $tmp = str_replace(array('(', ')', ';'), array('%28', '%29', $tempmarker), $m[1][$i]);
  383. $html = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', 'url(\'' . $tmp . '\')', $html);
  384. }
  385. preg_match_all('/url\(([^\'\"].*?[^\'\"])\)/', $html, $m);
  386. for ($i = 0; $i < count($m[1]); $i++) {
  387. $tmp = str_replace(array('(', ')', ';'), array('%28', '%29', $tempmarker), $m[1][$i]);
  388. $html = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', 'url(\'' . $tmp . '\')', $html);
  389. }
  390. }
  391. //Fix incomplete CSS code
  392. $size = strlen($html) - 1;
  393. if (substr($html, $size, 1) != ';')
  394. $html .= ';';
  395. //Make CSS[Name-of-the-class] = array(key => value)
  396. $regexp = '|\\s*?(\\S+?):(.+?);|i';
  397. preg_match_all($regexp, $html, $styleinfo);
  398. $properties = $styleinfo[1];
  399. $values = $styleinfo[2];
  400. //Array-properties and Array-values must have the SAME SIZE!
  401. $classproperties = array();
  402. for ($i = 0; $i < count($properties); $i++) {
  403. // Ignores -webkit-gradient so doesn't override -moz-
  404. if ((strtoupper($properties[$i]) == 'BACKGROUND-IMAGE' || strtoupper($properties[$i]) == 'BACKGROUND') && preg_match('/-webkit-gradient/i', $values[$i])) {
  405. continue;
  406. }
  407. $values[$i] = str_replace($tempmarker, ';', $values[$i]); // mPDF 5.7.4 URLs
  408. $classproperties[strtoupper($properties[$i])] = trim($values[$i]);
  409. }
  410. return $this->fixCSS($classproperties);
  411. }
  412. function _fix_borderStr($bd)
  413. {
  414. preg_match_all("/\((.*?)\)/", $bd, $m);
  415. if (count($m[1])) {
  416. for ($i = 0; $i < count($m[1]); $i++) {
  417. $sub = preg_replace("/ /", "", $m[1][$i]);
  418. $bd = preg_replace('/' . preg_quote($m[1][$i], '/') . '/si', $sub, $bd);
  419. }
  420. }
  421. $prop = preg_split('/\s+/', trim($bd));
  422. $w = 'medium';
  423. $c = '#000000';
  424. $s = 'none';
  425. if (count($prop) == 1) {
  426. // solid
  427. if (in_array($prop[0], $this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden') {
  428. $s = $prop[0];
  429. }
  430. // #000000
  431. else if (is_array($this->mpdf->ConvertColor($prop[0]))) {
  432. $c = $prop[0];
  433. }
  434. // 1px
  435. else {
  436. $w = $prop[0];
  437. }
  438. } else if (count($prop) == 2) {
  439. // 1px solid
  440. if (in_array($prop[1], $this->mpdf->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden') {
  441. $w = $prop[0];
  442. $s = $prop[1];
  443. }
  444. // solid #000000
  445. else if (in_array($prop[0], $this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden') {
  446. $s = $prop[0];
  447. $c = $prop[1];
  448. }
  449. // 1px #000000
  450. else {
  451. $w = $prop[0];
  452. $c = $prop[1];
  453. }
  454. } else if (count($prop) == 3) {
  455. // Change #000000 1px solid to 1px solid #000000 (proper)
  456. if (substr($prop[0], 0, 1) == '#') {
  457. $c = $prop[0];
  458. $w = $prop[1];
  459. $s = $prop[2];
  460. }
  461. // Change solid #000000 1px to 1px solid #000000 (proper)
  462. else if (substr($prop[0], 1, 1) == '#') {
  463. $s = $prop[0];
  464. $c = $prop[1];
  465. $w = $prop[2];
  466. }
  467. // Change solid 1px #000000 to 1px solid #000000 (proper)
  468. else if (in_array($prop[0], $this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden') {
  469. $s = $prop[0];
  470. $w = $prop[1];
  471. $c = $prop[2];
  472. } else {
  473. $w = $prop[0];
  474. $s = $prop[1];
  475. $c = $prop[2];
  476. }
  477. } else {
  478. return '';
  479. }
  480. $s = strtolower($s);
  481. return $w . ' ' . $s . ' ' . $c;
  482. }
  483. function fixCSS($prop)
  484. {
  485. if (!is_array($prop) || (count($prop) == 0))
  486. return array();
  487. $newprop = array();
  488. foreach ($prop AS $k => $v) {
  489. if ($k != 'BACKGROUND-IMAGE' && $k != 'BACKGROUND' && $k != 'ODD-HEADER-NAME' && $k != 'EVEN-HEADER-NAME' && $k != 'ODD-FOOTER-NAME' && $k != 'EVEN-FOOTER-NAME' && $k != 'HEADER' && $k != 'FOOTER') {
  490. $v = strtolower($v);
  491. }
  492. if ($k == 'FONT') {
  493. $s = trim($v);
  494. preg_match_all('/\"(.*?)\"/', $s, $ff);
  495. if (count($ff[1])) {
  496. foreach ($ff[1] AS $ffp) {
  497. $w = preg_split('/\s+/', $ffp);
  498. $s = preg_replace('/\"' . $ffp . '\"/', $w[0], $s);
  499. }
  500. }
  501. preg_match_all('/\'(.*?)\'/', $s, $ff);
  502. if (count($ff[1])) {
  503. foreach ($ff[1] AS $ffp) {
  504. $w = preg_split('/\s+/', $ffp);
  505. $s = preg_replace('/\'' . $ffp . '\'/', $w[0], $s);
  506. }
  507. }
  508. $s = preg_replace('/\s*,\s*/', ',', $s);
  509. $bits = preg_split('/\s+/', $s);
  510. if (count($bits) > 1) {
  511. $k = 'FONT-FAMILY';
  512. $v = $bits[(count($bits) - 1)];
  513. $fs = $bits[(count($bits) - 2)];
  514. if (preg_match('/(.*?)\/(.*)/', $fs, $fsp)) {
  515. $newprop['FONT-SIZE'] = $fsp[1];
  516. $newprop['LINE-HEIGHT'] = $fsp[2];
  517. } else {
  518. $newprop['FONT-SIZE'] = $fs;
  519. }
  520. if (preg_match('/(italic|oblique)/i', $s)) {
  521. $newprop['FONT-STYLE'] = 'italic';
  522. } else {
  523. $newprop['FONT-STYLE'] = 'normal';
  524. }
  525. if (preg_match('/bold/i', $s)) {
  526. $newprop['FONT-WEIGHT'] = 'bold';
  527. } else {
  528. $newprop['FONT-WEIGHT'] = 'normal';
  529. }
  530. if (preg_match('/small-caps/i', $s)) {
  531. $newprop['TEXT-TRANSFORM'] = 'uppercase';
  532. }
  533. }
  534. } else if ($k == 'FONT-FAMILY') {
  535. $aux_fontlist = explode(",", $v);
  536. $found = 0;
  537. foreach ($aux_fontlist AS $f) {
  538. $fonttype = trim($f);
  539. $fonttype = preg_replace('/["\']*(.*?)["\']*/', '\\1', $fonttype);
  540. $fonttype = preg_replace('/ /', '', $fonttype);
  541. $v = strtolower(trim($fonttype));
  542. if (isset($this->mpdf->fonttrans[$v]) && $this->mpdf->fonttrans[$v]) {
  543. $v = $this->mpdf->fonttrans[$v];
  544. }
  545. if ((!$this->mpdf->onlyCoreFonts && in_array($v, $this->mpdf->available_unifonts)) ||
  546. in_array($v, array('ccourier', 'ctimes', 'chelvetica')) ||
  547. ($this->mpdf->onlyCoreFonts && in_array($v, array('courier', 'times', 'helvetica', 'arial'))) ||
  548. in_array($v, array('sjis', 'uhc', 'big5', 'gb'))) {
  549. $newprop[$k] = $v;
  550. $found = 1;
  551. break;
  552. }
  553. }
  554. if (!$found) {
  555. foreach ($aux_fontlist AS $f) {
  556. $fonttype = trim($f);
  557. $fonttype = preg_replace('/["\']*(.*?)["\']*/', '\\1', $fonttype);
  558. $fonttype = preg_replace('/ /', '', $fonttype);
  559. $v = strtolower(trim($fonttype));
  560. if (isset($this->mpdf->fonttrans[$v]) && $this->mpdf->fonttrans[$v]) {
  561. $v = $this->mpdf->fonttrans[$v];
  562. }
  563. if (in_array($v, $this->mpdf->sans_fonts) || in_array($v, $this->mpdf->serif_fonts) || in_array($v, $this->mpdf->mono_fonts)) {
  564. $newprop[$k] = $v;
  565. break;
  566. }
  567. }
  568. }
  569. }
  570. // mPDF 5.7.1
  571. else if ($k == 'FONT-VARIANT') {
  572. if (preg_match('/(normal|none)/', $v, $m)) { // mPDF 6
  573. $newprop['FONT-VARIANT-LIGATURES'] = $m[1];
  574. $newprop['FONT-VARIANT-CAPS'] = $m[1];
  575. $newprop['FONT-VARIANT-NUMERIC'] = $m[1];
  576. $newprop['FONT-VARIANT-ALTERNATES'] = $m[1];
  577. } else {
  578. if (preg_match_all('/(no-common-ligatures|\bcommon-ligatures|no-discretionary-ligatures|\bdiscretionary-ligatures|no-historical-ligatures|\bhistorical-ligatures|no-contextual|\bcontextual)/i', $v, $m)) {
  579. $newprop['FONT-VARIANT-LIGATURES'] = implode(' ', $m[1]);
  580. }
  581. if (preg_match('/(all-small-caps|\bsmall-caps|all-petite-caps|\bpetite-caps|unicase|titling-caps)/i', $v, $m)) {
  582. $newprop['FONT-VARIANT-CAPS'] = $m[1];
  583. }
  584. if (preg_match_all('/(lining-nums|oldstyle-nums|proportional-nums|tabular-nums|diagonal-fractions|stacked-fractions)/i', $v, $m)) {
  585. $newprop['FONT-VARIANT-NUMERIC'] = implode(' ', $m[1]);
  586. }
  587. if (preg_match('/(historical-forms)/i', $v, $m)) {
  588. $newprop['FONT-VARIANT-ALTERNATES'] = $m[1];
  589. }
  590. }
  591. } else if ($k == 'MARGIN') {
  592. $tmp = $this->expand24($v);
  593. $newprop['MARGIN-TOP'] = $tmp['T'];
  594. $newprop['MARGIN-RIGHT'] = $tmp['R'];
  595. $newprop['MARGIN-BOTTOM'] = $tmp['B'];
  596. $newprop['MARGIN-LEFT'] = $tmp['L'];
  597. }
  598. /* -- BORDER-RADIUS -- */ else if ($k == 'BORDER-RADIUS' || $k == 'BORDER-TOP-LEFT-RADIUS' || $k == 'BORDER-TOP-RIGHT-RADIUS' || $k == 'BORDER-BOTTOM-LEFT-RADIUS' || $k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
  599. $tmp = $this->border_radius_expand($v, $k);
  600. if (isset($tmp['TL-H']))
  601. $newprop['BORDER-TOP-LEFT-RADIUS-H'] = $tmp['TL-H'];
  602. if (isset($tmp['TL-V']))
  603. $newprop['BORDER-TOP-LEFT-RADIUS-V'] = $tmp['TL-V'];
  604. if (isset($tmp['TR-H']))
  605. $newprop['BORDER-TOP-RIGHT-RADIUS-H'] = $tmp['TR-H'];
  606. if (isset($tmp['TR-V']))
  607. $newprop['BORDER-TOP-RIGHT-RADIUS-V'] = $tmp['TR-V'];
  608. if (isset($tmp['BL-H']))
  609. $newprop['BORDER-BOTTOM-LEFT-RADIUS-H'] = $tmp['BL-H'];
  610. if (isset($tmp['BL-V']))
  611. $newprop['BORDER-BOTTOM-LEFT-RADIUS-V'] = $tmp['BL-V'];
  612. if (isset($tmp['BR-H']))
  613. $newprop['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $tmp['BR-H'];
  614. if (isset($tmp['BR-V']))
  615. $newprop['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $tmp['BR-V'];
  616. }
  617. /* -- END BORDER-RADIUS -- */
  618. else if ($k == 'PADDING') {
  619. $tmp = $this->expand24($v);
  620. $newprop['PADDING-TOP'] = $tmp['T'];
  621. $newprop['PADDING-RIGHT'] = $tmp['R'];
  622. $newprop['PADDING-BOTTOM'] = $tmp['B'];
  623. $newprop['PADDING-LEFT'] = $tmp['L'];
  624. } else if ($k == 'BORDER') {
  625. if ($v == '1') {
  626. $v = '1px solid #000000';
  627. } else {
  628. $v = $this->_fix_borderStr($v);
  629. }
  630. $newprop['BORDER-TOP'] = $v;
  631. $newprop['BORDER-RIGHT'] = $v;
  632. $newprop['BORDER-BOTTOM'] = $v;
  633. $newprop['BORDER-LEFT'] = $v;
  634. } else if ($k == 'BORDER-TOP') {
  635. $newprop['BORDER-TOP'] = $this->_fix_borderStr($v);
  636. } else if ($k == 'BORDER-RIGHT') {
  637. $newprop['BORDER-RIGHT'] = $this->_fix_borderStr($v);
  638. } else if ($k == 'BORDER-BOTTOM') {
  639. $newprop['BORDER-BOTTOM'] = $this->_fix_borderStr($v);
  640. } else if ($k == 'BORDER-LEFT') {
  641. $newprop['BORDER-LEFT'] = $this->_fix_borderStr($v);
  642. } else if ($k == 'BORDER-STYLE') {
  643. $e = $this->expand24($v);
  644. if (!empty($e)) {
  645. $newprop['BORDER-TOP-STYLE'] = $e['T'];
  646. $newprop['BORDER-RIGHT-STYLE'] = $e['R'];
  647. $newprop['BORDER-BOTTOM-STYLE'] = $e['B'];
  648. $newprop['BORDER-LEFT-STYLE'] = $e['L'];
  649. }
  650. } else if ($k == 'BORDER-WIDTH') {
  651. $e = $this->expand24($v);
  652. if (!empty($e)) {
  653. $newprop['BORDER-TOP-WIDTH'] = $e['T'];
  654. $newprop['BORDER-RIGHT-WIDTH'] = $e['R'];
  655. $newprop['BORDER-BOTTOM-WIDTH'] = $e['B'];
  656. $newprop['BORDER-LEFT-WIDTH'] = $e['L'];
  657. }
  658. } else if ($k == 'BORDER-COLOR') {
  659. $e = $this->expand24($v);
  660. if (!empty($e)) {
  661. $newprop['BORDER-TOP-COLOR'] = $e['T'];
  662. $newprop['BORDER-RIGHT-COLOR'] = $e['R'];
  663. $newprop['BORDER-BOTTOM-COLOR'] = $e['B'];
  664. $newprop['BORDER-LEFT-COLOR'] = $e['L'];
  665. }
  666. } else if ($k == 'BORDER-SPACING') {
  667. $prop = preg_split('/\s+/', trim($v));
  668. if (count($prop) == 1) {
  669. $newprop['BORDER-SPACING-H'] = $prop[0];
  670. $newprop['BORDER-SPACING-V'] = $prop[0];
  671. } else if (count($prop) == 2) {
  672. $newprop['BORDER-SPACING-H'] = $prop[0];
  673. $newprop['BORDER-SPACING-V'] = $prop[1];
  674. }
  675. } else if ($k == 'TEXT-OUTLINE') { // mPDF 5.6.07
  676. $prop = preg_split('/\s+/', trim($v));
  677. if (trim(strtolower($v)) == 'none') {
  678. $newprop['TEXT-OUTLINE'] = 'none';
  679. } else if (count($prop) == 2) {
  680. $newprop['TEXT-OUTLINE-WIDTH'] = $prop[0];
  681. $newprop['TEXT-OUTLINE-COLOR'] = $prop[1];
  682. } else if (count($prop) == 3) {
  683. $newprop['TEXT-OUTLINE-WIDTH'] = $prop[0];
  684. $newprop['TEXT-OUTLINE-COLOR'] = $prop[2];
  685. }
  686. } else if ($k == 'SIZE') {
  687. $prop = preg_split('/\s+/', trim($v));
  688. if (preg_match('/(auto|portrait|landscape)/', $prop[0])) {
  689. $newprop['SIZE'] = strtoupper($prop[0]);
  690. } else if (count($prop) == 1) {
  691. $newprop['SIZE']['W'] = $this->mpdf->ConvertSize($prop[0]);
  692. $newprop['SIZE']['H'] = $this->mpdf->ConvertSize($prop[0]);
  693. } else if (count($prop) == 2) {
  694. $newprop['SIZE']['W'] = $this->mpdf->ConvertSize($prop[0]);
  695. $newprop['SIZE']['H'] = $this->mpdf->ConvertSize($prop[1]);
  696. }
  697. } else if ($k == 'SHEET-SIZE') {
  698. $prop = preg_split('/\s+/', trim($v));
  699. if (count($prop) == 2) {
  700. $newprop['SHEET-SIZE'] = array($this->mpdf->ConvertSize($prop[0]), $this->mpdf->ConvertSize($prop[1]));
  701. } else {
  702. if (preg_match('/([0-9a-zA-Z]*)-L/i', $v, $m)) { // e.g. A4-L = A$ landscape
  703. $ft = $this->mpdf->_getPageFormat($m[1]);
  704. $format = array($ft[1], $ft[0]);
  705. } else {
  706. $format = $this->mpdf->_getPageFormat($v);
  707. }
  708. if ($format) {
  709. $newprop['SHEET-SIZE'] = array($format[0] / _MPDFK, $format[1] / _MPDFK);
  710. }
  711. }
  712. } else if ($k == 'BACKGROUND') {
  713. $bg = $this->parseCSSbackground($v);
  714. if ($bg['c']) {
  715. $newprop['BACKGROUND-COLOR'] = $bg['c'];
  716. } else {
  717. $newprop['BACKGROUND-COLOR'] = 'transparent';
  718. }
  719. /* -- BACKGROUNDS -- */
  720. if ($bg['i']) {
  721. $newprop['BACKGROUND-IMAGE'] = $bg['i'];
  722. if ($bg['r']) {
  723. $newprop['BACKGROUND-REPEAT'] = $bg['r'];
  724. }
  725. if ($bg['p']) {
  726. $newprop['BACKGROUND-POSITION'] = $bg['p'];
  727. }
  728. } else {
  729. $newprop['BACKGROUND-IMAGE'] = '';
  730. }
  731. /* -- END BACKGROUNDS -- */
  732. }
  733. /* -- BACKGROUNDS -- */ else if ($k == 'BACKGROUND-IMAGE') {
  734. if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i', $v, $m)) {
  735. $newprop['BACKGROUND-IMAGE'] = $m[0];
  736. continue;
  737. }
  738. if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i', $v, $m)) {
  739. $newprop['BACKGROUND-IMAGE'] = $m[1];
  740. } else if (strtolower($v) == 'none') {
  741. $newprop['BACKGROUND-IMAGE'] = '';
  742. }
  743. } else if ($k == 'BACKGROUND-REPEAT') {
  744. if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/i', $v, $m)) {
  745. $newprop['BACKGROUND-REPEAT'] = strtolower($m[1]);
  746. }
  747. } else if ($k == 'BACKGROUND-POSITION') {
  748. $s = $v;
  749. $bits = preg_split('/\s+/', trim($s));
  750. // These should be Position x1 or x2
  751. if (count($bits) == 1) {
  752. if (preg_match('/bottom/', $bits[0])) {
  753. $bg['p'] = '50% 100%';
  754. } else if (preg_match('/top/', $bits[0])) {
  755. $bg['p'] = '50% 0%';
  756. } else {
  757. $bg['p'] = $bits[0] . ' 50%';
  758. }
  759. } else if (count($bits) == 2) {
  760. // Can be either right center or center right
  761. if (preg_match('/(top|bottom)/', $bits[0]) || preg_match('/(left|right)/', $bits[1])) {
  762. $bg['p'] = $bits[1] . ' ' . $bits[0];
  763. } else {
  764. $bg['p'] = $bits[0] . ' ' . $bits[1];
  765. }
  766. }
  767. if ($bg['p']) {
  768. $bg['p'] = preg_replace('/(left|top)/', '0%', $bg['p']);
  769. $bg['p'] = preg_replace('/(right|bottom)/', '100%', $bg['p']);
  770. $bg['p'] = preg_replace('/(center)/', '50%', $bg['p']);
  771. if (!preg_match('/[\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)* [\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)*/', $bg['p'])) {
  772. $bg['p'] = false;
  773. }
  774. }
  775. if ($bg['p']) {
  776. $newprop['BACKGROUND-POSITION'] = $bg['p'];
  777. }
  778. }
  779. /* -- END BACKGROUNDS -- */ else if ($k == 'IMAGE-ORIENTATION') {
  780. if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i', $v, $m)) {
  781. $angle = $m[1] + 0;
  782. if (strtolower($m[2]) == 'deg') {
  783. $angle = $angle;
  784. } else if (strtolower($m[2]) == 'grad') {
  785. $angle *= (360 / 400);
  786. } else if (strtolower($m[2]) == 'rad') {
  787. $angle = rad2deg($angle);
  788. }
  789. while ($angle < 0) {
  790. $angle += 360;
  791. }
  792. $angle = ($angle % 360);
  793. $angle /= 90;
  794. $angle = round($angle) * 90;
  795. $newprop['IMAGE-ORIENTATION'] = $angle;
  796. }
  797. } else if ($k == 'TEXT-ALIGN') {
  798. if (preg_match('/["\'](.){1}["\']/i', $v, $m)) {
  799. $d = array_search($m[1], $this->mpdf->decimal_align);
  800. if ($d !== false) {
  801. $newprop['TEXT-ALIGN'] = $d;
  802. }
  803. if (preg_match('/(center|left|right)/i', $v, $m)) {
  804. $newprop['TEXT-ALIGN'] .= strtoupper(substr($m[1], 0, 1));
  805. } else {
  806. $newprop['TEXT-ALIGN'] .= 'R';
  807. } // default = R
  808. } else if (preg_match('/["\'](\\\[a-fA-F0-9]{1,6})["\']/i', $v, $m)) {
  809. $utf8 = codeHex2utf(substr($m[1], 1, 6));
  810. $d = array_search($utf8, $this->mpdf->decimal_align);
  811. if ($d !== false) {
  812. $newprop['TEXT-ALIGN'] = $d;
  813. }
  814. if (preg_match('/(center|left|right)/i', $v, $m)) {
  815. $newprop['TEXT-ALIGN'] .= strtoupper(substr($m[1], 0, 1));
  816. } else {
  817. $newprop['TEXT-ALIGN'] .= 'R';
  818. } // default = R
  819. } else {
  820. $newprop[$k] = $v;
  821. }
  822. }
  823. // mpDF 6 Lists
  824. else if ($k == 'LIST-STYLE') {
  825. if (preg_match('/none/i', $v, $m)) {
  826. $newprop['LIST-STYLE-TYPE'] = 'none';
  827. $newprop['LIST-STYLE-IMAGE'] = 'none';
  828. }
  829. if (preg_match('/(lower-roman|upper-roman|lower-latin|lower-alpha|upper-latin|upper-alpha|decimal|disc|circle|square|arabic-indic|bengali|devanagari|gujarati|gurmukhi|kannada|malayalam|oriya|persian|tamil|telugu|thai|urdu|cambodian|khmer|lao|cjk-decimal|hebrew)/i', $v, $m)) {
  830. $newprop['LIST-STYLE-TYPE'] = strtolower(trim($m[1]));
  831. } else if (preg_match('/U\+([a-fA-F0-9]+)/i', $v, $m)) {
  832. $newprop['LIST-STYLE-TYPE'] = strtolower(trim($m[1]));
  833. }
  834. if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i', $v, $m)) {
  835. $newprop['LIST-STYLE-IMAGE'] = strtolower(trim($m[1]));
  836. }
  837. if (preg_match('/(inside|outside)/i', $v, $m)) {
  838. $newprop['LIST-STYLE-POSITION'] = strtolower(trim($m[1]));
  839. }
  840. } else {
  841. $newprop[$k] = $v;
  842. }
  843. }
  844. return $newprop;
  845. }
  846. function setCSSboxshadow($v)
  847. {
  848. $sh = array();
  849. $c = preg_match_all('/(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl)\(.*?\)/', $v, $x); // mPDF 5.6.05
  850. for ($i = 0; $i < $c; $i++) {
  851. $col = preg_replace('/,/', '*', $x[0][$i]);
  852. $v = preg_replace('/' . preg_quote($x[0][$i], '/') . '/', $col, $v);
  853. }
  854. $ss = explode(',', $v);
  855. foreach ($ss AS $s) {
  856. $new = array('inset' => false, 'blur' => 0, 'spread' => 0);
  857. if (preg_match('/inset/i', $s)) {
  858. $new['inset'] = true;
  859. $s = preg_replace('/\s*inset\s*/', '', $s);
  860. }
  861. $p = explode(' ', trim($s));
  862. if (isset($p[0])) {
  863. $new['x'] = $this->mpdf->ConvertSize(trim($p[0]), $this->mpdf->blk[$this->mpdf->blklvl - 1]['inner_width'], $this->mpdf->FontSize, false);
  864. }
  865. if (isset($p[1])) {
  866. $new['y'] = $this->mpdf->ConvertSize(trim($p[1]), $this->mpdf->blk[$this->mpdf->blklvl - 1]['inner_width'], $this->mpdf->FontSize, false);
  867. }
  868. if (isset($p[2])) {
  869. if (preg_match('/^\s*[\.\-0-9]/', $p[2])) {
  870. $new['blur'] = $this->mpdf->ConvertSize(trim($p[2]), $this->mpdf->blk[$this->mpdf->blklvl - 1]['inner_width'], $this->mpdf->FontSize, false);
  871. } else {
  872. $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/', ',', $p[2]));
  873. }
  874. if (isset($p[3])) {
  875. if (preg_match('/^\s*[\.\-0-9]/', $p[3])) {
  876. $new['spread'] = $this->mpdf->ConvertSize(trim($p[3]), $this->mpdf->blk[$this->mpdf->blklvl - 1]['inner_width'], $this->mpdf->FontSize, false);
  877. } else {
  878. $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/', ',', $p[3]));
  879. }
  880. if (isset($p[4])) {
  881. $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/', ',', $p[4]));
  882. }
  883. }
  884. }
  885. if (!$new['col']) {
  886. $new['col'] = $this->mpdf->ConvertColor('#888888');
  887. }
  888. if (isset($new['y'])) {
  889. array_unshift($sh, $new);
  890. }
  891. }
  892. return $sh;
  893. }
  894. function setCSStextshadow($v)
  895. {
  896. $sh = array();
  897. $c = preg_match_all('/(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl)\(.*?\)/', $v, $x); // mPDF 5.6.05
  898. for ($i = 0; $i < $c; $i++) {
  899. $col = preg_replace('/,/', '*', $x[0][$i]);
  900. $v = preg_replace('/' . preg_quote($x[0][$i], '/') . '/', $col, $v);
  901. }
  902. $ss = explode(',', $v);
  903. foreach ($ss AS $s) {
  904. $new = array('blur' => 0);
  905. $p = explode(' ', trim($s));
  906. if (isset($p[0])) {
  907. $new['x'] = $this->mpdf->ConvertSize(trim($p[0]), $this->mpdf->FontSize, $this->mpdf->FontSize, false);
  908. }
  909. if (isset($p[1])) {
  910. $new['y'] = $this->mpdf->ConvertSize(trim($p[1]), $this->mpdf->FontSize, $this->mpdf->FontSize, false);
  911. }
  912. if (isset($p[2])) {
  913. if (preg_match('/^\s*[\.\-0-9]/', $p[2])) {
  914. $new['blur'] = $this->mpdf->ConvertSize(trim($p[2]), $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'], $this->mpdf->FontSize, false);
  915. } else {
  916. $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/', ',', $p[2]));
  917. }
  918. if (isset($p[3])) {
  919. $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/', ',', $p[3]));
  920. }
  921. }
  922. if (!isset($new['col']) || !$new['col']) {
  923. $new['col'] = $this->mpdf->ConvertColor('#888888');
  924. }
  925. if (isset($new['y'])) {
  926. array_unshift($sh, $new);
  927. }
  928. }
  929. return $sh;
  930. }
  931. function parseCSSbackground($s)
  932. {
  933. $bg = array('c' => false, 'i' => false, 'r' => false, 'p' => false,);
  934. /* -- BACKGROUNDS -- */
  935. if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i', $s, $m)) {
  936. $bg['i'] = $m[0];
  937. } else
  938. /* -- END BACKGROUNDS -- */
  939. if (preg_match('/url\(/i', $s)) {
  940. // If color, set and strip it off
  941. // mPDF 5.6.05
  942. if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl|spot)\(.*?\)|[a-zA-Z]{3,})\s+(url\(.*)/i', $s, $m)) {
  943. $bg['c'] = strtolower($m[1]);
  944. $s = $m[3];
  945. }
  946. /* -- BACKGROUNDS -- */
  947. if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)\s*(.*)/i', $s, $m)) {
  948. $bg['i'] = $m[1];
  949. $s = strtolower($m[2]);
  950. if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/', $s, $m)) {
  951. $bg['r'] = $m[1];
  952. }
  953. // Remove repeat, attachment (discarded) and also any inherit
  954. $s = preg_replace('/(repeat-x|repeat-y|no-repeat|repeat|scroll|fixed|inherit)/', '', $s);
  955. $bits = preg_split('/\s+/', trim($s));
  956. // These should be Position x1 or x2
  957. if (count($bits) == 1) {
  958. if (preg_match('/bottom/', $bits[0])) {
  959. $bg['p'] = '50% 100%';
  960. } else if (preg_match('/top/', $bits[0])) {
  961. $bg['p'] = '50% 0%';
  962. } else {
  963. $bg['p'] = $bits[0] . ' 50%';
  964. }
  965. } else if (count($bits) == 2) {
  966. // Can be either right center or center right
  967. if (preg_match('/(top|bottom)/', $bits[0]) || preg_match('/(left|right)/', $bits[1])) {
  968. $bg['p'] = $bits[1] . ' ' . $bits[0];
  969. } else {
  970. $bg['p'] = $bits[0] . ' ' . $bits[1];
  971. }
  972. }
  973. if ($bg['p']) {
  974. $bg['p'] = preg_replace('/(left|top)/', '0%', $bg['p']);
  975. $bg['p'] = preg_replace('/(right|bottom)/', '100%', $bg['p']);
  976. $bg['p'] = preg_replace('/(center)/', '50%', $bg['p']);
  977. if (!preg_match('/[\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)* [\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)*/', $bg['p'])) {
  978. $bg['p'] = false;
  979. }
  980. }
  981. }
  982. /* -- END BACKGROUNDS -- */
  983. } else if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl|spot)\(.*?\)|[a-zA-Z]{3,})/i', $s, $m)) {
  984. $bg['c'] = strtolower($m[1]);
  985. } // mPDF 5.6.05
  986. return ($bg);
  987. }
  988. function expand24($mp)
  989. {
  990. $prop = preg_split('/\s+/', trim($mp));
  991. if (count($prop) == 1) {
  992. return array('T' => $prop[0], 'R' => $prop[0], 'B' => $prop[0], 'L' => $prop[0]);
  993. }
  994. if (count($prop) == 2) {
  995. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[0], 'L' => $prop[1]);
  996. }
  997. if (count($prop) == 3) {
  998. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L' => $prop[1]);
  999. }
  1000. if (count($prop) == 4) {
  1001. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L' => $prop[3]);
  1002. }
  1003. return array();
  1004. }
  1005. /* -- BORDER-RADIUS -- */
  1006. function border_radius_expand($val, $k)
  1007. {
  1008. $b = array();
  1009. if ($k == 'BORDER-RADIUS') {
  1010. $hv = explode('/', trim($val));
  1011. $prop = preg_split('/\s+/', trim($hv[0]));
  1012. if (count($prop) == 1) {
  1013. $b['TL-H'] = $b['TR-H'] = $b['BR-H'] = $b['BL-H'] = $prop[0];
  1014. } else if (count($prop) == 2) {
  1015. $b['TL-H'] = $b['BR-H'] = $prop[0];
  1016. $b['TR-H'] = $b['BL-H'] = $prop[1];
  1017. } else if (count($prop) == 3) {
  1018. $b['TL-H'] = $prop[0];
  1019. $b['TR-H'] = $b['BL-H'] = $prop[1];
  1020. $b['BR-H'] = $prop[2];
  1021. } else if (count($prop) == 4) {
  1022. $b['TL-H'] = $prop[0];
  1023. $b['TR-H'] = $prop[1];
  1024. $b['BR-H'] = $prop[2];
  1025. $b['BL-H'] = $prop[3];
  1026. }
  1027. if (count($hv) == 2) {
  1028. $prop = preg_split('/\s+/', trim($hv[1]));
  1029. if (count($prop) == 1) {
  1030. $b['TL-V'] = $b['TR-V'] = $b['BR-V'] = $b['BL-V'] = $prop[0];
  1031. } else if (count($prop) == 2) {
  1032. $b['TL-V'] = $b['BR-V'] = $prop[0];
  1033. $b['TR-V'] = $b['BL-V'] = $prop[1];
  1034. } else if (count($prop) == 3) {
  1035. $b['TL-V'] = $prop[0];
  1036. $b['TR-V'] = $b['BL-V'] = $prop[1];
  1037. $b['BR-V'] = $prop[2];
  1038. } else if (count($prop) == 4) {
  1039. $b['TL-V'] = $prop[0];
  1040. $b['TR-V'] = $prop[1];
  1041. $b['BR-V'] = $prop[2];
  1042. $b['BL-V'] = $prop[3];
  1043. }
  1044. } else {
  1045. $b['TL-V'] = $b['TL-H'];
  1046. $b['TR-V'] = $b['TR-H'];
  1047. $b['BL-V'] = $b['BL-H'];
  1048. $b['BR-V'] = $b['BR-H'];
  1049. }
  1050. return $b;
  1051. }
  1052. // Parse 2
  1053. $h = 0;
  1054. $v = 0;
  1055. $prop = preg_split('/\s+/', trim($val));
  1056. if (count($prop) == 1) {
  1057. $h = $v = $val;
  1058. } else {
  1059. $h = $prop[0];
  1060. $v = $prop[1];
  1061. }
  1062. if ($h == 0 || $v == 0) {
  1063. $h = $v = 0;
  1064. }
  1065. if ($k == 'BORDER-TOP-LEFT-RADIUS') {
  1066. $b['TL-H'] = $h;
  1067. $b['TL-V'] = $v;
  1068. } else if ($k == 'BORDER-TOP-RIGHT-RADIUS') {
  1069. $b['TR-H'] = $h;
  1070. $b['TR-V'] = $v;
  1071. } else if ($k == 'BORDER-BOTTOM-LEFT-RADIUS') {
  1072. $b['BL-H'] = $h;
  1073. $b['BL-V'] = $v;
  1074. } else if ($k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
  1075. $b['BR-H'] = $h;
  1076. $b['BR-V'] = $v;
  1077. }
  1078. return $b;
  1079. }
  1080. /* -- END BORDER-RADIUS -- */
  1081. function _mergeCSS($p, &$t)
  1082. {
  1083. // Save Cascading CSS e.g. "div.topic p" at this block level
  1084. if (isset($p) && $p) {
  1085. if ($t) {
  1086. $t = $this->array_merge_recursive_unique($t, $p);
  1087. } else {
  1088. $t = $p;
  1089. }
  1090. }
  1091. }
  1092. // for CSS handling
  1093. function array_merge_recursive_unique($array1, $array2)
  1094. {
  1095. $arrays = func_get_args();
  1096. $narrays = count($arrays);
  1097. $ret = $arrays[0];
  1098. for ($i = 1; $i < $narrays; $i ++) {
  1099. foreach ($arrays[$i] as $key => $value) {
  1100. if (((string) $key) === ((string) intval($key))) { // integer or string as integer key - append
  1101. $ret[] = $value;
  1102. } else { // string key - merge
  1103. if (is_array($value) && isset($ret[$key])) {
  1104. $ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value);
  1105. } else {
  1106. $ret[$key] = $value;
  1107. }
  1108. }
  1109. }
  1110. }
  1111. return $ret;
  1112. }
  1113. function _mergeFullCSS($p, &$t, $tag, $classes, $id, $lang)
  1114. { // mPDF 6
  1115. if (isset($p[$tag])) {
  1116. $this->_mergeCSS($p[$tag], $t);
  1117. }
  1118. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  1119. foreach ($classes AS $class) {
  1120. if (isset($p['CLASS>>' . $class])) {
  1121. $this->_mergeCSS($p['CLASS>>' . $class], $t);
  1122. }
  1123. }
  1124. // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
  1125. if ($tag == 'TR' && isset($p) && $p) {
  1126. foreach ($p AS $k => $val) {
  1127. if (preg_match('/' . $tag . '>>SELECTORNTHCHILD>>(.*)/', $k, $m)) {
  1128. $select = false;
  1129. if ($tag == 'TR') {
  1130. $row = $this->mpdf->row;
  1131. $thnr = (isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_thead']) ? count($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_thead']) : 0);
  1132. $tfnr = (isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_tfoot']) ? count($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_tfoot']) : 0);
  1133. if ($this->mpdf->tabletfoot) {
  1134. $row -= $thnr;
  1135. } else if (!$this->mpdf->tablethead) {
  1136. $row -= ($thnr + $tfnr);
  1137. }
  1138. if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/', $m[1], $a)) { // mPDF 5.7.4
  1139. $select = $this->_nthchild($a, $row);
  1140. }
  1141. } else if ($tag == 'TD' || $tag == 'TH') {
  1142. if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/', $m[1], $a)) { // mPDF 5.7.4
  1143. $select = $this->_nthchild($a, $this->mpdf->col);
  1144. }
  1145. }
  1146. if ($select) {
  1147. $this->_mergeCSS($p[$tag . '>>SELECTORNTHCHILD>>' . $m[1]], $t);
  1148. }
  1149. }
  1150. }
  1151. }
  1152. // STYLESHEET CLASS e.g. [lang=fr]{} or :lang(fr)
  1153. if (isset($lang) && isset($p['LANG>>' . $lang])) {
  1154. $this->_mergeCSS($p['LANG>>' . $lang], $t);
  1155. }
  1156. // STYLESHEET CLASS e.g. #smallone{} #redletter{}
  1157. if (isset($id) && isset($p['ID>>' . $id])) {
  1158. $this->_mergeCSS($p['ID>>' . $id], $t);
  1159. }
  1160. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  1161. foreach ($classes AS $class) {
  1162. if (isset($p[$tag . '>>CLASS>>' . $class])) {
  1163. $this->_mergeCSS($p[$tag . '>>CLASS>>' . $class], $t);
  1164. }
  1165. }
  1166. // STYLESHEET CLASS e.g. [lang=fr]{} or :lang(fr)
  1167. if (isset($lang) && isset($p[$tag . '>>LANG>>' . $lang])) {
  1168. $this->_mergeCSS($p[$tag . '>>LANG>>' . $lang], $t);
  1169. }
  1170. // STYLESHEET CLASS e.g. #smallone{} #redletter{}
  1171. if (isset($id) && isset($p[$tag . '>>ID>>' . $id])) {
  1172. $this->_mergeCSS($p[$tag . '>>ID>>' . $id], $t);
  1173. }
  1174. }
  1175. function setBorderDominance($prop, $val)
  1176. {
  1177. if (isset($prop['BORDER-LEFT']) && $prop['BORDER-LEFT']) {
  1178. $this->cell_border_dominance_L = $val;
  1179. }
  1180. if (isset($prop['BORDER-RIGHT']) && $prop['BORDER-RIGHT']) {
  1181. $this->cell_border_dominance_R = $val;
  1182. }
  1183. if (isset($prop['BORDER-TOP']) && $prop['BORDER-TOP']) {
  1184. $this->cell_border_dominance_T = $val;
  1185. }
  1186. if (isset($prop['BORDER-BOTTOM']) && $prop['BORDER-BOTTOM']) {
  1187. $this->cell_border_dominance_B = $val;
  1188. }
  1189. }
  1190. function _set_mergedCSS(&$m, &$p, $d = true, $bd = false)
  1191. {
  1192. if (isset($m)) {
  1193. if ((isset($m['depth']) && $m['depth'] > 1) || $d == false) { // include check for 'depth'
  1194. if ($bd) {
  1195. $this->setBorderDominance($m, $bd);
  1196. } // *TABLES*
  1197. if (is_array($m)) {
  1198. $p = array_merge($p, $m);
  1199. $this->_mergeBorders($p, $m);
  1200. }
  1201. }
  1202. }
  1203. }
  1204. function _mergeBorders(&$b, &$a)
  1205. { // Merges $a['BORDER-TOP-STYLE'] to $b['BORDER-TOP'] etc.
  1206. foreach (array('TOP', 'RIGHT', 'BOTTOM', 'LEFT') AS $side) {
  1207. foreach (array('STYLE', 'WIDTH', 'COLOR') AS $el) {
  1208. if (isset($a['BORDER-' . $side . '-' . $el])) { // e.g. $b['BORDER-TOP-STYLE']
  1209. $s = trim($a['BORDER-' . $side . '-' . $el]);
  1210. if (isset($b['BORDER-' . $side])) { // e.g. $b['BORDER-TOP']
  1211. $p = trim($b['BORDER-' . $side]);
  1212. } else {
  1213. $p = '';
  1214. }
  1215. if ($el == 'STYLE') {
  1216. if ($p) {
  1217. $b['BORDER-' . $side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 ' . $s . ' \\3', $p);
  1218. } else {
  1219. $b['BORDER-' . $side] = '0px ' . $s . ' #000000';
  1220. }
  1221. } else if ($el == 'WIDTH') {
  1222. if ($p) {
  1223. $b['BORDER-' . $side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', $s . ' \\2 \\3', $p);
  1224. } else {
  1225. $b['BORDER-' . $side] = $s . ' none #000000';
  1226. }
  1227. } else if ($el == 'COLOR') {
  1228. if ($p) {
  1229. $b['BORDER-' . $side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 \\2 ' . $s, $p);
  1230. } else {
  1231. $b['BORDER-' . $side] = '0px none ' . $s;
  1232. }
  1233. }
  1234. }
  1235. }
  1236. }
  1237. }
  1238. function MergeCSS($inherit, $tag, $attr)
  1239. {
  1240. $p = array();
  1241. $zp = array();
  1242. $classes = array();
  1243. if (isset($attr['CLASS'])) {
  1244. $classes = preg_split('/\s+/', $attr['CLASS']);
  1245. }
  1246. if (!isset($attr['ID'])) {
  1247. $attr['ID'] = '';
  1248. }
  1249. // mPDF 6
  1250. $shortlang = '';
  1251. if (!isset($attr['LANG'])) {
  1252. $attr['LANG'] = '';
  1253. } else {
  1254. $attr['LANG'] = strtolower($attr['LANG']);
  1255. if (strlen($attr['LANG']) == 5) {
  1256. $shortlang = substr($attr['LANG'], 0, 2);
  1257. }
  1258. }
  1259. //===============================================
  1260. /* -- TABLES -- */
  1261. // Set Inherited properties
  1262. if ($inherit == 'TOPTABLE') { // $tag = TABLE
  1263. //===============================================
  1264. // Save Cascading CSS e.g. "div.topic p" at this block level
  1265. if (isset($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'])) {
  1266. $this->tablecascadeCSS[0] = $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'];
  1267. } else {
  1268. $this->tablecascadeCSS[0] = $this->cascadeCSS;
  1269. }
  1270. }
  1271. //===============================================
  1272. // Set Inherited properties
  1273. if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') {
  1274. //Cascade everything from last level that is not an actual property, or defined by current tag/attributes
  1275. if (isset($this->tablecascadeCSS[$this->tbCSSlvl - 1]) && is_array($this->tablecascadeCSS[$this->tbCSSlvl - 1])) {
  1276. foreach ($this->tablecascadeCSS[$this->tbCSSlvl - 1] AS $k => $v) {
  1277. $this->tablecascadeCSS[$this->tbCSSlvl][$k] = $v;
  1278. }
  1279. }
  1280. $this->_mergeFullCSS($this->cascadeCSS, $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID'], $attr['LANG']);
  1281. //===============================================
  1282. // Cascading forward CSS e.g. "table.topic td" for this table in $this->tablecascadeCSS
  1283. //===============================================
  1284. // STYLESHEET TAG e.g. table
  1285. $this->_mergeFullCSS($this->tablecascadeCSS[$this->tbCSSlvl - 1], $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID'], $attr['LANG']);
  1286. //===============================================
  1287. }
  1288. /* -- END TABLES -- */
  1289. //===============================================
  1290. // Set Inherited properties
  1291. if ($inherit == 'BLOCK') {
  1292. if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['cascadeCSS']) && is_array($this->mpdf->blk[$this->mpdf->blklvl - 1]['cascadeCSS'])) {
  1293. foreach ($this->mpdf->blk[$this->mpdf->blklvl - 1]['cascadeCSS'] AS $k => $v) {
  1294. $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$k] = $v;
  1295. }
  1296. }
  1297. //===============================================
  1298. // Save Cascading CSS e.g. "div.topic p" at this block level
  1299. $this->_mergeFullCSS($this->cascadeCSS, $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID'], $attr['LANG']);
  1300. //===============================================
  1301. // Cascading forward CSS
  1302. //===============================================
  1303. if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1])) {
  1304. $this->_mergeFullCSS($this->mpdf->blk[$this->mpdf->blklvl - 1]['cascadeCSS'], $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID'], $attr['LANG']);
  1305. }
  1306. //===============================================
  1307. // Block properties which are inherited
  1308. if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['margin_collapse']) && $this->mpdf->blk[$this->mpdf->