feat(libSceFreeTypeOt): implement FT_Select_Metrics, FT_Request_Metrics and FT_Match_Size #15053

Merged
noamroger merged 5 commits from upstream-pr/15053 into main 2026-11-09 08:17:16 +00:00
noamroger commented 2026-11-02 12:35:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by noamroger on 2026-11-02T12:35:41Z.


What

libSceFreeTypeOt exports three sceFreeTypeOtUnknown_* stubs whose NIDs are the FreeType size helpers: Z8KG6700sw4 FT_Select_Metrics, z9Wsaf34JA4 FT_Request_Metrics and zE0V+0aouZ4 FT_Match_Size (checked with tools/nid_names.py compute_nid). They only read and write public FT_FaceRec / FT_SizeRec fields, so this PR ports them from FreeType 2.4.12 ftobjs.c, the version the module is already dated to in its debt file (the three functions are identical in 2.4.11), and removes the three stubs.

  • New src/SizeMetrics.cpp and include/SizeMetrics.hpp, on the existing GuestFaceRec, GuestSizeRequestRec and GuestBitmapSize layouts from libSceFreeType.
  • Grid-fitted metrics (GRID_FIT_METRICS), the five request types, the CELL rule, the SCALES shortcut, the resolution rounding of FT_REQUEST_WIDTH/HEIGHT, and the 0x07 / 0x17 / 0x23 errors of FT_Match_Size.
  • FT_MulFix, FT_DivFix and FT_MulDiv steps throw before any write on inputs where the 32-bit and FT_LONG64 builds of 2.4.12 can disagree, the same rule as the module's existing FT_MulDiv_No_Round. Null pointers FreeType would dereference, a strike index out of range and signed overflow also throw.
  • A debt entry lists these limits and the 2.13.3 differences (Divide_By_Zero and ppem range errors in FT_Request_Metrics, zero-size rejection in FT_Match_Size).

Tested

Linux x86-64, GCC 13, full build. The new guest_freetype_ot_size_metrics test covers each request type, the resolution path, a negative width, faces without outlines, scalable and bitmap strikes, every FT_Match_Size result, and that a throwing request leaves the metrics untouched. Expected values come from FreeType 2.4.12 (tag VER-2-4-12, src/base/ftbase.c) compiled on the same machine. Outside the repository, a differential run fed 3 000 000 random faces and requests to this code and to that FreeType build, once in the default 32-bit mode and once with FT_LONG64: the 2 634 957 non-throwing cases match exactly in both builds, and none of the 164 897 throwing cases writes the metrics. All 47 guest_freetype* tests pass, and the patched libSceFreeTypeOt.prx exports the three NIDs. tools/check_conventions.py --base origin/main passes. Not tested on a PS5.

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 (textual overlap only with #11613, #12370 and #12814 in libSceFreeTypeOt Export.cpp and its debt file; none of the 1 804 open PRs touches these three NIDs)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5120405643 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15053). Originally posted by [noamroger](https://github.com/noamroger) on 2026-11-02T12:35:41Z. --- ### What libSceFreeTypeOt exports three `sceFreeTypeOtUnknown_*` stubs whose NIDs are the FreeType size helpers: `Z8KG6700sw4` FT_Select_Metrics, `z9Wsaf34JA4` FT_Request_Metrics and `zE0V+0aouZ4` FT_Match_Size (checked with `tools/nid_names.py compute_nid`). They only read and write public `FT_FaceRec` / `FT_SizeRec` fields, so this PR ports them from FreeType 2.4.12 `ftobjs.c`, the version the module is already dated to in its debt file (the three functions are identical in 2.4.11), and removes the three stubs. - New `src/SizeMetrics.cpp` and `include/SizeMetrics.hpp`, on the existing `GuestFaceRec`, `GuestSizeRequestRec` and `GuestBitmapSize` layouts from libSceFreeType. - Grid-fitted metrics (`GRID_FIT_METRICS`), the five request types, the CELL rule, the SCALES shortcut, the resolution rounding of `FT_REQUEST_WIDTH/HEIGHT`, and the 0x07 / 0x17 / 0x23 errors of `FT_Match_Size`. - FT_MulFix, FT_DivFix and FT_MulDiv steps throw before any write on inputs where the 32-bit and FT_LONG64 builds of 2.4.12 can disagree, the same rule as the module's existing FT_MulDiv_No_Round. Null pointers FreeType would dereference, a strike index out of range and signed overflow also throw. - A debt entry lists these limits and the 2.13.3 differences (Divide_By_Zero and ppem range errors in `FT_Request_Metrics`, zero-size rejection in `FT_Match_Size`). ### Tested Linux x86-64, GCC 13, full build. The new `guest_freetype_ot_size_metrics` test covers each request type, the resolution path, a negative width, faces without outlines, scalable and bitmap strikes, every `FT_Match_Size` result, and that a throwing request leaves the metrics untouched. Expected values come from FreeType 2.4.12 (tag VER-2-4-12, `src/base/ftbase.c`) compiled on the same machine. Outside the repository, a differential run fed 3 000 000 random faces and requests to this code and to that FreeType build, once in the default 32-bit mode and once with FT_LONG64: the 2 634 957 non-throwing cases match exactly in both builds, and none of the 164 897 throwing cases writes the metrics. All 47 `guest_freetype*` tests pass, and the patched `libSceFreeTypeOt.prx` exports the three NIDs. `tools/check_conventions.py --base origin/main` passes. Not tested on a PS5. ### 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 (textual overlap only with #11613, #12370 and #12814 in libSceFreeTypeOt Export.cpp and its debt file; none of the 1 804 open PRs touches these three NIDs) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 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!15053
No description provided.