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