setasign\SetaPDF2\Core\Font\TrueType

Subset Class that represents a PDF TrueType font subset.

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

This class will embedded a subset of the original TrueType font programm with only glyphs, that were requested by calling the getCharCodes() method.

The subset can represent up to 255 glyphs.

Class hierarchy

Implements

Summary

Constants

STATE_FINISHED

public const Subset::STATE_FINISHED = 'finished'

State constant for a finished subset

STATE_NEW

public const Subset::STATE_NEW = 'new'

State constant for a new created subset

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

$_ascent

protected int Subset::$_ascent

The ascent value.

$_charCodes

protected array Subset::$_charCodes = array(...)

Mapping from UTF-16BE characters to glyph ids.

$_chars

protected array Subset::$_chars = array(...)

Mapping from glyph ids to UTF-16BE charcater codes.

$_descent

protected int Subset::$_descent

The descent value.

$_dictionary

The main font dictionary.

$_document

The document instance.

$_factor

protected float Subset::$_factor

The scaling factor from TrueType units to glyph coordinate system.

$_fontBBox

protected int[] Subset::$_fontBBox

The font bounding box.

$_fontFile

The source font file instance.

$_fontName

protected string Subset::$_fontName

The font name.

$_indirectObject

The indirect object for the PDF font object.

$_state

protected string Subset::$_state = 'new'

The state of this subset

$_subsetFile

The instance of the subset class.

$_throwExceptionWhenMissingGlyphIsUsed

Flag saying whether an exception should be thrown if a character is not available or not.

$_widths

protected int[] Subset::$_widths = array()

The widths of the used glyphs.

$maxCharLimit

public int Subset::$maxCharLimit = 256

The char count limit.


Methods

__construct()

public Subset::__construct (
\SetaPDF_Core_Document $document,
\SetaPDF_Core_Font_TrueType_File|string|\SetaPDF_Core_Reader_Binary $fontFile,
bool $throwExceptionWhenMissingGlyphIsUsed = false,
bool $ignoreLicenseRestrictions = false
)

The constructor.

Parameters
$document : \SetaPDF_Core_Document
 
$fontFile : \SetaPDF_Core_Font_TrueType_File|string|\SetaPDF_Core_Reader_Binary
 
$throwExceptionWhenMissingGlyphIsUsed : bool

Whether an exception should be thrown if the registered character cannot be found or not.

$ignoreLicenseRestrictions : bool

Can be used to disable the font license check

Exceptions

Throws \setasign\SetaPDF2\Core\Exception

Throws \setasign\SetaPDF2\Core\Font\Exception

Throws Subset\Exception

Throws \setasign\SetaPDF2\NotImplementedException

_checkState()

protected Subset::_checkState (
void
): void

_getSubsetFile()

Gets the subset file instance.

Exceptions

Throws \setasign\SetaPDF2\Core\Font\Exception

_getToUnicode()

protected Subset::_getToUnicode (
void
): string

Returns the ToUnicode cmap.

_registerChar()

protected Subset::_registerChar (
string $char,
string $charCode
): void

Registers a glyph that got registered in the font subsetter.

Parameters
$char : string
 
$charCode : string
 

cleanUp()

public Subset::cleanUp (
void
): void

Release cycled references and memory.

createSubset()

public Subset::createSubset (
void
): void

Create the final subset file and embed it into the PDF document.

Exceptions

Throws \setasign\SetaPDF2\Core\Font\Exception

Throws \setasign\SetaPDF2\NotImplementedException

getAscent()

public Subset::getAscent (
void
): float

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

Exceptions

Throws \setasign\SetaPDF2\NotImplementedException

getCharCodes()

public Subset::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

Exceptions

Throws \setasign\SetaPDF2\Core\Font\Exception

Throws \setasign\SetaPDF2\NotImplementedException

getDescent()

public Subset::getDescent (
void
): float

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

Exceptions

Throws \setasign\SetaPDF2\NotImplementedException

getDocument()

Get the document instance.

getFontBBox()

public Subset::getFontBBox (
void
): int[]

Get the font bounding box array.

Exceptions

Throws \setasign\SetaPDF2\Core\Font\Exception

Throws \setasign\SetaPDF2\NotImplementedException

getFontDescriptorFlags()

public Subset::getFontDescriptorFlags (
void
): int

Get flags defining various characteristics of the font.

Exceptions

Throws \setasign\SetaPDF2\NotImplementedException

See
  • PDF 32000-1:2008 - 9.8.2 Font Descriptor Flags

getFontFile()

Get the source true type file.

getFontName()

public Subset::getFontName (
void
): string

Get the font name.

Exceptions

Throws \setasign\SetaPDF2\Core\Font\Exception

Throws \setasign\SetaPDF2\NotImplementedException

getGlyphWidth()

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

Get the glyph width of a single character.

Parameters
$char : string

The character

$encoding : string

The encoding of the character

Exceptions

Throws \setasign\SetaPDF2\Core\Font\Exception

Throws \setasign\SetaPDF2\NotImplementedException

getGlyphWidthByCharCode()

public Subset::getGlyphWidthByCharCode (
string $charCode
): int

Get the glyph width by a char code.

Parameters
$charCode : string
 
Exceptions

Throws \setasign\SetaPDF2\Core\Font\Exception

Throws \setasign\SetaPDF2\NotImplementedException

getGlyphsWidth()

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

Get the glyphs width of a string.

Parameters
$chars : string

The string

$encoding : string

The encoding of the characters

Exceptions

Throws \setasign\SetaPDF2\Core\Font\Exception

Throws \setasign\SetaPDF2\NotImplementedException

getIndirectObject()

Get the indirect object of this resource.

Parameters
$document : ?\SetaPDF_Core_Document
 

getRegisteredChars()

public Subset::getRegisteredChars (
void
): array

Get all registered characters (UTF-16BE encoded) indexed by their glyph ids.

getResourceType()

public Subset::getResourceType (
void
): string

Get the resource type of an implementation.

getUnderlinePosition()

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

Get the underline position.

Exceptions

Throws \setasign\SetaPDF2\NotImplementedException

getUnderlineThickness()

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

Get the underline thickness.

Exceptions

Throws \setasign\SetaPDF2\NotImplementedException

splitCharCodes()

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

Split a string of char codes into single char codes.

Parameters
$charCodes : string