SetaPDF_Core_Font_TrueType Class for TrueType fonts

File: /SetaPDF/Core/Font/TrueType.php

Class hierarchy

Implements

Summary

Static Properties

$_fontDescriptors

static protected array SetaPDF_Core_Font_TrueType::$_fontDescriptors = array()

A cache for font descriptor objects.

$_fonts

static protected array SetaPDF_Core_Font_TrueType::$_fonts = array()

An array caching font objects


Properties

$_autoEncoding

protected boolean SetaPDF_Core_Font_TrueType::$_autoEncoding = false

Flag for handling automatic encoding

$_avgWidth

protected integer|float SetaPDF_Core_Font_TrueType::$_avgWidth

The average width of glyphs in the font.

$_charCodeCache

protected array SetaPDF_Core_Font_TrueType::$_charCodeCache = array()

A char code cache which is used in SetaPDF_Core_Font::getCharByCharCode().

$_dictionary

$_encodingTable

The encoding table

$_fontDescriptor

$_glyphsWidthCache

A cache of width values

$_indirectObject

$_info

protected array SetaPDF_Core_Font_TrueType::$_info = array()

Array holding information about the font

$_streamParser

The TTF/OTF parser of the embedded font file.

$_substituteCharacter

The UTF-16BE unicode value for a substitute character

$_tmpEncodingTable

This array is only used if the _autoEncoding property is used.

$_toUnicodeTable

The map that maps character codes to uncidoe values

$_ttfParser

$_widths

Glyph widths

$_widthsByCharCode

Widths by char codes


Static Methods

_createToUnicodeStream()

static protected string SetaPDF_Core_Font_TrueType::_createToUnicodeStream ( array $chars )

Creates a standard /ToUnicode stream for TrueType fonts.

Actually it writes only a single range. Gaps will be closed by the replacement character (U+FFFD).

Parameters
$chars : array
 

create()

static public SetaPDF_Core_Font_TrueType SetaPDF_Core_Font_TrueType::create ( SetaPDF_Core_Document $document, string $fontFile [, string $baseEncoding = \SetaPDF_Core_Encoding::WIN_ANSI [, array|string $diffEncoding = array ( ) [, boolean $embedded = true [, bool $forceLicenseRestrictions = false ]]]] )

Creates a font object based on a TrueType font file.

Parameters
$document : SetaPDF_Core_Document

The document instance in which the font will be used

$fontFile : string

A path to the TTF font file

$baseEncoding : string

The base encoding

$diffEncoding : array|string

A translation table to adjust individual char codes to different glyphs or "auto" to build this table dynamically.

$embedded : boolean

Defines if the font program will be embedded in the document or not

$forceLicenseRestrictions : bool

Could be used to disable the font license check

Return Values

The SetaPDF_Core_Font_TrueType instance

Exceptions

Throws SetaPDF_Core_Font_Exception

freeCache()

static public void SetaPDF_Core_Font::freeCache ( SetaPDF_Core_Document $document )

Release font instances by a document instance.

Parameters
$document : SetaPDF_Core_Document
 

freeFontCache()

static public void SetaPDF_Core_Font::freeFontCache ( SetaPDF_Core_Document $document )

Release font instances by a document instance.

Parameters
$document : SetaPDF_Core_Document
 
See

get()

Get a font object by an indirect reference.

The needed font object class is automatically resolve via the Subtype value of the font dictionary.

Parameters
$indirectObjectOrDictionary : SetaPDF_Core_Type_IndirectObjectInterface
 
Exceptions

Throws SetaPDF_Exception_NotImplemented, SetaPDF_Core_Font_Exception


Methods

__construct()

_getCharCodesTable()

Get the map that maps character codes to unicode values.

_getEncodingTable()

Get the encoding table based on the Encoding dictionary and it's Differences entry (if available).

_getWidths()

protected void SetaPDF_Core_Font_Type1::_getWidths ( void )

Resolves the width values from the font descriptor and fills the $_width-array.

_sortByArray()

protected array SetaPDF_Core_Font_Simple::_sortByArray ( $array $array )

Sorts an array by shifting the array values to the top of the resulting array.

Parameters
$array : $array
 

_updateToUnicodeStream()

A function which will create the current ToUnicode CMap.

getAscent()

public float SetaPDF_Core_Font_Type1::getAscent ( void )

Returns the distance from baseline of highest ascender (Typographic ascent).

getAvgWidth()

public integer|float SetaPDF_Core_Font_Type1::getAvgWidth ( [ boolean $calculateIfUndefined = false ] )

Get the average glyph width.

Parameters
$calculateIfUndefined : boolean
 

getBaseEncodingTable()

Get the base encoding for a TrueType font.

See PDF 32000-1:2008 - 9.6.6.4 Encodings for TrueType Fonts: "[...]A nonsymbolic font should specify MacRomanEncoding or WinAnsiEncoding as the value of its Encoding entry, with no Differences array[...]"

getCharByCharCode()

public string SetaPDF_Core_Font::getCharByCharCode ( string $charCode [, string $encoding = 'UTF-8' ] )

Converts a char code from the font specific encoding to another encoding.

Parameters
$charCode : string

The char code in the font specific encoding.

$encoding : string

The resulting encoding

getCharCode()

public string SetaPDF_Core_Font_TrueType::getCharCode ( string $char [, string $encoding = 'UTF-16BE' ] )

Get the final character code of a single character.

If the font is based on a TTF file and the $diffEncoding is set to 'auto' this method will build the differences from the encoding automatically. It will simply recreate a completely new encoding starting at 0.

Parameters
$char : string

The character

$encoding : string
 
Exceptions

Throws SetaPDF_Core_Font_Exception

getCharCodes()

public array SetaPDF_Core_Font::getCharCodes ( string $chars [, string $encoding = 'UTF-16BE' ] )

Get the final character codes of a character string.

Parameters
$chars : string

The character string

$encoding : string

The output encoding

getCharsByCharCodes()

public string|array SetaPDF_Core_Font::getCharsByCharCodes ( string $charCodes [, string $encoding = 'UTF-8' [, bool $asArray = true ]] )

Converts char codes from the font specific encoding to another encoding.

Parameters
$charCodes : string

The char codes in the font specific encoding.

$encoding : string

The resulting encoding

$asArray : bool
 

getDescent()

public float SetaPDF_Core_Font_Type1::getDescent ( void )

Returns the distance from baseline of lowest descender (Typographic descent).

getDictionary()

Get the font dictionary.

getFontBBox()

public array SetaPDF_Core_Font_TrueType::getFontBBox ( [ boolean $recalc = false ] )

Returns the font bounding box.

Parameters
$recalc : boolean

Set to true, to re-calculate the font bounding box by analysing the metrics of all embedded glyphs.

getFontDescriptor()

Get the font descriptor object.

getFontFamily()

public string SetaPDF_Core_Font_Type1::getFontFamily ( void )

Get the font family.

getFontName()

public string SetaPDF_Core_Font_Type1::getFontName ( void )

Get the font name.

getGlyphWidth()

public float|int SetaPDF_Core_Font_TrueType::getGlyphWidth ( string $char [, string $encoding = 'UTF-16BE' ] )

Get the glyph width.

This method is a proxy method if the width-array is not initialized and the font is build from a TTF font.

Parameters
$char : string
 
$encoding : string

The input encoding

See

getGlyphWidthByCharCode()

public float|int SetaPDF_Core_Font_Type1::getGlyphWidthByCharCode ( string $charCode )

Get the width of a glpyh by its char code.

Parameters
$charCode : string
 

getGlyphsWidth()

public float|int SetaPDF_Core_Font::getGlyphsWidth ( string $chars [, string $encoding = 'UTF-16BE' ] )

Get the width of the glyphs/characters.

Parameters
$chars : string

The characters

$encoding : string

The input encoding

getGlyphsWidthByCharCodes()

public float|int SetaPDF_Core_Font::getGlyphsWidthByCharCodes ( string $charCodes )

Get the width of glyphs by their char codes.

Parameters
$charCodes : string
 

getIndirectObject()

getInfo()

public bool|string SetaPDF_Core_Font::getInfo ( string $name )

Get information about the font.

Parameters
$name : string

The name of the font

getItalicAngle()

Returns the italic angle.

getMaxWidth()

public integer|float SetaPDF_Core_Font_Type1::getMaxWidth ( void )

Get the max glyph width.

getMissingWidth()

public integer|float SetaPDF_Core_Font_Type1::getMissingWidth ( void )

Get the missing glyph width.

getResourceType()

public string SetaPDF_Core_Font::getResourceType ( void )

Get the resource type.

See

getStreamParser()

Get the TTF/OTF parser for the embedded font programm.

getType()

public mixed SetaPDF_Core_Font::getType ( void )

Get the Subtype entry of the font dictionary.

isBold()

public boolean SetaPDF_Core_Font_Type1::isBold ( void )

Checks if the font is bold.

isItalic()

public boolean SetaPDF_Core_Font_Type1::isItalic ( void )

Checks if the font is italic.

isMonospace()

public boolean SetaPDF_Core_Font_Type1::isMonospace ( void )

Checks if the font is monospace.

splitCharCodes()

public array SetaPDF_Core_Font::splitCharCodes ( string $charCodes )

Split a string of char codes into single char codes.

Parameters
$charCodes : string
 

updateAutoEncoding()

A callback function which will update font data before it is written to the final PDF file.

This method should not be called manually. It is registered as a callback of the font object, which was created in the create()-method.