API Documentation

Pdf/FileParser/Font/OpenType.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.

category
Zend  
copyright
Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)  
license
New BSD License  
package
Zend_Pdf  
subpackage
FileParser  
version
$Id: OpenType.php 23775 2011-03-01 17:25:24Z ralph $  

\Zend_Pdf_FileParser_Font_OpenType

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:

  • {@link http://developer.apple.com/textfonts/TTRefMan/}
  • {@link http://www.microsoft.com/typography/OTSPEC/}
  • {@link http://partners.adobe.com/public/developer/opentype/index_spec.html}
Extends from
\Zend_Pdf_FileParser_Font
copyright
Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)  
license
New BSD License  
package
Zend_Pdf  
subpackage
FileParser  

Properties

Propertyprotectedinteger  $_scalerType= '0'

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

Default value0Details
Type
integer
Propertyprotectedarray  $_tableDirectory= 'array'

Stores the byte offsets to the various information tables.

Default valuearrayDetails
Type
array

Methods

methodpublic__construct( \Zend_Pdf_FileParserDataSource $dataSource ) : void

Object constructor.

Inherited from: \Zend_Pdf_FileParser_Font::__construct()

Validates the data source and enables debug logging if so configured.

Parameters
Name Type Description
$dataSource \Zend_Pdf_FileParserDataSource
Throws
Exception Description
\Zend_Pdf_Exception
methodpublic__destruct( ) : void

Object destructor.

Inherited from: \Zend_Pdf_FileParser::__destruct()

Discards the data source object.

methodpublic__get( string $property ) : mixed

Get handler

Inherited from: \Zend_Pdf_FileParser_Font::__get()
Parameters
Name Type Description
$property string
Returns
Type Description
mixed
methodpublic__set( string $property, mixed $value ) : void

Set handler

Inherited from: \Zend_Pdf_FileParser_Font::__set()

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

Parameters
Name Type Description
$property string
$value mixed
methodprotected_debugLog( string $message ) : void

If debug logging is enabled, writes the log message.

Inherited from: \Zend_Pdf_FileParser_Font::_debugLog()

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

Parameters
Name Type Description
$message string
methodprotected_jumpToTable( string $tableName ) : void

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

Parameters
Name Type Description
$tableName string
Throws
Exception Description
\Zend_Pdf_Exception
methodprotected_languageCodeForPlatform( integer $platformID,  $languageID ) : string

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.

Parameters
Name Type Description
$platformID integer
$languageID
Returns
Type Description
string | null
methodprotected_parseCmapTable( ) : void

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

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.

Throws
Exception Description
\Zend_Pdf_Exception
Details
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.  
methodprotected_parseHeadTable( ) : void

Parses the OpenType head (Font Header) table.

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

Throws
Exception Description
\Zend_Pdf_Exception
methodprotected_parseHheaTable( ) : void

Parses the OpenType hhea (Horizontal Header) table.

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.

Throws
Exception Description
\Zend_Pdf_Exception
methodprotected_parseHmtxTable( ) : void

Parses the OpenType hmtx (Horizontal Metrics) table.

The hmtx table contains the horizontal metrics for every glyph contained within the font. These are the critical values for horizontal layout of text.

Throws
Exception Description
\Zend_Pdf_Exception
methodprotected_parseMaxpTable( ) : void

Parses the OpenType hhea (Horizontal Header) table.

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.

Throws
Exception Description
\Zend_Pdf_Exception
methodprotected_parseNameTable( ) : void

Parses the OpenType name (Naming) table.

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

Throws
Exception Description
\Zend_Pdf_Exception
methodprotected_parseOs2Table( ) : void

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

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.

Throws
Exception Description
\Zend_Pdf_Exception
methodprotected_parsePostTable( ) : void

Parses the OpenType post (PostScript Information) table.

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.

Throws
Exception Description
\Zend_Pdf_Exception
methodprotected_parseTableDirectory( ) : void

Parses the OpenType table directory.

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

Throws
Exception Description
\Zend_Pdf_Exception
methodprotected_readScalerType( ) : integer

Reads the scaler type from the header of the OpenType font file and returns it as an unsigned long 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.

Returns
Type Description
integer
Throws
Exception Description
\Zend_Pdf_Exception
methodprotected_readTableVersion( float $minVersion,  $maxVersion ) : float

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

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

Parameters
Name Type Description
$minVersion float Minimum compatible version number.
$maxVersion
Returns
Type Description
float Table version number.
Throws
Exception Description
\Zend_Pdf_Exception
methodpublicgetDataSource( ) : \Zend_Pdf_FileParserDataSource

Returns the data source object representing the file being parsed.

Inherited from: \Zend_Pdf_FileParser::getDataSource()
Returns
Type Description
\Zend_Pdf_FileParserDataSource
methodpublicgetOffset( ) : void
methodpublicgetSize( ) : void
methodpublicisBitSet( integer $bit, integer $bitField ) : boolean

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

Inherited from: \Zend_Pdf_FileParser::isBitSet()
Parameters
Name Type Description
$bit integer

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

$bitField integer
Returns
Type Description
boolean
methodpublicisParsed( ) : boolean

Returns true if the file has been successfully parsed.

Inherited from: \Zend_Pdf_FileParser::isParsed()
Returns
Type Description
boolean
methodpublicisScreened( ) : boolean

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

Inherited from: \Zend_Pdf_FileParser::isScreened()
Returns
Type Description
boolean
methodpublicmoveToOffset( integer $offset ) : void

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

Inherited from: \Zend_Pdf_FileParser::moveToOffset()
Parameters
Name Type Description
$offset integer Destination byte offset.
Throws
Exception Description
\Zend_Pdf_Exception
methodpublicparse( ) : void

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

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

Throws
Exception Description
\Zend_Pdf_Exception
methodpublicreadBytes( integer $byteCount ) : string

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

Inherited from: \Zend_Pdf_FileParser::readBytes()
Parameters
Name Type Description
$byteCount integer Number of bytes to read.
Returns
Type Description
string
Throws
Exception Description
\Zend_Pdf_Exception
methodpublicreadFixed( integer $mantissaBits, integer $fractionBits, integer $byteOrder = Zend_Pdf_FileParser ) : float

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

Inherited from: \Zend_Pdf_FileParser::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.

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

Returns
Type Description
float
Throws
Exception Description
\Zend_Pdf_Exception
methodpublicreadInt( integer $size, integer $byteOrder = Zend_Pdf_FileParser ) : integer

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

Inherited from: \Zend_Pdf_FileParser::readInt()

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

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

Returns
Type Description
integer
Throws
Exception Description
\Zend_Pdf_Exception
methodpublicreadStringMacRoman( integer $byteCount, string $characterSet ) : string

Reads the Mac Roman-encoded string from the binary file at the current offset location. Overridden to fix return character set at UTF-16BE.

Inherited from: \Zend_Pdf_FileParser_Font::readStringMacRoman()

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
Name Type Description
$byteCount integer

Number of bytes (characters) to return.

$characterSet string

(optional) --Ignored--

Returns
Type Description
string
Throws
Exception Description
\Zend_Pdf_Exception
methodpublicreadStringPascal( string $characterSet, integer $lengthBytes = 1 ) : string

Reads the Pascal string from the binary file at the current offset location. Overridden to fix return character set at UTF-16BE.

Inherited from: \Zend_Pdf_FileParser_Font::readStringPascal()

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
Name Type Description
$characterSet string

(optional) --Ignored--

$lengthBytes integer

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

Returns
Type Description
string
Throws
Exception Description
\Zend_Pdf_Exception
methodpublicreadStringUTF16( integer $byteCount, integer $byteOrder = Zend_Pdf_FileParser, string $characterSet ) : string

Reads the Unicode UTF-16-encoded string from the binary file at the current offset location. Overridden to fix return character set at UTF-16BE.

Inherited from: \Zend_Pdf_FileParser_Font::readStringUTF16()

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.

Parameters
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--

Returns
Type Description
string
Throws
Exception Description
\Zend_Pdf_Exception
Details
todo
Deal with to-dos in the parent method.  
methodpublicreadUInt( integer $size, integer $byteOrder = Zend_Pdf_FileParser ) : integer

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

Inherited from: \Zend_Pdf_FileParser::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!

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

Returns
Type Description
integer
Throws
Exception Description
\Zend_Pdf_Exception
methodpublicscreen( ) : void

Verifies that the font file is in the expected format.

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

Throws
Exception Description
\Zend_Pdf_Exception
methodpublicskipBytes( integer $byteCount ) : void

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

Inherited from: \Zend_Pdf_FileParser::skipBytes()
Parameters
Name Type Description
$byteCount integer Number of bytes to skip.
Throws
Exception Description
\Zend_Pdf_Exception
methodpublicwriteDebug( ) : void

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

Inherited from: \Zend_Pdf_FileParser_Font::writeDebug()
Documentation was generated by DocBlox 0.13.3.