Pdf/FileParser/Font/OpenType/TrueType.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 [email protected] so we can send you a copy immediately.
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_Pdf
- Subpackage
- FileParser
- Version
- $Id: TrueType.php 24593 2012-01-05 20:35:02Z matthew $
\Zend_Pdf_FileParser_Font_OpenType_TrueType
Parses an OpenType font file containing TrueType outlines.
TrueType was originally developed by Apple and was adopted as the default font format for the Microsoft Windows platform. OpenType is an extension of TrueType, developed jointly by Microsoft and Adobe, which adds support for PostScript font data.
This abstract parser class forms the foundation for concrete subclasses which extract either TrueType or PostScript font data from the file.
All OpenType files use big-endian byte ordering.
The full TrueType and OpenType specifications can be found at:
- Parent(s)
- \Zend_Pdf_FileParser_Font_OpenType < \Zend_Pdf_FileParser_Font < \Zend_Pdf_FileParser
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Constants

BYTE_ORDER_LITTLE_ENDIAN
= 0
Little-endian byte order (0x04 0x03 0x02 0x01).
Inherited from: \Zend_Pdf_FileParser::BYTE_ORDER_LITTLE_ENDIAN\Zend_Pdf_FileParser_Font::BYTE_ORDER_LITTLE_ENDIAN\Zend_Pdf_FileParser_Font_OpenType::BYTE_ORDER_LITTLE_ENDIAN- Inherited_from
- \Zend_Pdf_FileParser::BYTE_ORDER_LITTLE_ENDIAN
- Inherited_from
- \Zend_Pdf_FileParser_Font::BYTE_ORDER_LITTLE_ENDIAN
- Inherited_from
- \Zend_Pdf_FileParser_Font_OpenType::BYTE_ORDER_LITTLE_ENDIAN

BYTE_ORDER_BIG_ENDIAN
= 1
Big-endian byte order (0x01 0x02 0x03 0x04).
Inherited from: \Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN\Zend_Pdf_FileParser_Font::BYTE_ORDER_BIG_ENDIAN\Zend_Pdf_FileParser_Font_OpenType::BYTE_ORDER_BIG_ENDIAN- Inherited_from
- \Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN
- Inherited_from
- \Zend_Pdf_FileParser_Font::BYTE_ORDER_BIG_ENDIAN
- Inherited_from
- \Zend_Pdf_FileParser_Font_OpenType::BYTE_ORDER_BIG_ENDIAN
Properties


\Zend_Pdf_FileParserDataSource $_dataSource = null
Object representing the data source to be parsed.
Inherited from: \Zend_Pdf_FileParser::$$_dataSource\Zend_Pdf_FileParser_Font::$$_dataSource\Zend_Pdf_FileParser_Font_OpenType::$$_dataSourcenull
Details- Type
- \Zend_Pdf_FileParserDataSource
- Inherited_from
- \Zend_Pdf_FileParser::$$_dataSource
- Inherited_from
- \Zend_Pdf_FileParser_Font::$$_dataSource
- Inherited_from
- \Zend_Pdf_FileParser_Font_OpenType::$$_dataSource


boolean $_debug = false
Flag indicating whether or not debug logging is active.
Inherited from: \Zend_Pdf_FileParser_Font::$$_debug\Zend_Pdf_FileParser_Font_OpenType::$$_debugfalse
Details- Type
- boolean
- Inherited_from
- \Zend_Pdf_FileParser_Font::$$_debug
- Inherited_from
- \Zend_Pdf_FileParser_Font_OpenType::$$_debug


array $_fontProperties = array()
Array of parsed font properties.
Inherited from: \Zend_Pdf_FileParser_Font::$$_fontProperties\Zend_Pdf_FileParser_Font_OpenType::$$_fontPropertiesarray()
Details- Type
- array
- Inherited_from
- \Zend_Pdf_FileParser_Font::$$_fontProperties
- Inherited_from
- \Zend_Pdf_FileParser_Font_OpenType::$$_fontProperties


boolean $_isParsed = false
Flag indicating that the file has been sucessfully parsed.
Inherited from: \Zend_Pdf_FileParser::$$_isParsed\Zend_Pdf_FileParser_Font::$$_isParsed\Zend_Pdf_FileParser_Font_OpenType::$$_isParsedfalse
Details- Type
- boolean
- Inherited_from
- \Zend_Pdf_FileParser::$$_isParsed
- Inherited_from
- \Zend_Pdf_FileParser_Font::$$_isParsed
- Inherited_from
- \Zend_Pdf_FileParser_Font_OpenType::$$_isParsed


boolean $_isScreened = false
Flag indicating that the file has passed a cursory validation check.
Inherited from: \Zend_Pdf_FileParser::$$_isScreened\Zend_Pdf_FileParser_Font::$$_isScreened\Zend_Pdf_FileParser_Font_OpenType::$$_isScreenedfalse
Details- Type
- boolean
- Inherited_from
- \Zend_Pdf_FileParser::$$_isScreened
- Inherited_from
- \Zend_Pdf_FileParser_Font::$$_isScreened
- Inherited_from
- \Zend_Pdf_FileParser_Font_OpenType::$$_isScreened


integer $_scalerType = 0
Stores the scaler type (font type) for the font file.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::$$_scalerTypeSee _readScalerType().
0
Details- Type
- integer
- Inherited_from
- \Zend_Pdf_FileParser_Font_OpenType::$$_scalerType


array $_tableDirectory = array()
Stores the byte offsets to the various information tables.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::$$_tableDirectoryarray()
Details- Type
- array
- Inherited_from
- \Zend_Pdf_FileParser_Font_OpenType::$$_tableDirectory
Methods


__construct(\Zend_Pdf_FileParserDataSource $dataSource) : void
Object constructor.
Inherited from: \Zend_Pdf_FileParser_Font::__construct()\Zend_Pdf_FileParser_Font_OpenType::__construct()Validates the data source and enables debug logging if so configured.
Name | Type | Description |
---|---|---|
$dataSource | \Zend_Pdf_FileParserDataSource |
Exception | Description |
---|---|
\Zend_Pdf_Exception |


__destruct() : void
Object destructor.
Inherited from: \Zend_Pdf_FileParser::__destruct()\Zend_Pdf_FileParser_Font::__destruct()\Zend_Pdf_FileParser_Font_OpenType::__destruct()Discards the data source object.


__get(string $property) : mixed
Get handler
Inherited from: \Zend_Pdf_FileParser_Font::__get()\Zend_Pdf_FileParser_Font_OpenType::__get()Name | Type | Description |
---|---|---|
$property | string |
Type | Description |
---|---|
mixed |


__set(string $property, mixed $value) : void
Set handler
Inherited from: \Zend_Pdf_FileParser_Font::__set()\Zend_Pdf_FileParser_Font_OpenType::__set()NOTE: This method is protected. Other classes may freely interrogate the font properties, but only this and its subclasses may set them.
Name | Type | Description |
---|---|---|
$property | string | |
$value | mixed |


_debugLog(string $message) : void
If debug logging is enabled, writes the log message.
Inherited from: \Zend_Pdf_FileParser_Font::_debugLog()\Zend_Pdf_FileParser_Font_OpenType::_debugLog()The log message is a sprintf() style string and any number of arguments may accompany it as additional parameters.
Name | Type | Description |
---|---|---|
$message | string |


_jumpToTable(string $tableName) : void
Validates a given table's existence, then sets the file pointer to the start of that table.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::_jumpToTable()Name | Type | Description |
---|---|---|
$tableName | string |
Exception | Description |
---|---|
\Zend_Pdf_Exception |


_languageCodeForPlatform(integer $platformID, $languageID) : string
Utility method that returns ISO 639 two-letter language codes from the TrueType platform and language ID.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::_languageCodeForPlatform()Returns NULL for languages that are not supported.
Name | Type | Description |
---|---|---|
$platformID | integer | |
$languageID |
Type | Description |
---|---|
string | | null |


_parseCmapTable() : void
Parses the OpenType cmap (Character to Glyph Mapping) table.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::_parseCmapTable()The cmap table provides the maps from character codes to font glyphs. There are usually at least two character maps in a font: Microsoft Unicode and Macintosh Roman. For very complex fonts, there may also be mappings for the characters in the Unicode Surrogates Area, which are UCS-4 characters.
Exception | Description |
---|---|
\Zend_Pdf_Exception |


_parseHeadTable() : void
Parses the OpenType head (Font Header) table.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::_parseHeadTable()The head table contains global information about the font such as the revision number and global metrics.
Exception | Description |
---|---|
\Zend_Pdf_Exception |


_parseHheaTable() : void
Parses the OpenType hhea (Horizontal Header) table.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::_parseHheaTable()The hhea table contains information used for horizontal layout. It also contains some vertical layout information for Apple systems. The vertical layout information for the PDF file is usually taken from the OS/2 table.
Exception | Description |
---|---|
\Zend_Pdf_Exception |


_parseHmtxTable() : void
Parses the OpenType hmtx (Horizontal Metrics) table.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::_parseHmtxTable()The hmtx table contains the horizontal metrics for every glyph contained within the font. These are the critical values for horizontal layout of text.
Exception | Description |
---|---|
\Zend_Pdf_Exception |


_parseMaxpTable() : void
Parses the OpenType hhea (Horizontal Header) table.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::_parseMaxpTable()The hhea table contains information used for horizontal layout. It also contains some vertical layout information for Apple systems. The vertical layout information for the PDF file is usually taken from the OS/2 table.
Exception | Description |
---|---|
\Zend_Pdf_Exception |


_parseNameTable() : void
Parses the OpenType name (Naming) table.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::_parseNameTable()The name table contains all of the identifying strings associated with the font such as its name, copyright, trademark, license, etc.
Exception | Description |
---|---|
\Zend_Pdf_Exception |


_parseOs2Table() : void
Parses the OpenType OS/2 (OS/2 and Windows Metrics) table.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::_parseOs2Table()The OS/2 table contains additional metrics data that is required to use the font on the OS/2 or Microsoft Windows platforms. It is not required for Macintosh fonts, so may not always be present. When available, we use this table to determine most of the vertical layout and stylistic information and for the font.
Exception | Description |
---|---|
\Zend_Pdf_Exception |


_parsePostTable() : void
Parses the OpenType post (PostScript Information) table.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::_parsePostTable()The post table contains additional information required for using the font on PostScript printers. It also contains the preferred location and thickness for an underline, which is used by our layout code.
Exception | Description |
---|---|
\Zend_Pdf_Exception |


_parseTableDirectory() : void
Parses the OpenType table directory.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::_parseTableDirectory()The table directory contains the identifier, checksum, byte offset, and length of each of the information tables housed in the font file.
Exception | Description |
---|---|
\Zend_Pdf_Exception |


_readScalerType() : integer
Reads the scaler type from the header of the OpenType font file and returns it as an unsigned long integer.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::_readScalerType()The scaler type defines the type of font: OpenType font files may contain TrueType or PostScript outlines. Throws an exception if the scaler type is not recognized.
Type | Description |
---|---|
integer |
Exception | Description |
---|---|
\Zend_Pdf_Exception |


_readTableVersion(float $minVersion, $maxVersion) : float
Reads the fixed 16.16 table version number and checks for compatibility.
Inherited from: \Zend_Pdf_FileParser_Font_OpenType::_readTableVersion()If the version is incompatible, throws an exception. If it is compatible, returns the version number.
Name | Type | Description |
---|---|---|
$minVersion | float | Minimum compatible version number. |
$maxVersion |
Type | Description |
---|---|
float | Table version number. |
Exception | Description |
---|---|
\Zend_Pdf_Exception |


getDataSource() : \Zend_Pdf_FileParserDataSource
Returns the data source object representing the file being parsed.
Inherited from: \Zend_Pdf_FileParser::getDataSource()\Zend_Pdf_FileParser_Font::getDataSource()\Zend_Pdf_FileParser_Font_OpenType::getDataSource()Type | Description |
---|---|
\Zend_Pdf_FileParserDataSource |


isBitSet(integer $bit, integer $bitField) : boolean
Returns true if the specified bit is set in the integer bitfield.
Inherited from: \Zend_Pdf_FileParser::isBitSet()\Zend_Pdf_FileParser_Font::isBitSet()\Zend_Pdf_FileParser_Font_OpenType::isBitSet()Name | Type | Description |
---|---|---|
$bit | integer | Bit number to test (i.e. - 0-31) |
$bitField | integer |
Type | Description |
---|---|
boolean |


isParsed() : boolean
Returns true if the file has been successfully parsed.
Inherited from: \Zend_Pdf_FileParser::isParsed()\Zend_Pdf_FileParser_Font::isParsed()\Zend_Pdf_FileParser_Font_OpenType::isParsed()Type | Description |
---|---|
boolean |


isScreened() : boolean
Returns true if the file has passed a cursory validation check.
Inherited from: \Zend_Pdf_FileParser::isScreened()\Zend_Pdf_FileParser_Font::isScreened()\Zend_Pdf_FileParser_Font_OpenType::isScreened()Type | Description |
---|---|
boolean |


moveToOffset(integer $offset) : void
Convenience wrapper for the data source object's moveToOffset() method.
Inherited from: \Zend_Pdf_FileParser::moveToOffset()\Zend_Pdf_FileParser_Font::moveToOffset()\Zend_Pdf_FileParser_Font_OpenType::moveToOffset()Name | Type | Description |
---|---|---|
$offset | integer | Destination byte offset. |
Exception | Description |
---|---|
\Zend_Pdf_Exception |


parse() : void
Reads and parses the TrueType font data from the file on disk.
NOTE: This method should be overridden in subclasses to add type- specific parsing and set $this->isParsed.
Exception | Description |
---|---|
\Zend_Pdf_Exception |


readBytes(integer $byteCount) : string
Convenience wrapper for the data source object's readBytes() method.
Inherited from: \Zend_Pdf_FileParser::readBytes()\Zend_Pdf_FileParser_Font::readBytes()\Zend_Pdf_FileParser_Font_OpenType::readBytes()Name | Type | Description |
---|---|---|
$byteCount | integer | Number of bytes to read. |
Type | Description |
---|---|
string |
Exception | Description |
---|---|
\Zend_Pdf_Exception |


readFixed(integer $mantissaBits, integer $fractionBits, integer $byteOrder = \Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN) : float
Reads the signed fixed-point number from the binary file at the current byte offset.
Inherited from: \Zend_Pdf_FileParser::readFixed()\Zend_Pdf_FileParser_Font::readFixed()\Zend_Pdf_FileParser_Font_OpenType::readFixed()Common fixed-point sizes are 2.14 and 16.16.
Advances the offset by the number of bytes read. Throws an exception if an error occurs.
Name | Type | Description |
---|---|---|
$mantissaBits | integer | Number of bits in the mantissa |
$fractionBits | integer | Number of bits in the fraction |
$byteOrder | integer | (optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in {@link Zend_Pdf_FileParser}. If omitted, uses big-endian. |
Type | Description |
---|---|
float |
Exception | Description |
---|---|
\Zend_Pdf_Exception |


readInt(integer $size, integer $byteOrder = \Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN) : integer
Reads the signed integer value from the binary file at the current byte offset.
Inherited from: \Zend_Pdf_FileParser::readInt()\Zend_Pdf_FileParser_Font::readInt()\Zend_Pdf_FileParser_Font_OpenType::readInt()Advances the offset by the number of bytes read. Throws an exception if an error occurs.
Name | Type | Description |
---|---|---|
$size | integer | Size of integer in bytes: 1-4 |
$byteOrder | integer | (optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in {@link Zend_Pdf_FileParser}. If omitted, uses big-endian. |
Type | Description |
---|---|
integer |
Exception | Description |
---|---|
\Zend_Pdf_Exception |


readStringMacRoman(integer $byteCount, string $characterSet = '') : string
Reads the Mac Roman-encoded string from the binary file at the current offset location.
Inherited from: \Zend_Pdf_FileParser_Font::readStringMacRoman()\Zend_Pdf_FileParser_Font_OpenType::readStringMacRoman()Overridden to fix return character set at UTF-16BE.
Name | Type | Description |
---|---|---|
$byteCount | integer | Number of bytes (characters) to return. |
$characterSet | string | (optional) --Ignored-- |
Type | Description |
---|---|
string |
Exception | Description |
---|---|
\Zend_Pdf_Exception |


readStringPascal(string $characterSet = '', integer $lengthBytes = 1) : string
Reads the Pascal string from the binary file at the current offset location.
Inherited from: \Zend_Pdf_FileParser_Font::readStringPascal()\Zend_Pdf_FileParser_Font_OpenType::readStringPascal()Overridden to fix return character set at UTF-16BE.
Name | Type | Description |
---|---|---|
$characterSet | string | (optional) --Ignored-- |
$lengthBytes | integer | (optional) Number of bytes that make up the length. Default is 1. |
Type | Description |
---|---|
string |
Exception | Description |
---|---|
\Zend_Pdf_Exception |


readStringUTF16(integer $byteCount, integer $byteOrder = \Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN, string $characterSet = '') : string
Reads the Unicode UTF-16-encoded string from the binary file at the current offset location.
Inherited from: \Zend_Pdf_FileParser_Font::readStringUTF16()\Zend_Pdf_FileParser_Font_OpenType::readStringUTF16()Overridden to fix return character set at UTF-16BE.
Name | Type | Description |
---|---|---|
$byteCount | integer | Number of bytes (characters * 2) to return. |
$byteOrder | integer | (optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in {@link Zend_Pdf_FileParser}. If omitted, uses big-endian. |
$characterSet | string | (optional) --Ignored-- |
Type | Description |
---|---|
string |
Exception | Description |
---|---|
\Zend_Pdf_Exception |


readUInt(integer $size, integer $byteOrder = \Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN) : integer
Reads the unsigned integer value from the binary file at the current byte offset.
Inherited from: \Zend_Pdf_FileParser::readUInt()\Zend_Pdf_FileParser_Font::readUInt()\Zend_Pdf_FileParser_Font_OpenType::readUInt()Advances the offset by the number of bytes read. Throws an exception if an error occurs.
NOTE: If you ask for a 4-byte unsigned integer on a 32-bit machine, the resulting value WILL BE SIGNED because PHP uses signed integers internally for everything. To guarantee portability, be sure to use bitwise operators operators on large unsigned integers!
Name | Type | Description |
---|---|---|
$size | integer | Size of integer in bytes: 1-4 |
$byteOrder | integer | (optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in {@link Zend_Pdf_FileParser}. If omitted, uses big-endian. |
Type | Description |
---|---|
integer |
Exception | Description |
---|---|
\Zend_Pdf_Exception |


screen() : void
Verifies that the font file actually contains TrueType outlines.
NOTE: This method should be overridden in subclasses to check the specific format and set $this->_isScreened!
Exception | Description |
---|---|
\Zend_Pdf_Exception |


skipBytes(integer $byteCount) : void
Convenience wrapper for the data source object's skipBytes() method.
Inherited from: \Zend_Pdf_FileParser::skipBytes()\Zend_Pdf_FileParser_Font::skipBytes()\Zend_Pdf_FileParser_Font_OpenType::skipBytes()Name | Type | Description |
---|---|---|
$byteCount | integer | Number of bytes to skip. |
Exception | Description |
---|---|
\Zend_Pdf_Exception |


writeDebug() : void
Writes the entire font properties array to STDOUT.
Inherited from: \Zend_Pdf_FileParser_Font::writeDebug()\Zend_Pdf_FileParser_Font_OpenType::writeDebug()Used only for debugging.