Thanks to visit codestin.com
Credit goes to github.com

Skip to content

GUI: Enable font fallback on missing glyphs - #7948

Draft
ied206 wants to merge 6 commits into
scummvm:masterfrom
ied206:gui-font-fallback
Draft

GUI: Enable font fallback on missing glyphs#7948
ied206 wants to merge 6 commits into
scummvm:masterfrom
ied206:gui-font-fallback

Conversation

@ied206

@ied206 ied206 commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

PR Summary

  • Enable font fallback on missing glyphs.
  • Add Unifont to fonts-cjk.dat, and use it as a final fallback TTFFont.
  • Update Noto Sans CJK font files to 2.004 from 1.004 to add Han character glyphs to Noto Sans KR.
    • Noto Sans KR 1.004 in fonts-cjk.dat does not have Han character glyphs.
    • Updating to 2.004 adds those glyphs to the font file.

Screenshots

I rendered this text in ScummVM, with the UI language set to Korean to force the use of Noto Sans KR, before/after the patch:

한국 韓國 Corée 鿿
  • Noto Sans KR, even 2.004, does not support the last character (U+9FFF 鿿). Unifont, a fallback, must render it.

AS-IS

  • Noto Sans KR 1.004 fails to render 韓國, é and 鿿.
image

TO-BE

  • Noto Sans KR 2.004 correctly renders 韓國, é.
  • Unifont, a fallback font, correctly renders 鿿.
image

PR Details

Font Fallback System

When a font is requested to draw a missing glyph in ScummVM, it simply omits rendering of that glyph.

  • Users usually expect a fallback font, or at least a tofu (�) to appear in that case.
  • It can cause an issue on CJK systems, especially Korean:
    • Korean fonts tend to support only a frequently used subset of Hangul glyphs (2350 out of 11172).
    • Modern Korean uses Han characters as a supplement, but they are often omitted, too.

This PR adds a fallback font glyph rendering system to mitigate this problem.

  • Implement Graphics::Font::hasGlyph() function.
    • It returns kPresent/kAbsence when implemented.
    • It returns kUnknown on unimplemented derived classes, to prevent breaking. It is treated the same as kPresent.
  • Add hasGlyph() overload to the TTFFont, a class for freetype-backed fonts.
    • No other derived font classes are touched.
  • Add Graphics::FallbackFont class; an object handles multiple font instances.
    • When a glyph render is requested, it checks its fonts in order of priority using hasGlyphs() and renders the first glyph available.
    • The render layout and dimensions are fixed to the primary font; use of the fallback font is an exception.
    • When no font has a glyph, render a tofu (U+FFFD �). Render ? as a last resort when even tofu is not available.
  • Add a fallback font feature to the ScummVM Theme system, as a first consumer.
    • In XML, <fonts>, <font>, <language> node can have a child node of <fallback>.

Addition/Update of fonts

This PR also adds an OpenType variant of Unifont.

  • Unifont is a lightweight (~5MB) console/monospace-friendly font that aims to cover all Unicode codepoints.
  • It makes a perfect candidate for a fallback font on a low-resolution, non-hinted surface.
  • It suits ScummVM's license, as it is dual-licensed under the SIL OFL and the GNU Font Embedding Exception.

This PR sets Unifont as a primary fallback font on freetype-based ScummVM themes.

  • Unifont was added to the CJK font dictionary to avoid a memory/storage issue on ScummVM ports for the old hardware.
  • When fonts-cjk.dat is excluded from the build, the fallback system would silently disable the use of Unifont in effect.

I also updated the Noto Sans CJK font family files to 2.004 from 1.004.

  • It was necessary to add Han character glyphs to Noto Sans KR.
  • The current OTF file embedded in ScummVM does not contain them.

Future Work

  • The ScummVM debug console is out of scope in this PR.
    • It was built on the assumption that 'every glyph has the same width', which interferes with the font fallback system.
  • This fallback font system can be expanded to bitmap fonts, too.

Support fallback declarations at the fonts, font and language scopes, with narrower scopes taking priority. Move Unifont into fonts.dat so the global fallback remains available in packages that omit fonts-cjk.dat.

Assisted-by: Codex:gpt-5
Keep Unifont in fonts-cjk.dat so distributions may omit the CJK font archive. Add an optional fallback declaration flag so scalable-font themes silently continue when Unifont is unavailable, while required fallbacks retain their warnings.

Assisted-by: Codex:gpt-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant