Stack

Com\Tecnick\Pdf\Font\Stack

Namespace: Com\Tecnick\Pdf\Font

Extends: Buffer

File: Stack.php line 103

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}
  • phpstan-type: TStackItem array{ ‘key’: string, ‘style’: 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, ‘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 108

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

Return values

string —

Font key

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

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 268

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

Return values

TFontMetric

getCharBBox()

File: Stack.php line 690

public getCharBBox(int $ord) : TBBox

Parameters

  • $ord : int: Unicode character value.

Tags

Return values

TBBox —

(xMin, yMin, xMax, yMax)

getCharWidth()

File: Stack.php line 580

public getCharWidth(int $ord) : float

Parameters

  • $ord : int: Unicode character value.

Tags

Return values

float

getCurrentFont()

File: Stack.php line 242

public getCurrentFont() : TFontMetric

Tags

Return values

TFontMetric

getCurrentFontIndex()

File: Stack.php line 378

public getCurrentFontIndex() : int

Return values

int

getCurrentFontKey()

File: Stack.php line 344

public getCurrentFontKey() : string

Tags

Return values

string

getCurrentFontType()

File: Stack.php line 354

public getCurrentFontType() : string

Tags

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

Return values

TFontData —

Returns the fonts array.

getFontFamilyName()

File: Stack.php line 1051

public getFontFamilyName(string $fontfamily) : string

Parameters

  • $fontfamily : string: Raw font family name.

Tags

Return values

string

getFonts()

File: Buffer.php line 155

public getFonts() : array<string, TFontData>

Return values

array<string, TFontData>

getGidForOrd()

File: Stack.php line 434

public getGidForOrd(int $ord) : int

Parameters

  • $ord : int: Unicode codepoint.

Tags

Return values

int —

The glyph index, or 0 (.notdef) when the font has no glyph for it.

getOrdArrDims()

File: Stack.php line 615

public getOrdArrDims(array<int, int> $uniarr) : TTextDims

Parameters

  • $uniarr : array<int, int>: Array of character codepoints.

Tags

Return values

TTextDims

getOrdArrWidth()

File: Stack.php line 601

public getOrdArrWidth(array<int, int> $uniarr) : float

Parameters

  • $uniarr : array<int, int>: Array of character codepoints.

Tags

Return values

float

getOutCurrentFont()

File: Stack.php line 388

public getOutCurrentFont() : string

Tags

Return values

string

getStackSize()

File: Stack.php line 370

public getStackSize() : int

Return values

int

hasCurrentFont()

File: Stack.php line 362

public hasCurrentFont() : bool

Return values

bool

insert()

File: Stack.php line 183

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

Return values

TFontMetric —

Font data

isCharDefined()

File: Stack.php line 565

public isCharDefined(int $ord) : bool

Parameters

  • $ord : int: Unicode character value to convert

Tags

Return values

bool

isCurrentByteFont()

File: Stack.php line 398

public isCurrentByteFont() : bool

Tags

Return values

bool

isCurrentGidEncoded()

File: Stack.php line 420

public isCurrentGidEncoded() : bool

Tags

Return values

bool

isCurrentUnicodeFont()

File: Stack.php line 409

public isCurrentUnicodeFont() : bool

Tags

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 478

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

Return values

string

popLastFont()

File: Stack.php line 506

public popLastFont() : TFontMetric

Tags

Return values

TFontMetric

replaceChar()

File: Stack.php line 708

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

Return values

int —

the replaced char or the old char in case the new char is not defined

replaceMissingChars()

File: Stack.php line 532

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

Return values

array<int, int> —

Array of character codepoints.