Consider performing font fallback analysis only if the chosen font is not adequate #14769

Open
opened 2026-01-31 04:19:02 +00:00 by claunia · 2 comments
Owner

Originally created by @skyline75489 on GitHub (Aug 3, 2021).

Description of the new feature/enhancement

Right now the _AnalyzeFontFallback is always called if the text is "complex":

e7108332f7/src/renderer/dx/CustomTextLayout.cpp (L246-L247)

We already know that even for pure ASCII characters, some fonts will treat them as "complex". But the real need for font fallback emerges only when the font don't actually contains the needed glyph. For example when dealing with "ABC中文". You have to find "Microsoft YaHei" as fallback, otherwise "中文" is nowhere to be find in "Cascadia Code“.

Proposed technical implementation details (optional)

To avoid the unnecessary overhead of finding fallbacks (MapCharacters, which is relatively expensive), my proposed solution is to delay the fallback analysis and put it in _ShapeGlyphRun. Inside _ShapeGlyphRun, the method GetGlyphs will tell you precisely if there are available glyphs inside the desired font (_glyphIndices):

e7108332f7/src/renderer/dx/CustomTextLayout.cpp (L414)

If no glyphs can be found (which I assume is a rather rare case), then the fallback analysis is necessary.

Originally created by @skyline75489 on GitHub (Aug 3, 2021). # Description of the new feature/enhancement Right now the `_AnalyzeFontFallback` is always called if the text is "complex": https://github.com/microsoft/terminal/blob/e7108332f72a3c14c72a65484d091c4e79ab28b2/src/renderer/dx/CustomTextLayout.cpp#L246-L247 We already know that even for pure ASCII characters, some fonts will treat them as "complex". But the real need for font fallback emerges *only* when the font don't actually contains the needed glyph. For example when dealing with "ABC中文". You have to find "Microsoft YaHei" as fallback, otherwise "中文" is nowhere to be find in "Cascadia Code“. # Proposed technical implementation details (optional) To avoid the unnecessary overhead of finding fallbacks (`MapCharacters`, which is relatively expensive), my proposed solution is to delay the fallback analysis and put it in `_ShapeGlyphRun`. Inside `_ShapeGlyphRun`, the method `GetGlyphs` will tell you precisely if there are available glyphs inside the desired font (`_glyphIndices`): https://github.com/microsoft/terminal/blob/e7108332f72a3c14c72a65484d091c4e79ab28b2/src/renderer/dx/CustomTextLayout.cpp#L414 <!-- A clear and concise description of what you want to happen. --> If no glyphs can be found (which I assume is a rather rare case), then the fallback analysis is necessary.
claunia added the Area-RenderingIssue-TaskProduct-TerminalArea-Performance labels 2026-01-31 04:19:02 +00:00
Author
Owner

@skyline75489 commented on GitHub (Aug 3, 2021):

/cc @miniksa

@skyline75489 commented on GitHub (Aug 3, 2021): /cc @miniksa
Author
Owner

@zadjii-msft commented on GitHub (Aug 3, 2021):

That makes sense to me

@zadjii-msft commented on GitHub (Aug 3, 2021): That makes sense to me
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#14769