Stack

Stack API reference

Namespace: Com\Tecnick\Pdf\Font

class Stack extends Buffer

Extends: Buffer

Source: src/Stack.php:109

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>,
    'gw': 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:114

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:273

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:836

getCharWidth()

Returns the width of the specified character.

A variation selector takes no space.

public getCharWidth(int $ord): float

Parameters:

  • $ord (int): Unicode character value.

Returns: float

Throws:

Source: src/Stack.php:660

getCurrentFont()

Returns the current font data array.

public getCurrentFont(): TFontMetric

Returns: TFontMetric

Throws:

Source: src/Stack.php:247

getCurrentFontIndex()

Returns the current font index in the stack.

public getCurrentFontIndex(): int

Returns: int

Source: src/Stack.php:384

getCurrentFontKey()

Returns the current font key.

public getCurrentFontKey(): string

Returns: string

Throws:

Source: src/Stack.php:350

getCurrentFontType()

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

public getCurrentFontType(): string

Returns: string

Throws:

Source: src/Stack.php:360

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:1199

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:440

getOrdArrCharWidths()

Returns the width of each codepoint of the string, without the character spacing.

A variation selector takes no space, and a base character followed by a variation selector the font maps takes the width of the glyph of the sequence.

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

Parameters:

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

Returns: array<int,float>: Widths in the order of the codepoints.

Throws:

Source: src/Stack.php:698

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:748

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:681

getOutCurrentFont()

Returns the PDF code to use the current font.

public getOutCurrentFont(): string

Returns: string

Throws:

Source: src/Stack.php:394

getStackSize()

Returns the number of fonts currently stored in the stack.

public getStackSize(): int

Returns: int

Source: src/Stack.php:376

getVariationGid()

Returns the glyph index of a variation sequence in the current font.

public getVariationGid(int $base, int $selector): int

Parameters:

  • $base (int): Base character.
  • $selector (int): Variation selector.

Returns: int: The glyph index, or 0 when the font does not map the sequence.

Throws:

Source: src/Stack.php:504

hasCurrentFont()

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

public hasCurrentFont(): bool

Returns: bool

Source: src/Stack.php:368

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:193

isCharDefined()

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

A variation selector needs no glyph of its own and is always defined.

public isCharDefined(int $ord): bool

Parameters:

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

Returns: bool

Throws:

Source: src/Stack.php:643

isCurrentByteFont()

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

public isCurrentByteFont(): bool

Returns: bool

Throws:

Source: src/Stack.php:404

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:426

isCurrentUnicodeFont()

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

public isCurrentUnicodeFont(): bool

Returns: bool

Throws:

Source: src/Stack.php:415

isVariationSelector()

Returns true when the codepoint is a variation selector: U+180B..U+180D, U+180F, U+FE00..U+FE0F or U+E0100..U+E01EF.

public static isVariationSelector(int $ord): bool

Parameters:

  • $ord (int): Unicode codepoint.

Returns: bool

Source: src/Stack.php:481

ordArrToGidStr()

Encode an array of codepoints as the 2-byte character codes of the current font.

The codes are glyph indices, or alias codes of the glyphs shown for more than one text (see Buffer::addUsedGlyph()). A base character followed by a variation selector the font maps is shown with the glyph of the sequence; a variation selector shows no glyph of its own. Every glyph is recorded on the font, and its base 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:538

popLastFont()

Remove and return the last inserted font

public popLastFont(): TFontMetric

Returns: TFontMetric

Throws:

Source: src/Stack.php:582

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:854

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:608

Inherited members

From Buffer

  • __construct(): Initialize fonts buffer
  • add(): Add a new font to the fonts buffer
  • addFont(): Add a new font to the fonts buffer and report the style it provides.
  • addSubsetChar(): Add a character to the subset list
  • addUsedGid(): Record a glyph index used by the document and the codepoint it was encoded from.
  • addUsedGlyph(): Record a glyph used by the document and the text it was selected for, and return the character code that shows it.
  • getEncDiffs(): Returns the encoding differences buffer
  • getFont(): Get font by key
  • getFonts(): Returns the fonts buffer
  • isSubsetMode(): Get the default subset mode
  • isValidKey(): Returns true if the specified font key exist on buffer
  • setSubsetMode(): Set the default subset mode.