Table of contents
Namespace: Com\Tecnick\Pdf\Font
Extends: Buffer
File: Stack.php line 108
Tags
- since: 2011-05-23
- category: Library
- author: Nicola Asuni info@tecnick.com
- copyright: 2011-2026 Nicola Asuni - Tecnick.com LTD
- license: https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
- link: https://github.com/tecnickcom/tc-lib-pdf-font
- phpstan-import-type: TFontData from Load
- phpstan-type: TTextSplit array{ ‘pos’: int, ‘ord’: int, ‘spaces’: int, ‘septype’: string, ‘wordwidth’: float, ’totwidth’: float, ’totspacewidth’: float, }
- phpstan-type: TTextDims array{ ‘chars’: int, ‘spaces’: int, ‘words’: int, ’totwidth’: float, ’totspacewidth’: float, ‘split’: array<int, TTextSplit>, }
- phpstan-type: TBBox array{float, float, float, float} The ‘fakestyle’ member holds the part of ‘style’ the font does not provide and that the caller synthesizes when it draws the text. See Buffer::addFont().
- phpstan-type: TStackItem array{ ‘key’: string, ‘style’: string, ‘fakestyle’: string, ‘size’: float, ‘spacing’: float, ‘stretching’: float, } The ‘ascent’, ‘descent’ and ‘height’ members measure the line box of the text and are not the ‘/Ascent’ and ‘/Descent’ of the font descriptor. See getFontMetric().
- phpstan-type: TFontMetric array{ ‘ascent’: float, ‘avgwidth’: float, ‘capheight’: float, ‘cbbox’: array<int, TBBox>, ‘cbboxu’: array<int, TBBox>, ‘cratio’: float, ‘cw’: array<int, float>, ‘cwu’: array<int, float>, ‘descent’: float, ‘dw’: float, ‘fakestyle’: string, ‘fbbox’: array<int, float>, ‘height’: float, ‘idx’: int, ‘key’: string, ‘maxwidth’: float, ‘midpoint’: float, ‘missingwidth’: float, ‘out’: string, ‘outraw’: string, ‘size’: float, ‘spacing’: float, ‘stretching’: float, ‘style’: string, ’type’: string, ‘up’: float, ‘usize’: float, ‘ut’: float, ‘xheight’: float, }
- SuppressWarnings: (“PHPMD.ExcessiveClassComplexity”)
Constants
DEFAULT_SIZE
File: Stack.php line 113
public mixed DEFAULT_SIZE = 10
Methods
__construct()
File: Buffer.php line 127
public __construct(float $kunit[, bool $subset = false ][, bool $unicode = true ][, bool $pdfa = false ][, File|null $fileHelper = null ]) : mixed
Parameters
- $kunit : float: Unit of measure conversion ratio.
- $subset : bool = false: If true, embed only the characters used by the document. Valid only for TrueTypeUnicode fonts. Subsetting is computational and memory intensive.
- $unicode : bool = true: True if we are in Unicode mode, False otherwise.
- $pdfa : bool = false: True if we are in PDF/A mode, False otherwise.
- $fileHelper : File|null = null: Optional file helper for font loading.
Tags
- throws: Exception if the unit ratio is not a positive number.
add()
File: Buffer.php line 337
public add(int &$objnum, string $font[, string $style = '' ][, string $ifile = '' ][, bool|null $subset = null ]) : string
The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by K_PATH_FONTS if the constant is defined.
Parameters
- $objnum : int: Current PDF object number
- $font : string: Font family. If it is a standard family name, it will override the corresponding font.
- $style : string = ‘’: Font style. Possible values are (case-insensitive): regular (default) B: bold I: italic U: underline D: strikeout (linethrough) O: overline
- $ifile : string = ‘’: The font definition file (or empty for autodetect). By default, the name is built from the family and style, in lower case with no spaces.
- $subset : bool|null = null: If true, embed only the characters used by the document. Valid only for TrueTypeUnicode fonts. Set to null to use the default value. Subsetting is computational and memory intensive.
Tags
- throws: Exception in case of error
Return values
string —
Font key
addFont()
File: Buffer.php line 369
public addFont(int &$objnum, string $font[, string $style = '' ][, string $ifile = '' ][, bool|null $subset = null ]) : array{key: string, style: string, fakestyle: string}
A family that ships no definition file for the requested variation is loaded from the file of its base family and buffered under the base key, so the same glyph program is neither held nor embedded twice. The variation is then reported as synthetic and is painted by the caller when it draws the text.
Parameters
- $objnum : int: Current PDF object number
- $font : string: Font family.
- $style : string = ‘’: Font style (see add()).
- $ifile : string = ‘’: The font definition file (or empty for autodetect).
- $subset : bool|null = null: If true, embed only the characters used by the document.
Tags
- throws: Exception in case of error
Return values
array{key: string, style: string, fakestyle: string} —
Font key, requested style, and the part of it the font does not provide (’’, ‘B’, ‘I’ or ‘BI’).
addSubsetChar()
File: Buffer.php line 206
public addSubsetChar(string $key, int $char) : void
Parameters
- $key : string: The font key
- $char : int: The Unicode character value to add
Tags
- throws: Exception
addUsedGid()
File: Buffer.php line 294
public addUsedGid(string $key, int $gid, int $ord) : void
The first codepoint mapped to a glyph is the one stored for it.
Parameters
- $key : string: The font key
- $gid : int: The glyph index, in the 0..65535 range
- $ord : int: The Unicode codepoint the glyph was selected for
Tags
- throws: Exception if the font is not loaded, or the glyph index is out of range
cloneFont()
File: Stack.php line 272
public cloneFont(int &$objnum[, int|null $idx = null ][, string|null $style = null ][, float|null $size = null ][, float|null $spacing = null ][, float|null $stretching = null ]) : TFontMetric
Parameters
- $objnum : int: Current PDF object number.
- $idx : int|null = null: Font index. Leave it null to use the current font.
- $style : string|null = null: Font style. Possible values are (case-insensitive): regular (default) B: bold I: italic U: underline D: strikeout (linethrough) O: overline
- $size : float|null = null: Font size in points (set to null to inherit the last font size).
- $spacing : float|null = null: Extra spacing between characters.
- $stretching : float|null = null: Horizontal character stretching ratio.
Tags
- throws: Exception
Return values
TFontMetric
getCharBBox()
File: Stack.php line 695
public getCharBBox(int $ord) : TBBox
Parameters
- $ord : int: Unicode character value.
Tags
- throws: Exception
Return values
TBBox —
(xMin, yMin, xMax, yMax)
getCharWidth()
File: Stack.php line 585
public getCharWidth(int $ord) : float
Parameters
- $ord : int: Unicode character value.
Tags
- throws: Exception
Return values
float
getCurrentFont()
File: Stack.php line 246
public getCurrentFont() : TFontMetric
Tags
- throws: Exception
Return values
TFontMetric
getCurrentFontIndex()
File: Stack.php line 383
public getCurrentFontIndex() : int
Return values
int
getCurrentFontKey()
File: Stack.php line 349
public getCurrentFontKey() : string
Tags
- throws: Exception
Return values
string
getCurrentFontType()
File: Stack.php line 359
public getCurrentFontType() : string
Tags
- throws: Exception
Return values
string
getEncDiffs()
File: Buffer.php line 165
public getEncDiffs() : array<int, string>
Return values
array<int, string>
getFont()
File: Buffer.php line 189
public getFont(string $key) : TFontData
Parameters
- $key : string: Font key
Tags
- throws: Exception in case of error
Return values
TFontData —
Returns the fonts array.
getFontFamilyName()
File: Stack.php line 1052
public getFontFamilyName(string $fontfamily) : string
Parameters
- $fontfamily : string: Raw font family name.
Tags
- throws: Exception
Return values
string
getFonts()
File: Buffer.php line 155
public getFonts() : array<string, TFontData>
Return values
array<string, TFontData>
getGidForOrd()
File: Stack.php line 439
public getGidForOrd(int $ord) : int
Parameters
- $ord : int: Unicode codepoint.
Tags
- throws: Exception
Return values
int —
The glyph index, or 0 (.notdef) when the font has no glyph for it.
getOrdArrDims()
File: Stack.php line 620
public getOrdArrDims(array<int, int> $uniarr) : TTextDims
Parameters
- $uniarr : array<int, int>: Array of character codepoints.
Tags
- throws: Exception
Return values
TTextDims
getOrdArrWidth()
File: Stack.php line 606
public getOrdArrWidth(array<int, int> $uniarr) : float
Parameters
- $uniarr : array<int, int>: Array of character codepoints.
Tags
- throws: Exception
Return values
float
getOutCurrentFont()
File: Stack.php line 393
public getOutCurrentFont() : string
Tags
- throws: Exception
Return values
string
getStackSize()
File: Stack.php line 375
public getStackSize() : int
Return values
int
hasCurrentFont()
File: Stack.php line 367
public hasCurrentFont() : bool
Return values
bool
insert()
File: Stack.php line 188
public insert(int &$objnum, string $font[, string $style = '' ][, float|null $size = null ][, float|null $spacing = null ][, float|null $stretching = null ][, string $ifile = '' ][, bool|null $subset = null ]) : TFontMetric
The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by K_PATH_FONTS if the constant is defined.
Parameters
- $objnum : int: Current PDF object number
- $font : string: Font family, or comma separated list of font families If it is a standard family name, it will override the corresponding font.
- $style : string = ‘’: Font style. Possible values are (case-insensitive): regular (default) B: bold I: italic U: underline D: strikeout (linethrough) O: overline
- $size : float|null = null: Font size in points (set to null to inherit the last font size).
- $spacing : float|null = null: Extra spacing between characters.
- $stretching : float|null = null: Horizontal character stretching ratio.
- $ifile : string = ‘’: The font definition file (or empty for autodetect). By default, the name is built from the family and style, in lower case with no spaces.
- $subset : bool|null = null: If true, embed only the characters used by the document. Valid only for TrueTypeUnicode fonts. Set to null to use the default value. Subsetting is computational and memory intensive.
Tags
- throws: Exception in case of error
Return values
TFontMetric —
Font data
isCharDefined()
File: Stack.php line 570
public isCharDefined(int $ord) : bool
Parameters
- $ord : int: Unicode character value to convert
Tags
- throws: Exception
Return values
bool
isCurrentByteFont()
File: Stack.php line 403
public isCurrentByteFont() : bool
Tags
- throws: Exception
Return values
bool
isCurrentGidEncoded()
File: Stack.php line 425
public isCurrentGidEncoded() : bool
Tags
- throws: Exception
Return values
bool
isCurrentUnicodeFont()
File: Stack.php line 414
public isCurrentUnicodeFont() : bool
Tags
- throws: Exception
Return values
bool
isSubsetMode()
File: Buffer.php line 145
public isSubsetMode() : bool
Return values
bool
isValidKey()
File: Buffer.php line 175
public isValidKey(string $key) : bool
Parameters
- $key : string: Font key
Return values
bool
ordArrToGidStr()
File: Stack.php line 483
public ordArrToGidStr(array<int, int> $uniarr) : string
Every glyph is recorded on the font, and its codepoint is added to the subset.
Parameters
- $uniarr : array<int, int>: Array of character codepoints.
Tags
- throws: Exception
Return values
string
popLastFont()
File: Stack.php line 511
public popLastFont() : TFontMetric
Tags
- throws: Exception
Return values
TFontMetric
replaceChar()
File: Stack.php line 713
public replaceChar(int $oldchar, int $newchar) : int
Parameters
- $oldchar : int: Integer code (Unicode) of the character to replace.
- $newchar : int: Integer code (Unicode) of the new character.
Tags
- throws: Exception
Return values
int —
the replaced char or the old char in case the new char is not defined
replaceMissingChars()
File: Stack.php line 537
public replaceMissingChars(array<int, int> $uniarr[, array<int, array<string|int, int>> $subs = [] ]) : array<int, int>
A character is missing when the font has no width for it (see isCharDefined()).
Parameters
- $uniarr : array<int, int>: Array of character codepoints.
- $subs : array<int, array<string|int, int» = []: Array of possible character substitutions. The key is the character to check (integer value), the value is an array of possible substitutes.
Tags
- throws: Exception
Return values
array<int, int> —
Array of character codepoints.