📄 byteencoding.php
字号:
<?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. * * @package Zend_Pdf * @subpackage Fonts * @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_Cmap */require_once 'Zend/Pdf/Cmap.php';/** * Implements the "byte encoding" character map (type 0). * * This is the (legacy) Apple standard encoding mechanism and provides coverage * for characters in the Mac Roman character set only. Consequently, this cmap * type should be used only as a last resort. * * The mapping from Mac Roman to Unicode can be found at * {@link http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/ROMAN.TXT}. * * @package Zend_Pdf * @subpackage Fonts * @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_Cmap_ByteEncoding extends Zend_Pdf_Cmap{ /**** Instance Variables ****/ /** * Glyph index array. Stores the actual glyph numbers. The array keys are * the translated Unicode code points. * @var array */ protected $_glyphIndexArray = array(); /**** Public Interface ****/ /* Concrete Class Implementation */ /** * Returns an array of glyph numbers corresponding to the Unicode characters. * * If a particular character doesn't exist in this font, the special 'missing * character glyph' will be substituted. * * See also {@link glyphNumberForCharacter()}. * * @param array $characterCodes Array of Unicode character codes (code points). * @return array Array of glyph numbers. */ public function glyphNumbersForCharacters($characterCodes) { $glyphNumbers = array(); foreach ($characterCodes as $key => $characterCode) { if (! isset($this->_glyphIndexArray[$characterCode])) { $glyphNumbers[$key] = Zend_Pdf_Cmap::MISSING_CHARACTER_GLYPH; continue; } $glyphNumbers[$key] = $this->_glyphIndexArray[$characterCode]; } return $glyphNumbers; } /** * Returns the glyph number corresponding to the Unicode character. * * If a particular character doesn't exist in this font, the special 'missing * character glyph' will be substituted. * * See also {@link glyphNumbersForCharacters()} which is optimized for bulk * operations. * * @param integer $characterCode Unicode character code (code point). * @return integer Glyph number. */ public function glyphNumberForCharacter($characterCode) { if (! isset($this->_glyphIndexArray[$characterCode])) { return Zend_Pdf_Cmap::MISSING_CHARACTER_GLYPH; } return $this->_glyphIndexArray[$characterCode]; } /** * Returns an array containing the Unicode characters that have entries in * this character map. * * @return array Unicode character codes. */ public function getCoveredCharacters() { return array_keys($this->_glyphIndexArray); } /**
* Returns an array containing the glyphs numbers that have entries in this character map.
* Keys are Unicode character codes (integers)
*
* This functionality is partially covered by glyphNumbersForCharacters(getCoveredCharacters())
* call, but this method do it in more effective way (prepare complete list instead of searching
* glyph for each character code).
*
* @internal
* @return array Array representing <Unicode character code> => <glyph number> pairs.
*/
public function getCoveredCharactersGlyphs()
{
return $this->_glyphIndexArray;
}
/* Object Lifecycle */ /** * Object constructor * * Parses the raw binary table data. Throws an exception if the table is * malformed. * * @param string $cmapData Raw binary cmap table data. * @throws Zend_Pdf_Exception */ public function __construct($cmapData) { /* Sanity check: This table must be exactly 262 bytes long. */ $actualLength = strlen($cmapData); if ($actualLength != 262) { throw new Zend_Pdf_Exception('Insufficient table data', Zend_Pdf_Exception::CMAP_TABLE_DATA_TOO_SMALL); } /* Sanity check: Make sure this is right data for this table type. */ $type = $this->_extractUInt2($cmapData, 0); if ($type != Zend_Pdf_Cmap::TYPE_BYTE_ENCODING) { throw new Zend_Pdf_Exception('Wrong cmap table type', Zend_Pdf_Exception::CMAP_WRONG_TABLE_TYPE); } $length = $this->_extractUInt2($cmapData, 2); if ($length != $actualLength) { throw new Zend_Pdf_Exception("Table length ($length) does not match actual length ($actualLength)", Zend_Pdf_Exception::CMAP_WRONG_TABLE_LENGTH); } /* Mapping tables should be language-independent. The font may not work * as expected if they are not. Unfortunately, many font files in the * wild incorrectly record a language ID in this field, so we can't * call this a failure. */ $language = $this->_extractUInt2($cmapData, 4); if ($language != 0) { // Record a warning here somehow? } /* The mapping between the Mac Roman and Unicode characters is static. * For simplicity, just put all 256 glyph indices into one array keyed * off the corresponding Unicode character. */ $i = 6; $this->_glyphIndexArray[0x00] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x01] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x02] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x03] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x04] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x05] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x06] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x07] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x08] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x09] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x0a] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x0b] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x0c] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x0d] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x0e] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x0f] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x10] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x11] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x12] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x13] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x14] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x15] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x16] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x17] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x18] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x19] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x1a] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x1b] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x1c] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x1d] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x1e] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x1f] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x20] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x21] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x22] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x23] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x24] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x25] = ord($cmapData[$i++]); $this->_glyphIndexArray[0x26] = ord($cmapData[$i++]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -