Abstract base class for OpenType font file parsers.

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:

  • [http://developer.apple.com/textfonts/TTRefMan/](http://developer.apple.com/textfonts/TTRefMan/)
  • [http://www.microsoft.com/typography/OTSPEC/](http://www.microsoft.com/typography/OTSPEC/)
  • [http://partners.adobe.com/public/developer/opentype/index_spec.html](http://partners.adobe.com/public/developer/opentype/index_spec.html)
package Zend_Pdf
subpackage FileParser
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License
inherited_from \Zend_Pdf_FileParser_Font

 Methods

Object constructor.

__construct(\Zend_Pdf_FileParserDataSource $dataSource) 
Inherited

Verifies that the data source has been properly initialized.

Parameters

$dataSource

\Zend_Pdf_FileParserDataSource

Exceptions

\Zend_Pdf_Exception

Object destructor.

__destruct() 
Inherited

Discards the data source object.

Get handler

__get(string $property) : mixed
Inherited

Parameters

$property

string

Returns

mixed

Set handler

__set(string $property, mixed $value) 
Inherited

NOTE: This method is protected. Other classes may freely interrogate the font properties, but only this and its subclasses may set them.

Parameters

$property

string

$value

mixed

Returns the data source object representing the file being parsed.

getDataSource() : \Zend_Pdf_FileParserDataSource
Inherited

Returns

\Zend_Pdf_FileParserDataSource

getOffset()

getOffset() 
Inherited

getSize()

getSize() 
Inherited

Returns true if the specified bit is set in the integer bitfield.

isBitSet(integer $bit, integer $bitField) : boolean
Inherited

Parameters

$bit

integer

Bit number to test (i.e. - 0-31)

$bitField

integer

Returns

boolean

Returns true if the file has been successfully parsed.

isParsed() : boolean
Inherited

Returns

boolean

Returns true if the file has passed a cursory validation check.

isScreened() : boolean
Inherited

Returns

boolean

Convenience wrapper for the data source object's moveToOffset() method.

moveToOffset(integer $offset) 
Inherited

Parameters

$offset

integer

Destination byte offset.

Exceptions

\Zend_Pdf_Exception

Reads and parses the font data from the file on disk.

parse() 

NOTE: This method should be overridden in subclasses to add type- specific parsing and set $this->isParsed.

Exceptions

\Zend_Pdf_Exception

Reads and parses the complete binary file.

parse() 
Inherited

Must set $this->_isParsed to true if successful.

Exceptions

\Zend_Pdf_Exception

Convenience wrapper for the data source object's readBytes() method.

readBytes(integer $byteCount) : string
Inherited

Parameters

$byteCount

integer

Number of bytes to read.

Exceptions

\Zend_Pdf_Exception

Returns

string

Reads the signed fixed-point number from the binary file at the current byte offset.

readFixed(integer $mantissaBits, integer $fractionBits, integer $byteOrder = \Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN) : float
Inherited

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.

Parameters

$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 BYTEORDER constants defined in {@link Zend_Pdf_FileParser}. If omitted, uses big-endian.

Exceptions

\Zend_Pdf_Exception

Returns

float

Reads the signed integer value from the binary file at the current byte offset.

readInt(integer $size, integer $byteOrder = \Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN) : integer
Inherited

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

Parameters

$size

integer

Size of integer in bytes: 1-4

$byteOrder

integer

(optional) Big- or little-endian byte order. Use the BYTEORDER constants defined in {@link Zend_Pdf_FileParser}. If omitted, uses big-endian.

Exceptions

\Zend_Pdf_Exception

Returns

integer

Reads the Mac Roman-encoded string from the binary file at the current byte offset.

readStringMacRoman(integer $byteCount, string $characterSet = '') : string
Inherited

You must supply the desired resulting character set.

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

Parameters

$byteCount

integer

Number of bytes (characters) to return.

$characterSet

string

(optional) Desired resulting character set. You may use any character set supported by {@link iconv()}. If omitted, uses 'current locale'.

Exceptions

\Zend_Pdf_Exception

Returns

string

Reads the Pascal string from the binary file at the current byte offset.

readStringPascal(string $characterSet = '', integer $lengthBytes = 1) : string
Inherited

The length of the Pascal string is determined by reading the length bytes which preceed the character data. You must supply the desired resulting character set.

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

Parameters

$characterSet

string

(optional) Desired resulting character set. You may use any character set supported by {@link iconv()}. If omitted, uses 'current locale'.

$lengthBytes

integer

(optional) Number of bytes that make up the length. Default is 1.

Exceptions

\Zend_Pdf_Exception

Returns

string

Reads the Unicode UTF-16-encoded string from the binary file at the current byte offset.

readStringUTF16(integer $byteCount, integer $byteOrder = \Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN, string $characterSet = '') : string
Inherited

The byte order of the UTF-16 string must be specified. You must also supply the desired resulting character set.

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

todo Consider changing $byteCount to a character count. They are not always equivalent (in the case of surrogates).
todo Make $byteOrder optional if there is a byte-order mark (BOM) in the string being extracted.

Parameters

$byteCount

integer

Number of bytes (characters * 2) to return.

$byteOrder

integer

(optional) Big- or little-endian byte order. Use the BYTEORDER constants defined in {@link Zend_Pdf_FileParser}. If omitted, uses big-endian.

$characterSet

string

(optional) Desired resulting character set. You may use any character set supported by {@link iconv()}. If omitted, uses 'current locale'.

Exceptions

\Zend_Pdf_Exception

Returns

string

Reads the unsigned integer value from the binary file at the current byte offset.

readUInt(integer $size, integer $byteOrder = \Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN) : integer
Inherited

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!

Parameters

$size

integer

Size of integer in bytes: 1-4

$byteOrder

integer

(optional) Big- or little-endian byte order. Use the BYTEORDER constants defined in {@link Zend_Pdf_FileParser}. If omitted, uses big-endian.

Exceptions

\Zend_Pdf_Exception

Returns

integer

Verifies that the font file is in the expected format.

screen() 

NOTE: This method should be overridden in subclasses to check the specific format and set $this->_isScreened!

Exceptions

\Zend_Pdf_Exception

Performs a cursory check to verify that the binary file is in the expected format. Intended to quickly weed out obviously bogus files.

screen() 
Inherited

Must set $this->_isScreened to true if successful.

Exceptions

\Zend_Pdf_Exception

Convenience wrapper for the data source object's skipBytes() method.

skipBytes(integer $byteCount) 
Inherited

Parameters

$byteCount

integer

Number of bytes to skip.

Exceptions

\Zend_Pdf_Exception

Writes the entire font properties array to STDOUT. Used only for debugging.

writeDebug() 
Inherited

If debug logging is enabled, writes the log message.

_debugLog(string $message) 
Inherited

The log message is a sprintf() style string and any number of arguments may accompany it as additional parameters.

Parameters

$message

string

Validates a given table's existence, then sets the file pointer to the start of that table.

_jumpToTable(string $tableName) 

Parameters

$tableName

string

Exceptions

\Zend_Pdf_Exception

Utility method that returns ISO 639 two-letter language codes from the TrueType platform and language ID. Returns NULL for languages that are not supported.

_languageCodeForPlatform(integer $platformID, $languageID) : string

Parameters

$platformID

integer

$languageID

Returns

string| null

Parses the OpenType cmap (Character to Glyph Mapping) table.

_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.

todo Need to rework the selection logic for picking a subtable. We should have an explicit list of preferences, followed by a list of those that are tolerable. Most specifically, since everything above this layer deals in Unicode, we need to be sure to only accept format 0 MacRoman tables.

Exceptions

\Zend_Pdf_Exception

Parses the OpenType head (Font Header) table.

_parseHeadTable() 

The head table contains global information about the font such as the revision number and global metrics.

Exceptions

\Zend_Pdf_Exception

Parses the OpenType hhea (Horizontal Header) table.

_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.

Exceptions

\Zend_Pdf_Exception

Parses the OpenType hmtx (Horizontal Metrics) table.

_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.

Exceptions

\Zend_Pdf_Exception

Parses the OpenType hhea (Horizontal Header) table.

_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.

Exceptions

\Zend_Pdf_Exception

Parses the OpenType name (Naming) table.

_parseNameTable() 

The name table contains all of the identifying strings associated with the font such as its name, copyright, trademark, license, etc.

Exceptions

\Zend_Pdf_Exception

Parses the OpenType OS/2 (OS/2 and Windows Metrics) table.

_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.

Exceptions

\Zend_Pdf_Exception

Parses the OpenType post (PostScript Information) table.

_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.

Exceptions

\Zend_Pdf_Exception

Parses the OpenType table directory.

_parseTableDirectory() 

The table directory contains the identifier, checksum, byte offset, and length of each of the information tables housed in the font file.

Exceptions

\Zend_Pdf_Exception

Reads the scaler type from the header of the OpenType font file and returns it as an unsigned long integer.

_readScalerType() : integer

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.

Exceptions

\Zend_Pdf_Exception

Returns

integer

Reads the fixed 16.16 table version number and checks for compatibility.

_readTableVersion(float $minVersion, $maxVersion) : float

If the version is incompatible, throws an exception. If it is compatible, returns the version number.

Parameters

$minVersion

float

Minimum compatible version number.

$maxVersion

Exceptions

\Zend_Pdf_Exception

Returns

floatTable version number.

 Properties

 

Object representing the data source to be parsed.

$_dataSource : \Zend_Pdf_FileParserDataSource

Default

null
 

Flag indicating that the file has been sucessfully parsed.

$_isParsed : boolean

Default

false
 

Flag indicating that the file has passed a cursory validation check.

$_isScreened : boolean

Default

false
 

Stores the scaler type (font type) for the font file. See {@link _readScalerType()}.

$_scalerType : integer

Default

0
 

Stores the byte offsets to the various information tables.

$_tableDirectory : array

Default

array()
 

Flag indicating whether or not debug logging is active.

$_debug : boolean

Default

false
 

Array of parsed font properties. Used with {@link __get()} and {@link __set()}.

$_fontProperties : array

Default

array()

 Constants

 

Big-endian byte order (0x01 0x02 0x03 0x04).

BYTE_ORDER_BIG_ENDIAN = 1 
 

Little-endian byte order (0x04 0x03 0x02 0x01).

BYTE_ORDER_LITTLE_ENDIAN = 0