Changeset 19716 for branches/version-2_5-dev/data/module/fpdf/fpdf.php
- Timestamp:
- 2010/12/11 12:15:20 (13 years ago)
- Location:
- branches/version-2_5-dev/data/module/fpdf
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/module/fpdf/fpdf.php
r17259 r19716 1 1 <?php 2 2 /******************************************************************************* 3 * Software: FPDF * 4 * Version: 1.53 * 5 * Date: 2004-12-31 * 6 * Author: Olivier PLATHEY * 7 * License: Freeware * 3 * FPDF * 8 4 * * 9 * You may use, modify and redistribute this software as you wish. * 5 * Version: 1.6 * 6 * Date: 2008-08-03 * 7 * Author: Olivier PLATHEY * 10 8 *******************************************************************************/ 11 9 12 if(!class_exists('FPDF')) 13 { 14 define('FPDF_VERSION','1.53'); 10 define('FPDF_VERSION','1.6'); 15 11 16 12 class FPDF 17 13 { 18 //Private properties19 14 var $page; //current page number 20 15 var $n; //current object number … … 24 19 var $state; //current document state 25 20 var $compress; //compression flag 21 var $k; //scale factor (number of points in user unit) 26 22 var $DefOrientation; //default orientation 27 23 var $CurOrientation; //current orientation 28 var $ OrientationChanges; //array indicating orientation changes29 var $ k; //scale factor (number of points in user unit)30 var $ fwPt,$fhPt; //dimensions of page format in points31 var $ fw,$fh; //dimensions of page format in user unit32 var $wPt,$hPt; // current dimensions ofpage in points33 var $w,$h; // current dimensions ofpage in user unit24 var $PageFormats; //available page formats 25 var $DefPageFormat; //default page format 26 var $CurPageFormat; //current page format 27 var $PageSizes; //array storing non-default page sizes 28 var $wPt,$hPt; //dimensions of current page in points 29 var $w,$h; //dimensions of current page in user unit 34 30 var $lMargin; //left margin 35 31 var $tMargin; //top margin … … 37 33 var $bMargin; //page break margin 38 34 var $cMargin; //cell margin 39 var $x,$y; //current position in user unit for cell positioning40 var $lasth; //height of last cell printed35 var $x,$y; //current position in user unit 36 var $lasth; //height of last printed cell 41 37 var $LineWidth; //line width in user unit 42 38 var $CoreFonts; //array of standard font names … … 44 40 var $FontFiles; //array of font files 45 41 var $diffs; //array of encoding differences 46 var $images; //array of used images47 var $PageLinks; //array of links in pages48 var $links; //array of internal links49 42 var $FontFamily; //current font family 50 43 var $FontStyle; //current font style … … 58 51 var $ColorFlag; //indicates whether fill and text colors are different 59 52 var $ws; //word spacing 53 var $images; //array of used images 54 var $PageLinks; //array of links in pages 55 var $links; //array of internal links 60 56 var $AutoPageBreak; //automatic page breaking 61 57 var $PageBreakTrigger; //threshold used to trigger page breaks 58 var $InHeader; //flag set when processing header 62 59 var $InFooter; //flag set when processing footer 63 60 var $ZoomMode; //zoom display mode … … 76 73 * * 77 74 *******************************************************************************/ 78 function FPDF($orientation='P', $unit='mm',$format='A4')75 function FPDF($orientation='P', $unit='mm', $format='A4') 79 76 { 80 77 //Some checks … … 85 82 $this->buffer=''; 86 83 $this->pages=array(); 87 $this-> OrientationChanges=array();84 $this->PageSizes=array(); 88 85 $this->state=0; 89 86 $this->fonts=array(); … … 92 89 $this->images=array(); 93 90 $this->links=array(); 91 $this->InHeader=false; 94 92 $this->InFooter=false; 95 93 $this->lasth=0; … … 104 102 $this->ws=0; 105 103 //Standard fonts 106 $this->CoreFonts=array('courier'=>'Courier', 'courierB'=>'Courier-Bold','courierI'=>'Courier-Oblique','courierBI'=>'Courier-BoldOblique',107 'helvetica'=>'Helvetica', 'helveticaB'=>'Helvetica-Bold','helveticaI'=>'Helvetica-Oblique','helveticaBI'=>'Helvetica-BoldOblique',108 'times'=>'Times-Roman', 'timesB'=>'Times-Bold','timesI'=>'Times-Italic','timesBI'=>'Times-BoldItalic',109 'symbol'=>'Symbol', 'zapfdingbats'=>'ZapfDingbats');104 $this->CoreFonts=array('courier'=>'Courier', 'courierB'=>'Courier-Bold', 'courierI'=>'Courier-Oblique', 'courierBI'=>'Courier-BoldOblique', 105 'helvetica'=>'Helvetica', 'helveticaB'=>'Helvetica-Bold', 'helveticaI'=>'Helvetica-Oblique', 'helveticaBI'=>'Helvetica-BoldOblique', 106 'times'=>'Times-Roman', 'timesB'=>'Times-Bold', 'timesI'=>'Times-Italic', 'timesBI'=>'Times-BoldItalic', 107 'symbol'=>'Symbol', 'zapfdingbats'=>'ZapfDingbats'); 110 108 //Scale factor 111 109 if($unit=='pt') … … 120 118 $this->Error('Incorrect unit: '.$unit); 121 119 //Page format 120 $this->PageFormats=array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28), 121 'letter'=>array(612,792), 'legal'=>array(612,1008)); 122 122 if(is_string($format)) 123 { 124 $format=strtolower($format); 125 if($format=='a3') 126 $format=array(841.89,1190.55); 127 elseif($format=='a4') 128 $format=array(595.28,841.89); 129 elseif($format=='a5') 130 $format=array(420.94,595.28); 131 elseif($format=='letter') 132 $format=array(612,792); 133 elseif($format=='legal') 134 $format=array(612,1008); 135 else 136 $this->Error('Unknown page format: '.$format); 137 $this->fwPt=$format[0]; 138 $this->fhPt=$format[1]; 139 } 140 else 141 { 142 $this->fwPt=$format[0]*$this->k; 143 $this->fhPt=$format[1]*$this->k; 144 } 145 $this->fw=$this->fwPt/$this->k; 146 $this->fh=$this->fhPt/$this->k; 123 $format=$this->_getpageformat($format); 124 $this->DefPageFormat=$format; 125 $this->CurPageFormat=$format; 147 126 //Page orientation 148 127 $orientation=strtolower($orientation); … … 150 129 { 151 130 $this->DefOrientation='P'; 152 $this->w Pt=$this->fwPt;153 $this->h Pt=$this->fhPt;131 $this->w=$this->DefPageFormat[0]; 132 $this->h=$this->DefPageFormat[1]; 154 133 } 155 134 elseif($orientation=='l' || $orientation=='landscape') 156 135 { 157 136 $this->DefOrientation='L'; 158 $this->w Pt=$this->fhPt;159 $this->h Pt=$this->fwPt;137 $this->w=$this->DefPageFormat[1]; 138 $this->h=$this->DefPageFormat[0]; 160 139 } 161 140 else 162 141 $this->Error('Incorrect orientation: '.$orientation); 163 142 $this->CurOrientation=$this->DefOrientation; 164 $this->w =$this->wPt/$this->k;165 $this->h =$this->hPt/$this->k;143 $this->wPt=$this->w*$this->k; 144 $this->hPt=$this->h*$this->k; 166 145 //Page margins (1 cm) 167 146 $margin=28.35/$this->k; … … 181 160 } 182 161 183 function SetMargins($left, $top,$right=-1)162 function SetMargins($left, $top, $right=null) 184 163 { 185 164 //Set left, top and right margins 186 165 $this->lMargin=$left; 187 166 $this->tMargin=$top; 188 if($right== -1)167 if($right===null) 189 168 $right=$left; 190 169 $this->rMargin=$right; … … 211 190 } 212 191 213 function SetAutoPageBreak($auto, $margin=0)192 function SetAutoPageBreak($auto, $margin=0) 214 193 { 215 194 //Set auto page break mode and triggering margin … … 219 198 } 220 199 221 function SetDisplayMode($zoom, $layout='continuous')200 function SetDisplayMode($zoom, $layout='continuous') 222 201 { 223 202 //Set display mode in viewer … … 241 220 } 242 221 243 function SetTitle($title )222 function SetTitle($title, $isUTF8=false) 244 223 { 245 224 //Title of document 225 if($isUTF8) 226 $title=$this->_UTF8toUTF16($title); 246 227 $this->title=$title; 247 228 } 248 229 249 function SetSubject($subject )230 function SetSubject($subject, $isUTF8=false) 250 231 { 251 232 //Subject of document 233 if($isUTF8) 234 $subject=$this->_UTF8toUTF16($subject); 252 235 $this->subject=$subject; 253 236 } 254 237 255 function SetAuthor($author )238 function SetAuthor($author, $isUTF8=false) 256 239 { 257 240 //Author of document 241 if($isUTF8) 242 $author=$this->_UTF8toUTF16($author); 258 243 $this->author=$author; 259 244 } 260 245 261 function SetKeywords($keywords )246 function SetKeywords($keywords, $isUTF8=false) 262 247 { 263 248 //Keywords of document 249 if($isUTF8) 250 $keywords=$this->_UTF8toUTF16($keywords); 264 251 $this->keywords=$keywords; 265 252 } 266 253 267 function SetCreator($creator )254 function SetCreator($creator, $isUTF8=false) 268 255 { 269 256 //Creator of document 257 if($isUTF8) 258 $creator=$this->_UTF8toUTF16($creator); 270 259 $this->creator=$creator; 271 260 } … … 280 269 { 281 270 //Fatal error 282 die('< B>FPDF error: </B>'.$msg);271 die('<b>FPDF error:</b> '.$msg); 283 272 } 284 273 … … 306 295 } 307 296 308 function AddPage($orientation='' )297 function AddPage($orientation='', $format='') 309 298 { 310 299 //Start a new page … … 329 318 } 330 319 //Start new page 331 $this->_beginpage($orientation );320 $this->_beginpage($orientation,$format); 332 321 //Set line cap style to square 333 322 $this->_out('2 J'); 334 323 //Set line width 335 324 $this->LineWidth=$lw; 336 $this->_out(sprintf('%.2 fw',$lw*$this->k));325 $this->_out(sprintf('%.2F w',$lw*$this->k)); 337 326 //Set font 338 327 if($family) … … 348 337 $this->ColorFlag=$cf; 349 338 //Page header 339 $this->InHeader=true; 350 340 $this->Header(); 341 $this->InHeader=false; 351 342 //Restore line width 352 343 if($this->LineWidth!=$lw) 353 344 { 354 345 $this->LineWidth=$lw; 355 $this->_out(sprintf('%.2 fw',$lw*$this->k));346 $this->_out(sprintf('%.2F w',$lw*$this->k)); 356 347 } 357 348 //Restore font … … 389 380 } 390 381 391 function SetDrawColor($r, $g=-1,$b=-1)382 function SetDrawColor($r, $g=null, $b=null) 392 383 { 393 384 //Set color for all stroking operations 394 if(($r==0 && $g==0 && $b==0) || $g== -1)395 $this->DrawColor=sprintf('%.3 fG',$r/255);396 else 397 $this->DrawColor=sprintf('%.3 f %.3f %.3fRG',$r/255,$g/255,$b/255);385 if(($r==0 && $g==0 && $b==0) || $g===null) 386 $this->DrawColor=sprintf('%.3F G',$r/255); 387 else 388 $this->DrawColor=sprintf('%.3F %.3F %.3F RG',$r/255,$g/255,$b/255); 398 389 if($this->page>0) 399 390 $this->_out($this->DrawColor); 400 391 } 401 392 402 function SetFillColor($r, $g=-1,$b=-1)393 function SetFillColor($r, $g=null, $b=null) 403 394 { 404 395 //Set color for all filling operations 405 if(($r==0 && $g==0 && $b==0) || $g== -1)406 $this->FillColor=sprintf('%.3 fg',$r/255);407 else 408 $this->FillColor=sprintf('%.3 f %.3f %.3frg',$r/255,$g/255,$b/255);396 if(($r==0 && $g==0 && $b==0) || $g===null) 397 $this->FillColor=sprintf('%.3F g',$r/255); 398 else 399 $this->FillColor=sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255); 409 400 $this->ColorFlag=($this->FillColor!=$this->TextColor); 410 401 if($this->page>0) … … 412 403 } 413 404 414 function SetTextColor($r, $g=-1,$b=-1)405 function SetTextColor($r, $g=null, $b=null) 415 406 { 416 407 //Set color for text 417 if(($r==0 && $g==0 && $b==0) || $g== -1)418 $this->TextColor=sprintf('%.3 fg',$r/255);419 else 420 $this->TextColor=sprintf('%.3 f %.3f %.3frg',$r/255,$g/255,$b/255);408 if(($r==0 && $g==0 && $b==0) || $g===null) 409 $this->TextColor=sprintf('%.3F g',$r/255); 410 else 411 $this->TextColor=sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255); 421 412 $this->ColorFlag=($this->FillColor!=$this->TextColor); 422 413 } … … 430 421 $l=strlen($s); 431 422 for($i=0;$i<$l;$i++) 432 $w+=$cw[$s {$i}];423 $w+=$cw[$s[$i]]; 433 424 return $w*$this->FontSize/1000; 434 425 } … … 439 430 $this->LineWidth=$width; 440 431 if($this->page>0) 441 $this->_out(sprintf('%.2 fw',$width*$this->k));442 } 443 444 function Line($x1, $y1,$x2,$y2)432 $this->_out(sprintf('%.2F w',$width*$this->k)); 433 } 434 435 function Line($x1, $y1, $x2, $y2) 445 436 { 446 437 //Draw a line 447 $this->_out(sprintf('%.2 f %.2f m %.2f %.2fl S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k));448 } 449 450 function Rect($x, $y,$w,$h,$style='')438 $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)); 439 } 440 441 function Rect($x, $y, $w, $h, $style='') 451 442 { 452 443 //Draw a rectangle … … 457 448 else 458 449 $op='S'; 459 $this->_out(sprintf('%.2 f %.2f %.2f %.2fre %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));460 } 461 462 function AddFont($family, $style='',$file='')450 $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); 451 } 452 453 function AddFont($family, $style='', $file='') 463 454 { 464 455 //Add a TrueType or Type1 font … … 473 464 $fontkey=$family.$style; 474 465 if(isset($this->fonts[$fontkey])) 475 $this->Error('Font already added: '.$family.' '.$style);466 return; 476 467 include($this->_getfontpath().$file); 477 468 if(!isset($name)) 478 469 $this->Error('Could not include font definition file'); 479 470 $i=count($this->fonts)+1; 480 $this->fonts[$fontkey]=array('i'=>$i, 'type'=>$type,'name'=>$name,'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw,'enc'=>$enc,'file'=>$file);471 $this->fonts[$fontkey]=array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file); 481 472 if($diff) 482 473 { … … 504 495 $this->FontFiles[$file]=array('length1'=>$originalsize); 505 496 else 506 $this->FontFiles[$file]=array('length1'=>$size1, 'length2'=>$size2);507 } 508 } 509 510 function SetFont($family, $style='',$size=0)497 $this->FontFiles[$file]=array('length1'=>$size1, 'length2'=>$size2); 498 } 499 } 500 501 function SetFont($family, $style='', $size=0) 511 502 { 512 503 //Select a font; size given in points … … 553 544 } 554 545 $i=count($this->fonts)+1; 555 $this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'up'=>-100,'ut'=>50,'cw'=>$fpdf_charwidths[$fontkey]); 546 $name=$this->CoreFonts[$fontkey]; 547 $cw=$fpdf_charwidths[$fontkey]; 548 $this->fonts[$fontkey]=array('i'=>$i, 'type'=>'core', 'name'=>$name, 'up'=>-100, 'ut'=>50, 'cw'=>$cw); 556 549 } 557 550 else … … 565 558 $this->CurrentFont=&$this->fonts[$fontkey]; 566 559 if($this->page>0) 567 $this->_out(sprintf('BT /F%d %.2 fTf ET',$this->CurrentFont['i'],$this->FontSizePt));560 $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); 568 561 } 569 562 … … 576 569 $this->FontSize=$size/$this->k; 577 570 if($this->page>0) 578 $this->_out(sprintf('BT /F%d %.2 fTf ET',$this->CurrentFont['i'],$this->FontSizePt));571 $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); 579 572 } 580 573 … … 583 576 //Create a new internal link 584 577 $n=count($this->links)+1; 585 $this->links[$n]=array(0, 0);578 $this->links[$n]=array(0, 0); 586 579 return $n; 587 580 } 588 581 589 function SetLink($link, $y=0,$page=-1)582 function SetLink($link, $y=0, $page=-1) 590 583 { 591 584 //Set destination of internal link … … 594 587 if($page==-1) 595 588 $page=$this->page; 596 $this->links[$link]=array($page, $y);597 } 598 599 function Link($x, $y,$w,$h,$link)589 $this->links[$link]=array($page, $y); 590 } 591 592 function Link($x, $y, $w, $h, $link) 600 593 { 601 594 //Put a link on the page 602 $this->PageLinks[$this->page][]=array($x*$this->k, $this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link);603 } 604 605 function Text($x, $y,$txt)595 $this->PageLinks[$this->page][]=array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link); 596 } 597 598 function Text($x, $y, $txt) 606 599 { 607 600 //Output a string 608 $s=sprintf('BT %.2 f %.2fTd (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));601 $s=sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); 609 602 if($this->underline && $txt!='') 610 603 $s.=' '.$this->_dounderline($x,$y,$txt); … … 620 613 } 621 614 622 function Cell($w, $h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='')615 function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') 623 616 { 624 617 //Output a cell 625 618 $k=$this->k; 626 if($this->y+$h>$this->PageBreakTrigger && !$this->In Footer && $this->AcceptPageBreak())619 if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) 627 620 { 628 621 //Automatic page break … … 634 627 $this->_out('0 Tw'); 635 628 } 636 $this->AddPage($this->CurOrientation );629 $this->AddPage($this->CurOrientation,$this->CurPageFormat); 637 630 $this->x=$x; 638 631 if($ws>0) 639 632 { 640 633 $this->ws=$ws; 641 $this->_out(sprintf('%.3 fTw',$ws*$k));634 $this->_out(sprintf('%.3F Tw',$ws*$k)); 642 635 } 643 636 } … … 645 638 $w=$this->w-$this->rMargin-$this->x; 646 639 $s=''; 647 if($fill ==1|| $border==1)648 { 649 if($fill ==1)640 if($fill || $border==1) 641 { 642 if($fill) 650 643 $op=($border==1) ? 'B' : 'f'; 651 644 else 652 645 $op='S'; 653 $s=sprintf('%.2 f %.2f %.2f %.2fre %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);646 $s=sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); 654 647 } 655 648 if(is_string($border)) … … 658 651 $y=$this->y; 659 652 if(strpos($border,'L')!==false) 660 $s.=sprintf('%.2 f %.2f m %.2f %.2fl S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);653 $s.=sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); 661 654 if(strpos($border,'T')!==false) 662 $s.=sprintf('%.2 f %.2f m %.2f %.2fl S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);655 $s.=sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); 663 656 if(strpos($border,'R')!==false) 664 $s.=sprintf('%.2 f %.2f m %.2f %.2fl S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);657 $s.=sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); 665 658 if(strpos($border,'B')!==false) 666 $s.=sprintf('%.2 f %.2f m %.2f %.2fl S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);659 $s.=sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); 667 660 } 668 661 if($txt!=='') … … 677 670 $s.='q '.$this->TextColor.' '; 678 671 $txt2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt))); 679 $s.=sprintf('BT %.2 f %.2fTd (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt2);672 $s.=sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt2); 680 673 if($this->underline) 681 674 $s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); … … 699 692 } 700 693 701 function MultiCell($w, $h,$txt,$border=0,$align='J',$fill=0, $ln = 2)694 function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false) 702 695 { 703 696 //Output text with automatic or explicit line breaks … … 735 728 $ns=0; 736 729 $nl=1; 737 $this->rise_h = 0; //³vZp738 739 730 while($i<$nb) 740 731 { 741 732 //Get next character 742 $c=$s {$i};733 $c=$s[$i]; 743 734 if($c=="\n") 744 735 { … … 756 747 $ns=0; 757 748 $nl++; 758 $this->rise_h += $h; //³vZp759 760 749 if($border && $nl==2) 761 750 $b=$b2; … … 788 777 { 789 778 $this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; 790 $this->_out(sprintf('%.3 fTw',$this->ws*$this->k));779 $this->_out(sprintf('%.3F Tw',$this->ws*$this->k)); 791 780 } 792 781 $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); 793 782 $i=$sep+1; 794 783 } 795 $this->rise_h += $h; //³vZp796 784 $sep=-1; 797 785 $j=$i; … … 813 801 if($border && strpos($border,'B')!==false) 814 802 $b.='B'; 815 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,$ln,$align,$fill); 816 $this->rise_h += $h; //ÁªÌ³ðvZ 817 //üsȵÝè©ÂA³ªKè̳ÈãÅ êÎY²ðÝèµÈ¨·B 818 if($ln == 0 and $h < $this->rise_h) { 819 $this->y = $this->y - $this->rise_h + $h; 820 } 821 822 //$this->x=$this->lMargin; 823 } 824 825 function Write($h,$txt,$link='') 803 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 804 $this->x=$this->lMargin; 805 } 806 807 function Write($h, $txt, $link='') 826 808 { 827 809 //Output text in flowing mode … … 839 821 { 840 822 //Get next character 841 $c=$s {$i};823 $c=$s[$i]; 842 824 if($c=="\n") 843 825 { … … 904 886 } 905 887 906 function Image($file,$x,$y,$w=0,$h=0,$type='',$link='') 888 function Ln($h=null) 889 { 890 //Line feed; default value is last cell height 891 $this->x=$this->lMargin; 892 if($h===null) 893 $this->y+=$this->lasth; 894 else 895 $this->y+=$h; 896 } 897 898 function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='') 907 899 { 908 900 //Put an image on the page 909 901 if(!isset($this->images[$file])) 910 902 { 911 //First use of image, get info903 //First use of this image, get info 912 904 if($type=='') 913 905 { … … 918 910 } 919 911 $type=strtolower($type); 920 $mqr=get_magic_quotes_runtime(); 921 set_magic_quotes_runtime(0); 922 if($type=='jpg' || $type=='jpeg') 923 $info=$this->_parsejpg($file); 924 elseif($type=='png') 925 $info=$this->_parsepng($file); 926 else 927 { 928 //Allow for additional formats 929 $mtd='_parse'.$type; 930 if(!method_exists($this,$mtd)) 931 $this->Error('Unsupported image type: '.$type); 932 $info=$this->$mtd($file); 933 } 934 set_magic_quotes_runtime($mqr); 912 if($type=='jpeg') 913 $type='jpg'; 914 $mtd='_parse'.$type; 915 if(!method_exists($this,$mtd)) 916 $this->Error('Unsupported image type: '.$type); 917 $info=$this->$mtd($file); 935 918 $info['i']=count($this->images)+1; 936 919 $this->images[$file]=$info; … … 945 928 $h=$info['h']/$this->k; 946 929 } 947 if($w==0)930 elseif($w==0) 948 931 $w=$h*$info['w']/$info['h']; 949 if($h==0)932 elseif($h==0) 950 933 $h=$w*$info['h']/$info['w']; 951 $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'])); 934 //Flowing mode 935 if($y===null) 936 { 937 if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) 938 { 939 //Automatic page break 940 $x2=$this->x; 941 $this->AddPage($this->CurOrientation,$this->CurPageFormat); 942 $this->x=$x2; 943 } 944 $y=$this->y; 945 $this->y+=$h; 946 } 947 if($x===null) 948 $x=$this->x; 949 $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'])); 952 950 if($link) 953 951 $this->Link($x,$y,$w,$h,$link); 954 }955 956 function Ln($h='')957 {958 //Line feed; default value is last cell height959 $this->x=$this->lMargin;960 if(is_string($h))961 $this->y+=$this->lasth;962 else963 $this->y+=$h;964 952 } 965 953 … … 995 983 } 996 984 997 function SetXY($x, $y)985 function SetXY($x, $y) 998 986 { 999 987 //Set x and y positions … … 1002 990 } 1003 991 1004 function Output($name='', $dest='')992 function Output($name='', $dest='') 1005 993 { 1006 994 //Output PDF to some destination 1007 //Finish document if necessary1008 995 if($this->state<3) 1009 996 $this->Close(); 1010 //Normalize parameters1011 if(is_bool($dest))1012 $dest=$dest ? 'D' : 'F';1013 997 $dest=strtoupper($dest); 1014 998 if($dest=='') … … 1026 1010 case 'I': 1027 1011 //Send to standard output 1028 if(ob_get_ contents())1012 if(ob_get_length()) 1029 1013 $this->Error('Some data has already been output, can\'t send PDF file'); 1030 1014 if(php_sapi_name()!='cli') 1031 1015 { 1032 1016 //We send to a browser 1033 if(isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) { header('Pragma:'); }1034 1017 header('Content-Type: application/pdf'); 1035 1018 if(headers_sent()) 1036 $this->Error('Some data has already been output to browser, can\'t send PDF file');1019 $this->Error('Some data has already been output, can\'t send PDF file'); 1037 1020 header('Content-Length: '.strlen($this->buffer)); 1038 header('Content-disposition: inline; filename="'.$name.'"'); 1021 header('Content-Disposition: inline; filename="'.$name.'"'); 1022 header('Cache-Control: private, max-age=0, must-revalidate'); 1023 header('Pragma: public'); 1024 ini_set('zlib.output_compression','0'); 1039 1025 } 1040 1026 echo $this->buffer; … … 1042 1028 case 'D': 1043 1029 //Download file 1044 if(ob_get_ contents())1030 if(ob_get_length()) 1045 1031 $this->Error('Some data has already been output, can\'t send PDF file'); 1046 if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) { 1047 header('Pragma:'); 1048 header('Content-Type: application/force-download'); 1049 } 1050 else 1051 header('Content-Type: application/octet-stream'); 1032 header('Content-Type: application/x-download'); 1052 1033 if(headers_sent()) 1053 $this->Error('Some data has already been output to browser, can\'t send PDF file');1034 $this->Error('Some data has already been output, can\'t send PDF file'); 1054 1035 header('Content-Length: '.strlen($this->buffer)); 1055 header('Content-disposition: attachment; filename="'.$name.'"'); 1036 header('Content-Disposition: attachment; filename="'.$name.'"'); 1037 header('Cache-Control: private, max-age=0, must-revalidate'); 1038 header('Pragma: public'); 1039 ini_set('zlib.output_compression','0'); 1056 1040 echo $this->buffer; 1057 1041 break; … … 1080 1064 function _dochecks() 1081 1065 { 1082 //Check for locale-related bug 1083 if(1.1==1) 1084 $this->Error('Don\'t alter the locale before including class file'); 1085 //Check for decimal separator 1086 if(sprintf('%.1f',1.0)!='1.0') 1087 setlocale(LC_NUMERIC,'C'); 1066 //Check availability of %F 1067 if(sprintf('%.1F',1.0)!='1.0') 1068 $this->Error('This version of PHP is not supported'); 1069 //Check mbstring overloading 1070 if(ini_get('mbstring.func_overload') & 2) 1071 $this->Error('mbstring overloading must be disabled'); 1072 //Disable runtime magic quotes 1073 if(get_magic_quotes_runtime()) 1074 @set_magic_quotes_runtime(0); 1075 } 1076 1077 function _getpageformat($format) 1078 { 1079 $format=strtolower($format); 1080 if(!isset($this->PageFormats[$format])) 1081 $this->Error('Unknown page format: '.$format); 1082 $a=$this->PageFormats[$format]; 1083 return array($a[0]/$this->k, $a[1]/$this->k); 1088 1084 } 1089 1085 … … 1095 1091 } 1096 1092 1093 function _beginpage($orientation, $format) 1094 { 1095 $this->page++; 1096 $this->pages[$this->page]=''; 1097 $this->state=2; 1098 $this->x=$this->lMargin; 1099 $this->y=$this->tMargin; 1100 $this->FontFamily=''; 1101 //Check page size 1102 if($orientation=='') 1103 $orientation=$this->DefOrientation; 1104 else 1105 $orientation=strtoupper($orientation[0]); 1106 if($format=='') 1107 $format=$this->DefPageFormat; 1108 else 1109 { 1110 if(is_string($format)) 1111 $format=$this->_getpageformat($format); 1112 } 1113 if($orientation!=$this->CurOrientation || $format[0]!=$this->CurPageFormat[0] || $format[1]!=$this->CurPageFormat[1]) 1114 { 1115 //New size 1116 if($orientation=='P') 1117 { 1118 $this->w=$format[0]; 1119 $this->h=$format[1]; 1120 } 1121 else 1122 { 1123 $this->w=$format[1]; 1124 $this->h=$format[0]; 1125 } 1126 $this->wPt=$this->w*$this->k; 1127 $this->hPt=$this->h*$this->k; 1128 $this->PageBreakTrigger=$this->h-$this->bMargin; 1129 $this->CurOrientation=$orientation; 1130 $this->CurPageFormat=$format; 1131 } 1132 if($orientation!=$this->DefOrientation || $format[0]!=$this->DefPageFormat[0] || $format[1]!=$this->DefPageFormat[1]) 1133 $this->PageSizes[$this->page]=array($this->wPt, $this->hPt); 1134 } 1135 1136 function _endpage() 1137 { 1138 $this->state=1; 1139 } 1140 1141 function _escape($s) 1142 { 1143 //Escape special characters in strings 1144 $s=str_replace('\\','\\\\',$s); 1145 $s=str_replace('(','\\(',$s); 1146 $s=str_replace(')','\\)',$s); 1147 $s=str_replace("\r",'\\r',$s); 1148 return $s; 1149 } 1150 1151 function _textstring($s) 1152 { 1153 //Format a text string 1154 return '('.$this->_escape($s).')'; 1155 } 1156 1157 function _UTF8toUTF16($s) 1158 { 1159 //Convert UTF-8 to UTF-16BE with BOM 1160 $res="\xFE\xFF"; 1161 $nb=strlen($s); 1162 $i=0; 1163 while($i<$nb) 1164 { 1165 $c1=ord($s[$i++]); 1166 if($c1>=224) 1167 { 1168 //3-byte character 1169 $c2=ord($s[$i++]); 1170 $c3=ord($s[$i++]); 1171 $res.=chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2)); 1172 $res.=chr((($c2 & 0x03)<<6) + ($c3 & 0x3F)); 1173 } 1174 elseif($c1>=192) 1175 { 1176 //2-byte character 1177 $c2=ord($s[$i++]); 1178 $res.=chr(($c1 & 0x1C)>>2); 1179 $res.=chr((($c1 & 0x03)<<6) + ($c2 & 0x3F)); 1180 } 1181 else 1182 { 1183 //Single-byte character 1184 $res.="\0".chr($c1); 1185 } 1186 } 1187 return $res; 1188 } 1189 1190 function _dounderline($x, $y, $txt) 1191 { 1192 //Underline text 1193 $up=$this->CurrentFont['up']; 1194 $ut=$this->CurrentFont['ut']; 1195 $w=$this->GetStringWidth($txt)+$this->ws*substr_count($txt,' '); 1196 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); 1197 } 1198 1199 function _parsejpg($file) 1200 { 1201 //Extract info from a JPEG file 1202 $a=GetImageSize($file); 1203 if(!$a) 1204 $this->Error('Missing or incorrect image file: '.$file); 1205 if($a[2]!=2) 1206 $this->Error('Not a JPEG file: '.$file); 1207 if(!isset($a['channels']) || $a['channels']==3) 1208 $colspace='DeviceRGB'; 1209 elseif($a['channels']==4) 1210 $colspace='DeviceCMYK'; 1211 else 1212 $colspace='DeviceGray'; 1213 $bpc=isset($a['bits']) ? $a['bits'] : 8; 1214 //Read whole file 1215 $f=fopen($file,'rb'); 1216 $data=''; 1217 while(!feof($f)) 1218 $data.=fread($f,8192); 1219 fclose($f); 1220 return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data); 1221 } 1222 1223 function _parsepng($file) 1224 { 1225 //Extract info from a PNG file 1226 $f=fopen($file,'rb'); 1227 if(!$f) 1228 $this->Error('Can\'t open image file: '.$file); 1229 //Check signature 1230 if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) 1231 $this->Error('Not a PNG file: '.$file); 1232 //Read header chunk 1233 $this->_readstream($f,4); 1234 if($this->_readstream($f,4)!='IHDR') 1235 $this->Error('Incorrect PNG file: '.$file); 1236 $w=$this->_readint($f); 1237 $h=$this->_readint($f); 1238 $bpc=ord($this->_readstream($f,1)); 1239 if($bpc>8) 1240 $this->Error('16-bit depth not supported: '.$file); 1241 $ct=ord($this->_readstream($f,1)); 1242 if($ct==0) 1243 $colspace='DeviceGray'; 1244 elseif($ct==2) 1245 $colspace='DeviceRGB'; 1246 elseif($ct==3) 1247 $colspace='Indexed'; 1248 else 1249 $this->Error('Alpha channel not supported: '.$file); 1250 if(ord($this->_readstream($f,1))!=0) 1251 $this->Error('Unknown compression method: '.$file); 1252 if(ord($this->_readstream($f,1))!=0) 1253 $this->Error('Unknown filter method: '.$file); 1254 if(ord($this->_readstream($f,1))!=0) 1255 $this->Error('Interlacing not supported: '.$file); 1256 $this->_readstream($f,4); 1257 $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>'; 1258 //Scan chunks looking for palette, transparency and image data 1259 $pal=''; 1260 $trns=''; 1261 $data=''; 1262 do 1263 { 1264 $n=$this->_readint($f); 1265 $type=$this->_readstream($f,4); 1266 if($type=='PLTE') 1267 { 1268 //Read palette 1269 $pal=$this->_readstream($f,$n); 1270 $this->_readstream($f,4); 1271 } 1272 elseif($type=='tRNS') 1273 { 1274 //Read transparency info 1275 $t=$this->_readstream($f,$n); 1276 if($ct==0) 1277 $trns=array(ord(substr($t,1,1))); 1278 elseif($ct==2) 1279 $trns=array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); 1280 else 1281 { 1282 $pos=strpos($t,chr(0)); 1283 if($pos!==false) 1284 $trns=array($pos); 1285 } 1286 $this->_readstream($f,4); 1287 } 1288 elseif($type=='IDAT') 1289 { 1290 //Read image data block 1291 $data.=$this->_readstream($f,$n); 1292 $this->_readstream($f,4); 1293 } 1294 elseif($type=='IEND') 1295 break; 1296 else 1297 $this->_readstream($f,$n+4); 1298 } 1299 while($n); 1300 if($colspace=='Indexed' && empty($pal)) 1301 $this->Error('Missing palette in '.$file); 1302 fclose($f); 1303 return array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'parms'=>$parms, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$data); 1304 } 1305 1306 function _readstream($f, $n) 1307 { 1308 //Read n bytes from stream 1309 $res=''; 1310 while($n>0 && !feof($f)) 1311 { 1312 $s=fread($f,$n); 1313 if($s===false) 1314 $this->Error('Error while reading stream'); 1315 $n-=strlen($s); 1316 $res.=$s; 1317 } 1318 if($n>0) 1319 $this->Error('Unexpected end of stream'); 1320 return $res; 1321 } 1322 1323 function _readint($f) 1324 { 1325 //Read a 4-byte integer from stream 1326 $a=unpack('Ni',$this->_readstream($f,4)); 1327 return $a['i']; 1328 } 1329 1330 function _parsegif($file) 1331 { 1332 //Extract info from a GIF file (via PNG conversion) 1333 if(!function_exists('imagepng')) 1334 $this->Error('GD extension is required for GIF support'); 1335 if(!function_exists('imagecreatefromgif')) 1336 $this->Error('GD has no GIF read support'); 1337 $im=imagecreatefromgif($file); 1338 if(!$im) 1339 $this->Error('Missing or incorrect image file: '.$file); 1340 imageinterlace($im,0); 1341 $tmp=tempnam('.','gif'); 1342 if(!$tmp) 1343 $this->Error('Unable to create a temporary file'); 1344 if(!imagepng($im,$tmp)) 1345 $this->Error('Error while saving to temporary file'); 1346 imagedestroy($im); 1347 $info=$this->_parsepng($tmp); 1348 unlink($tmp); 1349 return $info; 1350 } 1351 1352 function _newobj() 1353 { 1354 //Begin a new object 1355 $this->n++; 1356 $this->offsets[$this->n]=strlen($this->buffer); 1357 $this->_out($this->n.' 0 obj'); 1358 } 1359 1360 function _putstream($s) 1361 { 1362 $this->_out('stream'); 1363 $this->_out($s); 1364 $this->_out('endstream'); 1365 } 1366 1367 function _out($s) 1368 { 1369 //Add a line to the document 1370 if($this->state==2) 1371 $this->pages[$this->page].=$s."\n"; 1372 else 1373 $this->buffer.=$s."\n"; 1374 } 1375 1097 1376 function _putpages() 1098 1377 { … … 1106 1385 if($this->DefOrientation=='P') 1107 1386 { 1108 $wPt=$this-> fwPt;1109 $hPt=$this-> fhPt;1110 } 1111 else 1112 { 1113 $wPt=$this-> fhPt;1114 $hPt=$this-> fwPt;1387 $wPt=$this->DefPageFormat[0]*$this->k; 1388 $hPt=$this->DefPageFormat[1]*$this->k; 1389 } 1390 else 1391 { 1392 $wPt=$this->DefPageFormat[1]*$this->k; 1393 $hPt=$this->DefPageFormat[0]*$this->k; 1115 1394 } 1116 1395 $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; … … 1121 1400 $this->_out('<</Type /Page'); 1122 1401 $this->_out('/Parent 1 0 R'); 1123 if(isset($this-> OrientationChanges[$n]))1124 $this->_out(sprintf('/MediaBox [0 0 %.2 f %.2f]',$hPt,$wPt));1402 if(isset($this->PageSizes[$n])) 1403 $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageSizes[$n][0],$this->PageSizes[$n][1])); 1125 1404 $this->_out('/Resources 2 0 R'); 1126 1405 if(isset($this->PageLinks[$n])) … … 1130 1409 foreach($this->PageLinks[$n] as $pl) 1131 1410 { 1132 $rect=sprintf('%.2 f %.2f %.2f %.2f',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);1411 $rect=sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); 1133 1412 $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; 1134 1413 if(is_string($pl[4])) … … 1137 1416 { 1138 1417 $l=$this->links[$pl[4]]; 1139 $h=isset($this-> OrientationChanges[$l[0]]) ? $wPt: $hPt;1140 $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2 fnull]>>',1+2*$l[0],$h-$l[1]*$this->k);1418 $h=isset($this->PageSizes[$l[0]]) ? $this->PageSizes[$l[0]][1] : $hPt; 1419 $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',1+2*$l[0],$h-$l[1]*$this->k); 1141 1420 } 1142 1421 } … … 1161 1440 $this->_out($kids.']'); 1162 1441 $this->_out('/Count '.$nb); 1163 $this->_out(sprintf('/MediaBox [0 0 %.2 f %.2f]',$wPt,$hPt));1442 $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]',$wPt,$hPt)); 1164 1443 $this->_out('>>'); 1165 1444 $this->_out('endobj'); … … 1176 1455 $this->_out('endobj'); 1177 1456 } 1178 $mqr=get_magic_quotes_runtime();1179 set_magic_quotes_runtime(0);1180 1457 foreach($this->FontFiles as $file=>$info) 1181 1458 { … … 1193 1470 if(!$compressed && isset($info['length2'])) 1194 1471 { 1195 $header=(ord($font {0})==128);1472 $header=(ord($font[0])==128); 1196 1473 if($header) 1197 1474 { … … 1199 1476 $font=substr($font,6); 1200 1477 } 1201 if($header && ord($font {$info['length1']})==128)1478 if($header && ord($font[$info['length1']])==128) 1202 1479 { 1203 1480 //Strip second binary header … … 1215 1492 $this->_out('endobj'); 1216 1493 } 1217 set_magic_quotes_runtime($mqr);1218 1494 foreach($this->fonts as $k=>$font) 1219 1495 { … … 1375 1651 if(!empty($this->creator)) 1376 1652 $this->_out('/Creator '.$this->_textstring($this->creator)); 1377 $this->_out('/CreationDate '.$this->_textstring('D:'. date('YmdHis')));1653 $this->_out('/CreationDate '.$this->_textstring('D:'.@date('YmdHis'))); 1378 1654 } 1379 1655 … … 1444 1720 $this->state=3; 1445 1721 } 1446 1447 function _beginpage($orientation)1448 {1449 $this->page++;1450 $this->pages[$this->page]='';1451 $this->state=2;1452 $this->x=$this->lMargin;1453 $this->y=$this->tMargin;1454 $this->FontFamily='';1455 //Page orientation1456 if(!$orientation)1457 $orientation=$this->DefOrientation;1458 else1459 {1460 $orientation=strtoupper($orientation{0});1461 if($orientation!=$this->DefOrientation)1462 $this->OrientationChanges[$this->page]=true;1463 }1464 if($orientation!=$this->CurOrientation)1465 {1466 //Change orientation1467 if($orientation=='P')1468 {1469 $this->wPt=$this->fwPt;1470 $this->hPt=$this->fhPt;1471 $this->w=$this->fw;1472 $this->h=$this->fh;1473 }1474 else1475 {1476 $this->wPt=$this->fhPt;1477 $this->hPt=$this->fwPt;1478 $this->w=$this->fh;1479 $this->h=$this->fw;1480 }1481 $this->PageBreakTrigger=$this->h-$this->bMargin;1482 $this->CurOrientation=$orientation;1483 }1484 }1485 1486 function _endpage()1487 {1488 //End of page contents1489 $this->state=1;1490 }1491 1492 function _newobj()1493 {1494 //Begin a new object1495 $this->n++;1496 $this->offsets[$this->n]=strlen($this->buffer);1497 $this->_out($this->n.' 0 obj');1498 }1499 1500 function _dounderline($x,$y,$txt)1501 {1502 //Underline text1503 $up=$this->CurrentFont['up'];1504 $ut=$this->CurrentFont['ut'];1505 $w=$this->GetStringWidth($txt)+$this->ws*substr_count($txt,' ');1506 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);1507 }1508 1509 function _parsejpg($file)1510 {1511 //Extract info from a JPEG file1512 $a=GetImageSize($file);1513 if(!$a)1514 $this->Error('Missing or incorrect image file: '.$file);1515 if($a[2]!=2)1516 $this->Error('Not a JPEG file: '.$file);1517 if(!isset($a['channels']) || $a['channels']==3)1518 $colspace='DeviceRGB';1519 elseif($a['channels']==4)1520 $colspace='DeviceCMYK';1521 else1522 $colspace='DeviceGray';1523 $bpc=isset($a['bits']) ? $a['bits'] : 8;1524 //Read whole file1525 $f=fopen($file,'rb');1526 $data='';1527 while(!feof($f))1528 $data.=fread($f,4096);1529 fclose($f);1530 return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data);1531 }1532 1533 function _parsepng($file)1534 {1535 //Extract info from a PNG file1536 $f=fopen($file,'rb');1537 if(!$f)1538 $this->Error('Can\'t open image file: '.$file);1539 //Check signature1540 if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10))1541 $this->Error('Not a PNG file: '.$file);1542 //Read header chunk1543 fread($f,4);1544 if(fread($f,4)!='IHDR')1545 $this->Error('Incorrect PNG file: '.$file);1546 $w=$this->_freadint($f);1547 $h=$this->_freadint($f);1548 $bpc=ord(fread($f,1));1549 if($bpc>8)1550 $this->Error('16-bit depth not supported: '.$file);1551 $ct=ord(fread($f,1));1552 if($ct==0)1553 $colspace='DeviceGray';1554 elseif($ct==2)1555 $colspace='DeviceRGB';1556 elseif($ct==3)1557 $colspace='Indexed';1558 else1559 $this->Error('Alpha channel not supported: '.$file);1560 if(ord(fread($f,1))!=0)1561 $this->Error('Unknown compression method: '.$file);1562 if(ord(fread($f,1))!=0)1563 $this->Error('Unknown filter method: '.$file);1564 if(ord(fread($f,1))!=0)1565 $this->Error('Interlacing not supported: '.$file);1566 fread($f,4);1567 $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';1568 //Scan chunks looking for palette, transparency and image data1569 $pal='';1570 $trns='';1571 $data='';1572 do1573 {1574 $n=$this->_freadint($f);1575 $type=fread($f,4);1576 if($type=='PLTE')1577 {1578 //Read palette1579 $pal=fread($f,$n);1580 fread($f,4);1581 }1582 elseif($type=='tRNS')1583 {1584 //Read transparency info1585 $t=fread($f,$n);1586 if($ct==0)1587 $trns=array(ord(substr($t,1,1)));1588 elseif($ct==2)1589 $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1)));1590 else1591 {1592 $pos=strpos($t,chr(0));1593 if($pos!==false)1594 $trns=array($pos);1595 }1596 fread($f,4);1597 }1598 elseif($type=='IDAT')1599 {1600 //Read image data block1601 $data.=fread($f,$n);1602 fread($f,4);1603 }1604 elseif($type=='IEND')1605 break;1606 else1607 fread($f,$n+4);1608 }1609 while($n);1610 if($colspace=='Indexed' && empty($pal))1611 $this->Error('Missing palette in '.$file);1612 fclose($f);1613 return array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$data);1614 }1615 1616 function _freadint($f)1617 {1618 //Read a 4-byte integer from file1619 $a=unpack('Ni',fread($f,4));1620 return $a['i'];1621 }1622 1623 function _textstring($s)1624 {1625 //Format a text string1626 return '('.$this->_escape($s).')';1627 }1628 1629 function _escape($s)1630 {1631 //Add \ before \, ( and )1632 return str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$s)));1633 }1634 1635 function _putstream($s)1636 {1637 $this->_out('stream');1638 $this->_out($s);1639 $this->_out('endstream');1640 }1641 1642 function _out($s)1643 {1644 //Add a line to the document1645 if($this->state==2)1646 $this->pages[$this->page].=$s."\n";1647 else1648 $this->buffer.=$s."\n";1649 }1650 1722 //End of class 1651 1723 } … … 1658 1730 } 1659 1731 1660 }1661 1732 ?>
Note: See TracChangeset
for help on using the changeset viewer.