Optional module · pdftoolkit/opentype 0.4.1

English | Français

TrueTypeOutlineReader decodes both loca formats and simple/composite glyf records. It returns immutable point, contour, component, transform, bound and instruction-byte objects. The reader does not execute the retained instructions.

use PDFToolkit\OpenType\Outline\CompositeOffsetPolicy;
use PDFToolkit\OpenType\Outline\QuadraticPathBuilder;
use PDFToolkit\OpenType\Outline\TrueTypeOutlineEngine;
use PDFToolkit\OpenType\Outline\TrueTypeOutlineReader;
use PDFToolkit\OpenType\Value\GlyphId;

$outlines = (new TrueTypeOutlineReader())->read($font);
$outline = (new TrueTypeOutlineEngine(CompositeOffsetPolicy::Unscaled))
    ->outline($outlines, new GlyphId(2));
$path = (new QuadraticPathBuilder())->build($outline);

The engine assembles unhinted components, applying their affine transforms, explicit scaled/unscaled offsets and contour-point attachment. Absent offset-scaling flags use the caller's policy: unscaled, scaled or reject ambiguous transforms. The recommended platform behavior is unscaled. Nested components are resolved in font order; repeated children are legitimate, cycles are refused. Separate depth, operation and expanded-point budgets prevent a small acyclic graph from allocating an unbounded outline.

QuadraticPathBuilder turns on/off-curve points into explicit move, line, quadratic and close commands, including implied midpoints and contours with no explicit on-curve point. GlyphBounds is the declared control-point rectangle, not a claim that it is the tight Bézier bound or a varied/hinted rectangle.

Instruction execution and grid fitting remain separate. ROUND_XY_TO_GRID is retained without pixel rounding. Optional GvarInstance and PhantomPointProvider objects enable native variation, phantom-point attachment and USE_MY_METRICS through glyph(); see TrueType variations. outline() returns geometry alone. An attachment requiring phantom points fails explicitly when no provider is supplied. Empty glyph data and zero-contour glyphs with instructions remain distinguishable.

The original fixture exercises curves, all-off-curve contours, offsets, uniform and matrix transforms, point attachment and nested components. The independent oracle compares all glyph points from the original TrueType fixtures with fontTools, and their drawn quadratic geometry with HarfBuzz. HarfBuzz's horizontal origin adjustment (lsb minus xMin) is accounted for explicitly. Native tests cover short/long loca, cycles, malformed flags/ranges, instructions and output budgets.

Sources: glyf, loca, and TrueType instructions and phantom points.

Guide source at the documented commit ↗