microsoft / microsoft/terminal
Consider performing font fallback analysis only if the chosen font is not adequate
- Dominant language
- C++
- Stars
- 105k
- Forks
- 9.6k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 29
Description
# 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
If no glyphs can be found (which I assume is a rather rare case), then the fallback analysis is necessary.
Contributor guide
Research direction
Start in src/renderer/dx/CustomTextLayout.cpp at the _AnalyzeFontFallback call around lines 246-247 and the _ShapeGlyphRun/GetGlyphs flow around line 414. Trace how _glyphIndices reports available glyphs, then verify that fallback analysis is deferred until the chosen font lacks a needed glyph, including mixed text such as ABC中文.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- cli, computer-graphics, performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100