*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Pdf / Element / String / Binary.php
blobe1c08b540df4da0d3b34f84139f28e3887acc79d
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_Pdf
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';
27 /**
28 * PDF file 'binary string' element implementation
30 * @category Zend
31 * @package Zend_Pdf
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
37 /**
38 * Object value
40 * @var string
42 public $value;
45 /**
46 * Escape string according to the PDF rules
48 * @param string $inStr
49 * @return string
51 public static function escape($inStr)
53 $outStr = '';
55 for ($count = 0; $count < strlen($inStr); $count++) {
56 $outStr .= sprintf('%02X', ord($inStr[$count]));
58 return $outStr;
62 /**
63 * Unescape string according to the PDF rules
65 * @param string $inStr
66 * @return string
68 public static function unescape($inStr)
70 $outStr = '';
71 $nextHexCode = '';
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));
87 $nextHexCode = '';
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));
97 return $outStr;
102 * Return object as string
104 * @param Zend_Pdf_Factory $factory
105 * @return string
107 public function toString($factory = null)
109 return '<' . self::escape((string)$this->value) . '>';