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
- DescriptorInterface
- FontInterface
- Glyph\Collection\CollectionInterface
- \setasign\SetaPDF2\Core\Resource\ResourceInterface
Summary
Methods
- __construct()
- _ensureUnderlinePosition()
- _ensureUnderlineThickness()
- _getCharCodesTable()
- _getEncodingTable()
- _getWidths()
- _updateToUnicodeStream()
- getAscent()
- getAvgWidth()
- getBaseEncodingTable()
- getCharByCharCode()
- getCharCode()
- getCharCodes()
- getCharsByCharCodes()
- getDescent()
- getDictionary()
- getFontBBox()
- getFontBBoxVector()
- getFontDescriptor()
- getFontFamily()
- getFontName()
- getGlyphWidth()
- getGlyphWidthByCharCode()
- getGlyphsWidth()
- getIndirectObject()
- getInfo()
- getItalicAngle()
- getMaxWidth()
- getMissingWidth()
- getResourceType()
- getStreamParser()
- getType()
- getUnderlinePosition()
- getUnderlineThickness()
- isBold()
- isItalic()
- isMonospace()
- recalculateFontBBox()
- setUnderlinePosition()
- setUnderlineThickness()
- splitCharCodes()
- updateAutoEncoding()
Properties
- $_autoEncoding
- $_avgWidth
- $_calculatedFontBBox
- $_charCodeCache
- $_dictionary
- $_encodingTable
- $_fontBBox
- $_fontBBoxVector
- $_fontDescriptor
- $_indirectObject
- $_info
- $_streamParser
- $_substituteCharacter
- $_tmpEncodingTable
- $_toUnicodeTable
- $_ttfParser
- $_underlinePosition
- $_underlineThickness
- $_widths
- $_widthsByCharCode
Constants
INFO_COPYRIGHT
Info constant
INFO_CREATION_DATE
Info constant
INFO_UNIQUE_ID
Info constant
INFO_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
$_avgWidth
The average width of glyphs in the font.
$_calculatedFontBBox
$_charCodeCache
A char code cache which is used in Font::getCharByCharCode().
$_dictionary
The font dictionary
$_encodingTable
The encoding table
$_fontBBox
The font bounding box
$_fontDescriptor
The font descriptor object
$_substituteCharacter
The UTF-16BE unicode value for a substitute character
$_tmpEncodingTable
A temporary encoding table holding used character codes
This array is only used if the _autoEncoding property is used.
$_toUnicodeTable
The map that maps character codes to uncidoe values
$_ttfParser
The TTF/OTF parser
$_underlinePosition
The relative underline positioning.
$_underlineThickness
The underline thickness.
$_widthsByCharCode
Widths by char codes
Static Methods
_createToUnicodeStream()
Creates the /ToUnicode stream for this TrueType font.
Parameters
- $chars : array
create()
string $fontFile,
string $baseEncoding = \setasign\SetaPDF2\Core\Encoding\Encoding::WIN_ANSI,
array|string $diffEncoding = array ( ),
bool $embedded = true,
bool $ignoreLicenseRestrictions = 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 : 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
freeCache()
WARNING: This method is marked as deprecated!
Call \setasign\SetaPDF2\Core\Document::clearCache() with the type \setasign\SetaPDF2\Core\Document::CACHE_FONT instead.
Release font instances by a document instance.
Parameters
- $document : \SetaPDF_Core_Document
freeFontCache()
WARNING: This method is marked as deprecated!
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
Methods
__construct()
The constructor.
Parameters
- $indirectObjectOrDictionary : \SetaPDF_Core_Type_IndirectObjectInterface|\SetaPDF_Core_Type_Dictionary
Exceptions
Throws Exception
_ensureUnderlinePosition()
_ensureUnderlineThickness()
_getCharCodesTable()
_getEncodingTable()
Get the encoding table based on the Encoding dictionary and it's Differences entry (if available).
_getWidths()
Resolves the width values from the font descriptor and fills the $_width-array.
Exceptions
Throws \setasign\SetaPDF2\Core\Type\Exception
Throws Exception
getAvgWidth()
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[...]"
Exceptions
Throws Exception
getCharByCharCode()
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()
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
getCharCodes()
Get the final character codes of a character string.
Parameters
- $chars : string
The character string
- $encoding : string
The output encoding
getCharsByCharCodes()
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()
Returns the distance from baseline of lowest descender (Typographic descent).
Exceptions
Throws Exception
getFontBBoxVector()
Get a font bounding box vector.
Parameters
- $name : int
- $fontSize : float
Exceptions
getGlyphWidth()
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()
getGlyphsWidth()
Get the width of the glyphs/characters.
Parameters
- $chars : string
The characters
- $encoding : string
The input encoding
getIndirectObject()
Gets an indirect object for this font.
Parameters
- $document : ?\SetaPDF_Core_Document
Exceptions
Throws \InvalidArgumentException
See
getMissingWidth()
recalculateFontBBox()
Return Values
Format is [llx lly urx ury]. Returns false if the font isn't recalculatable
Exceptions
Throws Exception
setUnderlinePosition()
Sets the underline position for the current font.
Parameters
- $position : int|float
setUnderlineThickness()
Sets the underline thickness for the current font.
Parameters
- $thickness : int|float
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.