PdfFont

class PdfFont

A resolved PDF font.

The font knows how to:

  • decode show-text bytes into unicode (text extraction).

  • layoutBytes walk show-text bytes into a sequence of TextGlyphs — each tagged with its outline (if any), advance, and decoded text.

Simple fonts (Type 1, TrueType, Type1C, Type 3) consume one byte per glyph. Type 0 composite fonts (CIDFontType0/2 under a Type 0 parent) consume one code unit per glyph — typically 2 bytes via the Identity-H CMap, sometimes variable. layoutBytes is the unified iterator everything downstream uses.

Embedded outlines are pulled from whichever of these is present:

  • /FontFile → Type 1 (PostScript)

  • /FontFile2 → TrueType

  • /FontFile3 → CFF (Type1C or CIDFontType0C)

Order tried matches what real fonts actually carry; falls back to the host system font (via baseFont) when no outlines are available.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Units-per-em: TTF reports its own; CFF + Type 1 default to 1000.

Functions

Link copied to clipboard
fun decode(bytes: ByteArray): String

Decode show-text bytes (from a Tj / TJ operand) to unicode text.

Link copied to clipboard
fun embeddedAdvanceWidth(byteCode: Int): Int?

True iff the underlying embedded font has its own advance metrics.

Link copied to clipboard
fun forEachGlyphAdvance(bytes: ByteArray, action: (advanceWidth: Double, isWordSpace: Boolean) -> Unit)

Invoke action once per glyph with its advance width (1/1000 em) and word-space flag, WITHOUT resolving any glyph outline or allocating a TextGlyph list. The fast path for advance/measurement (text positioning, width sums) where glyph shapes aren't needed — used by the renderer's advance calc, text extraction, and redaction layout.

Link copied to clipboard
fun glyphIdForByte(byteCode: Int): Int

Glyph id for a single byte code in a simple font. Returns 0 for composite fonts (their glyph IDs come from CIDs, not byte codes).

Link copied to clipboard
fun layoutBytes(bytes: ByteArray, resolveOutlines: Boolean = true): List<TextGlyph>

Walk bytes one glyph at a time, dispatching to the right code-unit width (1 for simple fonts, usually 2 for Identity-H composites).

Link copied to clipboard

Per-byte outline lookup. Kept for backward compat with callers that pre-date the layoutBytes iterator; layoutBytes is the right path for any new code so composite Type 0 fonts work correctly.

Link copied to clipboard
fun widthOf(byteCode: Int): Int

Width (1/1000 em) for a single byte code in a simple font. Composite use layoutBytes.