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/fpdi_pdf_parser.php

    r18701 r19716  
    11<?php 
    22// 
    3 //  FPDI - Version 1.2 
    4 // 
    5 //    Copyright 2004-2007 Setasign - Jan Slabon 
     3//  FPDI - Version 1.4 
     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("pdf_parser.php"); 
     20require_once('pdf_parser.php'); 
    2121 
    2222class fpdi_pdf_parser extends pdf_parser { 
     
    5959     * @var array 
    6060     */ 
    61     var $availableBoxes = array("/MediaBox","/CropBox","/BleedBox","/TrimBox","/ArtBox"); 
     61    var $availableBoxes = array('/MediaBox', '/CropBox', '/BleedBox', '/TrimBox', '/ArtBox'); 
    6262         
    6363    /** 
     
    6767     * @param object $fpdi      Object of type fpdi 
    6868     */ 
    69     function fpdi_pdf_parser($filename,&$fpdi) { 
     69    function fpdi_pdf_parser($filename, &$fpdi) { 
    7070        $this->fpdi =& $fpdi; 
    71         $this->filename = $filename; 
    7271         
    7372        parent::pdf_parser($filename); 
     
    111110 
    112111        if ($pageno < 0 || $pageno >= $this->getPageCount()) { 
    113             $this->fpdi->error("Pagenumber is wrong!"); 
     112            $this->fpdi->error('Pagenumber is wrong!'); 
    114113        } 
    115114 
     
    164163     */ 
    165164    function getContent() { 
    166         $buffer = ""; 
     165        $buffer = ''; 
    167166         
    168167        if (isset($this->pages[$this->pageno][1][1]['/Contents'])) { 
    169168            $contents = $this->_getPageContent($this->pages[$this->pageno][1][1]['/Contents']); 
    170169            foreach($contents AS $tmp_content) { 
    171                 $buffer .= $this->_rebuildContentStream($tmp_content).' '; 
     170                $buffer .= $this->_rebuildContentStream($tmp_content) . ' '; 
    172171            } 
    173172        } 
     
    215214            $_filter = $obj[1][1]['/Filter']; 
    216215 
     216            if ($_filter[0] == PDF_TYPE_OBJREF) { 
     217                $tmpFilter = $this->pdf_resolve_object($this->c, $_filter); 
     218                $_filter = $tmpFilter[1]; 
     219            } 
     220             
    217221            if ($_filter[0] == PDF_TYPE_TOKEN) { 
    218222                $filters[] = $_filter; 
     
    226230        foreach ($filters AS $_filter) { 
    227231            switch ($_filter[1]) { 
    228                 case "/FlateDecode": 
    229                     if (function_exists('gzuncompress')) { 
    230                         $stream = (strlen($stream) > 0) ? @gzuncompress($stream) : '';                         
     232                case '/FlateDecode': 
     233                    // $stream .= "\x0F\x0D"; // in an errorious stream this suffix could work 
     234                    if (function_exists('gzuncompress')) { 
     235                        $stream = (strlen($stream) > 0) ? @gzuncompress($stream) : ''; 
    231236                    } else { 
    232                         $this->fpdi->error(sprintf("To handle %s filter, please compile php with zlib support.",$_filter[1])); 
     237                        $this->error(sprintf('To handle %s filter, please compile php with zlib support.',$_filter[1])); 
    233238                    } 
     239                     
    234240                    if ($stream === false) { 
    235                         $this->fpdi->error("Error while decompressing stream."); 
     241                        $this->error('Error while decompressing stream.'); 
    236242                    } 
    237243                break; 
     244                case '/LZWDecode': 
     245                    include_once('filters/FilterLZW_FPDI.php'); 
     246                    $decoder = new FilterLZW_FPDI($this->fpdi); 
     247                    $stream = $decoder->decode($stream); 
     248                    break; 
     249                case '/ASCII85Decode': 
     250                    include_once('filters/FilterASCII85_FPDI.php'); 
     251                    $decoder = new FilterASCII85_FPDI($this->fpdi); 
     252                    $stream = $decoder->decode($stream); 
     253                    break; 
    238254                case null: 
    239255                    $stream = $stream; 
    240256                break; 
    241257                default: 
    242                     if (preg_match("/^\/[a-z85]*$/i", $_filter[1], $filterName) && @include_once('decoders'.$_filter[1].'.php')) { 
    243                         $filterName = substr($_filter[1],1); 
    244                         if (class_exists($filterName)) { 
    245                             $decoder =& new $filterName($this->fpdi); 
    246                             $stream = $decoder->decode(trim($stream)); 
    247                         } else { 
    248                             $this->fpdi->error(sprintf("Unsupported Filter: %s",$_filter[1])); 
    249                         } 
    250                     } else { 
    251                         $this->fpdi->error(sprintf("Unsupported Filter: %s",$_filter[1])); 
    252                     } 
     258                    $this->error(sprintf('Unsupported Filter: %s',$_filter[1])); 
    253259            } 
    254260        } 
     
    264270     * @param array $page a /Page 
    265271     * @param string $box_index Type of Box @see $availableBoxes 
    266      * @return array 
    267      */ 
    268     function getPageBox($page, $box_index) { 
    269         $page = $this->pdf_resolve_object($this->c,$page); 
     272     * @param float Scale factor from user space units to points 
     273     * @return array 
     274     */ 
     275    function getPageBox($page, $box_index, $k) { 
     276        $page = $this->pdf_resolve_object($this->c, $page); 
    270277        $box = null; 
    271278        if (isset($page[1][1][$box_index])) 
     
    273280         
    274281        if (!is_null($box) && $box[0] == PDF_TYPE_OBJREF) { 
    275             $tmp_box = $this->pdf_resolve_object($this->c,$box); 
     282            $tmp_box = $this->pdf_resolve_object($this->c, $box); 
    276283            $box = $tmp_box[1]; 
    277284        } 
     
    279286        if (!is_null($box) && $box[0] == PDF_TYPE_ARRAY) { 
    280287            $b =& $box[1]; 
    281             return array("x" => $b[0][1]/$this->fpdi->k, 
    282                          "y" => $b[1][1]/$this->fpdi->k, 
    283                          "w" => abs($b[0][1]-$b[2][1])/$this->fpdi->k, 
    284                          "h" => abs($b[1][1]-$b[3][1])/$this->fpdi->k); 
     288            return array('x' => $b[0][1]/$k, 
     289                         'y' => $b[1][1]/$k, 
     290                         'w' => abs($b[0][1]-$b[2][1])/$k, 
     291                         'h' => abs($b[1][1]-$b[3][1])/$k, 
     292                         'llx' => min($b[0][1], $b[2][1])/$k, 
     293                         'lly' => min($b[1][1], $b[3][1])/$k, 
     294                         'urx' => max($b[0][1], $b[2][1])/$k, 
     295                         'ury' => max($b[1][1], $b[3][1])/$k, 
     296                         ); 
    285297        } else if (!isset ($page[1][1]['/Parent'])) { 
    286298            return false; 
    287299        } else { 
    288             return $this->getPageBox($this->pdf_resolve_object($this->c, $page[1][1]['/Parent']), $box_index); 
    289         } 
    290     } 
    291  
    292     function getPageBoxes($pageno) { 
    293         return $this->_getPageBoxes($this->pages[$pageno-1]); 
    294     } 
    295      
    296     /** 
    297      * Get all Boxes from /Page 
     300            return $this->getPageBox($this->pdf_resolve_object($this->c, $page[1][1]['/Parent']), $box_index, $k); 
     301        } 
     302    } 
     303 
     304    /** 
     305     * Get all page boxes by page no 
     306     *  
     307     * @param int The page number 
     308     * @param float Scale factor from user space units to points 
     309     * @return array 
     310     */ 
     311     function getPageBoxes($pageno, $k) { 
     312        return $this->_getPageBoxes($this->pages[$pageno-1], $k); 
     313    } 
     314     
     315    /** 
     316     * Get all boxes from /Page 
    298317     * 
    299318     * @param array a /Page 
    300319     * @return array 
    301320     */ 
    302     function _getPageBoxes($page) { 
     321    function _getPageBoxes($page, $k) { 
    303322        $boxes = array(); 
    304323 
    305324        foreach($this->availableBoxes AS $box) { 
    306             if ($_box = $this->getPageBox($page,$box)) { 
     325            if ($_box = $this->getPageBox($page, $box, $k)) { 
    307326                $boxes[$box] = $_box; 
    308327            } 
     
    312331    } 
    313332 
     333    /** 
     334     * Get the page rotation by pageno 
     335     * 
     336     * @param integer $pageno 
     337     * @return array 
     338     */ 
    314339    function getPageRotation($pageno) { 
    315340        return $this->_getPageRotation($this->pages[$pageno-1]); 
    316341    } 
    317342     
    318     function _getPageRotation ($obj) { // $obj = /Page 
     343    function _getPageRotation($obj) { // $obj = /Page 
    319344        $obj = $this->pdf_resolve_object($this->c, $obj); 
    320345        if (isset ($obj[1][1]['/Rotate'])) { 
     
    342367     * @param array the result-array 
    343368     */ 
    344     function read_pages (&$c, &$pages, &$result) { 
     369    function read_pages(&$c, &$pages, &$result) { 
    345370        // Get the kids dictionary 
    346         $kids = $this->pdf_resolve_object ($c, $pages[1][1]['/Kids']); 
    347  
    348         if (!is_array($kids)) 
    349             $this->fpdi->Error("Cannot find /Kids in current /Page-Dictionary"); 
    350         foreach ($kids[1] as $v) { 
     371        $_kids = $this->pdf_resolve_object ($c, $pages[1][1]['/Kids']); 
     372         
     373        if (!is_array($_kids)) 
     374            $this->error('Cannot find /Kids in current /Page-Dictionary'); 
     375             
     376        if ($_kids[1][0] == PDF_TYPE_ARRAY) { 
     377            $kids = $_kids[1][1]; 
     378        } else { 
     379            $kids = $_kids[1]; 
     380        } 
     381         
     382        foreach ($kids as $v) { 
    351383            $pg = $this->pdf_resolve_object ($c, $v); 
    352384            if ($pg[1][1]['/Type'][1] === '/Pages') { 
    353385                // If one of the kids is an embedded 
    354386                // /Pages array, resolve it as well. 
    355                 $this->read_pages ($c, $pg, $result); 
     387                $this->read_pages($c, $pg, $result); 
    356388            } else { 
    357389                $result[] = $pg; 
     
    369401    function getPDFVersion() { 
    370402        parent::getPDFVersion(); 
    371          
    372         if (isset($this->fpdi->importVersion) && $this->pdfVersion > $this->fpdi->importVersion) { 
    373             $this->fpdi->importVersion = $this->pdfVersion; 
    374         } 
     403        $this->fpdi->setPDFVersion(max($this->fpdi->getPDFVersion(), $this->pdfVersion)); 
    375404    } 
    376405     
    377406} 
    378  
    379 ?> 
Note: See TracChangeset for help on using the changeset viewer.