Skip to content

fix(font): keep Arabic and Thai text on one baseline (AnyPS5 #5209 backport) - #474

Merged
imnotsharingmyname merged 1 commit into
imnotsharingmyname:mainfrom
mauroalvare:agent06c/font-baseline-fix
Dec 5, 2026
Merged

imnotsharingmyname merged 1 commit into
imnotsharingmyname:mainfrom
mauroalvare:agent06c/font-baseline-fix

Conversation

@mauroalvare

@mauroalvare mauroalvare commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Update: I added repeat runs of the exact patch (no trace build), including a level.
They also corrected my first Arabic result. The first version of this description said Arabic prompts render "on one line, right to left". They are on one line, but the letters are unjoined, most labels read left to right, and strings with a space show a single glyph.
This PR fixes the Thai report (#91). For Arabic (#18), it removes the diagonal layout but does not make the text readable. Details are under Risks and limits.

Problem

With the game language set to Arabic or Thai, text laid out through libSceFont's writing API comes out one glyph per line. Each character lands lower and further right than the one before, so a short prompt turns into a diagonal column (#18, #91). The "invisible letters" part of the original Arabic report no longer reproduces on v1.2.33. The letters are drawn, just in the wrong places.

On v1.2.33 the Thai game doesn't get that far. It stops 9–21 s after boot with its own Out of graphics memory [Onion] assert: a 1,051,392-byte request against a full 184 MiB pool (192,581,280 of 192,937,984 bytes used, 2630 allocations). This happened in 5 of 5 boots. English and the other Latin languages are not affected.

Cause

The game lays out Arabic and Thai strings with sceFontCreateString and sceFontWritingRefersRenderStep, using writing forms 0x11 and 0x12. Latin text uses the per-glyph API and never reaches this code.

On the pinned AnyPS5 base (319621b), FillWritingMetricsFromGlyph set each step's advanceY to the glyph's vertical advance. The pen therefore moved down one line per character, even though every writing form the library accepts is horizontal. The function also overwrote the step's GlyphMetrics.width/height with the pen position. As a result, the first glyph of a run reported 0 × 0 and the run's render metrics grew with the drift.

A libSceFont call trace showed the drift in every string that took this path (numbers below). The game sizes its text surfaces from these metrics. With the fix, the median Thai text surface height drops from 1271 px to 118 px (Arabic: from 1081 px to 124 px). That is consistent with the Onion pool running out, but I did not instrument the pool itself.

Fix

Upstream AnyPS5 fixed this in boykopovar/AnyPS5#5209 (410e3b8b21, plus the test in 35f854562e), merged just after our pinned base. Source/anyps5/0042-fix-libSceFont-keep-horizontal-writing-on-one-baseline.patch backports it unchanged:

  • advanceY is 0 for writing steps.
  • Each step keeps the glyph's own metrics.

The patch also carries the upstream regression test (in guest_system_font) and the debt note. No AstroHybrid code or other library changes.

Two open PRs (#453 and #420) already use 0041, so this patch is 0042. It applies on top of both.

Testing

  • Patch series: 319621b + Source/anyps5/0001…0042 applies with git am --3way (as in Tools/build.ps1) and with git am --3way --keep-cr (as in Tools/linux/prepare-anyps5.sh). Source/anyps5-linux/0001 applies on top. The resulting tree is identical to the one I built and tested. The series also applies after the 0041 patches from Add PlayStation trophies and in-game trophy notifications #453 and Set up and play from a PS5 fake package (.pkg) or image (.ffpfsc, .ffpfs, .ffpkg, .exfat) read in place #420.
  • Build: AnyPS5 Release with MinGW GCC 15.2 (WinLibs UCRT), producing NID-patched libSceFont-module.prx, libSceFont.prx and libSceFont.native.prx as shipped. ctest -R "^(guest_font|guest_font_writing_line|guest_system_font)$" passes 3/3, including the new test.
  • In game, setup: v1.2.33 runtime on an RTX 5070 Ti with Windows 11, with the three font libraries swapped in.
  • Trace runs, with and without the patch: both builds included a local libSceFont call trace, which is not part of this PR. Each run booted to the world map and opened the pause menu.
Language Without the patch With the patch
Arabic (21) Pen drifts in 53 of 53 strings (up to 1690 px); median run height 624 px (max 1942); one glyph per line on screen Drift in 0 of 44 strings; median run height 78 px (max 254); one-word labels on one line (see Risks and limits for what is still wrong)
Thai (27) Pen drifts in 24 of 24 strings (up to 2094 px); median run height 1215 px (max 6919); Onion assert at 21 s Drift in 0 of 29 strings; median run height 76 px (max 351); ran the full 160 s and exited with code 0; prompts on one line with vowels and tone marks in place
English (1) Not run with the trace build; text is fine with the release libraries Does not use the writing API (no strings traced); prompts unchanged
  • Repeat runs: the patch's exact libraries (commit f821388c32, no trace), 8 runs. Boot runs lasted 160 s to the world map and pause menu, and 100 s for English. Level runs lasted 150 s in Sky Garden and opened the level pause menu.
    • Thai: 3 boots and 1 level run. All ran to the end with exit code 0 and no Onion assert. The world map prompts, the pause menu, and the level's title and pause menu (Continue, Restart, Leave planet) render correctly.
    • Arabic: 2 boots and 1 level run. All ran to the end with exit code 0. The text has the problems listed under Risks and limits.
    • English: 1 boot, unchanged.
    • Totals with the patch: Thai ran to the end in 5 of 5 runs, against 5 of 5 crashes without it.

Risks and limits

  • Arabic is still not right. The patch fixes the layout bug that both languages share. After it, Arabic shows these problems in the world map, pause menu and level pause menu:

    • Letters are drawn in their isolated forms, not joined.
    • The button prompts (Boost, Scan, Zoom, Options) run left to right, so the word reads backwards. The selected pill (Close, Continue) runs right to left.
    • Strings that contain a space show a single glyph. This hits Restart, Leave planet and the △ prompt (Title screen). The level title also shows a single glyph; I didn't capture its string.

    In the trace, each word of such a string gets a correct run on one baseline. AnyPS5's libSceFont reports bidi level 0 for every character and applies no Arabic contextual forms, which fits the first two problems. I haven't found the cause of the third, so treat it as unexplained. All three need a separate change. Without this patch, the same text is a one-glyph-per-line column, so this is still an improvement for Arabic but not a fix for Arabic text rendering bug (letters invisible, only diacritics shown) #18.

  • Coverage: Thai was checked in 5 runs with the patch (4 boots, 1 level), Arabic in 4 (3 boots, 1 level) and English in 2 boots, all on one PC. Long menus such as settings and other levels were not checked.

  • Scope: the change only affects writing steps. Latin text doesn't use them in this game, and the library only accepts horizontal writing forms, so nothing depended on the old advanceY.

  • Release files: the shipped .prx files only change once libSceFont is rebuilt from the series.

Refs #91 (Thai) and #18 (Arabic, partial). I'd leave closing #91 until a release build has been checked, and #18 should stay open.

🤖 Generated with Claude Code

Add Source/anyps5/0042, a backport of upstream AnyPS5 #5209. On the pinned
base, sceFontWritingRefersRenderStep moved the pen down by each glyph's
vertical advance, so text the game lays out through the writing API (Arabic
and Thai) drifted one glyph per line. It also reported each run's extent as
the pen position, which made Thai text surfaces several times too tall.
The patch keeps the pen on one baseline for the horizontal writing forms and
includes the upstream regression test.

Refs imnotsharingmyname#18, imnotsharingmyname#91.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants