Changeset 11339

Show
Ignore:
Timestamp:
02/10/11 14:37:06 (2 years ago)
Author:
mickecarlsson
Message:

#Re 4806, update fpdf.php in cdr to the latest version, this version does not use deprecated php long arrays

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/branches/2.9/amp_conf/htdocs/admin/cdr/lib/fpdf.php

    r11047 r11339  
    11<?php 
    22/******************************************************************************* 
    3 * Logiciel : FPDF                                                              * 
    4 * Version :  1.52                                                              * 
    5 * Date :     30/12/2003                                                        * 
    6 * Auteur :   Olivier PLATHEY                                                   * 
    7 * Licence :  Freeware                                                          * 
     3* FPDF                                                                         * 
    84*                                                                              * 
    9 * Vous pouvez utiliser et modifier ce logiciel comme vous le souhaitez.        * 
     5* Version: 1.6                                                                 * 
     6* Date:    2008-08-03                                                          * 
     7* Author:  Olivier PLATHEY                                                     * 
    108*******************************************************************************/ 
    11 defined('FREEPBX_IS_AUTH') OR die('No direct script access allowed'); 
    12 if(!class_exists('FPDF')) 
    13 
    14 define('FPDF_VERSION','1.52'); 
     9 
     10define('FPDF_VERSION','1.6'); 
    1511 
    1612class FPDF 
    1713{ 
    18 //Private properties 
    1914var $page;               //current page number 
    2015var $n;                  //current object number 
     
    2419var $state;              //current document state 
    2520var $compress;           //compression flag 
     21var $k;                  //scale factor (number of points in user unit) 
    2622var $DefOrientation;     //default orientation 
    2723var $CurOrientation;     //current orientation 
    28 var $OrientationChanges; //array indicating orientation change
    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 
     24var $PageFormats;        //available page format
     25var $DefPageFormat;      //default page format 
     26var $CurPageFormat;      //current page format 
     27var $PageSizes;          //array storing non-default page sizes 
     28var $wPt,$hPt;           //dimensions of current page in points 
     29var $w,$h;               //dimensions of current page in user unit 
    3430var $lMargin;            //left margin 
    3531var $tMargin;            //top margin 
     
    3733var $bMargin;            //page break margin 
    3834var $cMargin;            //cell margin 
    39 var $x,$y;               //current position in user unit for cell positioning 
    40 var $lasth;              //height of last cell printed 
     35var $x,$y;               //current position in user unit 
     36var $lasth;              //height of last printed cell 
    4137var $LineWidth;          //line width in user unit 
    4238var $CoreFonts;          //array of standard font names 
     
    4440var $FontFiles;          //array of font files 
    4541var $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 
    4942var $FontFamily;         //current font family 
    5043var $FontStyle;          //current font style 
     
    5851var $ColorFlag;          //indicates whether fill and text colors are different 
    5952var $ws;                 //word spacing 
     53var $images;             //array of used images 
     54var $PageLinks;          //array of links in pages 
     55var $links;              //array of internal links 
    6056var $AutoPageBreak;      //automatic page breaking 
    6157var $PageBreakTrigger;   //threshold used to trigger page breaks 
     58var $InHeader;           //flag set when processing header 
    6259var $InFooter;           //flag set when processing footer 
    6360var $ZoomMode;           //zoom display mode 
     
    6966var $creator;            //creator 
    7067var $AliasNbPages;       //alias for total number of pages 
     68var $PDFVersion;         //PDF version number 
    7169 
    7270/******************************************************************************* 
     
    7573*                                                                              * 
    7674*******************************************************************************/ 
    77 function FPDF($orientation='P',$unit='mm',$format='A4') 
     75function FPDF($orientation='P', $unit='mm', $format='A4') 
    7876{ 
    7977  //Some checks 
     
    8482  $this->buffer=''; 
    8583  $this->pages=array(); 
    86   $this->OrientationChanges=array(); 
     84  $this->PageSizes=array(); 
    8785  $this->state=0; 
    8886  $this->fonts=array(); 
     
    9189  $this->images=array(); 
    9290  $this->links=array(); 
     91  $this->InHeader=false; 
    9392  $this->InFooter=false; 
    9493  $this->lasth=0; 
     
    103102  $this->ws=0; 
    104103  //Standard fonts 
    105   $this->CoreFonts=array('courier'=>'Courier','courierB'=>'Courier-Bold','courierI'=>'Courier-Oblique','courierBI'=>'Courier-BoldOblique', 
    106     'helvetica'=>'Helvetica','helveticaB'=>'Helvetica-Bold','helveticaI'=>'Helvetica-Oblique','helveticaBI'=>'Helvetica-BoldOblique', 
    107     'times'=>'Times-Roman','timesB'=>'Times-Bold','timesI'=>'Times-Italic','timesBI'=>'Times-BoldItalic', 
    108     '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'); 
    109108  //Scale factor 
    110109  if($unit=='pt') 
     
    119118    $this->Error('Incorrect unit: '.$unit); 
    120119  //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)); 
    121122  if(is_string($format)) 
    122   { 
    123     $format=strtolower($format); 
    124     if($format=='a3') 
    125       $format=array(841.89,1190.55); 
    126     elseif($format=='a4') 
    127       $format=array(595.28,841.89); 
    128     elseif($format=='a5') 
    129       $format=array(420.94,595.28); 
    130     elseif($format=='letter') 
    131       $format=array(612,792); 
    132     elseif($format=='legal') 
    133       $format=array(612,1008); 
    134     else 
    135       $this->Error('Unknown page format: '.$format); 
    136     $this->fwPt=$format[0]; 
    137     $this->fhPt=$format[1]; 
    138   } 
    139   else 
    140   { 
    141     $this->fwPt=$format[0]*$this->k; 
    142     $this->fhPt=$format[1]*$this->k; 
    143   } 
    144   $this->fw=$this->fwPt/$this->k; 
    145   $this->fh=$this->fhPt/$this->k; 
     123    $format=$this->_getpageformat($format); 
     124  $this->DefPageFormat=$format; 
     125  $this->CurPageFormat=$format; 
    146126  //Page orientation 
    147127  $orientation=strtolower($orientation); 
    148   if($orientation=='p' or $orientation=='portrait') 
     128  if($orientation=='p' || $orientation=='portrait') 
    149129  { 
    150130    $this->DefOrientation='P'; 
    151     $this->wPt=$this->fwPt
    152     $this->hPt=$this->fhPt
    153   } 
    154   elseif($orientation=='l' or $orientation=='landscape') 
     131    $this->w=$this->DefPageFormat[0]
     132    $this->h=$this->DefPageFormat[1]
     133  } 
     134  elseif($orientation=='l' || $orientation=='landscape') 
    155135  { 
    156136    $this->DefOrientation='L'; 
    157     $this->wPt=$this->fhPt
    158     $this->hPt=$this->fwPt
     137    $this->w=$this->DefPageFormat[1]
     138    $this->h=$this->DefPageFormat[0]
    159139  } 
    160140  else 
    161141    $this->Error('Incorrect orientation: '.$orientation); 
    162142  $this->CurOrientation=$this->DefOrientation; 
    163   $this->w=$this->wPt/$this->k; 
    164   $this->h=$this->hPt/$this->k; 
     143  $this->wPt=$this->w*$this->k; 
     144  $this->hPt=$this->h*$this->k; 
    165145  //Page margins (1 cm) 
    166146  $margin=28.35/$this->k; 
     
    174154  //Full width display mode 
    175155  $this->SetDisplayMode('fullwidth'); 
    176   //Compression 
     156  //Enable compression 
    177157  $this->SetCompression(true); 
    178 
    179  
    180 function SetMargins($left,$top,$right=-1) 
     158  //Set default PDF version number 
     159  $this->PDFVersion='1.3'; 
     160
     161 
     162function SetMargins($left, $top, $right=null) 
    181163{ 
    182164  //Set left, top and right margins 
    183165  $this->lMargin=$left; 
    184166  $this->tMargin=$top; 
    185   if($right==-1
     167  if($right===null
    186168    $right=$left; 
    187169  $this->rMargin=$right; 
     
    192174  //Set left margin 
    193175  $this->lMargin=$margin; 
    194   if($this->page>0 and $this->x<$margin) 
     176  if($this->page>0 && $this->x<$margin) 
    195177    $this->x=$margin; 
    196178} 
     
    208190} 
    209191 
    210 function SetAutoPageBreak($auto,$margin=0) 
     192function SetAutoPageBreak($auto, $margin=0) 
    211193{ 
    212194  //Set auto page break mode and triggering margin 
     
    216198} 
    217199 
    218 function SetDisplayMode($zoom,$layout='continuous') 
     200function SetDisplayMode($zoom, $layout='continuous') 
    219201{ 
    220202  //Set display mode in viewer 
    221   if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) 
     203  if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) 
    222204    $this->ZoomMode=$zoom; 
    223205  else 
    224206    $this->Error('Incorrect zoom display mode: '.$zoom); 
    225   if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default') 
     207  if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') 
    226208    $this->LayoutMode=$layout; 
    227209  else 
     
    238220} 
    239221 
    240 function SetTitle($title
     222function SetTitle($title, $isUTF8=false
    241223{ 
    242224  //Title of document 
     225  if($isUTF8) 
     226    $title=$this->_UTF8toUTF16($title); 
    243227  $this->title=$title; 
    244228} 
    245229 
    246 function SetSubject($subject
     230function SetSubject($subject, $isUTF8=false
    247231{ 
    248232  //Subject of document 
     233  if($isUTF8) 
     234    $subject=$this->_UTF8toUTF16($subject); 
    249235  $this->subject=$subject; 
    250236} 
    251237 
    252 function SetAuthor($author
     238function SetAuthor($author, $isUTF8=false
    253239{ 
    254240  //Author of document 
     241  if($isUTF8) 
     242    $author=$this->_UTF8toUTF16($author); 
    255243  $this->author=$author; 
    256244} 
    257245 
    258 function SetKeywords($keywords
     246function SetKeywords($keywords, $isUTF8=false
    259247{ 
    260248  //Keywords of document 
     249  if($isUTF8) 
     250    $keywords=$this->_UTF8toUTF16($keywords); 
    261251  $this->keywords=$keywords; 
    262252} 
    263253 
    264 function SetCreator($creator
     254function SetCreator($creator, $isUTF8=false
    265255{ 
    266256  //Creator of document 
     257  if($isUTF8) 
     258    $creator=$this->_UTF8toUTF16($creator); 
    267259  $this->creator=$creator; 
    268260} 
     
    277269{ 
    278270  //Fatal error 
    279   die('<B>FPDF error: </B>'.$msg); 
     271  die('<b>FPDF error:</b> '.$msg); 
    280272} 
    281273 
     
    283275{ 
    284276  //Begin document 
    285   if($this->state==0) 
    286     $this->_begindoc(); 
     277  $this->state=1; 
    287278} 
    288279 
     
    304295} 
    305296 
    306 function AddPage($orientation=''
     297function AddPage($orientation='', $format=''
    307298{ 
    308299  //Start a new page 
     
    327318  } 
    328319  //Start new page 
    329   $this->_beginpage($orientation); 
     320  $this->_beginpage($orientation,$format); 
    330321  //Set line cap style to square 
    331322  $this->_out('2 J'); 
    332323  //Set line width 
    333324  $this->LineWidth=$lw; 
    334   $this->_out(sprintf('%.2f w',$lw*$this->k)); 
     325  $this->_out(sprintf('%.2F w',$lw*$this->k)); 
    335326  //Set font 
    336327  if($family) 
     
    346337  $this->ColorFlag=$cf; 
    347338  //Page header 
     339  $this->InHeader=true; 
    348340  $this->Header(); 
     341  $this->InHeader=false; 
    349342  //Restore line width 
    350343  if($this->LineWidth!=$lw) 
    351344  { 
    352345    $this->LineWidth=$lw; 
    353     $this->_out(sprintf('%.2f w',$lw*$this->k)); 
     346    $this->_out(sprintf('%.2F w',$lw*$this->k)); 
    354347  } 
    355348  //Restore font 
     
    387380} 
    388381 
    389 function SetDrawColor($r,$g=-1,$b=-1
     382function SetDrawColor($r, $g=null, $b=null
    390383{ 
    391384  //Set color for all stroking operations 
    392   if(($r==0 and $g==0 and $b==0) or $g==-1
    393     $this->DrawColor=sprintf('%.3f G',$r/255); 
    394   else 
    395     $this->DrawColor=sprintf('%.3f %.3f %.3f RG',$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); 
    396389  if($this->page>0) 
    397390    $this->_out($this->DrawColor); 
    398391} 
    399392 
    400 function SetFillColor($r,$g=-1,$b=-1
     393function SetFillColor($r, $g=null, $b=null
    401394{ 
    402395  //Set color for all filling operations 
    403   if(($r==0 and $g==0 and $b==0) or $g==-1
    404     $this->FillColor=sprintf('%.3f g',$r/255); 
    405   else 
    406     $this->FillColor=sprintf('%.3f %.3f %.3f rg',$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); 
    407400  $this->ColorFlag=($this->FillColor!=$this->TextColor); 
    408401  if($this->page>0) 
     
    410403} 
    411404 
    412 function SetTextColor($r,$g=-1,$b=-1
     405function SetTextColor($r, $g=null, $b=null
    413406{ 
    414407  //Set color for text 
    415   if(($r==0 and $g==0 and $b==0) or $g==-1
    416     $this->TextColor=sprintf('%.3f g',$r/255); 
    417   else 
    418     $this->TextColor=sprintf('%.3f %.3f %.3f rg',$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); 
    419412  $this->ColorFlag=($this->FillColor!=$this->TextColor); 
    420413} 
     
    428421  $l=strlen($s); 
    429422  for($i=0;$i<$l;$i++) 
    430     $w+=$cw[$s{$i}]; 
     423    $w+=$cw[$s[$i]]; 
    431424  return $w*$this->FontSize/1000; 
    432425} 
     
    437430  $this->LineWidth=$width; 
    438431  if($this->page>0) 
    439     $this->_out(sprintf('%.2f w',$width*$this->k)); 
    440 } 
    441  
    442 function Line($x1,$y1,$x2,$y2) 
     432    $this->_out(sprintf('%.2F w',$width*$this->k)); 
     433} 
     434 
     435function Line($x1, $y1, $x2, $y2) 
    443436{ 
    444437  //Draw a line 
    445   $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)); 
    446 } 
    447  
    448 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 
     441function Rect($x, $y, $w, $h, $style='') 
    449442{ 
    450443  //Draw a rectangle 
    451444  if($style=='F') 
    452445    $op='f'; 
    453   elseif($style=='FD' or $style=='DF') 
     446  elseif($style=='FD' || $style=='DF') 
    454447    $op='B'; 
    455448  else 
    456449    $op='S'; 
    457   $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); 
    458 } 
    459  
    460 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 
     453function AddFont($family, $style='', $file='') 
    461454{ 
    462455  //Add a TrueType or Type1 font 
    463456  $family=strtolower($family); 
     457  if($file=='') 
     458    $file=str_replace(' ','',$family).strtolower($style).'.php'; 
    464459  if($family=='arial') 
    465460    $family='helvetica'; 
     
    467462  if($style=='IB') 
    468463    $style='BI'; 
    469   if(isset($this->fonts[$family.$style])) 
    470     $this->Error('Font already added: '.$family.' '.$style); 
    471   if($file=='') 
    472     $file=str_replace(' ','',$family).strtolower($style).'.php'; 
    473   if(defined('FPDF_FONTPATH')) 
    474     $file=FPDF_FONTPATH.$file; 
    475   include($file); 
     464  $fontkey=$family.$style; 
     465  if(isset($this->fonts[$fontkey])) 
     466    return; 
     467  include($this->_getfontpath().$file); 
    476468  if(!isset($name)) 
    477469    $this->Error('Could not include font definition file'); 
    478470  $i=count($this->fonts)+1; 
    479   $this->fonts[$family.$style]=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); 
    480472  if($diff) 
    481473  { 
     
    484476    $nb=count($this->diffs); 
    485477    for($i=1;$i<=$nb;$i++) 
     478    { 
    486479      if($this->diffs[$i]==$diff) 
    487480      { 
     
    489482        break; 
    490483      } 
     484    } 
    491485    if($d==0) 
    492486    { 
     
    494488      $this->diffs[$d]=$diff; 
    495489    } 
    496     $this->fonts[$family.$style]['diff']=$d; 
     490    $this->fonts[$fontkey]['diff']=$d; 
    497491  } 
    498492  if($file) 
     
    501495      $this->FontFiles[$file]=array('length1'=>$originalsize); 
    502496    else 
    503       $this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2); 
    504   } 
    505 } 
    506  
    507 function SetFont($family,$style='',$size=0) 
     497      $this->FontFiles[$file]=array('length1'=>$size1, 'length2'=>$size2); 
     498  } 
     499} 
     500 
     501function SetFont($family, $style='', $size=0) 
    508502{ 
    509503  //Select a font; size given in points 
     
    515509  if($family=='arial') 
    516510    $family='helvetica'; 
    517   elseif($family=='symbol' or $family=='zapfdingbats') 
     511  elseif($family=='symbol' || $family=='zapfdingbats') 
    518512    $style=''; 
    519513  $style=strtoupper($style); 
    520   if(is_int(strpos($style,'U'))
     514  if(strpos($style,'U')!==false
    521515  { 
    522516    $this->underline=true; 
     
    530524    $size=$this->FontSizePt; 
    531525  //Test if font is already selected 
    532   if($this->FontFamily==$family and $this->FontStyle==$style and $this->FontSizePt==$size) 
     526  if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) 
    533527    return; 
    534528  //Test if used for the first time 
     
    543537        //Load metric file 
    544538        $file=$family; 
    545         if($family=='times' or $family=='helvetica') 
     539        if($family=='times' || $family=='helvetica') 
    546540          $file.=strtolower($style); 
    547         $file.='.php'; 
    548         if(defined('FPDF_FONTPATH')) 
    549           $file=FPDF_FONTPATH.$file; 
    550         include($file); 
     541        include($this->_getfontpath().$file.'.php'); 
    551542        if(!isset($fpdf_charwidths[$fontkey])) 
    552543          $this->Error('Could not include font metric file'); 
    553544      } 
    554545      $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); 
    556549    } 
    557550    else 
     
    565558  $this->CurrentFont=&$this->fonts[$fontkey]; 
    566559  if($this->page>0) 
    567     $this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); 
     560    $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); 
    568561} 
    569562 
     
    576569  $this->FontSize=$size/$this->k; 
    577570  if($this->page>0) 
    578     $this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); 
     571    $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); 
    579572} 
    580573 
     
    583576  //Create a new internal link 
    584577  $n=count($this->links)+1; 
    585   $this->links[$n]=array(0,0); 
     578  $this->links[$n]=array(0, 0); 
    586579  return $n; 
    587580} 
    588581 
    589 function SetLink($link,$y=0,$page=-1) 
     582function SetLink($link, $y=0, $page=-1) 
    590583{ 
    591584  //Set destination of internal link 
     
    594587  if($page==-1) 
    595588    $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 
     592function Link($x, $y, $w, $h, $link) 
    600593{ 
    601594  //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 
     598function Text($x, $y, $txt) 
    606599{ 
    607600  //Output a string 
    608   $s=sprintf('BT %.2f %.2f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); 
    609   if($this->underline and $txt!='') 
     601  $s=sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); 
     602  if($this->underline && $txt!='') 
    610603    $s.=' '.$this->_dounderline($x,$y,$txt); 
    611604  if($this->ColorFlag) 
     
    620613} 
    621614 
    622 function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='') 
     615function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') 
    623616{ 
    624617  //Output a cell 
    625618  $k=$this->k; 
    626   if($this->y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) 
     619  if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) 
    627620  { 
    628621    //Automatic page break 
     
    634627      $this->_out('0 Tw'); 
    635628    } 
    636     $this->AddPage($this->CurOrientation); 
     629    $this->AddPage($this->CurOrientation,$this->CurPageFormat); 
    637630    $this->x=$x; 
    638631    if($ws>0) 
    639632    { 
    640633      $this->ws=$ws; 
    641       $this->_out(sprintf('%.3f Tw',$ws*$k)); 
     634      $this->_out(sprintf('%.3F Tw',$ws*$k)); 
    642635    } 
    643636  } 
     
    645638    $w=$this->w-$this->rMargin-$this->x; 
    646639  $s=''; 
    647   if($fill==1 or $border==1) 
    648   { 
    649     if($fill==1
     640  if($fill || $border==1) 
     641  { 
     642    if($fill
    650643      $op=($border==1) ? 'B' : 'f'; 
    651644    else 
    652645      $op='S'; 
    653     $s=sprintf('%.2f %.2f %.2f %.2f re %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); 
    654647  } 
    655648  if(is_string($border)) 
     
    657650    $x=$this->x; 
    658651    $y=$this->y; 
    659     if(is_int(strpos($border,'L'))
    660       $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); 
    661     if(is_int(strpos($border,'T'))
    662       $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); 
    663     if(is_int(strpos($border,'R'))
    664       $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     if(is_int(strpos($border,'B'))
    666       $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   } 
    668   if($txt!='') 
     652    if(strpos($border,'L')!==false
     653      $s.=sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); 
     654    if(strpos($border,'T')!==false
     655      $s.=sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); 
     656    if(strpos($border,'R')!==false
     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); 
     658    if(strpos($border,'B')!==false
     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); 
     660  } 
     661  if($txt!=='') 
    669662  { 
    670663    if($align=='R') 
     
    677670      $s.='q '.$this->TextColor.' '; 
    678671    $txt2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt))); 
    679     $s.=sprintf('BT %.2f %.2f Td (%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); 
    680673    if($this->underline) 
    681674      $s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); 
     
    699692} 
    700693 
    701 function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0
     694function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false
    702695{ 
    703696  //Output text with automatic or explicit line breaks 
     
    708701  $s=str_replace("\r",'',$txt); 
    709702  $nb=strlen($s); 
    710   if($nb>0 and $s[$nb-1]=="\n") 
     703  if($nb>0 && $s[$nb-1]=="\n") 
    711704    $nb--; 
    712705  $b=0; 
     
    722715    { 
    723716      $b2=''; 
    724       if(is_int(strpos($border,'L'))
     717      if(strpos($border,'L')!==false
    725718        $b2.='L'; 
    726       if(is_int(strpos($border,'R'))
     719      if(strpos($border,'R')!==false
    727720        $b2.='R'; 
    728       $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; 
     721      $b=(strpos($border,'T')!==false) ? $b2.'T' : $b2; 
    729722    } 
    730723  } 
     
    738731  { 
    739732    //Get next character 
    740     $c=$s{$i}
     733    $c=$s[$i]
    741734    if($c=="\n") 
    742735    { 
     
    754747      $ns=0; 
    755748      $nl++; 
    756       if($border and $nl==2) 
     749      if($border && $nl==2) 
    757750        $b=$b2; 
    758751      continue; 
     
    784777        { 
    785778          $this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; 
    786           $this->_out(sprintf('%.3f Tw',$this->ws*$this->k)); 
     779          $this->_out(sprintf('%.3F Tw',$this->ws*$this->k)); 
    787780        } 
    788781        $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); 
     
    794787      $ns=0; 
    795788      $nl++; 
    796       if($border and $nl==2) 
     789      if($border && $nl==2) 
    797790        $b=$b2; 
    798791    } 
     
    806799    $this->_out('0 Tw'); 
    807800  } 
    808   if($border and is_int(strpos($border,'B'))
     801  if($border && strpos($border,'B')!==false
    809802    $b.='B'; 
    810803  $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 
     
    812805} 
    813806 
    814 function Write($h,$txt,$link='') 
     807function Write($h, $txt, $link='') 
    815808{ 
    816809  //Output text in flowing mode 
     
    828821  { 
    829822    //Get next character 
    830     $c=$s{$i}
     823    $c=$s[$i]
    831824    if($c=="\n") 
    832825    { 
     
    893886} 
    894887 
    895 function Image($file,$x,$y,$w=0,$h=0,$type='',$link='') 
     888function 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 
     898function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='') 
    896899{ 
    897900  //Put an image on the page 
    898901  if(!isset($this->images[$file])) 
    899902  { 
    900     //First use of image, get info 
     903    //First use of this image, get info 
    901904    if($type=='') 
    902905    { 
     
    907910    } 
    908911    $type=strtolower($type); 
    909     $mqr=get_magic_quotes_runtime(); 
    910     set_magic_quotes_runtime(0); 
    911     if($type=='jpg' or $type=='jpeg') 
    912       $info=$this->_parsejpg($file); 
    913     elseif($type=='png') 
    914       $info=$this->_parsepng($file); 
    915     else 
    916     { 
    917       //Allow for additional formats 
    918       $mtd='_parse'.$type; 
    919       if(!method_exists($this,$mtd)) 
    920         $this->Error('Unsupported image type: '.$type); 
    921       $info=$this->$mtd($file); 
    922     } 
    923     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); 
    924918    $info['i']=count($this->images)+1; 
    925919    $this->images[$file]=$info; 
     
    928922    $info=$this->images[$file]; 
    929923  //Automatic width and height calculation if needed 
    930   if($w==0 and $h==0) 
     924  if($w==0 && $h==0) 
    931925  { 
    932926    //Put image at 72 dpi 
     
    934928    $h=$info['h']/$this->k; 
    935929  } 
    936   if($w==0) 
     930  elseif($w==0) 
    937931    $w=$h*$info['w']/$info['h']; 
    938   if($h==0) 
     932  elseif($h==0) 
    939933    $h=$w*$info['h']/$info['w']; 
    940   $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'])); 
    941950  if($link) 
    942951    $this->Link($x,$y,$w,$h,$link); 
    943 } 
    944  
    945 function Ln($h='') 
    946 { 
    947   //Line feed; default value is last cell height 
    948   $this->x=$this->lMargin; 
    949   if(is_string($h)) 
    950     $this->y+=$this->lasth; 
    951   else 
    952     $this->y+=$h; 
    953952} 
    954953 
     
    984983} 
    985984 
    986 function SetXY($x,$y) 
     985function SetXY($x, $y) 
    987986{ 
    988987  //Set x and y positions 
     
    991990} 
    992991 
    993 function Output($name='',$dest='') 
     992function Output($name='', $dest='') 
    994993{ 
    995994  //Output PDF to some destination 
    996   global $HTTP_SERVER_VARS; 
    997  
    998   //Finish document if necessary 
    999995  if($this->state<3) 
    1000996    $this->Close(); 
    1001   //Normalize parameters 
    1002   if(is_bool($dest)) 
    1003     $dest=$dest ? 'D' : 'F'; 
    1004997  $dest=strtoupper($dest); 
    1005998  if($dest=='') 
     
    10171010    case 'I': 
    10181011      //Send to standard output 
    1019       if(isset($HTTP_SERVER_VARS['SERVER_NAME'])) 
     1012      if(ob_get_length()) 
     1013        $this->Error('Some data has already been output, can\'t send PDF file'); 
     1014      if(php_sapi_name()!='cli') 
    10201015      { 
    10211016        //We send to a browser 
    1022         Header('Content-Type: application/pdf'); 
     1017        header('Content-Type: application/pdf'); 
    10231018        if(headers_sent()) 
    1024           $this->Error('Some data has already been output to browser, can\'t send PDF file'); 
    1025         Header('Content-Length: '.strlen($this->buffer)); 
    1026         Header('Content-disposition: inline; filename='.$name); 
     1019          $this->Error('Some data has already been output, can\'t send PDF file'); 
     1020        header('Content-Length: '.strlen($this->buffer)); 
     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'); 
    10271025      } 
    10281026      echo $this->buffer; 
     
    10301028    case 'D': 
    10311029      //Download file 
    1032       if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'],'MSIE')) 
    1033         Header('Content-Type: application/force-download'); 
    1034       else 
    1035         Header('Content-Type: application/octet-stream'); 
     1030      if(ob_get_length()) 
     1031        $this->Error('Some data has already been output, can\'t send PDF file'); 
     1032      header('Content-Type: application/x-download'); 
    10361033      if(headers_sent()) 
    1037         $this->Error('Some data has already been output to browser, can\'t send PDF file'); 
    1038       Header('Content-Length: '.strlen($this->buffer)); 
    1039       Header('Content-disposition: attachment; filename='.$name); 
     1034        $this->Error('Some data has already been output, can\'t send PDF file'); 
     1035      header('Content-Length: '.strlen($this->buffer)); 
     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'); 
    10401040      echo $this->buffer; 
    10411041      break; 
     
    10641064function _dochecks() 
    10651065{ 
    1066   //Check for locale-related bug 
    1067   if(1.1==1) 
    1068     $this->Error('Don\'t alter the locale before including class file'); 
    1069   //Check for decimal separator 
    1070   if(sprintf('%.1f',1.0)!='1.0') 
    1071     setlocale(LC_NUMERIC,'C'); 
    1072 
    1073  
    1074 function _begindoc() 
    1075 
    1076   //Start document 
     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 
     1077function _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); 
     1084
     1085 
     1086function _getfontpath() 
     1087
     1088  if(!defined('FPDF_FONTPATH') && is_dir(dirname(__FILE__).'/font')) 
     1089    define('FPDF_FONTPATH',dirname(__FILE__).'/font/'); 
     1090  return defined('FPDF_FONTPATH') ? FPDF_FONTPATH : ''; 
     1091
     1092 
     1093function _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 
     1136function _endpage() 
     1137
    10771138  $this->state=1; 
    1078   $this->_out('%PDF-1.3'); 
     1139
     1140 
     1141function _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 
     1151function _textstring($s) 
     1152
     1153  //Format a text string 
     1154  return '('.$this->_escape($s).')'; 
     1155
     1156 
     1157function _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 
     1190function _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 
     1199function _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 
     1223function _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 
     1306function _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 
     1323function _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 
     1330function _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 
     1352function _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 
     1360function _putstream($s) 
     1361
     1362  $this->_out('stream'); 
     1363  $this->_out($s); 
     1364  $this->_out('endstream'); 
     1365
     1366 
     1367function _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"; 
    10791374} 
    10801375 
     
    10901385  if($this->DefOrientation=='P') 
    10911386  { 
    1092     $wPt=$this->fwPt
    1093     $hPt=$this->fhPt
    1094   } 
    1095   else 
    1096   { 
    1097     $wPt=$this->fhPt
    1098     $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
    10991394  } 
    11001395  $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; 
     
    11051400    $this->_out('<</Type /Page'); 
    11061401    $this->_out('/Parent 1 0 R'); 
    1107     if(isset($this->OrientationChanges[$n])) 
    1108       $this->_out(sprintf('/MediaBox [0 0 %.2f %.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])); 
    11091404    $this->_out('/Resources 2 0 R'); 
    11101405    if(isset($this->PageLinks[$n])) 
     
    11141409      foreach($this->PageLinks[$n] as $pl) 
    11151410      { 
    1116         $rect=sprintf('%.2f %.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]); 
    11171412        $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; 
    11181413        if(is_string($pl[4])) 
     
    11211416        { 
    11221417          $l=$this->links[$pl[4]]; 
    1123           $h=isset($this->OrientationChanges[$l[0]]) ? $wPt : $hPt; 
    1124           $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>',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); 
    11251420        } 
    11261421      } 
     
    11451440  $this->_out($kids.']'); 
    11461441  $this->_out('/Count '.$nb); 
    1147   $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$wPt,$hPt)); 
     1442  $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]',$wPt,$hPt)); 
    11481443  $this->_out('>>'); 
    11491444  $this->_out('endobj'); 
     
    11601455    $this->_out('endobj'); 
    11611456  } 
    1162   $mqr=get_magic_quotes_runtime(); 
    1163   set_magic_quotes_runtime(0); 
    11641457  foreach($this->FontFiles as $file=>$info) 
    11651458  { 
     
    11671460    $this->_newobj(); 
    11681461    $this->FontFiles[$file]['n']=$this->n; 
    1169     if(defined('FPDF_FONTPATH')) 
    1170       $file=FPDF_FONTPATH.$file; 
    1171     $size=filesize($file); 
    1172     if(!$size) 
     1462    $font=''; 
     1463    $f=fopen($this->_getfontpath().$file,'rb',1); 
     1464    if(!$f) 
    11731465      $this->Error('Font file not found'); 
    1174     $this->_out('<</Length '.$size); 
    1175     if(substr($file,-2)=='.z') 
     1466    while(!feof($f)) 
     1467      $font.=fread($f,8192); 
     1468    fclose($f); 
     1469    $compressed=(substr($file,-2)=='.z'); 
     1470    if(!$compressed && isset($info['length2'])) 
     1471    { 
     1472      $header=(ord($font[0])==128); 
     1473      if($header) 
     1474      { 
     1475        //Strip first binary header 
     1476        $font=substr($font,6); 
     1477      } 
     1478      if($header && ord($font[$info['length1']])==128) 
     1479      { 
     1480        //Strip second binary header 
     1481        $font=substr($font,0,$info['length1']).substr($font,$info['length1']+6); 
     1482      } 
     1483    } 
     1484    $this->_out('<</Length '.strlen($font)); 
     1485    if($compressed) 
    11761486      $this->_out('/Filter /FlateDecode'); 
    11771487    $this->_out('/Length1 '.$info['length1']); 
     
    11791489      $this->_out('/Length2 '.$info['length2'].' /Length3 0'); 
    11801490    $this->_out('>>'); 
    1181     $f=fopen($file,'rb'); 
    1182     $this->_putstream(fread($f,$size)); 
    1183     fclose($f); 
     1491    $this->_putstream($font); 
    11841492    $this->_out('endobj'); 
    11851493  } 
    1186   set_magic_quotes_runtime($mqr); 
    11871494  foreach($this->fonts as $k=>$font) 
    11881495  { 
     
    11981505      $this->_out('/BaseFont /'.$name); 
    11991506      $this->_out('/Subtype /Type1'); 
    1200       if($name!='Symbol' and $name!='ZapfDingbats') 
     1507      if($name!='Symbol' && $name!='ZapfDingbats') 
    12011508        $this->_out('/Encoding /WinAnsiEncoding'); 
    12021509      $this->_out('>>'); 
    12031510      $this->_out('endobj'); 
    12041511    } 
    1205     elseif($type=='Type1' or $type=='TrueType') 
     1512    elseif($type=='Type1' || $type=='TrueType') 
    12061513    { 
    12071514      //Additional Type1 or TrueType font 
     
    12731580    } 
    12741581    $this->_out('/BitsPerComponent '.$info['bpc']); 
    1275     $this->_out('/Filter /'.$info['f']); 
     1582    if(isset($info['f'])) 
     1583      $this->_out('/Filter /'.$info['f']); 
    12761584    if(isset($info['parms'])) 
    12771585      $this->_out($info['parms']); 
    1278     if(isset($info['trns']) and is_array($info['trns'])) 
     1586    if(isset($info['trns']) && is_array($info['trns'])) 
    12791587    { 
    12801588      $trns=''; 
     
    12991607} 
    13001608 
     1609function _putxobjectdict() 
     1610{ 
     1611  foreach($this->images as $image) 
     1612    $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); 
     1613} 
     1614 
     1615function _putresourcedict() 
     1616{ 
     1617  $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); 
     1618  $this->_out('/Font <<'); 
     1619  foreach($this->fonts as $font) 
     1620    $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); 
     1621  $this->_out('>>'); 
     1622  $this->_out('/XObject <<'); 
     1623  $this->_putxobjectdict(); 
     1624  $this->_out('>>'); 
     1625} 
     1626 
    13011627function _putresources() 
    13021628{ 
     
    13061632  $this->offsets[2]=strlen($this->buffer); 
    13071633  $this->_out('2 0 obj'); 
    1308   $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); 
    1309   $this->_out('/Font <<'); 
    1310   foreach($this->fonts as $font) 
    1311     $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); 
    1312   $this->_out('>>'); 
    1313   if(count($this->images)) 
    1314   { 
    1315     $this->_out('/XObject <<'); 
    1316     foreach($this->images as $image) 
    1317       $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); 
    1318     $this->_out('>>'); 
    1319   } 
     1634  $this->_out('<<'); 
     1635  $this->_putresourcedict(); 
    13201636  $this->_out('>>'); 
    13211637  $this->_out('endobj'); 
     
    13351651  if(!empty($this->creator)) 
    13361652    $this->_out('/Creator '.$this->_textstring($this->creator)); 
    1337   $this->_out('/CreationDate '.$this->_textstring('D:'.date('YmdHis'))); 
     1653  $this->_out('/CreationDate '.$this->_textstring('D:'.@date('YmdHis'))); 
    13381654} 
    13391655 
     
    13581674} 
    13591675 
     1676function _putheader() 
     1677{ 
     1678  $this->_out('%PDF-'.$this->PDFVersion); 
     1679} 
     1680 
    13601681function _puttrailer() 
    13611682{ 
     
    13671688function _enddoc() 
    13681689{ 
     1690  $this->_putheader(); 
    13691691  $this->_putpages(); 
    13701692  $this->_putresources(); 
     
    13981720  $this->state=3; 
    13991721} 
    1400  
    1401 function _beginpage($orientation) 
    1402 { 
    1403   $this->page++; 
    1404   $this->pages[$this->page]=''; 
    1405   $this->state=2; 
    1406   $this->x=$this->lMargin; 
    1407   $this->y=$this->tMargin; 
    1408   $this->FontFamily=''; 
    1409   //Page orientation 
    1410   if(!$orientation) 
    1411     $orientation=$this->DefOrientation; 
    1412   else 
    1413   { 
    1414     $orientation=strtoupper($orientation{0}); 
    1415     if($orientation!=$this->DefOrientation) 
    1416       $this->OrientationChanges[$this->page]=true; 
    1417   } 
    1418   if($orientation!=$this->CurOrientation) 
    1419   { 
    1420     //Change orientation 
    1421     if($orientation=='P') 
    1422     { 
    1423       $this->wPt=$this->fwPt; 
    1424       $this->hPt=$this->fhPt; 
    1425       $this->w=$this->fw; 
    1426       $this->h=$this->fh; 
    1427     } 
    1428     else 
    1429     { 
    1430       $this->wPt=$this->fhPt; 
    1431       $this->hPt=$this->fwPt; 
    1432       $this->w=$this->fh; 
    1433       $this->h=$this->fw; 
    1434     } 
    1435     $this->PageBreakTrigger=$this->h-$this->bMargin; 
    1436     $this->CurOrientation=$orientation; 
    1437   } 
    1438 } 
    1439  
    1440 function _endpage() 
    1441 { 
    1442   //End of page contents 
    1443   $this->state=1; 
    1444 } 
    1445  
    1446 function _newobj() 
    1447 { 
    1448   //Begin a new object 
    1449   $this->n++; 
    1450   $this->offsets[$this->n]=strlen($this->buffer); 
    1451   $this->_out($this->n.' 0 obj'); 
    1452 } 
    1453  
    1454 function _dounderline($x,$y,$txt) 
    1455 { 
    1456   //Underline text 
    1457   $up=$this->CurrentFont['up']; 
    1458   $ut=$this->CurrentFont['ut']; 
    1459   $w=$this->GetStringWidth($txt)+$this->ws*substr_count($txt,' '); 
    1460   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); 
    1461 } 
    1462  
    1463 function _parsejpg($file) 
    1464 { 
    1465   //Extract info from a JPEG file 
    1466   $a=GetImageSize($file); 
    1467   if(!$a) 
    1468     $this->Error('Missing or incorrect image file: '.$file); 
    1469   if($a[2]!=2) 
    1470     $this->Error('Not a JPEG file: '.$file); 
    1471   if(!isset($a['channels']) or $a['channels']==3) 
    1472     $colspace='DeviceRGB'; 
    1473   elseif($a['channels']==4) 
    1474     $colspace='DeviceCMYK'; 
    1475   else 
    1476     $colspace='DeviceGray'; 
    1477   $bpc=isset($a['bits']) ? $a['bits'] : 8; 
    1478   //Read whole file 
    1479   $f=fopen($file,'rb'); 
    1480   $data=''; 
    1481   while(!feof($f)) 
    1482     $data.=fread($f,4096); 
    1483   fclose($f); 
    1484   return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data); 
    1485 } 
    1486  
    1487 function _parsepng($file) 
    1488 { 
    1489   //Extract info from a PNG file 
    1490   $f=fopen($file,'rb'); 
    1491   if(!$f) 
    1492     $this->Error('Can\'t open image file: '.$file); 
    1493   //Check signature 
    1494   if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) 
    1495     $this->Error('Not a PNG file: '.$file); 
    1496   //Read header chunk 
    1497   fread($f,4); 
    1498   if(fread($f,4)!='IHDR') 
    1499     $this->Error('Incorrect PNG file: '.$file); 
    1500   $w=$this->_freadint($f); 
    1501   $h=$this->_freadint($f); 
    1502   $bpc=ord(fread($f,1)); 
    1503   if($bpc>8) 
    1504     $this->Error('16-bit depth not supported: '.$file); 
    1505   $ct=ord(fread($f,1)); 
    1506   if($ct==0) 
    1507     $colspace='DeviceGray'; 
    1508   elseif($ct==2) 
    1509     $colspace='DeviceRGB'; 
    1510   elseif($ct==3) 
    1511     $colspace='Indexed'; 
    1512   else 
    1513     $this->Error('Alpha channel not supported: '.$file); 
    1514   if(ord(fread($f,1))!=0) 
    1515     $this->Error('Unknown compression method: '.$file); 
    1516   if(ord(fread($f,1))!=0) 
    1517     $this->Error('Unknown filter method: '.$file); 
    1518   if(ord(fread($f,1))!=0) 
    1519     $this->Error('Interlacing not supported: '.$file); 
    1520   fread($f,4); 
    1521   $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>'; 
    1522   //Scan chunks looking for palette, transparency and image data 
    1523   $pal=''; 
    1524   $trns=''; 
    1525   $data=''; 
    1526   do 
    1527   { 
    1528     $n=$this->_freadint($f); 
    1529     $type=fread($f,4); 
    1530     if($type=='PLTE') 
    1531     { 
    1532       //Read palette 
    1533       $pal=fread($f,$n); 
    1534       fread($f,4); 
    1535     } 
    1536     elseif($type=='tRNS') 
    1537     { 
    1538       //Read transparency info 
    1539       $t=fread($f,$n); 
    1540       if($ct==0) 
    1541         $trns=array(ord(substr($t,1,1))); 
    1542       elseif($ct==2) 
    1543         $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1))); 
    1544       else 
    1545       { 
    1546         $pos=strpos($t,chr(0)); 
    1547         if(is_int($pos)) 
    1548           $trns=array($pos); 
    1549       } 
    1550       fread($f,4); 
    1551     } 
    1552     elseif($type=='IDAT') 
    1553     { 
    1554       //Read image data block 
    1555       $data.=fread($f,$n); 
    1556       fread($f,4); 
    1557     } 
    1558     elseif($type=='IEND') 
    1559       break; 
    1560     else 
    1561       fread($f,$n+4); 
    1562   } 
    1563   while($n); 
    1564   if($colspace=='Indexed' and empty($pal)) 
    1565     $this->Error('Missing palette in '.$file); 
    1566   fclose($f); 
    1567   return array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$data); 
    1568 } 
    1569  
    1570 function _freadint($f) 
    1571 { 
    1572   //Read a 4-byte integer from file 
    1573   $i=ord(fread($f,1))<<24; 
    1574   $i+=ord(fread($f,1))<<16; 
    1575   $i+=ord(fread($f,1))<<8; 
    1576   $i+=ord(fread($f,1)); 
    1577   return $i; 
    1578 } 
    1579  
    1580 function _textstring($s) 
    1581 { 
    1582   //Format a text string 
    1583   return '('.$this->_escape($s).')'; 
    1584 } 
    1585  
    1586 function _escape($s) 
    1587 { 
    1588   //Add \ before \, ( and ) 
    1589   return str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$s))); 
    1590 } 
    1591  
    1592 function _putstream($s) 
    1593 { 
    1594   $this->_out('stream'); 
    1595   $this->_out($s); 
    1596   $this->_out('endstream'); 
    1597 } 
    1598  
    1599 function _out($s) 
    1600 { 
    1601   //Add a line to the document 
    1602   if($this->state==2) 
    1603     $this->pages[$this->page].=$s."\n"; 
    1604   else 
    1605     $this->buffer.=$s."\n"; 
    1606 } 
    16071722//End of class 
    16081723} 
    16091724 
    16101725//Handle special IE contype request 
    1611 if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and $HTTP_SERVER_VARS['HTTP_USER_AGENT']=='contype') 
    1612 { 
    1613   Header('Content-Type: application/pdf'); 
     1726if(isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT']=='contype') 
     1727{ 
     1728  header('Content-Type: application/pdf'); 
    16141729  exit; 
    16151730} 
    16161731 
    1617 } 
    16181732?>