Repository navigation
fix(libSceFont): keep horizontal writing on a single baseline - #5209
Conversation
adriadam10
left a comment
There was a problem hiding this comment.
Thanks for tracking this down. Before merging I need three things:
- A test that reproduces it on Linux. The PR has no test, and the libSceFont tests (3/3) pass the same with and without the change. Please add one that walks a short horizontal string through the writing step API (
sceFontWritingRefersRenderStep/sceFontWritingGetRenderMetrics) and pinsstep.yconstant across characters,advanceY == 0, andGlyphMetrics.width/heightequal to the glyph's own values (including the first character at pen(0, 0)). A manual run on one title is not enough to merge a behaviour change. - Why the reference is wrong. shadPS4's
FillWritingMetricsFromGlyph(src/core/libraries/font/font.cpp:145) does what the code you removed did (advanceY = Vertical.advance,GlyphMetrics.width/height = step.x/y), with a comment saying the real library keeps the anchor at the pen position. Please say which source you follow for zeroing them, and whether the real library's step keeps the glyph's width/height. - Possible root cause.
docs/dev/debt/libSceFont.md:23notes that our vertical metrics (FreeType's vertical advance) are not confirmed on a title. If the real vertical advance of a CJK face is small or 0 for horizontal text, the drift may come from that value rather than from advancing the pen by it. Please check which of the two explains the dialog, and make the debt line say so.
|
Test that fails on current Test (added to
Real firmware (PS4 firmware 11.00 libSceFont loaded on Windows, not the PS5 library): the steps of "Ab c" come back Game: Ape Academy 2 (PPSA11132, PSP Classics) on current Test diffdiff --git a/core/libs/tests/GuestSystemFont.cpp b/core/libs/tests/GuestSystemFont.cpp
index ec2f80785..d8fc39a43 100644
--- a/core/libs/tests/GuestSystemFont.cpp
+++ b/core/libs/tests/GuestSystemFont.cpp
@@ -25,6 +25,12 @@ int APS5_VABI sceFontSetScalePixel(FontHandle, float, float);
int APS5_VABI sceFontGetCharGlyphMetrics(FontHandle, std::uint32_t, FontGlyphMetrics*);
int APS5_VABI sceFontGetHorizontalLayout(FontHandle, FontHorizontalLayout*);
const void* APS5_VABI sceFontSelectLibraryFt(int);
+int APS5_VABI sceFontTextSourceInit(FontTextSource*, const void*, std::uint32_t, FontTextParseFunction, void*);
+int APS5_VABI sceFontCreateString(const FontMemory*, FontTextSource*, const FontCreateStringDetail*, FontString*);
+int APS5_VABI sceFontDestroyString(FontString*);
+FontTextCharacter* APS5_VABI sceFontStringRefersTextCharacters(FontString, std::uint32_t*);
+int APS5_VABI sceFontWritingInit(FontWriting*, FontString, const FontTextCharacter*);
+const FontWritingStep* APS5_VABI sceFontWritingRefersRenderStep(FontWriting*);
}
static void Check(bool value, int line) {
@@ -124,6 +130,24 @@ static float AdvanceOf(FontHandle font, std::uint32_t code) {
return metrics.Horizontal.advance;
}
+struct ParsedText {
+ const char* text;
+ std::size_t at;
+ FontHandle font;
+};
+
+static std::int32_t APS5_VABI ParseText(FontTextSource* source, void** order, FontTextParseResult* result) {
+ auto* parsed = static_cast<ParsedText*>(source->textObject);
+ *order = const_cast<char*>(parsed->text + parsed->at);
+ if (parsed->text[parsed->at] == 0) {
+ result->Terminate.terminateCode = 0;
+ return 0;
+ }
+ result->FontCode.font = parsed->font;
+ result->FontCode.code = static_cast<unsigned char>(parsed->text[parsed->at++]);
+ return 1;
+}
+
int main() {
constexpr std::uint32_t EuropeanLight = 0x180700C3u;
constexpr std::uint32_t EuropeanBold = 0x180700C7u;
@@ -180,6 +204,27 @@ int main() {
FontHorizontalLayout layout{};
Require(sceFontGetHorizontalLayout(font, &layout) == SCE_FONT_OK && layout.baselineOffset > 0.0f && layout.lineAdvance >= layout.baselineOffset);
+ ParsedText parsed{"AA", 0, font};
+ FontTextSource source{};
+ Require(sceFontTextSourceInit(&source, parsed.text, 2, ParseText, &parsed) == SCE_FONT_OK);
+ FontString string = nullptr;
+ Require(sceFontCreateString(&memory, &source, nullptr, &string) == SCE_FONT_OK && string != nullptr);
+ std::uint32_t characterCount = 0;
+ FontTextCharacter* characters = sceFontStringRefersTextCharacters(string, &characterCount);
+ Require(characters != nullptr && characterCount == 2);
+ FontWriting writing{};
+ Require(sceFontWritingInit(&writing, string, characters) == SCE_FONT_OK);
+ const FontWritingStep* step = sceFontWritingRefersRenderStep(&writing);
+ Require(step != nullptr);
+ const FontWritingStep first = *step;
+ step = sceFontWritingRefersRenderStep(&writing);
+ Require(step != nullptr);
+ const FontWritingStep second = *step;
+ Require(first.x == 0.0f && first.y == 0.0f && first.advanceX == 70.0f && first.advanceY == 0.0f);
+ Require(second.x == 70.0f && second.y == 0.0f && second.advanceX == 70.0f && second.advanceY == 0.0f);
+ Require(second.GlyphMetrics.Vertical.advance == 100.0f);
+ Require(sceFontDestroyString(&string) == SCE_FONT_OK);
+
FontHandle again = nullptr;
Require(sceFontOpenFontSet(library, EuropeanBold, 2, nullptr, &again) == SCE_FONT_OK && again != font);
FontHandle instance = nullptr;🤖 Generated with Claude Code |
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Independent confirmation on a second Sony classics emulator: Syphon Filter (PPSA06323) 01.000.003, a PS1 classics title. Linux 7.2.9, Radeon RX 6650 XT, RADV Mesa 26.2.4, GCC Release. Setup
Result at the emulator's controller-layout screen, 95 s into each run:
Before/after crop: 20261021-pr5209-PPSA06323-before-after.png Both runs hold 59.94 FPS for 183 s with no driver stop. I scripted only Cross, so neither went past the screen, which asks for START; this checks the text layout only. The PR conflicts with current AI-assisted testing and report: yes, Claude Code. |
|
Test run (not a code review). I tried to merge this PR onto current |
|
This also fixes a PS1 classic: Ridge Racer (PPSA31372 01.000.002), which runs in Sony's PS1HD emulator. Setup
On The step's With this PR merged on Merge conflict. The PR now conflicts with
|
|
Test run (not a code review). Tekken Dark Resurrection (PPSA31371, PSPHD), Windows 11, RTX 5090, Release build. This PR still conflicts with current
It needs a rebase before it can merge. |
Horizontal writing steps advanced the pen by the glyph's vertical advance on every character, so text drifted down diagonally (steepest for CJK fonts, whose vertical advance is roughly the em size). The step's GlyphMetrics width/height were also overwritten with the pen position, leaving the first glyph of each run invisible at pen (0, 0). Every supported writing form (0x10/0x11/0x12) is horizontal, so the pen must advance only along X and the step reports the real glyph width/height.
Test adapted from JAB-dev's comment on boykopovar#5209. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
6912742 to
35f8545
Compare
|
Thanks for the fix, and to everyone who tested it. Since there was no push after the last review, I added the missing pieces on your branch:
Checked on top of that: the drift came from advancing the pen, not from the vertical advance value; confirmed on several titles by @JAB-dev, @JJenkx, @XatiX and @klosixgaming-arch; merged. |
What
Horizontal writing steps in libSceFont advanced the pen by the glyph's vertical
advance on every character, so text drifted down diagonally — steepest for CJK
fonts, whose vertical advance is roughly the em size. The step's
GlyphMetricswidth/height were also overwritten with the pen position, leaving the first
glyph of each run invisible at pen
(0, 0).Every supported writing form (
0x10,0x11,0x12) is horizontal, so the penmust advance only along X and the step must keep the real glyph width/height.
The vertical advance stays available as a metric through
sceFontGetCharGlyphMetrics.Tested
Windows 11 x64. Current
mainboots the PSP Classics title Ape Academy 2(UCES00302) to a playable state; the emulator's own UI dialog ("Confirm Rewind":
Rewind / Cancel / Yes) rendered its text with each glyph stepped diagonally
downwards and dropped the first glyph of every word. After this fix, rebuilt
libSceFont.prxandlibSceFont-module.prxwere redeployed and the dialog textrenders on a single baseline with all glyphs present; the title remains
playable. No other libSceFont callers regressed in this test.
Checklist
main; no equivalent open PR implements this fixdocs/dev/debt/libSceFont.md