1 | <?php
|
---|
2 | /**
|
---|
3 | * Logiciel : HTML2PDF - classe styleHTML
|
---|
4 | *
|
---|
5 | * Convertisseur HTML => PDF, utilise fpdf de Olivier PLATHEY
|
---|
6 | * Distribué sous la licence GPL.
|
---|
7 | *
|
---|
8 | * @author Laurent MINGUET <webmaster@spipu.net>
|
---|
9 | * @version 3.21 - 05/05/2009
|
---|
10 | */
|
---|
11 |
|
---|
12 | if (!defined('__CLASS_STYLEHTML__'))
|
---|
13 | {
|
---|
14 | define('__CLASS_STYLEHTML__', true);
|
---|
15 |
|
---|
16 | class styleHTML
|
---|
17 | {
|
---|
18 | var $css = array(); // tableau des CSS
|
---|
19 | var $css_keys = array(); // tableau des clefs CSS, pour l'ordre d'execution
|
---|
20 | var $value = array(); // valeurs actuelles
|
---|
21 | var $table = array(); // tableau d'empilement pour historisation des niveaux
|
---|
22 | var $pdf = null; // référence au PDF parent
|
---|
23 | var $htmlColor = array(); // liste des couleurs HTML
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Constructeur
|
---|
27 | *
|
---|
28 | * @param &pdf référence à l'objet HTML2PDF parent
|
---|
29 | * @return null
|
---|
30 | */
|
---|
31 | function styleHTML(&$pdf)
|
---|
32 | {
|
---|
33 | $this->init(); // initialisation
|
---|
34 | $this->pdf = &$pdf;
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Initialisation du style
|
---|
39 | *
|
---|
40 | * @return null
|
---|
41 | */
|
---|
42 | function init()
|
---|
43 | {
|
---|
44 | $color = array();
|
---|
45 | $color['AliceBlue'] = '#F0F8FF';
|
---|
46 | $color['AntiqueWhite'] = '#FAEBD7';
|
---|
47 | $color['Aqua'] = '#00FFFF';
|
---|
48 | $color['Aquamarine'] = '#7FFFD4';
|
---|
49 | $color['Azure'] = '#F0FFFF';
|
---|
50 | $color['Beige'] = '#F5F5DC';
|
---|
51 | $color['Bisque'] = '#FFE4C4';
|
---|
52 | $color['Black'] = '#000000';
|
---|
53 | $color['BlanchedAlmond'] = '#FFEBCD';
|
---|
54 | $color['Blue'] = '#0000FF';
|
---|
55 | $color['BlueViolet'] = '#8A2BE2';
|
---|
56 | $color['Brown'] = '#A52A2A';
|
---|
57 | $color['BurlyWood'] = '#DEB887';
|
---|
58 | $color['CadetBlue'] = '#5F9EA0';
|
---|
59 | $color['Chartreuse'] = '#7FFF00';
|
---|
60 | $color['Chocolate'] = '#D2691E';
|
---|
61 | $color['Coral'] = '#FF7F50';
|
---|
62 | $color['CornflowerBlue'] = '#6495ED';
|
---|
63 | $color['Cornsilk'] = '#FFF8DC';
|
---|
64 | $color['Crimson'] = '#DC143C';
|
---|
65 | $color['Cyan'] = '#00FFFF';
|
---|
66 | $color['DarkBlue'] = '#00008B';
|
---|
67 | $color['DarkCyan'] = '#008B8B';
|
---|
68 | $color['DarkGoldenRod'] = '#B8860B';
|
---|
69 | $color['DarkGray'] = '#A9A9A9';
|
---|
70 | $color['DarkGrey'] = '#A9A9A9';
|
---|
71 | $color['DarkGreen'] = '#006400';
|
---|
72 | $color['DarkKhaki'] = '#BDB76B';
|
---|
73 | $color['DarkMagenta'] = '#8B008B';
|
---|
74 | $color['DarkOliveGreen'] = '#556B2F';
|
---|
75 | $color['Darkorange'] = '#FF8C00';
|
---|
76 | $color['DarkOrchid'] = '#9932CC';
|
---|
77 | $color['DarkRed'] = '#8B0000';
|
---|
78 | $color['DarkSalmon'] = '#E9967A';
|
---|
79 | $color['DarkSeaGreen'] = '#8FBC8F';
|
---|
80 | $color['DarkSlateBlue'] = '#483D8B';
|
---|
81 | $color['DarkSlateGray'] = '#2F4F4F';
|
---|
82 | $color['DarkSlateGrey'] = '#2F4F4F';
|
---|
83 | $color['DarkTurquoise'] = '#00CED1';
|
---|
84 | $color['DarkViolet'] = '#9400D3';
|
---|
85 | $color['DeepPink'] = '#FF1493';
|
---|
86 | $color['DeepSkyBlue'] = '#00BFFF';
|
---|
87 | $color['DimGray'] = '#696969';
|
---|
88 | $color['DimGrey'] = '#696969';
|
---|
89 | $color['DodgerBlue'] = '#1E90FF';
|
---|
90 | $color['FireBrick'] = '#B22222';
|
---|
91 | $color['FloralWhite'] = '#FFFAF0';
|
---|
92 | $color['ForestGreen'] = '#228B22';
|
---|
93 | $color['Fuchsia'] = '#FF00FF';
|
---|
94 | $color['Gainsboro'] = '#DCDCDC';
|
---|
95 | $color['GhostWhite'] = '#F8F8FF';
|
---|
96 | $color['Gold'] = '#FFD700';
|
---|
97 | $color['GoldenRod'] = '#DAA520';
|
---|
98 | $color['Gray'] = '#808080';
|
---|
99 | $color['Grey'] = '#808080';
|
---|
100 | $color['Green'] = '#008000';
|
---|
101 | $color['GreenYellow'] = '#ADFF2F';
|
---|
102 | $color['HoneyDew'] = '#F0FFF0';
|
---|
103 | $color['HotPink'] = '#FF69B4';
|
---|
104 | $color['IndianRed'] = '#CD5C5C';
|
---|
105 | $color['Indigo'] = '#4B0082';
|
---|
106 | $color['Ivory'] = '#FFFFF0';
|
---|
107 | $color['Khaki'] = '#F0E68C';
|
---|
108 | $color['Lavender'] = '#E6E6FA';
|
---|
109 | $color['LavenderBlush'] = '#FFF0F5';
|
---|
110 | $color['LawnGreen'] = '#7CFC00';
|
---|
111 | $color['LemonChiffon'] = '#FFFACD';
|
---|
112 | $color['LightBlue'] = '#ADD8E6';
|
---|
113 | $color['LightCoral'] = '#F08080';
|
---|
114 | $color['LightCyan'] = '#E0FFFF';
|
---|
115 | $color['LightGoldenRodYellow'] = '#FAFAD2';
|
---|
116 | $color['LightGray'] = '#D3D3D3';
|
---|
117 | $color['LightGrey'] = '#D3D3D3';
|
---|
118 | $color['LightGreen'] = '#90EE90';
|
---|
119 | $color['LightPink'] = '#FFB6C1';
|
---|
120 | $color['LightSalmon'] = '#FFA07A';
|
---|
121 | $color['LightSeaGreen'] = '#20B2AA';
|
---|
122 | $color['LightSkyBlue'] = '#87CEFA';
|
---|
123 | $color['LightSlateGray'] = '#778899';
|
---|
124 | $color['LightSlateGrey'] = '#778899';
|
---|
125 | $color['LightSteelBlue'] = '#B0C4DE';
|
---|
126 | $color['LightYellow'] = '#FFFFE0';
|
---|
127 | $color['Lime'] = '#00FF00';
|
---|
128 | $color['LimeGreen'] = '#32CD32';
|
---|
129 | $color['Linen'] = '#FAF0E6';
|
---|
130 | $color['Magenta'] = '#FF00FF';
|
---|
131 | $color['Maroon'] = '#800000';
|
---|
132 | $color['MediumAquaMarine'] = '#66CDAA';
|
---|
133 | $color['MediumBlue'] = '#0000CD';
|
---|
134 | $color['MediumOrchid'] = '#BA55D3';
|
---|
135 | $color['MediumPurple'] = '#9370D8';
|
---|
136 | $color['MediumSeaGreen'] = '#3CB371';
|
---|
137 | $color['MediumSlateBlue'] = '#7B68EE';
|
---|
138 | $color['MediumSpringGreen'] = '#00FA9A';
|
---|
139 | $color['MediumTurquoise'] = '#48D1CC';
|
---|
140 | $color['MediumVioletRed'] = '#C71585';
|
---|
141 | $color['MidnightBlue'] = '#191970';
|
---|
142 | $color['MintCream'] = '#F5FFFA';
|
---|
143 | $color['MistyRose'] = '#FFE4E1';
|
---|
144 | $color['Moccasin'] = '#FFE4B5';
|
---|
145 | $color['NavajoWhite'] = '#FFDEAD';
|
---|
146 | $color['Navy'] = '#000080';
|
---|
147 | $color['OldLace'] = '#FDF5E6';
|
---|
148 | $color['Olive'] = '#808000';
|
---|
149 | $color['OliveDrab'] = '#6B8E23';
|
---|
150 | $color['Orange'] = '#FFA500';
|
---|
151 | $color['OrangeRed'] = '#FF4500';
|
---|
152 | $color['Orchid'] = '#DA70D6';
|
---|
153 | $color['PaleGoldenRod'] = '#EEE8AA';
|
---|
154 | $color['PaleGreen'] = '#98FB98';
|
---|
155 | $color['PaleTurquoise'] = '#AFEEEE';
|
---|
156 | $color['PaleVioletRed'] = '#D87093';
|
---|
157 | $color['PapayaWhip'] = '#FFEFD5';
|
---|
158 | $color['PeachPuff'] = '#FFDAB9';
|
---|
159 | $color['Peru'] = '#CD853F';
|
---|
160 | $color['Pink'] = '#FFC0CB';
|
---|
161 | $color['Plum'] = '#DDA0DD';
|
---|
162 | $color['PowderBlue'] = '#B0E0E6';
|
---|
163 | $color['Purple'] = '#800080';
|
---|
164 | $color['Red'] = '#FF0000';
|
---|
165 | $color['RosyBrown'] = '#BC8F8F';
|
---|
166 | $color['RoyalBlue'] = '#4169E1';
|
---|
167 | $color['SaddleBrown'] = '#8B4513';
|
---|
168 | $color['Salmon'] = '#FA8072';
|
---|
169 | $color['SandyBrown'] = '#F4A460';
|
---|
170 | $color['SeaGreen'] = '#2E8B57';
|
---|
171 | $color['SeaShell'] = '#FFF5EE';
|
---|
172 | $color['Sienna'] = '#A0522D';
|
---|
173 | $color['Silver'] = '#C0C0C0';
|
---|
174 | $color['SkyBlue'] = '#87CEEB';
|
---|
175 | $color['SlateBlue'] = '#6A5ACD';
|
---|
176 | $color['SlateGray'] = '#708090';
|
---|
177 | $color['SlateGrey'] = '#708090';
|
---|
178 | $color['Snow'] = '#FFFAFA';
|
---|
179 | $color['SpringGreen'] = '#00FF7F';
|
---|
180 | $color['SteelBlue'] = '#4682B4';
|
---|
181 | $color['Tan'] = '#D2B48C';
|
---|
182 | $color['Teal'] = '#008080';
|
---|
183 | $color['Thistle'] = '#D8BFD8';
|
---|
184 | $color['Tomato'] = '#FF6347';
|
---|
185 | $color['Turquoise'] = '#40E0D0';
|
---|
186 | $color['Violet'] = '#EE82EE';
|
---|
187 | $color['Wheat'] = '#F5DEB3';
|
---|
188 | $color['White'] = '#FFFFFF';
|
---|
189 | $color['WhiteSmoke'] = '#F5F5F5';
|
---|
190 | $color['Yellow'] = '#FFFF00';
|
---|
191 | $color['YellowGreen'] = '#9ACD32';
|
---|
192 |
|
---|
193 | $this->htmlColor = array();
|
---|
194 | foreach($color as $key => $val) $this->htmlColor[strtolower($key)] = $val;
|
---|
195 | unset($color);
|
---|
196 |
|
---|
197 | $this->table = array();
|
---|
198 |
|
---|
199 | $this->value = array();
|
---|
200 | $this->initStyle();
|
---|
201 |
|
---|
202 | // initialisation des styles sans héritages
|
---|
203 | $this->resetStyle();
|
---|
204 | }
|
---|
205 |
|
---|
206 | function initStyle()
|
---|
207 | {
|
---|
208 | $this->value['id_balise'] = 'body'; // balise
|
---|
209 | $this->value['id_name'] = null; // name
|
---|
210 | $this->value['id_id'] = null; // id
|
---|
211 | $this->value['id_class'] = null; // class
|
---|
212 | $this->value['id_lst'] = array('*'); // lst de dependance
|
---|
213 | $this->value['mini-size'] = 1.; // rapport de taille spécifique aux sup, sub
|
---|
214 | $this->value['mini-decal'] = 0; // rapport de position spécifique aux sup, sub
|
---|
215 | $this->value['font-family'] = 'Arial';
|
---|
216 | $this->value['font-bold'] = false;
|
---|
217 | $this->value['font-italic'] = false;
|
---|
218 | $this->value['font-underline'] = false;
|
---|
219 | $this->value['font-overline'] = false;
|
---|
220 | $this->value['font-linethrough'] = false;
|
---|
221 | $this->value['font-size'] = $this->ConvertToMM('10pt');
|
---|
222 | $this->value['text-indent'] = 0;
|
---|
223 | $this->value['text-align'] = 'left';
|
---|
224 | $this->value['vertical-align'] = 'middle';
|
---|
225 | $this->value['line-height'] = 'normal';
|
---|
226 |
|
---|
227 | $this->value['position'] = null;
|
---|
228 | $this->value['x'] = null;
|
---|
229 | $this->value['y'] = null;
|
---|
230 | $this->value['width'] = 0;
|
---|
231 | $this->value['height'] = 0;
|
---|
232 | $this->value['top'] = null;
|
---|
233 | $this->value['right'] = null;
|
---|
234 | $this->value['bottom'] = null;
|
---|
235 | $this->value['left'] = null;
|
---|
236 | $this->value['float'] = null;
|
---|
237 | $this->value['display'] = null;
|
---|
238 |
|
---|
239 | $this->value['color'] = array(0, 0, 0);
|
---|
240 | $this->value['background'] = array('color' => null, 'image' => null, 'position' => null, 'repeat' => null);
|
---|
241 | $this->value['border'] = array();
|
---|
242 | $this->value['padding'] = array();
|
---|
243 | $this->value['margin'] = array();
|
---|
244 | $this->value['margin-auto'] = false;
|
---|
245 |
|
---|
246 | $this->value['list-style-type'] = '';
|
---|
247 | $this->value['list-style-image'] = '';
|
---|
248 |
|
---|
249 | $this->value['xc'] = null;
|
---|
250 | $this->value['yc'] = null;
|
---|
251 | }
|
---|
252 |
|
---|
253 | /**
|
---|
254 | * Initialisation des styles sans héritages
|
---|
255 | *
|
---|
256 | * @param string balise HTML
|
---|
257 | * @return null
|
---|
258 | */
|
---|
259 | function resetStyle($balise = '')
|
---|
260 | {
|
---|
261 | $collapse = isset($this->value['border']['collapse']) ? $this->value['border']['collapse'] : false;
|
---|
262 | if (!in_array($balise, array('tr', 'td', 'th'))) $collapse = false;
|
---|
263 |
|
---|
264 | $this->value['position'] = null;
|
---|
265 | $this->value['x'] = null;
|
---|
266 | $this->value['y'] = null;
|
---|
267 | $this->value['width'] = 0;
|
---|
268 | $this->value['height'] = 0;
|
---|
269 | $this->value['top'] = null;
|
---|
270 | $this->value['right'] = null;
|
---|
271 | $this->value['bottom'] = null;
|
---|
272 | $this->value['left'] = null;
|
---|
273 | $this->value['float'] = null;
|
---|
274 | $this->value['display'] = null;
|
---|
275 | $this->value['background'] = array('color' => null, 'image' => null, 'position' => null, 'repeat' => null);
|
---|
276 | $this->value['border'] = array(
|
---|
277 | 't' => $this->readBorder('none'),
|
---|
278 | 'r' => $this->readBorder('none'),
|
---|
279 | 'b' => $this->readBorder('none'),
|
---|
280 | 'l' => $this->readBorder('none'),
|
---|
281 | 'radius' => array(0, 0),
|
---|
282 | 'collapse' => $collapse,
|
---|
283 | );
|
---|
284 |
|
---|
285 | $this->value['margin'] = array(
|
---|
286 | 't' => 0,
|
---|
287 | 'r' => 0,
|
---|
288 | 'b' => 0,
|
---|
289 | 'l' => 0
|
---|
290 | );
|
---|
291 | $this->value['margin-auto'] = false;
|
---|
292 |
|
---|
293 | if (in_array($balise, array('div')))
|
---|
294 | $this->value['vertical-align'] = 'top';
|
---|
295 |
|
---|
296 | if (in_array($balise, array('ul', 'li')))
|
---|
297 | {
|
---|
298 | $this->value['list-style-type'] = '';
|
---|
299 | $this->value['list-style-image'] = '';
|
---|
300 | }
|
---|
301 |
|
---|
302 | if (!in_array($balise, array('tr', 'td')))
|
---|
303 | {
|
---|
304 | $this->value['padding'] = array(
|
---|
305 | 't' => 0,
|
---|
306 | 'r' => 0,
|
---|
307 | 'b' => 0,
|
---|
308 | 'l' => 0
|
---|
309 | );
|
---|
310 | }
|
---|
311 | else
|
---|
312 | {
|
---|
313 | $this->value['padding'] = array(
|
---|
314 | 't' => $this->ConvertToMM('1px'),
|
---|
315 | 'r' => $this->ConvertToMM('1px'),
|
---|
316 | 'b' => $this->ConvertToMM('1px'),
|
---|
317 | 'l' => $this->ConvertToMM('1px')
|
---|
318 | );
|
---|
319 | }
|
---|
320 |
|
---|
321 | if ($balise=='hr')
|
---|
322 | {
|
---|
323 | $this->value['border'] = array(
|
---|
324 | 't' => $this->readBorder('solid 1px #000000'),
|
---|
325 | 'r' => $this->readBorder('solid 1px #000000'),
|
---|
326 | 'b' => $this->readBorder('solid 1px #000000'),
|
---|
327 | 'l' => $this->readBorder('solid 1px #000000'),
|
---|
328 | 'radius' => array(0, 0),
|
---|
329 | 'collapse' => false,
|
---|
330 | );
|
---|
331 | $this->ConvertBackground('#FFFFFF', $this->value['background']);
|
---|
332 | }
|
---|
333 |
|
---|
334 | $this->value['xc'] = null;
|
---|
335 | $this->value['yc'] = null;
|
---|
336 | }
|
---|
337 |
|
---|
338 | /**
|
---|
339 | * Initialisation de la font PDF
|
---|
340 | *
|
---|
341 | * @return null
|
---|
342 | */
|
---|
343 | function FontSet()
|
---|
344 | {
|
---|
345 | $b = ($this->value['font-bold'] ? 'B' : '');
|
---|
346 | $i = ($this->value['font-italic'] ? 'I' : '');
|
---|
347 | $u = ($this->value['font-underline'] ? 'U' : '');
|
---|
348 |
|
---|
349 | // taille en mm, à ramener en pt
|
---|
350 | $size = $this->value['font-size'];
|
---|
351 | $size = 72 * $size / 25.4;
|
---|
352 |
|
---|
353 | $this->pdf->setOverline($this->value['font-overline']);
|
---|
354 | $this->pdf->setLinethrough($this->value['font-linethrough']);
|
---|
355 |
|
---|
356 | // application de la fonte
|
---|
357 | $this->pdf->SetFont($this->value['font-family'], $b.$i.$u, $this->value['mini-size']*$size);
|
---|
358 | $this->pdf->SetTextColor($this->value['color'][0],$this->value['color'][1], $this->value['color'][2]);
|
---|
359 | if ($this->value['background']['color'])
|
---|
360 | $this->pdf->SetFillColor($this->value['background']['color'][0],$this->value['background']['color'][1], $this->value['background']['color'][2]);
|
---|
361 | else
|
---|
362 | $this->pdf->SetFillColor(255);
|
---|
363 | }
|
---|
364 |
|
---|
365 | /**
|
---|
366 | * Monter d'un niveau dans l'historisation
|
---|
367 | *
|
---|
368 | * @return null
|
---|
369 | */
|
---|
370 | function save()
|
---|
371 | {
|
---|
372 | $this->table[count($this->table)] = $this->value;
|
---|
373 | }
|
---|
374 |
|
---|
375 | /**
|
---|
376 | * Descendre d'un niveau dans l'historisation
|
---|
377 | *
|
---|
378 | * @return null
|
---|
379 | */
|
---|
380 | function load()
|
---|
381 | {
|
---|
382 | if (count($this->table))
|
---|
383 | {
|
---|
384 | $this->value = $this->table[count($this->table)-1];
|
---|
385 | unset($this->table[count($this->table)-1]);
|
---|
386 | }
|
---|
387 | }
|
---|
388 |
|
---|
389 | function setPosition(&$current_x, &$current_y)
|
---|
390 | {
|
---|
391 | $this->value['xc'] = $current_x;
|
---|
392 | $this->value['yc'] = $current_y;
|
---|
393 |
|
---|
394 | if ($this->value['position']=='relative' || $this->value['position']=='absolute')
|
---|
395 | {
|
---|
396 | if ($this->value['right']!==null)
|
---|
397 | {
|
---|
398 | $x = $this->getLastWidth(true) - $this->value['right'] - $this->value['width'];
|
---|
399 | if ($this->value['margin']['r']) $x-= $this->value['margin']['r'];
|
---|
400 | }
|
---|
401 | else
|
---|
402 | {
|
---|
403 | $x = $this->value['left'];
|
---|
404 | if ($this->value['margin']['l']) $x+= $this->value['margin']['l'];
|
---|
405 | }
|
---|
406 |
|
---|
407 | if ($this->value['bottom']!==null)
|
---|
408 | {
|
---|
409 | $y = $this->getLastHeight(true) - $this->value['bottom'] - $this->value['height'];
|
---|
410 | if ($this->value['margin']['b']) $y-= $this->value['margin']['b'];
|
---|
411 | }
|
---|
412 | else
|
---|
413 | {
|
---|
414 | $y = $this->value['top'];
|
---|
415 | if ($this->value['margin']['t']) $y+= $this->value['margin']['t'];
|
---|
416 | }
|
---|
417 |
|
---|
418 | if ($this->value['position']=='relative')
|
---|
419 | {
|
---|
420 | $this->value['x'] = $current_x + $x;
|
---|
421 | $this->value['y'] = $current_y + $y;
|
---|
422 | }
|
---|
423 | else
|
---|
424 | {
|
---|
425 | $this->value['x'] = $this->getLastAbsoluteX()+$x;
|
---|
426 | $this->value['y'] = $this->getLastAbsoluteY()+$y;
|
---|
427 | }
|
---|
428 | }
|
---|
429 | else
|
---|
430 | {
|
---|
431 | $this->value['x'] = $current_x;
|
---|
432 | $this->value['y'] = $current_y;
|
---|
433 | if ($this->value['margin']['l']) $this->value['x']+= $this->value['margin']['l'];
|
---|
434 | if ($this->value['margin']['t']) $this->value['y']+= $this->value['margin']['t'];
|
---|
435 | }
|
---|
436 |
|
---|
437 | $current_x = $this->value['x'];
|
---|
438 | $current_y = $this->value['y'];
|
---|
439 | }
|
---|
440 |
|
---|
441 | /**
|
---|
442 | * Analyse un tableau de style provenant du parseurHTML
|
---|
443 | *
|
---|
444 | * @param string nom de la balise
|
---|
445 | * @param array tableau de style
|
---|
446 | * @return null
|
---|
447 | */
|
---|
448 | function analyse($balise, &$param)
|
---|
449 | {
|
---|
450 | // preparation
|
---|
451 | $balise = strtolower($balise);
|
---|
452 | $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if (!$id) $id = null;
|
---|
453 | $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if (!$name) $name = null;
|
---|
454 |
|
---|
455 | // lecture de la propriete classe
|
---|
456 | $class = array();
|
---|
457 | $tmp = isset($param['class']) ? preg_replace('/[\s]+/', ' ', strtolower($param['class'])) : '';
|
---|
458 | $tmp = explode(' ', $tmp);
|
---|
459 | foreach($tmp as $k => $v)
|
---|
460 | {
|
---|
461 | $v = trim($v);
|
---|
462 | if ($v) $class[] = $v;
|
---|
463 | }
|
---|
464 |
|
---|
465 | // identification de la balise et des styles direct qui pourraient lui être appliqués
|
---|
466 | $this->value['id_balise'] = $balise;
|
---|
467 | $this->value['id_name'] = $name;
|
---|
468 | $this->value['id_id'] = $id;
|
---|
469 | $this->value['id_class'] = $class;
|
---|
470 | $this->value['id_lst'] = array();
|
---|
471 | $this->value['id_lst'][] = '*';
|
---|
472 | $this->value['id_lst'][] = $balise;
|
---|
473 | if (count($class))
|
---|
474 | {
|
---|
475 | foreach($class as $v)
|
---|
476 | {
|
---|
477 | $this->value['id_lst'][] = '*.'.$v;
|
---|
478 | $this->value['id_lst'][] = '.'.$v;
|
---|
479 | $this->value['id_lst'][] = $balise.'.'.$v;
|
---|
480 | }
|
---|
481 | }
|
---|
482 | if ($id)
|
---|
483 | {
|
---|
484 | $this->value['id_lst'][] = '*#'.$id;
|
---|
485 | $this->value['id_lst'][] = '#'.$id;
|
---|
486 | $this->value['id_lst'][] = $id.'#'.$id;
|
---|
487 | }
|
---|
488 |
|
---|
489 | // style CSS
|
---|
490 | $styles = $this->getFromCSS();
|
---|
491 |
|
---|
492 | // on ajoute le style propre à la balise
|
---|
493 | $styles = array_merge($styles, $param['style']);
|
---|
494 | if (isset($param['allwidth']) && !isset($styles['width'])) $styles['width'] = '100%';
|
---|
495 |
|
---|
496 | // mise à zero des styles non hérités
|
---|
497 | $this->resetStyle($balise);
|
---|
498 |
|
---|
499 | // interpreration des nouvelles valeurs
|
---|
500 | $correct_width = false;
|
---|
501 | foreach($styles as $nom => $val)
|
---|
502 | {
|
---|
503 | switch($nom)
|
---|
504 | {
|
---|
505 | case 'font-family':
|
---|
506 | $val = explode(',', $val);
|
---|
507 | $val = trim($val[0]);
|
---|
508 |
|
---|
509 | if ($val) $this->value['font-family'] = $val;
|
---|
510 | break;
|
---|
511 |
|
---|
512 | case 'font-weight':
|
---|
513 | $this->value['font-bold'] = ($val=='bold');
|
---|
514 | break;
|
---|
515 |
|
---|
516 | case 'font-style':
|
---|
517 | $this->value['font-italic'] = ($val=='italic');
|
---|
518 | break;
|
---|
519 |
|
---|
520 | case 'text-decoration':
|
---|
521 | $val = explode(' ', $val);
|
---|
522 | $this->value['font-underline'] = (in_array('underline', $val));
|
---|
523 | $this->value['font-overline'] = (in_array('overline', $val));
|
---|
524 | $this->value['font-linethrough'] = (in_array('line-through', $val));
|
---|
525 | break;
|
---|
526 |
|
---|
527 | case 'text-indent':
|
---|
528 | $this->value['text-indent'] = $this->ConvertToMM($val);
|
---|
529 | break;
|
---|
530 |
|
---|
531 | case 'font-size':
|
---|
532 | $val = $this->ConvertToMM($val, $this->value['font-size']);
|
---|
533 | if ($val) $this->value['font-size'] = $val;
|
---|
534 | break;
|
---|
535 |
|
---|
536 | case 'color':
|
---|
537 | $res = null;
|
---|
538 | $this->value['color'] = $this->ConvertToRVB($val, $res);
|
---|
539 |
|
---|
540 | if ($balise=='hr')
|
---|
541 | {
|
---|
542 | $this->value['border']['l']['color'] = $this->value['color'];
|
---|
543 | $this->value['border']['t']['color'] = $this->value['color'];
|
---|
544 | $this->value['border']['r']['color'] = $this->value['color'];
|
---|
545 | $this->value['border']['b']['color'] = $this->value['color'];
|
---|
546 | }
|
---|
547 | break;
|
---|
548 |
|
---|
549 | case 'text-align':
|
---|
550 | $this->value['text-align'] = $val;
|
---|
551 | break;
|
---|
552 |
|
---|
553 | case 'vertical-align':
|
---|
554 | $this->value['vertical-align'] = $val;
|
---|
555 | break;
|
---|
556 |
|
---|
557 | case 'width':
|
---|
558 | $this->value['width'] = $this->ConvertToMM($val, $this->getLastWidth());
|
---|
559 | if ($this->value['width'] && substr($val, -1)=='%') $correct_width=true;
|
---|
560 | break;
|
---|
561 |
|
---|
562 | case 'height':
|
---|
563 | $this->value['height'] = $this->ConvertToMM($val, $this->getLastHeight());
|
---|
564 | break;
|
---|
565 |
|
---|
566 | case 'line-height':
|
---|
567 | if (preg_match('/^[0-9\.]+$/isU', $val)) $val = floor($val*100).'%';
|
---|
568 | $this->value['line-height'] = $val;
|
---|
569 | break;
|
---|
570 |
|
---|
571 | case 'padding':
|
---|
572 | $val = explode(' ', $val);
|
---|
573 | foreach($val as $k => $v)
|
---|
574 | {
|
---|
575 | $v = trim($v);
|
---|
576 | if ($v!='') $val[$k] = $v;
|
---|
577 | else unset($val[$k]);
|
---|
578 | }
|
---|
579 | $val = array_values($val);
|
---|
580 | if (count($val)!=4)
|
---|
581 | {
|
---|
582 | $val = $this->ConvertToMM($val[0], 0);
|
---|
583 | $this->value['padding']['t'] = $val;
|
---|
584 | $this->value['padding']['r'] = $val;
|
---|
585 | $this->value['padding']['b'] = $val;
|
---|
586 | $this->value['padding']['l'] = $val;
|
---|
587 | }
|
---|
588 | else
|
---|
589 | {
|
---|
590 | $this->value['padding']['t'] = $this->ConvertToMM($val[0], 0);
|
---|
591 | $this->value['padding']['r'] = $this->ConvertToMM($val[1], 0);
|
---|
592 | $this->value['padding']['b'] = $this->ConvertToMM($val[2], 0);
|
---|
593 | $this->value['padding']['l'] = $this->ConvertToMM($val[3], 0);
|
---|
594 | }
|
---|
595 | break;
|
---|
596 |
|
---|
597 | case 'padding-top':
|
---|
598 | $this->value['padding']['t'] = $this->ConvertToMM($val, 0);
|
---|
599 | break;
|
---|
600 |
|
---|
601 | case 'padding-right':
|
---|
602 | $this->value['padding']['r'] = $this->ConvertToMM($val, 0);
|
---|
603 | break;
|
---|
604 |
|
---|
605 | case 'padding-bottom':
|
---|
606 | $this->value['padding']['b'] = $this->ConvertToMM($val, 0);
|
---|
607 | break;
|
---|
608 |
|
---|
609 | case 'padding-left':
|
---|
610 | $this->value['padding']['l'] = $this->ConvertToMM($val, 0);
|
---|
611 | break;
|
---|
612 |
|
---|
613 | case 'margin':
|
---|
614 | if ($val=='auto')
|
---|
615 | {
|
---|
616 | $this->value['margin-auto'] = true;
|
---|
617 | break;
|
---|
618 | }
|
---|
619 | $val = explode(' ', $val);
|
---|
620 | foreach($val as $k => $v)
|
---|
621 | {
|
---|
622 | $v = trim($v);
|
---|
623 | if ($v!='') $val[$k] = $v;
|
---|
624 | else unset($val[$k]);
|
---|
625 | }
|
---|
626 | $val = array_values($val);
|
---|
627 | if (count($val)!=4)
|
---|
628 | {
|
---|
629 | $val = $this->ConvertToMM($val[0], 0);
|
---|
630 | $this->value['margin']['t'] = $val;
|
---|
631 | $this->value['margin']['r'] = $val;
|
---|
632 | $this->value['margin']['b'] = $val;
|
---|
633 | $this->value['margin']['l'] = $val;
|
---|
634 | }
|
---|
635 | else
|
---|
636 | {
|
---|
637 | $this->value['margin']['t'] = $this->ConvertToMM($val[0], 0);
|
---|
638 | $this->value['margin']['r'] = $this->ConvertToMM($val[1], 0);
|
---|
639 | $this->value['margin']['b'] = $this->ConvertToMM($val[2], 0);
|
---|
640 | $this->value['margin']['l'] = $this->ConvertToMM($val[3], 0);
|
---|
641 | }
|
---|
642 | break;
|
---|
643 |
|
---|
644 | case 'margin-top':
|
---|
645 | $this->value['margin']['t'] = $this->ConvertToMM($val, 0);
|
---|
646 | break;
|
---|
647 |
|
---|
648 | case 'margin-right':
|
---|
649 | $this->value['margin']['r'] = $this->ConvertToMM($val, 0);
|
---|
650 | break;
|
---|
651 |
|
---|
652 | case 'margin-bottom':
|
---|
653 | $this->value['margin']['b'] = $this->ConvertToMM($val, 0);
|
---|
654 | break;
|
---|
655 |
|
---|
656 | case 'margin-left':
|
---|
657 | $this->value['margin']['l'] = $this->ConvertToMM($val, 0);
|
---|
658 | break;
|
---|
659 |
|
---|
660 | case 'border':
|
---|
661 | $val = $this->readBorder($val);
|
---|
662 | $this->value['border']['t'] = $val;
|
---|
663 | $this->value['border']['r'] = $val;
|
---|
664 | $this->value['border']['b'] = $val;
|
---|
665 | $this->value['border']['l'] = $val;
|
---|
666 | break;
|
---|
667 |
|
---|
668 | case 'border-style':
|
---|
669 | $val = explode(' ', $val);
|
---|
670 | foreach($val as $val_k => $val_v)
|
---|
671 | if (!in_array($val_v, array('solid', 'dotted', 'dashed')))
|
---|
672 | $val[$val_k] = null;
|
---|
673 | $this->duplicateBorder($val);
|
---|
674 |
|
---|
675 | if ($val[0]) $this->value['border']['t']['type'] = $val[0];
|
---|
676 | if ($val[1]) $this->value['border']['r']['type'] = $val[1];
|
---|
677 | if ($val[2]) $this->value['border']['b']['type'] = $val[2];
|
---|
678 | if ($val[3]) $this->value['border']['l']['type'] = $val[3];
|
---|
679 | break;
|
---|
680 |
|
---|
681 | case 'border-top-style':
|
---|
682 | if (in_array($val, array('solid', 'dotted', 'dashed')))
|
---|
683 | $this->value['border']['t']['type'] = $val;
|
---|
684 | break;
|
---|
685 |
|
---|
686 | case 'border-right-style':
|
---|
687 | if (in_array($val, array('solid', 'dotted', 'dashed')))
|
---|
688 | $this->value['border']['r']['type'] = $val;
|
---|
689 | break;
|
---|
690 |
|
---|
691 | case 'border-bottom-style':
|
---|
692 | if (in_array($val, array('solid', 'dotted', 'dashed')))
|
---|
693 | $this->value['border']['b']['type'] = $val;
|
---|
694 | break;
|
---|
695 |
|
---|
696 | case 'border-left-style':
|
---|
697 | if (in_array($val, array('solid', 'dotted', 'dashed')))
|
---|
698 | $this->value['border']['l']['type'] = $val;
|
---|
699 | break;
|
---|
700 |
|
---|
701 | case 'border-color':
|
---|
702 | $res = false;
|
---|
703 | $val = preg_replace('/,[\s]+/', ',', $val);
|
---|
704 | $val = explode(' ', $val);
|
---|
705 |
|
---|
706 | foreach($val as $val_k => $val_v)
|
---|
707 | {
|
---|
708 | $val[$val_k] = $this->ConvertToRVB($val_v, $res);
|
---|
709 | if (!$res) $val[$val_k] = null;
|
---|
710 | }
|
---|
711 | $this->duplicateBorder($val);
|
---|
712 |
|
---|
713 | if (is_array($val[0])) $this->value['border']['t']['color'] = $val[0];
|
---|
714 | if (is_array($val[1])) $this->value['border']['r']['color'] = $val[1];
|
---|
715 | if (is_array($val[2])) $this->value['border']['b']['color'] = $val[2];
|
---|
716 | if (is_array($val[3])) $this->value['border']['l']['color'] = $val[3];
|
---|
717 |
|
---|
718 | break;
|
---|
719 |
|
---|
720 | case 'border-top-color':
|
---|
721 | $res = false;
|
---|
722 | $val = $this->ConvertToRVB($val, $res);
|
---|
723 | if ($res) $this->value['border']['t']['color'] = $val;
|
---|
724 | break;
|
---|
725 |
|
---|
726 | case 'border-right-color':
|
---|
727 | $res = false;
|
---|
728 | $val = $this->ConvertToRVB($val, $res);
|
---|
729 | if ($res) $this->value['border']['r']['color'] = $val;
|
---|
730 | break;
|
---|
731 |
|
---|
732 | case 'border-bottom-color':
|
---|
733 | $res = false;
|
---|
734 | $val = $this->ConvertToRVB($val, $res);
|
---|
735 | if ($res) $this->value['border']['b']['color'] = $val;
|
---|
736 | break;
|
---|
737 |
|
---|
738 | case 'border-left-color':
|
---|
739 | $res = false;
|
---|
740 | $val = $this->ConvertToRVB($val, $res);
|
---|
741 | if ($res) $this->value['border']['l']['color'] = $val;
|
---|
742 | break;
|
---|
743 |
|
---|
744 | case 'border-width':
|
---|
745 | $val = explode(' ', $val);
|
---|
746 | foreach($val as $val_k => $val_v)
|
---|
747 | {
|
---|
748 | $val[$val_k] = $this->ConvertToMM($val_v, 0);
|
---|
749 | }
|
---|
750 | $this->duplicateBorder($val);
|
---|
751 |
|
---|
752 | if ($val[0]) $this->value['border']['t']['width'] = $val[0];
|
---|
753 | if ($val[1]) $this->value['border']['r']['width'] = $val[1];
|
---|
754 | if ($val[2]) $this->value['border']['b']['width'] = $val[2];
|
---|
755 | if ($val[3]) $this->value['border']['l']['width'] = $val[3];
|
---|
756 | break;
|
---|
757 |
|
---|
758 | case 'border-top-width':
|
---|
759 | $val = $this->ConvertToMM($val, 0);;
|
---|
760 | if ($val) $this->value['border']['t']['width'] = $val;
|
---|
761 | break;
|
---|
762 |
|
---|
763 | case 'border-right-width':
|
---|
764 | $val = $this->ConvertToMM($val, 0);;
|
---|
765 | if ($val) $this->value['border']['r']['width'] = $val;
|
---|
766 | break;
|
---|
767 |
|
---|
768 | case 'border-bottom-width':
|
---|
769 | $val = $this->ConvertToMM($val, 0);;
|
---|
770 | if ($val) $this->value['border']['b']['width'] = $val;
|
---|
771 | break;
|
---|
772 |
|
---|
773 | case 'border-left-width':
|
---|
774 | $val = $this->ConvertToMM($val, 0);;
|
---|
775 | if ($val) $this->value['border']['l']['width'] = $val;
|
---|
776 | break;
|
---|
777 |
|
---|
778 | case 'border-collapse':
|
---|
779 | if ($balise=='table') $this->value['border']['collapse'] = ($val=='collapse');
|
---|
780 | break;
|
---|
781 |
|
---|
782 | case 'border-radius':
|
---|
783 | // nettoyage des valeurs
|
---|
784 | $val = explode(' ', $val);
|
---|
785 | foreach($val as $k => $v)
|
---|
786 | {
|
---|
787 | $v = trim($v);
|
---|
788 | if ($v)
|
---|
789 | {
|
---|
790 | $v = $this->ConvertToMM($v, 0);
|
---|
791 | if ($v) $val[$k] = $v;
|
---|
792 | else unset($val[$k]);
|
---|
793 | }
|
---|
794 | else unset($val[$k]);
|
---|
795 | }
|
---|
796 | $val = array_values($val);
|
---|
797 |
|
---|
798 | if (!isset($val[1]) && isset($val[0])) $val[1] = $val[0];
|
---|
799 | if (count($val)==2)
|
---|
800 | $this->value['border']['radius'] = array($val[0], $val[1]);
|
---|
801 |
|
---|
802 | break;
|
---|
803 |
|
---|
804 | case 'border-top':
|
---|
805 | $this->value['border']['t'] = $this->readBorder($val);
|
---|
806 | break;
|
---|
807 |
|
---|
808 | case 'border-right':
|
---|
809 | $this->value['border']['r'] = $this->readBorder($val);
|
---|
810 | break;
|
---|
811 |
|
---|
812 | case 'border-bottom':
|
---|
813 | $this->value['border']['b'] = $this->readBorder($val);
|
---|
814 | break;
|
---|
815 |
|
---|
816 | case 'border-left':
|
---|
817 | $this->value['border']['l'] = $this->readBorder($val);
|
---|
818 | break;
|
---|
819 |
|
---|
820 | case 'background-color':
|
---|
821 | $this->value['background']['color'] = $this->ConvertBackgroundColor($val);
|
---|
822 | break;
|
---|
823 |
|
---|
824 | case 'background-image':
|
---|
825 | $this->value['background']['image'] = $this->ConvertBackgroundImage($val);
|
---|
826 | break;
|
---|
827 |
|
---|
828 | case 'background-position':
|
---|
829 | $res = null;
|
---|
830 | $this->value['background']['position'] = $this->ConvertBackgroundPosition($val, $res);
|
---|
831 | break;
|
---|
832 |
|
---|
833 | case 'background-repeat':
|
---|
834 | $this->value['background']['repeat'] = $this->ConvertBackgroundRepeat($val);
|
---|
835 | break;
|
---|
836 |
|
---|
837 | case 'background':
|
---|
838 | $this->ConvertBackground($val, $this->value['background']);
|
---|
839 | break;
|
---|
840 |
|
---|
841 | case 'position':
|
---|
842 | if ($val=='absolute') $this->value['position'] = 'absolute';
|
---|
843 | else if ($val=='relative') $this->value['position'] = 'relative';
|
---|
844 | else $this->value['position'] = null;
|
---|
845 | break;
|
---|
846 |
|
---|
847 | case 'float':
|
---|
848 | if ($val=='left') $this->value['float'] = 'left';
|
---|
849 | else if ($val=='right') $this->value['float'] = 'right';
|
---|
850 | else $this->value['float'] = null;
|
---|
851 | break;
|
---|
852 |
|
---|
853 | case 'display':
|
---|
854 | if ($val=='inline') $this->value['display'] = 'inline';
|
---|
855 | else if ($val=='block') $this->value['display'] = 'block';
|
---|
856 | else if ($val=='none') $this->value['display'] = 'none';
|
---|
857 | else $this->value['display'] = null;
|
---|
858 | break;
|
---|
859 |
|
---|
860 | case 'top':
|
---|
861 | case 'bottom':
|
---|
862 | case 'left':
|
---|
863 | case 'right':
|
---|
864 | $this->value[$nom] = $val;
|
---|
865 | break;
|
---|
866 |
|
---|
867 | case 'list-style':
|
---|
868 | case 'list-style-type':
|
---|
869 | case 'list-style-image':
|
---|
870 | if ($nom=='list-style') $nom = 'list-style-type';
|
---|
871 | $this->value[$nom] = $val;
|
---|
872 | break;
|
---|
873 |
|
---|
874 | default:
|
---|
875 | break;
|
---|
876 | }
|
---|
877 | }
|
---|
878 |
|
---|
879 | // correction de la largeur pour correspondre au modèle de boite quick
|
---|
880 | if ($correct_width)
|
---|
881 | {
|
---|
882 | if (!in_array($balise, array('table', 'div', 'hr')))
|
---|
883 | {
|
---|
884 | $this->value['width']-= $this->value['padding']['l'] + $this->value['padding']['r'];
|
---|
885 | $this->value['width']-= $this->value['border']['l']['width'] + $this->value['border']['r']['width'];
|
---|
886 | }
|
---|
887 | if (in_array($balise, array('th', 'td')))
|
---|
888 | {
|
---|
889 | $this->value['width']-= $this->ConvertToMM(isset($param['cellspacing']) ? $param['cellspacing'] : '2px');
|
---|
890 | }
|
---|
891 | if ($this->value['width']<0) $this->value['width']=0;
|
---|
892 | }
|
---|
893 | else
|
---|
894 | {
|
---|
895 | if ($this->value['width'])
|
---|
896 | {
|
---|
897 | if ($this->value['border']['l']['width']) $this->value['width'] += $this->value['border']['l']['width'];
|
---|
898 | if ($this->value['border']['r']['width']) $this->value['width'] += $this->value['border']['r']['width'];
|
---|
899 | if ($this->value['padding']['l']) $this->value['width'] += $this->value['padding']['l'];
|
---|
900 | if ($this->value['padding']['r']) $this->value['width'] += $this->value['padding']['r'];
|
---|
901 | }
|
---|
902 | }
|
---|
903 | if ($this->value['height'])
|
---|
904 | {
|
---|
905 | if ($this->value['border']['b']['width']) { $this->value['height'] += $this->value['border']['b']['width']; }
|
---|
906 | if ($this->value['border']['t']['width']) { $this->value['height'] += $this->value['border']['t']['width']; }
|
---|
907 | if ($this->value['padding']['b']) $this->value['height'] += $this->value['padding']['b'];
|
---|
908 | if ($this->value['padding']['t']) $this->value['height'] += $this->value['padding']['t'];
|
---|
909 | }
|
---|
910 |
|
---|
911 | if ($this->value['top']!=null) $this->value['top'] = $this->ConvertToMM($this->value['top'], $this->getLastHeight(true));
|
---|
912 | if ($this->value['bottom']!=null) $this->value['bottom'] = $this->ConvertToMM($this->value['bottom'], $this->getLastHeight(true));
|
---|
913 | if ($this->value['left']!=null) $this->value['left'] = $this->ConvertToMM($this->value['left'], $this->getLastWidth(true));
|
---|
914 | if ($this->value['right']!=null) $this->value['right'] = $this->ConvertToMM($this->value['right'], $this->getLastWidth(true));
|
---|
915 |
|
---|
916 | if ($this->value['top'] && $this->value['bottom'] && $this->value['height']) $this->value['bottom'] = null;
|
---|
917 | if ($this->value['left'] && $this->value['right'] && $this->value['width']) $this->value['right'] = null;
|
---|
918 | }
|
---|
919 |
|
---|
920 | /**
|
---|
921 | * Récupération de la hauteur de ligne courante
|
---|
922 | *
|
---|
923 | * @return float hauteur en mm
|
---|
924 | */
|
---|
925 | function getLineHeight()
|
---|
926 | {
|
---|
927 | $val = $this->value['line-height'];
|
---|
928 | if ($val=='normal') $val = '108%';
|
---|
929 | return $this->ConvertToMM($val, $this->value['font-size']);
|
---|
930 | }
|
---|
931 |
|
---|
932 | /**
|
---|
933 | * Récupération de la largeur de l'objet parent
|
---|
934 | *
|
---|
935 | * @return float largeur
|
---|
936 | */
|
---|
937 | function getLastWidth($mode = false)
|
---|
938 | {
|
---|
939 | for($k=count($this->table); $k>0; $k--)
|
---|
940 | {
|
---|
941 | if ($this->table[$k-1]['width'])
|
---|
942 | {
|
---|
943 | $w = $this->table[$k-1]['width'];
|
---|
944 | if ($mode)
|
---|
945 | {
|
---|
946 | $w+= $this->table[$k-1]['border']['l']['width'] + $this->table[$k-1]['padding']['l']+0.02;
|
---|
947 | $w+= $this->table[$k-1]['border']['r']['width'] + $this->table[$k-1]['padding']['r']+0.02;
|
---|
948 | }
|
---|
949 | return $w;
|
---|
950 | }
|
---|
951 | }
|
---|
952 | return $this->pdf->w - $this->pdf->lMargin - $this->pdf->rMargin;
|
---|
953 | }
|
---|
954 |
|
---|
955 | /**
|
---|
956 | * Récupération de la hauteur de l'objet parent
|
---|
957 | *
|
---|
958 | * @return float hauteur
|
---|
959 | */
|
---|
960 | function getLastHeight($mode = false)
|
---|
961 | {
|
---|
962 | for($k=count($this->table); $k>0; $k--)
|
---|
963 | {
|
---|
964 | if ($this->table[$k-1]['height'])
|
---|
965 | {
|
---|
966 | $h = $this->table[$k-1]['height'];
|
---|
967 | if ($mode)
|
---|
968 | {
|
---|
969 | $h+= $this->table[$k-1]['border']['t']['width'] + $this->table[$k-1]['padding']['t']+0.02;
|
---|
970 | $h+= $this->table[$k-1]['border']['b']['width'] + $this->table[$k-1]['padding']['b']+0.02;
|
---|
971 | }
|
---|
972 | return $h;
|
---|
973 | }
|
---|
974 | }
|
---|
975 | return $this->pdf->h - $this->pdf->tMargin - $this->pdf->bMargin;
|
---|
976 | }
|
---|
977 |
|
---|
978 | function getFloat()
|
---|
979 | {
|
---|
980 | if ($this->value['float']=='left') return 'left';
|
---|
981 | if ($this->value['float']=='right') return 'right';
|
---|
982 | return null;
|
---|
983 | }
|
---|
984 |
|
---|
985 | function getLastAbsoluteX()
|
---|
986 | {
|
---|
987 | for($k=count($this->table); $k>0; $k--)
|
---|
988 | {
|
---|
989 | if ($this->table[$k-1]['x'] && $this->table[$k-1]['position']) return $this->table[$k-1]['x'];
|
---|
990 | }
|
---|
991 | return $this->pdf->lMargin;
|
---|
992 | }
|
---|
993 |
|
---|
994 | function getLastAbsoluteY()
|
---|
995 | {
|
---|
996 | for($k=count($this->table); $k>0; $k--)
|
---|
997 | {
|
---|
998 | if ($this->table[$k-1]['y'] && $this->table[$k-1]['position']) return $this->table[$k-1]['y'];
|
---|
999 | }
|
---|
1000 | return $this->pdf->tMargin;
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | /**
|
---|
1004 | * Récupération des propriétés CSS de la balise en cours
|
---|
1005 | *
|
---|
1006 | * @return array() tableau des propriétés CSS
|
---|
1007 | */
|
---|
1008 | function getFromCSS()
|
---|
1009 | {
|
---|
1010 | $styles = array(); // style à appliquer
|
---|
1011 | $getit = array(); // styles à récuperer
|
---|
1012 |
|
---|
1013 | // identification des styles direct, et ceux des parents
|
---|
1014 | $lst = array();
|
---|
1015 | $lst[] = $this->value['id_lst'];
|
---|
1016 | for($i=count($this->table)-1; $i>=0; $i--) $lst[] = $this->table[$i]['id_lst'];
|
---|
1017 |
|
---|
1018 | // identification des styles à récuperer
|
---|
1019 | foreach($this->css_keys as $key => $num)
|
---|
1020 | if ($this->getReccursiveStyle($key, $lst))
|
---|
1021 | $getit[$key] = $num;
|
---|
1022 |
|
---|
1023 | // si des styles sont à recuperer
|
---|
1024 | if (count($getit))
|
---|
1025 | {
|
---|
1026 | // on les récupère, mais dans l'odre de définition, afin de garder les priorités
|
---|
1027 | asort($getit);
|
---|
1028 | foreach($getit as $key => $val) $styles = array_merge($styles, $this->css[$key]);
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | return $styles;
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | /**
|
---|
1035 | * Identification des styles à récuperer, en fonction de la balise et de ses parents
|
---|
1036 | *
|
---|
1037 | * @param string clef CSS à analyser
|
---|
1038 | * @param array() tableau des styles direct, et ceux des parents
|
---|
1039 | * @param string prochaine etape
|
---|
1040 | * @return boolean clef autorisée ou non
|
---|
1041 | */
|
---|
1042 | function getReccursiveStyle($key, $lst, $next = null)
|
---|
1043 | {
|
---|
1044 | // si propchaine etape, on construit les valeurs
|
---|
1045 | if ($next!==null)
|
---|
1046 | {
|
---|
1047 | if ($next) $key = trim(substr($key, 0, -strlen($next))); // on elève cette etape
|
---|
1048 | unset($lst[0]);
|
---|
1049 | if (!count($lst)) return false; // pas d'etape possible
|
---|
1050 | $lst = array_values($lst);
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | // pour chaque style direct possible de l'etape en cours
|
---|
1054 | foreach($lst[0] as $nom)
|
---|
1055 | {
|
---|
1056 | if ($key==$nom) return true; // si la clef conrrespond => ok
|
---|
1057 | if (substr($key, -strlen(' '.$nom))==' '.$nom && $this->getReccursiveStyle($key, $lst, $nom)) return true; // si la clef est la fin, on analyse ce qui précède
|
---|
1058 | }
|
---|
1059 |
|
---|
1060 | // si on est pas à la premiere etape, on doit analyse toutes les sous etapes
|
---|
1061 | if ($next!==null && $this->getReccursiveStyle($key, $lst, '')) return true;
|
---|
1062 |
|
---|
1063 | // aucun style trouvé
|
---|
1064 | return false;
|
---|
1065 | }
|
---|
1066 |
|
---|
1067 | /**
|
---|
1068 | * Analyse d'une propriété Border
|
---|
1069 | *
|
---|
1070 | * @param string propriété border
|
---|
1071 | * @return array() propriété décodée
|
---|
1072 | */
|
---|
1073 | function readBorder($val)
|
---|
1074 | {
|
---|
1075 | $none = array('type' => 'none', 'width' => 0, 'color' => array(0, 0, 0));
|
---|
1076 |
|
---|
1077 | // valeurs par défault
|
---|
1078 | $type = 'solid';
|
---|
1079 | $width = $this->ConvertToMM('1pt');
|
---|
1080 | $color = array(0, 0, 0);
|
---|
1081 |
|
---|
1082 | // nettoyage des valeurs
|
---|
1083 | $val = explode(' ', $val);
|
---|
1084 | foreach($val as $k => $v)
|
---|
1085 | {
|
---|
1086 | $v = trim($v);
|
---|
1087 | if ($v) $val[$k] = $v;
|
---|
1088 | else unset($val[$k]);
|
---|
1089 | }
|
---|
1090 | $val = array_values($val);
|
---|
1091 | // identification des valeurs
|
---|
1092 | $res = null;
|
---|
1093 | foreach($val as $key)
|
---|
1094 | {
|
---|
1095 | if ($key=='none' || $key=='hidden') return $none;
|
---|
1096 |
|
---|
1097 | if ($this->ConvertToMM($key)!==null) $width = $this->ConvertToMM($key);
|
---|
1098 | else if (in_array($key, array('solid', 'dotted', 'dashed'))) $type = $key;
|
---|
1099 | else
|
---|
1100 | {
|
---|
1101 | $tmp = $this->ConvertToRVB($key, $res);
|
---|
1102 | if ($res) $color = $tmp;
|
---|
1103 | }
|
---|
1104 | }
|
---|
1105 | if (!$width) return $none;
|
---|
1106 | return array('type' => $type, 'width' => $width, 'color' => $color);
|
---|
1107 | }
|
---|
1108 |
|
---|
1109 | function duplicateBorder(&$val)
|
---|
1110 | {
|
---|
1111 | if (count($val)==1)
|
---|
1112 | {
|
---|
1113 | $val[1] = $val[0];
|
---|
1114 | $val[2] = $val[0];
|
---|
1115 | $val[3] = $val[0];
|
---|
1116 | }
|
---|
1117 | else if (count($val)==2)
|
---|
1118 | {
|
---|
1119 | $val[2] = $val[0];
|
---|
1120 | $val[3] = $val[1];
|
---|
1121 | }
|
---|
1122 | else if (count($val)==3)
|
---|
1123 | {
|
---|
1124 | $val[3] = $val[1];
|
---|
1125 | }
|
---|
1126 | }
|
---|
1127 |
|
---|
1128 | function ConvertBackground($stl, &$res)
|
---|
1129 | {
|
---|
1130 | // Image
|
---|
1131 | $text = '/url\(([^)]*)\)/isU';
|
---|
1132 | if (preg_match($text, $stl, $match))
|
---|
1133 | {
|
---|
1134 | $res['image'] = $this->ConvertBackgroundImage($match[0]);
|
---|
1135 | $stl = preg_replace($text, '', $stl);
|
---|
1136 | $stl = preg_replace('/[\s]+/', ' ', $stl);
|
---|
1137 | }
|
---|
1138 |
|
---|
1139 | // protection des espaces
|
---|
1140 | $stl = preg_replace('/,[\s]+/', ',', $stl);
|
---|
1141 | $lst = explode(' ', $stl);
|
---|
1142 |
|
---|
1143 | $pos = '';
|
---|
1144 | foreach($lst as $val)
|
---|
1145 | {
|
---|
1146 | $ok = false;
|
---|
1147 | $color = $this->ConvertToRVB($val, $ok);
|
---|
1148 |
|
---|
1149 | if ($ok)
|
---|
1150 | {
|
---|
1151 | $res['color'] = $color;
|
---|
1152 | }
|
---|
1153 | else if ($val=='transparent')
|
---|
1154 | {
|
---|
1155 | $res['color'] = null;
|
---|
1156 | }
|
---|
1157 | else
|
---|
1158 | {
|
---|
1159 | $repeat = $this->ConvertBackgroundRepeat($val);
|
---|
1160 | if ($repeat)
|
---|
1161 | {
|
---|
1162 | $res['repeat'] = $repeat;
|
---|
1163 | }
|
---|
1164 | else
|
---|
1165 | {
|
---|
1166 | $pos.= ($pos ? ' ' : '').$val;
|
---|
1167 | }
|
---|
1168 | }
|
---|
1169 | }
|
---|
1170 | if ($pos)
|
---|
1171 | {
|
---|
1172 | $pos = $this->ConvertBackgroundPosition($pos, $ok);
|
---|
1173 | if ($ok) $res['position'] = $pos;
|
---|
1174 | }
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | function ConvertBackgroundColor($val)
|
---|
1178 | {
|
---|
1179 | $res = null;
|
---|
1180 | if ($val=='transparent') return null;
|
---|
1181 | else return $this->ConvertToRVB($val, $res);
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | function ConvertBackgroundImage($val)
|
---|
1185 | {
|
---|
1186 | if ($val=='none')
|
---|
1187 | return null;
|
---|
1188 | else if (preg_match('/^url\(([^)]*)\)$/isU', $val, $match))
|
---|
1189 | return $match[1];
|
---|
1190 | else
|
---|
1191 | return null;
|
---|
1192 | }
|
---|
1193 |
|
---|
1194 | function ConvertBackgroundPosition($val, &$res)
|
---|
1195 | {
|
---|
1196 | $val = explode(' ', $val);
|
---|
1197 | if (count($val)<2)
|
---|
1198 | {
|
---|
1199 | if (!$val[0]) return null;
|
---|
1200 | $val[1] = 'center';
|
---|
1201 | }
|
---|
1202 | if (count($val)>2) return null;
|
---|
1203 |
|
---|
1204 | $x = 0;
|
---|
1205 | $y = 0;
|
---|
1206 | $res = true;
|
---|
1207 |
|
---|
1208 | if ($val[0]=='left') $x = '0%';
|
---|
1209 | else if ($val[0]=='center') $x = '50%';
|
---|
1210 | else if ($val[0]=='right') $x = '100%';
|
---|
1211 | else if ($val[0]=='top') $y = '0%';
|
---|
1212 | else if ($val[0]=='bottom') $y = '100%';
|
---|
1213 | else if (preg_match('/^[-]?[0-9\.]+%$/isU', $val[0])) $x = $val[0];
|
---|
1214 | else if ($this->ConvertToMM($val[0])) $x = $this->ConvertToMM($val[0]);
|
---|
1215 | else $res = false;
|
---|
1216 |
|
---|
1217 | if ($val[1]=='left') $x = '0%';
|
---|
1218 | else if ($val[1]=='right') $x = '100%';
|
---|
1219 | else if ($val[1]=='top') $y = '0%';
|
---|
1220 | else if ($val[1]=='center') $y = '50%';
|
---|
1221 | else if ($val[1]=='bottom') $y = '100%';
|
---|
1222 | else if (preg_match('/^[-]?[0-9\.]+%$/isU', $val[1])) $y = $val[1];
|
---|
1223 | else if ($this->ConvertToMM($val[1])) $y = $this->ConvertToMM($val[1]);
|
---|
1224 | else $res = false;
|
---|
1225 |
|
---|
1226 | $val[0] = $x;
|
---|
1227 | $val[1] = $y;
|
---|
1228 |
|
---|
1229 | return $val;
|
---|
1230 | }
|
---|
1231 |
|
---|
1232 | function ConvertBackgroundRepeat($val)
|
---|
1233 | {
|
---|
1234 | switch($val)
|
---|
1235 | {
|
---|
1236 | case 'repeat':
|
---|
1237 | return array(true, true);
|
---|
1238 | case 'repeat-x':
|
---|
1239 | return array(true, false);
|
---|
1240 | case 'repeat-y':
|
---|
1241 | return array(false, true);
|
---|
1242 | case 'no-repeat':
|
---|
1243 | return array(false, false);
|
---|
1244 | }
|
---|
1245 | return null;
|
---|
1246 | }
|
---|
1247 | /**
|
---|
1248 | * Convertir une longueur en mm
|
---|
1249 | *
|
---|
1250 | * @param string longueur, avec unité, à convertir
|
---|
1251 | * @param float longueur du parent
|
---|
1252 | * @return float longueur exprimée en mm
|
---|
1253 | */
|
---|
1254 | function ConvertToMM($val, $old=0.)
|
---|
1255 | {
|
---|
1256 | $val = trim($val);
|
---|
1257 | if (preg_match('/^[0-9\.\-]+$/isU', $val)) $val.= 'px';
|
---|
1258 | if (preg_match('/^[0-9\.\-]+px$/isU', $val)) $val = 25.4/96. * str_replace('px', '', $val);
|
---|
1259 | else if (preg_match('/^[0-9\.\-]+pt$/isU', $val)) $val = 25.4/72. * str_replace('pt', '', $val);
|
---|
1260 | else if (preg_match('/^[0-9\.\-]+in$/isU', $val)) $val = 25.4 * str_replace('in', '', $val);
|
---|
1261 | else if (preg_match('/^[0-9\.\-]+mm$/isU', $val)) $val = 1.*str_replace('mm', '', $val);
|
---|
1262 | else if (preg_match('/^[0-9\.\-]+%$/isU', $val)) $val = 1.*$old*str_replace('%', '', $val)/100.;
|
---|
1263 | else $val = null;
|
---|
1264 |
|
---|
1265 | return $val;
|
---|
1266 | }
|
---|
1267 |
|
---|
1268 | /**
|
---|
1269 | * Décomposition d'un code couleur HTML
|
---|
1270 | *
|
---|
1271 | * @param string couleur au format CSS
|
---|
1272 | * @return array(r, v, b) couleur exprimé par ses comporantes R, V, B, de 0 à 255.
|
---|
1273 | */
|
---|
1274 | function ConvertToRVB($val, &$res)
|
---|
1275 | {
|
---|
1276 | $val = trim($val);
|
---|
1277 | $res = true;
|
---|
1278 |
|
---|
1279 | if (strtolower($val)=='transparent') return array(null, null, null);
|
---|
1280 | if (isset($this->htmlColor[strtolower($val)])) $val = $this->htmlColor[strtolower($val)];
|
---|
1281 |
|
---|
1282 | if (preg_match('/rgb\([\s]*([0-9%]+)[\s]*,[\s]*([0-9%]+)[\s]*,[\s]*([0-9%]+)[\s]*\)/isU', $val, $match))
|
---|
1283 | {
|
---|
1284 | $r =$match[1]; if (substr($r, -1)=='%') $r = floor(255*substr($r, 0, -1)/100);
|
---|
1285 | $v =$match[2]; if (substr($v, -1)=='%') $v = floor(255*substr($v, 0, -1)/100);
|
---|
1286 | $b =$match[3]; if (substr($b, -1)=='%') $b = floor(255*substr($b, 0, -1)/100);
|
---|
1287 | }
|
---|
1288 | else if (strlen($val)==7 && substr($val, 0, 1)=='#')
|
---|
1289 | {
|
---|
1290 | $r = hexdec(substr($val, 1, 2));
|
---|
1291 | $v = hexdec(substr($val, 3, 2));
|
---|
1292 | $b = hexdec(substr($val, 5, 2));
|
---|
1293 | }
|
---|
1294 | else if (strlen($val)==4 && substr($val, 0, 1)=='#')
|
---|
1295 | {
|
---|
1296 | $r = hexdec(substr($val, 1, 1).substr($val, 1, 1));
|
---|
1297 | $v = hexdec(substr($val, 2, 1).substr($val, 2, 1));
|
---|
1298 | $b = hexdec(substr($val, 3, 1).substr($val, 3, 1));
|
---|
1299 | }
|
---|
1300 | else
|
---|
1301 | {
|
---|
1302 | $r=0;
|
---|
1303 | $v=0;
|
---|
1304 | $b=0;
|
---|
1305 | $res = false;
|
---|
1306 | }
|
---|
1307 | return array(floor($r), floor($v), floor($b));
|
---|
1308 | }
|
---|
1309 |
|
---|
1310 | /**
|
---|
1311 | * Analyser une feuille de style
|
---|
1312 | *
|
---|
1313 | * @param string code CSS
|
---|
1314 | * @return null
|
---|
1315 | */
|
---|
1316 | function analyseStyle(&$code)
|
---|
1317 | {
|
---|
1318 | // on remplace tous les espaces, tab, \r, \n, par des espaces uniques
|
---|
1319 | $code = preg_replace('/[\s]+/', ' ', $code);
|
---|
1320 |
|
---|
1321 | // on enlève les commentaires
|
---|
1322 | $code = preg_replace('/\/\*.*?\*\//s', '', $code);
|
---|
1323 |
|
---|
1324 | // on analyse chaque style
|
---|
1325 | preg_match_all('/([^{}]+){([^}]*)}/isU', $code, $match);
|
---|
1326 | for($k=0; $k<count($match[0]); $k++)
|
---|
1327 | {
|
---|
1328 | // noms
|
---|
1329 | $noms = strtolower(trim($match[1][$k]));
|
---|
1330 |
|
---|
1331 | // style, séparé par des; => on remplie le tableau correspondant
|
---|
1332 | $styles = trim($match[2][$k]);
|
---|
1333 | $styles = explode(';', $styles);
|
---|
1334 | $stl = array();
|
---|
1335 | foreach($styles as $style)
|
---|
1336 | {
|
---|
1337 | $tmp = explode(':', $style);
|
---|
1338 | if (count($tmp)>1)
|
---|
1339 | {
|
---|
1340 | $cod = $tmp[0]; unset($tmp[0]); $tmp = implode(':', $tmp);
|
---|
1341 | $stl[trim(strtolower($cod))] = trim($tmp);
|
---|
1342 | }
|
---|
1343 | }
|
---|
1344 |
|
---|
1345 | // décomposition des noms par les ,
|
---|
1346 | $noms = explode(',', $noms);
|
---|
1347 | foreach($noms as $nom)
|
---|
1348 | {
|
---|
1349 | $nom = trim($nom);
|
---|
1350 | // Si il a une fonction spécifique, comme :hover => on zap
|
---|
1351 | if (strpos($nom, ':')!==false) continue;
|
---|
1352 | if (!isset($this->css[$nom]))
|
---|
1353 | $this->css[$nom] = $stl;
|
---|
1354 | else
|
---|
1355 | $this->css[$nom] = array_merge($this->css[$nom], $stl);
|
---|
1356 |
|
---|
1357 | }
|
---|
1358 | }
|
---|
1359 |
|
---|
1360 | $this->css_keys = array_flip(array_keys($this->css));
|
---|
1361 | }
|
---|
1362 |
|
---|
1363 | /**
|
---|
1364 | * Extraction des feuille de style du code HTML
|
---|
1365 | *
|
---|
1366 | * @param string code HTML
|
---|
1367 | * @return null
|
---|
1368 | */
|
---|
1369 | function readStyle(&$html)
|
---|
1370 | {
|
---|
1371 | $style = ' ';
|
---|
1372 |
|
---|
1373 | // extraction des balises link, et suppression de celles-ci dans le code HTML
|
---|
1374 | preg_match_all('/<link([^>]*)>/isU', $html, $match);
|
---|
1375 | $html = preg_replace('/<link[^>]*>/isU', '', $html);
|
---|
1376 | $html = preg_replace('/<\/link[^>]*>/isU', '', $html);
|
---|
1377 |
|
---|
1378 | // analyse de chaque balise
|
---|
1379 | foreach($match[1] as $code)
|
---|
1380 | {
|
---|
1381 | $tmp = array();
|
---|
1382 | // lecture des paramétres du type nom=valeur
|
---|
1383 | $prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)';
|
---|
1384 | preg_match_all('/'.$prop.'/is', $code, $match);
|
---|
1385 | for($k=0; $k<count($match[0]); $k++)
|
---|
1386 | $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]);
|
---|
1387 |
|
---|
1388 | // lecture des paramétres du type nom="valeur"
|
---|
1389 | $prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]';
|
---|
1390 | preg_match_all('/'.$prop.'/is', $code, $match);
|
---|
1391 | for($k=0; $k<count($match[0]); $k++)
|
---|
1392 | $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]);
|
---|
1393 |
|
---|
1394 | // lecture des paramétres du type nom='valeur'
|
---|
1395 | $prop = "([a-zA-Z0-9_]+)=[']([^']*)[']";
|
---|
1396 | preg_match_all('/'.$prop.'/is', $code, $match);
|
---|
1397 | for($k=0; $k<count($match[0]); $k++)
|
---|
1398 | $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]);
|
---|
1399 |
|
---|
1400 | // si de type text/css => on garde
|
---|
1401 | if (isset($tmp['type']) && strtolower($tmp['type'])=='text/css' && isset($tmp['href']))
|
---|
1402 | {
|
---|
1403 | $content = @file_get_contents($tmp['href']);
|
---|
1404 | $url = $tmp['href'];
|
---|
1405 | if (strpos($url, 'http://')!==false)
|
---|
1406 | {
|
---|
1407 | $url = str_replace('http://', '', $url);
|
---|
1408 | $url = explode('/', $url);
|
---|
1409 | $url_main = 'http://'.$url[0].'/';
|
---|
1410 | $url_self = $url; unset($url_self[count($url_self)-1]); $url_self = 'http://'.implode('/', $url_self).'/';
|
---|
1411 |
|
---|
1412 | $content = preg_replace('/url\(([^\\\\][^)]*)\)/isU', 'url('.$url_self.'$1)', $content);
|
---|
1413 | $content = preg_replace('/url\((\\\\[^)]*)\)/isU', 'url('.$url_main.'$1)', $content);
|
---|
1414 | }
|
---|
1415 |
|
---|
1416 | $style.= $content."\n";
|
---|
1417 | }
|
---|
1418 | }
|
---|
1419 |
|
---|
1420 |
|
---|
1421 | // extraction des balises style, et suppression de celles-ci dans le code HTML
|
---|
1422 | preg_match_all('/<style[^>]*>(.*)<\/style[^>]*>/isU', $html, $match);
|
---|
1423 | $html = preg_replace('/<style[^>]*>(.*)<\/style[^>]*>/isU', '', $html);
|
---|
1424 |
|
---|
1425 | // analyse de chaque balise
|
---|
1426 | foreach($match[1] as $code)
|
---|
1427 | {
|
---|
1428 | $code = str_replace('<!--', '', $code);
|
---|
1429 | $code = str_replace('-->', '', $code);
|
---|
1430 | $style.= $code."\n";
|
---|
1431 | }
|
---|
1432 |
|
---|
1433 | $this->analyseStyle($style);
|
---|
1434 | }
|
---|
1435 | }
|
---|
1436 | }
|
---|
1437 | ?>
|
---|