PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / trunk
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin vtrunk
trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 All 71 releases
← All changes | mpdf/classes/cssmgr.php +2044 -1721 1.8.3trunk View file →
@@ -1,1721 +1,2044 @@
1 -<?php
2 -
3 -class cssmgr {
4 -
5 -var $mpdf = null;
6 -
7 -var $tablecascadeCSS;
8 -var $cascadeCSS;
9 -var $CSS;
10 -var $tbCSSlvl;
11 -
12 -
13 -function cssmgr(&$mpdf) {
14 - $this->mpdf = $mpdf;
15 - $this->tablecascadeCSS = array();
16 - $this->CSS=array();
17 - $this->cascadeCSS = array();
18 - $this->tbCSSlvl = 0;
19 -}
20 -
21 -function ReadCSS($html) {
22 - preg_match_all('/<style[^>]*media=["\']([^"\'>]*)["\'].*?<\/style>/is',$html,$m);
23 - for($i=0; $i<count($m[0]); $i++) {
24 - if ($this->mpdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) {
25 - $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html);
26 - }
27 - }
28 - preg_match_all('/<link[^>]*media=["\']([^"\'>]*)["\'].*?>/is',$html,$m);
29 - for($i=0; $i<count($m[0]); $i++) {
30 - if ($this->mpdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) {
31 - $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html);
32 - }
33 - }
34 -
35 - // mPDF 5.5.02
36 - // Remove Comment tags <!-- ... --> inside CSS as <style> in HTML document
37 - // Remove Comment tags /* ... */ inside CSS as <style> in HTML document
38 - // But first, we replace upper and mixed case closing style tag with lower
39 - // case so we can use str_replace later.
40 - preg_replace('/<\/style>/i', '</style>', $html);
41 - preg_match_all('/<style.*?>(.*?)<\/style>/si',$html,$m);
42 - if (count($m[1])) {
43 - for($i=0;$i<count($m[1]);$i++) {
44 - // Remove comment tags
45 - $sub = preg_replace('/(<\!\-\-|\-\->)/s',' ',$m[1][$i]);
46 - $sub = '>'.preg_replace('|/\*.*?\*/|s',' ',$sub).'</style>';
47 - $html = str_replace('>'.$m[1][$i].'</style>', $sub, $html);
48 - }
49 - }
50 -
51 -
52 - $html = preg_replace('/<!--mpdf/i','',$html);
53 - $html = preg_replace('/mpdf-->/i','',$html);
54 - $html = preg_replace('/<\!\-\-.*?\-\->/s',' ',$html);
55 -
56 - $match = 0; // no match for instance
57 - $regexp = ''; // This helps debugging: showing what is the REAL string being processed
58 - $CSSext = array();
59 -
60 - //CSS inside external files
61 - $regexp = '/<link[^>]*rel=["\']stylesheet["\'][^>]*href=["\']([^>"\']*)["\'].*?>/si';
62 - $x = preg_match_all($regexp,$html,$cxt);
63 - if ($x) {
64 - $match += $x;
65 - $CSSext = $cxt[1];
66 - }
67 - $regexp = '/<link[^>]*href=["\']([^>"\']*)["\'][^>]*?rel=["\']stylesheet["\'].*?>/si';
68 - $x = preg_match_all($regexp,$html,$cxt);
69 - if ($x) {
70 - $match += $x;
71 - $CSSext = array_merge($CSSext,$cxt[1]);
72 - }
73 -
74 - // look for @import stylesheets
75 - //$regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css)[\'\"]{0,1}\)/si';
76 - $regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css(\?\S+)?)[\'\"]{0,1}\)/si';
77 - $x = preg_match_all($regexp,$html,$cxt);
78 - if ($x) {
79 - $match += $x;
80 - $CSSext = array_merge($CSSext,$cxt[1]);
81 - }
82 -
83 - // look for @import without the url()
84 - //$regexp = '/@import [\'\"]{0,1}([^;]*?\.css)[\'\"]{0,1}/si';
85 - $regexp = '/@import [\'\"]{0,1}([^;]*?\.css(\?\S+)?)[\'\"]{0,1}/si';
86 - $x = preg_match_all($regexp,$html,$cxt);
87 - if ($x) {
88 - $match += $x;
89 - $CSSext = array_merge($CSSext,$cxt[1]);
90 - }
91 -
92 - $ind = 0;
93 - $CSSstr = '';
94 -
95 - if (!is_array($this->cascadeCSS)) $this->cascadeCSS = array();
96 -
97 - while($match){
98 - $path = $CSSext[$ind];
99 -
100 - $path = htmlspecialchars_decode($path); // mPDF 6
101 -
102 - $this->mpdf->GetFullPath($path);
103 - $CSSextblock = $this->mpdf->_get_file($path);
104 - if ($CSSextblock) {
105 - // look for embedded @import stylesheets in other stylesheets
106 - // and fix url paths (including background-images) relative to stylesheet
107 - //$regexpem = '/@import url\([\'\"]{0,1}(.*?\.css)[\'\"]{0,1}\)/si';
108 - $regexpem = '/@import url\([\'\"]{0,1}(.*?\.css(\?\S+)?)[\'\"]{0,1}\)/si';
109 - $xem = preg_match_all($regexpem,$CSSextblock,$cxtem);
110 - $cssBasePath = preg_replace('/\/[^\/]*$/','',$path) . '/';
111 - if ($xem) {
112 - foreach($cxtem[1] AS $cxtembedded) {
113 - // path is relative to original stlyesheet!!
114 - $this->mpdf->GetFullPath($cxtembedded, $cssBasePath );
115 - $match++;
116 - $CSSext[] = $cxtembedded;
117 - }
118 - }
119 - $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
120 - $xem = preg_match_all($regexpem,$CSSextblock,$cxtem);
121 - if ($xem) {
122 - for ($i=0;$i<count($cxtem[0]);$i++) {
123 - // path is relative to original stlyesheet!!
124 - $embedded = $cxtem[2][$i];
125 - if (!preg_match('/^data:image/i', $embedded)) { // mPDF 5.5.13
126 - $this->mpdf->GetFullPath($embedded, $cssBasePath );
127 - $CSSextblock = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $CSSextblock);
128 - }
129 - }
130 - }
131 - $CSSstr .= ' '.$CSSextblock;
132 - }
133 - $match--;
134 - $ind++;
135 - } //end of match
136 -
137 - $match = 0; // reset value, if needed
138 - // CSS as <style> in HTML document
139 - $regexp = '/<style.*?>(.*?)<\/style>/si';
140 - $match = preg_match_all($regexp,$html,$CSSblock);
141 - if ($match) {
142 - $tmpCSSstr = implode(' ',$CSSblock[1]);
143 - $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
144 - $xem = preg_match_all($regexpem,$tmpCSSstr ,$cxtem);
145 - if ($xem) {
146 - for ($i=0;$i<count($cxtem[0]);$i++) {
147 - $embedded = $cxtem[2][$i];
148 - if (!preg_match('/^data:image/i', $embedded)) { // mPDF 5.5.13
149 - $this->mpdf->GetFullPath($embedded);
150 - $tmpCSSstr = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $tmpCSSstr );
151 - }
152 - }
153 - }
154 - $CSSstr .= ' '.$tmpCSSstr;
155 - }
156 - // Remove comments
157 - $CSSstr = preg_replace('|/\*.*?\*/|s',' ',$CSSstr);
158 - $CSSstr = preg_replace('/[\s\n\r\t\f]/s',' ',$CSSstr);
159 -
160 - if (preg_match('/@media/',$CSSstr)) {
161 - preg_match_all('/@media(.*?)\{(([^\{\}]*\{[^\{\}]*\})+)\s*\}/is',$CSSstr,$m);
162 - for($i=0; $i<count($m[0]); $i++) {
163 - if ($this->mpdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) {
164 - $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$CSSstr);
165 - }
166 - else {
167 - $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/',' '.$m[2][$i].' ',$CSSstr);
168 - }
169 - }
170 - }
171 -
172 - // Replace any background: url(data:image... with temporary image file reference
173 - preg_match_all("/(url\(data:image\/(jpeg|gif|png);base64,(.*?)\))/si", $CSSstr, $idata); // mPDF 5.7.2
174 - if (count($idata[0])) {
175 - for($i=0;$i<count($idata[0]);$i++) {
176 - $file = _MPDF_TEMP_PATH.'_tempCSSidata'.RAND(1,10000).'_'.$i.'.'.$idata[2][$i];
177 - //Save to local file
178 - file_put_contents($file, base64_decode($idata[3][$i]));
179 - // $this->mpdf->GetFullPath($file); // ? is this needed - NO mPDF 5.6.03
180 - $CSSstr = str_replace($idata[0][$i], 'url("'.$file.'")', $CSSstr); // mPDF 5.5.17
181 - }
182 - }
183 -
184 - $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s',' ',$CSSstr);
185 -
186 - // mPDF 5.7.4 URLs
187 - // Characters "(" ")" and ";" in url() e.g. background-image, cause problems parsing the CSS string
188 - // URLencode ( and ), but change ";" to a code which can be converted back after parsing (so as not to confuse ;
189 - // with a segment delimiter in the URI)
190 - $tempmarker = '%ZZ';
191 - if (strpos($CSSstr,'url(')!==false) {
192 - preg_match_all( '/url\(\"(.*?)\"\)/', $CSSstr, $m);
193 - for($i = 0; $i < count($m[1]) ; $i++) {
194 - $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
195 - $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $CSSstr);
196 - }
197 - preg_match_all( '/url\(\'(.*?)\'\)/', $CSSstr, $m);
198 - for($i = 0; $i < count($m[1]) ; $i++) {
199 - $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
200 - $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $CSSstr);
201 - }
202 - preg_match_all( '/url\(([^\'\"].*?[^\'\"])\)/', $CSSstr, $m);
203 - for($i = 0; $i < count($m[1]) ; $i++) {
204 - $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
205 - $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $CSSstr);
206 - }
207 - }
208 -
209 -
210 -
211 - if ($CSSstr ) {
212 - $classproperties = array(); // mPDF 6
213 - preg_match_all('/(.*?)\{(.*?)\}/',$CSSstr,$styles);
214 - for($i=0; $i < count($styles[1]) ; $i++) {
215 - // SET array e.g. $classproperties['COLOR'] = '#ffffff';
216 - $stylestr= trim($styles[2][$i]);
217 - $stylearr = explode(';',$stylestr);
218 - foreach($stylearr AS $sta) {
219 - if (trim($sta)) {
220 - // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')"
221 - $tmp = explode(':',$sta,2);
222 - $property = $tmp[0];
223 - if (isset($tmp[1])) { $value = $tmp[1]; }
224 - else { $value = ''; }
225 - $value = str_replace($tempmarker,';',$value); // mPDF 5.7.4 URLs
226 - $property = trim($property);
227 - $value = preg_replace('/\s*!important/i','',$value);
228 - $value = trim($value);
229 - if ($property && ($value || $value==='0')) {
230 - // Ignores -webkit-gradient so doesn't override -moz-
231 - if ((strtoupper($property)=='BACKGROUND-IMAGE' || strtoupper($property)=='BACKGROUND') && preg_match('/-webkit-gradient/i',$value)) {
232 - continue;
233 - }
234 - $classproperties[strtoupper($property)] = $value;
235 - }
236 - }
237 - }
238 - $classproperties = $this->fixCSS($classproperties);
239 - $tagstr = strtoupper(trim($styles[1][$i]));
240 - $tagarr = explode(',',$tagstr);
241 - $pageselectors = false; // used to turn on $this->mpdf->mirrorMargins
242 - foreach($tagarr AS $tg) {
243 - // mPDF 5.7.4
244 - if (preg_match('/NTH-CHILD\((\s*(([\-+]?\d*)N(\s*[\-+]\s*\d+)?|[\-+]?\d+|ODD|EVEN)\s*)\)/',$tg,$m) ) {
245 - $tg = preg_replace('/NTH-CHILD\(.*\)/', 'NTH-CHILD('.str_replace(' ','',$m[1]).')', $tg);
246 - }
247 - $tags = preg_split('/\s+/',trim($tg));
248 - $level = count($tags);
249 - $t = '';
250 - $t2 = '';
251 - $t3 = '';
252 - if (trim($tags[0])=='@PAGE') {
253 - if (isset($tags[0])) { $t = trim($tags[0]); }
254 - if (isset($tags[1])) { $t2 = trim($tags[1]); }
255 - if (isset($tags[2])) { $t3 = trim($tags[2]); }
256 - $tag = '';
257 - if ($level==1) { $tag = $t; }
258 - else if ($level==2 && preg_match('/^[:](.*)$/',$t2,$m)) {
259 - $tag = $t.'>>PSEUDO>>'.$m[1];
260 - if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mpdf->mirrorMargins
261 - }
262 - else if ($level==2) { $tag = $t.'>>NAMED>>'.$t2; }
263 - else if ($level==3 && preg_match('/^[:](.*)$/',$t3,$m)) {
264 - $tag = $t.'>>NAMED>>'.$t2.'>>PSEUDO>>'.$m[1];
265 - if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mpdf->mirrorMargins
266 - }
267 - if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); }
268 - else if ($tag) { $this->CSS[$tag] = $classproperties; }
269 - }
270 -
271 - else if ($level == 1) { // e.g. p or .class or #id or p.class or p#id
272 - if (isset($tags[0])) { $t = trim($tags[0]); }
273 - if ($t) {
274 - $tag = '';
275 - if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; }
276 - else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; }
277 - else if (preg_match('/^\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/',$t,$m)) { $tag = 'LANG>>'.strtolower($m[1]); } // mPDF 6 Special case for lang as attribute selector
278 - else if (preg_match('/^:LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/',$t,$m)) { $tag = 'LANG>>'.strtolower($m[1]); } // mPDF 6 Special case for lang as attribute selector
279 - else if (preg_match('/^('.$this->mpdf->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; }
280 - else if (preg_match('/^('.$this->mpdf->allowedCSStags.')\s*:NTH-CHILD\((.*)\)$/',$t,$m)) { $tag = $m[1].'>>SELECTORNTHCHILD>>'.$m[2]; }
281 - else if (preg_match('/^('.$this->mpdf->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; }
282 - else if (preg_match('/^('.$this->mpdf->allowedCSStags.')\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/',$t,$m)) { $tag = $m[1].'>>LANG>>'.strtolower($m[2]); } // mPDF 6 Special case for lang as attribute selector
283 - else if (preg_match('/^('.$this->mpdf->allowedCSStags.'):LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/',$t,$m)) { $tag = $m[1].'>>LANG>>'.strtolower($m[2]); } // mPDF 6 Special case for lang as attribute selector
284 - else if (preg_match('/^('.$this->mpdf->allowedCSStags.')$/',$t)) { $tag= $t; }
285 - if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); }
286 - else if ($tag) { $this->CSS[$tag] = $classproperties; }
287 - }
288 - }
289 - else {
290 - $tmp = array();
291 - for($n=0;$n<$level;$n++) {
292 - if (isset($tags[$n])) { $t = trim($tags[$n]); }
293 - else { $t = ''; }
294 - if ($t) {
295 - $tag = '';
296 - if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; }
297 - else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; }
298 - else if (preg_match('/^\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/',$t,$m)) { $tag = 'LANG>>'.strtolower($m[1]); } // mPDF 6 Special case for lang as attribute selector
299 - else if (preg_match('/^:LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/',$t,$m)) { $tag = 'LANG>>'.strtolower($m[1]); } // mPDF 6 Special case for lang as attribute selector
300 - else if (preg_match('/^('.$this->mpdf->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; }
301 - else if (preg_match('/^('.$this->mpdf->allowedCSStags.')\s*:NTH-CHILD\((.*)\)$/',$t,$m)) { $tag = $m[1].'>>SELECTORNTHCHILD>>'.$m[2]; }
302 - else if (preg_match('/^('.$this->mpdf->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; }
303 - else if (preg_match('/^('.$this->mpdf->allowedCSStags.')\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/',$t,$m)) { $tag = $m[1].'>>LANG>>'.strtolower($m[2]); } // mPDF 6 Special case for lang as attribute selector
304 - else if (preg_match('/^('.$this->mpdf->allowedCSStags.'):LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/',$t,$m)) { $tag = $m[1].'>>LANG>>'.strtolower($m[2]); } // mPDF 6 Special case for lang as attribute selector
305 - else if (preg_match('/^('.$this->mpdf->allowedCSStags.')$/',$t)) { $tag= $t; }
306 -
307 - if ($tag) $tmp[] = $tag;
308 - else { break; }
309 - }
310 - }
311 -
312 - if ($tag) {
313 - $x = &$this->cascadeCSS;
314 - foreach($tmp AS $tp) { $x = &$x[$tp]; }
315 - $x = $this->array_merge_recursive_unique($x, $classproperties);
316 - $x['depth'] = $level;
317 - }
318 - }
319 - }
320 - if ($pageselectors) { $this->mpdf->mirrorMargins = true; }
321 - $properties = array();
322 - $values = array();
323 - $classproperties = array();
324 - }
325 - } // end of if
326 - //Remove CSS (tags and content), if any
327 - $regexp = '/<style.*?>(.*?)<\/style>/si'; // it can be <style> or <style type="txt/css">
328 - $html = preg_replace($regexp,'',$html);
329 -//print_r($this->CSS); exit;
330 -//print_r($this->cascadeCSS); exit;
331 - return $html;
332 -}
333 -
334 -
335 -
336 -function readInlineCSS($html) {
337 - $html=htmlspecialchars_decode($html); // mPDF 5.7.4 URLs
338 - // mPDF 5.7.4 URLs
339 - // Characters "(" ")" and ";" in url() e.g. background-image, cause probems parsing the CSS string
340 - // URLencode ( and ), but change ";" to a code which can be converted back after parsing (so as not to confuse ;
341 - // with a segment delimiter in the URI)
342 - $tempmarker = '%ZZ';
343 - if (strpos($html,'url(')!==false) {
344 - preg_match_all( '/url\(\"(.*?)\"\)/', $html, $m);
345 - for($i = 0; $i < count($m[1]) ; $i++) {
346 - $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
347 - $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $html);
348 - }
349 - preg_match_all( '/url\(\'(.*?)\'\)/', $html, $m);
350 - for($i = 0; $i < count($m[1]) ; $i++) {
351 - $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
352 - $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $html);
353 - }
354 - preg_match_all( '/url\(([^\'\"].*?[^\'\"])\)/', $html, $m);
355 - for($i = 0; $i < count($m[1]) ; $i++) {
356 - $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
357 - $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $html);
358 - }
359 - }
360 - //Fix incomplete CSS code
361 - $size = strlen($html)-1;
362 - if (substr($html,$size,1) != ';') $html .= ';';
363 - //Make CSS[Name-of-the-class] = array(key => value)
364 - $regexp = '|\\s*?(\\S+?):(.+?);|i';
365 - preg_match_all( $regexp, $html, $styleinfo);
366 - $properties = $styleinfo[1];
367 - $values = $styleinfo[2];
368 - //Array-properties and Array-values must have the SAME SIZE!
369 - $classproperties = array();
370 - for($i = 0; $i < count($properties) ; $i++) {
371 - // Ignores -webkit-gradient so doesn't override -moz-
372 - if ((strtoupper($properties[$i])=='BACKGROUND-IMAGE' || strtoupper($properties[$i])=='BACKGROUND') && preg_match('/-webkit-gradient/i',$values[$i])) {
373 - continue;
374 - }
375 - $values[$i] = str_replace($tempmarker,';',$values[$i]); // mPDF 5.7.4 URLs
376 - $classproperties[strtoupper($properties[$i])] = trim($values[$i]);
377 - }
378 - return $this->fixCSS($classproperties);
379 -}
380 -
381 -
382 -
383 -function _fix_borderStr($bd) {
384 - preg_match_all("/\((.*?)\)/", $bd, $m);
385 - if (count($m[1])) {
386 - for($i=0;$i<count($m[1]);$i++) {
387 - $sub = preg_replace("/ /", "", $m[1][$i]);
388 - $bd = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $bd);
389 - }
390 - }
391 -
392 - $prop = preg_split('/\s+/',trim($bd));
393 - $w = 'medium';
394 - $c = '#000000';
395 - $s = 'none';
396 -
397 - if ( count($prop) == 1 ) {
398 - // solid
399 - if (in_array($prop[0],$this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; }
400 - // #000000
401 - else if (is_array($this->mpdf->ConvertColor($prop[0]))) { $c = $prop[0]; }
402 - // 1px
403 - else { $w = $prop[0]; }
404 - }
405 - else if (count($prop) == 2 ) {
406 - // 1px solid
407 - if (in_array($prop[1],$this->mpdf->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden' ) { $w = $prop[0]; $s = $prop[1]; }
408 - // solid #000000
409 - else if (in_array($prop[0],$this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; $c = $prop[1]; }
410 - // 1px #000000
411 - else { $w = $prop[0]; $c = $prop[1]; }
412 - }
413 - else if ( count($prop) == 3 ) {
414 - // Change #000000 1px solid to 1px solid #000000 (proper)
415 - if (substr($prop[0],0,1) == '#') { $c = $prop[0]; $w = $prop[1]; $s = $prop[2]; }
416 - // Change solid #000000 1px to 1px solid #000000 (proper)
417 - else if (substr($prop[0],1,1) == '#') { $s = $prop[0]; $c = $prop[1]; $w = $prop[2]; }
418 - // Change solid 1px #000000 to 1px solid #000000 (proper)
419 - else if (in_array($prop[0],$this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) {
420 - $s = $prop[0]; $w = $prop[1]; $c = $prop[2];
421 - }
422 - else { $w = $prop[0]; $s = $prop[1]; $c = $prop[2]; }
423 - }
424 - else { return ''; }
425 - $s = strtolower($s);
426 - return $w.' '.$s.' '.$c;
427 -}
428 -
429 -
430 -
431 -function fixCSS($prop) {
432 - if (!is_array($prop) || (count($prop)==0)) return array();
433 - $newprop = array();
434 - foreach($prop AS $k => $v) {
435 - 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') {
436 - $v = strtolower($v);
437 - }
438 -
439 - if ($k == 'FONT') {
440 - $s = trim($v);
441 - preg_match_all('/\"(.*?)\"/',$s,$ff);
442 - if (count($ff[1])) {
443 - foreach($ff[1] AS $ffp) {
444 - $w = preg_split('/\s+/',$ffp);
445 - $s = preg_replace('/\"'.$ffp.'\"/',$w[0],$s);
446 - }
447 - }
448 - preg_match_all('/\'(.*?)\'/',$s,$ff);
449 - if (count($ff[1])) {
450 - foreach($ff[1] AS $ffp) {
451 - $w = preg_split('/\s+/',$ffp);
452 - $s = preg_replace('/\''.$ffp.'\'/',$w[0],$s);
453 - }
454 - }
455 - $s = preg_replace('/\s*,\s*/',',',$s);
456 - $bits = preg_split('/\s+/',$s);
457 - if (count($bits)>1) {
458 - $k = 'FONT-FAMILY'; $v = $bits[(count($bits)-1)];
459 - $fs = $bits[(count($bits)-2)];
460 - if (preg_match('/(.*?)\/(.*)/',$fs, $fsp)) {
461 - $newprop['FONT-SIZE'] = $fsp[1];
462 - $newprop['LINE-HEIGHT'] = $fsp[2];
463 - }
464 - else { $newprop['FONT-SIZE'] = $fs; }
465 - if (preg_match('/(italic|oblique)/i',$s)) { $newprop['FONT-STYLE'] = 'italic'; }
466 - else { $newprop['FONT-STYLE'] = 'normal'; }
467 - if (preg_match('/bold/i',$s)) { $newprop['FONT-WEIGHT'] = 'bold'; }
468 - else { $newprop['FONT-WEIGHT'] = 'normal'; }
469 - if (preg_match('/small-caps/i',$s)) { $newprop['TEXT-TRANSFORM'] = 'uppercase'; }
470 - }
471 - }
472 - else if ($k == 'FONT-FAMILY') {
473 - $aux_fontlist = explode(",",$v);
474 - $found = 0;
475 - foreach($aux_fontlist AS $f) {
476 - $fonttype = trim($f);
477 - $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
478 - $fonttype = preg_replace('/ /','',$fonttype);
479 - $v = strtolower(trim($fonttype));
480 - if (isset($this->mpdf->fonttrans[$v]) && $this->mpdf->fonttrans[$v]) { $v = $this->mpdf->fonttrans[$v]; }
481 - if ((!$this->mpdf->onlyCoreFonts && in_array($v,$this->mpdf->available_unifonts)) ||
482 - in_array($v,array('ccourier','ctimes','chelvetica')) ||
483 - ($this->mpdf->onlyCoreFonts && in_array($v,array('courier','times','helvetica','arial'))) ||
484 - in_array($v, array('sjis','uhc','big5','gb'))) {
485 - $newprop[$k] = $v;
486 - $found = 1;
487 - break;
488 - }
489 - }
490 - if (!$found) {
491 - foreach($aux_fontlist AS $f) {
492 - $fonttype = trim($f);
493 - $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
494 - $fonttype = preg_replace('/ /','',$fonttype);
495 - $v = strtolower(trim($fonttype));
496 - if (isset($this->mpdf->fonttrans[$v]) && $this->mpdf->fonttrans[$v]) { $v = $this->mpdf->fonttrans[$v]; }
497 - if (in_array($v,$this->mpdf->sans_fonts) || in_array($v,$this->mpdf->serif_fonts) || in_array($v,$this->mpdf->mono_fonts) ) {
498 - $newprop[$k] = $v;
499 - break;
500 - }
501 - }
502 - }
503 - }
504 - // mPDF 5.7.1
505 - else if ($k == 'FONT-VARIANT') {
506 - if (preg_match('/(normal|none)/',$v, $m)) { // mPDF 6
507 - $newprop['FONT-VARIANT-LIGATURES'] = $m[1];
508 - $newprop['FONT-VARIANT-CAPS'] = $m[1];
509 - $newprop['FONT-VARIANT-NUMERIC'] = $m[1];
510 - $newprop['FONT-VARIANT-ALTERNATES'] = $m[1];
511 - }
512 - else {
513 - 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)) {
514 - $newprop['FONT-VARIANT-LIGATURES'] = implode(' ',$m[1]);
515 - }
516 - if (preg_match('/(all-small-caps|\bsmall-caps|all-petite-caps|\bpetite-caps|unicase|titling-caps)/i',$v, $m)) {
517 - $newprop['FONT-VARIANT-CAPS'] = $m[1];
518 - }
519 - if (preg_match_all('/(lining-nums|oldstyle-nums|proportional-nums|tabular-nums|diagonal-fractions|stacked-fractions)/i',$v, $m)) {
520 - $newprop['FONT-VARIANT-NUMERIC'] = implode(' ',$m[1]);
521 - }
522 - if (preg_match('/(historical-forms)/i',$v, $m)) {
523 - $newprop['FONT-VARIANT-ALTERNATES'] = $m[1];
524 - }
525 - }
526 - }
527 - else if ($k == 'MARGIN') {
528 - $tmp = $this->expand24($v);
529 - $newprop['MARGIN-TOP'] = $tmp['T'];
530 - $newprop['MARGIN-RIGHT'] = $tmp['R'];
531 - $newprop['MARGIN-BOTTOM'] = $tmp['B'];
532 - $newprop['MARGIN-LEFT'] = $tmp['L'];
533 - }
534 -/*-- BORDER-RADIUS --*/
535 - 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') {
536 - $tmp = $this->border_radius_expand($v,$k);
537 - if (isset($tmp['TL-H'])) $newprop['BORDER-TOP-LEFT-RADIUS-H'] = $tmp['TL-H'];
538 - if (isset($tmp['TL-V'])) $newprop['BORDER-TOP-LEFT-RADIUS-V'] = $tmp['TL-V'];
539 - if (isset($tmp['TR-H'])) $newprop['BORDER-TOP-RIGHT-RADIUS-H'] = $tmp['TR-H'];
540 - if (isset($tmp['TR-V'])) $newprop['BORDER-TOP-RIGHT-RADIUS-V'] = $tmp['TR-V'];
541 - if (isset($tmp['BL-H'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-H'] = $tmp['BL-H'];
542 - if (isset($tmp['BL-V'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-V'] = $tmp['BL-V'];
543 - if (isset($tmp['BR-H'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $tmp['BR-H'];
544 - if (isset($tmp['BR-V'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $tmp['BR-V'];
545 - }
546 -/*-- END BORDER-RADIUS --*/
547 - else if ($k == 'PADDING') {
548 - $tmp = $this->expand24($v);
549 - $newprop['PADDING-TOP'] = $tmp['T'];
550 - $newprop['PADDING-RIGHT'] = $tmp['R'];
551 - $newprop['PADDING-BOTTOM'] = $tmp['B'];
552 - $newprop['PADDING-LEFT'] = $tmp['L'];
553 - }
554 - else if ($k == 'BORDER') {
555 - if ($v == '1') { $v = '1px solid #000000'; }
556 - else { $v = $this->_fix_borderStr($v); }
557 - $newprop['BORDER-TOP'] = $v;
558 - $newprop['BORDER-RIGHT'] = $v;
559 - $newprop['BORDER-BOTTOM'] = $v;
560 - $newprop['BORDER-LEFT'] = $v;
561 - }
562 - else if ($k == 'BORDER-TOP') {
563 - $newprop['BORDER-TOP'] = $this->_fix_borderStr($v);
564 - }
565 - else if ($k == 'BORDER-RIGHT') {
566 - $newprop['BORDER-RIGHT'] = $this->_fix_borderStr($v);
567 - }
568 - else if ($k == 'BORDER-BOTTOM') {
569 - $newprop['BORDER-BOTTOM'] = $this->_fix_borderStr($v);
570 - }
571 - else if ($k == 'BORDER-LEFT') {
572 - $newprop['BORDER-LEFT'] = $this->_fix_borderStr($v);
573 - }
574 - else if ($k == 'BORDER-STYLE') {
575 - $e = $this->expand24($v);
576 - if (!empty($e)) {
577 - $newprop['BORDER-TOP-STYLE'] = $e['T'];
578 - $newprop['BORDER-RIGHT-STYLE'] = $e['R'];
579 - $newprop['BORDER-BOTTOM-STYLE'] = $e['B'];
580 - $newprop['BORDER-LEFT-STYLE'] = $e['L'];
581 - }
582 - }
583 - else if ($k == 'BORDER-WIDTH') {
584 - $e = $this->expand24($v);
585 - if (!empty($e)) {
586 - $newprop['BORDER-TOP-WIDTH'] = $e['T'];
587 - $newprop['BORDER-RIGHT-WIDTH'] = $e['R'];
588 - $newprop['BORDER-BOTTOM-WIDTH'] = $e['B'];
589 - $newprop['BORDER-LEFT-WIDTH'] = $e['L'];
590 - }
591 - }
592 - else if ($k == 'BORDER-COLOR') {
593 - $e = $this->expand24($v);
594 - if (!empty($e)) {
595 - $newprop['BORDER-TOP-COLOR'] = $e['T'];
596 - $newprop['BORDER-RIGHT-COLOR'] = $e['R'];
597 - $newprop['BORDER-BOTTOM-COLOR'] = $e['B'];
598 - $newprop['BORDER-LEFT-COLOR'] = $e['L'];
599 - }
600 - }
601 -
602 - else if ($k == 'BORDER-SPACING') {
603 - $prop = preg_split('/\s+/',trim($v));
604 - if (count($prop) == 1 ) {
605 - $newprop['BORDER-SPACING-H'] = $prop[0];
606 - $newprop['BORDER-SPACING-V'] = $prop[0];
607 - }
608 - else if (count($prop) == 2 ) {
609 - $newprop['BORDER-SPACING-H'] = $prop[0];
610 - $newprop['BORDER-SPACING-V'] = $prop[1];
611 - }
612 - }
613 - else if ($k == 'TEXT-OUTLINE') { // mPDF 5.6.07
614 - $prop = preg_split('/\s+/',trim($v));
615 - if (trim(strtolower($v)) == 'none' ) {
616 - $newprop['TEXT-OUTLINE'] = 'none';
617 - }
618 - else if (count($prop) == 2 ) {
619 - $newprop['TEXT-OUTLINE-WIDTH'] = $prop[0];
620 - $newprop['TEXT-OUTLINE-COLOR'] = $prop[1];
621 - }
622 - else if (count($prop) == 3 ) {
623 - $newprop['TEXT-OUTLINE-WIDTH'] = $prop[0];
624 - $newprop['TEXT-OUTLINE-COLOR'] = $prop[2];
625 - }
626 - }
627 - else if ($k == 'SIZE') {
628 - $prop = preg_split('/\s+/',trim($v));
629 - if (preg_match('/(auto|portrait|landscape)/',$prop[0])) {
630 - $newprop['SIZE'] = strtoupper($prop[0]);
631 - }
632 - else if (count($prop) == 1 ) {
633 - $newprop['SIZE']['W'] = $this->mpdf->ConvertSize($prop[0]);
634 - $newprop['SIZE']['H'] = $this->mpdf->ConvertSize($prop[0]);
635 - }
636 - else if (count($prop) == 2 ) {
637 - $newprop['SIZE']['W'] = $this->mpdf->ConvertSize($prop[0]);
638 - $newprop['SIZE']['H'] = $this->mpdf->ConvertSize($prop[1]);
639 - }
640 - }
641 - else if ($k == 'SHEET-SIZE') {
642 - $prop = preg_split('/\s+/',trim($v));
643 - if (count($prop) == 2 ) {
644 - $newprop['SHEET-SIZE'] = array($this->mpdf->ConvertSize($prop[0]), $this->mpdf->ConvertSize($prop[1]));
645 - }
646 - else {
647 - if(preg_match('/([0-9a-zA-Z]*)-L/i',$v,$m)) { // e.g. A4-L = A$ landscape
648 - $ft = $this->mpdf->_getPageFormat($m[1]);
649 - $format = array($ft[1],$ft[0]);
650 - }
651 - else { $format = $this->mpdf->_getPageFormat($v); }
652 - if ($format) { $newprop['SHEET-SIZE'] = array($format[0]/_MPDFK, $format[1]/_MPDFK); }
653 - }
654 - }
655 - else if ($k == 'BACKGROUND') {
656 - $bg = $this->parseCSSbackground($v);
657 - if ($bg['c']) { $newprop['BACKGROUND-COLOR'] = $bg['c']; }
658 - else { $newprop['BACKGROUND-COLOR'] = 'transparent'; }
659 -/*-- BACKGROUNDS --*/
660 - if ($bg['i']) {
661 - $newprop['BACKGROUND-IMAGE'] = $bg['i'];
662 - if ($bg['r']) { $newprop['BACKGROUND-REPEAT'] = $bg['r']; }
663 - if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; }
664 - }
665 - else { $newprop['BACKGROUND-IMAGE'] = ''; }
666 -/*-- END BACKGROUNDS --*/
667 - }
668 -/*-- BACKGROUNDS --*/
669 - else if ($k == 'BACKGROUND-IMAGE') {
670 - if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i',$v,$m)) {
671 - $newprop['BACKGROUND-IMAGE'] = $m[0];
672 - continue;
673 - }
674 - if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i',$v,$m)) {
675 - $newprop['BACKGROUND-IMAGE'] = $m[1];
676 - }
677 -
678 - else if (strtolower($v)=='none') { $newprop['BACKGROUND-IMAGE'] = ''; }
679 -
680 - }
681 - else if ($k == 'BACKGROUND-REPEAT') {
682 - if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/i',$v,$m)) {
683 - $newprop['BACKGROUND-REPEAT'] = strtolower($m[1]);
684 - }
685 - }
686 - else if ($k == 'BACKGROUND-POSITION') {
687 - $s = $v;
688 - $bits = preg_split('/\s+/',trim($s));
689 - // These should be Position x1 or x2
690 - if (count($bits)==1) {
691 - if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; }
692 - else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; }
693 - else { $bg['p'] = $bits[0] . ' 50%'; }
694 - }
695 - else if (count($bits)==2) {
696 - // Can be either right center or center right
697 - if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) {
698 - $bg['p'] = $bits[1] . ' '.$bits[0];
699 - }
700 - else {
701 - $bg['p'] = $bits[0] . ' '.$bits[1];
702 - }
703 - }
704 - if ($bg['p']) {
705 - $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']);
706 - $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']);
707 - $bg['p'] = preg_replace('/(center)/','50%',$bg['p']);
708 - 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'])) {
709 - $bg['p'] = false;
710 - }
711 - }
712 - if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; }
713 - }
714 -/*-- END BACKGROUNDS --*/
715 - else if ($k == 'IMAGE-ORIENTATION') {
716 - if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$v,$m)) {
717 - $angle = $m[1] + 0;
718 - if (strtolower($m[2])=='deg') { $angle = $angle; }
719 - else if (strtolower($m[2])=='grad') { $angle *= (360/400); }
720 - else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); }
721 - while($angle < 0) { $angle += 360; }
722 - $angle = ($angle % 360);
723 - $angle /= 90;
724 - $angle = round($angle) * 90;
725 - $newprop['IMAGE-ORIENTATION'] = $angle;
726 - }
727 - }
728 - else if ($k == 'TEXT-ALIGN') {
729 - if (preg_match('/["\'](.){1}["\']/i',$v,$m)) {
730 - $d = array_search($m[1],$this->mpdf->decimal_align);
731 - if ($d !== false) { $newprop['TEXT-ALIGN'] = $d; }
732 - if (preg_match('/(center|left|right)/i',$v,$m)) { $newprop['TEXT-ALIGN'] .= strtoupper(substr($m[1],0,1)); }
733 - else { $newprop['TEXT-ALIGN'] .= 'R'; } // default = R
734 - }
735 - else if (preg_match('/["\'](\\\[a-fA-F0-9]{1,6})["\']/i',$v,$m)) {
736 - $utf8 = codeHex2utf(substr($m[1],1,6));
737 - $d = array_search($utf8,$this->mpdf->decimal_align);
738 - if ($d !== false) { $newprop['TEXT-ALIGN'] = $d; }
739 - if (preg_match('/(center|left|right)/i',$v,$m)) { $newprop['TEXT-ALIGN'] .= strtoupper(substr($m[1],0,1)); }
740 - else { $newprop['TEXT-ALIGN'] .= 'R'; } // default = R
741 - }
742 - else { $newprop[$k] = $v; }
743 - }
744 - // mpDF 6 Lists
745 - else if ($k == 'LIST-STYLE') {
746 - if (preg_match('/none/i',$v,$m)) {
747 - $newprop['LIST-STYLE-TYPE'] = 'none';
748 - $newprop['LIST-STYLE-IMAGE'] = 'none';
749 - }
750 - 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)) {
751 - $newprop['LIST-STYLE-TYPE'] = strtolower(trim($m[1]));
752 - }
753 - else if (preg_match('/U\+([a-fA-F0-9]+)/i',$v,$m)) {
754 - $newprop['LIST-STYLE-TYPE'] = strtolower(trim($m[1]));
755 - }
756 - if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i',$v,$m)) {
757 - $newprop['LIST-STYLE-IMAGE'] = strtolower(trim($m[1]));
758 - }
759 - if (preg_match('/(inside|outside)/i',$v,$m)) {
760 - $newprop['LIST-STYLE-POSITION'] = strtolower(trim($m[1]));
761 - }
762 - }
763 -
764 - else {
765 - $newprop[$k] = $v;
766 - }
767 - }
768 -
769 - return $newprop;
770 -}
771 -
772 -function setCSSboxshadow($v) {
773 - $sh = array();
774 - $c = preg_match_all('/(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl)\(.*?\)/',$v,$x); // mPDF 5.6.05
775 - for($i=0; $i<$c; $i++) {
776 - $col = preg_replace('/,/','*',$x[0][$i]);
777 - $v = preg_replace('/'.preg_quote($x[0][$i],'/').'/',$col,$v);
778 - }
779 - $ss = explode(',',$v);
780 - foreach ($ss AS $s) {
781 - $new = array('inset'=>false, 'blur'=>0, 'spread'=>0);
782 - if (preg_match('/inset/i',$s)) { $new['inset'] = true; $s = preg_replace('/\s*inset\s*/','',$s); }
783 - $p = explode(' ',trim($s));
784 - if (isset($p[0])) { $new['x'] = $this->mpdf->ConvertSize(trim($p[0]),$this->mpdf->blk[$this->mpdf->blklvl-1]['inner_width'],$this->mpdf->FontSize,false); }
785 - if (isset($p[1])) { $new['y'] = $this->mpdf->ConvertSize(trim($p[1]),$this->mpdf->blk[$this->mpdf->blklvl-1]['inner_width'],$this->mpdf->FontSize,false); }
786 - if (isset($p[2])) {
787 - if (preg_match('/^\s*[\.\-0-9]/',$p[2])) {
788 - $new['blur'] = $this->mpdf->ConvertSize(trim($p[2]),$this->mpdf->blk[$this->mpdf->blklvl-1]['inner_width'],$this->mpdf->FontSize,false);
789 - }
790 - else { $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[2])); }
791 - if (isset($p[3])) {
792 - if (preg_match('/^\s*[\.\-0-9]/',$p[3])) {
793 - $new['spread'] = $this->mpdf->ConvertSize(trim($p[3]),$this->mpdf->blk[$this->mpdf->blklvl-1]['inner_width'],$this->mpdf->FontSize,false);
794 - }
795 - else { $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[3])); }
796 - if (isset($p[4])) {
797 - $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[4]));
798 - }
799 - }
800 - }
801 - if (!$new['col']) { $new['col'] = $this->mpdf->ConvertColor('#888888'); }
802 - if (isset($new['y'])) { array_unshift($sh, $new); }
803 - }
804 - return $sh;
805 -}
806 -
807 -function setCSStextshadow($v) {
808 - $sh = array();
809 - $c = preg_match_all('/(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl)\(.*?\)/',$v,$x); // mPDF 5.6.05
810 - for($i=0; $i<$c; $i++) {
811 - $col = preg_replace('/,/','*',$x[0][$i]);
812 - $v = preg_replace('/'.preg_quote($x[0][$i],'/').'/',$col,$v);
813 - }
814 - $ss = explode(',',$v);
815 - foreach ($ss AS $s) {
816 - $new = array('blur'=>0);
817 - $p = explode(' ',trim($s));
818 - if (isset($p[0])) { $new['x'] = $this->mpdf->ConvertSize(trim($p[0]),$this->mpdf->FontSize,$this->mpdf->FontSize,false); }
819 - if (isset($p[1])) { $new['y'] = $this->mpdf->ConvertSize(trim($p[1]),$this->mpdf->FontSize,$this->mpdf->FontSize,false); }
820 - if (isset($p[2])) {
821 - if (preg_match('/^\s*[\.\-0-9]/',$p[2])) {
822 - $new['blur'] = $this->mpdf->ConvertSize(trim($p[2]),$this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],$this->mpdf->FontSize,false);
823 - }
824 - else { $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[2])); }
825 - if (isset($p[3])) {
826 - $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[3]));
827 - }
828 - }
829 - if (!isset($new['col']) || !$new['col']) { $new['col'] = $this->mpdf->ConvertColor('#888888'); }
830 - if (isset($new['y'])) { array_unshift($sh, $new); }
831 - }
832 - return $sh;
833 -}
834 -
835 -function parseCSSbackground($s) {
836 - $bg = array('c'=>false, 'i'=>false, 'r'=>false, 'p'=>false, );
837 -/*-- BACKGROUNDS --*/
838 - if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i',$s,$m)) {
839 - $bg['i'] = $m[0];
840 - }
841 - else
842 -/*-- END BACKGROUNDS --*/
843 - if (preg_match('/url\(/i',$s)) {
844 - // If color, set and strip it off
845 - // mPDF 5.6.05
846 - 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)) {
847 - $bg['c'] = strtolower($m[1]);
848 - $s = $m[3];
849 - }
850 -/*-- BACKGROUNDS --*/
851 - if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)\s*(.*)/i',$s,$m)) {
852 - $bg['i'] = $m[1];
853 - $s = strtolower($m[2]);
854 - if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/',$s,$m)) {
855 - $bg['r'] = $m[1];
856 - }
857 - // Remove repeat, attachment (discarded) and also any inherit
858 - $s = preg_replace('/(repeat-x|repeat-y|no-repeat|repeat|scroll|fixed|inherit)/','',$s);
859 - $bits = preg_split('/\s+/',trim($s));
860 - // These should be Position x1 or x2
861 - if (count($bits)==1) {
862 - if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; }
863 - else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; }
864 - else { $bg['p'] = $bits[0] . ' 50%'; }
865 - }
866 - else if (count($bits)==2) {
867 - // Can be either right center or center right
868 - if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) {
869 - $bg['p'] = $bits[1] . ' '.$bits[0];
870 - }
871 - else {
872 - $bg['p'] = $bits[0] . ' '.$bits[1];
873 - }
874 - }
875 - if ($bg['p']) {
876 - $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']);
877 - $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']);
878 - $bg['p'] = preg_replace('/(center)/','50%',$bg['p']);
879 - 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'])) {
880 - $bg['p'] = false;
881 - }
882 - }
883 - }
884 -/*-- END BACKGROUNDS --*/
885 - }
886 - 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)) { $bg['c'] = strtolower($m[1]); } // mPDF 5.6.05
887 - return ($bg);
888 -}
889 -
890 -
891 -function expand24($mp) {
892 - $prop = preg_split('/\s+/',trim($mp));
893 - if (count($prop) == 1 ) {
894 - return array('T' => $prop[0], 'R' => $prop[0], 'B' => $prop[0], 'L'=> $prop[0]);
895 - }
896 - if (count($prop) == 2 ) {
897 - return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[0], 'L'=> $prop[1]);
898 - }
899 -
900 - if (count($prop) == 3 ) {
901 - return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[1]);
902 - }
903 - if (count($prop) == 4 ) {
904 - return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[3]);
905 - }
906 - return array();
907 -}
908 -
909 -/*-- BORDER-RADIUS --*/
910 -function border_radius_expand($val,$k) {
911 - $b = array();
912 - if ($k == 'BORDER-RADIUS') {
913 - $hv = explode('/',trim($val));
914 - $prop = preg_split('/\s+/',trim($hv[0]));
915 - if (count($prop)==1) {
916 - $b['TL-H'] = $b['TR-H'] = $b['BR-H'] = $b['BL-H'] = $prop[0];
917 - }
918 - else if (count($prop)==2) {
919 - $b['TL-H'] = $b['BR-H'] = $prop[0];
920 - $b['TR-H'] = $b['BL-H'] = $prop[1];
921 - }
922 - else if (count($prop)==3) {
923 - $b['TL-H'] = $prop[0];
924 - $b['TR-H'] = $b['BL-H'] = $prop[1];
925 - $b['BR-H'] = $prop[2];
926 - }
927 - else if (count($prop)==4) {
928 - $b['TL-H'] = $prop[0];
929 - $b['TR-H'] = $prop[1];
930 - $b['BR-H'] = $prop[2];
931 - $b['BL-H'] = $prop[3];
932 - }
933 - if (count($hv)==2) {
934 - $prop = preg_split('/\s+/',trim($hv[1]));
935 - if (count($prop)==1) {
936 - $b['TL-V'] = $b['TR-V'] = $b['BR-V'] = $b['BL-V'] = $prop[0];
937 - }
938 - else if (count($prop)==2) {
939 - $b['TL-V'] = $b['BR-V'] = $prop[0];
940 - $b['TR-V'] = $b['BL-V'] = $prop[1];
941 - }
942 - else if (count($prop)==3) {
943 - $b['TL-V'] = $prop[0];
944 - $b['TR-V'] = $b['BL-V'] = $prop[1];
945 - $b['BR-V'] = $prop[2];
946 - }
947 - else if (count($prop)==4) {
948 - $b['TL-V'] = $prop[0];
949 - $b['TR-V'] = $prop[1];
950 - $b['BR-V'] = $prop[2];
951 - $b['BL-V'] = $prop[3];
952 - }
953 - }
954 - else {
955 - $b['TL-V'] = $b['TL-H'];
956 - $b['TR-V'] = $b['TR-H'];
957 - $b['BL-V'] = $b['BL-H'];
958 - $b['BR-V'] = $b['BR-H'];
959 - }
960 - return $b;
961 - }
962 -
963 - // Parse 2
964 - $h = 0;
965 - $v = 0;
966 - $prop = preg_split('/\s+/',trim($val));
967 - if (count($prop)==1) { $h = $v = $val; }
968 - else { $h = $prop[0]; $v = $prop[1]; }
969 - if ($h==0 || $v==0) { $h = $v = 0; }
970 - if ($k == 'BORDER-TOP-LEFT-RADIUS') {
971 - $b['TL-H'] = $h;
972 - $b['TL-V'] = $v;
973 - }
974 - else if ($k == 'BORDER-TOP-RIGHT-RADIUS') {
975 - $b['TR-H'] = $h;
976 - $b['TR-V'] = $v;
977 - }
978 - else if ($k == 'BORDER-BOTTOM-LEFT-RADIUS') {
979 - $b['BL-H'] = $h;
980 - $b['BL-V'] = $v;
981 - }
982 - else if ($k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
983 - $b['BR-H'] = $h;
984 - $b['BR-V'] = $v;
985 - }
986 - return $b;
987 -
988 -}
989 -/*-- END BORDER-RADIUS --*/
990 -
991 -function _mergeCSS($p, &$t) {
992 - // Save Cascading CSS e.g. "div.topic p" at this block level
993 - if (isset($p) && $p) {
994 - if ($t) {
995 - $t = $this->array_merge_recursive_unique($t, $p);
996 - }
997 - else { $t = $p; }
998 - }
999 -}
1000 -
1001 -// for CSS handling
1002 -function array_merge_recursive_unique($array1, $array2) {
1003 - $arrays = func_get_args();
1004 - $narrays = count($arrays);
1005 - $ret = $arrays[0];
1006 - for ($i = 1; $i < $narrays; $i ++) {
1007 - foreach ($arrays[$i] as $key => $value) {
1008 - if (((string) $key) === ((string) intval($key))) { // integer or string as integer key - append
1009 - $ret[] = $value;
1010 - }
1011 - else { // string key - merge
1012 - if (is_array($value) && isset($ret[$key])) {
1013 - $ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value);
1014 - }
1015 - else {
1016 - $ret[$key] = $value;
1017 - }
1018 - }
1019 - }
1020 - }
1021 - return $ret;
1022 -}
1023 -
1024 -
1025 -
1026 -function _mergeFullCSS($p, &$t, $tag, $classes, $id, $lang) { // mPDF 6
1027 - if (isset($p[$tag])) { $this->_mergeCSS($p[$tag], $t); }
1028 - // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1029 - foreach($classes AS $class) {
1030 - if (isset($p['CLASS>>'.$class])) { $this->_mergeCSS($p['CLASS>>'.$class], $t); }
1031 - }
1032 - // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
1033 - if ($tag=='TR' && isset($p) && $p) {
1034 - foreach($p AS $k=>$val) {
1035 - if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
1036 - $select = false;
1037 - if ($tag=='TR') {
1038 - $row = $this->mpdf->row;
1039 - $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);
1040 - $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);
1041 - if ($this->mpdf->tabletfoot) { $row -= $thnr; }
1042 - else if (!$this->mpdf->tablethead) { $row -= ($thnr + $tfnr); }
1043 - if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1044 - $select = $this->_nthchild($a, $row);
1045 - }
1046 - }
1047 - else if ($tag=='TD' || $tag=='TH') {
1048 - if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1049 - $select = $this->_nthchild($a, $this->mpdf->col);
1050 - }
1051 - }
1052 - if ($select) {
1053 - $this->_mergeCSS($p[$tag.'>>SELECTORNTHCHILD>>'.$m[1]], $t);
1054 - }
1055 - }
1056 - }
1057 - }
1058 - // STYLESHEET CLASS e.g. [lang=fr]{} or :lang(fr)
1059 - if (isset($lang) && isset($p['LANG>>'.$lang])) {
1060 - $this->_mergeCSS($p['LANG>>'.$lang], $t);
1061 - }
1062 - // STYLESHEET CLASS e.g. #smallone{} #redletter{}
1063 - if (isset($id) && isset($p['ID>>'.$id])) {
1064 - $this->_mergeCSS($p['ID>>'.$id], $t);
1065 - }
1066 -
1067 - // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1068 - foreach($classes AS $class) {
1069 - if (isset($p[$tag.'>>CLASS>>'.$class])) { $this->_mergeCSS($p[$tag.'>>CLASS>>'.$class], $t); }
1070 - }
1071 - // STYLESHEET CLASS e.g. [lang=fr]{} or :lang(fr)
1072 - if (isset($lang) && isset($p[$tag.'>>LANG>>'.$lang])) {
1073 - $this->_mergeCSS($p[$tag.'>>LANG>>'.$lang], $t);
1074 - }
1075 - // STYLESHEET CLASS e.g. #smallone{} #redletter{}
1076 - if (isset($id) && isset($p[$tag.'>>ID>>'.$id])) {
1077 - $this->_mergeCSS($p[$tag.'>>ID>>'.$id], $t);
1078 - }
1079 -}
1080 -
1081 -function setBorderDominance($prop, $val) {
1082 - if (isset($prop['BORDER-LEFT']) && $prop['BORDER-LEFT']) { $this->cell_border_dominance_L = $val; }
1083 - if (isset($prop['BORDER-RIGHT']) && $prop['BORDER-RIGHT']) { $this->cell_border_dominance_R = $val; }
1084 - if (isset($prop['BORDER-TOP']) && $prop['BORDER-TOP']) { $this->cell_border_dominance_T = $val; }
1085 - if (isset($prop['BORDER-BOTTOM']) && $prop['BORDER-BOTTOM']) { $this->cell_border_dominance_B = $val; }
1086 -}
1087 -
1088 -function _set_mergedCSS(&$m, &$p, $d=true, $bd=false) {
1089 - if (isset($m)) {
1090 - if ((isset($m['depth']) && $m['depth']>1) || $d==false) { // include check for 'depth'
1091 - if ($bd) { $this->setBorderDominance($m, $bd); } // *TABLES*
1092 - if (is_array($m)) {
1093 - $p = array_merge($p,$m);
1094 - $this->_mergeBorders($p,$m);
1095 - }
1096 - }
1097 - }
1098 -}
1099 -
1100 -
1101 -function _mergeBorders(&$b, &$a) { // Merges $a['BORDER-TOP-STYLE'] to $b['BORDER-TOP'] etc.
1102 - foreach(array('TOP','RIGHT','BOTTOM','LEFT') AS $side) {
1103 - foreach(array('STYLE','WIDTH','COLOR') AS $el) {
1104 - if (isset($a['BORDER-'.$side.'-'.$el])) { // e.g. $b['BORDER-TOP-STYLE']
1105 - $s = trim($a['BORDER-'.$side.'-'.$el]);
1106 - if (isset($b['BORDER-'.$side])) { // e.g. $b['BORDER-TOP']
1107 - $p = trim($b['BORDER-'.$side]);
1108 - }
1109 - else { $p = ''; }
1110 - if ($el=='STYLE') {
1111 - if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 '.$s.' \\3', $p); }
1112 - else { $b['BORDER-'.$side] = '0px '.$s.' #000000'; }
1113 - }
1114 - else if ($el=='WIDTH') {
1115 - if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', $s.' \\2 \\3', $p); }
1116 - else { $b['BORDER-'.$side] = $s.' none #000000'; }
1117 - }
1118 - else if ($el=='COLOR') {
1119 - if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 \\2 '.$s, $p); }
1120 - else { $b['BORDER-'.$side] = '0px none '.$s; }
1121 - }
1122 - }
1123 - }
1124 - }
1125 -}
1126 -
1127 -
1128 -function MergeCSS($inherit,$tag,$attr) {
1129 - $p = array();
1130 - $zp = array();
1131 -
1132 - $classes = array();
1133 - if (isset($attr['CLASS'])) {
1134 - $classes = preg_split('/\s+/',$attr['CLASS']);
1135 - }
1136 - if (!isset($attr['ID'])) { $attr['ID']=''; }
1137 - // mPDF 6
1138 - $shortlang = '';
1139 - if (!isset($attr['LANG'])) { $attr['LANG']=''; }
1140 - else {
1141 - $attr['LANG'] = strtolower($attr['LANG']);
1142 - if (strlen($attr['LANG']) == 5) {
1143 - $shortlang = substr($attr['LANG'],0,2);
1144 - }
1145 - }
1146 - //===============================================
1147 -/*-- TABLES --*/
1148 - // Set Inherited properties
1149 - if ($inherit == 'TOPTABLE') { // $tag = TABLE
1150 - //===============================================
1151 - // Save Cascading CSS e.g. "div.topic p" at this block level
1152 -
1153 - if (isset($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'])) {
1154 - $this->tablecascadeCSS[0] = $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'];
1155 - }
1156 - else {
1157 - $this->tablecascadeCSS[0] = $this->cascadeCSS;
1158 - }
1159 - }
1160 - //===============================================
1161 - // Set Inherited properties
1162 - if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') {
1163 - //Cascade everything from last level that is not an actual property, or defined by current tag/attributes
1164 - if (isset($this->tablecascadeCSS[$this->tbCSSlvl-1]) && is_array($this->tablecascadeCSS[$this->tbCSSlvl-1])) {
1165 - foreach($this->tablecascadeCSS[$this->tbCSSlvl-1] AS $k=>$v) {
1166 - $this->tablecascadeCSS[$this->tbCSSlvl][$k] = $v;
1167 - }
1168 - }
1169 - $this->_mergeFullCSS($this->cascadeCSS, $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID'], $attr['LANG']);
1170 - //===============================================
1171 - // Cascading forward CSS e.g. "table.topic td" for this table in $this->tablecascadeCSS
1172 - //===============================================
1173 - // STYLESHEET TAG e.g. table
1174 - $this->_mergeFullCSS($this->tablecascadeCSS[$this->tbCSSlvl-1], $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID'], $attr['LANG']);
1175 - //===============================================
1176 - }
1177 -/*-- END TABLES --*/
1178 - //===============================================
1179 - // Set Inherited properties
1180 - if ($inherit == 'BLOCK') {
1181 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS']) && is_array($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'])) {
1182 - foreach($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'] AS $k=>$v) {
1183 - $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$k] = $v;
1184 -
1185 - }
1186 - }
1187 -
1188 - //===============================================
1189 - // Save Cascading CSS e.g. "div.topic p" at this block level
1190 - $this->_mergeFullCSS($this->cascadeCSS, $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID'], $attr['LANG']);
1191 - //===============================================
1192 - // Cascading forward CSS
1193 - //===============================================
1194 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1])) {
1195 - $this->_mergeFullCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'], $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID'], $attr['LANG']);
1196 - }
1197 - //===============================================
1198 - // Block properties which are inherited
1199 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['margin_collapse']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['margin_collapse']) { $p['MARGIN-COLLAPSE'] = 'COLLAPSE'; } // custom tag, but follows CSS principle that border-collapse is inherited
1200 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['line_height']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['line_height']) { $p['LINE-HEIGHT'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['line_height']; }
1201 - // mPDF 6
1202 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_strategy']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_strategy']) { $p['LINE-STACKING-STRATEGY'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_strategy']; }
1203 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_shift']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_shift']) { $p['LINE-STACKING-SHIFT'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_shift']; }
1204 -
1205 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['direction']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['direction']) { $p['DIRECTION'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['direction']; }
1206 - // mPDF 6 Lists
1207 - if ($tag == 'LI') {
1208 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_type']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_type']) { $p['LIST-STYLE-TYPE'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_type']; }
1209 - }
1210 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_image']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_image']) { $p['LIST-STYLE-IMAGE'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_image']; }
1211 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_position']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_position']) { $p['LIST-STYLE-POSITION'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_position']; }
1212 -
1213 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['align']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['align']) {
1214 - if ($this->mpdf->blk[$this->mpdf->blklvl-1]['align'] == 'L') { $p['TEXT-ALIGN'] = 'left'; }
1215 - else if ($this->mpdf->blk[$this->mpdf->blklvl-1]['align'] == 'J') { $p['TEXT-ALIGN'] = 'justify'; }
1216 - else if ($this->mpdf->blk[$this->mpdf->blklvl-1]['align'] == 'R') { $p['TEXT-ALIGN'] = 'right'; }
1217 - else if ($this->mpdf->blk[$this->mpdf->blklvl-1]['align'] == 'C') { $p['TEXT-ALIGN'] = 'center'; }
1218 - }
1219 - if ($this->mpdf->ColActive || $this->mpdf->keep_block_together) {
1220 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['bgcolor']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['bgcolor']) { // Doesn't officially inherit, but default value is transparent (?=inherited)
1221 - $cor = $this->mpdf->blk[$this->mpdf->blklvl-1]['bgcolorarray' ];
1222 - $p['BACKGROUND-COLOR'] = $this->mpdf->_colAtoString($cor);
1223 - }
1224 - }
1225 -
1226 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['text_indent']) && ($this->mpdf->blk[$this->mpdf->blklvl-1]['text_indent'] || $this->mpdf->blk[$this->mpdf->blklvl-1]['text_indent']===0)) { $p['TEXT-INDENT'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['text_indent']; }
1227 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['InlineProperties'])) {
1228 - $biilp = $this->mpdf->blk[$this->mpdf->blklvl-1]['InlineProperties'];
1229 - $this->inlinePropsToCSS($biilp, $p); // mPDF 5.7.1
1230 - }
1231 - else { $biilp = null; }
1232 - }
1233 - //===============================================
1234 - //===============================================
1235 - // INLINE HTML ATTRIBUTES e.g. .. ALIGN="CENTER">
1236 - // mPDF 6 (added)
1237 - if (isset($attr['DIR']) and $attr['DIR']!='') {
1238 - $p['DIRECTION'] = $attr['DIR'];
1239 - }
1240 - // mPDF 6 (moved)
1241 - if (isset($attr['LANG']) and $attr['LANG']!='') {
1242 - $p['LANG'] = $attr['LANG'];
1243 - }
1244 - if (isset($attr['COLOR']) and $attr['COLOR']!='') {
1245 - $p['COLOR'] = $attr['COLOR'];
1246 - }
1247 -
1248 - if ($tag != 'INPUT') {
1249 - if (isset($attr['WIDTH']) and $attr['WIDTH']!='') {
1250 - $p['WIDTH'] = $attr['WIDTH'];
1251 - }
1252 - if (isset($attr['HEIGHT']) and $attr['HEIGHT']!='') {
1253 - $p['HEIGHT'] = $attr['HEIGHT'];
1254 - }
1255 - }
1256 - if ($tag == 'FONT') {
1257 - if (isset($attr['FACE'])) {
1258 - $p['FONT-FAMILY'] = $attr['FACE'];
1259 - }
1260 - if (isset($attr['SIZE']) and $attr['SIZE']!='') {
1261 - $s = '';
1262 - if ($attr['SIZE'] === '+1') { $s = '120%'; }
1263 - else if ($attr['SIZE'] === '-1') { $s = '86%'; }
1264 - else if ($attr['SIZE'] === '1') { $s = 'XX-SMALL'; }
1265 - else if ($attr['SIZE'] == '2') { $s = 'X-SMALL'; }
1266 - else if ($attr['SIZE'] == '3') { $s = 'SMALL'; }
1267 - else if ($attr['SIZE'] == '4') { $s = 'MEDIUM'; }
1268 - else if ($attr['SIZE'] == '5') { $s = 'LARGE'; }
1269 - else if ($attr['SIZE'] == '6') { $s = 'X-LARGE'; }
1270 - else if ($attr['SIZE'] == '7') { $s = 'XX-LARGE'; }
1271 - if ($s) $p['FONT-SIZE'] = $s;
1272 - }
1273 - }
1274 - if (isset($attr['VALIGN']) and $attr['VALIGN']!='') {
1275 - $p['VERTICAL-ALIGN'] = $attr['VALIGN'];
1276 - }
1277 - if (isset($attr['VSPACE']) and $attr['VSPACE']!='') {
1278 - $p['MARGIN-TOP'] = $attr['VSPACE'];
1279 - $p['MARGIN-BOTTOM'] = $attr['VSPACE'];
1280 - }
1281 - if (isset($attr['HSPACE']) and $attr['HSPACE']!='') {
1282 - $p['MARGIN-LEFT'] = $attr['HSPACE'];
1283 - $p['MARGIN-RIGHT'] = $attr['HSPACE'];
1284 - }
1285 - //===============================================
1286 - //===============================================
1287 - // DEFAULT for this TAG set in DefaultCSS
1288 - if (isset($this->mpdf->defaultCSS[$tag])) {
1289 - $zp = $this->fixCSS($this->mpdf->defaultCSS[$tag]);
1290 - if (is_array($zp)) { // Default overwrites Inherited
1291 - $p = array_merge($p,$zp); // !! Note other way round !!
1292 - $this->_mergeBorders($p,$zp);
1293 - }
1294 - }
1295 - //===============================================
1296 -/*-- TABLES --*/
1297 - // mPDF 5.7.3
1298 - // cellSpacing overwrites TABLE default but not specific CSS set on table
1299 - if ($tag=='TABLE' && isset($attr['CELLSPACING'])) {
1300 - $p['BORDER-SPACING-H'] = $p['BORDER-SPACING-V'] = $attr['CELLSPACING'];
1301 - }
1302 - // cellPadding overwrites TD/TH default but not specific CSS set on cell
1303 - if (($tag=='TD' || $tag=='TH') && isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding']) && ($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'] || $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding']==='0')) { // mPDF 5.7.3
1304 - $p['PADDING-LEFT'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1305 - $p['PADDING-RIGHT'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1306 - $p['PADDING-TOP'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1307 - $p['PADDING-BOTTOM'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1308 - }
1309 -/*-- END TABLES --*/
1310 - //===============================================
1311 - // STYLESHEET TAG e.g. h1 p div table
1312 - if (isset($this->CSS[$tag]) && $this->CSS[$tag]) {
1313 - $zp = $this->CSS[$tag];
1314 - if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1315 - if (is_array($zp)) {
1316 - $p = array_merge($p,$zp);
1317 - $this->_mergeBorders($p,$zp);
1318 - }
1319 - }
1320 - //===============================================
1321 - // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1322 - foreach($classes AS $class) {
1323 - $zp = array();
1324 - if (isset($this->CSS['CLASS>>'.$class]) && $this->CSS['CLASS>>'.$class]) { $zp = $this->CSS['CLASS>>'.$class]; }
1325 - if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1326 - if (is_array($zp)) {
1327 - $p = array_merge($p,$zp);
1328 - $this->_mergeBorders($p,$zp);
1329 - }
1330 - }
1331 - //===============================================
1332 -/*-- TABLES --*/
1333 - // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
1334 - if ($tag=='TR' || $tag=='TD' || $tag=='TH') {
1335 - foreach($this->CSS AS $k=>$val) {
1336 - if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
1337 - $select = false;
1338 - if ($tag=='TR') {
1339 - $row = $this->mpdf->row;
1340 - $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);
1341 - $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);
1342 - if ($this->mpdf->tabletfoot) { $row -= $thnr; }
1343 - else if (!$this->mpdf->tablethead) { $row -= ($thnr + $tfnr); }
1344 - if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1345 - $select = $this->_nthchild($a, $row);
1346 - }
1347 - }
1348 - else if ($tag=='TD' || $tag=='TH') {
1349 - if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1350 - $select = $this->_nthchild($a, $this->mpdf->col);
1351 - }
1352 - }
1353 - if ($select) {
1354 - $zp = $this->CSS[$tag.'>>SELECTORNTHCHILD>>'.$m[1]];
1355 - if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); }
1356 - if (is_array($zp)) {
1357 - $p = array_merge($p,$zp);
1358 - $this->_mergeBorders($p,$zp);
1359 - }
1360 - }
1361 - }
1362 - }
1363 - }
1364 -/*-- END TABLES --*/
1365 - //===============================================
1366 - // STYLESHEET LANG e.g. [lang=fr]{} or :lang(fr)
1367 - if (isset($attr['LANG'])) {
1368 - if (isset($this->CSS['LANG>>'.$attr['LANG']]) && $this->CSS['LANG>>'.$attr['LANG']]) {
1369 - $zp = $this->CSS['LANG>>'.$attr['LANG']];
1370 - if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1371 - if (is_array($zp)) {
1372 - $p = array_merge($p,$zp);
1373 - $this->_mergeBorders($p,$zp);
1374 - }
1375 - }
1376 - else if (isset($this->CSS['LANG>>'.$shortlang]) && $this->CSS['LANG>>'.$shortlang]) {
1377 - $zp = $this->CSS['LANG>>'.$shortlang];
1378 - if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1379 - if (is_array($zp)) {
1380 - $p = array_merge($p,$zp);
1381 - $this->_mergeBorders($p,$zp);
1382 - }
1383 - }
1384 - }
1385 - //===============================================
1386 - // STYLESHEET ID e.g. #smallone{} #redletter{}
1387 - if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']]) && $this->CSS['ID>>'.$attr['ID']]) {
1388 - $zp = $this->CSS['ID>>'.$attr['ID']];
1389 - if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1390 - if (is_array($zp)) {
1391 - $p = array_merge($p,$zp);
1392 - $this->_mergeBorders($p,$zp);
1393 - }
1394 - }
1395 -
1396 - //===============================================
1397 - // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
1398 - foreach($classes AS $class) {
1399 - $zp = array();
1400 - if (isset($this->CSS[$tag.'>>CLASS>>'.$class]) && $this->CSS[$tag.'>>CLASS>>'.$class]) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; }
1401 - if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1402 - if (is_array($zp)) {
1403 - $p = array_merge($p,$zp);
1404 - $this->_mergeBorders($p,$zp);
1405 - }
1406 - }
1407 - //===============================================
1408 - // STYLESHEET LANG e.g. [lang=fr]{} or :lang(fr)
1409 - if (isset($attr['LANG'])) {
1410 - if (isset($this->CSS[$tag.'>>LANG>>'.$attr['LANG']]) && $this->CSS[$tag.'>>LANG>>'.$attr['LANG']]) {
1411 - $zp = $this->CSS[$tag.'>>LANG>>'.$attr['LANG']];
1412 - if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1413 - if (is_array($zp)) {
1414 - $p = array_merge($p,$zp);
1415 - $this->_mergeBorders($p,$zp);
1416 - }
1417 - }
1418 - else if (isset($this->CSS[$tag.'>>LANG>>'.$shortlang]) && $this->CSS[$tag.'>>LANG>>'.$shortlang]) {
1419 - $zp = $this->CSS[$tag.'>>LANG>>'.$shortlang];
1420 - if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1421 - if (is_array($zp)) {
1422 - $p = array_merge($p,$zp);
1423 - $this->_mergeBorders($p,$zp);
1424 - }
1425 - }
1426 - }
1427 - //===============================================
1428 - // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
1429 - if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']]) && $this->CSS[$tag.'>>ID>>'.$attr['ID']]) {
1430 - $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']];
1431 - if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1432 - if (is_array($zp)) {
1433 - $p = array_merge($p,$zp);
1434 - $this->_mergeBorders($p,$zp);
1435 - }
1436 - }
1437 - //===============================================
1438 - // Cascaded e.g. div.class p only works for block level
1439 - if ($inherit == 'BLOCK') {
1440 - if (isset($this->mpdf->blk[$this->mpdf->blklvl-1])) { // mPDF 6
1441 - $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'][$tag], $p);
1442 - foreach($classes AS $class) {
1443 - $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS']['CLASS>>'.$class], $p);
1444 - }
1445 - $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS']['ID>>'.$attr['ID']], $p);
1446 - foreach($classes AS $class) {
1447 - $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p);
1448 - }
1449 - $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p);
1450 - }
1451 - }
1452 - else if ($inherit == 'INLINE') {
1453 - $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$tag], $p);
1454 - foreach($classes AS $class) {
1455 - $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS']['CLASS>>'.$class], $p);
1456 - }
1457 - $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS']['ID>>'.$attr['ID']], $p);
1458 - foreach($classes AS $class) {
1459 - $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p);
1460 - }
1461 - $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p);
1462 - }
1463 -/*-- TABLES --*/
1464 - else if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') { // NB looks at $this->tablecascadeCSS-1 for cascading CSS
1465 - if (isset($this->tablecascadeCSS[$this->tbCSSlvl-1])) { // mPDF 6
1466 - // false, 9 = don't check for 'depth' and do set border dominance
1467 - $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag], $p, false, 9);
1468 - foreach($classes AS $class) {
1469 - $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['CLASS>>'.$class], $p, false, 9);
1470 - }
1471 - // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
1472 - if ($tag=='TR' || $tag=='TD' || $tag=='TH') {
1473 - foreach($this->tablecascadeCSS[$this->tbCSSlvl-1] AS $k=>$val) {
1474 - if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
1475 - $select = false;
1476 - if ($tag=='TR') {
1477 - $row = $this->mpdf->row;
1478 - $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);
1479 - $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);
1480 - if ($this->mpdf->tabletfoot) { $row -= $thnr; }
1481 - else if (!$this->mpdf->tablethead) { $row -= ($thnr + $tfnr); }
1482 - if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1483 - $select = $this->_nthchild($a, $row);
1484 - }
1485 - }
1486 - else if ($tag=='TD' || $tag=='TH') {
1487 - if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1488 - $select = $this->_nthchild($a, $this->mpdf->col);
1489 - }
1490 - }
1491 - if ($select) {
1492 - $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>SELECTORNTHCHILD>>'.$m[1]], $p, false, 9);
1493 - }
1494 - }
1495 - }
1496 - }
1497 - }
1498 - $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['ID>>'.$attr['ID']], $p, false, 9);
1499 - foreach($classes AS $class) {
1500 - $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>CLASS>>'.$class], $p, false, 9);
1501 - }
1502 - $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>ID>>'.$attr['ID']], $p, false, 9);
1503 - }
1504 -/*-- END TABLES --*/
1505 - //===============================================
1506 - //===============================================
1507 - // INLINE STYLE e.g. style="CSS:property"
1508 - if (isset($attr['STYLE'])) {
1509 - $zp = $this->readInlineCSS($attr['STYLE']);
1510 - if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1511 - if (is_array($zp)) {
1512 - $p = array_merge($p,$zp);
1513 - $this->_mergeBorders($p,$zp);
1514 - }
1515 - }
1516 - //===============================================
1517 - //===============================================
1518 - return $p;
1519 -}
1520 -
1521 -
1522 -// Convert inline Properties back to CSS
1523 -function inlinePropsToCSS($bilp, &$p) {
1524 - if (isset($bilp[ 'family' ]) && $bilp[ 'family' ]) { $p['FONT-FAMILY'] = $bilp[ 'family' ]; }
1525 - if (isset($bilp[ 'I' ]) && $bilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; }
1526 - if (isset($bilp[ 'sizePt' ]) && $bilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $bilp[ 'sizePt' ] . 'pt'; }
1527 - if (isset($bilp[ 'B' ]) && $bilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; }
1528 - if (isset($bilp[ 'colorarray' ]) && $bilp[ 'colorarray' ]) {
1529 - $cor = $bilp[ 'colorarray' ];
1530 - $p['COLOR'] = $this->mpdf->_colAtoString($cor);
1531 - }
1532 - if (isset($bilp[ 'lSpacingCSS' ]) && $bilp[ 'lSpacingCSS' ]) { $p['LETTER-SPACING'] = $bilp[ 'lSpacingCSS' ]; }
1533 - if (isset($bilp[ 'wSpacingCSS' ]) && $bilp[ 'wSpacingCSS' ]) { $p['WORD-SPACING'] = $bilp[ 'wSpacingCSS' ]; }
1534 -
1535 - if (isset($bilp[ 'textparam' ]) && $bilp[ 'textparam' ]) {
1536 - if (isset($bilp[ 'textparam' ]['hyphens'])) {
1537 - if ($bilp[ 'textparam' ]['hyphens']==2) { $p['HYPHENS'] = 'none'; }
1538 - if ($bilp[ 'textparam' ]['hyphens']==1) { $p['HYPHENS'] = 'auto'; }
1539 - if ($bilp[ 'textparam' ]['hyphens']==0) { $p['HYPHENS'] = 'manual'; }
1540 - }
1541 - if (isset($bilp[ 'textparam' ]['outline-s']) && !$bilp[ 'textparam' ]['outline-s']) { $p['TEXT-OUTLINE'] = 'none'; }
1542 - if (isset($bilp[ 'textparam' ]['outline-COLOR']) && $bilp[ 'textparam' ]['outline-COLOR']) { $p['TEXT-OUTLINE-COLOR'] = $this->mpdf->_colAtoString($bilp[ 'textparam' ]['outline-COLOR']); }
1543 - if (isset($bilp[ 'textparam' ]['outline-WIDTH']) && $bilp[ 'textparam' ]['outline-WIDTH']) { $p['TEXT-OUTLINE-WIDTH'] = $bilp[ 'textparam' ]['outline-WIDTH'].'mm'; }
1544 - }
1545 -
1546 - if (isset($bilp[ 'textvar' ]) && $bilp[ 'textvar' ]) {
1547 - // CSS says text-decoration is not inherited, but IE7 does??
1548 - if ($bilp[ 'textvar' ] & FD_LINETHROUGH) {
1549 - if ($bilp[ 'textvar' ] & FD_UNDERLINE) { $p['TEXT-DECORATION'] = 'underline line-through'; }
1550 - else { $p['TEXT-DECORATION'] = 'line-through'; }
1551 - }
1552 - else if ($bilp[ 'textvar' ] & FD_UNDERLINE) { $p['TEXT-DECORATION'] = 'underline'; }
1553 - else { $p['TEXT-DECORATION'] = 'none'; }
1554 -
1555 - if ($bilp[ 'textvar' ] & FA_SUPERSCRIPT) { $p['VERTICAL-ALIGN'] = 'super'; }
1556 - else if ($bilp[ 'textvar' ] & FA_SUBSCRIPT) { $p['VERTICAL-ALIGN'] = 'sub'; }
1557 - else { $p['VERTICAL-ALIGN'] = 'baseline'; }
1558 -
1559 - if ($bilp[ 'textvar' ] & FT_CAPITALIZE) { $p['TEXT-TRANSFORM'] = 'capitalize'; }
1560 - else if ($bilp[ 'textvar' ] & FT_UPPERCASE) { $p['TEXT-TRANSFORM'] = 'uppercase'; }
1561 - else if ($bilp[ 'textvar' ] & FT_LOWERCASE) { $p['TEXT-TRANSFORM'] = 'lowercase'; }
1562 - else { $p['TEXT-TRANSFORM'] = 'none'; }
1563 -
1564 - if ($bilp[ 'textvar' ] & FC_KERNING) { $p['FONT-KERNING'] = 'normal'; } // ignore 'auto' as default already applied
1565 - //if (isset($bilp[ 'OTLtags' ]) && $bilp[ 'OTLtags' ]['Plus'] contains 'kern'
1566 - else { $p['FONT-KERNING'] = 'none'; }
1567 -
1568 - if ($bilp[ 'textvar' ] & FA_SUPERSCRIPT) { $p['FONT-VARIANT-POSITION'] = 'super'; }
1569 - //if (isset($bilp[ 'OTLtags' ]) && $bilp[ 'OTLtags' ]['Plus'] contains 'sups' / 'subs'
1570 - else if ($bilp[ 'textvar' ] & FA_SUBSCRIPT) { $p['FONT-VARIANT-POSITION'] = 'sub'; }
1571 - else { $p['FONT-VARIANT-POSITION'] = 'normal'; }
1572 -
1573 - if ($bilp[ 'textvar' ] & FC_SMALLCAPS) { $p['FONT-VARIANT-CAPS'] = 'small-caps'; }
1574 - }
1575 - if (isset($bilp[ 'fontLanguageOverride' ])) {
1576 - if ($bilp[ 'fontLanguageOverride' ]) { $p['FONT-LANGUAGE-OVERRIDE'] = $bilp[ 'fontLanguageOverride' ]; }
1577 - else { $p['FONT-LANGUAGE-OVERRIDE'] = 'normal'; }
1578 - }
1579 - // All the variations of font-variant-* we are going to set as font-feature-settings...
1580 - if (isset($bilp[ 'OTLtags' ]) && $bilp[ 'OTLtags' ]) {
1581 - $ffs = array();
1582 - if (isset($bilp['OTLtags']['Minus']) && $bilp['OTLtags']['Minus']) {
1583 - $f = preg_split('/\s+/', trim($bilp['OTLtags']['Minus']));
1584 - foreach($f AS $ff) { $ffs[] = "'".$ff."' 0"; }
1585 - }
1586 - if (isset($bilp['OTLtags']['FFMinus']) && $bilp['OTLtags']['FFMinus']) {
1587 - $f = preg_split('/\s+/', trim($bilp['OTLtags']['FFMinus']));
1588 - foreach($f AS $ff) { $ffs[] = "'".$ff."' 0"; }
1589 - }
1590 - if (isset($bilp['OTLtags']['Plus']) && $bilp['OTLtags']['Plus']) {
1591 - $f = preg_split('/\s+/', trim($bilp['OTLtags']['Plus']));
1592 - foreach($f AS $ff) { $ffs[] = "'".$ff."' 1"; }
1593 - }
1594 - if (isset($bilp['OTLtags']['FFPlus']) && $bilp['OTLtags']['FFPlus']) { // May contain numeric value e.g. salt4
1595 - $f = preg_split('/\s+/', trim($bilp['OTLtags']['FFPlus']));
1596 - foreach($f AS $ff) {
1597 - if (strlen($ff)>4) { $ffs[] = "'".substr($ff,0,4)."' ".substr($ff,4); }
1598 - else { $ffs[] = "'".$ff."' 1"; }
1599 - }
1600 - }
1601 - $p['FONT-FEATURE-SETTINGS'] = implode(', ', $ffs);
1602 - }
1603 -
1604 -
1605 -}
1606 -
1607 -function PreviewBlockCSS($tag,$attr) {
1608 - // Looks ahead from current block level to a new level
1609 - $p = array();
1610 - $zp = array();
1611 - $oldcascadeCSS = $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'];
1612 - $classes = array();
1613 - if (isset($attr['CLASS'])) { $classes = preg_split('/\s+/',$attr['CLASS']); }
1614 - //===============================================
1615 - // DEFAULT for this TAG set in DefaultCSS
1616 - if (isset($this->mpdf->defaultCSS[$tag])) {
1617 - $zp = $this->fixCSS($this->mpdf->defaultCSS[$tag]);
1618 - if (is_array($zp)) { $p = array_merge($zp,$p); } // Inherited overwrites default
1619 - }
1620 - // STYLESHEET TAG e.g. h1 p div table
1621 - if (isset($this->CSS[$tag])) {
1622 - $zp = $this->CSS[$tag];
1623 - if (is_array($zp)) { $p = array_merge($p,$zp); }
1624 - }
1625 - // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1626 - foreach($classes AS $class) {
1627 - $zp = array();
1628 - if (isset($this->CSS['CLASS>>'.$class])) { $zp = $this->CSS['CLASS>>'.$class]; }
1629 - if (is_array($zp)) { $p = array_merge($p,$zp); }
1630 - }
1631 - // STYLESHEET ID e.g. #smallone{} #redletter{}
1632 - if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']])) {
1633 - $zp = $this->CSS['ID>>'.$attr['ID']];
1634 - if (is_array($zp)) { $p = array_merge($p,$zp); }
1635 - }
1636 - // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
1637 - foreach($classes AS $class) {
1638 - $zp = array();
1639 - if (isset($this->CSS[$tag.'>>CLASS>>'.$class])) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; }
1640 - if (is_array($zp)) { $p = array_merge($p,$zp); }
1641 - }
1642 - // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
1643 - if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']])) {
1644 - $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']];
1645 - if (is_array($zp)) { $p = array_merge($p,$zp); }
1646 - }
1647 - //===============================================
1648 - // STYLESHEET TAG e.g. div h1 div p
1649 -
1650 - $this->_set_mergedCSS($oldcascadeCSS[$tag], $p);
1651 - // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1652 - foreach($classes AS $class) {
1653 -
1654 - $this->_set_mergedCSS($oldcascadeCSS['CLASS>>'.$class], $p);
1655 - }
1656 - // STYLESHEET CLASS e.g. #smallone{} #redletter{}
1657 - if (isset($attr['ID'])) {
1658 -
1659 - $this->_set_mergedCSS($oldcascadeCSS['ID>>'.$attr['ID']], $p);
1660 - }
1661 - // STYLESHEET CLASS e.g. div.smallone{} p.redletter{}
1662 - foreach($classes AS $class) {
1663 -
1664 - $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>CLASS>>'.$class], $p);
1665 - }
1666 - // STYLESHEET CLASS e.g. div#smallone{} p#redletter{}
1667 - if (isset($attr['ID'])) {
1668 -
1669 - $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>ID>>'.$attr['ID']], $p);
1670 - }
1671 - //===============================================
1672 - // INLINE STYLE e.g. style="CSS:property"
1673 - if (isset($attr['STYLE'])) {
1674 - $zp = $this->readInlineCSS($attr['STYLE']);
1675 - if (is_array($zp)) { $p = array_merge($p,$zp); }
1676 - }
1677 - //===============================================
1678 - return $p;
1679 -}
1680 -
1681 -
1682 -// mPDF 5.7.4 nth-child
1683 -function _nthchild($f, $c) {
1684 - // $f is formual e.g. 2N+1 spilt into a preg_match array
1685 - // $c is the comparator value e.g row or column number
1686 - $c += 1;
1687 - $select = false;
1688 - $a=1; $b=1;
1689 - if ($f[0]=='ODD') { $a=2; $b=1; }
1690 - else if ($f[0]=='EVEN') { $a=2; $b=0; }
1691 - else if (count($f)==2) { $a=0; $b=$f[1]+0; } // e.g. (+6)
1692 - else if (count($f)==3) { // e.g. (2N)
1693 - if ($f[2]=='') { $a=1; }
1694 - else if ($f[2]=='-') { $a=-1; }
1695 - else { $a=$f[2]+0; }
1696 - $b=0;
1697 - }
1698 - else if (count($f)==4) { // e.g. (2N+6)
1699 - if ($f[2]=='') { $a=1; }
1700 - else if ($f[2]=='-') { $a=-1; }
1701 - else { $a=$f[2]+0; }
1702 - $b=$f[3]+0;
1703 - }
1704 - else { return false; }
1705 - if ($a>0) {
1706 - if (((($c % $a) - $b) % $a) == 0 && $c >= $b) { $select = true; }
1707 - }
1708 - else if ($a==0) {
1709 - if ($c == $b) { $select = true; }
1710 - }
1711 - else { // if ($a<0)
1712 - if (((($c % $a) - $b) % $a) == 0 && $c <= $b) { $select = true; }
1713 - }
1714 - return $select;
1715 -}
1716 -
1717 -
1718 -
1719 -} // end of class
1720 -
1721 -?>
1 +<?php
2 +
3 +class cssmgr
4 +{
5 +
6 + var $mpdf = null;
7 +
8 + var $tablecascadeCSS;
9 +
10 + var $cascadeCSS;
11 +
12 + var $CSS;
13 +
14 + var $tbCSSlvl;
15 +
16 + public function __construct(mPDF $mpdf)
17 + {
18 + $this->mpdf = $mpdf;
19 + $this->tablecascadeCSS = array();
20 + $this->CSS = array();
21 + $this->cascadeCSS = array();
22 + $this->tbCSSlvl = 0;
23 + }
24 +
25 + function ReadCSS($html)
26 + {
27 + preg_match_all('/<style[^>]*media=["\']([^"\'>]*)["\'].*?<\/style>/is', $html, $m);
28 + for ($i = 0; $i < count($m[0]); $i++) {
29 + if ($this->mpdf->CSSselectMedia && !preg_match('/(' . trim($this->mpdf->CSSselectMedia) . '|all)/i', $m[1][$i])) {
30 + $html = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', '', $html);
31 + }
32 + }
33 + preg_match_all('/<link[^>]*media=["\']([^"\'>]*)["\'].*?>/is', $html, $m);
34 + for ($i = 0; $i < count($m[0]); $i++) {
35 + if ($this->mpdf->CSSselectMedia && !preg_match('/(' . trim($this->mpdf->CSSselectMedia) . '|all)/i', $m[1][$i])) {
36 + $html = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', '', $html);
37 + }
38 + }
39 +
40 + // mPDF 5.5.02
41 + // Remove Comment tags <!-- ... --> inside CSS as <style> in HTML document
42 + // Remove Comment tags /* ... */ inside CSS as <style> in HTML document
43 + // But first, we replace upper and mixed case closing style tag with lower
44 + // case so we can use str_replace later.
45 + preg_match_all('/<style.*?>(.*?)<\/style>/si',$html,$m);
46 + if (count($m[1])) {
47 + for ($i = 0; $i < count($m[1]); $i++) {
48 + // Remove comment tags
49 + $sub = preg_replace('/(<\!\-\-|\-\->)/s',' ',$m[1][$i]);
50 + $sub = '>'.preg_replace('|/\*.*?\*/|s',' ',$sub).'</style>';
51 + $html = str_replace('>'.$m[1][$i].'</style>', $sub, $html);
52 +
53 + }
54 + }
55 +
56 + $html = preg_replace('/<!--mpdf/i', '', $html);
57 + $html = preg_replace('/mpdf-->/i', '', $html);
58 + $html = preg_replace('/<\!\-\-.*?\-\->/s', ' ', $html);
59 +
60 + $match = 0; // no match for instance
61 + $regexp = ''; // This helps debugging: showing what is the REAL string being processed
62 + $CSSext = array();
63 +
64 + //CSS inside external files
65 + $regexp = '/<link[^>]*rel=["\']stylesheet["\'][^>]*href=["\']([^>"\']*)["\'].*?>/si';
66 + $x = preg_match_all($regexp, $html, $cxt);
67 + if ($x) {
68 + $match += $x;
69 + $CSSext = $cxt[1];
70 + }
71 + $regexp = '/<link[^>]*href=["\']([^>"\']*)["\'][^>]*?rel=["\']stylesheet["\'].*?>/si';
72 + $x = preg_match_all($regexp, $html, $cxt);
73 + if ($x) {
74 + $match += $x;
75 + $CSSext = array_merge($CSSext, $cxt[1]);
76 + }
77 +
78 + // look for @import stylesheets
79 + //$regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css)[\'\"]{0,1}\)/si';
80 + $regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css(\?\S+)?)[\'\"]{0,1}\)/si';
81 + $x = preg_match_all($regexp, $html, $cxt);
82 + if ($x) {
83 + $match += $x;
84 + $CSSext = array_merge($CSSext, $cxt[1]);
85 + }
86 +
87 + // look for @import without the url()
88 + //$regexp = '/@import [\'\"]{0,1}([^;]*?\.css)[\'\"]{0,1}/si';
89 + $regexp = '/@import [\'\"]{0,1}([^;]*?\.css(\?\S+)?)[\'\"]{0,1}/si';
90 + $x = preg_match_all($regexp, $html, $cxt);
91 + if ($x) {
92 + $match += $x;
93 + $CSSext = array_merge($CSSext, $cxt[1]);
94 + }
95 +
96 + $ind = 0;
97 + $CSSstr = '';
98 +
99 + if (!is_array($this->cascadeCSS))
100 + $this->cascadeCSS = array();
101 +
102 + while ($match) {
103 + $path = $CSSext[$ind];
104 +
105 + $path = htmlspecialchars_decode($path); // mPDF 6
106 +
107 + $this->mpdf->GetFullPath($path);
108 + $CSSextblock = $this->mpdf->_get_file($path);
109 + if ($CSSextblock) {
110 + // look for embedded @import stylesheets in other stylesheets
111 + // and fix url paths (including background-images) relative to stylesheet
112 + //$regexpem = '/@import url\([\'\"]{0,1}(.*?\.css)[\'\"]{0,1}\)/si';
113 + $regexpem = '/@import url\([\'\"]{0,1}(.*?\.css(\?\S+)?)[\'\"]{0,1}\)/si';
114 + $xem = preg_match_all($regexpem, $CSSextblock, $cxtem);
115 + $cssBasePath = preg_replace('/\/[^\/]*$/', '', $path) . '/';
116 + if ($xem) {
117 + foreach ($cxtem[1] AS $cxtembedded) {
118 + // path is relative to original stlyesheet!!
119 + $this->mpdf->GetFullPath($cxtembedded, $cssBasePath);
120 + $match++;
121 + $CSSext[] = $cxtembedded;
122 + }
123 + }
124 + $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
125 + $xem = preg_match_all($regexpem, $CSSextblock, $cxtem);
126 + if ($xem) {
127 + for ($i = 0; $i < count($cxtem[0]); $i++) {
128 + // path is relative to original stlyesheet!!
129 + $embedded = $cxtem[2][$i];
130 + if (!preg_match('/^data:image/i', $embedded)) { // mPDF 5.5.13
131 + $this->mpdf->GetFullPath($embedded, $cssBasePath);
132 + $CSSextblock = preg_replace('/' . preg_quote($cxtem[0][$i], '/') . '/', ($cxtem[1][$i] . $embedded . $cxtem[3][$i]), $CSSextblock);
133 + }
134 + }
135 + }
136 + $CSSstr .= ' ' . $CSSextblock;
137 + }
138 + $match--;
139 + $ind++;
140 + } //end of match
141 +
142 + $match = 0; // reset value, if needed
143 + // CSS as <style> in HTML document
144 + $regexp = '/<style.*?>(.*?)<\/style>/si';
145 + $match = preg_match_all($regexp, $html, $CSSblock);
146 + if ($match) {
147 + $tmpCSSstr = implode(' ', $CSSblock[1]);
148 + $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
149 + $xem = preg_match_all($regexpem, $tmpCSSstr, $cxtem);
150 + if ($xem) {
151 + for ($i = 0; $i < count($cxtem[0]); $i++) {
152 + $embedded = $cxtem[2][$i];
153 + if (!preg_match('/^data:image/i', $embedded)) { // mPDF 5.5.13
154 + $this->mpdf->GetFullPath($embedded);
155 + $tmpCSSstr = preg_replace('/' . preg_quote($cxtem[0][$i], '/') . '/', ($cxtem[1][$i] . $embedded . $cxtem[3][$i]), $tmpCSSstr);
156 + }
157 + }
158 + }
159 + $CSSstr .= ' ' . $tmpCSSstr;
160 + }
161 + // Remove comments
162 + $CSSstr = preg_replace('|/\*.*?\*/|s', ' ', $CSSstr);
163 + $CSSstr = preg_replace('/[\s\n\r\t\f]/s', ' ', $CSSstr);
164 +
165 + if (preg_match('/@media/', $CSSstr)) {
166 + preg_match_all('/@media(.*?)\{(([^\{\}]*\{[^\{\}]*\})+)\s*\}/is', $CSSstr, $m);
167 + for ($i = 0; $i < count($m[0]); $i++) {
168 + if ($this->mpdf->CSSselectMedia && !preg_match('/(' . trim($this->mpdf->CSSselectMedia) . '|all)/i', $m[1][$i])) {
169 + $CSSstr = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', '', $CSSstr);
170 + } else {
171 + $CSSstr = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', ' ' . $m[2][$i] . ' ', $CSSstr);
172 + }
173 + }
174 + }
175 +
176 + // Replace any background: url(data:image... with temporary image file reference
177 + preg_match_all("/(url\(data:image\/(jpeg|gif|png);base64,(.*?)\))/si", $CSSstr, $idata); // mPDF 5.7.2
178 + if (count($idata[0])) {
179 + for ($i = 0; $i < count($idata[0]); $i++) {
180 + $file = _MPDF_TEMP_PATH . '_tempCSSidata' . RAND(1, 10000) . '_' . $i . '.' . $idata[2][$i];
181 + //Save to local file
182 + file_put_contents($file, base64_decode($idata[3][$i]));
183 + // $this->mpdf->GetFullPath($file); // ? is this needed - NO mPDF 5.6.03
184 + $CSSstr = str_replace($idata[0][$i], 'url("' . $file . '")', $CSSstr); // mPDF 5.5.17
185 + }
186 + }
187 +
188 + $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s', ' ', $CSSstr);
189 +
190 + // mPDF 5.7.4 URLs
191 + // Characters "(" ")" and ";" in url() e.g. background-image, cause problems parsing the CSS string
192 + // URLencode ( and ), but change ";" to a code which can be converted back after parsing (so as not to confuse ;
193 + // with a segment delimiter in the URI)
194 + $tempmarker = '%ZZ';
195 + if (strpos($CSSstr, 'url(') !== false) {
196 + preg_match_all('/url\(\"(.*?)\"\)/', $CSSstr, $m);
197 + for ($i = 0; $i < count($m[1]); $i++) {
198 + $tmp = str_replace(array('(', ')', ';'), array('%28', '%29', $tempmarker), $m[1][$i]);
199 + $CSSstr = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', 'url(\'' . $tmp . '\')', $CSSstr);
200 + }
201 + preg_match_all('/url\(\'(.*?)\'\)/', $CSSstr, $m);
202 + for ($i = 0; $i < count($m[1]); $i++) {
203 + $tmp = str_replace(array('(', ')', ';'), array('%28', '%29', $tempmarker), $m[1][$i]);
204 + $CSSstr = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', 'url(\'' . $tmp . '\')', $CSSstr);
205 + }
206 + preg_match_all('/url\(([^\'\"].*?[^\'\"])\)/', $CSSstr, $m);
207 + for ($i = 0; $i < count($m[1]); $i++) {
208 + $tmp = str_replace(array('(', ')', ';'), array('%28', '%29', $tempmarker), $m[1][$i]);
209 + $CSSstr = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', 'url(\'' . $tmp . '\')', $CSSstr);
210 + }
211 + }
212 +
213 +
214 +
215 + if ($CSSstr) {
216 + $classproperties = array(); // mPDF 6
217 + preg_match_all('/(.*?)\{(.*?)\}/', $CSSstr, $styles);
218 + for ($i = 0; $i < count($styles[1]); $i++) {
219 + // SET array e.g. $classproperties['COLOR'] = '#ffffff';
220 + $stylestr = trim($styles[2][$i]);
221 + $stylearr = explode(';', $stylestr);
222 + foreach ($stylearr AS $sta) {
223 + if (trim($sta)) {
224 + // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')"
225 + $tmp = explode(':', $sta, 2);
226 + $property = $tmp[0];
227 + if (isset($tmp[1])) {
228 + $value = $tmp[1];
229 + } else {
230 + $value = '';
231 + }
232 + $value = str_replace($tempmarker, ';', $value); // mPDF 5.7.4 URLs
233 + $property = trim($property);
234 + $value = preg_replace('/\s*!important/i', '', $value);
235 + $value = trim($value);
236 + if ($property && ($value || $value === '0')) {
237 + // Ignores -webkit-gradient so doesn't override -moz-
238 + if ((strtoupper($property) == 'BACKGROUND-IMAGE' || strtoupper($property) == 'BACKGROUND') && preg_match('/-webkit-gradient/i', $value)) {
239 + continue;
240 + }
241 + $classproperties[strtoupper($property)] = $value;
242 + }
243 + }
244 + }
245 + $classproperties = $this->fixCSS($classproperties);
246 + $tagstr = strtoupper(trim($styles[1][$i]));
247 + $tagarr = explode(',', $tagstr);
248 + $pageselectors = false; // used to turn on $this->mpdf->mirrorMargins
249 + foreach ($tagarr AS $tg) {
250 + // mPDF 5.7.4
251 + if (preg_match('/NTH-CHILD\((\s*(([\-+]?\d*)N(\s*[\-+]\s*\d+)?|[\-+]?\d+|ODD|EVEN)\s*)\)/', $tg, $m)) {
252 + $tg = preg_replace('/NTH-CHILD\(.*\)/', 'NTH-CHILD(' . str_replace(' ', '', $m[1]) . ')', $tg);
253 + }
254 + $tags = preg_split('/\s+/', trim($tg));
255 + $level = count($tags);
256 + $t = '';
257 + $t2 = '';
258 + $t3 = '';
259 + if (trim($tags[0]) == '@PAGE') {
260 + if (isset($tags[0])) {
261 + $t = trim($tags[0]);
262 + }
263 + if (isset($tags[1])) {
264 + $t2 = trim($tags[1]);
265 + }
266 + if (isset($tags[2])) {
267 + $t3 = trim($tags[2]);
268 + }
269 + $tag = '';
270 + if ($level == 1) {
271 + $tag = $t;
272 + } else if ($level == 2 && preg_match('/^[:](.*)$/', $t2, $m)) {
273 + $tag = $t . '>>PSEUDO>>' . $m[1];
274 + if ($m[1] == 'LEFT' || $m[1] == 'RIGHT') {
275 + $pageselectors = true;
276 + } // used to turn on $this->mpdf->mirrorMargins
277 + } else if ($level == 2) {
278 + $tag = $t . '>>NAMED>>' . $t2;
279 + } else if ($level == 3 && preg_match('/^[:](.*)$/', $t3, $m)) {
280 + $tag = $t . '>>NAMED>>' . $t2 . '>>PSEUDO>>' . $m[1];
281 + if ($m[1] == 'LEFT' || $m[1] == 'RIGHT') {
282 + $pageselectors = true;
283 + } // used to turn on $this->mpdf->mirrorMargins
284 + }
285 + if (isset($this->CSS[$tag]) && $tag) {
286 + $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties);
287 + } else if ($tag) {
288 + $this->CSS[$tag] = $classproperties;
289 + }
290 + } else if ($level == 1) { // e.g. p or .class or #id or p.class or p#id
291 + if (isset($tags[0])) {
292 + $t = trim($tags[0]);
293 + }
294 + if ($t) {
295 + $tag = '';
296 + if (preg_match('/^[.](.*)$/', $t, $m)) {
297 + $tag = 'CLASS>>' . $m[1];
298 + } else if (preg_match('/^[#](.*)$/', $t, $m)) {
299 + $tag = 'ID>>' . $m[1];
300 + } else if (preg_match('/^\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/', $t, $m)) {
301 + $tag = 'LANG>>' . strtolower($m[1]);
302 + } // mPDF 6 Special case for lang as attribute selector
303 + else if (preg_match('/^:LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/', $t, $m)) {
304 + $tag = 'LANG>>' . strtolower($m[1]);
305 + } // mPDF 6 Special case for lang as attribute selector
306 + else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')[.](.*)$/', $t, $m)) {
307 + $tag = $m[1] . '>>CLASS>>' . $m[2];
308 + } else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')\s*:NTH-CHILD\((.*)\)$/', $t, $m)) {
309 + $tag = $m[1] . '>>SELECTORNTHCHILD>>' . $m[2];
310 + } else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')[#](.*)$/', $t, $m)) {
311 + $tag = $m[1] . '>>ID>>' . $m[2];
312 + } else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/', $t, $m)) {
313 + $tag = $m[1] . '>>LANG>>' . strtolower($m[2]);
314 + } // mPDF 6 Special case for lang as attribute selector
315 + else if (preg_match('/^(' . $this->mpdf->allowedCSStags . '):LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/', $t, $m)) {
316 + $tag = $m[1] . '>>LANG>>' . strtolower($m[2]);
317 + } // mPDF 6 Special case for lang as attribute selector
318 + else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')$/', $t)) {
319 + $tag = $t;
320 + }
321 + if (isset($this->CSS[$tag]) && $tag) {
322 + $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties);
323 + } else if ($tag) {
324 + $this->CSS[$tag] = $classproperties;
325 + }
326 + }
327 + } else {
328 + $tmp = array();
329 + for ($n = 0; $n < $level; $n++) {
330 + if (isset($tags[$n])) {
331 + $t = trim($tags[$n]);
332 + } else {
333 + $t = '';
334 + }
335 + if ($t) {
336 + $tag = '';
337 + if (preg_match('/^[.](.*)$/', $t, $m)) {
338 + $tag = 'CLASS>>' . $m[1];
339 + } else if (preg_match('/^[#](.*)$/', $t, $m)) {
340 + $tag = 'ID>>' . $m[1];
341 + } else if (preg_match('/^\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/', $t, $m)) {
342 + $tag = 'LANG>>' . strtolower($m[1]);
343 + } // mPDF 6 Special case for lang as attribute selector
344 + else if (preg_match('/^:LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/', $t, $m)) {
345 + $tag = 'LANG>>' . strtolower($m[1]);
346 + } // mPDF 6 Special case for lang as attribute selector
347 + else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')[.](.*)$/', $t, $m)) {
348 + $tag = $m[1] . '>>CLASS>>' . $m[2];
349 + } else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')\s*:NTH-CHILD\((.*)\)$/', $t, $m)) {
350 + $tag = $m[1] . '>>SELECTORNTHCHILD>>' . $m[2];
351 + } else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')[#](.*)$/', $t, $m)) {
352 + $tag = $m[1] . '>>ID>>' . $m[2];
353 + } else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/', $t, $m)) {
354 + $tag = $m[1] . '>>LANG>>' . strtolower($m[2]);
355 + } // mPDF 6 Special case for lang as attribute selector
356 + else if (preg_match('/^(' . $this->mpdf->allowedCSStags . '):LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/', $t, $m)) {
357 + $tag = $m[1] . '>>LANG>>' . strtolower($m[2]);
358 + } // mPDF 6 Special case for lang as attribute selector
359 + else if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')$/', $t)) {
360 + $tag = $t;
361 + }
362 +
363 + if ($tag)
364 + $tmp[] = $tag;
365 + else {
366 + break;
367 + }
368 + }
369 + }
370 +
371 + if ($tag) {
372 + $x = &$this->cascadeCSS;
373 + foreach ($tmp AS $tp) {
374 + $x = &$x[$tp];
375 + }
376 + $x = $this->array_merge_recursive_unique($x, $classproperties);
377 + $x['depth'] = $level;
378 + }
379 + }
380 + }
381 + if ($pageselectors) {
382 + $this->mpdf->mirrorMargins = true;
383 + }
384 + $properties = array();
385 + $values = array();
386 + $classproperties = array();
387 + }
388 + } // end of if
389 + //Remove CSS (tags and content), if any
390 + $regexp = '/<style.*?>(.*?)<\/style>/si'; // it can be <style> or <style type="txt/css">
391 + $html = preg_replace($regexp, '', $html);
392 +//print_r($this->CSS); exit;
393 +//print_r($this->cascadeCSS); exit;
394 + return $html;
395 + }
396 +
397 + function readInlineCSS($html)
398 + {
399 + $html = htmlspecialchars_decode($html); // mPDF 5.7.4 URLs
400 + // mPDF 5.7.4 URLs
401 + // Characters "(" ")" and ";" in url() e.g. background-image, cause probems parsing the CSS string
402 + // URLencode ( and ), but change ";" to a code which can be converted back after parsing (so as not to confuse ;
403 + // with a segment delimiter in the URI)
404 + $tempmarker = '%ZZ';
405 + if (strpos($html, 'url(') !== false) {
406 + preg_match_all('/url\(\"(.*?)\"\)/', $html, $m);
407 + for ($i = 0; $i < count($m[1]); $i++) {
408 + $tmp = str_replace(array('(', ')', ';'), array('%28', '%29', $tempmarker), $m[1][$i]);
409 + $html = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', 'url(\'' . $tmp . '\')', $html);
410 + }
411 + preg_match_all('/url\(\'(.*?)\'\)/', $html, $m);
412 + for ($i = 0; $i < count($m[1]); $i++) {
413 + $tmp = str_replace(array('(', ')', ';'), array('%28', '%29', $tempmarker), $m[1][$i]);
414 + $html = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', 'url(\'' . $tmp . '\')', $html);
415 + }
416 + preg_match_all('/url\(([^\'\"].*?[^\'\"])\)/', $html, $m);
417 + for ($i = 0; $i < count($m[1]); $i++) {
418 + $tmp = str_replace(array('(', ')', ';'), array('%28', '%29', $tempmarker), $m[1][$i]);
419 + $html = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', 'url(\'' . $tmp . '\')', $html);
420 + }
421 + }
422 + //Fix incomplete CSS code
423 + $size = strlen($html) - 1;
424 + if (substr($html, $size, 1) != ';')
425 + $html .= ';';
426 + //Make CSS[Name-of-the-class] = array(key => value)
427 + $regexp = '|\\s*?(\\S+?):(.+?);|i';
428 + preg_match_all($regexp, $html, $styleinfo);
429 + $properties = $styleinfo[1];
430 + $values = $styleinfo[2];
431 + //Array-properties and Array-values must have the SAME SIZE!
432 + $classproperties = array();
433 + for ($i = 0; $i < count($properties); $i++) {
434 + // Ignores -webkit-gradient so doesn't override -moz-
435 + if ((strtoupper($properties[$i]) == 'BACKGROUND-IMAGE' || strtoupper($properties[$i]) == 'BACKGROUND') && preg_match('/-webkit-gradient/i', $values[$i])) {
436 + continue;
437 + }
438 + $values[$i] = str_replace($tempmarker, ';', $values[$i]); // mPDF 5.7.4 URLs
439 + $classproperties[strtoupper($properties[$i])] = trim($values[$i]);
440 + }
441 + return $this->fixCSS($classproperties);
442 + }
443 +
444 + function _fix_borderStr($bd)
445 + {
446 + preg_match_all("/\((.*?)\)/", $bd, $m);
447 + if (count($m[1])) {
448 + for ($i = 0; $i < count($m[1]); $i++) {
449 + $sub = preg_replace("/ /", "", $m[1][$i]);
450 + $bd = preg_replace('/' . preg_quote($m[1][$i], '/') . '/si', $sub, $bd);
451 + }
452 + }
453 +
454 + $prop = preg_split('/\s+/', trim($bd));
455 + $w = 'medium';
456 + $c = '#000000';
457 + $s = 'none';
458 +
459 + if (count($prop) == 1) {
460 + // solid
461 + if (in_array($prop[0], $this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden') {
462 + $s = $prop[0];
463 + }
464 + // #000000
465 + else if (is_array($this->mpdf->ConvertColor($prop[0]))) {
466 + $c = $prop[0];
467 + }
468 + // 1px
469 + else {
470 + $w = $prop[0];
471 + }
472 + } else if (count($prop) == 2) {
473 + // 1px solid
474 + if (in_array($prop[1], $this->mpdf->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden') {
475 + $w = $prop[0];
476 + $s = $prop[1];
477 + }
478 + // solid #000000
479 + else if (in_array($prop[0], $this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden') {
480 + $s = $prop[0];
481 + $c = $prop[1];
482 + }
483 + // 1px #000000
484 + else {
485 + $w = $prop[0];
486 + $c = $prop[1];
487 + }
488 + } else if (count($prop) == 3) {
489 + // Change #000000 1px solid to 1px solid #000000 (proper)
490 + if (substr($prop[0], 0, 1) == '#') {
491 + $c = $prop[0];
492 + $w = $prop[1];
493 + $s = $prop[2];
494 + }
495 + // Change solid #000000 1px to 1px solid #000000 (proper)
496 + else if (substr($prop[0], 1, 1) == '#') {
497 + $s = $prop[0];
498 + $c = $prop[1];
499 + $w = $prop[2];
500 + }
501 + // Change solid 1px #000000 to 1px solid #000000 (proper)
502 + else if (in_array($prop[0], $this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden') {
503 + $s = $prop[0];
504 + $w = $prop[1];
505 + $c = $prop[2];
506 + } else {
507 + $w = $prop[0];
508 + $s = $prop[1];
509 + $c = $prop[2];
510 + }
511 + } else {
512 + return '';
513 + }
514 + $s = strtolower($s);
515 + return $w . ' ' . $s . ' ' . $c;
516 + }
517 +
518 + function fixCSS($prop)
519 + {
520 + if (!is_array($prop) || (count($prop) == 0))
521 + return array();
522 + $newprop = array();
523 + foreach ($prop AS $k => $v) {
524 + 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') {
525 + $v = strtolower($v);
526 + }
527 +
528 + if ($k == 'FONT') {
529 + $s = trim($v);
530 + preg_match_all('/\"(.*?)\"/', $s, $ff);
531 + if (count($ff[1])) {
532 + foreach ($ff[1] AS $ffp) {
533 + $w = preg_split('/\s+/', $ffp);
534 + $s = preg_replace('/\"' . $ffp . '\"/', $w[0], $s);
535 + }
536 + }
537 + preg_match_all('/\'(.*?)\'/', $s, $ff);
538 + if (count($ff[1])) {
539 + foreach ($ff[1] AS $ffp) {
540 + $w = preg_split('/\s+/', $ffp);
541 + $s = preg_replace('/\'' . $ffp . '\'/', $w[0], $s);
542 + }
543 + }
544 + $s = preg_replace('/\s*,\s*/', ',', $s);
545 + $bits = preg_split('/\s+/', $s);
546 + if (count($bits) > 1) {
547 + $k = 'FONT-FAMILY';
548 + $v = $bits[(count($bits) - 1)];
549 + $fs = $bits[(count($bits) - 2)];
550 + if (preg_match('/(.*?)\/(.*)/', $fs, $fsp)) {
551 + $newprop['FONT-SIZE'] = $fsp[1];
552 + $newprop['LINE-HEIGHT'] = $fsp[2];
553 + } else {
554 + $newprop['FONT-SIZE'] = $fs;
555 + }
556 + if (preg_match('/(italic|oblique)/i', $s)) {
557 + $newprop['FONT-STYLE'] = 'italic';
558 + } else {
559 + $newprop['FONT-STYLE'] = 'normal';
560 + }
561 + if (preg_match('/bold/i', $s)) {
562 + $newprop['FONT-WEIGHT'] = 'bold';
563 + } else {
564 + $newprop['FONT-WEIGHT'] = 'normal';
565 + }
566 + if (preg_match('/small-caps/i', $s)) {
567 + $newprop['TEXT-TRANSFORM'] = 'uppercase';
568 + }
569 + }
570 + } else if ($k == 'FONT-FAMILY') {
571 + $aux_fontlist = explode(",", $v);
572 + $found = 0;
573 + foreach ($aux_fontlist AS $f) {
574 + $fonttype = trim($f);
575 + $fonttype = preg_replace('/["\']*(.*?)["\']*/', '\\1', $fonttype);
576 + $fonttype = preg_replace('/ /', '', $fonttype);
577 + $v = strtolower(trim($fonttype));
578 + if (isset($this->mpdf->fonttrans[$v]) && $this->mpdf->fonttrans[$v]) {
579 + $v = $this->mpdf->fonttrans[$v];
580 + }
581 + if ((!$this->mpdf->onlyCoreFonts && in_array($v, $this->mpdf->available_unifonts)) ||
582 + in_array($v, array('ccourier', 'ctimes', 'chelvetica')) ||
583 + ($this->mpdf->onlyCoreFonts && in_array($v, array('courier', 'times', 'helvetica', 'arial'))) ||
584 + in_array($v, array('sjis', 'uhc', 'big5', 'gb'))) {
585 + $newprop[$k] = $v;
586 + $found = 1;
587 + break;
588 + }
589 + }
590 + if (!$found) {
591 + foreach ($aux_fontlist AS $f) {
592 + $fonttype = trim($f);
593 + $fonttype = preg_replace('/["\']*(.*?)["\']*/', '\\1', $fonttype);
594 + $fonttype = preg_replace('/ /', '', $fonttype);
595 + $v = strtolower(trim($fonttype));
596 + if (isset($this->mpdf->fonttrans[$v]) && $this->mpdf->fonttrans[$v]) {
597 + $v = $this->mpdf->fonttrans[$v];
598 + }
599 + if (in_array($v, $this->mpdf->sans_fonts) || in_array($v, $this->mpdf->serif_fonts) || in_array($v, $this->mpdf->mono_fonts)) {
600 + $newprop[$k] = $v;
601 + break;
602 + }
603 + }
604 + }
605 + }
606 + // mPDF 5.7.1
607 + else if ($k == 'FONT-VARIANT') {
608 + if (preg_match('/(normal|none)/', $v, $m)) { // mPDF 6
609 + $newprop['FONT-VARIANT-LIGATURES'] = $m[1];
610 + $newprop['FONT-VARIANT-CAPS'] = $m[1];
611 + $newprop['FONT-VARIANT-NUMERIC'] = $m[1];
612 + $newprop['FONT-VARIANT-ALTERNATES'] = $m[1];
613 + } else {
614 + 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)) {
615 + $newprop['FONT-VARIANT-LIGATURES'] = implode(' ', $m[1]);
616 + }
617 + if (preg_match('/(all-small-caps|\bsmall-caps|all-petite-caps|\bpetite-caps|unicase|titling-caps)/i', $v, $m)) {
618 + $newprop['FONT-VARIANT-CAPS'] = $m[1];
619 + }
620 + if (preg_match_all('/(lining-nums|oldstyle-nums|proportional-nums|tabular-nums|diagonal-fractions|stacked-fractions)/i', $v, $m)) {
621 + $newprop['FONT-VARIANT-NUMERIC'] = implode(' ', $m[1]);
622 + }
623 + if (preg_match('/(historical-forms)/i', $v, $m)) {
624 + $newprop['FONT-VARIANT-ALTERNATES'] = $m[1];
625 + }
626 + }
627 + } else if ($k == 'MARGIN') {
628 + $tmp = $this->expand24($v);
629 + $newprop['MARGIN-TOP'] = $tmp['T'];
630 + $newprop['MARGIN-RIGHT'] = $tmp['R'];
631 + $newprop['MARGIN-BOTTOM'] = $tmp['B'];
632 + $newprop['MARGIN-LEFT'] = $tmp['L'];
633 + }
634 + /* -- 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') {
635 + $tmp = $this->border_radius_expand($v, $k);
636 + if (isset($tmp['TL-H']))
637 + $newprop['BORDER-TOP-LEFT-RADIUS-H'] = $tmp['TL-H'];
638 + if (isset($tmp['TL-V']))
639 + $newprop['BORDER-TOP-LEFT-RADIUS-V'] = $tmp['TL-V'];
640 + if (isset($tmp['TR-H']))
641 + $newprop['BORDER-TOP-RIGHT-RADIUS-H'] = $tmp['TR-H'];
642 + if (isset($tmp['TR-V']))
643 + $newprop['BORDER-TOP-RIGHT-RADIUS-V'] = $tmp['TR-V'];
644 + if (isset($tmp['BL-H']))
645 + $newprop['BORDER-BOTTOM-LEFT-RADIUS-H'] = $tmp['BL-H'];
646 + if (isset($tmp['BL-V']))
647 + $newprop['BORDER-BOTTOM-LEFT-RADIUS-V'] = $tmp['BL-V'];
648 + if (isset($tmp['BR-H']))
649 + $newprop['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $tmp['BR-H'];
650 + if (isset($tmp['BR-V']))
651 + $newprop['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $tmp['BR-V'];
652 + }
653 + /* -- END BORDER-RADIUS -- */
654 + else if ($k == 'PADDING') {
655 + $tmp = $this->expand24($v);
656 + $newprop['PADDING-TOP'] = $tmp['T'];
657 + $newprop['PADDING-RIGHT'] = $tmp['R'];
658 + $newprop['PADDING-BOTTOM'] = $tmp['B'];
659 + $newprop['PADDING-LEFT'] = $tmp['L'];
660 + } else if ($k == 'BORDER') {
661 + if ($v == '1') {
662 + $v = '1px solid #000000';
663 + } else {
664 + $v = $this->_fix_borderStr($v);
665 + }
666 + $newprop['BORDER-TOP'] = $v;
667 + $newprop['BORDER-RIGHT'] = $v;
668 + $newprop['BORDER-BOTTOM'] = $v;
669 + $newprop['BORDER-LEFT'] = $v;
670 + } else if ($k == 'BORDER-TOP') {
671 + $newprop['BORDER-TOP'] = $this->_fix_borderStr($v);
672 + } else if ($k == 'BORDER-RIGHT') {
673 + $newprop['BORDER-RIGHT'] = $this->_fix_borderStr($v);
674 + } else if ($k == 'BORDER-BOTTOM') {
675 + $newprop['BORDER-BOTTOM'] = $this->_fix_borderStr($v);
676 + } else if ($k == 'BORDER-LEFT') {
677 + $newprop['BORDER-LEFT'] = $this->_fix_borderStr($v);
678 + } else if ($k == 'BORDER-STYLE') {
679 + $e = $this->expand24($v);
680 + if (!empty($e)) {
681 + $newprop['BORDER-TOP-STYLE'] = $e['T'];
682 + $newprop['BORDER-RIGHT-STYLE'] = $e['R'];
683 + $newprop['BORDER-BOTTOM-STYLE'] = $e['B'];
684 + $newprop['BORDER-LEFT-STYLE'] = $e['L'];
685 + }
686 + } else if ($k == 'BORDER-WIDTH') {
687 + $e = $this->expand24($v);
688 + if (!empty($e)) {
689 + $newprop['BORDER-TOP-WIDTH'] = $e['T'];
690 + $newprop['BORDER-RIGHT-WIDTH'] = $e['R'];
691 + $newprop['BORDER-BOTTOM-WIDTH'] = $e['B'];
692 + $newprop['BORDER-LEFT-WIDTH'] = $e['L'];
693 + }
694 + } else if ($k == 'BORDER-COLOR') {
695 + $e = $this->expand24($v);
696 + if (!empty($e)) {
697 + $newprop['BORDER-TOP-COLOR'] = $e['T'];
698 + $newprop['BORDER-RIGHT-COLOR'] = $e['R'];
699 + $newprop['BORDER-BOTTOM-COLOR'] = $e['B'];
700 + $newprop['BORDER-LEFT-COLOR'] = $e['L'];
701 + }
702 + } else if ($k == 'BORDER-SPACING') {
703 + $prop = preg_split('/\s+/', trim($v));
704 + if (count($prop) == 1) {
705 + $newprop['BORDER-SPACING-H'] = $prop[0];
706 + $newprop['BORDER-SPACING-V'] = $prop[0];
707 + } else if (count($prop) == 2) {
708 + $newprop['BORDER-SPACING-H'] = $prop[0];
709 + $newprop['BORDER-SPACING-V'] = $prop[1];
710 + }
711 + } else if ($k == 'TEXT-OUTLINE') { // mPDF 5.6.07
712 + $prop = preg_split('/\s+/', trim($v));
713 + if (trim(strtolower($v)) == 'none') {
714 + $newprop['TEXT-OUTLINE'] = 'none';
715 + } else if (count($prop) == 2) {
716 + $newprop['TEXT-OUTLINE-WIDTH'] = $prop[0];
717 + $newprop['TEXT-OUTLINE-COLOR'] = $prop[1];
718 + } else if (count($prop) == 3) {
719 + $newprop['TEXT-OUTLINE-WIDTH'] = $prop[0];
720 + $newprop['TEXT-OUTLINE-COLOR'] = $prop[2];
721 + }
722 + } else if ($k == 'SIZE') {
723 + $prop = preg_split('/\s+/', trim($v));
724 + if (preg_match('/(auto|portrait|landscape)/', $prop[0])) {
725 + $newprop['SIZE'] = strtoupper($prop[0]);
726 + } else if (count($prop) == 1) {
727 + $newprop['SIZE']['W'] = $this->mpdf->ConvertSize($prop[0]);
728 + $newprop['SIZE']['H'] = $this->mpdf->ConvertSize($prop[0]);
729 + } else if (count($prop) == 2) {
730 + $newprop['SIZE']['W'] = $this->mpdf->ConvertSize($prop[0]);
731 + $newprop['SIZE']['H'] = $this->mpdf->ConvertSize($prop[1]);
732 + }
733 + } else if ($k == 'SHEET-SIZE') {
734 + $prop = preg_split('/\s+/', trim($v));
735 + if (count($prop) == 2) {
736 + $newprop['SHEET-SIZE'] = array($this->mpdf->ConvertSize($prop[0]), $this->mpdf->ConvertSize($prop[1]));
737 + } else {
738 + if (preg_match('/([0-9a-zA-Z]*)-L/i', $v, $m)) { // e.g. A4-L = A$ landscape
739 + $ft = $this->mpdf->_getPageFormat($m[1]);
740 + $format = array($ft[1], $ft[0]);
741 + } else {
742 + $format = $this->mpdf->_getPageFormat($v);
743 + }
744 + if ($format) {
745 + $newprop['SHEET-SIZE'] = array($format[0] / _MPDFK, $format[1] / _MPDFK);
746 + }
747 + }
748 + } else if ($k == 'BACKGROUND') {
749 + $bg = $this->parseCSSbackground($v);
750 + if ($bg['c']) {
751 + $newprop['BACKGROUND-COLOR'] = $bg['c'];
752 + } else {
753 + $newprop['BACKGROUND-COLOR'] = 'transparent';
754 + }
755 + /* -- BACKGROUNDS -- */
756 + if ($bg['i']) {
757 + $newprop['BACKGROUND-IMAGE'] = $bg['i'];
758 + if ($bg['r']) {
759 + $newprop['BACKGROUND-REPEAT'] = $bg['r'];
760 + }
761 + if ($bg['p']) {
762 + $newprop['BACKGROUND-POSITION'] = $bg['p'];
763 + }
764 + } else {
765 + $newprop['BACKGROUND-IMAGE'] = '';
766 + }
767 + /* -- END BACKGROUNDS -- */
768 + }
769 + /* -- BACKGROUNDS -- */ else if ($k == 'BACKGROUND-IMAGE') {
770 + if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i', $v, $m)) {
771 + $newprop['BACKGROUND-IMAGE'] = $m[0];
772 + continue;
773 + }
774 + if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i', $v, $m)) {
775 + $newprop['BACKGROUND-IMAGE'] = $m[1];
776 + } else if (strtolower($v) == 'none') {
777 + $newprop['BACKGROUND-IMAGE'] = '';
778 + }
779 + } else if ($k == 'BACKGROUND-REPEAT') {
780 + if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/i', $v, $m)) {
781 + $newprop['BACKGROUND-REPEAT'] = strtolower($m[1]);
782 + }
783 + } else if ($k == 'BACKGROUND-POSITION') {
784 + $s = $v;
785 + $bits = preg_split('/\s+/', trim($s));
786 + // These should be Position x1 or x2
787 + if (count($bits) == 1) {
788 + if (preg_match('/bottom/', $bits[0])) {
789 + $bg['p'] = '50% 100%';
790 + } else if (preg_match('/top/', $bits[0])) {
791 + $bg['p'] = '50% 0%';
792 + } else {
793 + $bg['p'] = $bits[0] . ' 50%';
794 + }
795 + } else if (count($bits) == 2) {
796 + // Can be either right center or center right
797 + if (preg_match('/(top|bottom)/', $bits[0]) || preg_match('/(left|right)/', $bits[1])) {
798 + $bg['p'] = $bits[1] . ' ' . $bits[0];
799 + } else {
800 + $bg['p'] = $bits[0] . ' ' . $bits[1];
801 + }
802 + }
803 + if ($bg['p']) {
804 + $bg['p'] = preg_replace('/(left|top)/', '0%', $bg['p']);
805 + $bg['p'] = preg_replace('/(right|bottom)/', '100%', $bg['p']);
806 + $bg['p'] = preg_replace('/(center)/', '50%', $bg['p']);
807 + 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'])) {
808 + $bg['p'] = false;
809 + }
810 + }
811 + if ($bg['p']) {
812 + $newprop['BACKGROUND-POSITION'] = $bg['p'];
813 + }
814 + }
815 + /* -- END BACKGROUNDS -- */ else if ($k == 'IMAGE-ORIENTATION') {
816 + if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i', $v, $m)) {
817 + $angle = $m[1] + 0;
818 + if (strtolower($m[2]) == 'deg') {
819 + $angle = $angle;
820 + } else if (strtolower($m[2]) == 'grad') {
821 + $angle *= (360 / 400);
822 + } else if (strtolower($m[2]) == 'rad') {
823 + $angle = rad2deg($angle);
824 + }
825 + while ($angle < 0) {
826 + $angle += 360;
827 + }
828 + $angle = ($angle % 360);
829 + $angle /= 90;
830 + $angle = round($angle) * 90;
831 + $newprop['IMAGE-ORIENTATION'] = $angle;
832 + }
833 + } else if ($k == 'TEXT-ALIGN') {
834 + if (preg_match('/["\'](.){1}["\']/i', $v, $m)) {
835 + $d = array_search($m[1], $this->mpdf->decimal_align);
836 + if ($d !== false) {
837 + $newprop['TEXT-ALIGN'] = $d;
838 + }
839 + if (preg_match('/(center|left|right)/i', $v, $m)) {
840 + $newprop['TEXT-ALIGN'] .= strtoupper(substr($m[1], 0, 1));
841 + } else {
842 + $newprop['TEXT-ALIGN'] .= 'R';
843 + } // default = R
844 + } else if (preg_match('/["\'](\\\[a-fA-F0-9]{1,6})["\']/i', $v, $m)) {
845 + $utf8 = codeHex2utf(substr($m[1], 1, 6));
846 + $d = array_search($utf8, $this->mpdf->decimal_align);
847 + if ($d !== false) {
848 + $newprop['TEXT-ALIGN'] = $d;
849 + }
850 + if (preg_match('/(center|left|right)/i', $v, $m)) {
851 + $newprop['TEXT-ALIGN'] .= strtoupper(substr($m[1], 0, 1));
852 + } else {
853 + $newprop['TEXT-ALIGN'] .= 'R';
854 + } // default = R
855 + } else {
856 + $newprop[$k] = $v;
857 + }
858 + }
859 + // mpDF 6 Lists
860 + else if ($k == 'LIST-STYLE') {
861 + if (preg_match('/none/i', $v, $m)) {
862 + $newprop['LIST-STYLE-TYPE'] = 'none';
863 + $newprop['LIST-STYLE-IMAGE'] = 'none';
864 + }
865 + 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)) {
866 + $newprop['LIST-STYLE-TYPE'] = strtolower(trim($m[1]));
867 + } else if (preg_match('/U\+([a-fA-F0-9]+)/i', $v, $m)) {
868 + $newprop['LIST-STYLE-TYPE'] = strtolower(trim($m[1]));
869 + }
870 + if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i', $v, $m)) {
871 + $newprop['LIST-STYLE-IMAGE'] = strtolower(trim($m[1]));
872 + }
873 + if (preg_match('/(inside|outside)/i', $v, $m)) {
874 + $newprop['LIST-STYLE-POSITION'] = strtolower(trim($m[1]));
875 + }
876 + } else {
877 + $newprop[$k] = $v;
878 + }
879 + }
880 +
881 + return $newprop;
882 + }
883 +
884 + function setCSSboxshadow($v)
885 + {
886 + $sh = array();
887 + $c = preg_match_all('/(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl)\(.*?\)/', $v, $x); // mPDF 5.6.05
888 + for ($i = 0; $i < $c; $i++) {
889 + $col = preg_replace('/,/', '*', $x[0][$i]);
890 + $v = preg_replace('/' . preg_quote($x[0][$i], '/') . '/', $col, $v);
891 + }
892 + $ss = explode(',', $v);
893 + foreach ($ss AS $s) {
894 + $new = array('inset' => false, 'blur' => 0, 'spread' => 0);
895 + if (preg_match('/inset/i', $s)) {
896 + $new['inset'] = true;
897 + $s = preg_replace('/\s*inset\s*/', '', $s);
898 + }
899 + $p = explode(' ', trim($s));
900 + if (isset($p[0])) {
901 + $new['x'] = $this->mpdf->ConvertSize(trim($p[0]), $this->mpdf->blk[$this->mpdf->blklvl - 1]['inner_width'], $this->mpdf->FontSize, false);
902 + }
903 + if (isset($p[1])) {
904 + $new['y'] = $this->mpdf->ConvertSize(trim($p[1]), $this->mpdf->blk[$this->mpdf->blklvl - 1]['inner_width'], $this->mpdf->FontSize, false);
905 + }
906 + if (isset($p[2])) {
907 + if (preg_match('/^\s*[\.\-0-9]/', $p[2])) {
908 + $new['blur'] = $this->mpdf->ConvertSize(trim($p[2]), $this->mpdf->blk[$this->mpdf->blklvl - 1]['inner_width'], $this->mpdf->FontSize, false);
909 + } else {
910 + $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/', ',', $p[2]));
911 + }
912 + if (isset($p[3])) {
913 + if (preg_match('/^\s*[\.\-0-9]/', $p[3])) {
914 + $new['spread'] = $this->mpdf->ConvertSize(trim($p[3]), $this->mpdf->blk[$this->mpdf->blklvl - 1]['inner_width'], $this->mpdf->FontSize, false);
915 + } else {
916 + $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/', ',', $p[3]));
917 + }
918 + if (isset($p[4])) {
919 + $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/', ',', $p[4]));
920 + }
921 + }
922 + }
923 + if (!$new['col']) {
924 + $new['col'] = $this->mpdf->ConvertColor('#888888');
925 + }
926 + if (isset($new['y'])) {
927 + array_unshift($sh, $new);
928 + }
929 + }
930 + return $sh;
931 + }
932 +
933 + function setCSStextshadow($v)
934 + {
935 + $sh = array();
936 + $c = preg_match_all('/(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl)\(.*?\)/', $v, $x); // mPDF 5.6.05
937 + for ($i = 0; $i < $c; $i++) {
938 + $col = preg_replace('/,/', '*', $x[0][$i]);
939 + $v = preg_replace('/' . preg_quote($x[0][$i], '/') . '/', $col, $v);
940 + }
941 + $ss = explode(',', $v);
942 + foreach ($ss AS $s) {
943 + $new = array('blur' => 0);
944 + $p = explode(' ', trim($s));
945 + if (isset($p[0])) {
946 + $new['x'] = $this->mpdf->ConvertSize(trim($p[0]), $this->mpdf->FontSize, $this->mpdf->FontSize, false);
947 + }
948 + if (isset($p[1])) {
949 + $new['y'] = $this->mpdf->ConvertSize(trim($p[1]), $this->mpdf->FontSize, $this->mpdf->FontSize, false);
950 + }
951 + if (isset($p[2])) {
952 + if (preg_match('/^\s*[\.\-0-9]/', $p[2])) {
953 + $new['blur'] = $this->mpdf->ConvertSize(trim($p[2]), $this->mpdf->blk[$this->mpdf->blklvl]['inner_width'], $this->mpdf->FontSize, false);
954 + } else {
955 + $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/', ',', $p[2]));
956 + }
957 + if (isset($p[3])) {
958 + $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/', ',', $p[3]));
959 + }
960 + }
961 + if (!isset($new['col']) || !$new['col']) {
962 + $new['col'] = $this->mpdf->ConvertColor('#888888');
963 + }
964 + if (isset($new['y'])) {
965 + array_unshift($sh, $new);
966 + }
967 + }
968 + return $sh;
969 + }
970 +
971 + function parseCSSbackground($s)
972 + {
973 + $bg = array('c' => false, 'i' => false, 'r' => false, 'p' => false,);
974 + /* -- BACKGROUNDS -- */
975 + if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i', $s, $m)) {
976 + $bg['i'] = $m[0];
977 + } else
978 + /* -- END BACKGROUNDS -- */
979 + if (preg_match('/url\(/i', $s)) {
980 + // If color, set and strip it off
981 + // mPDF 5.6.05
982 + 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)) {
983 + $bg['c'] = strtolower($m[1]);
984 + $s = $m[3];
985 + }
986 + /* -- BACKGROUNDS -- */
987 + if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)\s*(.*)/i', $s, $m)) {
988 + $bg['i'] = $m[1];
989 + $s = strtolower($m[2]);
990 + if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/', $s, $m)) {
991 + $bg['r'] = $m[1];
992 + }
993 + // Remove repeat, attachment (discarded) and also any inherit
994 + $s = preg_replace('/(repeat-x|repeat-y|no-repeat|repeat|scroll|fixed|inherit)/', '', $s);
995 + $bits = preg_split('/\s+/', trim($s));
996 + // These should be Position x1 or x2
997 + if (count($bits) == 1) {
998 + if (preg_match('/bottom/', $bits[0])) {
999 + $bg['p'] = '50% 100%';
1000 + } else if (preg_match('/top/', $bits[0])) {
1001 + $bg['p'] = '50% 0%';
1002 + } else {
1003 + $bg['p'] = $bits[0] . ' 50%';
1004 + }
1005 + } else if (count($bits) == 2) {
1006 + // Can be either right center or center right
1007 + if (preg_match('/(top|bottom)/', $bits[0]) || preg_match('/(left|right)/', $bits[1])) {
1008 + $bg['p'] = $bits[1] . ' ' . $bits[0];
1009 + } else {
1010 + $bg['p'] = $bits[0] . ' ' . $bits[1];
1011 + }
1012 + }
1013 + if ($bg['p']) {
1014 + $bg['p'] = preg_replace('/(left|top)/', '0%', $bg['p']);
1015 + $bg['p'] = preg_replace('/(right|bottom)/', '100%', $bg['p']);
1016 + $bg['p'] = preg_replace('/(center)/', '50%', $bg['p']);
1017 + 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'])) {
1018 + $bg['p'] = false;
1019 + }
1020 + }
1021 + }
1022 + /* -- END BACKGROUNDS -- */
1023 + } 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)) {
1024 + $bg['c'] = strtolower($m[1]);
1025 + } // mPDF 5.6.05
1026 + return ($bg);
1027 + }
1028 +
1029 + function expand24($mp)
1030 + {
1031 + $prop = preg_split('/\s+/', trim($mp));
1032 + if (count($prop) == 1) {
1033 + return array('T' => $prop[0], 'R' => $prop[0], 'B' => $prop[0], 'L' => $prop[0]);
1034 + }
1035 + if (count($prop) == 2) {
1036 + return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[0], 'L' => $prop[1]);
1037 + }
1038 +
1039 + if (count($prop) == 3) {
1040 + return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L' => $prop[1]);
1041 + }
1042 + if (count($prop) == 4) {
1043 + return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L' => $prop[3]);
1044 + }
1045 + return array();
1046 + }
1047 +
1048 + /* -- BORDER-RADIUS -- */
1049 +
1050 + function border_radius_expand($val, $k)
1051 + {
1052 + $b = array();
1053 + if ($k == 'BORDER-RADIUS') {
1054 + $hv = explode('/', trim($val));
1055 + $prop = preg_split('/\s+/', trim($hv[0]));
1056 + if (count($prop) == 1) {
1057 + $b['TL-H'] = $b['TR-H'] = $b['BR-H'] = $b['BL-H'] = $prop[0];
1058 + } else if (count($prop) == 2) {
1059 + $b['TL-H'] = $b['BR-H'] = $prop[0];
1060 + $b['TR-H'] = $b['BL-H'] = $prop[1];
1061 + } else if (count($prop) == 3) {
1062 + $b['TL-H'] = $prop[0];
1063 + $b['TR-H'] = $b['BL-H'] = $prop[1];
1064 + $b['BR-H'] = $prop[2];
1065 + } else if (count($prop) == 4) {
1066 + $b['TL-H'] = $prop[0];
1067 + $b['TR-H'] = $prop[1];
1068 + $b['BR-H'] = $prop[2];
1069 + $b['BL-H'] = $prop[3];
1070 + }
1071 + if (count($hv) == 2) {
1072 + $prop = preg_split('/\s+/', trim($hv[1]));
1073 + if (count($prop) == 1) {
1074 + $b['TL-V'] = $b['TR-V'] = $b['BR-V'] = $b['BL-V'] = $prop[0];
1075 + } else if (count($prop) == 2) {
1076 + $b['TL-V'] = $b['BR-V'] = $prop[0];
1077 + $b['TR-V'] = $b['BL-V'] = $prop[1];
1078 + } else if (count($prop) == 3) {
1079 + $b['TL-V'] = $prop[0];
1080 + $b['TR-V'] = $b['BL-V'] = $prop[1];
1081 + $b['BR-V'] = $prop[2];
1082 + } else if (count($prop) == 4) {
1083 + $b['TL-V'] = $prop[0];
1084 + $b['TR-V'] = $prop[1];
1085 + $b['BR-V'] = $prop[2];
1086 + $b['BL-V'] = $prop[3];
1087 + }
1088 + } else {
1089 + $b['TL-V'] = $b['TL-H'];
1090 + $b['TR-V'] = $b['TR-H'];
1091 + $b['BL-V'] = $b['BL-H'];
1092 + $b['BR-V'] = $b['BR-H'];
1093 + }
1094 + return $b;
1095 + }
1096 +
1097 + // Parse 2
1098 + $h = 0;
1099 + $v = 0;
1100 + $prop = preg_split('/\s+/', trim($val));
1101 + if (count($prop) == 1) {
1102 + $h = $v = $val;
1103 + } else {
1104 + $h = $prop[0];
1105 + $v = $prop[1];
1106 + }
1107 + if ($h == 0 || $v == 0) {
1108 + $h = $v = 0;
1109 + }
1110 + if ($k == 'BORDER-TOP-LEFT-RADIUS') {
1111 + $b['TL-H'] = $h;
1112 + $b['TL-V'] = $v;
1113 + } else if ($k == 'BORDER-TOP-RIGHT-RADIUS') {
1114 + $b['TR-H'] = $h;
1115 + $b['TR-V'] = $v;
1116 + } else if ($k == 'BORDER-BOTTOM-LEFT-RADIUS') {
1117 + $b['BL-H'] = $h;
1118 + $b['BL-V'] = $v;
1119 + } else if ($k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
1120 + $b['BR-H'] = $h;
1121 + $b['BR-V'] = $v;
1122 + }
1123 + return $b;
1124 + }
1125 +
1126 + /* -- END BORDER-RADIUS -- */
1127 +
1128 + function _mergeCSS($p, &$t)
1129 + {
1130 + // Save Cascading CSS e.g. "div.topic p" at this block level
1131 + if (isset($p) && $p) {
1132 + if ($t) {
1133 + $t = $this->array_merge_recursive_unique($t, $p);
1134 + } else {
1135 + $t = $p;
1136 + }
1137 + }
1138 + }
1139 +
1140 +// for CSS handling
1141 + function array_merge_recursive_unique($array1, $array2)
1142 + {
1143 + $arrays = func_get_args();
1144 + $narrays = count($arrays);
1145 + $ret = $arrays[0];
1146 + for ($i = 1; $i < $narrays; $i ++) {
1147 + foreach ($arrays[$i] as $key => $value) {
1148 + if (((string) $key) === ((string) intval($key))) { // integer or string as integer key - append
1149 + $ret[] = $value;
1150 + } else { // string key - merge
1151 + if (is_array($value) && isset($ret[$key])) {
1152 + $ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value);
1153 + } else {
1154 + $ret[$key] = $value;
1155 + }
1156 + }
1157 + }
1158 + }
1159 + return $ret;
1160 + }
1161 +
1162 + function _mergeFullCSS($p, &$t, $tag, $classes, $id, $lang)
1163 + { // mPDF 6
1164 + if (isset($p[$tag])) {
1165 + $this->_mergeCSS($p[$tag], $t);
1166 + }
1167 + // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1168 + foreach ($classes AS $class) {
1169 + if (isset($p['CLASS>>' . $class])) {
1170 + $this->_mergeCSS($p['CLASS>>' . $class], $t);
1171 + }
1172 + }
1173 + // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
1174 + if ($tag == 'TR' && isset($p) && $p) {
1175 + foreach ($p AS $k => $val) {
1176 + if (preg_match('/' . $tag . '>>SELECTORNTHCHILD>>(.*)/', $k, $m)) {
1177 + $select = false;
1178 + if ($tag == 'TR') {
1179 + $row = $this->mpdf->row;
1180 + $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);
1181 + $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);
1182 + if ($this->mpdf->tabletfoot) {
1183 + $row -= $thnr;
1184 + } else if (!$this->mpdf->tablethead) {
1185 + $row -= ($thnr + $tfnr);
1186 + }
1187 + if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/', $m[1], $a)) { // mPDF 5.7.4
1188 + $select = $this->_nthchild($a, $row);
1189 + }
1190 + } else if ($tag == 'TD' || $tag == 'TH') {
1191 + if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/', $m[1], $a)) { // mPDF 5.7.4
1192 + $select = $this->_nthchild($a, $this->mpdf->col);
1193 + }
1194 + }
1195 + if ($select) {
1196 + $this->_mergeCSS($p[$tag . '>>SELECTORNTHCHILD>>' . $m[1]], $t);
1197 + }
1198 + }
1199 + }
1200 + }
1201 + // STYLESHEET CLASS e.g. [lang=fr]{} or :lang(fr)
1202 + if (isset($lang) && isset($p['LANG>>' . $lang])) {
1203 + $this->_mergeCSS($p['LANG>>' . $lang], $t);
1204 + }
1205 + // STYLESHEET CLASS e.g. #smallone{} #redletter{}
1206 + if (isset($id) && isset($p['ID>>' . $id])) {
1207 + $this->_mergeCSS($p['ID>>' . $id], $t);
1208 + }
1209 +
1210 + // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1211 + foreach ($classes AS $class) {
1212 + if (isset($p[$tag . '>>CLASS>>' . $class])) {
1213 + $this->_mergeCSS($p[$tag . '>>CLASS>>' . $class], $t);
1214 + }
1215 + }
1216 + // STYLESHEET CLASS e.g. [lang=fr]{} or :lang(fr)
1217 + if (isset($lang) && isset($p[$tag . '>>LANG>>' . $lang])) {
1218 + $this->_mergeCSS($p[$tag . '>>LANG>>' . $lang], $t);
1219 + }
1220 + // STYLESHEET CLASS e.g. #smallone{} #redletter{}
1221 + if (isset($id) && isset($p[$tag . '>>ID>>' . $id])) {
1222 + $this->_mergeCSS($p[$tag . '>>ID>>' . $id], $t);
1223 + }
1224 + }
1225 +
1226 + function setBorderDominance($prop, $val)
1227 + {
1228 + if (isset($prop['BORDER-LEFT']) && $prop['BORDER-LEFT']) {
1229 + $this->cell_border_dominance_L = $val;
1230 + }
1231 + if (isset($prop['BORDER-RIGHT']) && $prop['BORDER-RIGHT']) {
1232 + $this->cell_border_dominance_R = $val;
1233 + }
1234 + if (isset($prop['BORDER-TOP']) && $prop['BORDER-TOP']) {
1235 + $this->cell_border_dominance_T = $val;
1236 + }
1237 + if (isset($prop['BORDER-BOTTOM']) && $prop['BORDER-BOTTOM']) {
1238 + $this->cell_border_dominance_B = $val;
1239 + }
1240 + }
1241 +
1242 + function _set_mergedCSS(&$m, &$p, $d = true, $bd = false)
1243 + {
1244 + if (isset($m)) {
1245 + if ((isset($m['depth']) && $m['depth'] > 1) || $d == false) { // include check for 'depth'
1246 + if ($bd) {
1247 + $this->setBorderDominance($m, $bd);
1248 + } // *TABLES*
1249 + if (is_array($m)) {
1250 + $p = array_merge($p, $m);
1251 + $this->_mergeBorders($p, $m);
1252 + }
1253 + }
1254 + }
1255 + }
1256 +
1257 + function _mergeBorders(&$b, &$a)
1258 + { // Merges $a['BORDER-TOP-STYLE'] to $b['BORDER-TOP'] etc.
1259 + foreach (array('TOP', 'RIGHT', 'BOTTOM', 'LEFT') AS $side) {
1260 + foreach (array('STYLE', 'WIDTH', 'COLOR') AS $el) {
1261 + if (isset($a['BORDER-' . $side . '-' . $el])) { // e.g. $b['BORDER-TOP-STYLE']
1262 + $s = trim($a['BORDER-' . $side . '-' . $el]);
1263 + if (isset($b['BORDER-' . $side])) { // e.g. $b['BORDER-TOP']
1264 + $p = trim($b['BORDER-' . $side]);
1265 + } else {
1266 + $p = '';
1267 + }
1268 + if ($el == 'STYLE') {
1269 + if ($p) {
1270 + $b['BORDER-' . $side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 ' . $s . ' \\3', $p);
1271 + } else {
1272 + $b['BORDER-' . $side] = '0px ' . $s . ' #000000';
1273 + }
1274 + } else if ($el == 'WIDTH') {
1275 + if ($p) {
1276 + $b['BORDER-' . $side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', $s . ' \\2 \\3', $p);
1277 + } else {
1278 + $b['BORDER-' . $side] = $s . ' none #000000';
1279 + }
1280 + } else if ($el == 'COLOR') {
1281 + if ($p) {
1282 + $b['BORDER-' . $side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 \\2 ' . $s, $p);
1283 + } else {
1284 + $b['BORDER-' . $side] = '0px none ' . $s;
1285 + }
1286 + }
1287 + }
1288 + }
1289 + }
1290 + }
1291 +
1292 + function MergeCSS($inherit, $tag, $attr)
1293 + {
1294 + $p = array();
1295 + $zp = array();
1296 +
1297 + $classes = array();
1298 + $attr = $attr === '' ? [] : $attr;
1299 + if (isset($attr['CLASS'])) {
1300 + $classes = preg_split('/\s+/', $attr['CLASS']);
1301 + }
1302 + if (!isset($attr['ID'])) {
1303 + $attr['ID'] = '';
1304 + }
1305 + // mPDF 6
1306 + $shortlang = '';
1307 + if (!isset($attr['LANG'])) {
1308 + $attr['LANG'] = '';
1309 + } else {
1310 + $attr['LANG'] = strtolower($attr['LANG']);
1311 + if (strlen($attr['LANG']) == 5) {
1312 + $shortlang = substr($attr['LANG'], 0, 2);
1313 + }
1314 + }
1315 + //===============================================
1316 + /* -- TABLES -- */
1317 + // Set Inherited properties
1318 + if ($inherit == 'TOPTABLE') { // $tag = TABLE
1319 + //===============================================
1320 + // Save Cascading CSS e.g. "div.topic p" at this block level
1321 + if (isset($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'])) {
1322 + $this->tablecascadeCSS[0] = $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'];
1323 + } else {
1324 + $this->tablecascadeCSS[0] = $this->cascadeCSS;
1325 + }
1326 + }
1327 + //===============================================
1328 + // Set Inherited properties
1329 + if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') {
1330 + //Cascade everything from last level that is not an actual property, or defined by current tag/attributes
1331 + if (isset($this->tablecascadeCSS[$this->tbCSSlvl - 1]) && is_array($this->tablecascadeCSS[$this->tbCSSlvl - 1])) {
1332 + foreach ($this->tablecascadeCSS[$this->tbCSSlvl - 1] AS $k => $v) {
1333 + $this->tablecascadeCSS[$this->tbCSSlvl][$k] = $v;
1334 + }
1335 + }
1336 + $this->_mergeFullCSS($this->cascadeCSS, $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID'], $attr['LANG']);
1337 + //===============================================
1338 + // Cascading forward CSS e.g. "table.topic td" for this table in $this->tablecascadeCSS
1339 + //===============================================
1340 + // STYLESHEET TAG e.g. table
1341 + $this->_mergeFullCSS($this->tablecascadeCSS[$this->tbCSSlvl - 1], $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID'], $attr['LANG']);
1342 + //===============================================
1343 + }
1344 + /* -- END TABLES -- */
1345 + //===============================================
1346 + // Set Inherited properties
1347 + if ($inherit == 'BLOCK') {
1348 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['cascadeCSS']) && is_array($this->mpdf->blk[$this->mpdf->blklvl - 1]['cascadeCSS'])) {
1349 + foreach ($this->mpdf->blk[$this->mpdf->blklvl - 1]['cascadeCSS'] AS $k => $v) {
1350 + $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$k] = $v;
1351 + }
1352 + }
1353 +
1354 + //===============================================
1355 + // Save Cascading CSS e.g. "div.topic p" at this block level
1356 + $this->_mergeFullCSS($this->cascadeCSS, $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID'], $attr['LANG']);
1357 + //===============================================
1358 + // Cascading forward CSS
1359 + //===============================================
1360 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1])) {
1361 + $this->_mergeFullCSS($this->mpdf->blk[$this->mpdf->blklvl - 1]['cascadeCSS'], $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID'], $attr['LANG']);
1362 + }
1363 + //===============================================
1364 + // Block properties which are inherited
1365 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['margin_collapse']) && $this->mpdf->blk[$this->mpdf->blklvl - 1]['margin_collapse']) {
1366 + $p['MARGIN-COLLAPSE'] = 'COLLAPSE';
1367 + } // custom tag, but follows CSS principle that border-collapse is inherited
1368 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['line_height']) && $this->mpdf->blk[$this->mpdf->blklvl - 1]['line_height']) {
1369 + $p['LINE-HEIGHT'] = $this->mpdf->blk[$this->mpdf->blklvl - 1]['line_height'];
1370 + }
1371 + // mPDF 6
1372 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['line_stacking_strategy']) && $this->mpdf->blk[$this->mpdf->blklvl - 1]['line_stacking_strategy']) {
1373 + $p['LINE-STACKING-STRATEGY'] = $this->mpdf->blk[$this->mpdf->blklvl - 1]['line_stacking_strategy'];
1374 + }
1375 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['line_stacking_shift']) && $this->mpdf->blk[$this->mpdf->blklvl - 1]['line_stacking_shift']) {
1376 + $p['LINE-STACKING-SHIFT'] = $this->mpdf->blk[$this->mpdf->blklvl - 1]['line_stacking_shift'];
1377 + }
1378 +
1379 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['direction']) && $this->mpdf->blk[$this->mpdf->blklvl - 1]['direction']) {
1380 + $p['DIRECTION'] = $this->mpdf->blk[$this->mpdf->blklvl - 1]['direction'];
1381 + }
1382 + // mPDF 6 Lists
1383 + if ($tag == 'LI') {
1384 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['list_style_type']) && $this->mpdf->blk[$this->mpdf->blklvl - 1]['list_style_type']) {
1385 + $p['LIST-STYLE-TYPE'] = $this->mpdf->blk[$this->mpdf->blklvl - 1]['list_style_type'];
1386 + }
1387 + }
1388 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['list_style_image']) && $this->mpdf->blk[$this->mpdf->blklvl - 1]['list_style_image']) {
1389 + $p['LIST-STYLE-IMAGE'] = $this->mpdf->blk[$this->mpdf->blklvl - 1]['list_style_image'];
1390 + }
1391 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['list_style_position']) && $this->mpdf->blk[$this->mpdf->blklvl - 1]['list_style_position']) {
1392 + $p['LIST-STYLE-POSITION'] = $this->mpdf->blk[$this->mpdf->blklvl - 1]['list_style_position'];
1393 + }
1394 +
1395 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['align']) && $this->mpdf->blk[$this->mpdf->blklvl - 1]['align']) {
1396 + if ($this->mpdf->blk[$this->mpdf->blklvl - 1]['align'] == 'L') {
1397 + $p['TEXT-ALIGN'] = 'left';
1398 + } else if ($this->mpdf->blk[$this->mpdf->blklvl - 1]['align'] == 'J') {
1399 + $p['TEXT-ALIGN'] = 'justify';
1400 + } else if ($this->mpdf->blk[$this->mpdf->blklvl - 1]['align'] == 'R') {
1401 + $p['TEXT-ALIGN'] = 'right';
1402 + } else if ($this->mpdf->blk[$this->mpdf->blklvl - 1]['align'] == 'C') {
1403 + $p['TEXT-ALIGN'] = 'center';
1404 + }
1405 + }
1406 + if ($this->mpdf->ColActive || $this->mpdf->keep_block_together) {
1407 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['bgcolor']) && $this->mpdf->blk[$this->mpdf->blklvl - 1]['bgcolor']) { // Doesn't officially inherit, but default value is transparent (?=inherited)
1408 + $cor = $this->mpdf->blk[$this->mpdf->blklvl - 1]['bgcolorarray'];
1409 + $p['BACKGROUND-COLOR'] = $this->mpdf->_colAtoString($cor);
1410 + }
1411 + }
1412 +
1413 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['text_indent']) && ($this->mpdf->blk[$this->mpdf->blklvl - 1]['text_indent'] || $this->mpdf->blk[$this->mpdf->blklvl - 1]['text_indent'] === 0)) {
1414 + $p['TEXT-INDENT'] = $this->mpdf->blk[$this->mpdf->blklvl - 1]['text_indent'];
1415 + }
1416 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1]['InlineProperties'])) {
1417 + $biilp = $this->mpdf->blk[$this->mpdf->blklvl - 1]['InlineProperties'];
1418 + $this->inlinePropsToCSS($biilp, $p); // mPDF 5.7.1
1419 + } else {
1420 + $biilp = null;
1421 + }
1422 + }
1423 + //===============================================
1424 + //===============================================
1425 + // INLINE HTML ATTRIBUTES e.g. .. ALIGN="CENTER">
1426 + // mPDF 6 (added)
1427 + if (isset($attr['DIR']) and $attr['DIR'] != '') {
1428 + $p['DIRECTION'] = $attr['DIR'];
1429 + }
1430 + // mPDF 6 (moved)
1431 + if (isset($attr['LANG']) and $attr['LANG'] != '') {
1432 + $p['LANG'] = $attr['LANG'];
1433 + }
1434 + if (isset($attr['COLOR']) and $attr['COLOR'] != '') {
1435 + $p['COLOR'] = $attr['COLOR'];
1436 + }
1437 +
1438 + if ($tag != 'INPUT') {
1439 + if (isset($attr['WIDTH']) and $attr['WIDTH'] != '') {
1440 + $p['WIDTH'] = $attr['WIDTH'];
1441 + }
1442 + if (isset($attr['HEIGHT']) and $attr['HEIGHT'] != '') {
1443 + $p['HEIGHT'] = $attr['HEIGHT'];
1444 + }
1445 + }
1446 + if ($tag == 'FONT') {
1447 + if (isset($attr['FACE'])) {
1448 + $p['FONT-FAMILY'] = $attr['FACE'];
1449 + }
1450 + if (isset($attr['SIZE']) and $attr['SIZE'] != '') {
1451 + $s = '';
1452 + if ($attr['SIZE'] === '+1') {
1453 + $s = '120%';
1454 + } else if ($attr['SIZE'] === '-1') {
1455 + $s = '86%';
1456 + } else if ($attr['SIZE'] === '1') {
1457 + $s = 'XX-SMALL';
1458 + } else if ($attr['SIZE'] == '2') {
1459 + $s = 'X-SMALL';
1460 + } else if ($attr['SIZE'] == '3') {
1461 + $s = 'SMALL';
1462 + } else if ($attr['SIZE'] == '4') {
1463 + $s = 'MEDIUM';
1464 + } else if ($attr['SIZE'] == '5') {
1465 + $s = 'LARGE';
1466 + } else if ($attr['SIZE'] == '6') {
1467 + $s = 'X-LARGE';
1468 + } else if ($attr['SIZE'] == '7') {
1469 + $s = 'XX-LARGE';
1470 + }
1471 + if ($s)
1472 + $p['FONT-SIZE'] = $s;
1473 + }
1474 + }
1475 + if (isset($attr['VALIGN']) and $attr['VALIGN'] != '') {
1476 + $p['VERTICAL-ALIGN'] = $attr['VALIGN'];
1477 + }
1478 + if (isset($attr['VSPACE']) and $attr['VSPACE'] != '') {
1479 + $p['MARGIN-TOP'] = $attr['VSPACE'];
1480 + $p['MARGIN-BOTTOM'] = $attr['VSPACE'];
1481 + }
1482 + if (isset($attr['HSPACE']) and $attr['HSPACE'] != '') {
1483 + $p['MARGIN-LEFT'] = $attr['HSPACE'];
1484 + $p['MARGIN-RIGHT'] = $attr['HSPACE'];
1485 + }
1486 + //===============================================
1487 + //===============================================
1488 + // DEFAULT for this TAG set in DefaultCSS
1489 + if (isset($this->mpdf->defaultCSS[$tag])) {
1490 + $zp = $this->fixCSS($this->mpdf->defaultCSS[$tag]);
1491 + if (is_array($zp)) { // Default overwrites Inherited
1492 + $p = array_merge($p, $zp); // !! Note other way round !!
1493 + $this->_mergeBorders($p, $zp);
1494 + }
1495 + }
1496 + //===============================================
1497 + /* -- TABLES -- */
1498 + // mPDF 5.7.3
1499 + // cellSpacing overwrites TABLE default but not specific CSS set on table
1500 + if ($tag == 'TABLE' && isset($attr['CELLSPACING'])) {
1501 + $p['BORDER-SPACING-H'] = $p['BORDER-SPACING-V'] = $attr['CELLSPACING'];
1502 + }
1503 + // cellPadding overwrites TD/TH default but not specific CSS set on cell
1504 + if (($tag == 'TD' || $tag == 'TH') && isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding']) && ($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'] || $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'] === '0')) { // mPDF 5.7.3
1505 + $p['PADDING-LEFT'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1506 + $p['PADDING-RIGHT'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1507 + $p['PADDING-TOP'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1508 + $p['PADDING-BOTTOM'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1509 + }
1510 + /* -- END TABLES -- */
1511 + //===============================================
1512 + // STYLESHEET TAG e.g. h1 p div table
1513 + if (isset($this->CSS[$tag]) && $this->CSS[$tag]) {
1514 + $zp = $this->CSS[$tag];
1515 + if ($tag == 'TD' || $tag == 'TH') {
1516 + $this->setBorderDominance($zp, 9);
1517 + } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1518 + if (is_array($zp)) {
1519 + $p = array_merge($p, $zp);
1520 + $this->_mergeBorders($p, $zp);
1521 + }
1522 + }
1523 + //===============================================
1524 + // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1525 + foreach ($classes AS $class) {
1526 + $zp = array();
1527 + if (isset($this->CSS['CLASS>>' . $class]) && $this->CSS['CLASS>>' . $class]) {
1528 + $zp = $this->CSS['CLASS>>' . $class];
1529 + }
1530 + if ($tag == 'TD' || $tag == 'TH') {
1531 + $this->setBorderDominance($zp, 9);
1532 + } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1533 + if (is_array($zp)) {
1534 + $p = array_merge($p, $zp);
1535 + $this->_mergeBorders($p, $zp);
1536 + }
1537 + }
1538 + //===============================================
1539 + /* -- TABLES -- */
1540 + // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
1541 + if ($tag == 'TR' || $tag == 'TD' || $tag == 'TH') {
1542 + foreach ($this->CSS AS $k => $val) {
1543 + if (preg_match('/' . $tag . '>>SELECTORNTHCHILD>>(.*)/', $k, $m)) {
1544 + $select = false;
1545 + if ($tag == 'TR') {
1546 + $row = $this->mpdf->row;
1547 + $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);
1548 + $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);
1549 + if ($this->mpdf->tabletfoot) {
1550 + $row -= $thnr;
1551 + } else if (!$this->mpdf->tablethead) {
1552 + $row -= ($thnr + $tfnr);
1553 + }
1554 + if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/', $m[1], $a)) { // mPDF 5.7.4
1555 + $select = $this->_nthchild($a, $row);
1556 + }
1557 + } else if ($tag == 'TD' || $tag == 'TH') {
1558 + if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/', $m[1], $a)) { // mPDF 5.7.4
1559 + $select = $this->_nthchild($a, $this->mpdf->col);
1560 + }
1561 + }
1562 + if ($select) {
1563 + $zp = $this->CSS[$tag . '>>SELECTORNTHCHILD>>' . $m[1]];
1564 + if ($tag == 'TD' || $tag == 'TH') {
1565 + $this->setBorderDominance($zp, 9);
1566 + }
1567 + if (is_array($zp)) {
1568 + $p = array_merge($p, $zp);
1569 + $this->_mergeBorders($p, $zp);
1570 + }
1571 + }
1572 + }
1573 + }
1574 + }
1575 + /* -- END TABLES -- */
1576 + //===============================================
1577 + // STYLESHEET LANG e.g. [lang=fr]{} or :lang(fr)
1578 + if (isset($attr['LANG'])) {
1579 + if (isset($this->CSS['LANG>>' . $attr['LANG']]) && $this->CSS['LANG>>' . $attr['LANG']]) {
1580 + $zp = $this->CSS['LANG>>' . $attr['LANG']];
1581 + if ($tag == 'TD' || $tag == 'TH') {
1582 + $this->setBorderDominance($zp, 9);
1583 + } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1584 + if (is_array($zp)) {
1585 + $p = array_merge($p, $zp);
1586 + $this->_mergeBorders($p, $zp);
1587 + }
1588 + } else if (isset($this->CSS['LANG>>' . $shortlang]) && $this->CSS['LANG>>' . $shortlang]) {
1589 + $zp = $this->CSS['LANG>>' . $shortlang];
1590 + if ($tag == 'TD' || $tag == 'TH') {
1591 + $this->setBorderDominance($zp, 9);
1592 + } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1593 + if (is_array($zp)) {
1594 + $p = array_merge($p, $zp);
1595 + $this->_mergeBorders($p, $zp);
1596 + }
1597 + }
1598 + }
1599 + //===============================================
1600 + // STYLESHEET ID e.g. #smallone{} #redletter{}
1601 + if (isset($attr['ID']) && isset($this->CSS['ID>>' . $attr['ID']]) && $this->CSS['ID>>' . $attr['ID']]) {
1602 + $zp = $this->CSS['ID>>' . $attr['ID']];
1603 + if ($tag == 'TD' || $tag == 'TH') {
1604 + $this->setBorderDominance($zp, 9);
1605 + } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1606 + if (is_array($zp)) {
1607 + $p = array_merge($p, $zp);
1608 + $this->_mergeBorders($p, $zp);
1609 + }
1610 + }
1611 +
1612 + //===============================================
1613 + // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
1614 + foreach ($classes AS $class) {
1615 + $zp = array();
1616 + if (isset($this->CSS[$tag . '>>CLASS>>' . $class]) && $this->CSS[$tag . '>>CLASS>>' . $class]) {
1617 + $zp = $this->CSS[$tag . '>>CLASS>>' . $class];
1618 + }
1619 + if ($tag == 'TD' || $tag == 'TH') {
1620 + $this->setBorderDominance($zp, 9);
1621 + } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1622 + if (is_array($zp)) {
1623 + $p = array_merge($p, $zp);
1624 + $this->_mergeBorders($p, $zp);
1625 + }
1626 + }
1627 + //===============================================
1628 + // STYLESHEET LANG e.g. [lang=fr]{} or :lang(fr)
1629 + if (isset($attr['LANG'])) {
1630 + if (isset($this->CSS[$tag . '>>LANG>>' . $attr['LANG']]) && $this->CSS[$tag . '>>LANG>>' . $attr['LANG']]) {
1631 + $zp = $this->CSS[$tag . '>>LANG>>' . $attr['LANG']];
1632 + if ($tag == 'TD' || $tag == 'TH') {
1633 + $this->setBorderDominance($zp, 9);
1634 + } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1635 + if (is_array($zp)) {
1636 + $p = array_merge($p, $zp);
1637 + $this->_mergeBorders($p, $zp);
1638 + }
1639 + } else if (isset($this->CSS[$tag . '>>LANG>>' . $shortlang]) && $this->CSS[$tag . '>>LANG>>' . $shortlang]) {
1640 + $zp = $this->CSS[$tag . '>>LANG>>' . $shortlang];
1641 + if ($tag == 'TD' || $tag == 'TH') {
1642 + $this->setBorderDominance($zp, 9);
1643 + } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1644 + if (is_array($zp)) {
1645 + $p = array_merge($p, $zp);
1646 + $this->_mergeBorders($p, $zp);
1647 + }
1648 + }
1649 + }
1650 + //===============================================
1651 + // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
1652 + if (isset($attr['ID']) && isset($this->CSS[$tag . '>>ID>>' . $attr['ID']]) && $this->CSS[$tag . '>>ID>>' . $attr['ID']]) {
1653 + $zp = $this->CSS[$tag . '>>ID>>' . $attr['ID']];
1654 + if ($tag == 'TD' || $tag == 'TH') {
1655 + $this->setBorderDominance($zp, 9);
1656 + } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1657 + if (is_array($zp)) {
1658 + $p = array_merge($p, $zp);
1659 + $this->_mergeBorders($p, $zp);
1660 + }
1661 + }
1662 + //===============================================
1663 + // Cascaded e.g. div.class p only works for block level
1664 + if ($inherit == 'BLOCK') {
1665 + if (isset($this->mpdf->blk[$this->mpdf->blklvl - 1])) { // mPDF 6
1666 + $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl - 1]['cascadeCSS'][$tag], $p);
1667 + foreach ($classes AS $class) {
1668 + $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl - 1]['cascadeCSS']['CLASS>>' . $class], $p);
1669 + }
1670 + $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl - 1]['cascadeCSS']['ID>>' . $attr['ID']], $p);
1671 + foreach ($classes AS $class) {
1672 + $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl - 1]['cascadeCSS'][$tag . '>>CLASS>>' . $class], $p);
1673 + }
1674 + $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl - 1]['cascadeCSS'][$tag . '>>ID>>' . $attr['ID']], $p);
1675 + }
1676 + } else if ($inherit == 'INLINE') {
1677 + $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$tag], $p);
1678 + foreach ($classes AS $class) {
1679 + $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS']['CLASS>>' . $class], $p);
1680 + }
1681 + $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS']['ID>>' . $attr['ID']], $p);
1682 + foreach ($classes AS $class) {
1683 + $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$tag . '>>CLASS>>' . $class], $p);
1684 + }
1685 + $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$tag . '>>ID>>' . $attr['ID']], $p);
1686 + }
1687 + /* -- TABLES -- */ else if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') { // NB looks at $this->tablecascadeCSS-1 for cascading CSS
1688 + if (isset($this->tablecascadeCSS[$this->tbCSSlvl - 1])) { // mPDF 6
1689 + // false, 9 = don't check for 'depth' and do set border dominance
1690 + $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl - 1][$tag], $p, false, 9);
1691 + foreach ($classes AS $class) {
1692 + $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl - 1]['CLASS>>' . $class], $p, false, 9);
1693 + }
1694 + // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
1695 + if ($tag == 'TR' || $tag == 'TD' || $tag == 'TH') {
1696 + foreach ($this->tablecascadeCSS[$this->tbCSSlvl - 1] AS $k => $val) {
1697 + if (preg_match('/' . $tag . '>>SELECTORNTHCHILD>>(.*)/', $k, $m)) {
1698 + $select = false;
1699 + if ($tag == 'TR') {
1700 + $row = $this->mpdf->row;
1701 + $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);
1702 + $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);
1703 + if ($this->mpdf->tabletfoot) {
1704 + $row -= $thnr;
1705 + } else if (!$this->mpdf->tablethead) {
1706 + $row -= ($thnr + $tfnr);
1707 + }
1708 + if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/', $m[1], $a)) { // mPDF 5.7.4
1709 + $select = $this->_nthchild($a, $row);
1710 + }
1711 + } else if ($tag == 'TD' || $tag == 'TH') {
1712 + if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/', $m[1], $a)) { // mPDF 5.7.4
1713 + $select = $this->_nthchild($a, $this->mpdf->col);
1714 + }
1715 + }
1716 + if ($select) {
1717 + $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl - 1][$tag . '>>SELECTORNTHCHILD>>' . $m[1]], $p, false, 9);
1718 + }
1719 + }
1720 + }
1721 + }
1722 + }
1723 + $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl - 1]['ID>>' . $attr['ID']], $p, false, 9);
1724 + foreach ($classes AS $class) {
1725 + $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl - 1][$tag . '>>CLASS>>' . $class], $p, false, 9);
1726 + }
1727 + $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl - 1][$tag . '>>ID>>' . $attr['ID']], $p, false, 9);
1728 + }
1729 + /* -- END TABLES -- */
1730 + //===============================================
1731 + //===============================================
1732 + // INLINE STYLE e.g. style="CSS:property"
1733 + if (isset($attr['STYLE'])) {
1734 + $zp = $this->readInlineCSS($attr['STYLE']);
1735 + if ($tag == 'TD' || $tag == 'TH') {
1736 + $this->setBorderDominance($zp, 9);
1737 + } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1738 + if (is_array($zp)) {
1739 + $p = array_merge($p, $zp);
1740 + $this->_mergeBorders($p, $zp);
1741 + }
1742 + }
1743 + //===============================================
1744 + //===============================================
1745 + return $p;
1746 + }
1747 +
1748 +// Convert inline Properties back to CSS
1749 + function inlinePropsToCSS($bilp, &$p)
1750 + {
1751 + if (isset($bilp['family']) && $bilp['family']) {
1752 + $p['FONT-FAMILY'] = $bilp['family'];
1753 + }
1754 + if (isset($bilp['I']) && $bilp['I']) {
1755 + $p['FONT-STYLE'] = 'italic';
1756 + }
1757 + if (isset($bilp['sizePt']) && $bilp['sizePt']) {
1758 + $p['FONT-SIZE'] = $bilp['sizePt'] . 'pt';
1759 + }
1760 + if (isset($bilp['B']) && $bilp['B']) {
1761 + $p['FONT-WEIGHT'] = 'bold';
1762 + }
1763 + if (isset($bilp['colorarray']) && $bilp['colorarray']) {
1764 + $cor = $bilp['colorarray'];
1765 + $p['COLOR'] = $this->mpdf->_colAtoString($cor);
1766 + }
1767 + if (isset($bilp['lSpacingCSS']) && $bilp['lSpacingCSS']) {
1768 + $p['LETTER-SPACING'] = $bilp['lSpacingCSS'];
1769 + }
1770 + if (isset($bilp['wSpacingCSS']) && $bilp['wSpacingCSS']) {
1771 + $p['WORD-SPACING'] = $bilp['wSpacingCSS'];
1772 + }
1773 +
1774 + if (isset($bilp['textparam']) && $bilp['textparam']) {
1775 + if (isset($bilp['textparam']['hyphens'])) {
1776 + if ($bilp['textparam']['hyphens'] == 2) {
1777 + $p['HYPHENS'] = 'none';
1778 + }
1779 + if ($bilp['textparam']['hyphens'] == 1) {
1780 + $p['HYPHENS'] = 'auto';
1781 + }
1782 + if ($bilp['textparam']['hyphens'] == 0) {
1783 + $p['HYPHENS'] = 'manual';
1784 + }
1785 + }
1786 + if (isset($bilp['textparam']['outline-s']) && !$bilp['textparam']['outline-s']) {
1787 + $p['TEXT-OUTLINE'] = 'none';
1788 + }
1789 + if (isset($bilp['textparam']['outline-COLOR']) && $bilp['textparam']['outline-COLOR']) {
1790 + $p['TEXT-OUTLINE-COLOR'] = $this->mpdf->_colAtoString($bilp['textparam']['outline-COLOR']);
1791 + }
1792 + if (isset($bilp['textparam']['outline-WIDTH']) && $bilp['textparam']['outline-WIDTH']) {
1793 + $p['TEXT-OUTLINE-WIDTH'] = $bilp['textparam']['outline-WIDTH'] . 'mm';
1794 + }
1795 + }
1796 +
1797 + if (isset($bilp['textvar']) && $bilp['textvar']) {
1798 + // CSS says text-decoration is not inherited, but IE7 does??
1799 + if ($bilp['textvar'] & FD_LINETHROUGH) {
1800 + if ($bilp['textvar'] & FD_UNDERLINE) {
1801 + $p['TEXT-DECORATION'] = 'underline line-through';
1802 + } else {
1803 + $p['TEXT-DECORATION'] = 'line-through';
1804 + }
1805 + } else if ($bilp['textvar'] & FD_UNDERLINE) {
1806 + $p['TEXT-DECORATION'] = 'underline';
1807 + } else {
1808 + $p['TEXT-DECORATION'] = 'none';
1809 + }
1810 +
1811 + if ($bilp['textvar'] & FA_SUPERSCRIPT) {
1812 + $p['VERTICAL-ALIGN'] = 'super';
1813 + } else if ($bilp['textvar'] & FA_SUBSCRIPT) {
1814 + $p['VERTICAL-ALIGN'] = 'sub';
1815 + } else {
1816 + $p['VERTICAL-ALIGN'] = 'baseline';
1817 + }
1818 +
1819 + if ($bilp['textvar'] & FT_CAPITALIZE) {
1820 + $p['TEXT-TRANSFORM'] = 'capitalize';
1821 + } else if ($bilp['textvar'] & FT_UPPERCASE) {
1822 + $p['TEXT-TRANSFORM'] = 'uppercase';
1823 + } else if ($bilp['textvar'] & FT_LOWERCASE) {
1824 + $p['TEXT-TRANSFORM'] = 'lowercase';
1825 + } else {
1826 + $p['TEXT-TRANSFORM'] = 'none';
1827 + }
1828 +
1829 + if ($bilp['textvar'] & FC_KERNING) {
1830 + $p['FONT-KERNING'] = 'normal';
1831 + } // ignore 'auto' as default already applied
1832 + //if (isset($bilp[ 'OTLtags' ]) && $bilp[ 'OTLtags' ]['Plus'] contains 'kern'
1833 + else {
1834 + $p['FONT-KERNING'] = 'none';
1835 + }
1836 +
1837 + if ($bilp['textvar'] & FA_SUPERSCRIPT) {
1838 + $p['FONT-VARIANT-POSITION'] = 'super';
1839 + }
1840 + //if (isset($bilp[ 'OTLtags' ]) && $bilp[ 'OTLtags' ]['Plus'] contains 'sups' / 'subs'
1841 + else if ($bilp['textvar'] & FA_SUBSCRIPT) {
1842 + $p['FONT-VARIANT-POSITION'] = 'sub';
1843 + } else {
1844 + $p['FONT-VARIANT-POSITION'] = 'normal';
1845 + }
1846 +
1847 + if ($bilp['textvar'] & FC_SMALLCAPS) {
1848 + $p['FONT-VARIANT-CAPS'] = 'small-caps';
1849 + }
1850 + }
1851 + if (isset($bilp['fontLanguageOverride'])) {
1852 + if ($bilp['fontLanguageOverride']) {
1853 + $p['FONT-LANGUAGE-OVERRIDE'] = $bilp['fontLanguageOverride'];
1854 + } else {
1855 + $p['FONT-LANGUAGE-OVERRIDE'] = 'normal';
1856 + }
1857 + }
1858 + // All the variations of font-variant-* we are going to set as font-feature-settings...
1859 + if (isset($bilp['OTLtags']) && $bilp['OTLtags']) {
1860 + $ffs = array();
1861 + if (isset($bilp['OTLtags']['Minus']) && $bilp['OTLtags']['Minus']) {
1862 + $f = preg_split('/\s+/', trim($bilp['OTLtags']['Minus']));
1863 + foreach ($f AS $ff) {
1864 + $ffs[] = "'" . $ff . "' 0";
1865 + }
1866 + }
1867 + if (isset($bilp['OTLtags']['FFMinus']) && $bilp['OTLtags']['FFMinus']) {
1868 + $f = preg_split('/\s+/', trim($bilp['OTLtags']['FFMinus']));
1869 + foreach ($f AS $ff) {
1870 + $ffs[] = "'" . $ff . "' 0";
1871 + }
1872 + }
1873 + if (isset($bilp['OTLtags']['Plus']) && $bilp['OTLtags']['Plus']) {
1874 + $f = preg_split('/\s+/', trim($bilp['OTLtags']['Plus']));
1875 + foreach ($f AS $ff) {
1876 + $ffs[] = "'" . $ff . "' 1";
1877 + }
1878 + }
1879 + if (isset($bilp['OTLtags']['FFPlus']) && $bilp['OTLtags']['FFPlus']) { // May contain numeric value e.g. salt4
1880 + $f = preg_split('/\s+/', trim($bilp['OTLtags']['FFPlus']));
1881 + foreach ($f AS $ff) {
1882 + if (strlen($ff) > 4) {
1883 + $ffs[] = "'" . substr($ff, 0, 4) . "' " . substr($ff, 4);
1884 + } else {
1885 + $ffs[] = "'" . $ff . "' 1";
1886 + }
1887 + }
1888 + }
1889 + $p['FONT-FEATURE-SETTINGS'] = implode(', ', $ffs);
1890 + }
1891 + }
1892 +
1893 + function PreviewBlockCSS($tag, $attr)
1894 + {
1895 + // Looks ahead from current block level to a new level
1896 + $p = array();
1897 + $zp = array();
1898 + $oldcascadeCSS = $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'];
1899 + $classes = array();
1900 + if (isset($attr['CLASS'])) {
1901 + $classes = preg_split('/\s+/', $attr['CLASS']);
1902 + }
1903 + //===============================================
1904 + // DEFAULT for this TAG set in DefaultCSS
1905 + if (isset($this->mpdf->defaultCSS[$tag])) {
1906 + $zp = $this->fixCSS($this->mpdf->defaultCSS[$tag]);
1907 + if (is_array($zp)) {
1908 + $p = array_merge($zp, $p);
1909 + } // Inherited overwrites default
1910 + }
1911 + // STYLESHEET TAG e.g. h1 p div table
1912 + if (isset($this->CSS[$tag])) {
1913 + $zp = $this->CSS[$tag];
1914 + if (is_array($zp)) {
1915 + $p = array_merge($p, $zp);
1916 + }
1917 + }
1918 + // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1919 + foreach ($classes AS $class) {
1920 + $zp = array();
1921 + if (isset($this->CSS['CLASS>>' . $class])) {
1922 + $zp = $this->CSS['CLASS>>' . $class];
1923 + }
1924 + if (is_array($zp)) {
1925 + $p = array_merge($p, $zp);
1926 + }
1927 + }
1928 + // STYLESHEET ID e.g. #smallone{} #redletter{}
1929 + if (isset($attr['ID']) && isset($this->CSS['ID>>' . $attr['ID']])) {
1930 + $zp = $this->CSS['ID>>' . $attr['ID']];
1931 + if (is_array($zp)) {
1932 + $p = array_merge($p, $zp);
1933 + }
1934 + }
1935 + // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
1936 + foreach ($classes AS $class) {
1937 + $zp = array();
1938 + if (isset($this->CSS[$tag . '>>CLASS>>' . $class])) {
1939 + $zp = $this->CSS[$tag . '>>CLASS>>' . $class];
1940 + }
1941 + if (is_array($zp)) {
1942 + $p = array_merge($p, $zp);
1943 + }
1944 + }
1945 + // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
1946 + if (isset($attr['ID']) && isset($this->CSS[$tag . '>>ID>>' . $attr['ID']])) {
1947 + $zp = $this->CSS[$tag . '>>ID>>' . $attr['ID']];
1948 + if (is_array($zp)) {
1949 + $p = array_merge($p, $zp);
1950 + }
1951 + }
1952 + //===============================================
1953 + // STYLESHEET TAG e.g. div h1 div p
1954 +
1955 + $this->_set_mergedCSS($oldcascadeCSS[$tag], $p);
1956 + // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1957 + foreach ($classes AS $class) {
1958 +
1959 + $this->_set_mergedCSS($oldcascadeCSS['CLASS>>' . $class], $p);
1960 + }
1961 + // STYLESHEET CLASS e.g. #smallone{} #redletter{}
1962 + if (isset($attr['ID'])) {
1963 +
1964 + $this->_set_mergedCSS($oldcascadeCSS['ID>>' . $attr['ID']], $p);
1965 + }
1966 + // STYLESHEET CLASS e.g. div.smallone{} p.redletter{}
1967 + foreach ($classes AS $class) {
1968 +
1969 + $this->_set_mergedCSS($oldcascadeCSS[$tag . '>>CLASS>>' . $class], $p);
1970 + }
1971 + // STYLESHEET CLASS e.g. div#smallone{} p#redletter{}
1972 + if (isset($attr['ID'])) {
1973 +
1974 + $this->_set_mergedCSS($oldcascadeCSS[$tag . '>>ID>>' . $attr['ID']], $p);
1975 + }
1976 + //===============================================
1977 + // INLINE STYLE e.g. style="CSS:property"
1978 + if (isset($attr['STYLE'])) {
1979 + $zp = $this->readInlineCSS($attr['STYLE']);
1980 + if (is_array($zp)) {
1981 + $p = array_merge($p, $zp);
1982 + }
1983 + }
1984 + //===============================================
1985 + return $p;
1986 + }
1987 +
1988 +// mPDF 5.7.4 nth-child
1989 + function _nthchild($f, $c)
1990 + {
1991 + // $f is formual e.g. 2N+1 spilt into a preg_match array
1992 + // $c is the comparator value e.g row or column number
1993 + $c += 1;
1994 + $select = false;
1995 + $a = 1;
1996 + $b = 1;
1997 + if ($f[0] == 'ODD') {
1998 + $a = 2;
1999 + $b = 1;
2000 + } else if ($f[0] == 'EVEN') {
2001 + $a = 2;
2002 + $b = 0;
2003 + } else if (count($f) == 2) {
2004 + $a = 0;
2005 + $b = $f[1] + 0;
2006 + } // e.g. (+6)
2007 + else if (count($f) == 3) { // e.g. (2N)
2008 + if ($f[2] == '') {
2009 + $a = 1;
2010 + } else if ($f[2] == '-') {
2011 + $a = -1;
2012 + } else {
2013 + $a = $f[2] + 0;
2014 + }
2015 + $b = 0;
2016 + } else if (count($f) == 4) { // e.g. (2N+6)
2017 + if ($f[2] == '') {
2018 + $a = 1;
2019 + } else if ($f[2] == '-') {
2020 + $a = -1;
2021 + } else {
2022 + $a = $f[2] + 0;
2023 + }
2024 + $b = $f[3] + 0;
2025 + } else {
2026 + return false;
2027 + }
2028 + if ($a > 0) {
2029 + if (((($c % $a) - $b) % $a) == 0 && $c >= $b) {
2030 + $select = true;
2031 + }
2032 + } else if ($a == 0) {
2033 + if ($c == $b) {
2034 + $select = true;
2035 + }
2036 + } else { // if ($a<0)
2037 + if (((($c % $a) - $b) % $a) == 0 && $c <= $b) {
2038 + $select = true;
2039 + }
2040 + }
2041 + return $select;
2042 + }
2043 +
2044 +}