Skip to content

GSHorizontalTypesetter improvements: Enable Kerning (Currently Disabled) #407

Description

@IOOI-SqAR

I asked the Kimi AI how to further improve GSHorizontalTypesetter. Here is what it came up with:

https://www.kimi.com/share/19d34cdb-8242-8fc9-8000-00001fd46e3b

Enable Kerning (Currently Disabled)

The kerning code is commented out as a "major bottleneck" but this significantly degrades text quality. Implement with caching:

// PROPOSED: Add kerning cache to avoid repeated font metrics calls
struct {
    NSGlyph prevGlyph;
    NSGlyph currGlyph;
    float kernAdjustment;
} *kerningCache;
size_t kerningCacheSize;

// Use conservative kerning: only query when glyph pair changes
if (lastGlyph && lastGlyph != NSNullGlyph && glyphEntry->font == font) {
    float kern = [font advancementForGlyph: lastGlyph].width + 
                 [font advancementForGlyph: glyphEntry->glyph].width -
                 [font advancementForGlyphPair: lastGlyph : glyphEntry->glyph].width;
    if (kern != 0) {
        position.x += kern;
        glyphEntry->nominal = NO;
    }
}

We should of course check if this is a bottle neck.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions