feat(libSceFreeType): implement the six FreeType functions OpenOrbis samples use #6376

Merged
Get-fix merged 1 commit from upstream-pr/6376 into main 2026-10-18 23:48:40 +00:00
Get-fix commented 2026-10-15 13:34:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-15T13:34:15Z.


What

PS4 homebrew built with the OpenOrbis toolchain draws text through the PS4 libSceFreeType. The OpenOrbis font, keyboard, threading, system and SDL2 samples import six of its functions and stop at start-up without them: FAIL: unresolved ELF import GNsiLzm4SH8 (FT_Init_FreeType), j-uMQE+unFY (FT_New_Face), lJxMIwj81SQ (FT_Set_Pixel_Sizes), obnSzeb-KXk (FT_Get_Char_Index), M156RuYoUbU (FT_Load_Glyph) and TCRmigbq7lc (FT_Render_Glyph).

This adds libSceFreeType with those six functions on top of the bundled FreeType 2.13.3.

  • Layout: the guest reads FreeType's structures directly, compiled for LP64, where FT_Long and FT_Pos are 64 bits. On Windows they are 32 bits, so the guest gets copies of the face, size, charmap and glyph slot in the LP64 layout, refreshed after each call that changes them. The offsets are checked with static_assert and match what the font sample reads: face->glyph at 0x98, slot->advance at 0x80, slot->bitmap at 0x98, slot->bitmap_left at 0xc0. Outline points are copied as 64-bit coordinates, and edits the guest makes to them are written back before FT_Render_Glyph.
  • Paths: FT_New_Face resolves the guest path, as libSceFont does, and opens the file from memory.
  • Argument handling follows FreeType: the order of the argument checks and their error codes; the face index masked to 31 bits and sign before it is narrowed; character codes truncated to 32 bits.
  • Exports: the bundled FreeType's own functions are kept out of the library's exports (--exclude-libs, as libSceSsl does). Another FreeType function a title imports still fails at start-up instead of resolving to a host function with the Windows calling convention.

The limits, such as private fields that are null, faces that are never freed and macOS exports, are in the new docs/dev/debt/libSceFreeType.md. Part of the PS4 homebrew work tracked in #3093.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, full build with BUILD_TESTING=ON, on main 9811e9d4b:

  • The new guest_freetype test writes a one-glyph TrueType font to app0/ and opens it through the guest path /app0/font.ttf. It loads the same bytes with the host FreeType and compares every mirrored field of the face, size, charmap and slot, before and after rendering: metrics, bitmap bytes, outline points, tags and contours. It also checks:
    • the error codes for a null path, a null library, a missing file and a null aface;
    • a face index of 0x180000000 opening face 0 and 0x80000001 failing as index 1;
    • FT_Get_Char_Index(face, 0x100000041) returning the glyph of A;
    • an outline moved one pixel by the guest rendering one pixel to the right;
    • replaced outline arrays throwing.
  • Each of these makes the test fail: not passing the bitmap buffer; swapping the advance; not converting the outline points; not writing guest outline edits back; narrowing the face index without FreeType's mask; not refreshing the size metrics or the glyph slot; not setting the active charmap; opening the guest path unresolved; reporting a missing file with another error.
  • The patched libSceFreeType.prx exports the six NIDs and none of FreeType's own functions.
  • OpenOrbis samples on main 92cdc7b62 with #5990 to #5994, #5138 and a local change that answers the Linux TIOCGWINSZ (0x5413) with ENOTTY, as #5569 does:
    • font, keyboard, threading and SDL2 now start and draw their text: font draws "Hello, World!" in two sizes, and SDL2 draws its score, its game-over text and a debug overlay at 58 FPS.
    • The system sample imports the same six functions but was not run here, because Windows Defender flags its converted executable with a machine-learning heuristic.
    • The nine samples that started before still start.
  • Full ctest of that build: every test passes except four. prx_thread_local_destructors and agc_driver_store_over_untracked fail the same way on main 92cdc7b62 without these changes; agc_driver_preparation_scope_settle and guest_raise_exception pass when run alone.
  • tools/check_conventions.py --base origin/main passes.

Not tested on Linux or macOS.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none for the code; the samples also need #5990 to #5994
  • Unblocks: OpenOrbis PS4 toolchain samples (font, keyboard, threading, system, SDL2), #3093
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4874121228 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6376). Originally posted by [Get-fix](https://github.com/Get-fix) on 2026-10-15T13:34:15Z. --- ### What PS4 homebrew built with the OpenOrbis toolchain draws text through the PS4 `libSceFreeType`. The OpenOrbis font, keyboard, threading, system and SDL2 samples import six of its functions and stop at start-up without them: `FAIL: unresolved ELF import GNsiLzm4SH8` (`FT_Init_FreeType`), `j-uMQE+unFY` (`FT_New_Face`), `lJxMIwj81SQ` (`FT_Set_Pixel_Sizes`), `obnSzeb-KXk` (`FT_Get_Char_Index`), `M156RuYoUbU` (`FT_Load_Glyph`) and `TCRmigbq7lc` (`FT_Render_Glyph`). This adds `libSceFreeType` with those six functions on top of the bundled FreeType 2.13.3. - **Layout:** the guest reads FreeType's structures directly, compiled for LP64, where `FT_Long` and `FT_Pos` are 64 bits. On Windows they are 32 bits, so the guest gets copies of the face, size, charmap and glyph slot in the LP64 layout, refreshed after each call that changes them. The offsets are checked with `static_assert` and match what the font sample reads: `face->glyph` at 0x98, `slot->advance` at 0x80, `slot->bitmap` at 0x98, `slot->bitmap_left` at 0xc0. Outline points are copied as 64-bit coordinates, and edits the guest makes to them are written back before `FT_Render_Glyph`. - **Paths:** `FT_New_Face` resolves the guest path, as libSceFont does, and opens the file from memory. - **Argument handling follows FreeType:** the order of the argument checks and their error codes; the face index masked to 31 bits and sign before it is narrowed; character codes truncated to 32 bits. - **Exports:** the bundled FreeType's own functions are kept out of the library's exports (`--exclude-libs`, as libSceSsl does). Another FreeType function a title imports still fails at start-up instead of resolving to a host function with the Windows calling convention. The limits, such as private fields that are null, faces that are never freed and macOS exports, are in the new `docs/dev/debt/libSceFreeType.md`. Part of the PS4 homebrew work tracked in #3093. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, full build with `BUILD_TESTING=ON`, on `main` `9811e9d4b`: - The new `guest_freetype` test writes a one-glyph TrueType font to `app0/` and opens it through the guest path `/app0/font.ttf`. It loads the same bytes with the host FreeType and compares every mirrored field of the face, size, charmap and slot, before and after rendering: metrics, bitmap bytes, outline points, tags and contours. It also checks: - the error codes for a null path, a null library, a missing file and a null `aface`; - a face index of `0x180000000` opening face 0 and `0x80000001` failing as index 1; - `FT_Get_Char_Index(face, 0x100000041)` returning the glyph of `A`; - an outline moved one pixel by the guest rendering one pixel to the right; - replaced outline arrays throwing. - Each of these makes the test fail: not passing the bitmap buffer; swapping the advance; not converting the outline points; not writing guest outline edits back; narrowing the face index without FreeType's mask; not refreshing the size metrics or the glyph slot; not setting the active charmap; opening the guest path unresolved; reporting a missing file with another error. - The patched `libSceFreeType.prx` exports the six NIDs and none of FreeType's own functions. - OpenOrbis samples on `main` `92cdc7b62` with #5990 to #5994, #5138 and a local change that answers the Linux `TIOCGWINSZ` (0x5413) with `ENOTTY`, as #5569 does: - font, keyboard, threading and SDL2 now start and draw their text: font draws "Hello, World!" in two sizes, and SDL2 draws its score, its game-over text and a debug overlay at 58 FPS. - The system sample imports the same six functions but was not run here, because Windows Defender flags its converted executable with a machine-learning heuristic. - The nine samples that started before still start. - Full ctest of that build: every test passes except four. `prx_thread_local_destructors` and `agc_driver_store_over_untracked` fail the same way on `main` `92cdc7b62` without these changes; `agc_driver_preparation_scope_settle` and `guest_raise_exception` pass when run alone. - `tools/check_conventions.py --base origin/main` passes. Not tested on Linux or macOS. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none for the code; the samples also need #5990 to #5994 - [x] Unblocks: OpenOrbis PS4 toolchain samples (font, keyboard, threading, system, SDL2), #3093 - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-15 13:35:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T13:35:05Z.


Progress report (0e4ea13 → 38fd195)

📈 System libraries: 88.71% (+0.01%, +6 implemented functions)

✅ 6 implemented
Library Name
libSceFreeType FT_Get_Char_Index_nid_postfix
libSceFreeType FT_Init_FreeType_nid_postfix
libSceFreeType FT_Load_Glyph_nid_postfix
libSceFreeType FT_New_Face_nid_postfix
libSceFreeType FT_Render_Glyph_nid_postfix
libSceFreeType FT_Set_Pixel_Sizes_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6193362589 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6376#issuecomment-6193362589). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T13:35:05Z. --- <!-- progress-report --> ### Progress report (0e4ea13 → 38fd195) 📈 **System libraries**: 88.71% (+0.01%, +6 implemented functions) <details> <summary>✅ 6 implemented</summary> | Library | Name | | - | - | | libSceFreeType | `FT_Get_Char_Index_nid_postfix` | | libSceFreeType | `FT_Init_FreeType_nid_postfix` | | libSceFreeType | `FT_Load_Glyph_nid_postfix` | | libSceFreeType | `FT_New_Face_nid_postfix` | | libSceFreeType | `FT_Render_Glyph_nid_postfix` | | libSceFreeType | `FT_Set_Pixel_Sizes_nid_postfix` | </details>
jotitadev commented 2026-10-15 20:04:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T20:04:17Z.

Review: COMMENTED


Linux run (Ubuntu 26.04, Intel i7-8700, GCC 15.2, full build, non-GPU tests), head 38fd195e9 merged onto main 44df21632.

  • The new library configures, builds and passes NID patching; guest_freetype passes (no early exit; the whole main runs, exit 0).
  • No red run: the library is new, so the test cannot build without it.

Non-GPU suite (ctest -E "^agc"): same result as main; only file_writer_binary and file_writer_text fail, and they fail on main too on this machine (Ubuntu 26.04 coreutils).

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5539187544 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6376#pullrequestreview-5539187544). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-15T20:04:17Z. **Review:** COMMENTED --- Linux run (Ubuntu 26.04, Intel i7-8700, GCC 15.2, full build, non-GPU tests), head `38fd195e9` merged onto `main` `44df21632`. - The new library configures, builds and passes NID patching; `guest_freetype` passes (no early exit; the whole `main` runs, exit 0). - No red run: the library is new, so the test cannot build without it. Non-GPU suite (`ctest -E "^agc"`): same result as `main`; only `file_writer_binary` and `file_writer_text` fail, and they fail on `main` too on this machine (Ubuntu 26.04 coreutils). Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Get-fix commented 2026-10-15 23:26:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-15T23:26:35Z.


Thanks for the Linux run and the NID patching check, @jotitadev.

AI-assisted: yes (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6204396382 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6376#issuecomment-6204396382). Originally posted by [Get-fix](https://github.com/Get-fix) on 2026-10-15T23:26:35Z. --- Thanks for the Linux run and the NID patching check, @jotitadev. AI-assisted: yes (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!6376
No description provided.