feat(libSceFreeType): support memory fonts and face cleanup #8247

Merged
santhoshkumar-dev merged 2 commits from upstream-pr/8247 into main 2026-10-21 12:03:14 +00:00
santhoshkumar-dev commented 2026-10-20 06:51:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-20T06:51:06Z.


What

libSceFreeType can load file-backed fonts but cannot load embedded font bytes or release any of its libraries and faces. Add FT_New_Memory_Face, FT_Done_Face and FT_Done_FreeType through the existing LP64 guest adapter.

Each library owns its guest face records. Face deletion releases the native face and its wrapper; library deletion lets FreeType close every remaining native face before releasing the wrappers. Face creation keeps a native face under RAII until guest setup succeeds. File and memory faces share this path, while memory faces borrow the caller's font buffer.

Guest face, size and glyph-slot generic finalizers run with the guest ABI and guest object addresses. They follow bundled FreeType's destruction order, including the face's glyph/size fields visible during callbacks. Negative-index font probes retain null glyph and size pointers when the native probe has none.

Behavior follows the bundled FreeType 2.13.3 face APIs and object destruction. The console's version, options, errors and finalizer ordering are unverified. The debt file records that gap and removes the now-resolved leak entry. Buffer sizes outside the host FT_Long range throw, including sizes of 2 GiB or more on Windows.

Tested

Windows 11 x64, WinLibs MinGW-w64 GCC 15.2.0 r7, Release, full project configured with BUILD_TESTING=ON.

  • cmake --build build --target guest_freetype_tests --parallel 8: passed.
  • ctest --test-dir build -R '^guest_freetype$' --output-on-failure: passed (0.06 s).
  • Changed C++ sources: -std=c++20 -Wall -Wextra -Werror -fsyntax-only: passed.
  • python tools/check_conventions.py --base origin/main: passed.
  • git diff --cached --check: passed before committing.

The regression compares memory-font records, outlines and rendered bitmaps with native FreeType; checks null arguments, invalid font/index inputs, negative-index probes and Windows size limits; compares face/size/slot finalizers with native callbacks during explicit face deletion and library shutdown; checks an independent library remains usable; and exercises empty-library destruction. Existing file-backed loading/rendering checks still pass.

No title, Linux runtime or console hardware tested. The full test suite was not run.

Refresh on 2026-10-21: rebased onto upstream 1381826358, clarified the Windows memory-size limit under Functional, and retained only the remaining gaps in the debt entry. Rebuilt the FreeType library and both test executables; guest_freetype and guest_freetype_charmap pass (0.08 s / 0.06 s), along with conventions. Production behavior is unchanged.

Compatibility validation (2026-10-21): temporarily combined this PR with #8286, #8289, #9045, #9054, #9064 and the charmap-metadata follow-up on main 3e91c8edf5. All system libraries built and all seven FreeType tests passed. The C++ changes merged cleanly; temporary CMake/debt resolutions were used only for this local compatibility check and are not published.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4932112655 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8247). Originally posted by [santhoshkumar-dev](https://github.com/santhoshkumar-dev) on 2026-10-20T06:51:06Z. --- ### What `libSceFreeType` can load file-backed fonts but cannot load embedded font bytes or release any of its libraries and faces. Add `FT_New_Memory_Face`, `FT_Done_Face` and `FT_Done_FreeType` through the existing LP64 guest adapter. Each library owns its guest face records. Face deletion releases the native face and its wrapper; library deletion lets FreeType close every remaining native face before releasing the wrappers. Face creation keeps a native face under RAII until guest setup succeeds. File and memory faces share this path, while memory faces borrow the caller's font buffer. Guest face, size and glyph-slot generic finalizers run with the guest ABI and guest object addresses. They follow bundled FreeType's destruction order, including the face's glyph/size fields visible during callbacks. Negative-index font probes retain null glyph and size pointers when the native probe has none. Behavior follows the bundled [FreeType 2.13.3 face APIs](https://github.com/freetype/freetype/blob/42608f77f20749dd6ddc9e0536788eaad70ea4b5/include/freetype/freetype.h) and [object destruction](https://github.com/freetype/freetype/blob/42608f77f20749dd6ddc9e0536788eaad70ea4b5/src/base/ftobjs.c). The console's version, options, errors and finalizer ordering are unverified. The debt file records that gap and removes the now-resolved leak entry. Buffer sizes outside the host `FT_Long` range throw, including sizes of 2 GiB or more on Windows. ### Tested Windows 11 x64, WinLibs MinGW-w64 GCC 15.2.0 r7, Release, full project configured with `BUILD_TESTING=ON`. - `cmake --build build --target guest_freetype_tests --parallel 8`: passed. - `ctest --test-dir build -R '^guest_freetype$' --output-on-failure`: passed (0.06 s). - Changed C++ sources: `-std=c++20 -Wall -Wextra -Werror -fsyntax-only`: passed. - `python tools/check_conventions.py --base origin/main`: passed. - `git diff --cached --check`: passed before committing. The regression compares memory-font records, outlines and rendered bitmaps with native FreeType; checks null arguments, invalid font/index inputs, negative-index probes and Windows size limits; compares face/size/slot finalizers with native callbacks during explicit face deletion and library shutdown; checks an independent library remains usable; and exercises empty-library destruction. Existing file-backed loading/rendering checks still pass. No title, Linux runtime or console hardware tested. The full test suite was not run. Refresh on 2026-10-21: rebased onto upstream `1381826358`, clarified the Windows memory-size limit under Functional, and retained only the remaining gaps in the debt entry. Rebuilt the FreeType library and both test executables; `guest_freetype` and `guest_freetype_charmap` pass (0.08 s / 0.06 s), along with conventions. Production behavior is unchanged. Compatibility validation (2026-10-21): temporarily combined this PR with #8286, #8289, #9045, #9054, #9064 and the charmap-metadata follow-up on main `3e91c8edf5`. All system libraries built and all seven FreeType tests passed. The C++ changes merged cleanly; temporary CMake/debt resolutions were used only for this local compatibility check and are not published. ### Checklist - [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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-20 06:51:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T06:51:43Z.


Progress report (1381826 → 303f15c)

📈 System libraries: 50.99% (+0.02%, +3 implemented functions)

✅ 3 implemented
Library Name
libSceFreeType FT_Done_Face_nid_postfix
libSceFreeType FT_Done_FreeType_nid_postfix
libSceFreeType FT_New_Memory_Face_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6285190378 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8247#issuecomment-6285190378). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T06:51:43Z. --- <!-- progress-report --> ### Progress report (1381826 → 303f15c) 📈 **System libraries**: 50.99% (+0.02%, +3 implemented functions) <details> <summary>✅ 3 implemented</summary> | Library | Name | | - | - | | libSceFreeType | `FT_Done_Face_nid_postfix` | | libSceFreeType | `FT_Done_FreeType_nid_postfix` | | libSceFreeType | `FT_New_Memory_Face_nid_postfix` | </details>
vittoriosalvadore commented 2026-10-20 07:42:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by vittoriosalvadore on 2026-10-20T07:42:39Z.


@santhoshkumar-dev Thank you for the lifecycle work. FT_Get_Kerning is now covered by #8558, so I will leave that API to its author and keep any future PR limited to point sizing. For the remaining debt overlap, may #8247 merge first?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6285980375 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8247#issuecomment-6285980375). Originally posted by [vittoriosalvadore](https://github.com/vittoriosalvadore) on 2026-10-20T07:42:39Z. --- @santhoshkumar-dev Thank you for the lifecycle work. FT_Get_Kerning is now covered by #8558, so I will leave that API to its author and keep any future PR limited to point sizing. For the remaining debt overlap, may #8247 merge first?
nikowolf123 commented 2026-10-20 22:04:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-20T22:04:26Z.


One wording issue in the new debt entry at docs/dev/debt/libSceFreeType.md#L7:

A font buffer size outside the host FT_Long range throws, excluding buffers of 2 GiB or more on Windows.

Read normally, "excluding" means "except", so this says a buffer of 2 GiB or more does not throw on Windows. The code does the opposite. FreeType's FT_Long is signed long (fttypes.h#L245), which is 32 bits with MinGW. So on Windows, FT_New_Memory_Face(library, buf, 0x80000000, 0, &face) fails the range check at Export.cpp#L127 and throws. The test asserts that throw (GuestFreeType.cpp#L268), and the PR description says "including sizes of 2 GiB or more on Windows". On Linux and macOS FT_Long is 64 bits, so the check never fires there.

I'd suggest this wording, which matches the code and the existing FT_New_Face note at libSceFreeType.md#L11:

-A font buffer size outside the host `FT_Long` range throws, excluding buffers of 2 GiB or more on Windows.
+On Windows, where FreeType's `long` is 32 bits, a font buffer size of 2 GiB or more, or below -2 GiB, throws.

This is a host limit rather than unknown console behaviour, so it may fit better in the Functional entry next to that FT_New_Face note.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6302780434 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8247#issuecomment-6302780434). Originally posted by [nikowolf123](https://github.com/nikowolf123) on 2026-10-20T22:04:26Z. --- One wording issue in the new debt entry at [docs/dev/debt/libSceFreeType.md#L7](https://github.com/boykopovar/AnyPS5/blob/30de287f9800b7224cdd4d513652d85ac31b4aca/docs/dev/debt/libSceFreeType.md#L7): > A font buffer size outside the host `FT_Long` range throws, excluding buffers of 2 GiB or more on Windows. Read normally, "excluding" means "except", so this says a buffer of 2 GiB or more does not throw on Windows. The code does the opposite. FreeType's `FT_Long` is `signed long` ([fttypes.h#L245](https://github.com/freetype/freetype/blob/42608f77f20749dd6ddc9e0536788eaad70ea4b5/include/freetype/fttypes.h#L245)), which is 32 bits with MinGW. So on Windows, `FT_New_Memory_Face(library, buf, 0x80000000, 0, &face)` fails the range check at [Export.cpp#L127](https://github.com/boykopovar/AnyPS5/blob/30de287f9800b7224cdd4d513652d85ac31b4aca/core/libs/prx/libSceFreeType/Export.cpp#L127) and throws. The test asserts that throw ([GuestFreeType.cpp#L268](https://github.com/boykopovar/AnyPS5/blob/30de287f9800b7224cdd4d513652d85ac31b4aca/core/libs/tests/GuestFreeType.cpp#L268)), and the PR description says "including sizes of 2 GiB or more on Windows". On Linux and macOS `FT_Long` is 64 bits, so the check never fires there. I'd suggest this wording, which matches the code and the existing `FT_New_Face` note at [libSceFreeType.md#L11](https://github.com/boykopovar/AnyPS5/blob/30de287f9800b7224cdd4d513652d85ac31b4aca/docs/dev/debt/libSceFreeType.md#L11): ```diff -A font buffer size outside the host `FT_Long` range throws, excluding buffers of 2 GiB or more on Windows. +On Windows, where FreeType's `long` is 32 bits, a font buffer size of 2 GiB or more, or below -2 GiB, throws. ``` This is a host limit rather than unknown console behaviour, so it may fit better in the Functional entry next to that `FT_New_Face` note.
adriadam10 commented 2026-10-21 12:04:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T12:04:58Z.


Checked the memory/file face lifecycle (ownership per library, finalizer order for size/slot/face against native FreeType 2.13.3, null glyph/size on negative-index probes), the FT_Long range throw and the debt entries (the Windows wording fix is in); the new test needs the new exports and compares against native FreeType; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6315457891 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8247#issuecomment-6315457891). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-21T12:04:58Z. --- Checked the memory/file face lifecycle (ownership per library, finalizer order for size/slot/face against native FreeType 2.13.3, null glyph/size on negative-index probes), the FT_Long range throw and the debt entries (the Windows wording fix is in); the new test needs the new exports and compares against native FreeType; merged.
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!8247
No description provided.