PageRenderTime 849ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Pdf/Element/String/Binary.php

https://bitbucket.org/baruffaldi/website-2008-computer-shopping-3
PHP | 110 lines | 42 code | 16 blank | 52 comment | 7 complexity | 62dfaf03aea537f0d2ec3471d16c4f09 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  15. * @category Zend
  16. * @package Zend_Pdf
  17. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. /** Zend_Pdf_Element_String */
  21. require_once 'Zend/Pdf/Element/String.php';
  22. /**
  23. * PDF file 'binary string' element implementation
  24. *
  25. * @category Zend
  26. * @package Zend_Pdf
  27. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. */
  30. class Zend_Pdf_Element_String_Binary extends Zend_Pdf_Element_String
  31. {
  32. /**
  33. * Object value
  34. *
  35. * @var string
  36. */
  37. public $value;
  38. /**
  39. * Escape string according to the PDF rules
  40. *
  41. * @param string $inStr
  42. * @return string
  43. */
  44. public static function escape($inStr)
  45. {
  46. $outStr = '';
  47. for ($count = 0; $count < strlen($inStr); $count++) {
  48. $outStr .= sprintf('%02X', ord($inStr[$count]));
  49. }
  50. return $outStr;
  51. }
  52. /**
  53. * Unescape string according to the PDF rules
  54. *
  55. * @param string $inStr
  56. * @return string
  57. */
  58. public static function unescape($inStr)
  59. {
  60. $outStr = '';
  61. $nextHexCode = '';
  62. for ($count = 0; $count < strlen($inStr); $count++) {
  63. $nextCharCode = ord($inStr[$count]);
  64. if( ($nextCharCode >= 48 /*'0'*/ &&
  65. $nextCharCode <= 57 /*'9'*/ ) ||
  66. ($nextCharCode >= 97 /*'a'*/ &&
  67. $nextCharCode <= 102 /*'f'*/ ) ||
  68. ($nextCharCode >= 65 /*'A'*/ &&
  69. $nextCharCode <= 70 /*'F'*/ ) ) {
  70. $nextHexCode .= $inStr[$count];
  71. }
  72. if (strlen($nextHexCode) == 2) {
  73. $outStr .= chr(intval($nextHexCode, 16));
  74. $nextHexCode = '';
  75. }
  76. }
  77. if ($nextHexCode != '') {
  78. // We have odd number of digits.
  79. // Final digit is assumed to be '0'
  80. $outStr .= chr(base_convert($nextHexCode . '0', 16, 10));
  81. }
  82. return $outStr;
  83. }
  84. /**
  85. * Return object as string
  86. *
  87. * @param Zend_Pdf_Factory $factory
  88. * @return string
  89. */
  90. public function toString($factory = null)
  91. {
  92. return '<' . self::escape((string)$this->value) . '>';
  93. }
  94. }