You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
6.0 KiB

11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
  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. * @subpackage FileParser
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /** Internally used classes */
  23. // require_once 'Zend/Pdf/Font.php';
  24. /** Zend_Pdf_FileParser */
  25. // require_once 'Zend/Pdf/FileParser.php';
  26. /**
  27. * Abstract helper class for {@link Zend_Pdf_Font} that parses font files.
  28. *
  29. * Defines the public interface for concrete subclasses which are responsible
  30. * for parsing the raw binary data from the font file on disk. Also provides
  31. * a debug logging interface and a couple of shared utility methods.
  32. *
  33. * @package Zend_Pdf
  34. * @subpackage FileParser
  35. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. */
  38. abstract class Zend_Pdf_FileParser_Font extends Zend_Pdf_FileParser
  39. {
  40. /**** Instance Variables ****/
  41. /**
  42. * Array of parsed font properties. Used with {@link __get()} and
  43. * {@link __set()}.
  44. * @var array
  45. */
  46. private $_fontProperties = array();
  47. /**
  48. * Flag indicating whether or not debug logging is active.
  49. * @var boolean
  50. */
  51. private $_debug = false;
  52. /**** Public Interface ****/
  53. /* Object Lifecycle */
  54. /**
  55. * Object constructor.
  56. *
  57. * Validates the data source and enables debug logging if so configured.
  58. *
  59. * @param Zend_Pdf_FileParserDataSource $dataSource
  60. * @throws Zend_Pdf_Exception
  61. */
  62. public function __construct(Zend_Pdf_FileParserDataSource $dataSource)
  63. {
  64. parent::__construct($dataSource);
  65. $this->fontType = Zend_Pdf_Font::TYPE_UNKNOWN;
  66. }
  67. /* Accessors */
  68. /**
  69. * Get handler
  70. *
  71. * @param string $property
  72. * @return mixed
  73. */
  74. public function __get($property)
  75. {
  76. if (isset($this->_fontProperties[$property])) {
  77. return $this->_fontProperties[$property];
  78. } else {
  79. return null;
  80. }
  81. }
  82. /* NOTE: The set handler is defined below in the internal methods group. */
  83. /* Parser Methods */
  84. /**
  85. * Reads the Unicode UTF-16-encoded string from the binary file at the
  86. * current offset location. Overridden to fix return character set at UTF-16BE.
  87. *
  88. * @todo Deal with to-dos in the parent method.
  89. *
  90. * @param integer $byteCount Number of bytes (characters * 2) to return.
  91. * @param integer $byteOrder (optional) Big- or little-endian byte order.
  92. * Use the BYTE_ORDER_ constants defined in {@link Zend_Pdf_FileParser}. If
  93. * omitted, uses big-endian.
  94. * @param string $characterSet (optional) --Ignored--
  95. * @return string
  96. * @throws Zend_Pdf_Exception
  97. */
  98. public function readStringUTF16($byteCount,
  99. $byteOrder = Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN,
  100. $characterSet = '')
  101. {
  102. return parent::readStringUTF16($byteCount, $byteOrder, 'UTF-16BE');
  103. }
  104. /**
  105. * Reads the Mac Roman-encoded string from the binary file at the current
  106. * offset location. Overridden to fix return character set at UTF-16BE.
  107. *
  108. * @param integer $byteCount Number of bytes (characters) to return.
  109. * @param string $characterSet (optional) --Ignored--
  110. * @return string
  111. * @throws Zend_Pdf_Exception
  112. */
  113. public function readStringMacRoman($byteCount, $characterSet = '')
  114. {
  115. return parent::readStringMacRoman($byteCount, 'UTF-16BE');
  116. }
  117. /**
  118. * Reads the Pascal string from the binary file at the current offset
  119. * location. Overridden to fix return character set at UTF-16BE.
  120. *
  121. * @param string $characterSet (optional) --Ignored--
  122. * @param integer $lengthBytes (optional) Number of bytes that make up the
  123. * length. Default is 1.
  124. * @return string
  125. * @throws Zend_Pdf_Exception
  126. */
  127. public function readStringPascal($characterSet = '', $lengthBytes = 1)
  128. {
  129. return parent::readStringPascal('UTF-16BE');
  130. }
  131. /* Utility Methods */
  132. /**
  133. * Writes the entire font properties array to STDOUT. Used only for debugging.
  134. */
  135. public function writeDebug()
  136. {
  137. print_r($this->_fontProperties);
  138. }
  139. /**** Internal Methods ****/
  140. /* Internal Accessors */
  141. /**
  142. * Set handler
  143. *
  144. * NOTE: This method is protected. Other classes may freely interrogate
  145. * the font properties, but only this and its subclasses may set them.
  146. *
  147. * @param string $property
  148. * @param mixed $value
  149. */
  150. public function __set($property, $value)
  151. {
  152. if ($value === null) {
  153. unset($this->_fontProperties[$property]);
  154. } else {
  155. $this->_fontProperties[$property] = $value;
  156. }
  157. }
  158. /* Internal Utility Methods */
  159. /**
  160. * If debug logging is enabled, writes the log message.
  161. *
  162. * The log message is a sprintf() style string and any number of arguments
  163. * may accompany it as additional parameters.
  164. *
  165. * @param string $message
  166. * @param mixed (optional, multiple) Additional arguments
  167. */
  168. protected function _debugLog($message)
  169. {
  170. if (! $this->_debug) {
  171. return;
  172. }
  173. if (func_num_args() > 1) {
  174. $args = func_get_args();
  175. $message = array_shift($args);
  176. $message = vsprintf($message, $args);
  177. }
  178. // require_once 'Zend/Log.php';
  179. $logger = new Zend_Log();
  180. $logger->log($message, Zend_Log::DEBUG);
  181. }
  182. }