Stack

Stack API reference

Namespace: Com\Tecnick\Pdf\Font

class Stack extends Buffer

Extends: Buffer

Source: src/Stack.php:108

Types

TTextSplit

array{
    'pos': int,
    'ord': int,
    'spaces': int,
    'septype': string,
    'wordwidth': float,
    'totwidth': float,
    'totspacewidth': float,
}

TTextDims

array{
    'chars': int,
    'spaces': int,
    'words': int,
    'totwidth': float,
    'totspacewidth': float,
    'split': array<int, TTextSplit>,
}

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().

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().

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,
}

Constants

DEFAULT_SIZE

Default font size in points

public const DEFAULT_SIZE = 10

Source: src/Stack.php:113

Methods

cloneFont()

Returns a clone of the specified font with new parameters.

public cloneFont(
    int &$objnum,
    ?int $idx = null,
    ?string $style = null,
    ?float $size = null,
    ?float $spacing = null,
    ?float $stretching = null
): TFontMetric

Parameters:

  • $objnum (int): Current PDF object number.
  • $idx (?int): Font index. Leave it null to use the current 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): Font size in points (set to null to inherit the last font size).
  • $spacing (?float): Extra spacing between characters.
  • $stretching (?float): Horizontal character stretching ratio.

Returns: TFontMetric

Throws:

Source: src/Stack.php:272

getCharBBox()

Returns the glyph bounding box of the specified character in the current font in user units.

public getCharBBox(int $ord): TBBox

Parameters:

  • $ord (int): Unicode character value.

Returns: TBBox: (xMin, yMin, xMax, yMax)

Throws:

Source: src/Stack.php:695

getCharWidth()

Returns the width of the specified character

public getCharWidth(int $ord): float

Parameters:

  • $ord (int): Unicode character value.

Returns: float

Throws:

Source: src/Stack.php:585

getCurrentFont()

Returns the current font data array.

public getCurrentFont(): TFontMetric

Returns: TFontMetric

Throws:

Source: src/Stack.php:246

getCurrentFontIndex()

Returns the current font index in the stack.

public getCurrentFontIndex(): int

Returns: int

Source: src/Stack.php:383

getCurrentFontKey()

Returns the current font key.

public getCurrentFontKey(): string

Returns: string

Throws:

Source: src/Stack.php:349

getCurrentFontType()

Returns the current font type (i.e.: Core, TrueType, TrueTypeUnicode, Type1).

public getCurrentFontType(): string

Returns: string

Throws:

Source: src/Stack.php:359

getFontFamilyName()

Returns the normalized font family name or the current font name key.

public getFontFamilyName(string $fontfamily): string

Parameters:

  • $fontfamily (string): Raw font family name.

Returns: string

Throws:

Source: src/Stack.php:1052

getGidForOrd()

Returns the glyph index of the specified codepoint in the current font.

public getGidForOrd(int $ord): int

Parameters:

  • $ord (int): Unicode codepoint.

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

Throws:

Source: src/Stack.php:439

getOrdArrDims()

Returns various dimensions of the string specified using an array of codepoints.

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

Parameters:

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

Returns: TTextDims

Throws:

Source: src/Stack.php:620

getOrdArrWidth()

Returns the length of the string specified using an array of codepoints.

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

Parameters:

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

Returns: float

Throws:

Source: src/Stack.php:606

getOutCurrentFont()

Returns the PDF code to use the current font.

public getOutCurrentFont(): string

Returns: string

Throws:

Source: src/Stack.php:393

getStackSize()

Returns the number of fonts currently stored in the stack.

public getStackSize(): int

Returns: int

Source: src/Stack.php:375

hasCurrentFont()

Returns true if a current font is available on the stack.

public hasCurrentFont(): bool

Returns: bool

Source: src/Stack.php:367

insert()

Insert a font into the stack

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.

public insert(
    int &$objnum,
    string $font,
    string $style = '',
    ?float $size = null,
    ?float $spacing = null,
    ?float $stretching = null,
    string $ifile = '',
    ?bool $subset = null
): TFontMetric

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): Font size in points (set to null to inherit the last font size).
  • $spacing (?float): Extra spacing between characters.
  • $stretching (?float): 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): If true, embed only the characters used by the document. Valid only for TrueTypeUnicode fonts. Set to null to use the default value for a new font, or to keep the mode of a font already loaded. Subsetting is computational and memory intensive.

Returns: TFontMetric: Font data

Throws:

Source: src/Stack.php:192

isCharDefined()

Returns true if the specified Unicode value is defined in the current font

public isCharDefined(int $ord): bool

Parameters:

  • $ord (int): Unicode character value to convert

Returns: bool

Throws:

Source: src/Stack.php:570

isCurrentByteFont()

Returns true if the current font type is Core, TrueType or Type1.

public isCurrentByteFont(): bool

Returns: bool

Throws:

Source: src/Stack.php:403

isCurrentGidEncoded()

Returns true if the current font encodes the text as glyph indices (CID == GID).

public isCurrentGidEncoded(): bool

Returns: bool

Throws:

Source: src/Stack.php:425

isCurrentUnicodeFont()

Returns true if the current font type is TrueTypeUnicode or cidfont0.

public isCurrentUnicodeFont(): bool

Returns: bool

Throws:

Source: src/Stack.php:414

ordArrToGidStr()

Encode an array of codepoints as the 2-byte glyph indices of the current font.

Every glyph is recorded on the font, and its codepoint is added to the subset.

public ordArrToGidStr(array<int,int> $uniarr): string

Parameters:

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

Returns: string

Throws:

Source: src/Stack.php:483

popLastFont()

Remove and return the last inserted font

public popLastFont(): TFontMetric

Returns: TFontMetric

Throws:

Source: src/Stack.php:511

replaceChar()

Replace a char if it is defined on the current font.

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.

Returns: int: the replaced char or the old char in case the new char is not defined

Throws:

Source: src/Stack.php:713

replaceMissingChars()

Replace missing characters with selected substitutions

A character is missing when the font has no width for it (see isCharDefined()).

public replaceMissingChars(array<int,int> $uniarr, array<int,int[]> $subs = []): array<int,int>

Parameters:

  • $uniarr (array<int,int>): Array of character codepoints.
  • $subs (array<int,int[]>): Array of possible character substitutions. The key is the character to check (integer value), the value is an array of possible substitutes.

Returns: array<int,int>: Array of character codepoints.

Throws:

Source: src/Stack.php:537

Inherited members

From Buffer