source: trunk/client/inc/hpdf/_mypdf/mypdf.class.php@ 2

Last change on this file since 2 was 2, checked in by root, 15 years ago

importo il progetto

File size: 15.1 KB
RevLine 
[2]1<?php
2/**
3 * Logiciel : HTML2PDF - classe MyPDF
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
12if (!defined('__CLASS_MYPDF__'))
13{
14 define('__CLASS_MYPDF__', true);
15
16 require_once(dirname(__FILE__).'/99_fpdf_protection.class.php'); // classe fpdf_protection
17
18 class MyPDF extends FPDF_Protection
19 {
20 var $footer_param = array();
21
22 var $underline = false;
23 var $overline = false;
24 var $linethrough = false;
25
26 function MyPDF($sens = 'P', $unit = 'mm', $format = 'A4')
27 {
28 $this->underline = false;
29 $this->overline = false;
30 $this->linethrough = false;
31
32 $this->FPDF_Protection($sens, $unit, $format);
33 $this->AliasNbPages();
34 $this->SetMyFooter();
35 }
36
37 function SetMyFooter($page = null, $date = null, $heure = null, $form = null)
38 {
39 if ($page===null) $page = null;
40 if ($date===null) $date = null;
41 if ($heure===null) $heure = null;
42 if ($form===null) $form = null;
43
44 $this->footer_param = array('page' => $page, 'date' => $date, 'heure' => $heure, 'form' => $form);
45 }
46
47 function Footer()
48 {
49 $txt = '';
50 if ($this->footer_param['form']) $txt = (HTML2PDF::textGET('pdf05'));
51 if ($this->footer_param['date'] && $this->footer_param['heure']) $txt.= ($txt ? ' - ' : '').(HTML2PDF::textGET('pdf03'));
52 if ($this->footer_param['date'] && !$this->footer_param['heure']) $txt.= ($txt ? ' - ' : '').(HTML2PDF::textGET('pdf01'));
53 if (!$this->footer_param['date'] && $this->footer_param['heure']) $txt.= ($txt ? ' - ' : '').(HTML2PDF::textGET('pdf02'));
54 if ($this->footer_param['page']) $txt.= ($txt ? ' - ' : '').(HTML2PDF::textGET('pdf04'));
55
56 $txt = str_replace('[[date_d]]', date('d'), $txt);
57 $txt = str_replace('[[date_m]]', date('m'), $txt);
58 $txt = str_replace('[[date_y]]', date('Y'), $txt);
59 $txt = str_replace('[[date_h]]', date('H'), $txt);
60 $txt = str_replace('[[date_i]]', date('i'), $txt);
61 $txt = str_replace('[[date_s]]', date('s'), $txt);
62 $txt = str_replace('[[current]]', $this->PageNo(), $txt);
63 $txt = str_replace('[[nb]]', '{nb}', $txt);
64
65 if (strlen($txt)>0)
66 {
67 $this->SetY(-11);
68 $this->setOverline(false);
69 $this->setLinethrough(false);
70 $this->SetFont('Arial','I',8);
71 $this->Cell(0, 10, $txt, 0, 0, 'R');
72 }
73 }
74
75 // redéfinition de la fonction Image de FPDF afin de rajouter la gestion des fichiers PHP
76 function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='')
77 {
78 //Put an image on the page
79 if(!isset($this->images[$file]))
80 {
81 //First use of this image, get info
82 if($type=='')
83 {
84 /* MODIFICATION HTML2PDF pour le support des images PHP */
85 $type = explode('?', $file);
86 $type = pathinfo($type[0]);
87 if (!isset($type['extension']) || !$type['extension'])
88 $this->Error('Image file has no extension and no type was specified: '.$file);
89
90 $type = $type['extension'];
91 /* FIN MODIFICATION */
92 }
93
94 $type=strtolower($type);
95
96 /* MODIFICATION HTML2PDF pour le support des images PHP */
97 if ($type=='php')
98 {
99 // identification des infos
100 $infos=@GetImageSize($file);
101 if (!$infos) $this->Error('Unsupported image : '.$file);
102
103 // identification du type
104 $type = explode('/', $infos['mime']);
105 if ($type[0]!='image') $this->Error('Unsupported image : '.$file);
106 $type = $type[1];
107 }
108 /* FIN MODIFICATION */
109
110 if($type=='jpeg')
111 $type='jpg';
112 $mtd='_parse'.$type;
113 if(!method_exists($this,$mtd))
114 $this->Error('Unsupported image type: '.$type);
115 $info=$this->$mtd($file);
116 $info['i']=count($this->images)+1;
117 $this->images[$file]=$info;
118 }
119 else
120 $info=$this->images[$file];
121 //Automatic width and height calculation if needed
122 if($w==0 && $h==0)
123 {
124 //Put image at 72 dpi
125 $w=$info['w']/$this->k;
126 $h=$info['h']/$this->k;
127 }
128 elseif($w==0)
129 $w=$h*$info['w']/$info['h'];
130 elseif($h==0)
131 $h=$w*$info['h']/$info['w'];
132 //Flowing mode
133 if($y===null)
134 {
135 if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak())
136 {
137 //Automatic page break
138 $x2=$this->x;
139 $this->AddPage($this->CurOrientation,$this->CurPageFormat);
140 $this->x=$x2;
141 }
142 $y=$this->y;
143 $this->y+=$h;
144 }
145 if($x===null)
146 $x=$this->x;
147
148 $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q',$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i']));
149 if($link)
150 $this->Link($x,$y,$w,$h,$link);
151 }
152
153 // Draw a polygon
154 // Auteur : Andrew Meier
155 // Licence : Freeware
156 function Polygon($points, $style='D')
157 {
158 if($style=='F') $op='f';
159 elseif($style=='FD' or $style=='DF') $op='b';
160 else $op='s';
161
162 $h = $this->h;
163 $k = $this->k;
164
165 $points_string = '';
166 for($i=0; $i<count($points); $i+=2)
167 {
168 $points_string .= sprintf('%.2f %.2f', $points[$i]*$k, ($h-$points[$i+1])*$k);
169 if($i==0) $points_string .= ' m ';
170 else $points_string .= ' l ';
171 }
172 $this->_out($points_string . $op);
173 }
174
175 function setOverline($value = true)
176 {
177 $this->overline = $value;
178 }
179
180 function setLinethrough($value = true)
181 {
182 $this->linethrough = $value;
183 }
184
185 // redéfinition de la methode Text de FPDF afin de rajouter la gestion des overline et linethrough
186 function Text($x, $y, $txt)
187 {
188 //Output a string
189 $s=sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
190
191 /* MODIFICATION HTML2PDF pour le support de underline, overline, linethrough */
192 if ($txt!='')
193 {
194 if($this->underline) $s.=' '.$this->_dounderline($x,$y,$txt);
195 if($this->overline) $s.=' '.$this->_dooverline($x,$y,$txt);
196 if($this->linethrough) $s.=' '.$this->_dolinethrough($x,$y,$txt);
197 }
198 /* FIN MODIFICATION */
199
200 if($this->ColorFlag)
201 $s='q '.$this->TextColor.' '.$s.' Q';
202 $this->_out($s);
203 }
204
205 // redéfinition de la methode Cell de FPDF afin de rajouter la gestion des overline et linethrough
206 function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='')
207 {
208 //Output a cell
209 $k=$this->k;
210 if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak())
211 {
212 //Automatic page break
213 $x=$this->x;
214 $ws=$this->ws;
215 if($ws>0)
216 {
217 $this->ws=0;
218 $this->_out('0 Tw');
219 }
220 $this->AddPage($this->CurOrientation,$this->CurPageFormat);
221 $this->x=$x;
222 if($ws>0)
223 {
224 $this->ws=$ws;
225 $this->_out(sprintf('%.3F Tw',$ws*$k));
226 }
227 }
228 if($w==0)
229 $w=$this->w-$this->rMargin-$this->x;
230 $s='';
231 if($fill || $border==1)
232 {
233 if($fill)
234 $op=($border==1) ? 'B' : 'f';
235 else
236 $op='S';
237 $s=sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);
238 }
239 if(is_string($border))
240 {
241 $x=$this->x;
242 $y=$this->y;
243 if(strpos($border,'L')!==false)
244 $s.=sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
245 if(strpos($border,'T')!==false)
246 $s.=sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
247 if(strpos($border,'R')!==false)
248 $s.=sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
249 if(strpos($border,'B')!==false)
250 $s.=sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
251 }
252 if($txt!=='')
253 {
254 if($align=='R')
255 $dx=$w-$this->cMargin-$this->GetStringWidth($txt);
256 elseif($align=='C')
257 $dx=($w-$this->GetStringWidth($txt))/2;
258 else
259 $dx=$this->cMargin;
260 if($this->ColorFlag)
261 $s.='q '.$this->TextColor.' ';
262 $txt2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt)));
263 $s.=sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt2);
264
265 /* MODIFICATION HTML2PDF pour le support de underline, overline, linethrough */
266 if($this->underline) $s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt);
267 if($this->overline) $s.=' '.$this->_dooverline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt);
268 if($this->linethrough) $s.=' '.$this->_dolinethrough($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt);
269 /* FIN MODIFICATION */
270
271 if($this->ColorFlag)
272 $s.=' Q';
273 if($link)
274 $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link);
275 }
276 if($s)
277 $this->_out($s);
278 $this->lasth=$h;
279 if($ln>0)
280 {
281 //Go to next line
282 $this->y+=$h;
283 if($ln==1)
284 $this->x=$this->lMargin;
285 }
286 else
287 $this->x+=$w;
288 }
289
290 function _dounderline($x, $y, $txt)
291 {
292 //Underline text
293 $up=$this->CurrentFont['up'];
294 $ut=$this->CurrentFont['ut'];
295
296 $p_x = $x*$this->k;
297 $p_y = ($this->h-($y-$up/1000*$this->FontSize))*$this->k;
298 $p_w = ($this->GetStringWidth($txt)+$this->ws*substr_count($txt,' '))*$this->k;
299 $p_h = -$ut/1000*$this->FontSizePt;
300
301 return sprintf('%.2F %.2F %.2F %.2F re f',$p_x,$p_y,$p_w,$p_h);
302 }
303
304 function _dooverline($x, $y, $txt)
305 {
306 //Overline text
307 $up=$this->CurrentFont['up'];
308 $ut=$this->CurrentFont['ut'];
309
310 $p_x = $x*$this->k;
311 $p_y = ($this->h-($y-(1000+1.5*$up)/1000*$this->FontSize))*$this->k;
312 $p_w = ($this->GetStringWidth($txt)+$this->ws*substr_count($txt,' '))*$this->k;
313 $p_h = -$ut/1000*$this->FontSizePt;
314
315 return sprintf('%.2F %.2F %.2F %.2F re f',$p_x,$p_y,$p_w,$p_h);
316 }
317
318 function _dolinethrough($x, $y, $txt)
319 {
320 //Linethrough text
321 $up=$this->CurrentFont['up'];
322 $ut=$this->CurrentFont['ut'];
323
324 $p_x = $x*$this->k;
325 $p_y = ($this->h-($y-(1000+2.5*$up)/2000*$this->FontSize))*$this->k;
326 $p_w = ($this->GetStringWidth($txt)+$this->ws*substr_count($txt,' '))*$this->k;
327 $p_h = -$ut/1000*$this->FontSizePt;
328
329 return sprintf('%.2F %.2F %.2F %.2F re f',$p_x,$p_y,$p_w,$p_h);
330 }
331
332 function clippingPathOpen($x = null, $y = null, $w = null, $h = null, $coin_TL=null, $coin_TR=null, $coin_BL=null, $coin_BR=null)
333 {
334 $path = '';
335 if ($x!==null && $y!==null && $w!==null && $h!==null)
336 {
337 $x1 = $x*$this->k;
338 $y1 = ($this->h-$y)*$this->k;
339
340 $x2 = ($x+$w)*$this->k;
341 $y2 = ($this->h-$y)*$this->k;
342
343 $x3 = ($x+$w)*$this->k;
344 $y3 = ($this->h-$y-$h)*$this->k;
345
346 $x4 = $x*$this->k;
347 $y4 = ($this->h-$y-$h)*$this->k;
348
349 if ($coin_TL || $coin_TR || $coin_BL || $coin_BR)
350 {
351 if ($coin_TL) { $coin_TL[0] = $coin_TL[0]*$this->k; $coin_TL[1] =-$coin_TL[1]*$this->k; }
352 if ($coin_TR) { $coin_TR[0] = $coin_TR[0]*$this->k; $coin_TR[1] =-$coin_TR[1]*$this->k; }
353 if ($coin_BL) { $coin_BL[0] = $coin_BL[0]*$this->k; $coin_BL[1] =-$coin_BL[1]*$this->k; }
354 if ($coin_BR) { $coin_BR[0] = $coin_BR[0]*$this->k; $coin_BR[1] =-$coin_BR[1]*$this->k; }
355
356 $MyArc = 4/3 * (sqrt(2) - 1);
357
358 if ($coin_TL)
359 $path.= sprintf('%.2f %.2f m ', $x1+$coin_TL[0], $y1);
360 else
361 $path.= sprintf('%.2f %.2f m ', $x1, $y1);
362
363 if ($coin_TR)
364 {
365 $xt1 = ($x2-$coin_TR[0])+$coin_TR[0]*$MyArc;
366 $yt1 = ($y2+$coin_TR[1])-$coin_TR[1];
367 $xt2 = ($x2-$coin_TR[0])+$coin_TR[0];
368 $yt2 = ($y2+$coin_TR[1])-$coin_TR[1]*$MyArc;
369
370 $path.= sprintf('%.2f %.2f l ', $x2-$coin_TR[0], $y2);
371 $path.= sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c ', $xt1, $yt1, $xt2, $yt2, $x2, $y2+$coin_TR[1]);
372 }
373 else
374 $path.= sprintf('%.2f %.2f l ', $x2, $y2);
375
376 if ($coin_BR)
377 {
378 $xt1 = ($x3-$coin_BR[0])+$coin_BR[0];
379 $yt1 = ($y3-$coin_BR[1])+$coin_BR[1]*$MyArc;
380 $xt2 = ($x3-$coin_BR[0])+$coin_BR[0]*$MyArc;
381 $yt2 = ($y3-$coin_BR[1])+$coin_BR[1];
382
383 $path.= sprintf('%.2f %.2f l ', $x3, $y3-$coin_BR[1]);
384 $path.= sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c ', $xt1, $yt1, $xt2, $yt2, $x3-$coin_BR[0], $y3);
385 }
386 else
387 $path.= sprintf('%.2f %.2f l ', $x3, $y3);
388
389 if ($coin_BL)
390 {
391 $xt1 = ($x4+$coin_BL[0])-$coin_BL[0]*$MyArc;
392 $yt1 = ($y4-$coin_BL[1])+$coin_BL[1];
393 $xt2 = ($x4+$coin_BL[0])-$coin_BL[0];
394 $yt2 = ($y4-$coin_BL[1])+$coin_BL[1]*$MyArc;
395
396 $path.= sprintf('%.2f %.2f l ', $x4+$coin_BL[0], $y4);
397 $path.= sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c ', $xt1, $yt1, $xt2, $yt2, $x4, $y4-$coin_BL[1]);
398 }
399 else
400 $path.= sprintf('%.2f %.2f l ', $x4, $y4);
401
402 if ($coin_TL)
403 {
404 $xt1 = ($x1+$coin_TL[0])-$coin_TL[0];
405 $yt1 = ($y1+$coin_TL[1])-$coin_TL[1]*$MyArc;
406 $xt2 = ($x1+$coin_TL[0])-$coin_TL[0]*$MyArc;
407 $yt2 = ($y1+$coin_TL[1])-$coin_TL[1];
408
409 $path.= sprintf('%.2f %.2f l ', $x1, $y1+$coin_TL[1]);
410 $path.= sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c ', $xt1, $yt1, $xt2, $yt2, $x1+$coin_TL[0], $y1);
411 }
412 }
413 else
414 {
415 $path.= sprintf('%.2f %.2f m ', $x1, $y1);
416 $path.= sprintf('%.2f %.2f l ', $x2, $y2);
417 $path.= sprintf('%.2f %.2f l ', $x3, $y3);
418 $path.= sprintf('%.2f %.2f l ', $x4, $y4);
419 }
420
421 $path.= ' h W n';
422 }
423 $this->_out('q '.$path.' ');
424 }
425
426 function clippingPathClose()
427 {
428 $this->_out(' Q');
429 }
430
431 function drawCourbe($ext1_x, $ext1_y, $ext2_x, $ext2_y, $int1_x, $int1_y, $int2_x, $int2_y, $cen_x, $cen_y)
432 {
433 $MyArc = 4/3 * (sqrt(2) - 1);
434
435 $ext1_x = $ext1_x*$this->k; $ext1_y = ($this->h-$ext1_y)*$this->k;
436 $ext2_x = $ext2_x*$this->k; $ext2_y = ($this->h-$ext2_y)*$this->k;
437 $int1_x = $int1_x*$this->k; $int1_y = ($this->h-$int1_y)*$this->k;
438 $int2_x = $int2_x*$this->k; $int2_y = ($this->h-$int2_y)*$this->k;
439 $cen_x = $cen_x*$this->k; $cen_y = ($this->h-$cen_y) *$this->k;
440
441 $path = '';
442
443 if ($ext1_x-$cen_x!=0)
444 {
445 $xt1 = $cen_x+($ext1_x-$cen_x);
446 $yt1 = $cen_y+($ext2_y-$cen_y)*$MyArc;
447 $xt2 = $cen_x+($ext1_x-$cen_x)*$MyArc;
448 $yt2 = $cen_y+($ext2_y-$cen_y);
449 }
450 else
451 {
452 $xt1 = $cen_x+($ext2_x-$cen_x)*$MyArc;
453 $yt1 = $cen_y+($ext1_y-$cen_y);
454 $xt2 = $cen_x+($ext2_x-$cen_x);
455 $yt2 = $cen_y+($ext1_y-$cen_y)*$MyArc;
456
457 }
458
459 $path.= sprintf('%.2f %.2f m ', $ext1_x, $ext1_y);
460 $path.= sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c ', $xt1, $yt1, $xt2, $yt2, $ext2_x, $ext2_y);
461
462 if ($int1_x-$cen_x!=0)
463 {
464 $xt1 = $cen_x+($int1_x-$cen_x)*$MyArc;
465 $yt1 = $cen_y+($int2_y-$cen_y);
466 $xt2 = $cen_x+($int1_x-$cen_x);
467 $yt2 = $cen_y+($int2_y-$cen_y)*$MyArc;
468 }
469 else
470 {
471 $xt1 = $cen_x+($int2_x-$cen_x);
472 $yt1 = $cen_y+($int1_y-$cen_y)*$MyArc;
473 $xt2 = $cen_x+($int2_x-$cen_x)*$MyArc;
474 $yt2 = $cen_y+($int1_y-$cen_y);
475
476 }
477
478 $path.= sprintf('%.2f %.2f l ', $int2_x, $int2_y);
479 $path.= sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c ', $xt1, $yt1, $xt2, $yt2, $int1_x, $int1_y);
480
481 $this->_out($path . 'f');
482 }
483 }
484}
485?>
Note: See TracBrowser for help on using the repository browser.