TtfFont class

High-level interface for a loaded TrueType font.

Wraps TtfParser with caching, metrics, and pixel-scale APIs.

Load a font:

final bytes = File('/path/to/Roboto-Regular.ttf').readAsBytesSync();
final font = TtfFont.load(bytes);

Render text (with FontLoader + ParagraphBuilder — see Phase 4+):

final glyphId = font.getGlyphId('A'.codeUnitAt(0));
if (glyphId != null) {
  final outline = font.getGlyphOutline(glyphId);
  final advance = font.getAdvanceWidth(glyphId, 16.0);
}

Properties

availableTables Set<String>
The set of TTF table tags available in this font.
no setter
glyphCount int
Total number of glyphs in the font.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasKerning bool
Whether a kern table is present.
no setter
metrics FontMetrics
Typographic metrics for this font.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getAdvanceWidth(int glyphId, double fontSize) double
Advance width for glyphId scaled to fontSize in pixels.
getGlyphId(int codePoint) int?
Returns the glyph ID for codePoint, or null if the character is not mapped in this font.
getGlyphOutline(int glyphId) GlyphOutline?
Returns the glyph outline for glyphId, or null if the glyph data cannot be parsed (e.g. the glyph ID is out of range).
getKerning(int glyphId1, int glyphId2, double fontSize) double
Pair-kerning adjustment between two consecutive glyphs, in pixels.
getLsb(int glyphId) int
Left side bearing for glyphId in font units (unscaled).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

load(Uint8List bytes) TtfFont
Loads a TTF/OTF font from raw bytes.