Skip to content

fix(issue-144): macOS Cyrillic text fix#153

Open
fbraz3 wants to merge 12 commits into
mainfrom
fix/issue-144-clean
Open

fix(issue-144): macOS Cyrillic text fix#153
fbraz3 wants to merge 12 commits into
mainfrom
fix/issue-144-clean

Conversation

@fbraz3
Copy link
Copy Markdown
Owner

@fbraz3 fbraz3 commented Jun 5, 2026

Description

Clean re-application of the Issue #144 macOS Cyrillic text fix, started from a fresh main (a7279e6) and cherry-picking only the font/caption related commits. The previous branch fix/issue-144-macos-cyrillic-text had accumulated upstream sync, CI work, diagnostic instrumentation, and a critical Drawable::calcPhysicsXformWheels regression (broken roll clamp (unclampedRoll > 0.5f && unclampedRoll < -0.5f) + autolevel branch + wheel consolidation) that broke the macOS replay-CI CRC at frames 1700/6900.

Approach

  • Branched from clean main (a7279e682).
  • Cherry-picked 9 Issue macOS: Cyrillic text labels not rendered (numbers work, English labels work) #144 commits in dependency order (see commits).
  • For commit 6b1c77e72 fix(localization): harden drawable caption fallback, manually extracted the safe font/caption work and dropped the physics changes from Drawable::calcPhysicsXformWheels (autolevel branch, broken roll clamp, wheel offset consolidation, commented-out roll-height block, cosmetic edits in drawEnthusiastic/drawBombed). Verified the resulting diff has zero matches for m_totalRoll|unclampedRoll|Autolevel|m_pitchRate|m_rollRate|m_wheelInfo|REAL_TO_INT|rasing up|calcPhysics.
  • Used main's .github/ folder as-is, then applied the 3 echo "$OUTPUT" changes from 0bc3a40d0 feat(ci): show full debug (replaces filtered grep with full output for replay debugging).
  • Skipped e38c00a2f perf(headless): skip drawable caption + alternate-unicode chain (locally verified: does not fix CRC, not the actual root cause).
  • Skipped 15e669dcf fix(macos-fontconfig): prefer system Arial fallback (deploy-script only, not on the user's list).
  • Skipped 5b8b43697 (blog) and 4e9387ae7 (branch analysis report) — both refer to the old branch structure.

Commits

  • 4d7e6e841 fix(fonts): add unicode fallback for cyrillic
  • 292bb8c51 fix(localization): add csf label fallback
  • f28e9ef19 fix(localization): harden drawable caption fallback (cleaned: physics hunks removed)
  • 00f0d56a7 fix(issue-144): add stderr diagnostics traces
  • 45dd89b21 fix(language-ini): implement fallback chain to restore Cyrillic font descriptors (Issue macOS: Cyrillic text labels not rendered (numbers work, English labels work) #144)
  • 6f4534f7a fix(fonts): break circular unicode fallback
  • 68f79fd26 fix(unicode-format): allow Cyrillic in vswprintf on macOS
  • 7f6cb7558 fix(unicode-format): make locale.h include portable for Linux
  • 62b25e736 fix(language): only fall back to English when UnicodeFontName is missing
  • 2e74fee81 feat(ci): show full debug

Diff size

  • 12 code files (was 86 in the old branch)
  • +795 / -62 lines of code (was +2338 / -1853 in the old branch)
  • 0 physics-related changes (was 90 lines of physics in the old branch)

Local validation

  • macos_2p_vanilla_map.rep — exit 0 (was CRC mismatch at frame 6900)
  • macos_6p_custom_map.rep — exit 0 (was CRC mismatch at frame 1700)
  • macos_2p_custom_map.rep — exit 0 (was already passing)

What was confirmed

  • The vswprintf uselocale(newlocale(LC_CTYPE_MASK, "UTF-8", 0)) wrap is the root cause fix for the 3D construction caption Строительство: 57% not rendering on macOS.
  • The font fallback chain (LoadUnicodeFallbackFont + circular fallback break) ensures the localized Arial resolves to a Unicode-capable font on macOS.
  • The Drawable::calcPhysicsXformWheels change in 6b1c77e72 was the regression source for the replay CI CRC mismatch and has been removed.

Why not just fix the old branch?

The old branch had grown to 86 changed code files and 2,338 / 1,853 line changes, much of it upstream sync from thesuperhackers, CI infrastructure, and diagnostic instrumentation. A clean re-apply is simpler to review and bisect than surgical fixes on the old branch.

Related

Game screenshot

image

@fbraz3 fbraz3 closed this Jun 5, 2026
@fbraz3 fbraz3 reopened this Jun 5, 2026
@fbraz3 fbraz3 changed the title fix(issue-144): clean re-apply of macOS Cyrillic text fix fix(issue-144): macOS Cyrillic text fix Jun 6, 2026
@w1semannn
Copy link
Copy Markdown

w1semannn commented Jun 6, 2026

Sorry for the late reply! Tested build from run 26990397402 — Cyrillic text is now rendering correctly ✅
One separate issue observed: tooltip text is clipped at the bottom — the tooltip box does not expand to fit the full description (see screenshot). This appears to be a UI layout issue, unrelated to the font fix.

изображение

@w1semannn
Copy link
Copy Markdown

Tooltip text clipping — root cause found
Confirmed Cyrillic rendering works ✅. The bottom clip is a separate pre-existing bug, but I tracked it down to the exact line.
In populateBuildTooltipLayout (both Generals/ and GeneralsMD/ copies of ControlBarPopupDescription.cpp), the height measurement for the description box does this:
cppoverrideTooltipGadgetFont(win); // sets Arial Unicode MS via GadgetStaticTextSetFont()
...
GameFont tooltipFont = win->winGetFont(); // ← still returns old Arial
tempDString->setFont(tooltipFont); // measurement uses wrong font
tempDString->getSize(&newSize.x, &newSize.y); // height underestimated
diffSize = newSize.y - size.y; // window not tall enough → clip
GadgetStaticTextSetFont updates the gadget's internal DisplayString but not the window's m_font pointer, so win->winGetFont() returns the old "Arial". The measurement underestimates height because Cyrillic in Arial Unicode MS uses different metrics than Latin Arial.
Minimal fix — change overrideTooltipGadgetFont from void to GameFont
(return newFont on success, oldFont on failure), then in the description block replace:
cppoverrideTooltipGadgetFont(win);
...
GameFont *tooltipFont = win->winGetFont();
with:
cppGameFont *tooltipFont = overrideTooltipGadgetFont(win);
if (!tooltipFont) tooltipFont = win->winGetFont();
The temp DisplayString then measures with the exact same font the renderer uses → correct height → no clip. The other three call sites (Name, Cost gadgets) keep their existing void-call style unchanged.

@fbraz3 fbraz3 force-pushed the fix/issue-144-clean branch from 2e74fee to 80856cb Compare June 7, 2026 21:27
fbraz3 added 11 commits June 7, 2026 20:17
Improve AlternateUnicodeFont resolution on macOS/Linux by trying configured Unicode font first and then a deterministic fallback list of common system fonts.

Also update the May 2026 dev diary before commit as required by project workflow.

Fixes #144

(cherry picked from commit d8fd346)
Add GX-ISSUE144 instrumentation using sprintf + fprintf(stderr, ...) across font resolution, language loading, drawable caption paths, and control bar tooltip/cost rendering.

Include a 2026-05-26 DEV_BLOG entry describing the diagnostics scope.

(cherry picked from commit 9df81a3)
…descriptors (Issue #144)

When russifier mod (00RussianZH.big) loads an incomplete Language.ini with
UnicodeFontName=\"Arial\", it permanently overrides the stock \"Arial Unicode MS\"
which supports Cyrillic. Since Arial lacks Cyrillic, construction captions
render blank on macOS.

Now when registryLanguage != \"English\", load stock English/Language with
INI_LOAD_MULTIFILE mode to fill missing keys. This restores UnicodeFontName
to \"Arial Unicode MS\" while preserving legitimate russifier overrides.

Mirrors existing CSF fallback pattern (commit 3a28555).

Fixes #144
Affects GeneralsXZH only (Language.ini path pattern)

- GlobalLanguage::init() now loads stock Language.ini as fallback
- Updated stderr diagnostics to show primary + fallback resolution
- Expected fix: construction captions \"Строительство: XX%\" now render

(cherry picked from commit 38f0e49)
…deFont from reusing the same base family\nwhen unicode font config resolves to the same name (e.g., Arial),\nforcing fallback to continue into Unicode-capable candidates.\n\nThis targets Issue #144 macOS Cyrillic caption rendering path.

(cherry picked from commit 8de42b1)
vswprintf on macOS returns -1 when the wide-char format string
contains any non-ASCII code point under the default C locale.
This silently truncated every UnicodeString::format() call whose
template included Cyrillic, producing an empty buffer and a
width=0 caption.

Root cause confirmed via stderr instrumentation showing
'vswprintf FAILED result=-1 fmt=Строительство: %.0f%%'.

Fix wraps vswprintf in uselocale(newlocale(LC_CTYPE_MASK, UTF-8))
for the duration of the call, then restores the previous thread
locale. Static locale_t, no per-call allocation.

Validation:
- Russian test: 'Строительство: 57%' renders in 3D caption.
- English test: construction text unaffected.
- Tooltip path unaffected (2D UnicodeString::format used here too).

Also includes Cyrillic font pipeline and tooltip work from this
session, plus diagnostic logs the user wants to keep until
reporter validation is fully complete.

Fixes #144

(cherry picked from commit 70fcb1f)
xlocale.h is macOS-only; on Linux it does not exist. uselocale and
newlocale are exposed via <locale.h> when _GNU_SOURCE is defined.

The previous Cyrillic vswprintf fix broke the Linux Flatpak CI build
with:
  fatal error: xlocale.h: No such file or directory

Guard the macOS-only include behind __APPLE__ and define _GNU_SOURCE
on other POSIX systems so the locale_t APIs remain visible.

(cherry picked from commit 135b1b6)
The 2026-05-27 fallback chain forced a reload of
Data\\English\\Language.ini whenever the primary language was
not English. This regressed in two ways:

1. Deploys without English (e.g. brazilian-only test data)
   caused INI::loadFileDirectory to throw INI_CANT_OPEN_FILE
   because it cannot find any file in the fallback directory.

2. When the primary language already set UnicodeFontName, the
   fallback ran with INI_LOAD_MULTIFILE semantics (overwrite)
   and clobbered the primary value with English's value, which
   is wrong for any official localization that has its own
   font descriptor.

Gate the fallback on m_unicodeFontName.isEmpty() so it only
activates for the russifier case (mod overrides the field with
a Cyrillic-unfriendly font and leaves it broken). Also probe
the file with doesFileExist first so a missing English file in
the deploy is a no-op rather than a fatal throw.

Fixes the macOS replay CI which is now run against a brazilian
deploy.

(cherry picked from commit ab2268e)
(cherry picked from commit 0bc3a40)
- Add ControlBar::overrideTooltipGadgetFont() to set Arial Unicode MS on tooltip
  gadgets and return the font for correct height measurement
- Update populateBuildTooltipLayout() in both Generals/ and GeneralsMD/ to use
  the returned font for size calculation instead of win->winGetFont()

Fixes tooltip text clipping at bottom when using Cyrillic/Unicode text (Issue #153).
Root cause: GadgetStaticTextSetFont updates gadget's DisplayString but not
window's m_font pointer, so win->winGetFont() returned old "Arial" instead of
"Arial Unicode MS", causing height underestimation for Cyrillic metrics.

GeneralsX @BugFix w1semannn 07/06/2026 Fix tooltip height clipping with Unicode fonts (Issue #153)
@fbraz3 fbraz3 force-pushed the fix/issue-144-clean branch from 80856cb to 4fb6292 Compare June 7, 2026 23:22
@fbraz3
Copy link
Copy Markdown
Owner Author

fbraz3 commented Jun 8, 2026

I believe now the tooltip clipping issue was solved. Not perfectly aligned but is seems all text are now visible.
image

Can you please tes from 27107941094 and confirm? thanks!

EDIT: I'm trying to fix alignment in build 27109976197, but it I not tested it on my local computer yet.

- Remove standalone static overrideTooltipGadgetFont function (from Cyrillic fix)
  that used old font's pointSize, causing font size mismatch
- Use ControlBar::overrideTooltipGadgetFont member function consistently for
  Name, Cost, and Description gadgets
- This ensures all gadgets use the same font size (12pt) for consistent layout
- Removes duplicate font override calls that could cause height calculation issues

Fixes tooltip text clipping and energy info misalignment (Issue #153).
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.

macOS: Cyrillic text labels not rendered (numbers work, English labels work)

2 participants