7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
17 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id: Binary.php 16541 2009-07-07 06:59:03Z bkarwin $
23 /** Zend_Pdf_Element_String */
24 require_once 'Zend/Pdf/Element/String.php';
28 * PDF file 'binary string' element implementation
32 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
33 * @license http://framework.zend.com/license/new-bsd New BSD License
35 class Zend_Pdf_Element_String_Binary
extends Zend_Pdf_Element_String
46 * Escape string according to the PDF rules
48 * @param string $inStr
51 public static function escape($inStr)
55 for ($count = 0; $count < strlen($inStr); $count++
) {
56 $outStr .= sprintf('%02X', ord($inStr[$count]));
63 * Unescape string according to the PDF rules
65 * @param string $inStr
68 public static function unescape($inStr)
73 for ($count = 0; $count < strlen($inStr); $count++
) {
74 $nextCharCode = ord($inStr[$count]);
76 if( ($nextCharCode >= 48 /*'0'*/ &&
77 $nextCharCode <= 57 /*'9'*/ ) ||
78 ($nextCharCode >= 97 /*'a'*/ &&
79 $nextCharCode <= 102 /*'f'*/ ) ||
80 ($nextCharCode >= 65 /*'A'*/ &&
81 $nextCharCode <= 70 /*'F'*/ ) ) {
82 $nextHexCode .= $inStr[$count];
85 if (strlen($nextHexCode) == 2) {
86 $outStr .= chr(intval($nextHexCode, 16));
91 if ($nextHexCode != '') {
92 // We have odd number of digits.
93 // Final digit is assumed to be '0'
94 $outStr .= chr(base_convert($nextHexCode . '0', 16, 10));
102 * Return object as string
104 * @param Zend_Pdf_Factory $factory
107 public function toString($factory = null)
109 return '<' . self
::escape((string)$this->value
) . '>';