Skip to content

FontRun.UpdateOverhang uses wrong offset for glyph pointer #105

@Beldaa

Description

@Beldaa

In FontRun.UpdateOverhang() (FontRun.cs line 521), the glyph pointer passed to GetGlyphWidths uses Start (the code point index in the text block) instead of Glyphs.Start (the offset into the underlying glyph array).

// Current (wrong):
paint.GetGlyphWidths((IntPtr)(pGlyphs + Start), sizeof(ushort) * Glyphs.Length, out var bounds);

// Should be:
paint.GetGlyphWidths((IntPtr)(pGlyphs + Glyphs.Start), sizeof(ushort) * Glyphs.Length, out var bounds);

Start is the code point index of this font run in the overall text, while Glyphs.Start is the actual offset into the glyph buffer. These differ whenever glyph count != code point count (ligatures, combining marks, surrogate pairs, complex scripts).

This causes incorrect overhang/bounds calculations, affecting MeasuredOverhang results particularly with non-Latin text or fonts with ligatures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions