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 */ 0024 // require_once 'Zend/Pdf/Element.php'; 0025 0026 0027 /** 0028 * PDF file 'name' 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_Name extends Zend_Pdf_Element 0036 { 0037 /** 0038 * Object value 0039 * 0040 * @var string 0041 */ 0042 public $value; 0043 0044 0045 /** 0046 * Object constructor 0047 * 0048 * @param string $val 0049 * @throws Zend_Pdf_Exception 0050 */ 0051 public function __construct($val) 0052 { 0053 settype($val, 'string'); 0054 if (strpos($val,"\x00") !== false) { 0055 // require_once 'Zend/Pdf/Exception.php'; 0056 throw new Zend_Pdf_Exception('Null character is not allowed in PDF Names'); 0057 } 0058 $this->value = (string)$val; 0059 } 0060 0061 0062 /** 0063 * Return type of the element. 0064 * 0065 * @return integer 0066 */ 0067 public function getType() 0068 { 0069 return Zend_Pdf_Element::TYPE_NAME; 0070 } 0071 0072 0073 /** 0074 * Escape string according to the PDF rules 0075 * 0076 * @param string $inStr 0077 * @return string 0078 */ 0079 public static function escape($inStr) 0080 { 0081 $outStr = ''; 0082 0083 for ($count = 0; $count < strlen($inStr); $count++) { 0084 $nextCode = ord($inStr[$count]); 0085 0086 switch ($inStr[$count]) { 0087 case '(': 0088 // fall through to next case 0089 case ')': 0090 // fall through to next case 0091 case '<': 0092 // fall through to next case 0093 case '>': 0094 // fall through to next case 0095 case '[': 0096 // fall through to next case 0097 case ']': 0098 // fall through to next case 0099 case '{': 0100 // fall through to next case 0101 case '}': 0102 // fall through to next case 0103 case '/': 0104 // fall through to next case 0105 case '%': 0106 // fall through to next case 0107 case '\\': 0108 // fall through to next case 0109 case '#': 0110 $outStr .= sprintf('#%02X', $nextCode); 0111 break; 0112 0113 default: 0114 if ($nextCode >= 33 && $nextCode <= 126 ) { 0115 // Visible ASCII symbol 0116 $outStr .= $inStr[$count]; 0117 } else { 0118 $outStr .= sprintf('#%02X', $nextCode); 0119 } 0120 } 0121 0122 } 0123 0124 return $outStr; 0125 } 0126 0127 0128 /** 0129 * Unescape string according to the PDF rules 0130 * 0131 * @param string $inStr 0132 * @return string 0133 */ 0134 public static function unescape($inStr) 0135 { 0136 $outStr = ''; 0137 0138 for ($count = 0; $count < strlen($inStr); $count++) { 0139 if ($inStr[$count] != '#' ) { 0140 $outStr .= $inStr[$count]; 0141 } else { 0142 // Escape sequence 0143 $outStr .= chr(base_convert(substr($inStr, $count+1, 2), 16, 10 )); 0144 $count +=2; 0145 } 0146 } 0147 return $outStr; 0148 } 0149 0150 0151 /** 0152 * Return object as string 0153 * 0154 * @param Zend_Pdf_Factory $factory 0155 * @return string 0156 */ 0157 public function toString($factory = null) 0158 { 0159 return '/' . self::escape((string)$this->value); 0160 } 0161 }