1 | <?php |
---|
2 | /******************************************************************************* |
---|
3 | * Logiciel : FPDF * |
---|
4 | * Version : 1.53 * |
---|
5 | * Date : 31/12/2004 * |
---|
6 | * Auteur : Olivier PLATHEY * |
---|
7 | * Licence : Freeware * |
---|
8 | * * |
---|
9 | * Vous pouvez utiliser et modifier ce logiciel comme vous le souhaitez. * |
---|
10 | *******************************************************************************/ |
---|
11 | |
---|
12 | if(!class_exists('FPDF')) |
---|
13 | { |
---|
14 | define('FPDF_VERSION','1.53'); |
---|
15 | |
---|
16 | class FPDF |
---|
17 | { |
---|
18 | //Private properties |
---|
19 | var $page; //current page number |
---|
20 | var $n; //current object number |
---|
21 | var $offsets; //array of object offsets |
---|
22 | var $buffer; //buffer holding in-memory PDF |
---|
23 | var $pages; //array containing pages |
---|
24 | var $state; //current document state |
---|
25 | var $compress; //compression flag |
---|
26 | var $DefOrientation; //default orientation |
---|
27 | var $CurOrientation; //current orientation |
---|
28 | var $OrientationChanges; //array indicating orientation changes |
---|
29 | var $k; //scale factor (number of points in user unit) |
---|
30 | var $fwPt,$fhPt; //dimensions of page format in points |
---|
31 | var $fw,$fh; //dimensions of page format in user unit |
---|
32 | var $wPt,$hPt; //current dimensions of page in points |
---|
33 | var $w,$h; //current dimensions of page in user unit |
---|
34 | var $lMargin; //left margin |
---|
35 | var $tMargin; //top margin |
---|
36 | var $rMargin; //right margin |
---|
37 | var $bMargin; //page break margin |
---|
38 | var $cMargin; //cell margin |
---|
39 | var $x,$y; //current position in user unit for cell positioning |
---|
40 | var $lasth; //height of last cell printed |
---|
41 | var $LineWidth; //line width in user unit |
---|
42 | var $CoreFonts; //array of standard font names |
---|
43 | var $fonts; //array of used fonts |
---|
44 | var $FontFiles; //array of font files |
---|
45 | var $diffs; //array of encoding differences |
---|
46 | var $images; //array of used images |
---|
47 | var $PageLinks; //array of links in pages |
---|
48 | var $links; //array of internal links |
---|
49 | var $FontFamily; //current font family |
---|
50 | var $FontStyle; //current font style |
---|
51 | var $underline; //underlining flag |
---|
52 | var $CurrentFont; //current font info |
---|
53 | var $FontSizePt; //current font size in points |
---|
54 | var $FontSize; //current font size in user unit |
---|
55 | var $DrawColor; //commands for drawing color |
---|
56 | var $FillColor; //commands for filling color |
---|
57 | var $TextColor; //commands for text color |
---|
58 | var $ColorFlag; //indicates whether fill and text colors are different |
---|
59 | var $ws; //word spacing |
---|
60 | var $AutoPageBreak; //automatic page breaking |
---|
61 | var $PageBreakTrigger; //threshold used to trigger page breaks |
---|
62 | var $InFooter; //flag set when processing footer |
---|
63 | var $ZoomMode; //zoom display mode |
---|
64 | var $LayoutMode; //layout display mode |
---|
65 | var $title; //title |
---|
66 | var $subject; //subject |
---|
67 | var $author; //author |
---|
68 | var $copyright; //copyright |
---|
69 | var $keywords; //keywords |
---|
70 | var $creator; //creator |
---|
71 | var $AliasNbPages; //alias for total number of pages |
---|
72 | var $PDFVersion; //PDF version number |
---|
73 | |
---|
74 | var $maxLineWidth; // ajout CM 24/09/2006 |
---|
75 | var $îmages = array(); |
---|
76 | /******************************************************************************* |
---|
77 | * * |
---|
78 | * Public methods * |
---|
79 | * * |
---|
80 | *******************************************************************************/ |
---|
81 | function FPDF($orientation='P',$unit='mm',$format='A4') |
---|
82 | { |
---|
83 | //Some checks |
---|
84 | $this->_dochecks(); |
---|
85 | //Initialization of properties |
---|
86 | $this->page=0; |
---|
87 | $this->n=2; |
---|
88 | $this->buffer=''; |
---|
89 | $this->pages=array(); |
---|
90 | $this->OrientationChanges=array(); |
---|
91 | $this->state=0; |
---|
92 | $this->fonts=array(); |
---|
93 | $this->FontFiles=array(); |
---|
94 | $this->diffs=array(); |
---|
95 | $this->images=array(); |
---|
96 | $this->links=array(); |
---|
97 | $this->InFooter=false; |
---|
98 | $this->lasth=0; |
---|
99 | $this->FontFamily=''; |
---|
100 | $this->FontStyle=''; |
---|
101 | $this->FontSizePt=12; |
---|
102 | $this->underline=false; |
---|
103 | $this->DrawColor='0 G'; |
---|
104 | $this->FillColor='0 g'; |
---|
105 | $this->TextColor='0 g'; |
---|
106 | $this->ColorFlag=false; |
---|
107 | $this->ws=0; |
---|
108 | //Standard fonts |
---|
109 | $this->CoreFonts=array('courier'=>'Courier','courierB'=>'Courier-Bold','courierI'=>'Courier-Oblique','courierBI'=>'Courier-BoldOblique', |
---|
110 | 'helvetica'=>'Helvetica','helveticaB'=>'Helvetica-Bold','helveticaI'=>'Helvetica-Oblique','helveticaBI'=>'Helvetica-BoldOblique', |
---|
111 | 'times'=>'Times-Roman','timesB'=>'Times-Bold','timesI'=>'Times-Italic','timesBI'=>'Times-BoldItalic', |
---|
112 | 'symbol'=>'Symbol','zapfdingbats'=>'ZapfDingbats'); |
---|
113 | //Scale factor |
---|
114 | if($unit=='pt') |
---|
115 | $this->k=1; |
---|
116 | elseif($unit=='mm') |
---|
117 | $this->k=72/25.4; |
---|
118 | elseif($unit=='cm') |
---|
119 | $this->k=72/2.54; |
---|
120 | elseif($unit=='in') |
---|
121 | $this->k=72; |
---|
122 | else |
---|
123 | $this->Error('Incorrect unit: '.$unit); |
---|
124 | //Page format |
---|
125 | if(is_string($format)) |
---|
126 | { |
---|
127 | $format=strtolower($format); |
---|
128 | if($format=='a3') |
---|
129 | $format=array(841.89,1190.55); |
---|
130 | elseif($format=='a4') |
---|
131 | $format=array(595.28,841.89); |
---|
132 | elseif($format=='a5') |
---|
133 | $format=array(420.94,595.28); |
---|
134 | elseif($format=='letter') |
---|
135 | $format=array(612,792); |
---|
136 | elseif($format=='legal') |
---|
137 | $format=array(612,1008); |
---|
138 | else |
---|
139 | $this->Error('Unknown page format: '.$format); |
---|
140 | $this->fwPt=$format[0]; |
---|
141 | $this->fhPt=$format[1]; |
---|
142 | } |
---|
143 | else |
---|
144 | { |
---|
145 | $this->fwPt=$format[0]*$this->k; |
---|
146 | $this->fhPt=$format[1]*$this->k; |
---|
147 | } |
---|
148 | $this->fw=$this->fwPt/$this->k; |
---|
149 | $this->fh=$this->fhPt/$this->k; |
---|
150 | //Page orientation |
---|
151 | $orientation=strtolower($orientation); |
---|
152 | if($orientation=='p' || $orientation=='portrait') |
---|
153 | { |
---|
154 | $this->DefOrientation='P'; |
---|
155 | $this->wPt=$this->fwPt; |
---|
156 | $this->hPt=$this->fhPt; |
---|
157 | } |
---|
158 | elseif($orientation=='l' || $orientation=='landscape') |
---|
159 | { |
---|
160 | $this->DefOrientation='L'; |
---|
161 | $this->wPt=$this->fhPt; |
---|
162 | $this->hPt=$this->fwPt; |
---|
163 | } |
---|
164 | else |
---|
165 | $this->Error('Incorrect orientation: '.$orientation); |
---|
166 | $this->CurOrientation=$this->DefOrientation; |
---|
167 | $this->w=$this->wPt/$this->k; |
---|
168 | $this->h=$this->hPt/$this->k; |
---|
169 | //Page margins (1 cm) |
---|
170 | $margin=28.35/$this->k; |
---|
171 | $this->SetMargins($margin,$margin); |
---|
172 | //Interior cell margin (1 mm) |
---|
173 | $this->cMargin=$margin/10; |
---|
174 | //Line width (0.2 mm) |
---|
175 | $this->LineWidth=.567/$this->k; |
---|
176 | //Automatic page break |
---|
177 | $this->SetAutoPageBreak(true,2*$margin); |
---|
178 | //Full width display mode |
---|
179 | $this->SetDisplayMode('fullwidth'); |
---|
180 | //Enable compression |
---|
181 | $this->SetCompression(true); |
---|
182 | //Set default PDF version number |
---|
183 | $this->PDFVersion='1.3'; |
---|
184 | $this->maxLineWidth=0; |
---|
185 | } |
---|
186 | |
---|
187 | function SetMargins($left,$top,$right=-1) |
---|
188 | { |
---|
189 | //Set left, top and right margins |
---|
190 | $this->lMargin=$left; |
---|
191 | $this->tMargin=$top; |
---|
192 | if($right==-1) |
---|
193 | $right=$left; |
---|
194 | $this->rMargin=$right; |
---|
195 | } |
---|
196 | |
---|
197 | function SetLeftMargin($margin) |
---|
198 | { |
---|
199 | //Set left margin |
---|
200 | $this->lMargin=$margin; |
---|
201 | if($this->page>0 && $this->x<$margin) |
---|
202 | $this->x=$margin; |
---|
203 | } |
---|
204 | |
---|
205 | function SetTopMargin($margin) |
---|
206 | { |
---|
207 | //Set top margin |
---|
208 | $this->tMargin=$margin; |
---|
209 | } |
---|
210 | |
---|
211 | function SetRightMargin($margin) |
---|
212 | { |
---|
213 | //Set right margin |
---|
214 | $this->rMargin=$margin; |
---|
215 | } |
---|
216 | |
---|
217 | function SetAutoPageBreak($auto,$margin=0) |
---|
218 | { |
---|
219 | //Set auto page break mode and triggering margin |
---|
220 | $this->AutoPageBreak=$auto; |
---|
221 | $this->bMargin=$margin; |
---|
222 | $this->PageBreakTrigger=$this->h-$margin; |
---|
223 | } |
---|
224 | |
---|
225 | function SetDisplayMode($zoom,$layout='continuous') |
---|
226 | { |
---|
227 | //Set display mode in viewer |
---|
228 | if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) |
---|
229 | $this->ZoomMode=$zoom; |
---|
230 | else |
---|
231 | $this->Error('Incorrect zoom display mode: '.$zoom); |
---|
232 | if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') |
---|
233 | $this->LayoutMode=$layout; |
---|
234 | else |
---|
235 | $this->Error('Incorrect layout display mode: '.$layout); |
---|
236 | } |
---|
237 | |
---|
238 | function SetCompression($compress) |
---|
239 | { |
---|
240 | //Set page compression |
---|
241 | if(function_exists('gzcompress')) |
---|
242 | $this->compress=$compress; |
---|
243 | else |
---|
244 | $this->compress=false; |
---|
245 | } |
---|
246 | |
---|
247 | function SetTitle($title) |
---|
248 | { |
---|
249 | //Title of document |
---|
250 | $this->title=$title; |
---|
251 | } |
---|
252 | |
---|
253 | function SetSubject($subject) |
---|
254 | { |
---|
255 | //Subject of document |
---|
256 | $this->subject=$subject; |
---|
257 | } |
---|
258 | |
---|
259 | function SetAuthor($author) |
---|
260 | { |
---|
261 | //Author of document |
---|
262 | $this->author=$author; |
---|
263 | } |
---|
264 | |
---|
265 | function SetCopyright($copyright) |
---|
266 | { |
---|
267 | $this->copyright=$copyright; |
---|
268 | } |
---|
269 | |
---|
270 | function SetKeywords($keywords) |
---|
271 | { |
---|
272 | //Keywords of document |
---|
273 | $this->keywords=$keywords; |
---|
274 | } |
---|
275 | |
---|
276 | function SetCreator($creator) |
---|
277 | { |
---|
278 | //Creator of document |
---|
279 | $this->creator=$creator; |
---|
280 | } |
---|
281 | |
---|
282 | function AliasNbPages($alias='{nb}') |
---|
283 | { |
---|
284 | //Define an alias for total number of pages |
---|
285 | $this->AliasNbPages=$alias; |
---|
286 | } |
---|
287 | |
---|
288 | function Error($msg) |
---|
289 | { |
---|
290 | //Fatal error |
---|
291 | die('<B>FPDF error: </B>'.$msg); |
---|
292 | } |
---|
293 | |
---|
294 | function Open() |
---|
295 | { |
---|
296 | //Begin document |
---|
297 | $this->state=1; |
---|
298 | } |
---|
299 | |
---|
300 | function Close() |
---|
301 | { |
---|
302 | //Terminate document |
---|
303 | if($this->state==3) |
---|
304 | return; |
---|
305 | if($this->page==0) |
---|
306 | $this->AddPage(); |
---|
307 | //Page footer |
---|
308 | $this->InFooter=true; |
---|
309 | $this->Footer(); |
---|
310 | $this->InFooter=false; |
---|
311 | //Close page |
---|
312 | $this->_endpage(); |
---|
313 | //Close document |
---|
314 | $this->_enddoc(); |
---|
315 | } |
---|
316 | |
---|
317 | function ResetBuffer() |
---|
318 | { |
---|
319 | $this->n=2; |
---|
320 | $this->buffer=''; |
---|
321 | $this->state==0; |
---|
322 | $this->page=0; |
---|
323 | $this->FontFamily=''; |
---|
324 | $this->FontStyle=''; |
---|
325 | $this->FontSizePt=12; |
---|
326 | $this->underline=false; |
---|
327 | } |
---|
328 | |
---|
329 | function AddPage($orientation='') |
---|
330 | { |
---|
331 | //Start a new page |
---|
332 | if($this->state==0) |
---|
333 | { |
---|
334 | $this->Open(); |
---|
335 | } |
---|
336 | |
---|
337 | $family=$this->FontFamily; |
---|
338 | $style=$this->FontStyle.($this->underline ? 'U' : ''); |
---|
339 | $size=$this->FontSizePt; |
---|
340 | $lw=$this->LineWidth; |
---|
341 | $dc=$this->DrawColor; |
---|
342 | $fc=$this->FillColor; |
---|
343 | $tc=$this->TextColor; |
---|
344 | $cf=$this->ColorFlag; |
---|
345 | if($this->page>0) |
---|
346 | { |
---|
347 | //Page footer |
---|
348 | $this->InFooter=true; |
---|
349 | $this->Footer(); |
---|
350 | $this->InFooter=false; |
---|
351 | //Close page |
---|
352 | $this->_endpage(); |
---|
353 | } |
---|
354 | //Start new page |
---|
355 | $this->_beginpage($orientation); |
---|
356 | //Set line cap style to square |
---|
357 | $this->_out('2 J'); |
---|
358 | //Set line width |
---|
359 | $this->LineWidth=$lw; |
---|
360 | $this->_out(sprintf('%.2f w',$lw*$this->k)); |
---|
361 | //Set font |
---|
362 | if($family) |
---|
363 | $this->SetFont($family,$style,$size); |
---|
364 | //Set colors |
---|
365 | $this->DrawColor=$dc; |
---|
366 | if($dc!='0 G') |
---|
367 | $this->_out($dc); |
---|
368 | $this->FillColor=$fc; |
---|
369 | if($fc!='0 g') |
---|
370 | $this->_out($fc); |
---|
371 | $this->TextColor=$tc; |
---|
372 | $this->ColorFlag=$cf; |
---|
373 | //Page header |
---|
374 | $this->Header(); |
---|
375 | //Restore line width |
---|
376 | if($this->LineWidth!=$lw) |
---|
377 | { |
---|
378 | $this->LineWidth=$lw; |
---|
379 | $this->_out(sprintf('%.2f w',$lw*$this->k)); |
---|
380 | } |
---|
381 | //Restore font |
---|
382 | if($family) |
---|
383 | $this->SetFont($family,$style,$size); |
---|
384 | //Restore colors |
---|
385 | if($this->DrawColor!=$dc) |
---|
386 | { |
---|
387 | $this->DrawColor=$dc; |
---|
388 | $this->_out($dc); |
---|
389 | } |
---|
390 | if($this->FillColor!=$fc) |
---|
391 | { |
---|
392 | $this->FillColor=$fc; |
---|
393 | $this->_out($fc); |
---|
394 | } |
---|
395 | $this->TextColor=$tc; |
---|
396 | $this->ColorFlag=$cf; |
---|
397 | } |
---|
398 | |
---|
399 | function Header() |
---|
400 | { |
---|
401 | //To be implemented in your own inherited class |
---|
402 | } |
---|
403 | |
---|
404 | function Footer() |
---|
405 | { |
---|
406 | //To be implemented in your own inherited class |
---|
407 | } |
---|
408 | |
---|
409 | function PageNo() |
---|
410 | { |
---|
411 | //Get current page number |
---|
412 | return $this->page; |
---|
413 | } |
---|
414 | |
---|
415 | function SetDrawColor($r,$g=-1,$b=-1) |
---|
416 | { |
---|
417 | //Set color for all stroking operations |
---|
418 | if(($r==0 && $g==0 && $b==0) || $g==-1) |
---|
419 | $this->DrawColor=sprintf('%.3f G',$r/255); |
---|
420 | else |
---|
421 | $this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255); |
---|
422 | if($this->page>0) |
---|
423 | $this->_out($this->DrawColor); |
---|
424 | } |
---|
425 | |
---|
426 | function SetFillColor($r,$g=-1,$b=-1) |
---|
427 | { |
---|
428 | //Set color for all filling operations |
---|
429 | if(($r==0 && $g==0 && $b==0) || $g==-1) |
---|
430 | $this->FillColor=sprintf('%.3f g',$r/255); |
---|
431 | else |
---|
432 | $this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); |
---|
433 | $this->ColorFlag=($this->FillColor!=$this->TextColor); |
---|
434 | if($this->page>0) |
---|
435 | $this->_out($this->FillColor); |
---|
436 | } |
---|
437 | |
---|
438 | function SetTextColor($r,$g=-1,$b=-1) |
---|
439 | { |
---|
440 | //Set color for text |
---|
441 | if(($r==0 && $g==0 && $b==0) || $g==-1) |
---|
442 | $this->TextColor=sprintf('%.3f g',$r/255); |
---|
443 | else |
---|
444 | $this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); |
---|
445 | $this->ColorFlag=($this->FillColor!=$this->TextColor); |
---|
446 | } |
---|
447 | |
---|
448 | function GetStringWidth($s) |
---|
449 | { |
---|
450 | //Get width of a string in the current font |
---|
451 | $s=(string)$s; |
---|
452 | $cw=&$this->CurrentFont['cw']; |
---|
453 | $w=0; |
---|
454 | $l=strlen($s); |
---|
455 | for($i=0;$i<$l;$i++) |
---|
456 | $w+=$cw[$s{$i}]; |
---|
457 | return $w*$this->FontSize/1000; |
---|
458 | } |
---|
459 | |
---|
460 | function SetLineWidth($width) |
---|
461 | { |
---|
462 | //Set line width |
---|
463 | $this->LineWidth=$width; |
---|
464 | if($this->page>0) |
---|
465 | $this->_out(sprintf('%.2f w',$width*$this->k)); |
---|
466 | } |
---|
467 | |
---|
468 | function Line($x1,$y1,$x2,$y2) |
---|
469 | { |
---|
470 | //Draw a line |
---|
471 | $this->_out(sprintf('%.2f %.2f m %.2f %.2f l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k)); |
---|
472 | } |
---|
473 | |
---|
474 | function Rect($x,$y,$w,$h,$style='') |
---|
475 | { |
---|
476 | //Draw a rectangle |
---|
477 | if($style=='F') |
---|
478 | $op='f'; |
---|
479 | elseif($style=='FD' || $style=='DF') |
---|
480 | $op='B'; |
---|
481 | else |
---|
482 | $op='S'; |
---|
483 | $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); |
---|
484 | } |
---|
485 | |
---|
486 | function AddFont($family,$style='',$file='') |
---|
487 | { |
---|
488 | //Add a TrueType or Type1 font |
---|
489 | $family=strtolower($family); |
---|
490 | if($file=='') |
---|
491 | $file=str_replace(' ','',$family).strtolower($style).'.php'; |
---|
492 | if($family=='arial') |
---|
493 | $family='helvetica'; |
---|
494 | $style=strtoupper($style); |
---|
495 | if($style=='IB') |
---|
496 | $style='BI'; |
---|
497 | $fontkey=$family.$style; |
---|
498 | if(isset($this->fonts[$fontkey])) |
---|
499 | $this->Error('Font already added: '.$family.' '.$style); |
---|
500 | include($this->_getfontpath().$file); |
---|
501 | if(!isset($name)) |
---|
502 | $this->Error('Could not include font definition file'); |
---|
503 | $i=count($this->fonts)+1; |
---|
504 | $this->fonts[$fontkey]=array('i'=>$i,'type'=>$type,'name'=>$name,'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw,'enc'=>$enc,'file'=>$file); |
---|
505 | if($diff) |
---|
506 | { |
---|
507 | //Search existing encodings |
---|
508 | $d=0; |
---|
509 | $nb=count($this->diffs); |
---|
510 | for($i=1;$i<=$nb;$i++) |
---|
511 | { |
---|
512 | if($this->diffs[$i]==$diff) |
---|
513 | { |
---|
514 | $d=$i; |
---|
515 | break; |
---|
516 | } |
---|
517 | } |
---|
518 | if($d==0) |
---|
519 | { |
---|
520 | $d=$nb+1; |
---|
521 | $this->diffs[$d]=$diff; |
---|
522 | } |
---|
523 | $this->fonts[$fontkey]['diff']=$d; |
---|
524 | } |
---|
525 | if($file) |
---|
526 | { |
---|
527 | if($type=='TrueType') |
---|
528 | $this->FontFiles[$file]=array('length1'=>$originalsize); |
---|
529 | else |
---|
530 | $this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2); |
---|
531 | } |
---|
532 | } |
---|
533 | |
---|
534 | function SetFont($family,$style='',$size=0) |
---|
535 | { |
---|
536 | //Select a font; size given in points |
---|
537 | global $fpdf_charwidths; |
---|
538 | |
---|
539 | $family=strtolower($family); |
---|
540 | if($family=='') |
---|
541 | $family=$this->FontFamily; |
---|
542 | if($family=='arial') |
---|
543 | $family='helvetica'; |
---|
544 | elseif($family=='symbol' || $family=='zapfdingbats') |
---|
545 | $style=''; |
---|
546 | $style=strtoupper($style); |
---|
547 | if(strpos($style,'U')!==false) |
---|
548 | { |
---|
549 | $this->underline=true; |
---|
550 | $style=str_replace('U','',$style); |
---|
551 | } |
---|
552 | else |
---|
553 | $this->underline=false; |
---|
554 | if($style=='IB') |
---|
555 | $style='BI'; |
---|
556 | if($size==0) |
---|
557 | $size=$this->FontSizePt; |
---|
558 | //Test if font is already selected |
---|
559 | if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) |
---|
560 | return; |
---|
561 | //Test if used for the first time |
---|
562 | $fontkey=$family.$style; |
---|
563 | if(!isset($this->fonts[$fontkey])) |
---|
564 | { |
---|
565 | //Check if one of the standard fonts |
---|
566 | if(isset($this->CoreFonts[$fontkey])) |
---|
567 | { |
---|
568 | if(!isset($fpdf_charwidths[$fontkey])) |
---|
569 | { |
---|
570 | //Load metric file |
---|
571 | $file=$family; |
---|
572 | if($family=='times' || $family=='helvetica') |
---|
573 | $file.=strtolower($style); |
---|
574 | include($this->_getfontpath().$file.'.php'); |
---|
575 | if(!isset($fpdf_charwidths[$fontkey])) |
---|
576 | $this->Error('Could not include font metric file'); |
---|
577 | } |
---|
578 | $i=count($this->fonts)+1; |
---|
579 | $this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'up'=>-100,'ut'=>50,'cw'=>$fpdf_charwidths[$fontkey]); |
---|
580 | } |
---|
581 | else |
---|
582 | $this->Error('Undefined font: '.$family.' '.$style); |
---|
583 | } |
---|
584 | //Select it |
---|
585 | $this->FontFamily=$family; |
---|
586 | $this->FontStyle=$style; |
---|
587 | $this->FontSizePt=$size; |
---|
588 | $this->FontSize=$size/$this->k; |
---|
589 | $this->CurrentFont=&$this->fonts[$fontkey]; |
---|
590 | if($this->page>0) |
---|
591 | $this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); |
---|
592 | } |
---|
593 | |
---|
594 | function SetFontSize($size) |
---|
595 | { |
---|
596 | //Set font size in points |
---|
597 | if($this->FontSizePt==$size) |
---|
598 | return; |
---|
599 | $this->FontSizePt=$size; |
---|
600 | $this->FontSize=$size/$this->k; |
---|
601 | if($this->page>0) |
---|
602 | $this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); |
---|
603 | } |
---|
604 | |
---|
605 | function AddLink() |
---|
606 | { |
---|
607 | //Create a new internal link |
---|
608 | $n=count($this->links)+1; |
---|
609 | $this->links[$n]=array(0,0); |
---|
610 | return $n; |
---|
611 | } |
---|
612 | |
---|
613 | function SetLink($link,$y=0,$page=-1) |
---|
614 | { |
---|
615 | //Set destination of internal link |
---|
616 | if($y==-1) |
---|
617 | $y=$this->y; |
---|
618 | if($page==-1) |
---|
619 | $page=$this->page; |
---|
620 | $this->links[$link]=array($page,$y); |
---|
621 | } |
---|
622 | |
---|
623 | function Link($x,$y,$w,$h,$link) |
---|
624 | { |
---|
625 | //Put a link on the page |
---|
626 | $this->PageLinks[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link); |
---|
627 | } |
---|
628 | |
---|
629 | function Text($x,$y,$txt) |
---|
630 | { |
---|
631 | //Output a string |
---|
632 | $s=sprintf('BT %.2f %.2f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); |
---|
633 | if($this->underline && $txt!='') |
---|
634 | $s.=' '.$this->_dounderline($x,$y,$txt); |
---|
635 | if($this->ColorFlag) |
---|
636 | $s='q '.$this->TextColor.' '.$s.' Q'; |
---|
637 | $this->_out($s); |
---|
638 | } |
---|
639 | |
---|
640 | function AcceptPageBreak() |
---|
641 | { |
---|
642 | //Accept automatic page break or not |
---|
643 | return $this->AutoPageBreak; |
---|
644 | } |
---|
645 | |
---|
646 | function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='') |
---|
647 | { |
---|
648 | //Output a cell |
---|
649 | $k=$this->k; |
---|
650 | if($this->y+$h>$this->PageBreakTrigger && !$this->InFooter && $this->AcceptPageBreak()) |
---|
651 | { |
---|
652 | //Automatic page break |
---|
653 | $x=$this->x; |
---|
654 | $ws=$this->ws; |
---|
655 | if($ws>0) |
---|
656 | { |
---|
657 | $this->ws=0; |
---|
658 | $this->_out('0 Tw'); |
---|
659 | } |
---|
660 | $this->AddPage($this->CurOrientation); |
---|
661 | $this->x=$x; |
---|
662 | if($ws>0) |
---|
663 | { |
---|
664 | $this->ws=$ws; |
---|
665 | $this->_out(sprintf('%.3f Tw',$ws*$k)); |
---|
666 | } |
---|
667 | } |
---|
668 | if($w==0) |
---|
669 | $w=$this->w-$this->rMargin-$this->x; |
---|
670 | $s=''; |
---|
671 | if($fill==1 || $border==1) |
---|
672 | { |
---|
673 | if($fill==1) |
---|
674 | $op=($border==1) ? 'B' : 'f'; |
---|
675 | else |
---|
676 | $op='S'; |
---|
677 | $s=sprintf('%.2f %.2f %.2f %.2f re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); |
---|
678 | } |
---|
679 | if(is_string($border)) |
---|
680 | { |
---|
681 | $x=$this->x; |
---|
682 | $y=$this->y; |
---|
683 | if(strpos($border,'L')!==false) |
---|
684 | $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); |
---|
685 | if(strpos($border,'T')!==false) |
---|
686 | $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); |
---|
687 | if(strpos($border,'R')!==false) |
---|
688 | $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); |
---|
689 | if(strpos($border,'B')!==false) |
---|
690 | $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); |
---|
691 | } |
---|
692 | if($txt!=='') |
---|
693 | { |
---|
694 | if($align=='R') |
---|
695 | $dx=$w-$this->cMargin-$this->GetStringWidth($txt); |
---|
696 | elseif($align=='C') |
---|
697 | $dx=($w-$this->GetStringWidth($txt))/2; |
---|
698 | else |
---|
699 | $dx=$this->cMargin; |
---|
700 | if($this->ColorFlag) |
---|
701 | $s.='q '.$this->TextColor.' '; |
---|
702 | $txt2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt))); |
---|
703 | $s.=sprintf('BT %.2f %.2f Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt2); |
---|
704 | if($this->underline) |
---|
705 | $s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); |
---|
706 | if($this->ColorFlag) |
---|
707 | $s.=' Q'; |
---|
708 | if($link) |
---|
709 | $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link); |
---|
710 | } |
---|
711 | if($s) |
---|
712 | $this->_out($s); |
---|
713 | $this->lasth=$h; |
---|
714 | if($ln>0) |
---|
715 | { |
---|
716 | $this->maxLineWidth=max($this->maxLineWidth,$this->x+$w); |
---|
717 | //Go to next line |
---|
718 | $this->y+=$h; |
---|
719 | if($ln==1) |
---|
720 | $this->x=$this->lMargin; |
---|
721 | } |
---|
722 | else |
---|
723 | $this->x+=$w; |
---|
724 | } |
---|
725 | |
---|
726 | function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0) |
---|
727 | { |
---|
728 | //Output text with automatic or explicit line breaks |
---|
729 | $cw=&$this->CurrentFont['cw']; |
---|
730 | if($w==0) |
---|
731 | $w=$this->w-$this->rMargin-$this->x; |
---|
732 | $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
---|
733 | $s=str_replace("\r",'',$txt); |
---|
734 | $nb=strlen($s); |
---|
735 | if($nb>0 && $s[$nb-1]=="\n") |
---|
736 | $nb--; |
---|
737 | $b=0; |
---|
738 | if($border) |
---|
739 | { |
---|
740 | if($border==1) |
---|
741 | { |
---|
742 | $border='LTRB'; |
---|
743 | $b='LRT'; |
---|
744 | $b2='LR'; |
---|
745 | } |
---|
746 | else |
---|
747 | { |
---|
748 | $b2=''; |
---|
749 | if(strpos($border,'L')!==false) |
---|
750 | $b2.='L'; |
---|
751 | if(strpos($border,'R')!==false) |
---|
752 | $b2.='R'; |
---|
753 | $b=(strpos($border,'T')!==false) ? $b2.'T' : $b2; |
---|
754 | } |
---|
755 | } |
---|
756 | $sep=-1; |
---|
757 | $i=0; |
---|
758 | $j=0; |
---|
759 | $l=0; |
---|
760 | $ns=0; |
---|
761 | $nl=1; |
---|
762 | while($i<$nb) |
---|
763 | { |
---|
764 | //Get next character |
---|
765 | $c=$s{$i}; |
---|
766 | if($c=="\n") |
---|
767 | { |
---|
768 | //Explicit line break |
---|
769 | if($this->ws>0) |
---|
770 | { |
---|
771 | $this->ws=0; |
---|
772 | $this->_out('0 Tw'); |
---|
773 | } |
---|
774 | $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
---|
775 | $i++; |
---|
776 | $sep=-1; |
---|
777 | $j=$i; |
---|
778 | $l=0; |
---|
779 | $ns=0; |
---|
780 | $nl++; |
---|
781 | if($border && $nl==2) |
---|
782 | $b=$b2; |
---|
783 | continue; |
---|
784 | } |
---|
785 | if($c==' ') |
---|
786 | { |
---|
787 | $sep=$i; |
---|
788 | $ls=$l; |
---|
789 | $ns++; |
---|
790 | } |
---|
791 | $l+=$cw[$c]; |
---|
792 | if($l>$wmax) |
---|
793 | { |
---|
794 | //Automatic line break |
---|
795 | if($sep==-1) |
---|
796 | { |
---|
797 | if($i==$j) |
---|
798 | $i++; |
---|
799 | if($this->ws>0) |
---|
800 | { |
---|
801 | $this->ws=0; |
---|
802 | $this->_out('0 Tw'); |
---|
803 | } |
---|
804 | $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
---|
805 | } |
---|
806 | else |
---|
807 | { |
---|
808 | if($align=='J') |
---|
809 | { |
---|
810 | $this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; |
---|
811 | $this->_out(sprintf('%.3f Tw',$this->ws*$this->k)); |
---|
812 | } |
---|
813 | $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); |
---|
814 | $i=$sep+1; |
---|
815 | } |
---|
816 | $sep=-1; |
---|
817 | $j=$i; |
---|
818 | $l=0; |
---|
819 | $ns=0; |
---|
820 | $nl++; |
---|
821 | if($border && $nl==2) |
---|
822 | $b=$b2; |
---|
823 | } |
---|
824 | else |
---|
825 | $i++; |
---|
826 | } |
---|
827 | //Last chunk |
---|
828 | if($this->ws>0) |
---|
829 | { |
---|
830 | $this->ws=0; |
---|
831 | $this->_out('0 Tw'); |
---|
832 | } |
---|
833 | if($border && strpos($border,'B')!==false) |
---|
834 | $b.='B'; |
---|
835 | $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
---|
836 | $this->x=$this->lMargin; |
---|
837 | } |
---|
838 | |
---|
839 | function Write($h,$txt,$link='') |
---|
840 | { |
---|
841 | //Output text in flowing mode |
---|
842 | $cw=&$this->CurrentFont['cw']; |
---|
843 | $w=$this->w-$this->rMargin-$this->x; |
---|
844 | $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
---|
845 | $s=str_replace("\r",'',$txt); |
---|
846 | $nb=strlen($s); |
---|
847 | $sep=-1; |
---|
848 | $i=0; |
---|
849 | $j=0; |
---|
850 | $l=0; |
---|
851 | $nl=1; |
---|
852 | while($i<$nb) |
---|
853 | { |
---|
854 | //Get next character |
---|
855 | $c=$s{$i}; |
---|
856 | if($c=="\n") |
---|
857 | { |
---|
858 | //Explicit line break |
---|
859 | $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); |
---|
860 | $this->maxLineWidth=max($this->maxLineWidth,$this->x); |
---|
861 | $i++; |
---|
862 | $sep=-1; |
---|
863 | $j=$i; |
---|
864 | $l=0; |
---|
865 | if($nl==1) |
---|
866 | { |
---|
867 | $this->x=$this->lMargin; |
---|
868 | $w=$this->w-$this->rMargin-$this->x; |
---|
869 | $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
---|
870 | } |
---|
871 | $nl++; |
---|
872 | continue; |
---|
873 | } |
---|
874 | if($c==' ') |
---|
875 | $sep=$i; |
---|
876 | $l+=$cw[$c]; |
---|
877 | if($l>$wmax) |
---|
878 | { |
---|
879 | //Automatic line break |
---|
880 | if($sep==-1) |
---|
881 | { |
---|
882 | if($this->x>$this->lMargin) |
---|
883 | { |
---|
884 | //Move to next line |
---|
885 | $this->maxLineWidth=max($this->maxLineWidth,$this->x); |
---|
886 | $this->x=$this->lMargin; |
---|
887 | $this->y+=$h; |
---|
888 | $w=$this->w-$this->rMargin-$this->x; |
---|
889 | $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
---|
890 | $i++; |
---|
891 | $nl++; |
---|
892 | continue; |
---|
893 | } |
---|
894 | if($i==$j) |
---|
895 | $i++; |
---|
896 | $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); |
---|
897 | $this->maxLineWidth=max($this->maxLineWidth,$this->x); |
---|
898 | } |
---|
899 | else |
---|
900 | { |
---|
901 | $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link); |
---|
902 | $this->maxLineWidth=max($this->maxLineWidth,$this->x); |
---|
903 | $i=$sep+1; |
---|
904 | } |
---|
905 | $sep=-1; |
---|
906 | $j=$i; |
---|
907 | $l=0; |
---|
908 | if($nl==1) |
---|
909 | { |
---|
910 | $this->maxLineWidth=max($this->maxLineWidth,$this->x); |
---|
911 | $this->x=$this->lMargin; |
---|
912 | $w=$this->w-$this->rMargin-$this->x; |
---|
913 | $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
---|
914 | } |
---|
915 | $nl++; |
---|
916 | } |
---|
917 | else |
---|
918 | $i++; |
---|
919 | } |
---|
920 | //Last chunk |
---|
921 | if($i!=$j) |
---|
922 | $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',0,$link); |
---|
923 | $this->maxLineWidth=max($this->maxLineWidth,$this->x); |
---|
924 | } |
---|
925 | |
---|
926 | function Image($file,$x,$y,$w=0,$h=0,$type='',$link='',$maxframe='0') |
---|
927 | { |
---|
928 | //Put an image on the page |
---|
929 | if(!isset($this->images[$file])) |
---|
930 | { |
---|
931 | //First use of image, get info |
---|
932 | if($type=='') |
---|
933 | { |
---|
934 | $pos=strrpos($file,'.'); |
---|
935 | if(!$pos) |
---|
936 | $this->Error('Image file has no extension and no type was specified: '.$file); |
---|
937 | $type=substr($file,$pos+1); |
---|
938 | $name=substr($file,0,$pos); |
---|
939 | $pos=strrpos($name,'/'); |
---|
940 | $name=substr($name,$pos+1); |
---|
941 | } |
---|
942 | $type=strtolower($type); |
---|
943 | $mqr=get_magic_quotes_runtime(); |
---|
944 | set_magic_quotes_runtime(0); |
---|
945 | |
---|
946 | if($type=='jpg' || $type=='jpeg') |
---|
947 | { |
---|
948 | $info=$this->_parsejpg($file); |
---|
949 | } |
---|
950 | elseif ($type=='png') |
---|
951 | { |
---|
952 | Header( "Content-type: image/png"); |
---|
953 | $image = @imagecreatefromPNG("$file"); |
---|
954 | $im_X = ImageSX($image); |
---|
955 | $im_Y = ImageSY($image); |
---|
956 | $backgroundimage = imagecreatetruecolor($im_X, $im_Y); |
---|
957 | $backgroundcolor = ImageColorAllocate($backgroundimage, 255, 255, 255); |
---|
958 | ImageFilledRectangle($backgroundimage, 0, 0, $im_X, $im_Y, $backgroundcolor); |
---|
959 | ImageAlphaBlending($backgroundimage, true); |
---|
960 | imagecopy($backgroundimage, $image, 0, 0, 0, 0, $im_X, $im_Y); |
---|
961 | ImagePNG($backgroundimage,"./IMG/tempo.png"); |
---|
962 | ImageDestroy($image); |
---|
963 | ImageDestroy($backgroundimage); |
---|
964 | $info=$this->_parsepng("./IMG/tempo.png"); |
---|
965 | unlink ("./IMG/tempo.png"); |
---|
966 | } |
---|
967 | //$info=$this->_parsepng($file); |
---|
968 | |
---|
969 | elseif($type=='gif') |
---|
970 | { |
---|
971 | /* |
---|
972 | $readgif= gd_info(); |
---|
973 | if ($readgif[3]) { |
---|
974 | Header( "Content-type: image/png"); |
---|
975 | $image = @imagecreatefromGIF("$file"); |
---|
976 | imageinterlace($image,0); |
---|
977 | ImagePNG($image,"./IMG/tempo.png"); |
---|
978 | ImageDestroy($image); |
---|
979 | $info=$this->_parsepng("./IMG/tempo.png"); |
---|
980 | unlink ("./IMG/tempo.png"); |
---|
981 | } else { |
---|
982 | $info=$this->_parsegif($file); |
---|
983 | } |
---|
984 | */ |
---|
985 | $ImagesGif = $this->_parsegif2($file,'GIF','./IMG/'.$name.'_frame',0); |
---|
986 | |
---|
987 | foreach($ImagesGif as $i=>$gs_frame){ |
---|
988 | Header( "Content-type: image/png"); |
---|
989 | $image = @imagecreatefromGIF($gs_frame); |
---|
990 | imageinterlace($image,0); |
---|
991 | ImagePNG($image,"./IMG/tempo.png"); |
---|
992 | $info=$this->_parsepng("./IMG/tempo.png"); |
---|
993 | ImageDestroy($image); |
---|
994 | unlink ("./IMG/tempo.png"); |
---|
995 | unlink ($gs_frame); |
---|
996 | } |
---|
997 | |
---|
998 | } |
---|
999 | else |
---|
1000 | { |
---|
1001 | //Allow for additional formats |
---|
1002 | $mtd='_parse'.$type; |
---|
1003 | if(!method_exists($this,$mtd)) |
---|
1004 | { |
---|
1005 | $this->Error('Unsupported image type: '.$type); |
---|
1006 | } |
---|
1007 | $info=$this->$mtd($file); |
---|
1008 | } |
---|
1009 | |
---|
1010 | set_magic_quotes_runtime($mqr); |
---|
1011 | $info['i']=count($this->images)+1; |
---|
1012 | $this->images[$file]=$info; |
---|
1013 | } |
---|
1014 | else |
---|
1015 | { |
---|
1016 | $info=$this->images[$file]; |
---|
1017 | } |
---|
1018 | //Automatic width and height calculation if needed |
---|
1019 | if($w==0 && $h==0) |
---|
1020 | { |
---|
1021 | //Put image at 72 dpi |
---|
1022 | $w=$info['w']/$this->k; |
---|
1023 | $h=$info['h']/$this->k; |
---|
1024 | } |
---|
1025 | if($w==0) |
---|
1026 | $w=$h*$info['w']/$info['h']; |
---|
1027 | if($h==0) |
---|
1028 | $h=$w*$info['h']/$info['w']; |
---|
1029 | $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'])); |
---|
1030 | if($link) |
---|
1031 | $this->Link($x,$y,$w,$h,$link); |
---|
1032 | } |
---|
1033 | |
---|
1034 | function Ln($h='') |
---|
1035 | { |
---|
1036 | $this->maxLineWidth=max($this->maxLineWidth,$this->x); |
---|
1037 | //Line feed; default value is last cell height |
---|
1038 | $this->x=$this->lMargin; |
---|
1039 | if(is_string($h)) |
---|
1040 | $this->y+=$this->lasth; |
---|
1041 | else |
---|
1042 | $this->y+=$h; |
---|
1043 | } |
---|
1044 | |
---|
1045 | function GetX() |
---|
1046 | { |
---|
1047 | //Get x position |
---|
1048 | return $this->x; |
---|
1049 | } |
---|
1050 | |
---|
1051 | function SetX($x) |
---|
1052 | { |
---|
1053 | //Set x position |
---|
1054 | if($x>=0) |
---|
1055 | $this->x=$x; |
---|
1056 | else |
---|
1057 | $this->x=$this->w+$x; |
---|
1058 | } |
---|
1059 | |
---|
1060 | function GetY() |
---|
1061 | { |
---|
1062 | //Get y position |
---|
1063 | return $this->y; |
---|
1064 | } |
---|
1065 | |
---|
1066 | function SetY($y) |
---|
1067 | { |
---|
1068 | //Set y position and reset x |
---|
1069 | $this->x=$this->lMargin; |
---|
1070 | if($y>=0) |
---|
1071 | $this->y=$y; |
---|
1072 | else |
---|
1073 | $this->y=$this->h+$y; |
---|
1074 | } |
---|
1075 | |
---|
1076 | function SetXY($x,$y) |
---|
1077 | { |
---|
1078 | //Set x and y positions |
---|
1079 | $this->SetY($y); |
---|
1080 | $this->SetX($x); |
---|
1081 | } |
---|
1082 | |
---|
1083 | function Output($name='',$dest='') |
---|
1084 | { |
---|
1085 | //Output PDF to some destination |
---|
1086 | //Finish document if necessary |
---|
1087 | if($this->state<3) |
---|
1088 | $this->Close(); |
---|
1089 | //Normalize parameters |
---|
1090 | if(is_bool($dest)) |
---|
1091 | $dest=$dest ? 'D' : 'F'; |
---|
1092 | $dest=strtoupper($dest); |
---|
1093 | if($dest=='') |
---|
1094 | { |
---|
1095 | if($name=='') |
---|
1096 | { |
---|
1097 | $name='doc.pdf'; |
---|
1098 | $dest='I'; |
---|
1099 | } |
---|
1100 | else |
---|
1101 | $dest='F'; |
---|
1102 | } |
---|
1103 | switch($dest) |
---|
1104 | { |
---|
1105 | case 'I': |
---|
1106 | //Send to standard output |
---|
1107 | if(ob_get_contents()) |
---|
1108 | $this->Error('Some data has already been output, can\'t send PDF file'); |
---|
1109 | if(php_sapi_name()!='cli') |
---|
1110 | { |
---|
1111 | //We send to a browser |
---|
1112 | header('Content-Type: application/pdf'); |
---|
1113 | if(headers_sent()) |
---|
1114 | $this->Error('Some data has already been output to browser, can\'t send PDF file'); |
---|
1115 | header('Content-Length: '.strlen($this->buffer)); |
---|
1116 | header('Content-disposition: inline; filename="'.$name.'"'); |
---|
1117 | } |
---|
1118 | echo $this->buffer; |
---|
1119 | break; |
---|
1120 | case 'D': |
---|
1121 | //Download file |
---|
1122 | if(ob_get_contents()) |
---|
1123 | $this->Error('Some data has already been output, can\'t send PDF file'); |
---|
1124 | if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) |
---|
1125 | header('Content-Type: application/force-download'); |
---|
1126 | else |
---|
1127 | header('Content-Type: application/octet-stream'); |
---|
1128 | if(headers_sent()) |
---|
1129 | $this->Error('Some data has already been output to browser, can\'t send PDF file'); |
---|
1130 | header('Content-Length: '.strlen($this->buffer)); |
---|
1131 | header('Content-disposition: attachment; filename="'.$name.'"'); |
---|
1132 | echo $this->buffer; |
---|
1133 | break; |
---|
1134 | case 'F': |
---|
1135 | //Save to local file |
---|
1136 | $f=fopen($name,'wb'); |
---|
1137 | if(!$f) |
---|
1138 | $this->Error('Unable to create output file: '.$name); |
---|
1139 | fwrite($f,$this->buffer,strlen($this->buffer)); |
---|
1140 | fclose($f); |
---|
1141 | break; |
---|
1142 | case 'S': |
---|
1143 | //Return as a string |
---|
1144 | return $this->buffer; |
---|
1145 | default: |
---|
1146 | $this->Error('Incorrect output destination: '.$dest); |
---|
1147 | } |
---|
1148 | return ''; |
---|
1149 | } |
---|
1150 | |
---|
1151 | /******************************************************************************* |
---|
1152 | * * |
---|
1153 | * Protected methods * |
---|
1154 | * * |
---|
1155 | *******************************************************************************/ |
---|
1156 | function _dochecks() |
---|
1157 | { |
---|
1158 | //Check for locale-related bug |
---|
1159 | if(1.1==1) |
---|
1160 | $this->Error('Don\'t alter the locale before including class file'); |
---|
1161 | //Check for decimal separator |
---|
1162 | if(sprintf('%.1f',1.0)!='1.0') |
---|
1163 | setlocale(LC_NUMERIC,'C'); |
---|
1164 | } |
---|
1165 | |
---|
1166 | function _getfontpath() |
---|
1167 | { |
---|
1168 | if(!defined('FPDF_FONTPATH') && is_dir(dirname(__FILE__).'/font')) |
---|
1169 | define('FPDF_FONTPATH',dirname(__FILE__).'/font/'); |
---|
1170 | return defined('FPDF_FONTPATH') ? FPDF_FONTPATH : ''; |
---|
1171 | } |
---|
1172 | |
---|
1173 | function _putpages() |
---|
1174 | { |
---|
1175 | $nb=$this->page; |
---|
1176 | if(!empty($this->AliasNbPages)) |
---|
1177 | { |
---|
1178 | //Replace number of pages |
---|
1179 | for($n=1;$n<=$nb;$n++) |
---|
1180 | $this->pages[$n]=str_replace($this->AliasNbPages,$nb,$this->pages[$n]); |
---|
1181 | } |
---|
1182 | if($this->DefOrientation=='P') |
---|
1183 | { |
---|
1184 | $wPt=$this->fwPt; |
---|
1185 | $hPt=$this->fhPt; |
---|
1186 | } |
---|
1187 | else |
---|
1188 | { |
---|
1189 | $wPt=$this->fhPt; |
---|
1190 | $hPt=$this->fwPt; |
---|
1191 | } |
---|
1192 | $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; |
---|
1193 | for($n=1;$n<=$nb;$n++) |
---|
1194 | { |
---|
1195 | //Page |
---|
1196 | $this->_newobj(); |
---|
1197 | $this->_out('<</Type /Page'); |
---|
1198 | $this->_out('/Parent 1 0 R'); |
---|
1199 | if(isset($this->OrientationChanges[$n])) |
---|
1200 | $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$hPt,$wPt)); |
---|
1201 | $this->_out('/Resources 2 0 R'); |
---|
1202 | if(isset($this->PageLinks[$n])) |
---|
1203 | { |
---|
1204 | //Links |
---|
1205 | $annots='/Annots ['; |
---|
1206 | foreach($this->PageLinks[$n] as $pl) |
---|
1207 | { |
---|
1208 | $rect=sprintf('%.2f %.2f %.2f %.2f',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); |
---|
1209 | $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
---|
1210 | if(is_string($pl[4])) |
---|
1211 | $annots.='/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
---|
1212 | else |
---|
1213 | { |
---|
1214 | $l=$this->links[$pl[4]]; |
---|
1215 | $h=isset($this->OrientationChanges[$l[0]]) ? $wPt : $hPt; |
---|
1216 | $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>',1+2*$l[0],$h-$l[1]*$this->k); |
---|
1217 | } |
---|
1218 | } |
---|
1219 | $this->_out($annots.']'); |
---|
1220 | } |
---|
1221 | $this->_out('/Contents '.($this->n+1).' 0 R>>'); |
---|
1222 | $this->_out('endobj'); |
---|
1223 | //Page content |
---|
1224 | $p=($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n]; |
---|
1225 | $this->_newobj(); |
---|
1226 | $this->_out('<<'.$filter.'/Length '.strlen($p).'>>'); |
---|
1227 | $this->_putstream($p); |
---|
1228 | $this->_out('endobj'); |
---|
1229 | } |
---|
1230 | //Pages root |
---|
1231 | $this->offsets[1]=strlen($this->buffer); |
---|
1232 | $this->_out('1 0 obj'); |
---|
1233 | $this->_out('<</Type /Pages'); |
---|
1234 | $kids='/Kids ['; |
---|
1235 | for($i=0;$i<$nb;$i++) |
---|
1236 | $kids.=(3+2*$i).' 0 R '; |
---|
1237 | $this->_out($kids.']'); |
---|
1238 | $this->_out('/Count '.$nb); |
---|
1239 | $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$wPt,$hPt)); |
---|
1240 | $this->_out('>>'); |
---|
1241 | $this->_out('endobj'); |
---|
1242 | } |
---|
1243 | |
---|
1244 | function _putfonts() |
---|
1245 | { |
---|
1246 | $nf=$this->n; |
---|
1247 | foreach($this->diffs as $diff) |
---|
1248 | { |
---|
1249 | //Encodings |
---|
1250 | $this->_newobj(); |
---|
1251 | $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>'); |
---|
1252 | $this->_out('endobj'); |
---|
1253 | } |
---|
1254 | $mqr=get_magic_quotes_runtime(); |
---|
1255 | set_magic_quotes_runtime(0); |
---|
1256 | foreach($this->FontFiles as $file=>$info) |
---|
1257 | { |
---|
1258 | //Font file embedding |
---|
1259 | $this->_newobj(); |
---|
1260 | $this->FontFiles[$file]['n']=$this->n; |
---|
1261 | $font=''; |
---|
1262 | $f=fopen($this->_getfontpath().$file,'rb',1); |
---|
1263 | if(!$f) |
---|
1264 | $this->Error('Font file not found'); |
---|
1265 | while(!feof($f)) |
---|
1266 | $font.=fread($f,8192); |
---|
1267 | fclose($f); |
---|
1268 | $compressed=(substr($file,-2)=='.z'); |
---|
1269 | if(!$compressed && isset($info['length2'])) |
---|
1270 | { |
---|
1271 | $header=(ord($font{0})==128); |
---|
1272 | if($header) |
---|
1273 | { |
---|
1274 | //Strip first binary header |
---|
1275 | $font=substr($font,6); |
---|
1276 | } |
---|
1277 | if($header && ord($font{$info['length1']})==128) |
---|
1278 | { |
---|
1279 | //Strip second binary header |
---|
1280 | $font=substr($font,0,$info['length1']).substr($font,$info['length1']+6); |
---|
1281 | } |
---|
1282 | } |
---|
1283 | $this->_out('<</Length '.strlen($font)); |
---|
1284 | if($compressed) |
---|
1285 | $this->_out('/Filter /FlateDecode'); |
---|
1286 | $this->_out('/Length1 '.$info['length1']); |
---|
1287 | if(isset($info['length2'])) |
---|
1288 | $this->_out('/Length2 '.$info['length2'].' /Length3 0'); |
---|
1289 | $this->_out('>>'); |
---|
1290 | $this->_putstream($font); |
---|
1291 | $this->_out('endobj'); |
---|
1292 | } |
---|
1293 | set_magic_quotes_runtime($mqr); |
---|
1294 | foreach($this->fonts as $k=>$font) |
---|
1295 | { |
---|
1296 | //Font objects |
---|
1297 | $this->fonts[$k]['n']=$this->n+1; |
---|
1298 | $type=$font['type']; |
---|
1299 | $name=$font['name']; |
---|
1300 | if($type=='core') |
---|
1301 | { |
---|
1302 | //Standard font |
---|
1303 | $this->_newobj(); |
---|
1304 | $this->_out('<</Type /Font'); |
---|
1305 | $this->_out('/BaseFont /'.$name); |
---|
1306 | $this->_out('/Subtype /Type1'); |
---|
1307 | if($name!='Symbol' && $name!='ZapfDingbats') |
---|
1308 | $this->_out('/Encoding /WinAnsiEncoding'); |
---|
1309 | $this->_out('>>'); |
---|
1310 | $this->_out('endobj'); |
---|
1311 | } |
---|
1312 | elseif($type=='Type1' || $type=='TrueType') |
---|
1313 | { |
---|
1314 | //Additional Type1 or TrueType font |
---|
1315 | $this->_newobj(); |
---|
1316 | $this->_out('<</Type /Font'); |
---|
1317 | $this->_out('/BaseFont /'.$name); |
---|
1318 | $this->_out('/Subtype /'.$type); |
---|
1319 | $this->_out('/FirstChar 32 /LastChar 255'); |
---|
1320 | $this->_out('/Widths '.($this->n+1).' 0 R'); |
---|
1321 | $this->_out('/FontDescriptor '.($this->n+2).' 0 R'); |
---|
1322 | if($font['enc']) |
---|
1323 | { |
---|
1324 | if(isset($font['diff'])) |
---|
1325 | $this->_out('/Encoding '.($nf+$font['diff']).' 0 R'); |
---|
1326 | else |
---|
1327 | $this->_out('/Encoding /WinAnsiEncoding'); |
---|
1328 | } |
---|
1329 | $this->_out('>>'); |
---|
1330 | $this->_out('endobj'); |
---|
1331 | //Widths |
---|
1332 | $this->_newobj(); |
---|
1333 | $cw=&$font['cw']; |
---|
1334 | $s='['; |
---|
1335 | for($i=32;$i<=255;$i++) |
---|
1336 | $s.=$cw[chr($i)].' '; |
---|
1337 | $this->_out($s.']'); |
---|
1338 | $this->_out('endobj'); |
---|
1339 | //Descriptor |
---|
1340 | $this->_newobj(); |
---|
1341 | $s='<</Type /FontDescriptor /FontName /'.$name; |
---|
1342 | foreach($font['desc'] as $k=>$v) |
---|
1343 | $s.=' /'.$k.' '.$v; |
---|
1344 | $file=$font['file']; |
---|
1345 | if($file) |
---|
1346 | $s.=' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R'; |
---|
1347 | $this->_out($s.'>>'); |
---|
1348 | $this->_out('endobj'); |
---|
1349 | } |
---|
1350 | else |
---|
1351 | { |
---|
1352 | //Allow for additional types |
---|
1353 | $mtd='_put'.strtolower($type); |
---|
1354 | if(!method_exists($this,$mtd)) |
---|
1355 | $this->Error('Unsupported font type: '.$type); |
---|
1356 | $this->$mtd($font); |
---|
1357 | } |
---|
1358 | } |
---|
1359 | } |
---|
1360 | |
---|
1361 | function _putimages() |
---|
1362 | { |
---|
1363 | $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; |
---|
1364 | reset($this->images); |
---|
1365 | while(list($file,$info)=each($this->images)) |
---|
1366 | { |
---|
1367 | $this->_newobj(); |
---|
1368 | $this->images[$file]['n']=$this->n; |
---|
1369 | $this->_out('<</Type /XObject'); |
---|
1370 | $this->_out('/Subtype /Image'); |
---|
1371 | $this->_out('/Width '.$info['w']); |
---|
1372 | $this->_out('/Height '.$info['h']); |
---|
1373 | if($info['cs']=='Indexed') |
---|
1374 | $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]'); |
---|
1375 | else |
---|
1376 | { |
---|
1377 | $this->_out('/ColorSpace /'.$info['cs']); |
---|
1378 | if($info['cs']=='DeviceCMYK') |
---|
1379 | $this->_out('/Decode [1 0 1 0 1 0 1 0]'); |
---|
1380 | } |
---|
1381 | $this->_out('/BitsPerComponent '.$info['bpc']); |
---|
1382 | if(isset($info['f'])) |
---|
1383 | $this->_out('/Filter /'.$info['f']); |
---|
1384 | if(isset($info['parms'])) |
---|
1385 | $this->_out($info['parms']); |
---|
1386 | if(isset($info['trns']) && is_array($info['trns'])) |
---|
1387 | { |
---|
1388 | $trns=''; |
---|
1389 | for($i=0;$i<count($info['trns']);$i++) |
---|
1390 | $trns.=$info['trns'][$i].' '.$info['trns'][$i].' '; |
---|
1391 | $this->_out('/Mask ['.$trns.']'); |
---|
1392 | } |
---|
1393 | $this->_out('/Length '.strlen($info['data']).'>>'); |
---|
1394 | $this->_putstream($info['data']); |
---|
1395 | unset($this->images[$file]['data']); |
---|
1396 | $this->_out('endobj'); |
---|
1397 | //Palette |
---|
1398 | if($info['cs']=='Indexed') |
---|
1399 | { |
---|
1400 | $this->_newobj(); |
---|
1401 | $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal']; |
---|
1402 | $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>'); |
---|
1403 | $this->_putstream($pal); |
---|
1404 | $this->_out('endobj'); |
---|
1405 | } |
---|
1406 | } |
---|
1407 | } |
---|
1408 | |
---|
1409 | function _putxobjectdict() |
---|
1410 | { |
---|
1411 | foreach($this->images as $image) |
---|
1412 | $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); |
---|
1413 | } |
---|
1414 | |
---|
1415 | function _putresourcedict() |
---|
1416 | { |
---|
1417 | $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); |
---|
1418 | $this->_out('/Font <<'); |
---|
1419 | foreach($this->fonts as $font) |
---|
1420 | $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); |
---|
1421 | $this->_out('>>'); |
---|
1422 | $this->_out('/XObject <<'); |
---|
1423 | $this->_putxobjectdict(); |
---|
1424 | $this->_out('>>'); |
---|
1425 | } |
---|
1426 | |
---|
1427 | function _putresources() |
---|
1428 | { |
---|
1429 | $this->_putfonts(); |
---|
1430 | $this->_putimages(); |
---|
1431 | //Resource dictionary |
---|
1432 | $this->offsets[2]=strlen($this->buffer); |
---|
1433 | $this->_out('2 0 obj'); |
---|
1434 | $this->_out('<<'); |
---|
1435 | $this->_putresourcedict(); |
---|
1436 | $this->_out('>>'); |
---|
1437 | $this->_out('endobj'); |
---|
1438 | } |
---|
1439 | |
---|
1440 | function _putinfo() |
---|
1441 | { |
---|
1442 | $this->_out('/Producer '.$this->_textstring('FPDF '.FPDF_VERSION)); |
---|
1443 | if(!empty($this->title)) |
---|
1444 | $this->_out('/Title '.$this->_textstring($this->title)); |
---|
1445 | if(!empty($this->subject)) |
---|
1446 | $this->_out('/Subject '.$this->_textstring($this->subject)); |
---|
1447 | if(!empty($this->author)) |
---|
1448 | $this->_out('/Author '.$this->_textstring($this->author)); |
---|
1449 | if(!empty($this->keywords)) |
---|
1450 | $this->_out('/Keywords '.$this->_textstring($this->keywords)); |
---|
1451 | if(!empty($this->creator)) |
---|
1452 | $this->_out('/Creator '.$this->_textstring($this->creator)); |
---|
1453 | $this->_out('/CreationDate '.$this->_textstring('D:'.date('YmdHis'))); |
---|
1454 | } |
---|
1455 | |
---|
1456 | function _putcatalog() |
---|
1457 | { |
---|
1458 | $this->_out('/Type /Catalog'); |
---|
1459 | $this->_out('/Pages 1 0 R'); |
---|
1460 | if($this->ZoomMode=='fullpage') |
---|
1461 | $this->_out('/OpenAction [3 0 R /Fit]'); |
---|
1462 | elseif($this->ZoomMode=='fullwidth') |
---|
1463 | $this->_out('/OpenAction [3 0 R /FitH null]'); |
---|
1464 | elseif($this->ZoomMode=='real') |
---|
1465 | $this->_out('/OpenAction [3 0 R /XYZ null null 1]'); |
---|
1466 | elseif(!is_string($this->ZoomMode)) |
---|
1467 | $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']'); |
---|
1468 | if($this->LayoutMode=='single') |
---|
1469 | $this->_out('/PageLayout /SinglePage'); |
---|
1470 | elseif($this->LayoutMode=='continuous') |
---|
1471 | $this->_out('/PageLayout /OneColumn'); |
---|
1472 | elseif($this->LayoutMode=='two') |
---|
1473 | $this->_out('/PageLayout /TwoColumnLeft'); |
---|
1474 | } |
---|
1475 | |
---|
1476 | function _putheader() |
---|
1477 | { |
---|
1478 | $this->_out('%PDF-'.$this->PDFVersion); |
---|
1479 | } |
---|
1480 | |
---|
1481 | function _puttrailer() |
---|
1482 | { |
---|
1483 | $this->_out('/Size '.($this->n+1)); |
---|
1484 | $this->_out('/Root '.$this->n.' 0 R'); |
---|
1485 | $this->_out('/Info '.($this->n-1).' 0 R'); |
---|
1486 | } |
---|
1487 | |
---|
1488 | function _enddoc() |
---|
1489 | { |
---|
1490 | $this->_putheader(); |
---|
1491 | $this->_putpages(); |
---|
1492 | $this->_putresources(); |
---|
1493 | //Info |
---|
1494 | $this->_newobj(); |
---|
1495 | $this->_out('<<'); |
---|
1496 | $this->_putinfo(); |
---|
1497 | $this->_out('>>'); |
---|
1498 | $this->_out('endobj'); |
---|
1499 | //Catalog |
---|
1500 | $this->_newobj(); |
---|
1501 | $this->_out('<<'); |
---|
1502 | $this->_putcatalog(); |
---|
1503 | $this->_out('>>'); |
---|
1504 | $this->_out('endobj'); |
---|
1505 | //Cross-ref |
---|
1506 | $o=strlen($this->buffer); |
---|
1507 | $this->_out('xref'); |
---|
1508 | $this->_out('0 '.($this->n+1)); |
---|
1509 | $this->_out('0000000000 65535 f '); |
---|
1510 | for($i=1;$i<=$this->n;$i++) |
---|
1511 | $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i])); |
---|
1512 | //Trailer |
---|
1513 | $this->_out('trailer'); |
---|
1514 | $this->_out('<<'); |
---|
1515 | $this->_puttrailer(); |
---|
1516 | $this->_out('>>'); |
---|
1517 | $this->_out('startxref'); |
---|
1518 | $this->_out($o); |
---|
1519 | $this->_out('%%EOF'); |
---|
1520 | $this->state=3; |
---|
1521 | } |
---|
1522 | |
---|
1523 | function _beginpage($orientation) |
---|
1524 | { |
---|
1525 | $this->page++; |
---|
1526 | $this->pages[$this->page]=''; |
---|
1527 | $this->state=2; |
---|
1528 | $this->x=$this->lMargin; |
---|
1529 | $this->y=$this->tMargin; |
---|
1530 | $this->FontFamily=''; |
---|
1531 | //Page orientation |
---|
1532 | if(!$orientation) |
---|
1533 | $orientation=$this->DefOrientation; |
---|
1534 | else |
---|
1535 | { |
---|
1536 | $orientation=strtoupper($orientation{0}); |
---|
1537 | if($orientation!=$this->DefOrientation) |
---|
1538 | $this->OrientationChanges[$this->page]=true; |
---|
1539 | } |
---|
1540 | if($orientation!=$this->CurOrientation) |
---|
1541 | { |
---|
1542 | //Change orientation |
---|
1543 | if($orientation=='P') |
---|
1544 | { |
---|
1545 | $this->wPt=$this->fwPt; |
---|
1546 | $this->hPt=$this->fhPt; |
---|
1547 | $this->w=$this->fw; |
---|
1548 | $this->h=$this->fh; |
---|
1549 | } |
---|
1550 | else |
---|
1551 | { |
---|
1552 | $this->wPt=$this->fhPt; |
---|
1553 | $this->hPt=$this->fwPt; |
---|
1554 | $this->w=$this->fh; |
---|
1555 | $this->h=$this->fw; |
---|
1556 | } |
---|
1557 | $this->PageBreakTrigger=$this->h-$this->bMargin; |
---|
1558 | $this->CurOrientation=$orientation; |
---|
1559 | } |
---|
1560 | } |
---|
1561 | |
---|
1562 | function _endpage() |
---|
1563 | { |
---|
1564 | //End of page contents |
---|
1565 | $this->state=1; |
---|
1566 | } |
---|
1567 | |
---|
1568 | function _newobj() |
---|
1569 | { |
---|
1570 | //Begin a new object |
---|
1571 | $this->n++; |
---|
1572 | $this->offsets[$this->n]=strlen($this->buffer); |
---|
1573 | $this->_out($this->n.' 0 obj'); |
---|
1574 | } |
---|
1575 | |
---|
1576 | function _dounderline($x,$y,$txt) |
---|
1577 | { |
---|
1578 | //Underline text |
---|
1579 | $up=$this->CurrentFont['up']; |
---|
1580 | $ut=$this->CurrentFont['ut']; |
---|
1581 | $w=$this->GetStringWidth($txt)+$this->ws*substr_count($txt,' '); |
---|
1582 | return sprintf('%.2f %.2f %.2f %.2f re f',$x*$this->k,($this->h-($y-$up/1000*$this->FontSize))*$this->k,$w*$this->k,-$ut/1000*$this->FontSizePt); |
---|
1583 | } |
---|
1584 | |
---|
1585 | function _parsejpg($file) |
---|
1586 | { |
---|
1587 | //Extract info from a JPEG file |
---|
1588 | $a=GetImageSize($file); |
---|
1589 | if(!$a) |
---|
1590 | $this->Error('Missing or incorrect image file: '.$file); |
---|
1591 | if($a[2]!=2) |
---|
1592 | $this->Error('Not a JPEG file: '.$file); |
---|
1593 | if(!isset($a['channels']) || $a['channels']==3) |
---|
1594 | $colspace='DeviceRGB'; |
---|
1595 | elseif($a['channels']==4) |
---|
1596 | $colspace='DeviceCMYK'; |
---|
1597 | else |
---|
1598 | $colspace='DeviceGray'; |
---|
1599 | $bpc=isset($a['bits']) ? $a['bits'] : 8; |
---|
1600 | //Read whole file |
---|
1601 | $f=fopen($file,'rb'); |
---|
1602 | $data=''; |
---|
1603 | while(!feof($f)) |
---|
1604 | $data.=fread($f,4096); |
---|
1605 | fclose($f); |
---|
1606 | return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data); |
---|
1607 | } |
---|
1608 | |
---|
1609 | function _parsepng($file) |
---|
1610 | { |
---|
1611 | //Extract info from a PNG file |
---|
1612 | $f=fopen($file,'rb'); |
---|
1613 | if(!$f) |
---|
1614 | $this->Error('Can\'t open image file: '.$file); |
---|
1615 | //Check signature |
---|
1616 | if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) |
---|
1617 | $this->Error('Not a PNG file: '.$file); |
---|
1618 | //Read header chunk |
---|
1619 | fread($f,4); |
---|
1620 | if(fread($f,4)!='IHDR') |
---|
1621 | $this->Error('Incorrect PNG file: '.$file); |
---|
1622 | $w=$this->_freadint($f); |
---|
1623 | $h=$this->_freadint($f); |
---|
1624 | $bpc=ord(fread($f,1)); |
---|
1625 | if($bpc>8) |
---|
1626 | $this->Error('16-bit depth not supported: '.$file); |
---|
1627 | $ct=ord(fread($f,1)); |
---|
1628 | if($ct==0) |
---|
1629 | $colspace='DeviceGray'; |
---|
1630 | elseif($ct==2) |
---|
1631 | $colspace='DeviceRGB'; |
---|
1632 | elseif($ct==3) |
---|
1633 | $colspace='Indexed'; |
---|
1634 | else |
---|
1635 | $this->Error('Alpha channel not supported: '.$file); |
---|
1636 | if(ord(fread($f,1))!=0) |
---|
1637 | $this->Error('Unknown compression method: '.$file); |
---|
1638 | if(ord(fread($f,1))!=0) |
---|
1639 | $this->Error('Unknown filter method: '.$file); |
---|
1640 | if(ord(fread($f,1))!=0) |
---|
1641 | $this->Error('Interlacing not supported: '.$file); |
---|
1642 | fread($f,4); |
---|
1643 | $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>'; |
---|
1644 | //Scan chunks looking for palette, transparency and image data |
---|
1645 | $pal=''; |
---|
1646 | $trns=''; |
---|
1647 | $data=''; |
---|
1648 | do |
---|
1649 | { |
---|
1650 | $n=$this->_freadint($f); |
---|
1651 | $type=fread($f,4); |
---|
1652 | if($type=='PLTE') |
---|
1653 | { |
---|
1654 | //Read palette |
---|
1655 | $pal=fread($f,$n); |
---|
1656 | fread($f,4); |
---|
1657 | } |
---|
1658 | elseif($type=='tRNS') |
---|
1659 | { |
---|
1660 | //Read transparency info |
---|
1661 | $t=fread($f,$n); |
---|
1662 | if($ct==0) |
---|
1663 | $trns=array(ord(substr($t,1,1))); |
---|
1664 | elseif($ct==2) |
---|
1665 | $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1))); |
---|
1666 | else |
---|
1667 | { |
---|
1668 | $pos=strpos($t,chr(0)); |
---|
1669 | if($pos!==false) |
---|
1670 | $trns=array($pos); |
---|
1671 | } |
---|
1672 | fread($f,4); |
---|
1673 | } |
---|
1674 | elseif($type=='IDAT') |
---|
1675 | { |
---|
1676 | //Read image data block |
---|
1677 | $data.=fread($f,$n); |
---|
1678 | fread($f,4); |
---|
1679 | } |
---|
1680 | elseif($type=='IEND') |
---|
1681 | break; |
---|
1682 | else |
---|
1683 | fread($f,$n+4); |
---|
1684 | } |
---|
1685 | while($n); |
---|
1686 | if($colspace=='Indexed' && empty($pal)) |
---|
1687 | $this->Error('Missing palette in '.$file); |
---|
1688 | fclose($f); |
---|
1689 | return array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$data); |
---|
1690 | } |
---|
1691 | |
---|
1692 | function _parsegif2($gs_file,$gs_type,$gs_path,$gs_maxframe) |
---|
1693 | { |
---|
1694 | include_once('GifSplit.class.php'); |
---|
1695 | $sg = new GifSplit($gs_file, $gs_type, $gs_path,$gs_maxframe,1); |
---|
1696 | return ($sg->getfilelist()); |
---|
1697 | } |
---|
1698 | |
---|
1699 | function _parsegif($file) |
---|
1700 | { |
---|
1701 | require_once "gif.php"; // Classes GIF en pur PHP de Yamasoft (http://www.yamasoft.com/) |
---|
1702 | |
---|
1703 | $h=0; |
---|
1704 | $w=0; |
---|
1705 | |
---|
1706 | $gif= new CGIF(); |
---|
1707 | |
---|
1708 | if (!$gif->loadFile($file, 0)) { |
---|
1709 | $this->Error("GIF parser : unable to open file $file"); |
---|
1710 | } |
---|
1711 | |
---|
1712 | if($gif->m_img->m_gih->m_bLocalClr) { |
---|
1713 | $nColors = $gif->m_img->m_gih->m_nTableSize; |
---|
1714 | $pal = $gif->m_img->m_gih->m_colorTable->toString(); |
---|
1715 | if($bgColor != -1) { |
---|
1716 | $bgColor = $this->m_img->m_gih->m_colorTable->colorIndex($bgColor); |
---|
1717 | } |
---|
1718 | $colspace='Indexed'; |
---|
1719 | } elseif($gif->m_gfh->m_bGlobalClr) { |
---|
1720 | $nColors = $gif->m_gfh->m_nTableSize; |
---|
1721 | $pal = $gif->m_gfh->m_colorTable->toString(); |
---|
1722 | if($bgColor != -1) { |
---|
1723 | $bgColor = $gif->m_gfh->m_colorTable->colorIndex($bgColor); |
---|
1724 | } |
---|
1725 | $colspace='Indexed'; |
---|
1726 | } else { |
---|
1727 | $nColors = 0; |
---|
1728 | $bgColor = -1; |
---|
1729 | $colspace='DeviceGray'; |
---|
1730 | $pal=''; |
---|
1731 | } |
---|
1732 | |
---|
1733 | $trns=''; |
---|
1734 | if($gif->m_img->m_bTrans && ($nColors > 0)) { |
---|
1735 | $trns=array($gif->m_img->m_nTrans); |
---|
1736 | } |
---|
1737 | |
---|
1738 | $data=$gif->m_img->m_data; |
---|
1739 | $w=$gif->m_gfh->m_nWidth; |
---|
1740 | $h=$gif->m_gfh->m_nHeight; |
---|
1741 | |
---|
1742 | if($colspace=='Indexed' and empty($pal)) |
---|
1743 | $this->Error('Missing palette in '.$file); |
---|
1744 | |
---|
1745 | $gif=''; |
---|
1746 | |
---|
1747 | if ($this->compress) { |
---|
1748 | $data=gzcompress($data); |
---|
1749 | // Attention : |
---|
1750 | // - on vient de recompresser de façon globale les données de l'image |
---|
1751 | // GIF, il n'y a donc plus lieu d'utiliser une quelconque prediction |
---|
1752 | // au décodage Flate du PDF -> Predictor=1 et non plus 15 |
---|
1753 | // - bpc=8 dans tous les cas car décodage du GIF à raison de 1 pixel par octet |
---|
1754 | // - Colors=1 car GIF toujours sur 8 bits maxi (en couleur et niveaux de gris) |
---|
1755 | $parms='/DecodeParms <</Predictor 1 /Colors 1 /BitsPerComponent 8>>'; |
---|
1756 | return array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, |
---|
1757 | 'bpc'=>8, 'f'=>'FlateDecode', 'parms'=>$parms, |
---|
1758 | 'pal'=>$pal, 'trns'=>$trns, 'data'=>$data); |
---|
1759 | } else { |
---|
1760 | return array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, |
---|
1761 | 'bpc'=>8, 'pal'=>$pal, 'trns'=>$trns, |
---|
1762 | 'data'=>$data); |
---|
1763 | } |
---|
1764 | } |
---|
1765 | |
---|
1766 | |
---|
1767 | |
---|
1768 | function _freadint($f) |
---|
1769 | { |
---|
1770 | //Read a 4-byte integer from file |
---|
1771 | $a=unpack('Ni',fread($f,4)); |
---|
1772 | return $a['i']; |
---|
1773 | } |
---|
1774 | |
---|
1775 | function _textstring($s) |
---|
1776 | { |
---|
1777 | //Format a text string |
---|
1778 | return '('.$this->_escape($s).')'; |
---|
1779 | } |
---|
1780 | |
---|
1781 | function _escape($s) |
---|
1782 | { |
---|
1783 | //Add \ before \, ( and ) |
---|
1784 | return str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$s))); |
---|
1785 | } |
---|
1786 | |
---|
1787 | function _putstream($s) |
---|
1788 | { |
---|
1789 | $this->_out('stream'); |
---|
1790 | $this->_out($s); |
---|
1791 | $this->_out('endstream'); |
---|
1792 | } |
---|
1793 | |
---|
1794 | function _out($s) |
---|
1795 | { |
---|
1796 | //Add a line to the document |
---|
1797 | if($this->state==2) |
---|
1798 | $this->pages[$this->page].=$s."\n"; |
---|
1799 | else |
---|
1800 | $this->buffer.=$s."\n"; |
---|
1801 | } |
---|
1802 | |
---|
1803 | |
---|
1804 | //End of class |
---|
1805 | } |
---|
1806 | |
---|
1807 | //Handle special IE contype request |
---|
1808 | if(isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT']=='contype') |
---|
1809 | { |
---|
1810 | header('Content-Type: application/pdf'); |
---|
1811 | exit; |
---|
1812 | } |
---|
1813 | |
---|
1814 | |
---|
1815 | } |
---|
1816 | ?> |
---|