Documentation

Parser
in package

Pdf font parser class

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
6.0.0

Table of Contents

Properties

$cidFontObjectIndex  : int|null
CID (descendant) font object index
$compression  : bool
Font compression flag
$font  : Type1|TrueType|null
Font object
$fontDescIndex  : int|null
Font descriptor index
$fontFileIndex  : int|null
Font file index
$fontIndex  : int|null
Font reference index
$fontObjectIndex  : int|null
Font object index
$objects  : array<string|int, mixed>
Font objects
$toUnicodeIndex  : int|null
ToUnicode CMap stream object index

Methods

__construct()  : mixed
Constructor
getCidFontObjectIndex()  : int|null
Get the CID (descendant) font object index
getFont()  : AbstractFont|null
Get the font object
getFontDescIndex()  : int|null
Get the font descriptor index
getFontFileIndex()  : int|null
Get the font file index
getFontIndex()  : int|null
Get the font index
getFontName()  : string
Method to get the font name.
getFontObjectIndex()  : int|null
Get the font object index
getFontReference()  : string
Method to get the font reference.
getObjects()  : array<string|int, mixed>
Get the font objects
getToUnicodeIndex()  : int|null
Get the ToUnicode CMap stream object index
isCompressed()  : bool
Get whether or not the font objects are compressed
isEmbeddable()  : bool
Method to get if the font is embeddable.
loadFromStream()  : void
Load font from stream
parse()  : void
Parse the font data and create the font objects
setCidFontObjectIndex()  : Parser
Set the CID (descendant) font object index
setCompression()  : Parser
Set the compression
setFontDescIndex()  : Parser
Set the font descriptor index
setFontFileIndex()  : Parser
Set the font file index
setFontIndex()  : Parser
Set the font index
setFontObjectIndex()  : Parser
Set the font object index
setToUnicodeIndex()  : Parser
Set the ToUnicode CMap stream object index
buildCidWidths()  : string
Build the /W (per-CID width) array for a CID font from GID-indexed glyph widths
buildToUnicodeCMap()  : string
Build a /ToUnicode CMap stream mapping glyph IDs back to Unicode code units

Properties

$cidFontObjectIndex

CID (descendant) font object index

protected int|null $cidFontObjectIndex = null

$compression

Font compression flag

protected bool $compression = false

$fontDescIndex

Font descriptor index

protected int|null $fontDescIndex = null

$fontFileIndex

Font file index

protected int|null $fontFileIndex = null

$fontIndex

Font reference index

protected int|null $fontIndex = null

$fontObjectIndex

Font object index

protected int|null $fontObjectIndex = null

$objects

Font objects

protected array<string|int, mixed> $objects = []

$toUnicodeIndex

ToUnicode CMap stream object index

protected int|null $toUnicodeIndex = null

Methods

__construct()

Constructor

public __construct(string $fontFile[, bool $compression = false ]) : mixed

Instantiate a font parser object

Parameters
$fontFile : string
$compression : bool = false
Tags
throws
Exception|Exception

getCidFontObjectIndex()

Get the CID (descendant) font object index

public getCidFontObjectIndex() : int|null
Return values
int|null

getFontDescIndex()

Get the font descriptor index

public getFontDescIndex() : int|null
Return values
int|null

getFontFileIndex()

Get the font file index

public getFontFileIndex() : int|null
Return values
int|null

getFontIndex()

Get the font index

public getFontIndex() : int|null
Return values
int|null

getFontName()

Method to get the font name.

public getFontName() : string
Return values
string

getFontObjectIndex()

Get the font object index

public getFontObjectIndex() : int|null
Return values
int|null

getFontReference()

Method to get the font reference.

public getFontReference() : string
Return values
string

getObjects()

Get the font objects

public getObjects() : array<string|int, mixed>
Return values
array<string|int, mixed>

getToUnicodeIndex()

Get the ToUnicode CMap stream object index

public getToUnicodeIndex() : int|null
Return values
int|null

isCompressed()

Get whether or not the font objects are compressed

public isCompressed() : bool
Return values
bool

isEmbeddable()

Method to get if the font is embeddable.

public isEmbeddable() : bool
Return values
bool

loadFromStream()

Load font from stream

public static loadFromStream(string $stream) : void
Parameters
$stream : string

parse()

Parse the font data and create the font objects

public parse() : void
Tags
throws
Exception

setCidFontObjectIndex()

Set the CID (descendant) font object index

public setCidFontObjectIndex(int $index) : Parser
Parameters
$index : int
Return values
Parser

setCompression()

Set the compression

public setCompression(bool $compression) : Parser
Parameters
$compression : bool
Return values
Parser

setFontDescIndex()

Set the font descriptor index

public setFontDescIndex(int $index) : Parser
Parameters
$index : int
Return values
Parser

setFontFileIndex()

Set the font file index

public setFontFileIndex(int $index) : Parser
Parameters
$index : int
Return values
Parser

setFontIndex()

Set the font index

public setFontIndex(int $index) : Parser
Parameters
$index : int
Return values
Parser

setFontObjectIndex()

Set the font object index

public setFontObjectIndex(int $index) : Parser
Parameters
$index : int
Return values
Parser

setToUnicodeIndex()

Set the ToUnicode CMap stream object index

public setToUnicodeIndex(int $index) : Parser
Parameters
$index : int
Return values
Parser

buildCidWidths()

Build the /W (per-CID width) array for a CID font from GID-indexed glyph widths

protected buildCidWidths(TrueType $font) : string

hmtx-derived glyph widths are already contiguous from GID 0, so this emits a single 'c [w1 w2 ... wn]' run rather than detecting ranges.

Parameters
$font : TrueType
Return values
string

buildToUnicodeCMap()

Build a /ToUnicode CMap stream mapping glyph IDs back to Unicode code units

protected buildToUnicodeCMap(TrueType $font) : string

Inverts the font's own codepoint => GID cmap. The inversion is lossy: several codepoints can share one GID (e.g. times.ttf maps both U+0020 and U+00A1 to GID 3), but a /ToUnicode CMap can only name one of them. The LOWEST codepoint wins, which keeps the ASCII/Latin-1 member of any such collision - so a space extracts as a space rather than as whatever exotic codepoint happened to be iterated last.

Parameters
$font : TrueType
Return values
string

        
On this page

Search results