File indexing completed on 2025-01-19 05:21:21
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Pdf 0017 * @subpackage FileParser 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** Internally used classes */ 0024 // require_once 'Zend/Pdf/Font.php'; 0025 0026 0027 /** Zend_Pdf_FileParser */ 0028 // require_once 'Zend/Pdf/FileParser.php'; 0029 0030 /** 0031 * Abstract helper class for {@link Zend_Pdf_Font} that parses font files. 0032 * 0033 * Defines the public interface for concrete subclasses which are responsible 0034 * for parsing the raw binary data from the font file on disk. Also provides 0035 * a debug logging interface and a couple of shared utility methods. 0036 * 0037 * @package Zend_Pdf 0038 * @subpackage FileParser 0039 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0040 * @license http://framework.zend.com/license/new-bsd New BSD License 0041 */ 0042 abstract class Zend_Pdf_FileParser_Font extends Zend_Pdf_FileParser 0043 { 0044 /**** Instance Variables ****/ 0045 0046 0047 /** 0048 * Array of parsed font properties. Used with {@link __get()} and 0049 * {@link __set()}. 0050 * @var array 0051 */ 0052 private $_fontProperties = array(); 0053 0054 /** 0055 * Flag indicating whether or not debug logging is active. 0056 * @var boolean 0057 */ 0058 private $_debug = false; 0059 0060 0061 0062 /**** Public Interface ****/ 0063 0064 0065 /* Object Lifecycle */ 0066 0067 /** 0068 * Object constructor. 0069 * 0070 * Validates the data source and enables debug logging if so configured. 0071 * 0072 * @param Zend_Pdf_FileParserDataSource $dataSource 0073 * @throws Zend_Pdf_Exception 0074 */ 0075 public function __construct(Zend_Pdf_FileParserDataSource $dataSource) 0076 { 0077 parent::__construct($dataSource); 0078 $this->fontType = Zend_Pdf_Font::TYPE_UNKNOWN; 0079 } 0080 0081 0082 /* Accessors */ 0083 0084 /** 0085 * Get handler 0086 * 0087 * @param string $property 0088 * @return mixed 0089 */ 0090 public function __get($property) 0091 { 0092 if (isset($this->_fontProperties[$property])) { 0093 return $this->_fontProperties[$property]; 0094 } else { 0095 return null; 0096 } 0097 } 0098 0099 /* NOTE: The set handler is defined below in the internal methods group. */ 0100 0101 0102 /* Parser Methods */ 0103 0104 /** 0105 * Reads the Unicode UTF-16-encoded string from the binary file at the 0106 * current offset location. Overridden to fix return character set at UTF-16BE. 0107 * 0108 * @todo Deal with to-dos in the parent method. 0109 * 0110 * @param integer $byteCount Number of bytes (characters * 2) to return. 0111 * @param integer $byteOrder (optional) Big- or little-endian byte order. 0112 * Use the BYTE_ORDER_ constants defined in {@link Zend_Pdf_FileParser}. If 0113 * omitted, uses big-endian. 0114 * @param string $characterSet (optional) --Ignored-- 0115 * @return string 0116 * @throws Zend_Pdf_Exception 0117 */ 0118 public function readStringUTF16($byteCount, 0119 $byteOrder = Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN, 0120 $characterSet = '') 0121 { 0122 return parent::readStringUTF16($byteCount, $byteOrder, 'UTF-16BE'); 0123 } 0124 0125 /** 0126 * Reads the Mac Roman-encoded string from the binary file at the current 0127 * offset location. Overridden to fix return character set at UTF-16BE. 0128 * 0129 * @param integer $byteCount Number of bytes (characters) to return. 0130 * @param string $characterSet (optional) --Ignored-- 0131 * @return string 0132 * @throws Zend_Pdf_Exception 0133 */ 0134 public function readStringMacRoman($byteCount, $characterSet = '') 0135 { 0136 return parent::readStringMacRoman($byteCount, 'UTF-16BE'); 0137 } 0138 0139 /** 0140 * Reads the Pascal string from the binary file at the current offset 0141 * location. Overridden to fix return character set at UTF-16BE. 0142 * 0143 * @param string $characterSet (optional) --Ignored-- 0144 * @param integer $lengthBytes (optional) Number of bytes that make up the 0145 * length. Default is 1. 0146 * @return string 0147 * @throws Zend_Pdf_Exception 0148 */ 0149 public function readStringPascal($characterSet = '', $lengthBytes = 1) 0150 { 0151 return parent::readStringPascal('UTF-16BE'); 0152 } 0153 0154 0155 /* Utility Methods */ 0156 0157 /** 0158 * Writes the entire font properties array to STDOUT. Used only for debugging. 0159 */ 0160 public function writeDebug() 0161 { 0162 print_r($this->_fontProperties); 0163 } 0164 0165 0166 0167 /**** Internal Methods ****/ 0168 0169 0170 /* Internal Accessors */ 0171 0172 /** 0173 * Set handler 0174 * 0175 * NOTE: This method is protected. Other classes may freely interrogate 0176 * the font properties, but only this and its subclasses may set them. 0177 * 0178 * @param string $property 0179 * @param mixed $value 0180 */ 0181 public function __set($property, $value) 0182 { 0183 if ($value === null) { 0184 unset($this->_fontProperties[$property]); 0185 } else { 0186 $this->_fontProperties[$property] = $value; 0187 } 0188 } 0189 0190 0191 /* Internal Utility Methods */ 0192 0193 /** 0194 * If debug logging is enabled, writes the log message. 0195 * 0196 * The log message is a sprintf() style string and any number of arguments 0197 * may accompany it as additional parameters. 0198 * 0199 * @param string $message 0200 * @param mixed (optional, multiple) Additional arguments 0201 */ 0202 protected function _debugLog($message) 0203 { 0204 if (! $this->_debug) { 0205 return; 0206 } 0207 if (func_num_args() > 1) { 0208 $args = func_get_args(); 0209 $message = array_shift($args); 0210 $message = vsprintf($message, $args); 0211 } 0212 0213 // require_once 'Zend/Log.php'; 0214 $logger = new Zend_Log(); 0215 $logger->log($message, Zend_Log::DEBUG); 0216 } 0217 }