phpBMS

Show
Ignore:
Timestamp:
12/31/09 13:36:45 (2 years ago)
Author:
brieb
Message:
  • Introduced administratively changeable settings to indvidual reports
  • Modified all reports to work with new settings system
  • Altered invoice and line item total reports to accept parameters from reportsettings: You can now bypass the grouping/column dialog by providing the infrmation administratively
  • Altered all sales order PDF reports to accept parameters from reportsettings: You can now administratively change certain aspects of the print outs, including what parts of the top of the report to show, and what to title the report
  • Altered label reports to accept parameters from reportsettings: printed data as well

as label measurements and layout are now defined by administratively

  • Altered export and tableprint reports to accept parameters from reportsettings: You can specify individual columns and from table instead of just the defaults (all fields, main table only)
  • Added var_dump-esque 'debug' function for development purposes to common functions
  • Integrated FPDI functionality with sales order PDF reports: It is now possible to use a PDF saved in the files table as a background template for your invoices (e.g. watermarks)
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/fpdf/fpdf.php

    r673 r693  
    11<?php 
    22/******************************************************************************* 
    3 * Software: FPDF                                                               * 
    4 * Version:  1.53                                                               * 
    5 * Date:     2004-12-31                                                         * 
    6 * Author:   Olivier PLATHEY                                                    * 
    7 * License:  Freeware                                                           * 
     3* FPDF                                                                         * 
    84*                                                                              * 
    9 * You may use and modify this software as you wish.                            * 
     5* Version: 1.6                                                                 * 
     6* Date:    2008-08-03                                                          * 
     7* Author:  Olivier PLATHEY                                                     * 
    108*******************************************************************************/ 
    119 
    12 if(!class_exists('FPDF')) 
    13 { 
    14 define('FPDF_VERSION','1.53'); 
     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 changes 
    29 var $k;                  //scale factor (number of points in user unit) 
    30 var $fwPt,$fhPt;         //dimensions of page format in points 
    31 var $fw,$fh;             //dimensions of page format in user unit 
    32 var $wPt,$hPt;           //current dimensions of page in points 
    33 var $w,$h;               //current dimensions of page in user unit 
     24var $PageFormats;        //available page formats 
     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 
     
    7673*                                                                              * 
    7774*******************************************************************************/ 
    78 function FPDF($orientation='P',$unit='mm',$format='A4') 
     75function FPDF($orientation='P', $unit='mm', $format='A4') 
    7976{ 
    8077        //Some checks 
     
    8582        $this->buffer=''; 
    8683        $this->pages=array(); 
    87         $this->OrientationChanges=array(); 
     84        $this->PageSizes=array(); 
    8885        $this->state=0; 
    8986        $this->fonts=array(); 
     
    9289        $this->images=array(); 
    9390        $this->links=array(); 
     91        $this->InHeader=false; 
    9492        $this->InFooter=false; 
    9593        $this->lasth=0; 
     
    104102        $this->ws=0; 
    105103        //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'); 
    110108        //Scale factor 
    111109        if($unit=='pt') 
     
    120118                $this->Error('Incorrect unit: '.$unit); 
    121119        //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)); 
    122122        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; 
    147126        //Page orientation 
    148127        $orientation=strtolower($orientation); 
     
    150129        { 
    151130                $this->DefOrientation='P'; 
    152                 $this->wPt=$this->fwPt; 
    153                 $this->hPt=$this->fhPt; 
     131                $this->w=$this->DefPageFormat[0]; 
     132                $this->h=$this->DefPageFormat[1]; 
    154133        } 
    155134        elseif($orientation=='l' || $orientation=='landscape') 
    156135        { 
    157136                $this->DefOrientation='L'; 
    158                 $this->wPt=$this->fhPt; 
    159                 $this->hPt=$this->fwPt; 
     137                $this->w=$this->DefPageFormat[1]; 
     138                $this->h=$this->DefPageFormat[0]; 
    160139        } 
    161140        else 
    162141                $this->Error('Incorrect orientation: '.$orientation); 
    163142        $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; 
    166145        //Page margins (1 cm) 
    167146        $margin=28.35/$this->k; 
     
    181160} 
    182161 
    183 function SetMargins($left,$top,$right=-1) 
     162function SetMargins($left, $top, $right=null) 
    184163{ 
    185164        //Set left, top and right margins 
    186165        $this->lMargin=$left; 
    187166        $this->tMargin=$top; 
    188         if($right==-1) 
     167        if($right===null) 
    189168                $right=$left; 
    190169        $this->rMargin=$right; 
     
    211190} 
    212191 
    213 function SetAutoPageBreak($auto,$margin=0) 
     192function SetAutoPageBreak($auto, $margin=0) 
    214193{ 
    215194        //Set auto page break mode and triggering margin 
     
    219198} 
    220199 
    221 function SetDisplayMode($zoom,$layout='continuous') 
     200function SetDisplayMode($zoom, $layout='continuous') 
    222201{ 
    223202        //Set display mode in viewer 
     
    241220} 
    242221 
    243 function SetTitle($title) 
     222function SetTitle($title, $isUTF8=false) 
    244223{ 
    245224        //Title of document 
     225        if($isUTF8) 
     226                $title=$this->_UTF8toUTF16($title); 
    246227        $this->title=$title; 
    247228} 
    248229 
    249 function SetSubject($subject) 
     230function SetSubject($subject, $isUTF8=false) 
    250231{ 
    251232        //Subject of document 
     233        if($isUTF8) 
     234                $subject=$this->_UTF8toUTF16($subject); 
    252235        $this->subject=$subject; 
    253236} 
    254237 
    255 function SetAuthor($author) 
     238function SetAuthor($author, $isUTF8=false) 
    256239{ 
    257240        //Author of document 
     241        if($isUTF8) 
     242                $author=$this->_UTF8toUTF16($author); 
    258243        $this->author=$author; 
    259244} 
    260245 
    261 function SetKeywords($keywords) 
     246function SetKeywords($keywords, $isUTF8=false) 
    262247{ 
    263248        //Keywords of document 
     249        if($isUTF8) 
     250                $keywords=$this->_UTF8toUTF16($keywords); 
    264251        $this->keywords=$keywords; 
    265252} 
    266253 
    267 function SetCreator($creator) 
     254function SetCreator($creator, $isUTF8=false) 
    268255{ 
    269256        //Creator of document 
     257        if($isUTF8) 
     258                $creator=$this->_UTF8toUTF16($creator); 
    270259        $this->creator=$creator; 
    271260} 
     
    280269{ 
    281270        //Fatal error 
    282         die('<B>FPDF error: </B>'.$msg); 
     271        die('<b>FPDF error:</b> '.$msg); 
    283272} 
    284273 
     
    306295} 
    307296 
    308 function AddPage($orientation='') 
     297function AddPage($orientation='', $format='') 
    309298{ 
    310299        //Start a new page 
     
    329318        } 
    330319        //Start new page 
    331         $this->_beginpage($orientation); 
     320        $this->_beginpage($orientation,$format); 
    332321        //Set line cap style to square 
    333322        $this->_out('2 J'); 
    334323        //Set line width 
    335324        $this->LineWidth=$lw; 
    336         $this->_out(sprintf('%.2f w',$lw*$this->k)); 
     325        $this->_out(sprintf('%.2F w',$lw*$this->k)); 
    337326        //Set font 
    338327        if($family) 
     
    348337        $this->ColorFlag=$cf; 
    349338        //Page header 
     339        $this->InHeader=true; 
    350340        $this->Header(); 
     341        $this->InHeader=false; 
    351342        //Restore line width 
    352343        if($this->LineWidth!=$lw) 
    353344        { 
    354345                $this->LineWidth=$lw; 
    355                 $this->_out(sprintf('%.2f w',$lw*$this->k)); 
     346                $this->_out(sprintf('%.2F w',$lw*$this->k)); 
    356347        } 
    357348        //Restore font 
     
    389380} 
    390381 
    391 function SetDrawColor($r,$g=-1,$b=-1) 
     382function SetDrawColor($r, $g=null, $b=null) 
    392383{ 
    393384        //Set color for all stroking operations 
    394         if(($r==0 && $g==0 && $b==0) || $g==-1) 
    395                 $this->DrawColor=sprintf('%.3f G',$r/255); 
    396         else 
    397                 $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); 
    398389        if($this->page>0) 
    399390                $this->_out($this->DrawColor); 
    400391} 
    401392 
    402 function SetFillColor($r,$g=-1,$b=-1) 
     393function SetFillColor($r, $g=null, $b=null) 
    403394{ 
    404395        //Set color for all filling operations 
    405         if(($r==0 && $g==0 && $b==0) || $g==-1) 
    406                 $this->FillColor=sprintf('%.3f g',$r/255); 
    407         else 
    408                 $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); 
    409400        $this->ColorFlag=($this->FillColor!=$this->TextColor); 
    410401        if($this->page>0) 
     
    412403} 
    413404 
    414 function SetTextColor($r,$g=-1,$b=-1) 
     405function SetTextColor($r, $g=null, $b=null) 
    415406{ 
    416407        //Set color for text 
    417         if(($r==0 && $g==0 && $b==0) || $g==-1) 
    418                 $this->TextColor=sprintf('%.3f g',$r/255); 
    419         else 
    420                 $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); 
    421412        $this->ColorFlag=($this->FillColor!=$this->TextColor); 
    422413} 
     
    430421        $l=strlen($s); 
    431422        for($i=0;$i<$l;$i++) 
    432                 $w+=$cw[$s{$i}]; 
     423                $w+=$cw[$s[$i]]; 
    433424        return $w*$this->FontSize/1000; 
    434425} 
     
    439430        $this->LineWidth=$width; 
    440431        if($this->page>0) 
    441                 $this->_out(sprintf('%.2f w',$width*$this->k)); 
    442 } 
    443  
    444 function Line($x1,$y1,$x2,$y2) 
     432                $this->_out(sprintf('%.2F w',$width*$this->k)); 
     433} 
     434 
     435function Line($x1, $y1, $x2, $y2) 
    445436{ 
    446437        //Draw a line 
    447         $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)); 
    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 
     441function Rect($x, $y, $w, $h, $style='') 
    451442{ 
    452443        //Draw a rectangle 
     
    457448        else 
    458449                $op='S'; 
    459         $this->_out(sprintf('%.2f %.2f %.2f %.2f re %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 
     453function AddFont($family, $style='', $file='') 
    463454{ 
    464455        //Add a TrueType or Type1 font 
     
    473464        $fontkey=$family.$style; 
    474465        if(isset($this->fonts[$fontkey])) 
    475                 $this->Error('Font already added: '.$family.' '.$style); 
     466                return; 
    476467        include($this->_getfontpath().$file); 
    477468        if(!isset($name)) 
    478469                $this->Error('Could not include font definition file'); 
    479470        $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); 
    481472        if($diff) 
    482473        { 
     
    504495                        $this->FontFiles[$file]=array('length1'=>$originalsize); 
    505496                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 
     501function SetFont($family, $style='', $size=0) 
    511502{ 
    512503        //Select a font; size given in points 
     
    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)); 
     601        $s=sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); 
    609602        if($this->underline && $txt!='') 
    610603                $s.=' '.$this->_dounderline($x,$y,$txt); 
     
    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 && !$this->InFooter && $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 || $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)) 
     
    658651                $y=$this->y; 
    659652                if(strpos($border,'L')!==false) 
    660                         $s.=sprintf('%.2f %.2f m %.2f %.2f l 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); 
    661654                if(strpos($border,'T')!==false) 
    662                         $s.=sprintf('%.2f %.2f m %.2f %.2f l 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); 
    663656                if(strpos($border,'R')!==false) 
    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); 
     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); 
    665658                if(strpos($border,'B')!==false) 
    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); 
     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); 
    667660        } 
    668661        if($txt!=='') 
     
    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 
     
    738731        { 
    739732                //Get next character 
    740                 $c=$s{$i}; 
     733                $c=$s[$i]; 
    741734                if($c=="\n") 
    742735                { 
     
    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); 
     
    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' || $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; 
     
    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         //Finish document if necessary 
    997995        if($this->state<3) 
    998996                $this->Close(); 
    999         //Normalize parameters 
    1000         if(is_bool($dest)) 
    1001                 $dest=$dest ? 'D' : 'F'; 
    1002997        $dest=strtoupper($dest); 
    1003998        if($dest=='') 
     
    10151010                case 'I': 
    10161011                        //Send to standard output 
    1017                         if(ob_get_contents()) 
     1012                        if(ob_get_length()) 
    10181013                                $this->Error('Some data has already been output, can\'t send PDF file'); 
    10191014                        if(php_sapi_name()!='cli') 
     
    10221017                                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'); 
     1019                                        $this->Error('Some data has already been output, can\'t send PDF file'); 
    10251020                                header('Content-Length: '.strlen($this->buffer)); 
    1026                                 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'); 
    10271025                        } 
    10281026                        echo $this->buffer; 
     
    10301028                case 'D': 
    10311029                        //Download file 
    1032                         if(ob_get_contents()) 
     1030                        if(ob_get_length()) 
    10331031                                $this->Error('Some data has already been output, can\'t send PDF file'); 
    1034                         if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) 
    1035                                 header('Content-Type: application/force-download'); 
    1036                         else 
    1037                                 header('Content-Type: application/octet-stream'); 
     1032                        header('Content-Type: application/x-download'); 
    10381033                        if(headers_sent()) 
    1039                                 $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'); 
    10401035                        header('Content-Length: '.strlen($this->buffer)); 
    1041                         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'); 
    10421040                        echo $this->buffer; 
    10431041                        break; 
     
    10661064function _dochecks() 
    10671065{ 
    1068         //Check for locale-related bug 
    1069         if(1.1==1) 
    1070                 $this->Error('Don\'t alter the locale before including class file'); 
    1071         //Check for decimal separator 
    1072         if(sprintf('%.1f',1.0)!='1.0') 
    1073                 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 
     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); 
    10741084} 
    10751085 
     
    10811091} 
    10821092 
     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{ 
     1138        $this->state=1; 
     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"; 
     1374} 
     1375 
    10831376function _putpages() 
    10841377{ 
     
    10921385        if($this->DefOrientation=='P') 
    10931386        { 
    1094                 $wPt=$this->fwPt; 
    1095                 $hPt=$this->fhPt; 
    1096         } 
    1097         else 
    1098         { 
    1099                 $wPt=$this->fhPt; 
    1100                 $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; 
    11011394        } 
    11021395        $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; 
     
    11071400                $this->_out('<</Type /Page'); 
    11081401                $this->_out('/Parent 1 0 R'); 
    1109                 if(isset($this->OrientationChanges[$n])) 
    1110                         $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])); 
    11111404                $this->_out('/Resources 2 0 R'); 
    11121405                if(isset($this->PageLinks[$n])) 
     
    11161409                        foreach($this->PageLinks[$n] as $pl) 
    11171410                        { 
    1118                                 $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]); 
    11191412                                $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; 
    11201413                                if(is_string($pl[4])) 
     
    11231416                                { 
    11241417                                        $l=$this->links[$pl[4]]; 
    1125                                         $h=isset($this->OrientationChanges[$l[0]]) ? $wPt : $hPt; 
    1126                                         $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); 
    11271420                                } 
    11281421                        } 
     
    11471440        $this->_out($kids.']'); 
    11481441        $this->_out('/Count '.$nb); 
    1149         $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$wPt,$hPt)); 
     1442        $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]',$wPt,$hPt)); 
    11501443        $this->_out('>>'); 
    11511444        $this->_out('endobj'); 
     
    11621455                $this->_out('endobj'); 
    11631456        } 
    1164         $mqr=get_magic_quotes_runtime(); 
    1165         @set_magic_quotes_runtime(0); 
    11661457        foreach($this->FontFiles as $file=>$info) 
    11671458        { 
     
    11791470                if(!$compressed && isset($info['length2'])) 
    11801471                { 
    1181                         $header=(ord($font{0})==128); 
     1472                        $header=(ord($font[0])==128); 
    11821473                        if($header) 
    11831474                        { 
     
    11851476                                $font=substr($font,6); 
    11861477                        } 
    1187                         if($header && ord($font{$info['length1']})==128) 
     1478                        if($header && ord($font[$info['length1']])==128) 
    11881479                        { 
    11891480                                //Strip second binary header 
     
    12011492                $this->_out('endobj'); 
    12021493        } 
    1203         @set_magic_quotes_runtime($mqr); 
    12041494        foreach($this->fonts as $k=>$font) 
    12051495        { 
     
    13611651        if(!empty($this->creator)) 
    13621652                $this->_out('/Creator '.$this->_textstring($this->creator)); 
    1363         $this->_out('/CreationDate '.$this->_textstring('D:'.date('YmdHis'))); 
     1653        $this->_out('/CreationDate '.$this->_textstring('D:'.@date('YmdHis'))); 
    13641654} 
    13651655 
     
    14301720        $this->state=3; 
    14311721} 
    1432  
    1433 function _beginpage($orientation) 
    1434 { 
    1435         $this->page++; 
    1436         $this->pages[$this->page]=''; 
    1437         $this->state=2; 
    1438         $this->x=$this->lMargin; 
    1439         $this->y=$this->tMargin; 
    1440         $this->FontFamily=''; 
    1441         //Page orientation 
    1442         if(!$orientation) 
    1443                 $orientation=$this->DefOrientation; 
    1444         else 
    1445         { 
    1446                 $orientation=strtoupper($orientation{0}); 
    1447                 if($orientation!=$this->DefOrientation) 
    1448                         $this->OrientationChanges[$this->page]=true; 
    1449         } 
    1450         if($orientation!=$this->CurOrientation) 
    1451         { 
    1452                 //Change orientation 
    1453                 if($orientation=='P') 
    1454                 { 
    1455                         $this->wPt=$this->fwPt; 
    1456                         $this->hPt=$this->fhPt; 
    1457                         $this->w=$this->fw; 
    1458                         $this->h=$this->fh; 
    1459                 } 
    1460                 else 
    1461                 { 
    1462                         $this->wPt=$this->fhPt; 
    1463                         $this->hPt=$this->fwPt; 
    1464                         $this->w=$this->fh; 
    1465                         $this->h=$this->fw; 
    1466                 } 
    1467                 $this->PageBreakTrigger=$this->h-$this->bMargin; 
    1468                 $this->CurOrientation=$orientation; 
    1469         } 
    1470 } 
    1471  
    1472 function _endpage() 
    1473 { 
    1474         //End of page contents 
    1475         $this->state=1; 
    1476 } 
    1477  
    1478 function _newobj() 
    1479 { 
    1480         //Begin a new object 
    1481         $this->n++; 
    1482         $this->offsets[$this->n]=strlen($this->buffer); 
    1483         $this->_out($this->n.' 0 obj'); 
    1484 } 
    1485  
    1486 function _dounderline($x,$y,$txt) 
    1487 { 
    1488         //Underline text 
    1489         $up=$this->CurrentFont['up']; 
    1490         $ut=$this->CurrentFont['ut']; 
    1491         $w=$this->GetStringWidth($txt)+$this->ws*substr_count($txt,' '); 
    1492         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); 
    1493 } 
    1494  
    1495 function _parsejpg($file) 
    1496 { 
    1497         //Extract info from a JPEG file 
    1498         $a=GetImageSize($file); 
    1499         if(!$a) 
    1500                 $this->Error('Missing or incorrect image file: '.$file); 
    1501         if($a[2]!=2) 
    1502                 $this->Error('Not a JPEG file: '.$file); 
    1503         if(!isset($a['channels']) || $a['channels']==3) 
    1504                 $colspace='DeviceRGB'; 
    1505         elseif($a['channels']==4) 
    1506                 $colspace='DeviceCMYK'; 
    1507         else 
    1508                 $colspace='DeviceGray'; 
    1509         $bpc=isset($a['bits']) ? $a['bits'] : 8; 
    1510         //Read whole file 
    1511         $f=fopen($file,'rb'); 
    1512         $data=''; 
    1513         while(!feof($f)) 
    1514                 $data.=fread($f,4096); 
    1515         fclose($f); 
    1516         return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data); 
    1517 } 
    1518  
    1519 function _parsepng($file) 
    1520 { 
    1521         //Extract info from a PNG file 
    1522         $f=fopen($file,'rb'); 
    1523         if(!$f) 
    1524                 $this->Error('Can\'t open image file: '.$file); 
    1525         //Check signature 
    1526         if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) 
    1527                 $this->Error('Not a PNG file: '.$file); 
    1528         //Read header chunk 
    1529         fread($f,4); 
    1530         if(fread($f,4)!='IHDR') 
    1531                 $this->Error('Incorrect PNG file: '.$file); 
    1532         $w=$this->_freadint($f); 
    1533         $h=$this->_freadint($f); 
    1534         $bpc=ord(fread($f,1)); 
    1535         if($bpc>8) 
    1536                 $this->Error('16-bit depth not supported: '.$file); 
    1537         $ct=ord(fread($f,1)); 
    1538         if($ct==0) 
    1539                 $colspace='DeviceGray'; 
    1540         elseif($ct==2) 
    1541                 $colspace='DeviceRGB'; 
    1542         elseif($ct==3) 
    1543                 $colspace='Indexed'; 
    1544         else 
    1545                 $this->Error('Alpha channel not supported: '.$file); 
    1546         if(ord(fread($f,1))!=0) 
    1547                 $this->Error('Unknown compression method: '.$file); 
    1548         if(ord(fread($f,1))!=0) 
    1549                 $this->Error('Unknown filter method: '.$file); 
    1550         if(ord(fread($f,1))!=0) 
    1551                 $this->Error('Interlacing not supported: '.$file); 
    1552         fread($f,4); 
    1553         $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>'; 
    1554         //Scan chunks looking for palette, transparency and image data 
    1555         $pal=''; 
    1556         $trns=''; 
    1557         $data=''; 
    1558         do 
    1559         { 
    1560                 $n=$this->_freadint($f); 
    1561                 $type=fread($f,4); 
    1562                 if($type=='PLTE') 
    1563                 { 
    1564                         //Read palette 
    1565                         $pal=fread($f,$n); 
    1566                         fread($f,4); 
    1567                 } 
    1568                 elseif($type=='tRNS') 
    1569                 { 
    1570                         //Read transparency info 
    1571                         $t=fread($f,$n); 
    1572                         if($ct==0) 
    1573                                 $trns=array(ord(substr($t,1,1))); 
    1574                         elseif($ct==2) 
    1575                                 $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1))); 
    1576                         else 
    1577                         { 
    1578                                 $pos=strpos($t,chr(0)); 
    1579                                 if($pos!==false) 
    1580                                         $trns=array($pos); 
    1581                         } 
    1582                         fread($f,4); 
    1583                 } 
    1584                 elseif($type=='IDAT') 
    1585                 { 
    1586                         //Read image data block 
    1587                         $data.=fread($f,$n); 
    1588                         fread($f,4); 
    1589                 } 
    1590                 elseif($type=='IEND') 
    1591                         break; 
    1592                 else 
    1593                         fread($f,$n+4); 
    1594         } 
    1595         while($n); 
    1596         if($colspace=='Indexed' && empty($pal)) 
    1597                 $this->Error('Missing palette in '.$file); 
    1598         fclose($f); 
    1599         return array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$data); 
    1600 } 
    1601  
    1602 function _freadint($f) 
    1603 { 
    1604         //Read a 4-byte integer from file 
    1605         $a=unpack('Ni',fread($f,4)); 
    1606         return $a['i']; 
    1607 } 
    1608  
    1609 function _textstring($s) 
    1610 { 
    1611         //Format a text string 
    1612         return '('.$this->_escape($s).')'; 
    1613 } 
    1614  
    1615 function _escape($s) 
    1616 { 
    1617         //Add \ before \, ( and ) 
    1618         return str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$s))); 
    1619 } 
    1620  
    1621 function _putstream($s) 
    1622 { 
    1623         $this->_out('stream'); 
    1624         $this->_out($s); 
    1625         $this->_out('endstream'); 
    1626 } 
    1627  
    1628 function _out($s) 
    1629 { 
    1630         //Add a line to the document 
    1631         if($this->state==2) 
    1632                 $this->pages[$this->page].=$s."\n"; 
    1633         else 
    1634                 $this->buffer.=$s."\n"; 
    1635 } 
    16361722//End of class 
    16371723} 
     
    16441730} 
    16451731 
    1646 } 
    16471732?> 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.