GlyphRun Object
The GlyphRun object in Fontkit represents a sequence of glyphs and their associated positions. When you layout a string using the font.layout() method, it returns a GlyphRun object.
Properties:
glyphRun.glyphs:
glyphRun.glyphs:Description: An array of
Glyphobjects representing the individual glyphs in the run.Type: Array of
Glyphobjects
glyphRun.positions:
glyphRun.positions:Description: An array of position objects, where each position corresponds to the
Glyphat the same index in theglyphsarray. Each position object typically containsxandyoffsets and an advance width and height.Type: Array of Position Objects. Each position object has properties:
xAdvance: The amount to move the pen in the x-direction after drawing the glyph.yAdvance: The amount to move the pen in the y-direction after drawing the glyph.xOffset: The x offset to apply when drawing this glyph.yOffset: The y offset to apply when drawing this glyph.
glyphRun.features:
glyphRun.features:Description: An array of OpenType feature tags applied to this run, which can affect the final set of glyphs and their positions.
Type: Array of Strings
glyphRun.script:
glyphRun.script:Description: The script (or writing system) used for this run of text, as determined by the shaping engine.
Type: String
glyphRun.language:
glyphRun.language:Description: The language tag for this run of text, which can affect shaping in some scripts.
Type: String
glyphRun.direction:
glyphRun.direction:Description: The text direction for this run. Common values include 'ltr' (left-to-right) and 'rtl' (right-to-left).
Type: String
glyphRun.advanceWidth:
glyphRun.advanceWidth:Description: The total advance width of the glyph run. This is the sum of the horizontal advances of all the glyphs in the run, and it represents the width that the glyph run would occupy if rendered.
Type: Number
glyphRun.advanceHeight:
glyphRun.advanceHeight:Description: The total advance height of the glyph run. This is particularly relevant for vertical text layouts.
Type: Number
glyphRun.bbox:
glyphRun.bbox:Description: The bounding box of the glyph run. It encompasses all the glyphs in the run and provides
minX,minY,maxX, andmaxYproperties.Type: Object
Methods:
The main interaction with a GlyphRun object revolves around accessing its properties rather than calling methods. Most of the manipulation or querying one would do with the GlyphRun results involves working directly with the properties listed above. For instance, iterating over the glyphs or positions to perform certain tasks or calculations.
Last updated
Was this helpful?