setasign\SetaPDF2\Core\Font

TrueType Class for TrueType fonts

File: /SetaPDF v2/Core/Font/TrueType.php
Old class name (alias): \SetaPDF_Core_Font_TrueType

Class hierarchy

Implements

Summary

Constants

INFO_COPYRIGHT

public const string Font::INFO_COPYRIGHT = 'copyright'

Info constant

INFO_CREATION_DATE

public const string Font::INFO_CREATION_DATE = 'creationDate'

Info constant

INFO_UNIQUE_ID

public const string Font::INFO_UNIQUE_ID = 'uniqueId'

Info constant

INFO_VERSION

public const string Font::INFO_VERSION = 'version'

Info constant

TYPE_COLOR_SPACE

Type constant

TYPE_EXT_G_STATE

Type constant

TYPE_FONT

Type constant

TYPE_PATTERN

Type constant

TYPE_PROC_SET

Type constant

TYPE_PROPERTIES

Type constant

TYPE_SHADING

Type constant

TYPE_X_OBJECT

Type constant


Properties

$_autoEncoding

protected bool TrueType::$_autoEncoding = false

Flag for handling automatic encoding

$_avgWidth

protected int|float Simple::$_avgWidth

The average width of glyphs in the font.

$_calculatedFontBBox

protected array TrueType::$_calculatedFontBBox

$_charCodeCache

protected array Font::$_charCodeCache = array()

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

$_dictionary

The font dictionary

$_encodingTable

protected array Simple::$_encodingTable

The encoding table

$_fontBBox

protected ?array Type1::$_fontBBox

The font bounding box

$_fontBBoxVector

protected array<string, \SetaPDF_Core_Geometry_Point> Font::$_fontBBoxVector = array()

$_fontDescriptor

The font descriptor object

$_indirectObject

The indirect object of the font

$_info

protected array Font::$_info = array()

Array holding information about the font

$_streamParser

The TTF/OTF parser of the embedded font file.

$_substituteCharacter

protected ?string Type1::$_substituteCharacter

The UTF-16BE unicode value for a substitute character

$_tmpEncodingTable

protected array TrueType::$_tmpEncodingTable = array()

A temporary encoding table holding used character codes

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

$_toUnicodeTable

protected array Simple::$_toUnicodeTable

The map that maps character codes to uncidoe values

$_ttfParser

The TTF/OTF parser

$_underlinePosition

protected null|int|float Font::$_underlinePosition

The relative underline positioning.

$_underlineThickness

protected null|int|float Font::$_underlineThickness

The underline thickness.

$_widths

protected ?array Type1::$_widths

Glyph widths

$_widthsByCharCode

protected array Font::$_widthsByCharCode

Widths by char codes


Static Methods

_createToUnicodeStream()

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

Creates the /ToUnicode stream for this TrueType font.

Parameters
$chars : array
 

create()

public static TrueType::create (
\SetaPDF_Core_Document $document,
string $fontFile,
string $baseEncoding = \setasign\SetaPDF2\Core\Encoding\Encoding::WIN_ANSI,
array|string $diffEncoding = array ( ),
bool $embedded = true,
bool $ignoreLicenseRestrictions = false
): \SetaPDF_Core_Font_TrueType

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 : bool

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

$ignoreLicenseRestrictions : bool

Can be used to disable the font license check

Return Values

The TrueType instance

Exceptions

Throws Exception

Throws \setasign\SetaPDF2\NotImplementedException

Throws \setasign\SetaPDF2\Core\Exception

freeCache()

WARNING: This method is marked as deprecated!

Call \setasign\SetaPDF2\Core\Document::clearCache() with the type \setasign\SetaPDF2\Core\Document::CACHE_FONT instead.

public static Font::freeCache (): void

Release font instances by a document instance.

Parameters
$document : \SetaPDF_Core_Document
 

freeFontCache()

WARNING: This method is marked as deprecated!

public static Font::freeFontCache (): void

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|\SetaPDF_Core_Type_Dictionary
 
Exceptions

Throws \setasign\SetaPDF2\NotImplementedException

Throws Exception

Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception


Methods

__construct()

_ensureUnderlinePosition()

protected TrueType::_ensureUnderlinePosition (
void
): int|float

Calculates the underline position.

Exceptions

Throws \setasign\SetaPDF2\Core\Exception

Throws \setasign\SetaPDF2\NotImplementedException

_ensureUnderlineThickness()

protected TrueType::_ensureUnderlineThickness (
void
): float|int

Calculates the underline thickness.

Exceptions

Throws \setasign\SetaPDF2\NotImplementedException

Throws \setasign\SetaPDF2\Core\Exception

_getCharCodesTable()

protected Simple::_getCharCodesTable (
void
): \SetaPDF_Core_Font_Cmap|array|false

Get the map that maps character codes to unicode values.

Exceptions

Throws Exception

_getEncodingTable()

protected Simple::_getEncodingTable (
void
): array

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

_getWidths()

protected Type1::_getWidths (
void
): void

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

Exceptions

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws Exception

_updateToUnicodeStream()

protected TrueType::_updateToUnicodeStream (
void
): void

A function which will create the current ToUnicode CMap.

Exceptions

Throws \setasign\SetaPDF2\Core\Type\Exception

getAscent()

public Type1::getAscent (
void
): float

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

Exceptions

Throws Exception

getAvgWidth()

public Type1::getAvgWidth (
bool $calculateIfUndefined = false
): int|float

Get the average glyph width.

Parameters
$calculateIfUndefined : bool
 
Exceptions

Throws Exception

getBaseEncodingTable()

public TrueType::getBaseEncodingTable (
void
): array

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[...]"

Exceptions

Throws Exception

getCharByCharCode()

public TrueType::getCharByCharCode (
string $charCode,
string $encoding = 'UTF-8'
): string

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

Exceptions

Throws Exception

getCharCode()

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

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 Exception

Throws \setasign\SetaPDF2\NotImplementedException

Throws \setasign\SetaPDF2\Core\Type\Exception

getCharCodes()

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

Get the final character codes of a character string.

Parameters
$chars : string

The character string

$encoding : string

The output encoding

getCharsByCharCodes()

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

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 Type1::getDescent (
void
): float

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

Exceptions

Throws Exception

getDictionary()

Get the font dictionary.

getFontBBox()

public Type1::getFontBBox (
void
): array

Returns the font bounding box.

getFontBBoxVector()

public Font::getFontBBoxVector (
int $name,
float $fontSize
): \SetaPDF_Core_Geometry_Vector

Get a font bounding box vector.

Parameters
$name : int
 
$fontSize : float
 
Exceptions

Throws \setasign\SetaPDF2\Core\Exception

getFontDescriptor()

Get the font descriptor object.

getFontFamily()

public Type1::getFontFamily (
void
): string

Get the font family.

Exceptions

Throws Exception

getFontName()

public Type1::getFontName (
void
): string

Get the font name.

getGlyphWidth()

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

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

Exceptions

Throws Exception

Throws \setasign\SetaPDF2\NotImplementedException,\setasign\SetaPDF2\Core\Type\Exception

See

getGlyphWidthByCharCode()

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

Get the width of a glpyh by its char code.

Parameters
$charCode : string
 
Exceptions

Throws Exception

Throws \setasign\SetaPDF2\NotImplementedException

getGlyphsWidth()

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

Get the width of the glyphs/characters.

Parameters
$chars : string

The characters

$encoding : string

The input encoding

getIndirectObject()

getInfo()

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

Get information about the font.

Parameters
$name : string

The name of the font

getItalicAngle()

public Type1::getItalicAngle (
void
): float

Returns the italic angle.

Exceptions

Throws Exception

getMaxWidth()

public Type1::getMaxWidth (
void
): int|float

Get the max glyph width.

Exceptions

Throws Exception

getMissingWidth()

public Type1::getMissingWidth (
void
): int|float

Get the missing glyph width.

Exceptions

Throws Exception

getResourceType()

getStreamParser()

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

Exceptions

Throws \setasign\SetaPDF2\Core\Exception

getType()

public Font::getType (
void
): string

Get the Subtype entry of the font dictionary.

Exceptions

Throws \setasign\SetaPDF2\Core\Type\Exception

getUnderlinePosition()

public Font::getUnderlinePosition (
void
): int|float

Get the underline position.

getUnderlineThickness()

public Font::getUnderlineThickness (
void
): int|float

Get the underline thickness.

isBold()

public Type1::isBold (
void
): bool

Checks if the font is bold.

Exceptions

Throws Exception

isItalic()

public Type1::isItalic (
void
): bool

Checks if the font is italic.

Exceptions

Throws Exception

isMonospace()

public Type1::isMonospace (
void
): bool

Checks if the font is monospace.

Exceptions

Throws Exception

recalculateFontBBox()

public TrueType::recalculateFontBBox (
void
): false|array
Return Values

Format is [llx lly urx ury]. Returns false if the font isn't recalculatable

Exceptions

Throws Exception

Throws \setasign\SetaPDF2\NotImplementedException

Throws \setasign\SetaPDF2\Core\Exception

setUnderlinePosition()

public Font::setUnderlinePosition (
int|float $position
): void

Sets the underline position for the current font.

Parameters
$position : int|float
 

setUnderlineThickness()

public Font::setUnderlineThickness (
int|float $thickness
): void

Sets the underline thickness for the current font.

Parameters
$thickness : int|float
 

splitCharCodes()

public Font::splitCharCodes (
string $charCodes
): array

Split a string of char codes into single char codes.

Parameters
$charCodes : string
 

updateAutoEncoding()

public TrueType::updateAutoEncoding (
void
): void

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.

Exceptions

Throws \setasign\SetaPDF2\Core\Type\Exception