PageRenderTime 58ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/DevApp/library/Zend/Pdf/FileParser/Font.php

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