adding zend project folders into old campcaster.

This commit is contained in:
naomiaro 2010-12-07 14:19:27 -05:00
parent 56abfaf28e
commit 7ef0c18b26
4045 changed files with 1054952 additions and 0 deletions

View file

@ -0,0 +1,148 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Array.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'array' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2010 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
{
/**
* Array element items
*
* Array of Zend_Pdf_Element objects
*
* @var array
*/
public $items;
/**
* Object constructor
*
* @param array $val - array of Zend_Pdf_Element objects
* @throws Zend_Pdf_Exception
*/
public function __construct($val = null)
{
$this->items = new ArrayObject();
if ($val !== null && is_array($val)) {
foreach ($val as $element) {
if (!$element instanceof Zend_Pdf_Element) {
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('Array elements must be Zend_Pdf_Element objects');
}
$this->items[] = $element;
}
} else if ($val !== null){
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('Argument must be an array');
}
}
/**
* Getter
*
* @param string $property
* @throws Zend_Pdf_Exception
*/
public function __get($property) {
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('Undefined property: Zend_Pdf_Element_Array::$' . $property);
}
/**
* Setter
*
* @param mixed $offset
* @param mixed $value
* @throws Zend_Pdf_Exception
*/
public function __set($property, $value) {
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_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()
{
$phpArray = array();
foreach ($this->items as $item) {
$phpArray[] = $item->toPhp();
}
return $phpArray;
}
}

View file

@ -0,0 +1,83 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Boolean.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'boolean' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2010 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)) {
require_once 'Zend/Pdf/Exception.php';
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,189 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Dictionary.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Internally used classes */
require_once 'Zend/Pdf/Element/Name.php';
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'dictionary' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2010 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)) {
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('Argument must be an array');
}
foreach ($val as $name => $element) {
if (!$element instanceof Zend_Pdf_Element) {
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('Array elements must be Zend_Pdf_Element objects');
}
if (!is_string($name)) {
require_once 'Zend/Pdf/Exception.php';
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)) {
require_once 'Zend/Pdf/Exception.php';
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,161 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Name.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'name' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2010 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) {
require_once 'Zend/Pdf/Exception.php';
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,75 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Null.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'null' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2010 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,95 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Numeric.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'numeric' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2010 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) ) {
require_once 'Zend/Pdf/Exception.php';
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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Object.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'indirect object' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2010 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) {
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('Object number must not be an instance of Zend_Pdf_Element_Object.');
}
if ( !(is_integer($objNum) && $objNum > 0) ) {
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('Object number must be positive integer.');
}
if ( !(is_integer($genNum) && $genNum >= 0) ) {
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('Generation number must be non-negative integer.');
}
$this->_value = $val;
$this->_objNum = $objNum;
$this->_genNum = $genNum;
$this->_factory = $factory;
$this->setParentObject($this);
$factory->registerObject($this, $objNum . ' ' . $genNum);
}
/**
* 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)
{
return call_user_func_array(array($this->_value, $method), $args);
}
/**
* Mark object as modified, to include it into new PDF file segment
*/
public function touch()
{
$this->_factory->markAsModified($this);
}
/**
* Return object, which can be used to identify object and its references identity
*
* @return Zend_Pdf_Element_Object
*/
public function getObject()
{
return $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,422 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Stream.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Internally used classes */
require_once 'Zend/Pdf/Element/Stream.php';
require_once 'Zend/Pdf/Element/Dictionary.php';
require_once 'Zend/Pdf/Element/Numeric.php';
/** Zend_Pdf_Element_Object */
require_once 'Zend/Pdf/Element/Object.php';
/**
* PDF file 'stream object' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2010 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. */
require_once 'Zend/Pdf/Exception.php';
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':
require_once 'Zend/Pdf/Filter/AsciiHex.php';
$valueRef = Zend_Pdf_Filter_AsciiHex::decode($valueRef);
break;
case 'ASCII85Decode':
require_once 'Zend/Pdf/Filter/Ascii85.php';
$valueRef = Zend_Pdf_Filter_Ascii85::decode($valueRef);
break;
case 'FlateDecode':
require_once 'Zend/Pdf/Filter/Compression/Flate.php';
$valueRef = Zend_Pdf_Filter_Compression_Flate::decode($valueRef,
$this->_originalDictionary['DecodeParms'][$id]);
break;
case 'LZWDecode':
require_once 'Zend/Pdf/Filter/Compression/Lzw.php';
$valueRef = Zend_Pdf_Filter_Compression_Lzw::decode($valueRef,
$this->_originalDictionary['DecodeParms'][$id]);
break;
case 'RunLengthDecode':
require_once 'Zend/Pdf/Filter/RunLength.php';
$valueRef = Zend_Pdf_Filter_RunLength::decode($valueRef);
break;
default:
require_once 'Zend/Pdf/Exception.php';
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. */
require_once 'Zend/Pdf/Exception.php';
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':
require_once 'Zend/Pdf/Filter/AsciiHex.php';
$valueRef = Zend_Pdf_Filter_AsciiHex::encode($valueRef);
break;
case 'ASCII85Decode':
require_once 'Zend/Pdf/Filter/Ascii85.php';
$valueRef = Zend_Pdf_Filter_Ascii85::encode($valueRef);
break;
case 'FlateDecode':
require_once 'Zend/Pdf/Filter/Compression/Flate.php';
$valueRef = Zend_Pdf_Filter_Compression_Flate::encode($valueRef,
$this->_originalDictionary['DecodeParms'][$id]);
break;
case 'LZWDecode':
require_once 'Zend/Pdf/Filter/Compression/Lzw.php';
$valueRef = Zend_Pdf_Filter_Compression_Lzw::encode($valueRef,
$this->_originalDictionary['DecodeParms'][$id]);
break;
case 'RunLengthDecode':
require_once 'Zend/Pdf/Filter/RunLength.php';
$valueRef = Zend_Pdf_Filter_RunLength::encode($valueRef);
break;
default:
require_once 'Zend/Pdf/Exception.php';
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();
}
require_once 'Zend/Pdf/Exception.php';
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;
}
require_once 'Zend/Pdf/Exception.php';
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:
require_once 'Zend/Pdf/Exception.php';
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,277 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Reference.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Internally used classes */
require_once 'Zend/Pdf/Element/Null.php';
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'reference' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2010 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) ) {
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('Object number must be positive integer');
}
if ( !(is_integer($genNum) && $genNum >= 0) ) {
require_once 'Zend/Pdf/Exception.php';
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()
{
if (($obj = $this->_factory->fetchObject($this->_objNum . ' ' . $this->_genNum)) === null) {
$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') {
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('Incorrect reference to the object');
}
$this->_ref = $obj;
}
/**
* Mark object as modified, to include it into new PDF file segment.
*/
public function touch()
{
if ($this->_ref === null) {
$this->_dereference();
}
$this->_ref->touch();
}
/**
* Return object, which can be used to identify object and its references identity
*
* @return Zend_Pdf_Element_Object
*/
public function getObject()
{
if ($this->_ref === null) {
$this->_dereference();
}
return $this->_ref;
}
/**
* 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();
}
return call_user_func_array(array($this->_ref, $method), $args);
}
/**
* 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,83 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Context.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* PDF reference object context
* Reference context is defined by PDF parser and PDF Refernce table
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2010 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_StringParser
*/
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_StringParser
*/
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,198 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Table.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* PDF file reference table
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2010 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') {
require_once 'Zend/Pdf/Exception.php';
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])) {
require_once 'Zend/Pdf/Exception.php';
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);
}
require_once 'Zend/Pdf/Exception.php';
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])) {
require_once 'Zend/Pdf/Exception.php';
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);
}
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('Object not found.');
}
}

View file

@ -0,0 +1,117 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Stream.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Internally used classes */
require_once 'Zend/Pdf.php';
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'stream' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2010 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,263 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: String.php 21545 2010-03-18 09:12:27Z bate $
*/
/** Zend_Pdf_Element */
require_once 'Zend/Pdf/Element.php';
/**
* PDF file 'string' element implementation
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2010 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 $str
* @return string
*/
public static function escape($str)
{
$outEntries = array();
foreach (str_split($str, 128) as $chunk) {
// Collect sequence of unescaped characters
$offset = strcspn($chunk, "\n\r\t\x08\x0C()\\");
$chunkOut = substr($chunk, 0, $offset);
while ($offset < strlen($chunk)) {
$nextCode = ord($chunk[$offset++]);
switch ($nextCode) {
// "\n" - line feed (LF)
case 10:
$chunkOut .= '\\n';
break;
// "\r" - carriage return (CR)
case 13:
$chunkOut .= '\\r';
break;
// "\t" - horizontal tab (HT)
case 9:
$chunkOut .= '\\t';
break;
// "\b" - backspace (BS)
case 8:
$chunkOut .= '\\b';
break;
// "\f" - form feed (FF)
case 12:
$chunkOut .= '\\f';
break;
// '(' - left paranthesis
case 40:
$chunkOut .= '\\(';
break;
// ')' - right paranthesis
case 41:
$chunkOut .= '\\)';
break;
// '\' - backslash
case 92:
$chunkOut .= '\\\\';
break;
default:
// This code is never executed extually
//
// Don't use non-ASCII characters escaping
// if ($nextCode >= 32 && $nextCode <= 126 ) {
// // Visible ASCII symbol
// $chunkEntries[] = chr($nextCode);
// } else {
// $chunkEntries[] = sprintf('\\%03o', $nextCode);
// }
break;
}
// Collect sequence of unescaped characters
$start = $offset;
$offset += strcspn($chunk, "\n\r\t\x08\x0C()\\", $offset);
$chunkOut .= substr($chunk, $start, $offset - $start);
}
$outEntries[] = $chunkOut;
}
return implode("\\\n", $outEntries);
}
/**
* Unescape string according to the PDF rules
*
* @param string $str
* @return string
*/
public static function unescape($str)
{
$outEntries = array();
$offset = 0;
while ($offset < strlen($str)) {
// Searche for the next escaped character/sequence
$escapeCharOffset = strpos($str, '\\', $offset);
if ($escapeCharOffset === false || $escapeCharOffset == strlen($str) - 1) {
// There are no escaped characters or '\' char has came at the end of string
$outEntries[] = substr($str, $offset);
break;
} else {
// Collect unescaped characters sequence
$outEntries[] = substr($str, $offset, $escapeCharOffset - $offset);
// Go to the escaped character
$offset = $escapeCharOffset + 1;
switch ($str[$offset]) {
// '\\n' - line feed (LF)
case 'n':
$outEntries[] = "\n";
break;
// '\\r' - carriage return (CR)
case 'r':
$outEntries[] = "\r";
break;
// '\\t' - horizontal tab (HT)
case 't':
$outEntries[] = "\t";
break;
// '\\b' - backspace (BS)
case 'b':
$outEntries[] = "\x08";
break;
// '\\f' - form feed (FF)
case 'f':
$outEntries[] = "\x0C";
break;
// '\\(' - left paranthesis
case '(':
$outEntries[] = '(';
break;
// '\\)' - right paranthesis
case ')':
$outEntries[] = ')';
break;
// '\\\\' - backslash
case '\\':
$outEntries[] = '\\';
break;
// "\\\n" or "\\\n\r"
case "\n":
// skip new line symbol
if ($str[$offset + 1] == "\r") {
$offset++;
}
break;
default:
if (strpos('0123456789', $str[$offset]) !== false) {
// Character in octal representation
// '\\xxx'
$nextCode = '0' . $str[$offset];
if (strpos('0123456789', $str[$offset + 1]) !== false) {
$nextCode .= $str[++$offset];
if (strpos('0123456789', $str[$offset + 1]) !== false) {
$nextCode .= $str[++$offset];
}
}
$outEntries[] = chr(octdec($nextCode));
} else {
$outEntries[] = $str[$offset];
}
break;
}
$offset++;
}
}
return implode($outEntries);
}
}

View file

@ -0,0 +1,98 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Binary.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** 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-2010 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)
{
return strtoupper(bin2hex($inStr));
}
/**
* Unescape string according to the PDF rules
*
* @param string $inStr
* @return string
*/
public static function unescape($inStr)
{
$chunks = array();
$offset = 0;
$length = 0;
while ($offset < strlen($inStr)) {
// Collect hexadecimal characters
$start = $offset;
$offset += strspn($inStr, "0123456789abcdefABCDEF", $offset);
$chunks[] = substr($inStr, $start, $offset - $start);
$length += strlen(end($chunks));
// Skip non-hexadecimal characters
$offset += strcspn($inStr, "0123456789abcdefABCDEF", $offset);
}
if ($length % 2 != 0) {
// We have odd number of digits.
// Final digit is assumed to be '0'
$chunks[] = '0';
}
return pack('H*' , implode($chunks));
}
/**
* Return object as string
*
* @param Zend_Pdf_Factory $factory
* @return string
*/
public function toString($factory = null)
{
return '<' . self::escape((string)$this->value) . '>';
}
}