import v1.0.0-RC4 | 2009-05-20

This commit is contained in:
2019-07-17 22:08:50 +02:00
commit b484e522e8
2459 changed files with 1038434 additions and 0 deletions

View File

@ -0,0 +1,151 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/** Zend_Pdf_PhpArray */
require_once 'Zend/Pdf/PhpArray.php';
/**
* PDF file 'array' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Element_Array extends Zend_Pdf_Element
{
/**
* Object value
* Array of Zend_Pdf_Element objects.
* Appropriate methods must (!) be used to modify it to provide correct
* work with objects and references.
*
* @var Zend_Pdf_PhpArray
*/
private $_items;
/**
* Object constructor
*
* @param array $val - array of Zend_Pdf_Element objects
* @throws Zend_Pdf_Exception
*/
public function __construct($val = null)
{
$this->_items = new Zend_Pdf_PhpArray();
if ($val !== null && is_array($val)) {
foreach ($val as $element) {
if (!$element instanceof Zend_Pdf_Element) {
throw new Zend_Pdf_Exception('Array elements must be Zend_Pdf_Element objects');
}
$this->_items[] = $element;
}
} else if ($val !== null){
throw new Zend_Pdf_Exception('Argument must be an array');
}
}
/**
* Provides access to $this->_items
*
* @param string $property
* @return Zend_Pdf_PhpArray
*/
public function __get($property) {
if ($property=='items') {
return $this->_items;
}
throw new Exception('Undefined property: Zend_Pdf_Element_Array::$' . $property);
}
/**
* Provides read-only access to $this->_items;
*
* @param unknown_type $offset
* @param unknown_type $value
*/
public function __set($property, $value) {
if ($property=='items') {
throw new Exception('Array container cannot be overwritten');
}
throw new Exception('Undefined property: Zend_Pdf_Element_Array::$' . $property);
}
/**
* Return type of the element.
*
* @return integer
*/
public function getType()
{
return Zend_Pdf_Element::TYPE_ARRAY;
}
/**
* Return object as string
*
* @param Zend_Pdf_Factory $factory
* @return string
*/
public function toString($factory = null)
{
$outStr = '[';
$lastNL = 0;
foreach ($this->_items as $element) {
if (strlen($outStr) - $lastNL > 128) {
$outStr .= "\n";
$lastNL = strlen($outStr);
}
$outStr .= $element->toString($factory) . ' ';
}
$outStr .= ']';
return $outStr;
}
/**
* Convert PDF element to PHP type.
*
* Dictionary is returned as an associative array
*
* @return mixed
*/
public function toPhp()
{
foreach ($this->_items as $item) {
$phpArray[] = $item->toPhp();
}
return $phpArray;
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'boolean' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Element_Boolean extends Zend_Pdf_Element
{
/**
* Object value
*
* @var boolean
*/
public $value;
/**
* Object constructor
*
* @param boolean $val
* @throws Zend_Pdf_Exception
*/
public function __construct($val)
{
if (! is_bool($val)) {
throw new Zend_Pdf_Exception('Argument must be boolean.');
}
$this->value = $val;
}
/**
* Return type of the element.
*
* @return integer
*/
public function getType()
{
return Zend_Pdf_Element::TYPE_BOOL;
}
/**
* Return object as string
*
* @param Zend_Pdf_Factory $factory
* @return string
*/
public function toString($factory = null)
{
return $this->value ? 'true' : 'false';
}
}

View File

@ -0,0 +1,181 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'dictionary' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Element_Dictionary extends Zend_Pdf_Element
{
/**
* Dictionary elements
* Array of Zend_Pdf_Element objects ('name' => Zend_Pdf_Element)
*
* @var array
*/
private $_items = array();
/**
* Object constructor
*
* @param array $val - array of Zend_Pdf_Element objects
* @throws Zend_Pdf_Exception
*/
public function __construct($val = null)
{
if ($val === null) {
return;
} else if (!is_array($val)) {
throw new Zend_Pdf_Exception('Argument must be an array');
}
foreach ($val as $name => $element) {
if (!$element instanceof Zend_Pdf_Element) {
throw new Zend_Pdf_Exception('Array elements must be Zend_Pdf_Element objects');
}
if (!is_string($name)) {
throw new Zend_Pdf_Exception('Array keys must be strings');
}
$this->_items[$name] = $element;
}
}
/**
* Add element to an array
*
* @name Zend_Pdf_Element_Name $name
* @param Zend_Pdf_Element $val - Zend_Pdf_Element object
* @throws Zend_Pdf_Exception
*/
public function add(Zend_Pdf_Element_Name $name, Zend_Pdf_Element $val)
{
$this->_items[$name->value] = $val;
}
/**
* Return dictionary keys
*
* @return array
*/
public function getKeys()
{
return array_keys($this->_items);
}
/**
* Get handler
*
* @param string $property
* @return Zend_Pdf_Element | null
*/
public function __get($item)
{
$element = isset($this->_items[$item]) ? $this->_items[$item]
: null;
return $element;
}
/**
* Set handler
*
* @param string $property
* @param mixed $value
*/
public function __set($item, $value)
{
if ($value === null) {
unset($this->_items[$item]);
} else {
$this->_items[$item] = $value;
}
}
/**
* Return type of the element.
*
* @return integer
*/
public function getType()
{
return Zend_Pdf_Element::TYPE_DICTIONARY;
}
/**
* Return object as string
*
* @param Zend_Pdf_Factory $factory
* @return string
*/
public function toString($factory = null)
{
$outStr = '<<';
$lastNL = 0;
foreach ($this->_items as $name => $element) {
if (!is_object($element)) {
throw new Zend_Pdf_Exception('Wrong data');
}
if (strlen($outStr) - $lastNL > 128) {
$outStr .= "\n";
$lastNL = strlen($outStr);
}
$nameObj = new Zend_Pdf_Element_Name($name);
$outStr .= $nameObj->toString($factory) . ' ' . $element->toString($factory) . ' ';
}
$outStr .= '>>';
return $outStr;
}
/**
* Convert PDF element to PHP type.
*
* Dictionary is returned as an associative array
*
* @return mixed
*/
public function toPhp()
{
$phpArray = array();
foreach ($this->_items as $itemName => $item) {
$phpArray[$itemName] = $item->toPhp();
}
return $phpArray;
}
}

View File

@ -0,0 +1,159 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'name' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Element_Name extends Zend_Pdf_Element
{
/**
* Object value
*
* @var string
*/
public $value;
/**
* Object constructor
*
* @param string $val
* @throws Zend_Pdf_Exception
*/
public function __construct($val)
{
settype($val, 'string');
if (strpos($val,"\x00") !== false) {
throw new Zend_Pdf_Exception('Null character is not allowed in PDF Names');
}
$this->value = (string)$val;
}
/**
* Return type of the element.
*
* @return integer
*/
public function getType()
{
return Zend_Pdf_Element::TYPE_NAME;
}
/**
* Escape string according to the PDF rules
*
* @param string $inStr
* @return string
*/
public static function escape($inStr)
{
$outStr = '';
for ($count = 0; $count < strlen($inStr); $count++) {
$nextCode = ord($inStr[$count]);
switch ($inStr[$count]) {
case '(':
// fall through to next case
case ')':
// fall through to next case
case '<':
// fall through to next case
case '>':
// fall through to next case
case '[':
// fall through to next case
case ']':
// fall through to next case
case '{':
// fall through to next case
case '}':
// fall through to next case
case '/':
// fall through to next case
case '%':
// fall through to next case
case '\\':
// fall through to next case
case '#':
$outStr .= sprintf('#%02X', $nextCode);
break;
default:
if ($nextCode >= 33 && $nextCode <= 126 ) {
// Visible ASCII symbol
$outStr .= $inStr[$count];
} else {
$outStr .= sprintf('#%02X', $nextCode);
}
}
}
return $outStr;
}
/**
* Unescape string according to the PDF rules
*
* @param string $inStr
* @return string
*/
public static function unescape($inStr)
{
$outStr = '';
for ($count = 0; $count < strlen($inStr); $count++) {
if ($inStr[$count] != '#' ) {
$outStr .= $inStr[$count];
} else {
// Escape sequence
$outStr .= chr(base_convert(substr($inStr, $count+1, 2), 16, 10 ));
$count +=2;
}
}
return $outStr;
}
/**
* Return object as string
*
* @param Zend_Pdf_Factory $factory
* @return string
*/
public function toString($factory = null)
{
return '/' . self::escape((string)$this->value);
}
}

View File

@ -0,0 +1,74 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'null' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Element_Null extends Zend_Pdf_Element
{
/**
* Object value. Always null.
*
* @var mixed
*/
public $value;
/**
* Object constructor
*/
public function __construct()
{
$this->value = null;
}
/**
* Return type of the element.
*
* @return integer
*/
public function getType()
{
return Zend_Pdf_Element::TYPE_NULL;
}
/**
* Return object as string
*
* @param Zend_Pdf_Factory $factory
* @return string
*/
public function toString($factory = null)
{
return 'null';
}
}

View File

@ -0,0 +1,93 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'numeric' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Element_Numeric extends Zend_Pdf_Element
{
/**
* Object value
*
* @var numeric
*/
public $value;
/**
* Object constructor
*
* @param numeric $val
* @throws Zend_Pdf_Exception
*/
public function __construct($val)
{
if ( !is_numeric($val) ) {
throw new Zend_Pdf_Exception('Argument must be numeric');
}
$this->value = $val;
}
/**
* Return type of the element.
*
* @return integer
*/
public function getType()
{
return Zend_Pdf_Element::TYPE_NUMERIC;
}
/**
* Return object as string
*
* @param Zend_Pdf_Factory $factory
* @return string
*/
public function toString($factory = null)
{
if (is_integer($this->value)) {
return (string)$this->value;
}
/**
* PDF doesn't support exponental format.
* Fixed point format must be used instead
*/
$prec = 0; $v = $this->value;
while (abs( floor($v) - $v ) > 1e-10) {
$prec++; $v *= 10;
}
return sprintf("%.{$prec}F", $this->value);
}
}

View File

@ -0,0 +1,250 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/** Zend_Pdf_ElementFactory */
require_once 'Zend/Pdf/ElementFactory.php';
/**
* PDF file 'indirect object' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Element_Object extends Zend_Pdf_Element
{
/**
* Object value
*
* @var Zend_Pdf_Element
*/
protected $_value;
/**
* Object number within PDF file
*
* @var integer
*/
protected $_objNum;
/**
* Generation number
*
* @var integer
*/
protected $_genNum;
/**
* Reference to the factory.
*
* @var Zend_Pdf_ElementFactory
*/
protected $_factory;
/**
* Object constructor
*
* @param Zend_Pdf_Element $val
* @param integer $objNum
* @param integer $genNum
* @param Zend_Pdf_ElementFactory $factory
* @throws Zend_Pdf_Exception
*/
public function __construct(Zend_Pdf_Element $val, $objNum, $genNum, Zend_Pdf_ElementFactory $factory)
{
if ($val instanceof self) {
throw new Zend_Pdf_Exception('Object number must not be instance of Zend_Pdf_Element_Object.');
}
if ( !(is_integer($objNum) && $objNum > 0) ) {
throw new Zend_Pdf_Exception('Object number must be positive integer.');
}
if ( !(is_integer($genNum) && $genNum >= 0) ) {
throw new Zend_Pdf_Exception('Generation number must be non-negative integer.');
}
$this->_value = $val;
$this->_objNum = $objNum;
$this->_genNum = $genNum;
$this->_factory = $factory;
$factory->registerObject($this);
}
/**
* Check, that object is generated by specified factory
*
* @return Zend_Pdf_ElementFactory
*/
public function getFactory()
{
return $this->_factory;
}
/**
* Return type of the element.
*
* @return integer
*/
public function getType()
{
return $this->_value->getType();
}
/**
* Get object number
*
* @return integer
*/
public function getObjNum()
{
return $this->_objNum;
}
/**
* Get generation number
*
* @return integer
*/
public function getGenNum()
{
return $this->_genNum;
}
/**
* Return reference to the object
*
* @param Zend_Pdf_Factory $factory
* @return string
*/
public function toString($factory = null)
{
if ($factory === null) {
$shift = 0;
} else {
$shift = $factory->getEnumerationShift($this->_factory);
}
return $this->_objNum + $shift . ' ' . $this->_genNum . ' R';
}
/**
* Dump object to a string to save within PDF file.
*
* $factory parameter defines operation context.
*
* @param Zend_Pdf_ElementFactory $factory
* @return string
*/
public function dump(Zend_Pdf_ElementFactory $factory)
{
$shift = $factory->getEnumerationShift($this->_factory);
return $this->_objNum + $shift . " " . $this->_genNum . " obj \n"
. $this->_value->toString($factory) . "\n"
. "endobj\n";
}
/**
* Get handler
*
* @param string $property
* @return mixed
*/
public function __get($property)
{
return $this->_value->$property;
}
/**
* Set handler
*
* @param string $property
* @param mixed $value
*/
public function __set($property, $value)
{
$this->_value->$property = $value;
}
/**
* Call handler
*
* @param string $method
* @param array $args
* @return mixed
*/
public function __call($method, $args)
{
switch (count($args)) {
case 0:
return $this->_value->$method();
case 1:
return $this->_value->$method($args[0]);
case 2:
return $this->_value->$method($args[0], $args[1]);
case 3:
return $this->_value->$method($args[0], $args[1], $args[2]);
case 4:
return $this->_value->$method($args[0], $args[1], $args[2], $args[3]);
default:
throw new Zend_Pdf_Exception('Unsupported number of arguments');
}
}
/**
* Mark object as modified, to include it into new PDF file segment
*/
public function touch()
{
$this->_factory->markAsModified($this);
}
/**
* Clean up resources, used by object
*/
public function cleanUp()
{
$this->_value = null;
}
/**
* Convert PDF element to PHP type.
*
* @return mixed
*/
public function toPhp()
{
return $this->_value->toPhp();
}
}

View File

@ -0,0 +1,409 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Pdf_Element_Object */
require_once 'Zend/Pdf/Element/Object.php';
/** Zend_Pdf_Element_Stream */
require_once 'Zend/Pdf/Element/Stream.php';
/** Zend_Pdf_Filter_Ascii85 */
require_once 'Zend/Pdf/Filter/Ascii85.php';
/** Zend_Pdf_Filter_AsciiHex */
require_once 'Zend/Pdf/Filter/AsciiHex.php';
/** Zend_Pdf_Filter_Compression_Flate */
require_once 'Zend/Pdf/Filter/Compression/Flate.php';
/** Zend_Pdf_Filter_Compression_Lzw */
require_once 'Zend/Pdf/Filter/Compression/Lzw.php';
/** Zend_Pdf_ElementFactory */
require_once 'Zend/Pdf/ElementFactory.php';
/**
* PDF file 'stream object' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Element_Object_Stream extends Zend_Pdf_Element_Object
{
/**
* StreamObject dictionary
* Required enries:
* Length
*
* @var Zend_Pdf_Element_Dictionary
*/
private $_dictionary;
/**
* Flag which signals, that stream is decoded
*
* @var boolean
*/
private $_streamDecoded;
/**
* Stored original stream object dictionary.
* Used to decode stream during an access time.
*
* The only properties, which affect decoding, are sored here.
*
* @var array|null
*/
private $_originalDictionary = null;
/**
* Object constructor
*
* @param mixed $val
* @param integer $objNum
* @param integer $genNum
* @param Zend_Pdf_ElementFactory $factory
* @param Zend_Pdf_Element_Dictionary|null $dictionary
* @throws Zend_Pdf_Exception
*/
public function __construct($val, $objNum, $genNum, Zend_Pdf_ElementFactory $factory, $dictionary = null)
{
parent::__construct(new Zend_Pdf_Element_Stream($val), $objNum, $genNum, $factory);
if ($dictionary === null) {
$this->_dictionary = new Zend_Pdf_Element_Dictionary();
$this->_dictionary->Length = new Zend_Pdf_Element_Numeric(strlen( $val ));
$this->_streamDecoded = true;
} else {
$this->_dictionary = $dictionary;
$this->_streamDecoded = false;
}
}
/**
* Store original dictionary information in $_originalDictionary class member.
* Used to store information and to normalize filters information before defiltering.
*
*/
private function _storeOriginalDictionary()
{
$this->_originalDictionary = array();
$this->_originalDictionary['Filter'] = array();
$this->_originalDictionary['DecodeParms'] = array();
if ($this->_dictionary->Filter === null) {
// Do nothing.
} else if ($this->_dictionary->Filter->getType() == Zend_Pdf_Element::TYPE_ARRAY) {
foreach ($this->_dictionary->Filter->items as $id => $filter) {
$this->_originalDictionary['Filter'][$id] = $filter->value;
$this->_originalDictionary['DecodeParms'][$id] = array();
if ($this->_dictionary->DecodeParms !== null ) {
if ($this->_dictionary->DecodeParms->items[$id] !== null &&
$this->_dictionary->DecodeParms->items[$id]->value !== null ) {
foreach ($this->_dictionary->DecodeParms->items[$id]->getKeys() as $paramKey) {
$this->_originalDictionary['DecodeParms'][$id][$paramKey] =
$this->_dictionary->DecodeParms->items[$id]->$paramKey->value;
}
}
}
}
} else if ($this->_dictionary->Filter->getType() != Zend_Pdf_Element::TYPE_NULL) {
$this->_originalDictionary['Filter'][0] = $this->_dictionary->Filter->value;
$this->_originalDictionary['DecodeParms'][0] = array();
if ($this->_dictionary->DecodeParms !== null ) {
foreach ($this->_dictionary->DecodeParms->getKeys() as $paramKey) {
$this->_originalDictionary['DecodeParms'][0][$paramKey] =
$this->_dictionary->DecodeParms->$paramKey->value;
}
}
}
if ($this->_dictionary->F !== null) {
$this->_originalDictionary['F'] = $this->_dictionary->F->value;
}
$this->_originalDictionary['FFilter'] = array();
$this->_originalDictionary['FDecodeParms'] = array();
if ($this->_dictionary->FFilter === null) {
// Do nothing.
} else if ($this->_dictionary->FFilter->getType() == Zend_Pdf_Element::TYPE_ARRAY) {
foreach ($this->_dictionary->FFilter->items as $id => $filter) {
$this->_originalDictionary['FFilter'][$id] = $filter->value;
$this->_originalDictionary['FDecodeParms'][$id] = array();
if ($this->_dictionary->FDecodeParms !== null ) {
if ($this->_dictionary->FDecodeParms->items[$id] !== null &&
$this->_dictionary->FDecodeParms->items[$id]->value !== null) {
foreach ($this->_dictionary->FDecodeParms->items[$id]->getKeys() as $paramKey) {
$this->_originalDictionary['FDecodeParms'][$id][$paramKey] =
$this->_dictionary->FDecodeParms->items[$id]->items[$paramKey]->value;
}
}
}
}
} else {
$this->_originalDictionary['FFilter'][0] = $this->_dictionary->FFilter->value;
$this->_originalDictionary['FDecodeParms'][0] = array();
if ($this->_dictionary->FDecodeParms !== null ) {
foreach ($this->_dictionary->FDecodeParms->getKeys() as $paramKey) {
$this->_originalDictionary['FDecodeParms'][0][$paramKey] =
$this->_dictionary->FDecodeParms->items[$paramKey]->value;
}
}
}
}
/**
* Decode stream
*
* @throws Zend_Pdf_Exception
*/
private function _decodeStream()
{
if ($this->_originalDictionary === null) {
$this->_storeOriginalDictionary();
}
/**
* All applied stream filters must be processed to decode stream.
* If we don't recognize any of applied filetrs an exception should be thrown here
*/
if (isset($this->_originalDictionary['F'])) {
/** @todo Check, how external files can be processed. */
throw new Zend_Pdf_Exception('External filters are not supported now.');
}
foreach ($this->_originalDictionary['Filter'] as $id => $filterName ) {
$valueRef = &$this->_value->value->getRef();
$this->_value->value->touch();
switch ($filterName) {
case 'ASCIIHexDecode':
$valueRef = Zend_Pdf_Filter_AsciiHex::decode($valueRef);
break;
case 'ASCII85Decode':
$valueRef = Zend_Pdf_Filter_Ascii85::decode($valueRef);
break;
case 'FlateDecode':
$valueRef = Zend_Pdf_Filter_Compression_Flate::decode($valueRef,
$this->_originalDictionary['DecodeParms'][$id]);
break;
case 'LZWDecode':
$valueRef = Zend_Pdf_Filter_Compression_Lzw::decode($valueRef,
$this->_originalDictionary['DecodeParms'][$id]);
break;
default:
throw new Zend_Pdf_Exception('Unknown stream filter: \'' . $filterName . '\'.');
}
}
$this->_streamDecoded = true;
}
/**
* Encode stream
*
* @throws Zend_Pdf_Exception
*/
private function _encodeStream()
{
/**
* All applied stream filters must be processed to encode stream.
* If we don't recognize any of applied filetrs an exception should be thrown here
*/
if (isset($this->_originalDictionary['F'])) {
/** @todo Check, how external files can be processed. */
throw new Zend_Pdf_Exception('External filters are not supported now.');
}
$filters = array_reverse($this->_originalDictionary['Filter'], true);
foreach ($filters as $id => $filterName ) {
$valueRef = &$this->_value->value->getRef();
$this->_value->value->touch();
switch ($filterName) {
case 'ASCIIHexDecode':
$valueRef = Zend_Pdf_Filter_AsciiHex::encode($valueRef);
break;
case 'ASCII85Decode':
$valueRef = Zend_Pdf_Filter_Ascii85::encode($valueRef);
break;
case 'FlateDecode':
$valueRef = Zend_Pdf_Filter_Compression_Flate::encode($valueRef,
$this->_originalDictionary['DecodeParms'][$id]);
break;
case 'LZWDecode':
$valueRef = Zend_Pdf_Filter_Compression_Lzw::encode($valueRef,
$this->_originalDictionary['DecodeParms'][$id]);
break;
default:
throw new Zend_Pdf_Exception('Unknown stream filter: \'' . $filterName . '\'.');
}
}
$this->_streamDecoded = false;
}
/**
* Get handler
*
* @param string $property
* @return mixed
* @throws Zend_Pdf_Exception
*/
public function __get($property)
{
if ($property == 'dictionary') {
/**
* If stream is note decoded yet, then store original decoding options (do it only once).
*/
if (( !$this->_streamDecoded ) && ($this->_originalDictionary === null)) {
$this->_storeOriginalDictionary();
}
return $this->_dictionary;
}
if ($property == 'value') {
if (!$this->_streamDecoded) {
$this->_decodeStream();
}
return $this->_value->value->getRef();
}
throw new Zend_Pdf_Exception('Unknown stream object property requested.');
}
/**
* Set handler
*
* @param string $property
* @param mixed $value
*/
public function __set($property, $value)
{
if ($property == 'value') {
$valueRef = &$this->_value->value->getRef();
$valueRef = $value;
$this->_value->value->touch();
$this->_streamDecoded = true;
return;
}
throw new Zend_Pdf_Exception('Unknown stream object property: \'' . $property . '\'.');
}
/**
* Treat stream data as already encoded
*/
public function skipFilters()
{
$this->_streamDecoded = false;
}
/**
* Call handler
*
* @param string $method
* @param array $args
* @return mixed
*/
public function __call($method, $args)
{
if (!$this->_streamDecoded) {
$this->_decodeStream();
}
switch (count($args)) {
case 0:
return $this->_value->$method();
case 1:
return $this->_value->$method($args[0]);
default:
throw new Zend_Pdf_Exception('Unsupported number of arguments');
}
}
/**
* Dump object to a string to save within PDF file
*
* $factory parameter defines operation context.
*
* @param Zend_Pdf_ElementFactory $factory
* @return string
*/
public function dump(Zend_Pdf_ElementFactory $factory)
{
$shift = $factory->getEnumerationShift($this->_factory);
if ($this->_streamDecoded) {
$this->_storeOriginalDictionary();
$this->_encodeStream();
} else if ($this->_originalDictionary != null) {
$startDictionary = $this->_originalDictionary;
$this->_storeOriginalDictionary();
$newDictionary = $this->_originalDictionary;
if ($startDictionary !== $newDictionary) {
$this->_originalDictionary = $startDictionary;
$this->_decodeStream();
$this->_originalDictionary = $newDictionary;
$this->_encodeStream();
}
}
// Update stream length
$this->dictionary->Length->value = $this->_value->length();
return $this->_objNum + $shift . " " . $this->_genNum . " obj \n"
. $this->dictionary->toString($factory) . "\n"
. $this->_value->toString($factory) . "\n"
. "endobj\n";
}
/**
* Clean up resources, used by object
*/
public function cleanUp()
{
$this->_dictionary = null;
$this->_value = null;
}
}

View File

@ -0,0 +1,280 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/** Zend_Pdf_Element_Reference_Context */
require_once 'Zend/Pdf/Element/Reference/Context.php';
/** Zend_Pdf_Element_Reference_Table */
require_once 'Zend/Pdf/Element/Reference/Table.php';
/** Zend_Pdf_ElementFactory */
require_once 'Zend/Pdf/ElementFactory.php';
/**
* PDF file 'reference' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Element_Reference extends Zend_Pdf_Element
{
/**
* Object value
* The reference to the object
*
* @var mixed
*/
private $_ref;
/**
* Object number within PDF file
*
* @var integer
*/
private $_objNum;
/**
* Generation number
*
* @var integer
*/
private $_genNum;
/**
* Reference context
*
* @var Zend_Pdf_Element_Reference_Context
*/
private $_context;
/**
* Reference to the factory.
*
* It's the same as referenced object factory, but we save it here to avoid
* unnecessary dereferencing, whech can produce cascade dereferencing and parsing.
* The same for duplication of getFactory() function. It can be processed by __call()
* method, but we catch it here.
*
* @var Zend_Pdf_ElementFactory
*/
private $_factory;
/**
* Object constructor:
*
* @param integer $objNum
* @param integer $genNum
* @param Zend_Pdf_Element_Reference_Context $context
* @param Zend_Pdf_ElementFactory $factory
* @throws Zend_Pdf_Exception
*/
public function __construct($objNum, $genNum = 0, Zend_Pdf_Element_Reference_Context $context, Zend_Pdf_ElementFactory $factory)
{
if ( !(is_integer($objNum) && $objNum > 0) ) {
throw new Zend_Pdf_Exception('Object number must be positive integer');
}
if ( !(is_integer($genNum) && $genNum >= 0) ) {
throw new Zend_Pdf_Exception('Generation number must be non-negative integer');
}
$this->_objNum = $objNum;
$this->_genNum = $genNum;
$this->_ref = null;
$this->_context = $context;
$this->_factory = $factory;
}
/**
* Check, that object is generated by specified factory
*
* @return Zend_Pdf_ElementFactory
*/
public function getFactory()
{
return $this->_factory;
}
/**
* Return type of the element.
*
* @return integer
*/
public function getType()
{
if ($this->_ref === null) {
$this->_dereference();
}
return $this->_ref->getType();
}
/**
* Return reference to the object
*
* @param Zend_Pdf_Factory $factory
* @return string
*/
public function toString($factory = null)
{
if ($factory === null) {
$shift = 0;
} else {
$shift = $factory->getEnumerationShift($this->_factory);
}
return $this->_objNum + $shift . ' ' . $this->_genNum . ' R';
}
/**
* Dereference.
* Take inderect object, take $value member of this object (must be Zend_Pdf_Element),
* take reference to the $value member of this object and assign it to
* $value member of current PDF Reference object
* $obj can be null
*
* @throws Zend_Pdf_Exception
*/
private function _dereference()
{
$obj = $this->_context->getParser()->getObject(
$this->_context->getRefTable()->getOffset($this->_objNum . ' ' . $this->_genNum . ' R'),
$this->_context
);
if ($obj === null ) {
$this->_ref = new Zend_Pdf_Element_Null();
return;
}
if ($obj->toString() != $this->_objNum . ' ' . $this->_genNum . ' R') {
throw new Zend_Pdf_Exception('Incorrect reference to the object');
}
$this->_ref = $obj;
$this->setParentObject($obj);
$this->_factory->registerObject($this);
}
/**
* Mark object as modified, to include it into new PDF file segment.
*/
public function touch()
{
if ($this->_ref === null) {
$this->_dereference();
}
$this->_ref->touch();
}
/**
* Get handler
*
* @param string $property
* @return mixed
*/
public function __get($property)
{
if ($this->_ref === null) {
$this->_dereference();
}
return $this->_ref->$property;
}
/**
* Set handler
*
* @param string $property
* @param mixed $value
*/
public function __set($property, $value)
{
if ($this->_ref === null) {
$this->_dereference();
}
$this->_ref->$property = $value;
}
/**
* Call handler
*
* @param string $method
* @param array $args
* @return mixed
*/
public function __call($method, $args)
{
if ($this->_ref === null) {
$this->_dereference();
}
switch (count($args)) {
case 0:
return $this->_ref->$method();
case 1:
return $this->_ref->$method($args[0]);
case 2:
return $this->_ref->$method($args[0], $args[1]);
case 3:
return $this->_ref->$method($args[0], $args[1], $args[2]);
case 4:
return $this->_ref->$method($args[0], $args[1], $args[2], $args[3]);
default:
throw new Zend_Pdf_Exception('Unsupported number of arguments');
}
}
/**
* Clean up resources
*/
public function cleanUp()
{
$this->_ref = null;
}
/**
* Convert PDF element to PHP type.
*
* @return mixed
*/
public function toPhp()
{
if ($this->_ref === null) {
$this->_dereference();
}
return $this->_ref->toPhp();
}
}

View File

@ -0,0 +1,89 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Pdf_StringParser */
require_once 'Zend/Pdf/StringParser.php';
/** Zend_Pdf_Element_Reference_Table */
require_once 'Zend/Pdf/Element/Reference/Table.php';
/**
* PDF reference object context
* Reference context is defined by PDF parser and PDF Refernce table
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Element_Reference_Context
{
/**
* PDF parser object.
*
* @var Zend_Pdf_Parser
*/
private $_stringParser;
/**
* Reference table
*
* @var Zend_Pdf_Element_Reference_Table
*/
private $_refTable;
/**
* Object constructor
*
* @param Zend_Pdf_StringParser $parser
* @param Zend_Pdf_Element_Reference_Table $refTable
*/
public function __construct(Zend_Pdf_StringParser $parser,
Zend_Pdf_Element_Reference_Table $refTable)
{
$this->_stringParser = $parser;
$this->_refTable = $refTable;
}
/**
* Context parser
*
* @return Zend_Pdf_Parser
*/
public function getParser()
{
return $this->_stringParser;
}
/**
* Context reference table
*
* @return Zend_Pdf_Element_Reference_Table
*/
public function getRefTable()
{
return $this->_refTable;
}
}

View File

@ -0,0 +1,193 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* PDF file reference table
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Element_Reference_Table
{
/**
* Parent reference table
*
* @var Zend_Pdf_Element_Reference_Table
*/
private $_parent;
/**
* Free entries
* 'reference' => next free object number
*
* @var array
*/
private $_free;
/**
* Generation numbers for free objects.
* Array: objNum => nextGeneration
*
* @var array
*/
private $_generations;
/**
* In use entries
* 'reference' => offset
*
* @var array
*/
private $_inuse;
/**
* Generation numbers for free objects.
* Array: objNum => objGeneration
*
* @var array
*/
private $_usedObjects;
/**
* Object constructor
*/
public function __construct()
{
$this->_parent = null;
$this->_free = array(); $this->_generations = array();
$this->_inuse = array(); $this->_usedObjects = array();
}
/**
* Add reference to the reference table
*
* @param string $ref
* @param integer $offset
* @param boolean $inuse
*/
public function addReference($ref, $offset, $inuse = true)
{
$refElements = explode(' ', $ref);
if (!is_numeric($refElements[0]) || !is_numeric($refElements[1]) || $refElements[2] != 'R') {
throw new Zend_Pdf_Exception("Incorrect reference: '$ref'");
}
$objNum = (int)$refElements[0];
$genNum = (int)$refElements[1];
if ($inuse) {
$this->_inuse[$ref] = $offset;
$this->_usedObjects[$objNum] = $objNum;
} else {
$this->_free[$ref] = $offset;
$this->_generations[$objNum] = $genNum;
}
}
/**
* Set parent reference table
*
* @param Zend_Pdf_Element_Reference_Table $parent
*/
public function setParent(self $parent)
{
$this->_parent = $parent;
}
/**
* Get object offset
*
* @param string $ref
* @return integer
*/
public function getOffset($ref)
{
if (isset($this->_inuse[$ref])) {
return $this->_inuse[$ref];
}
if (isset($this->_free[$ref])) {
return null;
}
if (isset($this->_parent)) {
return $this->_parent->getOffset($ref);
}
return null;
}
/**
* Get next object from a list of free objects.
*
* @param string $ref
* @return integer
* @throws Zend_Pdf_Exception
*/
public function getNextFree($ref)
{
if (isset($this->_inuse[$ref])) {
throw new Zend_Pdf_Exception('Object is not free');
}
if (isset($this->_free[$ref])) {
return $this->_free[$ref];
}
if (isset($this->_parent)) {
return $this->_parent->getNextFree($ref);
}
throw new Zend_Pdf_Exception('Object not found.');
}
/**
* Get next generation number for free object
*
* @param integer $objNum
* @return unknown
*/
public function getNewGeneration($objNum)
{
if (isset($this->_usedObjects[$objNum])) {
throw new Zend_Pdf_Exception('Object is not free');
}
if (isset($this->_generations[$objNum])) {
return $this->_generations[$objNum];
}
if (isset($this->_parent)) {
return $this->_parent->getNewGeneration($objNum);
}
throw new Zend_Pdf_Exception('Object not found.');
}
}

View File

@ -0,0 +1,124 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Pdf
*/
require_once 'Zend/Pdf.php';
/**
* @see Zend_Pdf_Element
*/
require_once 'Zend/Pdf/Element.php';
/**
* @see Zend_Memory
*/
require_once 'Zend/Memory.php';
/**
* PDF file 'stream' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Element_Stream extends Zend_Pdf_Element
{
/**
* Object value
*
* @var Zend_Memory_Container
*/
public $value;
/**
* Object constructor
*
* @param string $val
*/
public function __construct($val)
{
$this->value = Zend_Pdf::getMemoryManager()->create($val);
}
/**
* Return type of the element.
*
* @return integer
*/
public function getType()
{
return Zend_Pdf_Element::TYPE_STREAM;
}
/**
* Stream length.
* (Method is used to avoid string copying, which may occurs in some cases)
*
* @return integer
*/
public function length()
{
return strlen($this->value->getRef());
}
/**
* Clear stream
*
*/
public function clear()
{
$ref = &$this->value->getRef();
$ref = '';
$this->value->touch();
}
/**
* Append value to a stream
*
* @param mixed $val
*/
public function append($val)
{
$ref = &$this->value->getRef();
$ref .= (string)$val;
$this->value->touch();
}
/**
* Return object as string
*
* @param Zend_Pdf_Factory $factory
* @return string
*/
public function toString($factory = null)
{
return "stream\n" . $this->value->getRef() . "\nendstream";
}
}

View File

@ -0,0 +1,246 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'string' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Element_String extends Zend_Pdf_Element
{
/**
* Object value
*
* @var string
*/
public $value;
/**
* Object constructor
*
* @param string $val
*/
public function __construct($val)
{
$this->value = (string)$val;
}
/**
* Return type of the element.
*
* @return integer
*/
public function getType()
{
return Zend_Pdf_Element::TYPE_STRING;
}
/**
* Return object as string
*
* @param Zend_Pdf_Factory $factory
* @return string
*/
public function toString($factory = null)
{
return '(' . self::escape((string)$this->value) . ')';
}
/**
* Escape string according to the PDF rules
*
* @param string $inStr
* @return string
*/
public static function escape($inStr)
{
$outStr = '';
$lastNL = 0;
for ($count = 0; $count < strlen($inStr); $count++) {
if (strlen($outStr) - $lastNL > 128) {
$outStr .= "\\\n";
$lastNL = strlen($outStr);
}
$nextCode = ord($inStr[$count]);
switch ($nextCode) {
// "\n" - line feed (LF)
case 10:
$outStr .= '\\n';
break;
// "\r" - carriage return (CR)
case 13:
$outStr .= '\\r';
break;
// "\t" - horizontal tab (HT)
case 9:
$outStr .= '\\t';
break;
// "\b" - backspace (BS)
case 8:
$outStr .= '\\b';
break;
// "\f" - form feed (FF)
case 12:
$outStr .= '\\f';
break;
// '(' - left paranthesis
case 40:
$outStr .= '\\(';
break;
// ')' - right paranthesis
case 41:
$outStr .= '\\)';
break;
// '\' - backslash
case 92:
$outStr .= '\\\\';
break;
default:
// Don't use non-ASCII characters escaping
// if ($nextCode >= 32 && $nextCode <= 126 ) {
// // Visible ASCII symbol
// $outStr .= $inStr[$count];
// } else {
// $outStr .= sprintf('\\%03o', $nextCode);
// }
$outStr .= $inStr[$count];
break;
}
}
return $outStr;
}
/**
* Unescape string according to the PDF rules
*
* @param string $inStr
* @return string
*/
public static function unescape($inStr)
{
$outStr = '';
for ($count = 0; $count < strlen($inStr); $count++) {
if ($inStr[$count] != '\\' || $count == strlen($inStr)-1) {
$outStr .= $inStr[$count];
} else { // Escape sequence
switch ($inStr{++$count}) {
// '\\n' - line feed (LF)
case 'n':
$outStr .= "\n";
break;
// '\\r' - carriage return (CR)
case 'r':
$outStr .= "\r";
break;
// '\\t' - horizontal tab (HT)
case 't':
$outStr .= "\t";
break;
// '\\b' - backspace (BS)
case 'b':
$outStr .= "\x08";
break;
// '\\f' - form feed (FF)
case 'f':
$outStr .= "\x0C";
break;
// '\\(' - left paranthesis
case '(':
$outStr .= '(';
break;
// '\\)' - right paranthesis
case ')':
$outStr .= ')';
break;
// '\\\\' - backslash
case '\\':
$outStr .= '\\';
break;
// "\\\n" or "\\\n\r"
case "\n":
// skip new line symbol
if ($inStr[$count+1] == "\r") {
$count++;
}
break;
default:
if (ord($inStr[$count]) >= ord('0') &&
ord($inStr[$count]) <= ord('9')) {
// Character in octal representation
// '\\xxx'
$nextCode = '0' . $inStr[$count];
if (ord($inStr[$count+1]) >= ord('0') &&
ord($inStr[$count+1]) <= ord('9')) {
$nextCode .= $inStr{++$count};
if (ord($inStr[$count+1]) >= ord('0') &&
ord($inStr[$count+1]) <= ord('9')) {
$nextCode .= $inStr{++$count};
}
}
$outStr .= chr($nextCode);
} else {
$outStr .= $inStr[$count];
}
break;
}
}
}
return $outStr;
}
}

View File

@ -0,0 +1,110 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Pdf_Element_String */
require_once 'Zend/Pdf/Element/String.php';
/**
* PDF file 'binary string' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Element_String_Binary extends Zend_Pdf_Element_String
{
/**
* Object value
*
* @var string
*/
public $value;
/**
* Escape string according to the PDF rules
*
* @param string $inStr
* @return string
*/
public static function escape($inStr)
{
$outStr = '';
for ($count = 0; $count < strlen($inStr); $count++) {
$outStr .= sprintf('%02X', ord($inStr[$count]));
}
return $outStr;
}
/**
* Unescape string according to the PDF rules
*
* @param string $inStr
* @return string
*/
public static function unescape($inStr)
{
$outStr = '';
$nextHexCode = '';
for ($count = 0; $count < strlen($inStr); $count++) {
$nextCharCode = ord($inStr[$count]);
if( ($nextCharCode >= 48 /*'0'*/ &&
$nextCharCode <= 57 /*'9'*/ ) ||
($nextCharCode >= 97 /*'a'*/ &&
$nextCharCode <= 102 /*'f'*/ ) ||
($nextCharCode >= 65 /*'A'*/ &&
$nextCharCode <= 70 /*'F'*/ ) ) {
$nextHexCode .= $inStr[$count];
}
if (strlen($nextHexCode) == 2) {
$outStr .= chr(intval($nextHexCode, 16));
$nextHexCode = '';
}
}
if ($nextHexCode != '') {
// We have odd number of digits.
// Final digit is assumed to be '0'
$outStr .= chr(base_convert($nextHexCode . '0', 16, 10));
}
return $outStr;
}
/**
* Return object as string
*
* @param Zend_Pdf_Factory $factory
* @return string
*/
public function toString($factory = null)
{
return '<' . self::escape((string)$this->value) . '>';
}
}