phpdftk API Documentation

TextLayout
in package

FinalYes

Shared text-layout primitives — greedy word wrapping and width measurement against AFM metrics. Used by `Pdf` and by the shared primitive renderers (`TableRenderer`, `ListRenderer`, etc.) so flow layout and explicit placement agree on geometry.

Width measurement assumes WinAnsi-encoded byte input: the caller is responsible for encoding UTF-8 to the font's byte encoding before calling measure() / wrap(). This matches what ContentStream::showText() expects when the caller passes a resource-name string (no auto-encoding).

Table of Contents

Methods

measure()  : float
Measure a single line of byte-encoded text in points.
wrap()  : array<int, string>
Greedy word-wrap: split on whitespace, pack words onto lines until the next word would overflow the column width. A single word wider than the column is emitted on its own line without mid-word breaking. Explicit newlines produce paragraph breaks within the returned line list.

Methods

measure()

Measure a single line of byte-encoded text in points.

public static measure(string $text, AfmData $metrics, float $size) : float
Parameters
$text : string
$metrics : AfmData
$size : float
Return values
float

wrap()

Greedy word-wrap: split on whitespace, pack words onto lines until the next word would overflow the column width. A single word wider than the column is emitted on its own line without mid-word breaking. Explicit newlines produce paragraph breaks within the returned line list.

public static wrap(string $text, AfmData $metrics, float $size, float $columnWidth) : array<int, string>
Parameters
$text : string
$metrics : AfmData
$size : float
$columnWidth : float
Return values
array<int, string>

        
On this page

Search results