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
Implement Truncation Modes Properly
The current code treats all truncation modes as clipping. Implement proper head/middle/tail truncation:
case NSLineBreakByTruncatingTail: {
// Calculate if truncation is needed
if (position.x + glyphEntry->size.width > lineFragment->rect.size.width) {
// Find truncation glyph (ellipsis) and fit it
NSGlyph ellipsisGlyph = [font glyphWithName: @"ellipsis"];
CGFloat ellipsisWidth = [font advancementForGlyph: ellipsisGlyph].width;
// Remove glyphs until ellipsis fits
while (index > firstGlyphIndex &&
glyphEntry[-1].position.x + ellipsisWidth > lineFragment->rect.size.width) {
index--;
glyphEntry--;
}
// Insert ellipsis
glyphEntry->glyph = ellipsisGlyph;
glyphEntry->position = position;
glyphEntry->size.width = ellipsisWidth;
glyphEntry->dontShow = NO;
lineFragment->lastGlyphIndex = index + 1;
*newParagraph = NO;
return NO; // Line is complete
}
break;
}
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
Implement Truncation Modes Properly
The current code treats all truncation modes as clipping. Implement proper head/middle/tail truncation: