Ignore:
Timestamp:
2010/12/11 12:15:20 (13 years ago)
Author:
Seasoft
Message:

#403(インクルードしているライブラリ群をバージョンアップする)

  • FPDF関連 (PHP4について、動作環境無く未確認)
Location:
branches/version-2_5-dev/data/module/fpdf
Files:
1 added
1 moved

Legend:

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

    r18701 r19716  
    11<?php 
    22// 
    3 //  FPDF_TPL - Version 1.1.1 
    4 // 
    5 //    Copyright 2004-2007 Setasign - Jan Slabon 
     3//  FPDF_TPL - Version 1.2 
     4// 
     5//    Copyright 2004-2010 Setasign - Jan Slabon 
    66// 
    77//  Licensed under the Apache License, Version 2.0 (the "License"); 
     
    1818// 
    1919 
    20 require_once("fpdf.php"); 
    21  
    2220class FPDF_TPL extends FPDF { 
    2321    /** 
     
    5250     
    5351    /** 
    54      * Constructor 
    55      * See FPDF-Documentation 
    56      * @param string $orientation 
    57      * @param string $unit 
    58      * @param mixed $format 
    59      */ 
    60     function fpdf_tpl($orientation='P',$unit='mm',$format='A4') { 
    61         parent::fpdf($orientation,$unit,$format); 
    62     } 
     52     * Last used Template data 
     53     * 
     54     * @var array 
     55     */ 
     56    var $lastUsedTemplateData = array(); 
    6357     
    6458    /** 
     
    8074     * @return int The ID of new created Template 
    8175     */ 
    82     function beginTemplate($x=null,$y=null,$w=null,$h=null) { 
     76    function beginTemplate($x = null, $y = null, $w = null, $h = null) { 
     77        if (is_subclass_of($this, 'TCPDF')) { 
     78            $this->Error('This method is only usable with FPDF. Use TCPDF methods startTemplate() instead.'); 
     79            return; 
     80        } 
     81         
    8382        if ($this->page <= 0) 
    8483            $this->error("You have to add a page to fpdf first!"); 
     
    120119 
    121120        $this->_intpl = true; 
    122         $this->SetXY($x+$this->lMargin,$y+$this->tMargin); 
    123         $this->SetRightMargin($this->w-$w+$this->rMargin); 
     121        $this->SetXY($x + $this->lMargin, $y + $this->tMargin); 
     122        $this->SetRightMargin($this->w - $w + $this->rMargin); 
    124123 
    125124        return $this->tpl; 
     
    134133     */ 
    135134    function endTemplate() { 
     135        if (is_subclass_of($this, 'TCPDF')) { 
     136            $args = func_get_args(); 
     137            return call_user_func_array(array($this, 'TCPDF::endTemplate'), $args); 
     138        } 
     139         
    136140        if ($this->_intpl) { 
    137141            $this->_intpl = false;  
     
    168172     * @retrun array The height and width of the template 
    169173     */ 
    170     function useTemplate($tplidx, $_x=null, $_y=null, $_w=0, $_h=0) { 
     174    function useTemplate($tplidx, $_x = null, $_y = null, $_w = 0, $_h = 0) { 
    171175        if ($this->page <= 0) 
    172             $this->error("You have to add a page to fpdf first!"); 
    173  
     176            $this->error('You have to add a page first!'); 
     177         
    174178        if (!isset($this->tpls[$tplidx])) 
    175             $this->error("Template does not exist!"); 
     179            $this->error('Template does not exist!'); 
    176180             
    177181        if ($this->_intpl) { 
     
    180184         
    181185        $tpl =& $this->tpls[$tplidx]; 
    182         $x = $tpl['x']; 
    183         $y = $tpl['y']; 
    184186        $w = $tpl['w']; 
    185187        $h = $tpl['h']; 
    186188         
    187189        if ($_x == null) 
    188             $_x = $x; 
     190            $_x = 0; 
    189191        if ($_y == null) 
    190             $_y = $y; 
    191         $wh = $this->getTemplateSize($tplidx,$_w,$_h); 
     192            $_y = 0; 
     193             
     194        $_x += $tpl['x']; 
     195        $_y += $tpl['y']; 
     196         
     197        $wh = $this->getTemplateSize($tplidx, $_w, $_h); 
    192198        $_w = $wh['w']; 
    193199        $_h = $wh['h']; 
    194200     
    195         $this->_out(sprintf("q %.4f 0 0 %.4f %.2f %.2f cm", ($_w/$w), ($_h/$h), $_x*$this->k, ($this->h-($_y+$_h))*$this->k)); // Translate  
    196         $this->_out($this->tplprefix.$tplidx." Do Q"); 
    197  
    198         return array("w" => $_w, "h" => $_h); 
     201        $tData = array( 
     202            'x' => $this->x, 
     203            'y' => $this->y, 
     204            'w' => $_w, 
     205            'h' => $_h, 
     206            'scaleX' => ($_w / $w), 
     207            'scaleY' => ($_h / $h), 
     208            'tx' => $_x, 
     209            'ty' =>  ($this->h - $_y - $_h), 
     210            'lty' => ($this->h - $_y - $_h) - ($this->h - $h) * ($_h / $h) 
     211        ); 
     212         
     213        $this->_out(sprintf('q %.4F 0 0 %.4F %.4F %.4F cm', $tData['scaleX'], $tData['scaleY'], $tData['tx'] * $this->k, $tData['ty'] * $this->k)); // Translate  
     214        $this->_out(sprintf('%s%d Do Q', $this->tplprefix, $tplidx)); 
     215 
     216        // reset font in the outer graphic state 
     217        if ($this->FontFamily) { 
     218            $family = $this->FontFamily; 
     219            $this->FontFamily = ''; 
     220            $this->SetFont($family); 
     221        } 
     222         
     223        $this->lastUsedTemplateData = $tData; 
     224         
     225        return array('w' => $_w, 'h' => $_h); 
    199226    } 
    200227     
     
    209236     * @return array The height and width of the template 
    210237     */ 
    211     function getTemplateSize($tplidx, $_w=0, $_h=0) { 
     238    function getTemplateSize($tplidx, $_w = 0, $_h = 0) { 
    212239        if (!$this->tpls[$tplidx]) 
    213240            return false; 
     
    222249        } 
    223250 
    224         if($_w==0) 
    225             $_w=$_h*$w/$h; 
    226         if($_h==0) 
    227             $_h=$_w*$h/$w; 
     251        if($_w == 0) 
     252            $_w = $_h * $w / $h; 
     253        if($_h == 0) 
     254            $_h = $_w * $h / $w; 
    228255             
    229256        return array("w" => $_w, "h" => $_h); 
     
    231258     
    232259    /** 
    233      * See FPDF-Documentation ;-) 
    234      */ 
    235     function SetFont($family,$style='',$size=0) { 
     260     * See FPDF/TCPDF-Documentation ;-) 
     261     */ 
     262    public function SetFont($family, $style = '', $size = 0) { 
     263        if (is_subclass_of($this, 'TCPDF')) { 
     264            $args = func_get_args(); 
     265            return call_user_func_array(array($this, 'TCPDF::SetFont'), $args); 
     266        } 
     267         
    236268        /** 
    237269         * force the resetting of font changes in a template 
     
    242274        parent::SetFont($family, $style, $size); 
    243275        
    244         $fontkey = $this->FontFamily.$this->FontStyle; 
     276        $fontkey = $this->FontFamily . $this->FontStyle; 
    245277         
    246278        if ($this->_intpl) { 
     
    252284     
    253285    /** 
    254      * See FPDF-Documentation ;-) 
    255      */ 
    256     function Image($file,$x,$y,$w=0,$h=0,$type='',$link='') { 
    257         parent::Image($file,$x,$y,$w,$h,$type,$link); 
     286     * See FPDF/TCPDF-Documentation ;-) 
     287     */ 
     288    function Image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $link = '') { 
     289        if (is_subclass_of($this, 'TCPDF')) { 
     290            $args = func_get_args(); 
     291            return call_user_func_array(array($this, 'TCPDF::Image'), $args); 
     292        } 
     293         
     294        $ret = parent::Image($file, $x, $y, $w, $h, $type, $link); 
    258295        if ($this->_intpl) { 
    259296            $this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file]; 
     
    261298            $this->_res['page'][$this->page]['images'][$file] =& $this->images[$file]; 
    262299        } 
     300         
     301        return $ret; 
    263302    } 
    264303     
     
    268307     * AddPage is not available when you're "in" a template. 
    269308     */ 
    270     function AddPage($orientation='') { 
     309    function AddPage($orientation = '', $format = '') { 
     310        if (is_subclass_of($this, 'TCPDF')) { 
     311            $args = func_get_args(); 
     312            return call_user_func_array(array($this, 'TCPDF::AddPage'), $args); 
     313        } 
     314         
    271315        if ($this->_intpl) 
    272316            $this->Error('Adding pages in templates isn\'t possible!'); 
    273         parent::AddPage($orientation); 
     317             
     318        parent::AddPage($orientation, $format); 
    274319    } 
    275320 
     
    277322     * Preserve adding Links in Templates ...won't work 
    278323     */ 
    279     function Link($x,$y,$w,$h,$link) { 
     324    function Link($x, $y, $w, $h, $link) { 
     325        if (is_subclass_of($this, 'TCPDF')) { 
     326            $args = func_get_args(); 
     327            return call_user_func_array(array($this, 'TCPDF::Link'), $args); 
     328        } 
     329         
    280330        if ($this->_intpl) 
    281331            $this->Error('Using links in templates aren\'t possible!'); 
    282         parent::Link($x,$y,$w,$h,$link); 
     332             
     333        parent::Link($x, $y, $w, $h, $link); 
    283334    } 
    284335     
    285336    function AddLink() { 
     337        if (is_subclass_of($this, 'TCPDF')) { 
     338            $args = func_get_args(); 
     339            return call_user_func_array(array($this, 'TCPDF::AddLink'), $args); 
     340        } 
     341         
    286342        if ($this->_intpl) 
    287343            $this->Error('Adding links in templates aren\'t possible!'); 
     
    289345    } 
    290346     
    291     function SetLink($link,$y=0,$page=-1) { 
     347    function SetLink($link, $y = 0, $page = -1) { 
     348        if (is_subclass_of($this, 'TCPDF')) { 
     349            $args = func_get_args(); 
     350            return call_user_func_array(array($this, 'TCPDF::SetLink'), $args); 
     351        } 
     352         
    292353        if ($this->_intpl) 
    293354            $this->Error('Setting links in templates aren\'t possible!'); 
    294         parent::SetLink($link,$y,$page); 
     355        parent::SetLink($link, $y, $page); 
    295356    } 
    296357     
     
    309370            $this->_out('/Subtype /Form'); 
    310371            $this->_out('/FormType 1'); 
    311             $this->_out(sprintf('/BBox [%.2f %.2f %.2f %.2f]',$tpl['x']*$this->k, ($tpl['h']-$tpl['y'])*$this->k, $tpl['w']*$this->k, ($tpl['h']-$tpl['y']-$tpl['h'])*$this->k)); 
     372            $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]', 
     373                // llx 
     374                $tpl['x'] * $this->k, 
     375                // lly 
     376                -$tpl['y'] * $this->k, 
     377                // urx 
     378                ($tpl['w'] + $tpl['x']) * $this->k, 
     379                // ury 
     380                ($tpl['h'] - $tpl['y']) * $this->k 
     381            )); 
     382             
     383            if ($tpl['x'] != 0 || $tpl['y'] != 0) { 
     384                $this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]', 
     385                     -$tpl['x'] * $this->k * 2, $tpl['y'] * $this->k * 2 
     386                )); 
     387            } 
     388             
    312389            $this->_out('/Resources '); 
    313390 
     
    316393                $this->_out('/Font <<'); 
    317394                foreach($this->_res['tpl'][$tplidx]['fonts'] as $font) 
    318                     $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); 
     395                    $this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R'); 
    319396                $this->_out('>>'); 
    320397            } 
     
    325402                if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) { 
    326403                    foreach($this->_res['tpl'][$tplidx]['images'] as $image) 
    327                         $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); 
     404                        $this->_out('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R'); 
    328405                } 
    329406                if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) { 
    330407                    foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $tpl) 
    331                         $this->_out($this->tplprefix.$i.' '.$tpl['n'].' 0 R'); 
     408                        $this->_out($this->tplprefix . $i . ' ' . $tpl['n'] . ' 0 R'); 
    332409                } 
    333410                $this->_out('>>'); 
     
    335412            $this->_out('>>'); 
    336413             
    337             $this->_out('/Length '.strlen($p).' >>'); 
     414            $this->_out('/Length ' . strlen($p) . ' >>'); 
    338415            $this->_putstream($p); 
    339416            $this->_out('endobj'); 
     
    342419     
    343420    /** 
    344      * Private Method 
    345      */ 
    346     function _putresources() { 
    347         $this->_putfonts(); 
    348         $this->_putimages(); 
    349         $this->_putformxobjects(); 
    350         //Resource dictionary 
    351         $this->offsets[2]=strlen($this->buffer); 
    352         $this->_out('2 0 obj'); 
    353         $this->_out('<<'); 
    354         $this->_putresourcedict(); 
    355         $this->_out('>>'); 
    356         $this->_out('endobj'); 
     421     * Overwritten to add _putformxobjects() after _putimages() 
     422     * 
     423     */ 
     424    function _putimages() { 
     425        parent::_putimages(); 
     426        $this->_putformxobjects(); 
    357427    } 
    358428     
     
    362432        if (count($this->tpls)) { 
    363433            foreach($this->tpls as $tplidx => $tpl) { 
    364                 $this->_out($this->tplprefix.$tplidx.' '.$tpl['n'].' 0 R'); 
     434                $this->_out(sprintf('%s%d %d 0 R', $this->tplprefix, $tplidx, $tpl['n'])); 
    365435            } 
    366436        } 
     
    371441     */ 
    372442    function _out($s) { 
    373        //Add a line to the document 
    374        if ($this->state==2) { 
    375            if (!$this->_intpl) 
    376                $this->pages[$this->page].=$s."\n"; 
    377            else 
    378                $this->tpls[$this->tpl]['buffer'] .= $s."\n"; 
    379        } else { 
    380            $this->buffer.=$s."\n"; 
    381        } 
     443        if ($this->state == 2 && $this->_intpl) { 
     444            $this->tpls[$this->tpl]['buffer'] .= $s . "\n"; 
     445        } else { 
     446            parent::_out($s); 
     447        } 
    382448    } 
    383449} 
    384  
    385 ?> 
Note: See TracChangeset for help on using the changeset viewer.