website-2008-computer-shopping-3 /library/Zend/Pdf/Element/String/Binary.php

Language PHP Lines 111
MD5 Hash 62dfaf03aea537f0d2ec3471d16c4f09 Estimated Cost $944 (why?)
Repository https://bitbucket.org/baruffaldi/website-2008-computer-shopping-3.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
<?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */


/** 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-2008 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)
    {
        $outStr = '';

        for ($count = 0; $count < strlen($inStr); $count++) {
            $outStr .= sprintf('%02X', ord($inStr[$count]));
        }
        return $outStr;
    }


    /**
     * Unescape string according to the PDF rules
     *
     * @param string $inStr
     * @return string
     */
    public static function unescape($inStr)
    {
        $outStr = '';
        $nextHexCode = '';

        for ($count = 0; $count < strlen($inStr); $count++) {
            $nextCharCode = ord($inStr[$count]);

            if( ($nextCharCode >= 48  /*'0'*/ &&
                 $nextCharCode <= 57  /*'9'*/   ) ||
                ($nextCharCode >= 97  /*'a'*/ &&
                 $nextCharCode <= 102 /*'f'*/   ) ||
                ($nextCharCode >= 65  /*'A'*/ &&
                 $nextCharCode <= 70  /*'F'*/   ) ) {
                $nextHexCode .= $inStr[$count];
            }

            if (strlen($nextHexCode) == 2) {
                $outStr .= chr(intval($nextHexCode, 16));
                $nextHexCode = '';
            }
        }

        if ($nextHexCode != '') {
            // We have odd number of digits.
            // Final digit is assumed to be '0'
            $outStr .= chr(base_convert($nextHexCode . '0', 16, 10));
        }

        return $outStr;
    }


    /**
     * Return object as string
     *
     * @param Zend_Pdf_Factory $factory
     * @return string
     */
    public function toString($factory = null)
    {
        return '<' . self::escape((string)$this->value) . '>';
    }
}
Back to Top