Ignore:
Timestamp:
2011/06/25 16:45:04 (15 years ago)
Author:
Seasoft
Message:

#1374 (依存ライブラリのアップデート)

  • FPDF 1.6 -> 1.7
  • FPDI 1.4 -> 1.4.1 (配置パスをFPDFから分離)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_11-dev/data/module/fpdf/fpdf.php

    r20119 r20993  
    33* FPDF                                                                         * 
    44*                                                                              * 
    5 * Version: 1.6                                                                 * 
    6 * Date:    2008-08-03                                                          * 
     5* Version: 1.7                                                                 * 
     6* Date:    2011-06-18                                                          * 
    77* Author:  Olivier PLATHEY                                                     * 
    88*******************************************************************************/ 
    99 
    10 define('FPDF_VERSION','1.6'); 
     10define('FPDF_VERSION','1.7'); 
    1111 
    1212class FPDF 
    1313{ 
    14 var $page;               //current page number 
    15 var $n;                  //current object number 
    16 var $offsets;            //array of object offsets 
    17 var $buffer;             //buffer holding in-memory PDF 
    18 var $pages;              //array containing pages 
    19 var $state;              //current document state 
    20 var $compress;           //compression flag 
    21 var $k;                  //scale factor (number of points in user unit) 
    22 var $DefOrientation;     //default orientation 
    23 var $CurOrientation;     //current orientation 
    24 var $PageFormats;        //available page formats 
    25 var $DefPageFormat;      //default page format 
    26 var $CurPageFormat;      //current page format 
    27 var $PageSizes;          //array storing non-default page sizes 
    28 var $wPt,$hPt;           //dimensions of current page in points 
    29 var $w,$h;               //dimensions of current page in user unit 
    30 var $lMargin;            //left margin 
    31 var $tMargin;            //top margin 
    32 var $rMargin;            //right margin 
    33 var $bMargin;            //page break margin 
    34 var $cMargin;            //cell margin 
    35 var $x,$y;               //current position in user unit 
    36 var $lasth;              //height of last printed cell 
    37 var $LineWidth;          //line width in user unit 
    38 var $CoreFonts;          //array of standard font names 
    39 var $fonts;              //array of used fonts 
    40 var $FontFiles;          //array of font files 
    41 var $diffs;              //array of encoding differences 
    42 var $FontFamily;         //current font family 
    43 var $FontStyle;          //current font style 
    44 var $underline;          //underlining flag 
    45 var $CurrentFont;        //current font info 
    46 var $FontSizePt;         //current font size in points 
    47 var $FontSize;           //current font size in user unit 
    48 var $DrawColor;          //commands for drawing color 
    49 var $FillColor;          //commands for filling color 
    50 var $TextColor;          //commands for text color 
    51 var $ColorFlag;          //indicates whether fill and text colors are different 
    52 var $ws;                 //word spacing 
    53 var $images;             //array of used images 
    54 var $PageLinks;          //array of links in pages 
    55 var $links;              //array of internal links 
    56 var $AutoPageBreak;      //automatic page breaking 
    57 var $PageBreakTrigger;   //threshold used to trigger page breaks 
    58 var $InHeader;           //flag set when processing header 
    59 var $InFooter;           //flag set when processing footer 
    60 var $ZoomMode;           //zoom display mode 
    61 var $LayoutMode;         //layout display mode 
    62 var $title;              //title 
    63 var $subject;            //subject 
    64 var $author;             //author 
    65 var $keywords;           //keywords 
    66 var $creator;            //creator 
    67 var $AliasNbPages;       //alias for total number of pages 
    68 var $PDFVersion;         //PDF version number 
     14var $page;               // current page number 
     15var $n;                  // current object number 
     16var $offsets;            // array of object offsets 
     17var $buffer;             // buffer holding in-memory PDF 
     18var $pages;              // array containing pages 
     19var $state;              // current document state 
     20var $compress;           // compression flag 
     21var $k;                  // scale factor (number of points in user unit) 
     22var $DefOrientation;     // default orientation 
     23var $CurOrientation;     // current orientation 
     24var $StdPageSizes;       // standard page sizes 
     25var $DefPageSize;        // default page size 
     26var $CurPageSize;        // current page size 
     27var $PageSizes;          // used for pages with non default sizes or orientations 
     28var $wPt, $hPt;          // dimensions of current page in points 
     29var $w, $h;              // dimensions of current page in user unit 
     30var $lMargin;            // left margin 
     31var $tMargin;            // top margin 
     32var $rMargin;            // right margin 
     33var $bMargin;            // page break margin 
     34var $cMargin;            // cell margin 
     35var $x, $y;              // current position in user unit 
     36var $lasth;              // height of last printed cell 
     37var $LineWidth;          // line width in user unit 
     38var $fontpath;           // path containing fonts 
     39var $CoreFonts;          // array of core font names 
     40var $fonts;              // array of used fonts 
     41var $FontFiles;          // array of font files 
     42var $diffs;              // array of encoding differences 
     43var $FontFamily;         // current font family 
     44var $FontStyle;          // current font style 
     45var $underline;          // underlining flag 
     46var $CurrentFont;        // current font info 
     47var $FontSizePt;         // current font size in points 
     48var $FontSize;           // current font size in user unit 
     49var $DrawColor;          // commands for drawing color 
     50var $FillColor;          // commands for filling color 
     51var $TextColor;          // commands for text color 
     52var $ColorFlag;          // indicates whether fill and text colors are different 
     53var $ws;                 // word spacing 
     54var $images;             // array of used images 
     55var $PageLinks;          // array of links in pages 
     56var $links;              // array of internal links 
     57var $AutoPageBreak;      // automatic page breaking 
     58var $PageBreakTrigger;   // threshold used to trigger page breaks 
     59var $InHeader;           // flag set when processing header 
     60var $InFooter;           // flag set when processing footer 
     61var $ZoomMode;           // zoom display mode 
     62var $LayoutMode;         // layout display mode 
     63var $title;              // title 
     64var $subject;            // subject 
     65var $author;             // author 
     66var $keywords;           // keywords 
     67var $creator;            // creator 
     68var $AliasNbPages;       // alias for total number of pages 
     69var $PDFVersion;         // PDF version number 
    6970 
    7071/******************************************************************************* 
     
    7374*                                                                              * 
    7475*******************************************************************************/ 
    75 function FPDF($orientation='P', $unit='mm', $format='A4') 
    76 { 
    77     //Some checks 
     76function FPDF($orientation='P', $unit='mm', $size='A4') 
     77{ 
     78    // Some checks 
    7879    $this->_dochecks(); 
    79     //Initialization of properties 
    80     $this->page=0; 
    81     $this->n=2; 
    82     $this->buffer=''; 
    83     $this->pages=array(); 
    84     $this->PageSizes=array(); 
    85     $this->state=0; 
    86     $this->fonts=array(); 
    87     $this->FontFiles=array(); 
    88     $this->diffs=array(); 
    89     $this->images=array(); 
    90     $this->links=array(); 
    91     $this->InHeader=false; 
    92     $this->InFooter=false; 
    93     $this->lasth=0; 
    94     $this->FontFamily=''; 
    95     $this->FontStyle=''; 
    96     $this->FontSizePt=12; 
    97     $this->underline=false; 
    98     $this->DrawColor='0 G'; 
    99     $this->FillColor='0 g'; 
    100     $this->TextColor='0 g'; 
    101     $this->ColorFlag=false; 
    102     $this->ws=0; 
    103     //Standard fonts 
    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'); 
    108     //Scale factor 
     80    // Initialization of properties 
     81    $this->page = 0; 
     82    $this->n = 2; 
     83    $this->buffer = ''; 
     84    $this->pages = array(); 
     85    $this->PageSizes = array(); 
     86    $this->state = 0; 
     87    $this->fonts = array(); 
     88    $this->FontFiles = array(); 
     89    $this->diffs = array(); 
     90    $this->images = array(); 
     91    $this->links = array(); 
     92    $this->InHeader = false; 
     93    $this->InFooter = false; 
     94    $this->lasth = 0; 
     95    $this->FontFamily = ''; 
     96    $this->FontStyle = ''; 
     97    $this->FontSizePt = 12; 
     98    $this->underline = false; 
     99    $this->DrawColor = '0 G'; 
     100    $this->FillColor = '0 g'; 
     101    $this->TextColor = '0 g'; 
     102    $this->ColorFlag = false; 
     103    $this->ws = 0; 
     104    // Font path 
     105    if(defined('FPDF_FONTPATH')) 
     106    { 
     107        $this->fontpath = FPDF_FONTPATH; 
     108        if(substr($this->fontpath,-1)!='/' && substr($this->fontpath,-1)!='\\') 
     109            $this->fontpath .= '/'; 
     110    } 
     111    elseif(is_dir(dirname(__FILE__).'/font')) 
     112        $this->fontpath = dirname(__FILE__).'/font/'; 
     113    else 
     114        $this->fontpath = ''; 
     115    // Core fonts 
     116    $this->CoreFonts = array('courier', 'helvetica', 'times', 'symbol', 'zapfdingbats'); 
     117    // Scale factor 
    109118    if($unit=='pt') 
    110         $this->k=1; 
     119        $this->k = 1; 
    111120    elseif($unit=='mm') 
    112         $this->k=72/25.4; 
     121        $this->k = 72/25.4; 
    113122    elseif($unit=='cm') 
    114         $this->k=72/2.54; 
     123        $this->k = 72/2.54; 
    115124    elseif($unit=='in') 
    116         $this->k=72; 
     125        $this->k = 72; 
    117126    else 
    118127        $this->Error('Incorrect unit: '.$unit); 
    119     //Page format 
    120     $this->PageFormats=array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28), 
     128    // Page sizes 
     129    $this->StdPageSizes = array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28), 
    121130        'letter'=>array(612,792), 'legal'=>array(612,1008)); 
    122     if(is_string($format)) 
    123         $format=$this->_getpageformat($format); 
    124     $this->DefPageFormat=$format; 
    125     $this->CurPageFormat=$format; 
    126     //Page orientation 
    127     $orientation=strtolower($orientation); 
     131    $size = $this->_getpagesize($size); 
     132    $this->DefPageSize = $size; 
     133    $this->CurPageSize = $size; 
     134    // Page orientation 
     135    $orientation = strtolower($orientation); 
    128136    if($orientation=='p' || $orientation=='portrait') 
    129137    { 
    130         $this->DefOrientation='P'; 
    131         $this->w=$this->DefPageFormat[0]; 
    132         $this->h=$this->DefPageFormat[1]; 
     138        $this->DefOrientation = 'P'; 
     139        $this->w = $size[0]; 
     140        $this->h = $size[1]; 
    133141    } 
    134142    elseif($orientation=='l' || $orientation=='landscape') 
    135143    { 
    136         $this->DefOrientation='L'; 
    137         $this->w=$this->DefPageFormat[1]; 
    138         $this->h=$this->DefPageFormat[0]; 
     144        $this->DefOrientation = 'L'; 
     145        $this->w = $size[1]; 
     146        $this->h = $size[0]; 
    139147    } 
    140148    else 
    141149        $this->Error('Incorrect orientation: '.$orientation); 
    142     $this->CurOrientation=$this->DefOrientation; 
    143     $this->wPt=$this->w*$this->k; 
    144     $this->hPt=$this->h*$this->k; 
    145     //Page margins (1 cm) 
    146     $margin=28.35/$this->k; 
     150    $this->CurOrientation = $this->DefOrientation; 
     151    $this->wPt = $this->w*$this->k; 
     152    $this->hPt = $this->h*$this->k; 
     153    // Page margins (1 cm) 
     154    $margin = 28.35/$this->k; 
    147155    $this->SetMargins($margin,$margin); 
    148     //Interior cell margin (1 mm) 
    149     $this->cMargin=$margin/10; 
    150     //Line width (0.2 mm) 
    151     $this->LineWidth=.567/$this->k; 
    152     //Automatic page break 
     156    // Interior cell margin (1 mm) 
     157    $this->cMargin = $margin/10; 
     158    // Line width (0.2 mm) 
     159    $this->LineWidth = .567/$this->k; 
     160    // Automatic page break 
    153161    $this->SetAutoPageBreak(true,2*$margin); 
    154     //Full width display mode 
    155     $this->SetDisplayMode('fullwidth'); 
    156     //Enable compression 
     162    // Default display mode 
     163    $this->SetDisplayMode('default'); 
     164    // Enable compression 
    157165    $this->SetCompression(true); 
    158     //Set default PDF version number 
    159     $this->PDFVersion='1.3'; 
     166    // Set default PDF version number 
     167    $this->PDFVersion = '1.3'; 
    160168} 
    161169 
    162170function SetMargins($left, $top, $right=null) 
    163171{ 
    164     //Set left, top and right margins 
    165     $this->lMargin=$left; 
    166     $this->tMargin=$top; 
     172    // Set left, top and right margins 
     173    $this->lMargin = $left; 
     174    $this->tMargin = $top; 
    167175    if($right===null) 
    168         $right=$left; 
    169     $this->rMargin=$right; 
     176        $right = $left; 
     177    $this->rMargin = $right; 
    170178} 
    171179 
    172180function SetLeftMargin($margin) 
    173181{ 
    174     //Set left margin 
    175     $this->lMargin=$margin; 
     182    // Set left margin 
     183    $this->lMargin = $margin; 
    176184    if($this->page>0 && $this->x<$margin) 
    177         $this->x=$margin; 
     185        $this->x = $margin; 
    178186} 
    179187 
    180188function SetTopMargin($margin) 
    181189{ 
    182     //Set top margin 
    183     $this->tMargin=$margin; 
     190    // Set top margin 
     191    $this->tMargin = $margin; 
    184192} 
    185193 
    186194function SetRightMargin($margin) 
    187195{ 
    188     //Set right margin 
    189     $this->rMargin=$margin; 
     196    // Set right margin 
     197    $this->rMargin = $margin; 
    190198} 
    191199 
    192200function SetAutoPageBreak($auto, $margin=0) 
    193201{ 
    194     //Set auto page break mode and triggering margin 
    195     $this->AutoPageBreak=$auto; 
    196     $this->bMargin=$margin; 
    197     $this->PageBreakTrigger=$this->h-$margin; 
    198 } 
    199  
    200 function SetDisplayMode($zoom, $layout='continuous') 
    201 { 
    202     //Set display mode in viewer 
     202    // Set auto page break mode and triggering margin 
     203    $this->AutoPageBreak = $auto; 
     204    $this->bMargin = $margin; 
     205    $this->PageBreakTrigger = $this->h-$margin; 
     206} 
     207 
     208function SetDisplayMode($zoom, $layout='default') 
     209{ 
     210    // Set display mode in viewer 
    203211    if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) 
    204         $this->ZoomMode=$zoom; 
     212        $this->ZoomMode = $zoom; 
    205213    else 
    206214        $this->Error('Incorrect zoom display mode: '.$zoom); 
    207215    if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') 
    208         $this->LayoutMode=$layout; 
     216        $this->LayoutMode = $layout; 
    209217    else 
    210218        $this->Error('Incorrect layout display mode: '.$layout); 
     
    213221function SetCompression($compress) 
    214222{ 
    215     //Set page compression 
     223    // Set page compression 
    216224    if(function_exists('gzcompress')) 
    217         $this->compress=$compress; 
    218     else 
    219         $this->compress=false; 
     225        $this->compress = $compress; 
     226    else 
     227        $this->compress = false; 
    220228} 
    221229 
    222230function SetTitle($title, $isUTF8=false) 
    223231{ 
    224     //Title of document 
     232    // Title of document 
    225233    if($isUTF8) 
    226         $title=$this->_UTF8toUTF16($title); 
    227     $this->title=$title; 
     234        $title = $this->_UTF8toUTF16($title); 
     235    $this->title = $title; 
    228236} 
    229237 
    230238function SetSubject($subject, $isUTF8=false) 
    231239{ 
    232     //Subject of document 
     240    // Subject of document 
    233241    if($isUTF8) 
    234         $subject=$this->_UTF8toUTF16($subject); 
    235     $this->subject=$subject; 
     242        $subject = $this->_UTF8toUTF16($subject); 
     243    $this->subject = $subject; 
    236244} 
    237245 
    238246function SetAuthor($author, $isUTF8=false) 
    239247{ 
    240     //Author of document 
     248    // Author of document 
    241249    if($isUTF8) 
    242         $author=$this->_UTF8toUTF16($author); 
    243     $this->author=$author; 
     250        $author = $this->_UTF8toUTF16($author); 
     251    $this->author = $author; 
    244252} 
    245253 
    246254function SetKeywords($keywords, $isUTF8=false) 
    247255{ 
    248     //Keywords of document 
     256    // Keywords of document 
    249257    if($isUTF8) 
    250         $keywords=$this->_UTF8toUTF16($keywords); 
    251     $this->keywords=$keywords; 
     258        $keywords = $this->_UTF8toUTF16($keywords); 
     259    $this->keywords = $keywords; 
    252260} 
    253261 
    254262function SetCreator($creator, $isUTF8=false) 
    255263{ 
    256     //Creator of document 
     264    // Creator of document 
    257265    if($isUTF8) 
    258         $creator=$this->_UTF8toUTF16($creator); 
    259     $this->creator=$creator; 
     266        $creator = $this->_UTF8toUTF16($creator); 
     267    $this->creator = $creator; 
    260268} 
    261269 
    262270function AliasNbPages($alias='{nb}') 
    263271{ 
    264     //Define an alias for total number of pages 
    265     $this->AliasNbPages=$alias; 
     272    // Define an alias for total number of pages 
     273    $this->AliasNbPages = $alias; 
    266274} 
    267275 
    268276function Error($msg) 
    269277{ 
    270     //Fatal error 
     278    // Fatal error 
    271279    die('<b>FPDF error:</b> '.$msg); 
    272280} 
     
    274282function Open() 
    275283{ 
    276     //Begin document 
    277     $this->state=1; 
     284    // Begin document 
     285    $this->state = 1; 
    278286} 
    279287 
    280288function Close() 
    281289{ 
    282     //Terminate document 
     290    // Terminate document 
    283291    if($this->state==3) 
    284292        return; 
    285293    if($this->page==0) 
    286294        $this->AddPage(); 
    287     //Page footer 
    288     $this->InFooter=true; 
     295    // Page footer 
     296    $this->InFooter = true; 
    289297    $this->Footer(); 
    290     $this->InFooter=false; 
    291     //Close page 
     298    $this->InFooter = false; 
     299    // Close page 
    292300    $this->_endpage(); 
    293     //Close document 
     301    // Close document 
    294302    $this->_enddoc(); 
    295303} 
    296304 
    297 function AddPage($orientation='', $format='') 
    298 { 
    299     //Start a new page 
     305function AddPage($orientation='', $size='') 
     306{ 
     307    // Start a new page 
    300308    if($this->state==0) 
    301309        $this->Open(); 
    302     $family=$this->FontFamily; 
    303     $style=$this->FontStyle.($this->underline ? 'U' : ''); 
    304     $size=$this->FontSizePt; 
    305     $lw=$this->LineWidth; 
    306     $dc=$this->DrawColor; 
    307     $fc=$this->FillColor; 
    308     $tc=$this->TextColor; 
    309     $cf=$this->ColorFlag; 
     310    $family = $this->FontFamily; 
     311    $style = $this->FontStyle.($this->underline ? 'U' : ''); 
     312    $fontsize = $this->FontSizePt; 
     313    $lw = $this->LineWidth; 
     314    $dc = $this->DrawColor; 
     315    $fc = $this->FillColor; 
     316    $tc = $this->TextColor; 
     317    $cf = $this->ColorFlag; 
    310318    if($this->page>0) 
    311319    { 
    312         //Page footer 
    313         $this->InFooter=true; 
     320        // Page footer 
     321        $this->InFooter = true; 
    314322        $this->Footer(); 
    315         $this->InFooter=false; 
    316         //Close page 
     323        $this->InFooter = false; 
     324        // Close page 
    317325        $this->_endpage(); 
    318326    } 
    319     //Start new page 
    320     $this->_beginpage($orientation,$format); 
    321     //Set line cap style to square 
     327    // Start new page 
     328    $this->_beginpage($orientation,$size); 
     329    // Set line cap style to square 
    322330    $this->_out('2 J'); 
    323     //Set line width 
    324     $this->LineWidth=$lw; 
     331    // Set line width 
     332    $this->LineWidth = $lw; 
    325333    $this->_out(sprintf('%.2F w',$lw*$this->k)); 
    326     //Set font 
     334    // Set font 
    327335    if($family) 
    328         $this->SetFont($family,$style,$size); 
    329     //Set colors 
    330     $this->DrawColor=$dc; 
     336        $this->SetFont($family,$style,$fontsize); 
     337    // Set colors 
     338    $this->DrawColor = $dc; 
    331339    if($dc!='0 G') 
    332340        $this->_out($dc); 
    333     $this->FillColor=$fc; 
     341    $this->FillColor = $fc; 
    334342    if($fc!='0 g') 
    335343        $this->_out($fc); 
    336     $this->TextColor=$tc; 
    337     $this->ColorFlag=$cf; 
    338     //Page header 
    339     $this->InHeader=true; 
     344    $this->TextColor = $tc; 
     345    $this->ColorFlag = $cf; 
     346    // Page header 
     347    $this->InHeader = true; 
    340348    $this->Header(); 
    341     $this->InHeader=false; 
    342     //Restore line width 
     349    $this->InHeader = false; 
     350    // Restore line width 
    343351    if($this->LineWidth!=$lw) 
    344352    { 
    345         $this->LineWidth=$lw; 
     353        $this->LineWidth = $lw; 
    346354        $this->_out(sprintf('%.2F w',$lw*$this->k)); 
    347355    } 
    348     //Restore font 
     356    // Restore font 
    349357    if($family) 
    350         $this->SetFont($family,$style,$size); 
    351     //Restore colors 
     358        $this->SetFont($family,$style,$fontsize); 
     359    // Restore colors 
    352360    if($this->DrawColor!=$dc) 
    353361    { 
    354         $this->DrawColor=$dc; 
     362        $this->DrawColor = $dc; 
    355363        $this->_out($dc); 
    356364    } 
    357365    if($this->FillColor!=$fc) 
    358366    { 
    359         $this->FillColor=$fc; 
     367        $this->FillColor = $fc; 
    360368        $this->_out($fc); 
    361369    } 
    362     $this->TextColor=$tc; 
    363     $this->ColorFlag=$cf; 
     370    $this->TextColor = $tc; 
     371    $this->ColorFlag = $cf; 
    364372} 
    365373 
    366374function Header() 
    367375{ 
    368     //To be implemented in your own inherited class 
     376    // To be implemented in your own inherited class 
    369377} 
    370378 
    371379function Footer() 
    372380{ 
    373     //To be implemented in your own inherited class 
     381    // To be implemented in your own inherited class 
    374382} 
    375383 
    376384function PageNo() 
    377385{ 
    378     //Get current page number 
     386    // Get current page number 
    379387    return $this->page; 
    380388} 
     
    382390function SetDrawColor($r, $g=null, $b=null) 
    383391{ 
    384     //Set color for all stroking operations 
     392    // Set color for all stroking operations 
    385393    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); 
     394        $this->DrawColor = sprintf('%.3F G',$r/255); 
     395    else 
     396        $this->DrawColor = sprintf('%.3F %.3F %.3F RG',$r/255,$g/255,$b/255); 
    389397    if($this->page>0) 
    390398        $this->_out($this->DrawColor); 
     
    393401function SetFillColor($r, $g=null, $b=null) 
    394402{ 
    395     //Set color for all filling operations 
     403    // Set color for all filling operations 
    396404    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); 
    400     $this->ColorFlag=($this->FillColor!=$this->TextColor); 
     405        $this->FillColor = sprintf('%.3F g',$r/255); 
     406    else 
     407        $this->FillColor = sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255); 
     408    $this->ColorFlag = ($this->FillColor!=$this->TextColor); 
    401409    if($this->page>0) 
    402410        $this->_out($this->FillColor); 
     
    405413function SetTextColor($r, $g=null, $b=null) 
    406414{ 
    407     //Set color for text 
     415    // Set color for text 
    408416    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); 
    412     $this->ColorFlag=($this->FillColor!=$this->TextColor); 
     417        $this->TextColor = sprintf('%.3F g',$r/255); 
     418    else 
     419        $this->TextColor = sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255); 
     420    $this->ColorFlag = ($this->FillColor!=$this->TextColor); 
    413421} 
    414422 
    415423function GetStringWidth($s) 
    416424{ 
    417     //Get width of a string in the current font 
    418     $s=(string)$s; 
    419     $cw=&$this->CurrentFont['cw']; 
    420     $w=0; 
    421     $l=strlen($s); 
     425    // Get width of a string in the current font 
     426    $s = (string)$s; 
     427    $cw = &$this->CurrentFont['cw']; 
     428    $w = 0; 
     429    $l = strlen($s); 
    422430    for($i=0;$i<$l;$i++) 
    423         $w+=$cw[$s[$i]]; 
     431        $w += $cw[$s[$i]]; 
    424432    return $w*$this->FontSize/1000; 
    425433} 
     
    427435function SetLineWidth($width) 
    428436{ 
    429     //Set line width 
    430     $this->LineWidth=$width; 
     437    // Set line width 
     438    $this->LineWidth = $width; 
    431439    if($this->page>0) 
    432440        $this->_out(sprintf('%.2F w',$width*$this->k)); 
     
    435443function Line($x1, $y1, $x2, $y2) 
    436444{ 
    437     //Draw a line 
     445    // Draw a line 
    438446    $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)); 
    439447} 
     
    441449function Rect($x, $y, $w, $h, $style='') 
    442450{ 
    443     //Draw a rectangle 
     451    // Draw a rectangle 
    444452    if($style=='F') 
    445         $op='f'; 
     453        $op = 'f'; 
    446454    elseif($style=='FD' || $style=='DF') 
    447         $op='B'; 
    448     else 
    449         $op='S'; 
     455        $op = 'B'; 
     456    else 
     457        $op = 'S'; 
    450458    $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); 
    451459} 
     
    453461function AddFont($family, $style='', $file='') 
    454462{ 
    455     //Add a TrueType or Type1 font 
    456     $family=strtolower($family); 
     463    // Add a TrueType, OpenType or Type1 font 
     464    $family = strtolower($family); 
    457465    if($file=='') 
    458         $file=str_replace(' ','',$family).strtolower($style).'.php'; 
    459     if($family=='arial') 
    460         $family='helvetica'; 
    461     $style=strtoupper($style); 
     466        $file = str_replace(' ','',$family).strtolower($style).'.php'; 
     467    $style = strtoupper($style); 
    462468    if($style=='IB') 
    463         $style='BI'; 
    464     $fontkey=$family.$style; 
     469        $style = 'BI'; 
     470    $fontkey = $family.$style; 
    465471    if(isset($this->fonts[$fontkey])) 
    466472        return; 
    467     include($this->_getfontpath().$file); 
    468     if(!isset($name)) 
    469         $this->Error('Could not include font definition file'); 
    470     $i=count($this->fonts)+1; 
    471     $this->fonts[$fontkey]=array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file); 
    472     if($diff) 
    473     { 
    474         //Search existing encodings 
    475         $d=0; 
    476         $nb=count($this->diffs); 
    477         for($i=1;$i<=$nb;$i++) 
    478         { 
    479             if($this->diffs[$i]==$diff) 
    480             { 
    481                 $d=$i; 
    482                 break; 
    483             } 
    484         } 
    485         if($d==0) 
    486         { 
    487             $d=$nb+1; 
    488             $this->diffs[$d]=$diff; 
    489         } 
    490         $this->fonts[$fontkey]['diff']=$d; 
    491     } 
    492     if($file) 
    493     { 
    494         if($type=='TrueType') 
    495             $this->FontFiles[$file]=array('length1'=>$originalsize); 
     473    $info = $this->_loadfont($file); 
     474    $info['i'] = count($this->fonts)+1; 
     475    if(!empty($info['diff'])) 
     476    { 
     477        // Search existing encodings 
     478        $n = array_search($info['diff'],$this->diffs); 
     479        if(!$n) 
     480        { 
     481            $n = count($this->diffs)+1; 
     482            $this->diffs[$n] = $info['diff']; 
     483        } 
     484        $info['diffn'] = $n; 
     485    } 
     486    if(!empty($info['file'])) 
     487    { 
     488        // Embedded font 
     489        if($info['type']=='TrueType') 
     490            $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']); 
    496491        else 
    497             $this->FontFiles[$file]=array('length1'=>$size1, 'length2'=>$size2); 
    498     } 
     492            $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']); 
     493    } 
     494    $this->fonts[$fontkey] = $info; 
    499495} 
    500496 
    501497function SetFont($family, $style='', $size=0) 
    502498{ 
    503     //Select a font; size given in points 
    504     global $fpdf_charwidths; 
    505  
    506     $family=strtolower($family); 
     499    // Select a font; size given in points 
    507500    if($family=='') 
    508         $family=$this->FontFamily; 
    509     if($family=='arial') 
    510         $family='helvetica'; 
    511     elseif($family=='symbol' || $family=='zapfdingbats') 
    512         $style=''; 
    513     $style=strtoupper($style); 
     501        $family = $this->FontFamily; 
     502    else 
     503        $family = strtolower($family); 
     504    $style = strtoupper($style); 
    514505    if(strpos($style,'U')!==false) 
    515506    { 
    516         $this->underline=true; 
    517         $style=str_replace('U','',$style); 
    518     } 
    519     else 
    520         $this->underline=false; 
     507        $this->underline = true; 
     508        $style = str_replace('U','',$style); 
     509    } 
     510    else 
     511        $this->underline = false; 
    521512    if($style=='IB') 
    522         $style='BI'; 
     513        $style = 'BI'; 
    523514    if($size==0) 
    524         $size=$this->FontSizePt; 
    525     //Test if font is already selected 
     515        $size = $this->FontSizePt; 
     516    // Test if font is already selected 
    526517    if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) 
    527518        return; 
    528     //Test if used for the first time 
    529     $fontkey=$family.$style; 
     519    // Test if font is already loaded 
     520    $fontkey = $family.$style; 
    530521    if(!isset($this->fonts[$fontkey])) 
    531522    { 
    532         //Check if one of the standard fonts 
    533         if(isset($this->CoreFonts[$fontkey])) 
    534         { 
    535             if(!isset($fpdf_charwidths[$fontkey])) 
    536             { 
    537                 //Load metric file 
    538                 $file=$family; 
    539                 if($family=='times' || $family=='helvetica') 
    540                     $file.=strtolower($style); 
    541                 include($this->_getfontpath().$file.'.php'); 
    542                 if(!isset($fpdf_charwidths[$fontkey])) 
    543                     $this->Error('Could not include font metric file'); 
    544             } 
    545             $i=count($this->fonts)+1; 
    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); 
     523        // Test if one of the core fonts 
     524        if($family=='arial') 
     525            $family = 'helvetica'; 
     526        if(in_array($family,$this->CoreFonts)) 
     527        { 
     528            if($family=='symbol' || $family=='zapfdingbats') 
     529                $style = ''; 
     530            $fontkey = $family.$style; 
     531            if(!isset($this->fonts[$fontkey])) 
     532                $this->AddFont($family,$style); 
    549533        } 
    550534        else 
    551535            $this->Error('Undefined font: '.$family.' '.$style); 
    552536    } 
    553     //Select it 
    554     $this->FontFamily=$family; 
    555     $this->FontStyle=$style; 
    556     $this->FontSizePt=$size; 
    557     $this->FontSize=$size/$this->k; 
    558     $this->CurrentFont=&$this->fonts[$fontkey]; 
     537    // Select it 
     538    $this->FontFamily = $family; 
     539    $this->FontStyle = $style; 
     540    $this->FontSizePt = $size; 
     541    $this->FontSize = $size/$this->k; 
     542    $this->CurrentFont = &$this->fonts[$fontkey]; 
    559543    if($this->page>0) 
    560544        $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); 
     
    563547function SetFontSize($size) 
    564548{ 
    565     //Set font size in points 
     549    // Set font size in points 
    566550    if($this->FontSizePt==$size) 
    567551        return; 
    568     $this->FontSizePt=$size; 
    569     $this->FontSize=$size/$this->k; 
     552    $this->FontSizePt = $size; 
     553    $this->FontSize = $size/$this->k; 
    570554    if($this->page>0) 
    571555        $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); 
     
    574558function AddLink() 
    575559{ 
    576     //Create a new internal link 
    577     $n=count($this->links)+1; 
    578     $this->links[$n]=array(0, 0); 
     560    // Create a new internal link 
     561    $n = count($this->links)+1; 
     562    $this->links[$n] = array(0, 0); 
    579563    return $n; 
    580564} 
     
    582566function SetLink($link, $y=0, $page=-1) 
    583567{ 
    584     //Set destination of internal link 
     568    // Set destination of internal link 
    585569    if($y==-1) 
    586         $y=$this->y; 
     570        $y = $this->y; 
    587571    if($page==-1) 
    588         $page=$this->page; 
    589     $this->links[$link]=array($page, $y); 
     572        $page = $this->page; 
     573    $this->links[$link] = array($page, $y); 
    590574} 
    591575 
    592576function Link($x, $y, $w, $h, $link) 
    593577{ 
    594     //Put a link on the page 
    595     $this->PageLinks[$this->page][]=array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link); 
     578    // Put a link on the page 
     579    $this->PageLinks[$this->page][] = array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link); 
    596580} 
    597581 
    598582function Text($x, $y, $txt) 
    599583{ 
    600     //Output a string 
    601     $s=sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); 
     584    // Output a string 
     585    $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); 
    602586    if($this->underline && $txt!='') 
    603         $s.=' '.$this->_dounderline($x,$y,$txt); 
     587        $s .= ' '.$this->_dounderline($x,$y,$txt); 
    604588    if($this->ColorFlag) 
    605         $s='q '.$this->TextColor.' '.$s.' Q'; 
     589        $s = 'q '.$this->TextColor.' '.$s.' Q'; 
    606590    $this->_out($s); 
    607591} 
     
    609593function AcceptPageBreak() 
    610594{ 
    611     //Accept automatic page break or not 
     595    // Accept automatic page break or not 
    612596    return $this->AutoPageBreak; 
    613597} 
     
    615599function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') 
    616600{ 
    617     //Output a cell 
    618     $k=$this->k; 
     601    // Output a cell 
     602    $k = $this->k; 
    619603    if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) 
    620604    { 
    621         //Automatic page break 
    622         $x=$this->x; 
    623         $ws=$this->ws; 
     605        // Automatic page break 
     606        $x = $this->x; 
     607        $ws = $this->ws; 
    624608        if($ws>0) 
    625609        { 
    626             $this->ws=0; 
     610            $this->ws = 0; 
    627611            $this->_out('0 Tw'); 
    628612        } 
    629         $this->AddPage($this->CurOrientation,$this->CurPageFormat); 
    630         $this->x=$x; 
     613        $this->AddPage($this->CurOrientation,$this->CurPageSize); 
     614        $this->x = $x; 
    631615        if($ws>0) 
    632616        { 
    633             $this->ws=$ws; 
     617            $this->ws = $ws; 
    634618            $this->_out(sprintf('%.3F Tw',$ws*$k)); 
    635619        } 
    636620    } 
    637621    if($w==0) 
    638         $w=$this->w-$this->rMargin-$this->x; 
    639     $s=''; 
     622        $w = $this->w-$this->rMargin-$this->x; 
     623    $s = ''; 
    640624    if($fill || $border==1) 
    641625    { 
    642626        if($fill) 
    643             $op=($border==1) ? 'B' : 'f'; 
     627            $op = ($border==1) ? 'B' : 'f'; 
    644628        else 
    645             $op='S'; 
    646         $s=sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); 
     629            $op = 'S'; 
     630        $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); 
    647631    } 
    648632    if(is_string($border)) 
    649633    { 
    650         $x=$this->x; 
    651         $y=$this->y; 
     634        $x = $this->x; 
     635        $y = $this->y; 
    652636        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); 
     637            $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); 
    654638        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); 
     639            $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); 
    656640        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); 
     641            $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); 
    658642        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); 
     643            $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); 
    660644    } 
    661645    if($txt!=='') 
    662646    { 
    663647        if($align=='R') 
    664             $dx=$w-$this->cMargin-$this->GetStringWidth($txt); 
     648            $dx = $w-$this->cMargin-$this->GetStringWidth($txt); 
    665649        elseif($align=='C') 
    666             $dx=($w-$this->GetStringWidth($txt))/2; 
     650            $dx = ($w-$this->GetStringWidth($txt))/2; 
    667651        else 
    668             $dx=$this->cMargin; 
     652            $dx = $this->cMargin; 
    669653        if($this->ColorFlag) 
    670             $s.='q '.$this->TextColor.' '; 
    671         $txt2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt))); 
    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); 
     654            $s .= 'q '.$this->TextColor.' '; 
     655        $txt2 = str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt))); 
     656        $s .= sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt2); 
    673657        if($this->underline) 
    674             $s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); 
     658            $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); 
    675659        if($this->ColorFlag) 
    676             $s.=' Q'; 
     660            $s .= ' Q'; 
    677661        if($link) 
    678662            $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link); 
     
    680664    if($s) 
    681665        $this->_out($s); 
    682     $this->lasth=$h; 
     666    $this->lasth = $h; 
    683667    if($ln>0) 
    684668    { 
    685         //Go to next line 
    686         $this->y+=$h; 
     669        // Go to next line 
     670        $this->y += $h; 
    687671        if($ln==1) 
    688             $this->x=$this->lMargin; 
    689     } 
    690     else 
    691         $this->x+=$w; 
     672            $this->x = $this->lMargin; 
     673    } 
     674    else 
     675        $this->x += $w; 
    692676} 
    693677 
    694678function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false) 
    695679{ 
    696     //Output text with automatic or explicit line breaks 
    697     $cw=&$this->CurrentFont['cw']; 
     680    // Output text with automatic or explicit line breaks 
     681    $cw = &$this->CurrentFont['cw']; 
    698682    if($w==0) 
    699         $w=$this->w-$this->rMargin-$this->x; 
    700     $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 
    701     $s=str_replace("\r",'',$txt); 
    702     $nb=strlen($s); 
     683        $w = $this->w-$this->rMargin-$this->x; 
     684    $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; 
     685    $s = str_replace("\r",'',$txt); 
     686    $nb = strlen($s); 
    703687    if($nb>0 && $s[$nb-1]=="\n") 
    704688        $nb--; 
    705     $b=0; 
     689    $b = 0; 
    706690    if($border) 
    707691    { 
    708692        if($border==1) 
    709693        { 
    710             $border='LTRB'; 
    711             $b='LRT'; 
    712             $b2='LR'; 
     694            $border = 'LTRB'; 
     695            $b = 'LRT'; 
     696            $b2 = 'LR'; 
    713697        } 
    714698        else 
    715699        { 
    716             $b2=''; 
     700            $b2 = ''; 
    717701            if(strpos($border,'L')!==false) 
    718                 $b2.='L'; 
     702                $b2 .= 'L'; 
    719703            if(strpos($border,'R')!==false) 
    720                 $b2.='R'; 
    721             $b=(strpos($border,'T')!==false) ? $b2.'T' : $b2; 
    722         } 
    723     } 
    724     $sep=-1; 
    725     $i=0; 
    726     $j=0; 
    727     $l=0; 
    728     $ns=0; 
    729     $nl=1; 
     704                $b2 .= 'R'; 
     705            $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; 
     706        } 
     707    } 
     708    $sep = -1; 
     709    $i = 0; 
     710    $j = 0; 
     711    $l = 0; 
     712    $ns = 0; 
     713    $nl = 1; 
    730714    while($i<$nb) 
    731715    { 
    732         //Get next character 
    733         $c=$s[$i]; 
     716        // Get next character 
     717        $c = $s[$i]; 
    734718        if($c=="\n") 
    735719        { 
    736             //Explicit line break 
     720            // Explicit line break 
    737721            if($this->ws>0) 
    738722            { 
    739                 $this->ws=0; 
     723                $this->ws = 0; 
    740724                $this->_out('0 Tw'); 
    741725            } 
    742726            $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 
    743727            $i++; 
    744             $sep=-1; 
    745             $j=$i; 
    746             $l=0; 
    747             $ns=0; 
     728            $sep = -1; 
     729            $j = $i; 
     730            $l = 0; 
     731            $ns = 0; 
    748732            $nl++; 
    749733            if($border && $nl==2) 
    750                 $b=$b2; 
     734                $b = $b2; 
    751735            continue; 
    752736        } 
    753737        if($c==' ') 
    754738        { 
    755             $sep=$i; 
    756             $ls=$l; 
     739            $sep = $i; 
     740            $ls = $l; 
    757741            $ns++; 
    758742        } 
    759         $l+=$cw[$c]; 
     743        $l += $cw[$c]; 
    760744        if($l>$wmax) 
    761745        { 
    762             //Automatic line break 
     746            // Automatic line break 
    763747            if($sep==-1) 
    764748            { 
     
    767751                if($this->ws>0) 
    768752                { 
    769                     $this->ws=0; 
     753                    $this->ws = 0; 
    770754                    $this->_out('0 Tw'); 
    771755                } 
     
    776760                if($align=='J') 
    777761                { 
    778                     $this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; 
     762                    $this->ws = ($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; 
    779763                    $this->_out(sprintf('%.3F Tw',$this->ws*$this->k)); 
    780764                } 
    781765                $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); 
    782                 $i=$sep+1; 
     766                $i = $sep+1; 
    783767            } 
    784             $sep=-1; 
    785             $j=$i; 
    786             $l=0; 
    787             $ns=0; 
     768            $sep = -1; 
     769            $j = $i; 
     770            $l = 0; 
     771            $ns = 0; 
    788772            $nl++; 
    789773            if($border && $nl==2) 
    790                 $b=$b2; 
     774                $b = $b2; 
    791775        } 
    792776        else 
    793777            $i++; 
    794778    } 
    795     //Last chunk 
     779    // Last chunk 
    796780    if($this->ws>0) 
    797781    { 
    798         $this->ws=0; 
     782        $this->ws = 0; 
    799783        $this->_out('0 Tw'); 
    800784    } 
    801785    if($border && strpos($border,'B')!==false) 
    802         $b.='B'; 
     786        $b .= 'B'; 
    803787    $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 
    804     $this->x=$this->lMargin; 
     788    $this->x = $this->lMargin; 
    805789} 
    806790 
    807791function Write($h, $txt, $link='') 
    808792{ 
    809     //Output text in flowing mode 
    810     $cw=&$this->CurrentFont['cw']; 
    811     $w=$this->w-$this->rMargin-$this->x; 
    812     $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 
    813     $s=str_replace("\r",'',$txt); 
    814     $nb=strlen($s); 
    815     $sep=-1; 
    816     $i=0; 
    817     $j=0; 
    818     $l=0; 
    819     $nl=1; 
     793    // Output text in flowing mode 
     794    $cw = &$this->CurrentFont['cw']; 
     795    $w = $this->w-$this->rMargin-$this->x; 
     796    $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; 
     797    $s = str_replace("\r",'',$txt); 
     798    $nb = strlen($s); 
     799    $sep = -1; 
     800    $i = 0; 
     801    $j = 0; 
     802    $l = 0; 
     803    $nl = 1; 
    820804    while($i<$nb) 
    821805    { 
    822         //Get next character 
    823         $c=$s[$i]; 
     806        // Get next character 
     807        $c = $s[$i]; 
    824808        if($c=="\n") 
    825809        { 
    826             //Explicit line break 
     810            // Explicit line break 
    827811            $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); 
    828812            $i++; 
    829             $sep=-1; 
    830             $j=$i; 
    831             $l=0; 
     813            $sep = -1; 
     814            $j = $i; 
     815            $l = 0; 
    832816            if($nl==1) 
    833817            { 
    834                 $this->x=$this->lMargin; 
    835                 $w=$this->w-$this->rMargin-$this->x; 
    836                 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 
     818                $this->x = $this->lMargin; 
     819                $w = $this->w-$this->rMargin-$this->x; 
     820                $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; 
    837821            } 
    838822            $nl++; 
     
    840824        } 
    841825        if($c==' ') 
    842             $sep=$i; 
    843         $l+=$cw[$c]; 
     826            $sep = $i; 
     827        $l += $cw[$c]; 
    844828        if($l>$wmax) 
    845829        { 
    846             //Automatic line break 
     830            // Automatic line break 
    847831            if($sep==-1) 
    848832            { 
    849833                if($this->x>$this->lMargin) 
    850834                { 
    851                     //Move to next line 
    852                     $this->x=$this->lMargin; 
    853                     $this->y+=$h; 
    854                     $w=$this->w-$this->rMargin-$this->x; 
    855                     $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 
     835                    // Move to next line 
     836                    $this->x = $this->lMargin; 
     837                    $this->y += $h; 
     838                    $w = $this->w-$this->rMargin-$this->x; 
     839                    $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; 
    856840                    $i++; 
    857841                    $nl++; 
     
    865849            { 
    866850                $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link); 
    867                 $i=$sep+1; 
     851                $i = $sep+1; 
    868852            } 
    869             $sep=-1; 
    870             $j=$i; 
    871             $l=0; 
     853            $sep = -1; 
     854            $j = $i; 
     855            $l = 0; 
    872856            if($nl==1) 
    873857            { 
    874                 $this->x=$this->lMargin; 
    875                 $w=$this->w-$this->rMargin-$this->x; 
    876                 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 
     858                $this->x = $this->lMargin; 
     859                $w = $this->w-$this->rMargin-$this->x; 
     860                $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; 
    877861            } 
    878862            $nl++; 
     
    881865            $i++; 
    882866    } 
    883     //Last chunk 
     867    // Last chunk 
    884868    if($i!=$j) 
    885869        $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',0,$link); 
     
    888872function Ln($h=null) 
    889873{ 
    890     //Line feed; default value is last cell height 
    891     $this->x=$this->lMargin; 
     874    // Line feed; default value is last cell height 
     875    $this->x = $this->lMargin; 
    892876    if($h===null) 
    893         $this->y+=$this->lasth; 
    894     else 
    895         $this->y+=$h; 
     877        $this->y += $this->lasth; 
     878    else 
     879        $this->y += $h; 
    896880} 
    897881 
    898882function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='') 
    899883{ 
    900     //Put an image on the page 
     884    // Put an image on the page 
    901885    if(!isset($this->images[$file])) 
    902886    { 
    903         //First use of this image, get info 
     887        // First use of this image, get info 
    904888        if($type=='') 
    905889        { 
    906             $pos=strrpos($file,'.'); 
     890            $pos = strrpos($file,'.'); 
    907891            if(!$pos) 
    908892                $this->Error('Image file has no extension and no type was specified: '.$file); 
    909             $type=substr($file,$pos+1); 
    910         } 
    911         $type=strtolower($type); 
     893            $type = substr($file,$pos+1); 
     894        } 
     895        $type = strtolower($type); 
    912896        if($type=='jpeg') 
    913             $type='jpg'; 
    914         $mtd='_parse'.$type; 
     897            $type = 'jpg'; 
     898        $mtd = '_parse'.$type; 
    915899        if(!method_exists($this,$mtd)) 
    916900            $this->Error('Unsupported image type: '.$type); 
    917         $info=$this->$mtd($file); 
    918         $info['i']=count($this->images)+1; 
    919         $this->images[$file]=$info; 
    920     } 
    921     else 
    922         $info=$this->images[$file]; 
    923     //Automatic width and height calculation if needed 
     901        $info = $this->$mtd($file); 
     902        $info['i'] = count($this->images)+1; 
     903        $this->images[$file] = $info; 
     904    } 
     905    else 
     906        $info = $this->images[$file]; 
     907 
     908    // Automatic width and height calculation if needed 
    924909    if($w==0 && $h==0) 
    925910    { 
    926         //Put image at 72 dpi 
    927         $w=$info['w']/$this->k; 
    928         $h=$info['h']/$this->k; 
    929     } 
    930     elseif($w==0) 
    931         $w=$h*$info['w']/$info['h']; 
    932     elseif($h==0) 
    933         $h=$w*$info['h']/$info['w']; 
    934     //Flowing mode 
     911        // Put image at 96 dpi 
     912        $w = -96; 
     913        $h = -96; 
     914    } 
     915    if($w<0) 
     916        $w = -$info['w']*72/$w/$this->k; 
     917    if($h<0) 
     918        $h = -$info['h']*72/$h/$this->k; 
     919    if($w==0) 
     920        $w = $h*$info['w']/$info['h']; 
     921    if($h==0) 
     922        $h = $w*$info['h']/$info['w']; 
     923 
     924    // Flowing mode 
    935925    if($y===null) 
    936926    { 
    937927        if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) 
    938928        { 
    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     } 
     929            // Automatic page break 
     930            $x2 = $this->x; 
     931            $this->AddPage($this->CurOrientation,$this->CurPageSize); 
     932            $this->x = $x2; 
     933        } 
     934        $y = $this->y; 
     935        $this->y += $h; 
     936    } 
     937 
    947938    if($x===null) 
    948         $x=$this->x; 
     939        $x = $this->x; 
    949940    $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'])); 
    950941    if($link) 
     
    954945function GetX() 
    955946{ 
    956     //Get x position 
     947    // Get x position 
    957948    return $this->x; 
    958949} 
     
    960951function SetX($x) 
    961952{ 
    962     //Set x position 
     953    // Set x position 
    963954    if($x>=0) 
    964         $this->x=$x; 
    965     else 
    966         $this->x=$this->w+$x; 
     955        $this->x = $x; 
     956    else 
     957        $this->x = $this->w+$x; 
    967958} 
    968959 
    969960function GetY() 
    970961{ 
    971     //Get y position 
     962    // Get y position 
    972963    return $this->y; 
    973964} 
     
    975966function SetY($y) 
    976967{ 
    977     //Set y position and reset x 
    978     $this->x=$this->lMargin; 
     968    // Set y position and reset x 
     969    $this->x = $this->lMargin; 
    979970    if($y>=0) 
    980         $this->y=$y; 
    981     else 
    982         $this->y=$this->h+$y; 
     971        $this->y = $y; 
     972    else 
     973        $this->y = $this->h+$y; 
    983974} 
    984975 
    985976function SetXY($x, $y) 
    986977{ 
    987     //Set x and y positions 
     978    // Set x and y positions 
    988979    $this->SetY($y); 
    989980    $this->SetX($x); 
     
    992983function Output($name='', $dest='') 
    993984{ 
    994     //Output PDF to some destination 
     985    // Output PDF to some destination 
    995986    if($this->state<3) 
    996987        $this->Close(); 
    997     $dest=strtoupper($dest); 
     988    $dest = strtoupper($dest); 
    998989    if($dest=='') 
    999990    { 
    1000991        if($name=='') 
    1001992        { 
    1002             $name='doc.pdf'; 
    1003             $dest='I'; 
     993            $name = 'doc.pdf'; 
     994            $dest = 'I'; 
    1004995        } 
    1005996        else 
    1006             $dest='F'; 
     997            $dest = 'F'; 
    1007998    } 
    1008999    switch($dest) 
    10091000    { 
    10101001        case 'I': 
    1011             //Send to standard output 
    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') 
     1002            // Send to standard output 
     1003            $this->_checkoutput(); 
     1004            if(PHP_SAPI!='cli') 
    10151005            { 
    1016                 //We send to a browser 
     1006                // We send to a browser 
    10171007                header('Content-Type: application/pdf'); 
    1018                 if(headers_sent()) 
    1019                     $this->Error('Some data has already been output, can\'t send PDF file'); 
    1020                 header('Content-Length: '.strlen($this->buffer)); 
    10211008                header('Content-Disposition: inline; filename="'.$name.'"'); 
    10221009                header('Cache-Control: private, max-age=0, must-revalidate'); 
    10231010                header('Pragma: public'); 
    1024                 ini_set('zlib.output_compression','0'); 
    10251011            } 
    10261012            echo $this->buffer; 
    10271013            break; 
    10281014        case 'D': 
    1029             //Download file 
    1030             if(ob_get_length()) 
    1031                 $this->Error('Some data has already been output, can\'t send PDF file'); 
     1015            // Download file 
     1016            $this->_checkoutput(); 
    10321017            header('Content-Type: application/x-download'); 
    1033             if(headers_sent()) 
    1034                 $this->Error('Some data has already been output, can\'t send PDF file'); 
    1035             header('Content-Length: '.strlen($this->buffer)); 
    10361018            header('Content-Disposition: attachment; filename="'.$name.'"'); 
    10371019            header('Cache-Control: private, max-age=0, must-revalidate'); 
    10381020            header('Pragma: public'); 
    1039             ini_set('zlib.output_compression','0'); 
    10401021            echo $this->buffer; 
    10411022            break; 
    10421023        case 'F': 
    1043             //Save to local file 
    1044             $f=fopen($name,'wb'); 
     1024            // Save to local file 
     1025            $f = fopen($name,'wb'); 
    10451026            if(!$f) 
    10461027                $this->Error('Unable to create output file: '.$name); 
     
    10491030            break; 
    10501031        case 'S': 
    1051             //Return as a string 
     1032            // Return as a string 
    10521033            return $this->buffer; 
    10531034        default: 
     
    10641045function _dochecks() 
    10651046{ 
    1066     //Check availability of %F 
     1047    // Check availability of %F 
    10671048    if(sprintf('%.1F',1.0)!='1.0') 
    10681049        $this->Error('This version of PHP is not supported'); 
    1069     //Check mbstring overloading 
     1050    // Check mbstring overloading 
    10701051    if(ini_get('mbstring.func_overload') & 2) 
    10711052        $this->Error('mbstring overloading must be disabled'); 
    1072     //Disable runtime magic quotes 
     1053    // Ensure runtime magic quotes are disabled 
    10731054    if(get_magic_quotes_runtime()) 
    10741055        @set_magic_quotes_runtime(0); 
    10751056} 
    10761057 
    1077 function _getpageformat($format) 
    1078 { 
    1079     $format=strtolower($format); 
    1080     if(!isset($this->PageFormats[$format])) 
    1081         $this->Error('Unknown page format: '.$format); 
    1082     $a=$this->PageFormats[$format]; 
    1083     return array($a[0]/$this->k, $a[1]/$this->k); 
    1084 } 
    1085  
    1086 function _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  
    1093 function _beginpage($orientation, $format) 
     1058function _checkoutput() 
     1059{ 
     1060    if(PHP_SAPI!='cli') 
     1061    { 
     1062        if(headers_sent($file,$line)) 
     1063            $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)"); 
     1064    } 
     1065    if(ob_get_length()) 
     1066    { 
     1067        // The output buffer is not empty 
     1068        if(preg_match('/^(\xEF\xBB\xBF)?\s*$/',ob_get_contents())) 
     1069        { 
     1070            // It contains only a UTF-8 BOM and/or whitespace, let's clean it 
     1071            ob_clean(); 
     1072        } 
     1073        else 
     1074            $this->Error("Some data has already been output, can't send PDF file"); 
     1075    } 
     1076} 
     1077 
     1078function _getpagesize($size) 
     1079{ 
     1080    if(is_string($size)) 
     1081    { 
     1082        $size = strtolower($size); 
     1083        if(!isset($this->StdPageSizes[$size])) 
     1084            $this->Error('Unknown page size: '.$size); 
     1085        $a = $this->StdPageSizes[$size]; 
     1086        return array($a[0]/$this->k, $a[1]/$this->k); 
     1087    } 
     1088    else 
     1089    { 
     1090        if($size[0]>$size[1]) 
     1091            return array($size[1], $size[0]); 
     1092        else 
     1093            return $size; 
     1094    } 
     1095} 
     1096 
     1097function _beginpage($orientation, $size) 
    10941098{ 
    10951099    $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 
     1100    $this->pages[$this->page] = ''; 
     1101    $this->state = 2; 
     1102    $this->x = $this->lMargin; 
     1103    $this->y = $this->tMargin; 
     1104    $this->FontFamily = ''; 
     1105    // Check page size and orientation 
    11021106    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 
     1107        $orientation = $this->DefOrientation; 
     1108    else 
     1109        $orientation = strtoupper($orientation[0]); 
     1110    if($size=='') 
     1111        $size = $this->DefPageSize; 
     1112    else 
     1113        $size = $this->_getpagesize($size); 
     1114    if($orientation!=$this->CurOrientation || $size[0]!=$this->CurPageSize[0] || $size[1]!=$this->CurPageSize[1]) 
     1115    { 
     1116        // New size or orientation 
    11161117        if($orientation=='P') 
    11171118        { 
    1118             $this->w=$format[0]; 
    1119             $this->h=$format[1]; 
     1119            $this->w = $size[0]; 
     1120            $this->h = $size[1]; 
    11201121        } 
    11211122        else 
    11221123        { 
    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); 
     1124            $this->w = $size[1]; 
     1125            $this->h = $size[0]; 
     1126        } 
     1127        $this->wPt = $this->w*$this->k; 
     1128        $this->hPt = $this->h*$this->k; 
     1129        $this->PageBreakTrigger = $this->h-$this->bMargin; 
     1130        $this->CurOrientation = $orientation; 
     1131        $this->CurPageSize = $size; 
     1132    } 
     1133    if($orientation!=$this->DefOrientation || $size[0]!=$this->DefPageSize[0] || $size[1]!=$this->DefPageSize[1]) 
     1134        $this->PageSizes[$this->page] = array($this->wPt, $this->hPt); 
    11341135} 
    11351136 
    11361137function _endpage() 
    11371138{ 
    1138     $this->state=1; 
     1139    $this->state = 1; 
     1140} 
     1141 
     1142function _loadfont($font) 
     1143{ 
     1144    // Load a font definition file from the font directory 
     1145    include($this->fontpath.$font); 
     1146    $a = get_defined_vars(); 
     1147    if(!isset($a['name'])) 
     1148        $this->Error('Could not include font definition file'); 
     1149    return $a; 
    11391150} 
    11401151 
    11411152function _escape($s) 
    11421153{ 
    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); 
     1154    // Escape special characters in strings 
     1155    $s = str_replace('\\','\\\\',$s); 
     1156    $s = str_replace('(','\\(',$s); 
     1157    $s = str_replace(')','\\)',$s); 
     1158    $s = str_replace("\r",'\\r',$s); 
    11481159    return $s; 
    11491160} 
     
    11511162function _textstring($s) 
    11521163{ 
    1153     //Format a text string 
     1164    // Format a text string 
    11541165    return '('.$this->_escape($s).')'; 
    11551166} 
     
    11571168function _UTF8toUTF16($s) 
    11581169{ 
    1159     //Convert UTF-8 to UTF-16BE with BOM 
    1160     $res="\xFE\xFF"; 
    1161     $nb=strlen($s); 
    1162     $i=0; 
     1170    // Convert UTF-8 to UTF-16BE with BOM 
     1171    $res = "\xFE\xFF"; 
     1172    $nb = strlen($s); 
     1173    $i = 0; 
    11631174    while($i<$nb) 
    11641175    { 
    1165         $c1=ord($s[$i++]); 
     1176        $c1 = ord($s[$i++]); 
    11661177        if($c1>=224) 
    11671178        { 
    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)); 
     1179            // 3-byte character 
     1180            $c2 = ord($s[$i++]); 
     1181            $c3 = ord($s[$i++]); 
     1182            $res .= chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2)); 
     1183            $res .= chr((($c2 & 0x03)<<6) + ($c3 & 0x3F)); 
    11731184        } 
    11741185        elseif($c1>=192) 
    11751186        { 
    1176             //2-byte character 
    1177             $c2=ord($s[$i++]); 
    1178             $res.=chr(($c1 & 0x1C)>>2); 
    1179             $res.=chr((($c1 & 0x03)<<6) + ($c2 & 0x3F)); 
     1187            // 2-byte character 
     1188            $c2 = ord($s[$i++]); 
     1189            $res .= chr(($c1 & 0x1C)>>2); 
     1190            $res .= chr((($c1 & 0x03)<<6) + ($c2 & 0x3F)); 
    11801191        } 
    11811192        else 
    11821193        { 
    1183             //Single-byte character 
    1184             $res.="\0".chr($c1); 
     1194            // Single-byte character 
     1195            $res .= "\0".chr($c1); 
    11851196        } 
    11861197    } 
     
    11901201function _dounderline($x, $y, $txt) 
    11911202{ 
    1192     //Underline text 
    1193     $up=$this->CurrentFont['up']; 
    1194     $ut=$this->CurrentFont['ut']; 
    1195     $w=$this->GetStringWidth($txt)+$this->ws*substr_count($txt,' '); 
     1203    // Underline text 
     1204    $up = $this->CurrentFont['up']; 
     1205    $ut = $this->CurrentFont['ut']; 
     1206    $w = $this->GetStringWidth($txt)+$this->ws*substr_count($txt,' '); 
    11961207    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); 
    11971208} 
     
    11991210function _parsejpg($file) 
    12001211{ 
    1201     //Extract info from a JPEG file 
    1202     $a=GetImageSize($file); 
     1212    // Extract info from a JPEG file 
     1213    $a = getimagesize($file); 
    12031214    if(!$a) 
    12041215        $this->Error('Missing or incorrect image file: '.$file); 
     
    12061217        $this->Error('Not a JPEG file: '.$file); 
    12071218    if(!isset($a['channels']) || $a['channels']==3) 
    1208         $colspace='DeviceRGB'; 
     1219        $colspace = 'DeviceRGB'; 
    12091220    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); 
     1221        $colspace = 'DeviceCMYK'; 
     1222    else 
     1223        $colspace = 'DeviceGray'; 
     1224    $bpc = isset($a['bits']) ? $a['bits'] : 8; 
     1225    $data = file_get_contents($file); 
    12201226    return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data); 
    12211227} 
     
    12231229function _parsepng($file) 
    12241230{ 
    1225     //Extract info from a PNG file 
    1226     $f=fopen($file,'rb'); 
     1231    // Extract info from a PNG file 
     1232    $f = fopen($file,'rb'); 
    12271233    if(!$f) 
    12281234        $this->Error('Can\'t open image file: '.$file); 
    1229     //Check signature 
     1235    $info = $this->_parsepngstream($f,$file); 
     1236    fclose($f); 
     1237    return $info; 
     1238} 
     1239 
     1240function _parsepngstream($f, $file) 
     1241{ 
     1242    // Check signature 
    12301243    if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) 
    12311244        $this->Error('Not a PNG file: '.$file); 
    1232     //Read header chunk 
     1245 
     1246    // Read header chunk 
    12331247    $this->_readstream($f,4); 
    12341248    if($this->_readstream($f,4)!='IHDR') 
    12351249        $this->Error('Incorrect PNG file: '.$file); 
    1236     $w=$this->_readint($f); 
    1237     $h=$this->_readint($f); 
    1238     $bpc=ord($this->_readstream($f,1)); 
     1250    $w = $this->_readint($f); 
     1251    $h = $this->_readint($f); 
     1252    $bpc = ord($this->_readstream($f,1)); 
    12391253    if($bpc>8) 
    12401254        $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'; 
     1255    $ct = ord($this->_readstream($f,1)); 
     1256    if($ct==0 || $ct==4) 
     1257        $colspace = 'DeviceGray'; 
     1258    elseif($ct==2 || $ct==6) 
     1259        $colspace = 'DeviceRGB'; 
    12461260    elseif($ct==3) 
    1247         $colspace='Indexed'; 
    1248     else 
    1249         $this->Error('Alpha channel not supported: '.$file); 
     1261        $colspace = 'Indexed'; 
     1262    else 
     1263        $this->Error('Unknown color type: '.$file); 
    12501264    if(ord($this->_readstream($f,1))!=0) 
    12511265        $this->Error('Unknown compression method: '.$file); 
     
    12551269        $this->Error('Interlacing not supported: '.$file); 
    12561270    $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=''; 
     1271    $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w; 
     1272 
     1273    // Scan chunks looking for palette, transparency and image data 
     1274    $pal = ''; 
     1275    $trns = ''; 
     1276    $data = ''; 
    12621277    do 
    12631278    { 
    1264         $n=$this->_readint($f); 
    1265         $type=$this->_readstream($f,4); 
     1279        $n = $this->_readint($f); 
     1280        $type = $this->_readstream($f,4); 
    12661281        if($type=='PLTE') 
    12671282        { 
    1268             //Read palette 
    1269             $pal=$this->_readstream($f,$n); 
     1283            // Read palette 
     1284            $pal = $this->_readstream($f,$n); 
    12701285            $this->_readstream($f,4); 
    12711286        } 
    12721287        elseif($type=='tRNS') 
    12731288        { 
    1274             //Read transparency info 
    1275             $t=$this->_readstream($f,$n); 
     1289            // Read transparency info 
     1290            $t = $this->_readstream($f,$n); 
    12761291            if($ct==0) 
    1277                 $trns=array(ord(substr($t,1,1))); 
     1292                $trns = array(ord(substr($t,1,1))); 
    12781293            elseif($ct==2) 
    1279                 $trns=array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); 
     1294                $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); 
    12801295            else 
    12811296            { 
    1282                 $pos=strpos($t,chr(0)); 
     1297                $pos = strpos($t,chr(0)); 
    12831298                if($pos!==false) 
    1284                     $trns=array($pos); 
     1299                    $trns = array($pos); 
    12851300            } 
    12861301            $this->_readstream($f,4); 
     
    12881303        elseif($type=='IDAT') 
    12891304        { 
    1290             //Read image data block 
    1291             $data.=$this->_readstream($f,$n); 
     1305            // Read image data block 
     1306            $data .= $this->_readstream($f,$n); 
    12921307            $this->_readstream($f,4); 
    12931308        } 
     
    12981313    } 
    12991314    while($n); 
     1315 
    13001316    if($colspace=='Indexed' && empty($pal)) 
    13011317        $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); 
     1318    $info = array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns); 
     1319    if($ct>=4) 
     1320    { 
     1321        // Extract alpha channel 
     1322        if(!function_exists('gzuncompress')) 
     1323            $this->Error('Zlib not available, can\'t handle alpha channel: '.$file); 
     1324        $data = gzuncompress($data); 
     1325        $color = ''; 
     1326        $alpha = ''; 
     1327        if($ct==4) 
     1328        { 
     1329            // Gray image 
     1330            $len = 2*$w; 
     1331            for($i=0;$i<$h;$i++) 
     1332            { 
     1333                $pos = (1+$len)*$i; 
     1334                $color .= $data[$pos]; 
     1335                $alpha .= $data[$pos]; 
     1336                $line = substr($data,$pos+1,$len); 
     1337                $color .= preg_replace('/(.)./s','$1',$line); 
     1338                $alpha .= preg_replace('/.(.)/s','$1',$line); 
     1339            } 
     1340        } 
     1341        else 
     1342        { 
     1343            // RGB image 
     1344            $len = 4*$w; 
     1345            for($i=0;$i<$h;$i++) 
     1346            { 
     1347                $pos = (1+$len)*$i; 
     1348                $color .= $data[$pos]; 
     1349                $alpha .= $data[$pos]; 
     1350                $line = substr($data,$pos+1,$len); 
     1351                $color .= preg_replace('/(.{3})./s','$1',$line); 
     1352                $alpha .= preg_replace('/.{3}(.)/s','$1',$line); 
     1353            } 
     1354        } 
     1355        unset($data); 
     1356        $data = gzcompress($color); 
     1357        $info['smask'] = gzcompress($alpha); 
     1358        if($this->PDFVersion<'1.4') 
     1359            $this->PDFVersion = '1.4'; 
     1360    } 
     1361    $info['data'] = $data; 
     1362    return $info; 
    13041363} 
    13051364 
    13061365function _readstream($f, $n) 
    13071366{ 
    1308     //Read n bytes from stream 
    1309     $res=''; 
     1367    // Read n bytes from stream 
     1368    $res = ''; 
    13101369    while($n>0 && !feof($f)) 
    13111370    { 
    1312         $s=fread($f,$n); 
     1371        $s = fread($f,$n); 
    13131372        if($s===false) 
    13141373            $this->Error('Error while reading stream'); 
    1315         $n-=strlen($s); 
    1316         $res.=$s; 
     1374        $n -= strlen($s); 
     1375        $res .= $s; 
    13171376    } 
    13181377    if($n>0) 
     
    13231382function _readint($f) 
    13241383{ 
    1325     //Read a 4-byte integer from stream 
    1326     $a=unpack('Ni',$this->_readstream($f,4)); 
     1384    // Read a 4-byte integer from stream 
     1385    $a = unpack('Ni',$this->_readstream($f,4)); 
    13271386    return $a['i']; 
    13281387} 
     
    13301389function _parsegif($file) 
    13311390{ 
    1332     //Extract info from a GIF file (via PNG conversion) 
     1391    // Extract info from a GIF file (via PNG conversion) 
    13331392    if(!function_exists('imagepng')) 
    13341393        $this->Error('GD extension is required for GIF support'); 
    13351394    if(!function_exists('imagecreatefromgif')) 
    13361395        $this->Error('GD has no GIF read support'); 
    1337     $im=imagecreatefromgif($file); 
     1396    $im = imagecreatefromgif($file); 
    13381397    if(!$im) 
    13391398        $this->Error('Missing or incorrect image file: '.$file); 
    13401399    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); 
     1400    $f = @fopen('php://temp','rb+'); 
     1401    if($f) 
     1402    { 
     1403        // Perform conversion in memory 
     1404        ob_start(); 
     1405        imagepng($im); 
     1406        $data = ob_get_clean(); 
     1407        imagedestroy($im); 
     1408        fwrite($f,$data); 
     1409        rewind($f); 
     1410        $info = $this->_parsepngstream($f,$file); 
     1411        fclose($f); 
     1412    } 
     1413    else 
     1414    { 
     1415        // Use temporary file 
     1416        $tmp = tempnam('.','gif'); 
     1417        if(!$tmp) 
     1418            $this->Error('Unable to create a temporary file'); 
     1419        if(!imagepng($im,$tmp)) 
     1420            $this->Error('Error while saving to temporary file'); 
     1421        imagedestroy($im); 
     1422        $info = $this->_parsepng($tmp); 
     1423        unlink($tmp); 
     1424    } 
    13491425    return $info; 
    13501426} 
     
    13521428function _newobj() 
    13531429{ 
    1354     //Begin a new object 
     1430    // Begin a new object 
    13551431    $this->n++; 
    1356     $this->offsets[$this->n]=strlen($this->buffer); 
     1432    $this->offsets[$this->n] = strlen($this->buffer); 
    13571433    $this->_out($this->n.' 0 obj'); 
    13581434} 
     
    13671443function _out($s) 
    13681444{ 
    1369     //Add a line to the document 
     1445    // Add a line to the document 
    13701446    if($this->state==2) 
    1371         $this->pages[$this->page].=$s."\n"; 
    1372     else 
    1373         $this->buffer.=$s."\n"; 
     1447        $this->pages[$this->page] .= $s."\n"; 
     1448    else 
     1449        $this->buffer .= $s."\n"; 
    13741450} 
    13751451 
    13761452function _putpages() 
    13771453{ 
    1378     $nb=$this->page; 
     1454    $nb = $this->page; 
    13791455    if(!empty($this->AliasNbPages)) 
    13801456    { 
    1381         //Replace number of pages 
     1457        // Replace number of pages 
    13821458        for($n=1;$n<=$nb;$n++) 
    1383             $this->pages[$n]=str_replace($this->AliasNbPages,$nb,$this->pages[$n]); 
     1459            $this->pages[$n] = str_replace($this->AliasNbPages,$nb,$this->pages[$n]); 
    13841460    } 
    13851461    if($this->DefOrientation=='P') 
    13861462    { 
    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; 
    1394     } 
    1395     $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; 
     1463        $wPt = $this->DefPageSize[0]*$this->k; 
     1464        $hPt = $this->DefPageSize[1]*$this->k; 
     1465    } 
     1466    else 
     1467    { 
     1468        $wPt = $this->DefPageSize[1]*$this->k; 
     1469        $hPt = $this->DefPageSize[0]*$this->k; 
     1470    } 
     1471    $filter = ($this->compress) ? '/Filter /FlateDecode ' : ''; 
    13961472    for($n=1;$n<=$nb;$n++) 
    13971473    { 
    1398         //Page 
     1474        // Page 
    13991475        $this->_newobj(); 
    14001476        $this->_out('<</Type /Page'); 
     
    14051481        if(isset($this->PageLinks[$n])) 
    14061482        { 
    1407             //Links 
    1408             $annots='/Annots ['; 
     1483            // Links 
     1484            $annots = '/Annots ['; 
    14091485            foreach($this->PageLinks[$n] as $pl) 
    14101486            { 
    1411                 $rect=sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); 
    1412                 $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; 
     1487                $rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); 
     1488                $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; 
    14131489                if(is_string($pl[4])) 
    1414                     $annots.='/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; 
     1490                    $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; 
    14151491                else 
    14161492                { 
    1417                     $l=$this->links[$pl[4]]; 
    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); 
     1493                    $l = $this->links[$pl[4]]; 
     1494                    $h = isset($this->PageSizes[$l[0]]) ? $this->PageSizes[$l[0]][1] : $hPt; 
     1495                    $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',1+2*$l[0],$h-$l[1]*$this->k); 
    14201496                } 
    14211497            } 
    14221498            $this->_out($annots.']'); 
    14231499        } 
     1500        if($this->PDFVersion>'1.3') 
     1501            $this->_out('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>'); 
    14241502        $this->_out('/Contents '.($this->n+1).' 0 R>>'); 
    14251503        $this->_out('endobj'); 
    1426         //Page content 
    1427         $p=($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n]; 
     1504        // Page content 
     1505        $p = ($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n]; 
    14281506        $this->_newobj(); 
    14291507        $this->_out('<<'.$filter.'/Length '.strlen($p).'>>'); 
     
    14311509        $this->_out('endobj'); 
    14321510    } 
    1433     //Pages root 
    1434     $this->offsets[1]=strlen($this->buffer); 
     1511    // Pages root 
     1512    $this->offsets[1] = strlen($this->buffer); 
    14351513    $this->_out('1 0 obj'); 
    14361514    $this->_out('<</Type /Pages'); 
    1437     $kids='/Kids ['; 
     1515    $kids = '/Kids ['; 
    14381516    for($i=0;$i<$nb;$i++) 
    1439         $kids.=(3+2*$i).' 0 R '; 
     1517        $kids .= (3+2*$i).' 0 R '; 
    14401518    $this->_out($kids.']'); 
    14411519    $this->_out('/Count '.$nb); 
     
    14471525function _putfonts() 
    14481526{ 
    1449     $nf=$this->n; 
     1527    $nf = $this->n; 
    14501528    foreach($this->diffs as $diff) 
    14511529    { 
    1452         //Encodings 
     1530        // Encodings 
    14531531        $this->_newobj(); 
    14541532        $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>'); 
     
    14571535    foreach($this->FontFiles as $file=>$info) 
    14581536    { 
    1459         //Font file embedding 
     1537        // Font file embedding 
    14601538        $this->_newobj(); 
    1461         $this->FontFiles[$file]['n']=$this->n; 
    1462         $font=''; 
    1463         $f=fopen($this->_getfontpath().$file,'rb',1); 
    1464         if(!$f) 
    1465             $this->Error('Font file not found'); 
    1466         while(!feof($f)) 
    1467             $font.=fread($f,8192); 
    1468         fclose($f); 
    1469         $compressed=(substr($file,-2)=='.z'); 
     1539        $this->FontFiles[$file]['n'] = $this->n; 
     1540        $font = file_get_contents($this->fontpath.$file,true); 
     1541        if(!$font) 
     1542            $this->Error('Font file not found: '.$file); 
     1543        $compressed = (substr($file,-2)=='.z'); 
    14701544        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         } 
     1545            $font = substr($font,6,$info['length1']).substr($font,6+$info['length1']+6,$info['length2']); 
    14841546        $this->_out('<</Length '.strlen($font)); 
    14851547        if($compressed) 
     
    14941556    foreach($this->fonts as $k=>$font) 
    14951557    { 
    1496         //Font objects 
    1497         $this->fonts[$k]['n']=$this->n+1; 
    1498         $type=$font['type']; 
    1499         $name=$font['name']; 
    1500         if($type=='core') 
    1501         { 
    1502             //Standard font 
     1558        // Font objects 
     1559        $this->fonts[$k]['n'] = $this->n+1; 
     1560        $type = $font['type']; 
     1561        $name = $font['name']; 
     1562        if($type=='Core') 
     1563        { 
     1564            // Core font 
    15031565            $this->_newobj(); 
    15041566            $this->_out('<</Type /Font'); 
     
    15121574        elseif($type=='Type1' || $type=='TrueType') 
    15131575        { 
    1514             //Additional Type1 or TrueType font 
     1576            // Additional Type1 or TrueType/OpenType font 
    15151577            $this->_newobj(); 
    15161578            $this->_out('<</Type /Font'); 
     
    15201582            $this->_out('/Widths '.($this->n+1).' 0 R'); 
    15211583            $this->_out('/FontDescriptor '.($this->n+2).' 0 R'); 
    1522             if($font['enc']) 
    1523             { 
    1524                 if(isset($font['diff'])) 
    1525                     $this->_out('/Encoding '.($nf+$font['diff']).' 0 R'); 
    1526                 else 
    1527                     $this->_out('/Encoding /WinAnsiEncoding'); 
    1528             } 
     1584            if(isset($font['diffn'])) 
     1585                $this->_out('/Encoding '.($nf+$font['diffn']).' 0 R'); 
     1586            else 
     1587                $this->_out('/Encoding /WinAnsiEncoding'); 
    15291588            $this->_out('>>'); 
    15301589            $this->_out('endobj'); 
    1531             //Widths 
     1590            // Widths 
    15321591            $this->_newobj(); 
    1533             $cw=&$font['cw']; 
    1534             $s='['; 
     1592            $cw = &$font['cw']; 
     1593            $s = '['; 
    15351594            for($i=32;$i<=255;$i++) 
    1536                 $s.=$cw[chr($i)].' '; 
     1595                $s .= $cw[chr($i)].' '; 
    15371596            $this->_out($s.']'); 
    15381597            $this->_out('endobj'); 
    1539             //Descriptor 
     1598            // Descriptor 
    15401599            $this->_newobj(); 
    1541             $s='<</Type /FontDescriptor /FontName /'.$name; 
     1600            $s = '<</Type /FontDescriptor /FontName /'.$name; 
    15421601            foreach($font['desc'] as $k=>$v) 
    1543                 $s.=' /'.$k.' '.$v; 
    1544             $file=$font['file']; 
    1545             if($file) 
    1546                 $s.=' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R'; 
     1602                $s .= ' /'.$k.' '.$v; 
     1603            if(!empty($font['file'])) 
     1604                $s .= ' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R'; 
    15471605            $this->_out($s.'>>'); 
    15481606            $this->_out('endobj'); 
     
    15501608        else 
    15511609        { 
    1552             //Allow for additional types 
    1553             $mtd='_put'.strtolower($type); 
     1610            // Allow for additional types 
     1611            $mtd = '_put'.strtolower($type); 
    15541612            if(!method_exists($this,$mtd)) 
    15551613                $this->Error('Unsupported font type: '.$type); 
     
    15611619function _putimages() 
    15621620{ 
    1563     $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; 
    1564     reset($this->images); 
    1565     while(list($file,$info)=each($this->images)) 
    1566     { 
     1621    foreach(array_keys($this->images) as $file) 
     1622    { 
     1623        $this->_putimage($this->images[$file]); 
     1624        unset($this->images[$file]['data']); 
     1625        unset($this->images[$file]['smask']); 
     1626    } 
     1627} 
     1628 
     1629function _putimage(&$info) 
     1630{ 
     1631    $this->_newobj(); 
     1632    $info['n'] = $this->n; 
     1633    $this->_out('<</Type /XObject'); 
     1634    $this->_out('/Subtype /Image'); 
     1635    $this->_out('/Width '.$info['w']); 
     1636    $this->_out('/Height '.$info['h']); 
     1637    if($info['cs']=='Indexed') 
     1638        $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]'); 
     1639    else 
     1640    { 
     1641        $this->_out('/ColorSpace /'.$info['cs']); 
     1642        if($info['cs']=='DeviceCMYK') 
     1643            $this->_out('/Decode [1 0 1 0 1 0 1 0]'); 
     1644    } 
     1645    $this->_out('/BitsPerComponent '.$info['bpc']); 
     1646    if(isset($info['f'])) 
     1647        $this->_out('/Filter /'.$info['f']); 
     1648    if(isset($info['dp'])) 
     1649        $this->_out('/DecodeParms <<'.$info['dp'].'>>'); 
     1650    if(isset($info['trns']) && is_array($info['trns'])) 
     1651    { 
     1652        $trns = ''; 
     1653        for($i=0;$i<count($info['trns']);$i++) 
     1654            $trns .= $info['trns'][$i].' '.$info['trns'][$i].' '; 
     1655        $this->_out('/Mask ['.$trns.']'); 
     1656    } 
     1657    if(isset($info['smask'])) 
     1658        $this->_out('/SMask '.($this->n+1).' 0 R'); 
     1659    $this->_out('/Length '.strlen($info['data']).'>>'); 
     1660    $this->_putstream($info['data']); 
     1661    $this->_out('endobj'); 
     1662    // Soft mask 
     1663    if(isset($info['smask'])) 
     1664    { 
     1665        $dp = '/Predictor 15 /Colors 1 /BitsPerComponent 8 /Columns '.$info['w']; 
     1666        $smask = array('w'=>$info['w'], 'h'=>$info['h'], 'cs'=>'DeviceGray', 'bpc'=>8, 'f'=>$info['f'], 'dp'=>$dp, 'data'=>$info['smask']); 
     1667        $this->_putimage($smask); 
     1668    } 
     1669    // Palette 
     1670    if($info['cs']=='Indexed') 
     1671    { 
     1672        $filter = ($this->compress) ? '/Filter /FlateDecode ' : ''; 
     1673        $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal']; 
    15671674        $this->_newobj(); 
    1568         $this->images[$file]['n']=$this->n; 
    1569         $this->_out('<</Type /XObject'); 
    1570         $this->_out('/Subtype /Image'); 
    1571         $this->_out('/Width '.$info['w']); 
    1572         $this->_out('/Height '.$info['h']); 
    1573         if($info['cs']=='Indexed') 
    1574             $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]'); 
    1575         else 
    1576         { 
    1577             $this->_out('/ColorSpace /'.$info['cs']); 
    1578             if($info['cs']=='DeviceCMYK') 
    1579                 $this->_out('/Decode [1 0 1 0 1 0 1 0]'); 
    1580         } 
    1581         $this->_out('/BitsPerComponent '.$info['bpc']); 
    1582         if(isset($info['f'])) 
    1583             $this->_out('/Filter /'.$info['f']); 
    1584         if(isset($info['parms'])) 
    1585             $this->_out($info['parms']); 
    1586         if(isset($info['trns']) && is_array($info['trns'])) 
    1587         { 
    1588             $trns=''; 
    1589             for($i=0;$i<count($info['trns']);$i++) 
    1590                 $trns.=$info['trns'][$i].' '.$info['trns'][$i].' '; 
    1591             $this->_out('/Mask ['.$trns.']'); 
    1592         } 
    1593         $this->_out('/Length '.strlen($info['data']).'>>'); 
    1594         $this->_putstream($info['data']); 
    1595         unset($this->images[$file]['data']); 
     1675        $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>'); 
     1676        $this->_putstream($pal); 
    15961677        $this->_out('endobj'); 
    1597         //Palette 
    1598         if($info['cs']=='Indexed') 
    1599         { 
    1600             $this->_newobj(); 
    1601             $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal']; 
    1602             $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>'); 
    1603             $this->_putstream($pal); 
    1604             $this->_out('endobj'); 
    1605         } 
    16061678    } 
    16071679} 
     
    16291701    $this->_putfonts(); 
    16301702    $this->_putimages(); 
    1631     //Resource dictionary 
    1632     $this->offsets[2]=strlen($this->buffer); 
     1703    // Resource dictionary 
     1704    $this->offsets[2] = strlen($this->buffer); 
    16331705    $this->_out('2 0 obj'); 
    16341706    $this->_out('<<'); 
     
    16651737        $this->_out('/OpenAction [3 0 R /XYZ null null 1]'); 
    16661738    elseif(!is_string($this->ZoomMode)) 
    1667         $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']'); 
     1739        $this->_out('/OpenAction [3 0 R /XYZ null null '.sprintf('%.2F',$this->ZoomMode/100).']'); 
    16681740    if($this->LayoutMode=='single') 
    16691741        $this->_out('/PageLayout /SinglePage'); 
     
    16911763    $this->_putpages(); 
    16921764    $this->_putresources(); 
    1693     //Info 
     1765    // Info 
    16941766    $this->_newobj(); 
    16951767    $this->_out('<<'); 
     
    16971769    $this->_out('>>'); 
    16981770    $this->_out('endobj'); 
    1699     //Catalog 
     1771    // Catalog 
    17001772    $this->_newobj(); 
    17011773    $this->_out('<<'); 
     
    17031775    $this->_out('>>'); 
    17041776    $this->_out('endobj'); 
    1705     //Cross-ref 
    1706     $o=strlen($this->buffer); 
     1777    // Cross-ref 
     1778    $o = strlen($this->buffer); 
    17071779    $this->_out('xref'); 
    17081780    $this->_out('0 '.($this->n+1)); 
     
    17101782    for($i=1;$i<=$this->n;$i++) 
    17111783        $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i])); 
    1712     //Trailer 
     1784    // Trailer 
    17131785    $this->_out('trailer'); 
    17141786    $this->_out('<<'); 
     
    17181790    $this->_out($o); 
    17191791    $this->_out('%%EOF'); 
    1720     $this->state=3; 
    1721 } 
    1722 //End of class 
    1723 } 
    1724  
    1725 //Handle special IE contype request 
     1792    $this->state = 3; 
     1793} 
     1794// End of class 
     1795} 
     1796 
     1797// Handle special IE contype request 
    17261798if(isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT']=='contype') 
    17271799{ 
Note: See TracChangeset for help on using the changeset viewer.