File indexing completed on 2025-01-19 05:21:21
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Pdf 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 0023 /** Zend_Pdf_Element_String */ 0024 // require_once 'Zend/Pdf/Element/String.php'; 0025 0026 0027 /** 0028 * PDF file 'binary string' element implementation 0029 * 0030 * @category Zend 0031 * @package Zend_Pdf 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 class Zend_Pdf_Element_String_Binary extends Zend_Pdf_Element_String 0036 { 0037 /** 0038 * Object value 0039 * 0040 * @var string 0041 */ 0042 public $value; 0043 0044 0045 /** 0046 * Escape string according to the PDF rules 0047 * 0048 * @param string $inStr 0049 * @return string 0050 */ 0051 public static function escape($inStr) 0052 { 0053 return strtoupper(bin2hex($inStr)); 0054 } 0055 0056 0057 /** 0058 * Unescape string according to the PDF rules 0059 * 0060 * @param string $inStr 0061 * @return string 0062 */ 0063 public static function unescape($inStr) 0064 { 0065 $chunks = array(); 0066 $offset = 0; 0067 $length = 0; 0068 while ($offset < strlen($inStr)) { 0069 // Collect hexadecimal characters 0070 $start = $offset; 0071 $offset += strspn($inStr, "0123456789abcdefABCDEF", $offset); 0072 $chunks[] = substr($inStr, $start, $offset - $start); 0073 $length += strlen(end($chunks)); 0074 0075 // Skip non-hexadecimal characters 0076 $offset += strcspn($inStr, "0123456789abcdefABCDEF", $offset); 0077 } 0078 if ($length % 2 != 0) { 0079 // We have odd number of digits. 0080 // Final digit is assumed to be '0' 0081 $chunks[] = '0'; 0082 } 0083 0084 return pack('H*' , implode($chunks)); 0085 } 0086 0087 0088 /** 0089 * Return object as string 0090 * 0091 * @param Zend_Pdf_Factory $factory 0092 * @return string 0093 */ 0094 public function toString($factory = null) 0095 { 0096 return '<' . self::escape((string)$this->value) . '>'; 0097 } 0098 }