font: kerning and requested-scale glyph metrics (My First Gran Turismo menu text) #1030

Closed
github-bot wants to merge 3 commits from gh-pr/1030/head into gh-pr/1030/base
Owner

@⁠defektu on GitHub · 2026-10-04 01:02 UTC · original
defektu:pr/mfgt-font → main · +59 −0 · 1 files · 3 commits · closed without merging

This is one of a few PRs that together get My First Gran Turismo (PPSA24156) running: #1030 (font), #1031 (hle), #1032 (tess), #1033 (host), #1034 (shader), and the draft #1035 (mixed sample counts), which the game also needs to get past the loading screen after "Start" (without it the game stops with "mixed color/depth sample counts are unsupported"). Each PR builds and passes the tests on its own; the title only works with all of them.

Checked by hand on a combined branch (all of the above) on an RTX 5060 Ti, Windows 11, clean save data: intro, title screen (car, lighting, reflections), main menu and the License Center screen. The individual PRs were not run in the game on their own.

Note: on current main this title waits at the "Sign in to PlayStation Network" dialog until Cancel is pressed; that comes from the sign-in dialog change, not from this PR.

Commits

font: answer FontGetCharGlyphMetrics at the requested scale, not the bitmap clamp
font: add FontGetKerning and FontDettachDeviceCacheBuffer

Body

Menu text in My First Gran Turismo (PPSA24156) was wrong in two ways:

  • FontGetCharGlyphMetrics answered with the clamped bitmap size instead of the size at the requested scale.
  • FontGetKerning was missing, so strings were laid out with spaced letters ("S a v i n g").

Adds FontGetKerning (writes the stb_truetype kern advance into the FontKerning struct) and
FontDettachDeviceCacheBuffer.

Testing: builds, 23 test executables pass. Text checked on the My First Gran Turismo title screen (combined branch).

🤖 Generated with Claude Code

**@⁠defektu** on GitHub · 2026-10-04 01:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1030) `defektu:pr/mfgt-font` → `main` · +59 −0 · 1 files · 3 commits · closed without merging This is one of a few PRs that together get My First Gran Turismo (PPSA24156) running: #1030 (font), #1031 (hle), #1032 (tess), #1033 (host), #1034 (shader), and the draft #1035 (mixed sample counts), which the game also needs to get past the loading screen after "Start" (without it the game stops with "mixed color/depth sample counts are unsupported"). Each PR builds and passes the tests on its own; the title only works with all of them. Checked by hand on a combined branch (all of the above) on an RTX 5060 Ti, Windows 11, clean save data: intro, title screen (car, lighting, reflections), main menu and the License Center screen. The individual PRs were not run in the game on their own. Note: on current `main` this title waits at the "Sign in to PlayStation Network" dialog until `Cancel` is pressed; that comes from the sign-in dialog change, not from this PR. **Commits** ``` font: answer FontGetCharGlyphMetrics at the requested scale, not the bitmap clamp font: add FontGetKerning and FontDettachDeviceCacheBuffer ``` **Body** Menu text in My First Gran Turismo (PPSA24156) was wrong in two ways: - `FontGetCharGlyphMetrics` answered with the clamped bitmap size instead of the size at the requested scale. - `FontGetKerning` was missing, so strings were laid out with spaced letters ("S a v i n g"). Adds `FontGetKerning` (writes the stb_truetype kern advance into the `FontKerning` struct) and `FontDettachDeviceCacheBuffer`. **Testing:** builds, 23 test executables pass. Text checked on the My First Gran Turismo title screen (combined branch). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
stb_font_pixel_height clamped every scale to FONT_BITMAP_MAX_DIM (128). Titles that set a very
large pixel scale and normalise the returned metrics by it (My First Gran Turismo calls SetScalePixel(10000, 10000)
and divides by 10000) therefore got advances and boxes that were ~80x too small, so their text
laid out as dots. Metrics now use the exact requested scale through a thread-local scope guard;
glyph bitmaps keep the clamped size.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
(cherry picked from commit 280be66258b615a0cccd8e9c658660d52032f7a7)
(cherry picked from commit 25be88b5e82887ca8037910f58d1c8a42e7a2cf9)
Without kerning the menu text was rendered with spaced letters ("S a v i n g").

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
(cherry picked from commit 821004ac64e9fa2c937f4f653d50eabc5fc9a581)
FontGetKerning computed the pair adjustment at the bitmap-clamped scale while
FontGetCharGlyphMetrics answers at the scale the title asked for. At the
10000 pixel scale the title sets, the kerning came out far smaller than the
metrics it is added to.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:40:57 +00:00
github-bot closed this pull request 2026-11-26 09:40:57 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-04 01:04 UTC · original · edited 2026-10-04 01:50 UTC

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b29b9e3b-7fdf-42e4-ab8b-f71f4884fcda
📥 Commits

Reviewing files that changed from the base of the PR and between 555f501ec0 and dd8fc6058e.

📒 Files selected for processing (1)
  • src/libs/libFont.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/libs/libFont.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.


📝 Walkthrough

Walkthrough

FontGetCharGlyphMetrics and FontGetKerning use the font’s requested pixel scale for TTF metric calculations. The change adds and registers FontGetKerning and FontDettachDeviceCacheBuffer. Kerning results are initialized to zero, and the horizontal offset is calculated when supported TTF data is available.

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to dd8fc

This change fixes spaced-out menu text by returning glyph metrics at the requested scale and adding kerning. No merge-blocking risk was identified.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 555f5

Requested-scale metrics bypass the former size cap but still convert scaled glyph bounds to signed integers. Large caller-supplied sizes can exceed that representation. Bitmap storage remains bounded, and no privilege gain or memory-corruption exploit was demonstrated.

Retained concerns

  • Medium · security · inferred: The requested-scale contract removes a numerical bound before host-side signed-integer glyph-box computation. Caller-controlled finite scales and font geometry can produce out-of-range conversions or overflowing box differences where the previous path used a capped scale. This weakens failure containment; downstream allocation misuse and exploitable memory corruption are not established.
Security review details

Security Blast Radius

  • inferred — The supported exposure is guest-controlled font requests reaching host-side numerical computation. Potential failure affects execution of those requests; broader consumer allocation effects and cross-system propagation remain unresolved.

Security Findings and Attack Paths

  • inferred — A caller can set a large finite height and request glyph metrics. The new exact-scale path multiplies font coordinates by that scale before signed-integer conversion and subtraction. Values can exceed the integer range despite being representable at the former pixel-height conversion. This is a numerical failure-containment concern, not a demonstrated memory-corruption attack.

Trust Boundaries and Controls

  • observed — Exact metric retrieval does not invoke the local bitmap-writing path. Bitmap generation retains fixed storage and bounded output dimensions, providing counterevidence against a direct bitmap overflow caused by the new metrics mode.

Hardening Proposals

  • proposed — Preserve requested-scale semantics while checking scaled coordinate and dimension ranges before signed-integer conversion or subtraction. Define a deterministic result for unrepresentable metrics rather than relying on the bitmap-size clamp.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the font kerning and requested-scale glyph metrics changes. The game-specific context in parentheses is relevant.
Description check ✅ Passed The description explains the font changes, their effect on menu text, and the reported build, test, and in-game validation results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-04 01:04 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1030#issuecomment-5975234241) · edited 2026-10-04 01:50 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1030?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `b29b9e3b-7fdf-42e4-ab8b-f71f4884fcda` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 555f501ec00a8b1bb953cb0eab4972de866e0eec and dd8fc6058e2b9a7489c6bda9b907102ea29468b2. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/libs/libFont.cpp` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary> * src/libs/libFont.cpp </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough `FontGetCharGlyphMetrics` and `FontGetKerning` use the font’s requested pixel scale for TTF metric calculations. The change adds and registers `FontGetKerning` and `FontDettachDeviceCacheBuffer`. Kerning results are initialized to zero, and the horizontal offset is calculated when supported TTF data is available. </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"dd8fc6058e2b9a7489c6bda9b907102ea29468b2" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `dd8fc` <!-- final_review_risk_coverage:{"sourceCommitId":"dd8fc6058e2b9a7489c6bda9b907102ea29468b2","coveredCommitId":"dd8fc6058e2b9a7489c6bda9b907102ea29468b2","kind":"reviewed"} --> This change fixes spaced-out menu text by returning glyph metrics at the requested scale and adding kerning. No merge-blocking risk was identified. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🟡 Moderate_ · up to `555f5` Requested-scale metrics bypass the former size cap but still convert scaled glyph bounds to signed integers. Large caller-supplied sizes can exceed that representation. Bitmap storage remains bounded, and no privilege gain or memory-corruption exploit was demonstrated. **Retained concerns** - **Medium · security · inferred:** The requested-scale contract removes a numerical bound before host-side signed-integer glyph-box computation. Caller-controlled finite scales and font geometry can produce out-of-range conversions or overflowing box differences where the previous path used a capped scale. This weakens failure containment; downstream allocation misuse and exploitable memory corruption are not established. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — The supported exposure is guest-controlled font requests reaching host-side numerical computation. Potential failure affects execution of those requests; broader consumer allocation effects and cross-system propagation remain unresolved. **Security Findings and Attack Paths** - _inferred_ — A caller can set a large finite height and request glyph metrics. The new exact-scale path multiplies font coordinates by that scale before signed-integer conversion and subtraction. Values can exceed the integer range despite being representable at the former pixel-height conversion. This is a numerical failure-containment concern, not a demonstrated memory-corruption attack. **Trust Boundaries and Controls** - _observed_ — Exact metric retrieval does not invoke the local bitmap-writing path. Bitmap generation retains fixed storage and bounded output dimensions, providing counterevidence against a direct bitmap overflow caused by the new metrics mode. **Hardening Proposals** - _proposed_ — Preserve requested-scale semantics while checking scaled coordinate and dimension ranges before signed-integer conversion or subtraction. Define a deterministic result for unrepresentable metrics rather than relying on the bitmap-size clamp. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 1 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly identifies the font kerning and requested-scale glyph metrics changes. The game-specific context in parentheses is relevant. | | Description check | ✅ Passed | The description explains the font changes, their effect on menu text, and the reported build, test, and in-game validation results. | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1030)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -2084,0 +2126,4 @@
auto* font = static_cast<FontState*>(font_handle);
if (font != nullptr && ensure_stb_font(font)) {
const float scale = stb_font_scale(font);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-04 01:04 UTC · original · edited 2026-10-04 01:50 UTC

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use the requested scale for kerning.

If FontSetScalePixel sets a height above 128, FontGetCharGlyphMetrics uses that height, but FontGetKerning uses the 128-pixel clamp. At the reported height of 10,000, the pair adjustment is therefore much smaller than the corresponding glyph metrics. Calculate kerning with the same requested-scale rule so the title can place the next glyph correctly.

✅ Addressed in commit dd8fc60

**@⁠coderabbitai[bot]** on GitHub · 2026-10-04 01:04 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1030#discussion_r4175621617) · edited 2026-10-04 01:50 UTC _🎯 Functional Correctness_ | _🟠 Major_ | _⚡ Quick win_ **Use the requested scale for kerning.** If `FontSetScalePixel` sets a height above 128, `FontGetCharGlyphMetrics` uses that height, but `FontGetKerning` uses the 128-pixel clamp. At the reported height of 10,000, the pair adjustment is therefore much smaller than the corresponding glyph metrics. Calculate kerning with the same requested-scale rule so the title can place the next glyph correctly. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:397e321ef91b6af9a6a33cae --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit dd8fc60
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-04 01:04 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 352cd811-a35b-4501-97c4-d822a491c538
📥 Commits

Reviewing files that changed from the base of the PR and between db17585277 and 555f501ec0.

📒 Files selected for processing (1)
  • src/libs/libFont.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-04 01:04 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1030#pullrequestreview-5403691748) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `352cd811-a35b-4501-97c4-d822a491c538` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between db1758527751125592f57bf02f29616fa0643159 and 555f501ec00a8b1bb953cb0eab4972de866e0eec. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/libs/libFont.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Author
Owner

@⁠Nmzik on GitHub · 2026-10-04 22:53 UTC · original

@⁠defektu credited

**@⁠Nmzik** on GitHub · 2026-10-04 22:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1030#issuecomment-5985333390) @⁠defektu credited

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.