feat(libfreetype): implement the Multiple Masters setters #15447

Merged
VakzOs merged 7 commits from upstream-pr/15447 into main 2026-11-07 05:09:00 +00:00
VakzOs commented 2026-11-03 10:54:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by VakzOs on 2026-11-03T10:54:40Z.


What

The legacy libfreetype exports OGVR5us9otU and V476bsxEylk threw. The verified NID name database names them FT_Set_MM_WeightVector and FT_Set_Named_Instance, and tools/nid_names.py computes the same NIDs for those names. They are now implemented next to the getters from #15442 in src/MultipleMasters.cpp.

Both call the bundled FreeType 2.15.0 on the host FT_Face behind the guest face, so their results are FreeType's own. Both setters change the face (face_flags, face_index, metrics through MVAR), so the guest FT_FaceRec, its size and its glyph slot are then refreshed with libSceFreeType's existing SyncFace.

The NID patcher strips C++ exports, so libSceFreeType now exports FreeTypeSyncFace_nid_no_patch, a C wrapper around SyncFace. libSceFreeTypeOptOl already calls FreeTypePfr*_nid_no_patch this way. libfreetype links libSceFreeType, and the patched module imports only that helper from it.

Weights cross as the console's 64-bit FT_Fixed. On Windows, a weight outside 32 bits returns Invalid_Argument without calling FreeType. Only as many weights as the face has designs are read (the count comes from FT_Get_MM_WeightVector), which is what FreeType's Type 1 driver reads, so a large len never reads past the guest array.

Tested

Linux, GCC 13, Release: guest_legacy_freetype_multiple_masters passes with the new cases. On FreeType's varc-reset-only.ttf (variable) and varc-static-gvar.ttf (no fvar), it compares results with native FreeType:

  • FT_Set_Named_Instance for instances 0, 1 and 2, after a blend has set FT_FACE_FLAG_VARIATION;
  • FT_Set_MM_WeightVector with lengths 0, 2 and UINT32_MAX (on a two-entry array) and a null array;
  • null faces.

Before each call the test corrupts the guest record. It then checks that face_flags, face_index and ascender match the host face again, and that a successful named instance clears the variation flag. Removing the refresh makes the test fail. All 52 guest_freetype* and guest_legacy_freetype* tests pass.

The patched libfreetype.prx exports OGVR5us9otU and V476bsxEylk, has no FT_* exports, and its only libSceFreeType import, FreeTypeSyncFace_nid_no_patch, is exported by the patched libSceFreeType.prx. python3 tools/check_conventions.py --base origin/main passes.

FreeType has no TrueType weight vector setter and no Adobe Multiple Master font is available, so a successful FT_Set_MM_WeightVector is not exercised. docs/dev/debt/libfreetype.md records this.

tools/pr_overlap.py --branch reports:

  • #15408, for the same reasons as #15439;
  • #10606 and #10609, which also edit libSceFreeType/include/GuestObjects.hpp. That file merges cleanly with both; their remaining conflicts are in debt files this PR does not touch, and they already conflict with main.

Not tested on hardware or with a title.

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: #15439, #15442, #15444 (land order: #15408, #15439, #15442, #15444, then this PR)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5135984752 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15447). Originally posted by [VakzOs](https://github.com/VakzOs) on 2026-11-03T10:54:40Z. --- ### What The legacy `libfreetype` exports `OGVR5us9otU` and `V476bsxEylk` threw. The [verified NID name database](https://github.com/zecoxao/sce_symbols/blob/2883963a0a514ba6e77407a08ef4730a65e88254/aerolib.csv) names them `FT_Set_MM_WeightVector` and `FT_Set_Named_Instance`, and `tools/nid_names.py` computes the same NIDs for those names. They are now implemented next to the getters from #15442 in `src/MultipleMasters.cpp`. Both call the bundled FreeType 2.15.0 on the host `FT_Face` behind the guest face, so their results are FreeType's own. Both setters change the face (`face_flags`, `face_index`, metrics through `MVAR`), so the guest `FT_FaceRec`, its size and its glyph slot are then refreshed with libSceFreeType's existing `SyncFace`. The NID patcher strips C++ exports, so libSceFreeType now exports `FreeTypeSyncFace_nid_no_patch`, a C wrapper around `SyncFace`. libSceFreeTypeOptOl already calls `FreeTypePfr*_nid_no_patch` this way. `libfreetype` links `libSceFreeType`, and the patched module imports only that helper from it. Weights cross as the console's 64-bit `FT_Fixed`. On Windows, a weight outside 32 bits returns `Invalid_Argument` without calling FreeType. Only as many weights as the face has designs are read (the count comes from `FT_Get_MM_WeightVector`), which is what FreeType's Type 1 driver reads, so a large `len` never reads past the guest array. ### Tested Linux, GCC 13, Release: `guest_legacy_freetype_multiple_masters` passes with the new cases. On FreeType's `varc-reset-only.ttf` (variable) and `varc-static-gvar.ttf` (no `fvar`), it compares results with native FreeType: - `FT_Set_Named_Instance` for instances 0, 1 and 2, after a blend has set `FT_FACE_FLAG_VARIATION`; - `FT_Set_MM_WeightVector` with lengths 0, 2 and `UINT32_MAX` (on a two-entry array) and a null array; - null faces. Before each call the test corrupts the guest record. It then checks that `face_flags`, `face_index` and `ascender` match the host face again, and that a successful named instance clears the variation flag. Removing the refresh makes the test fail. All 52 `guest_freetype*` and `guest_legacy_freetype*` tests pass. The patched `libfreetype.prx` exports `OGVR5us9otU` and `V476bsxEylk`, has no `FT_*` exports, and its only libSceFreeType import, `FreeTypeSyncFace_nid_no_patch`, is exported by the patched `libSceFreeType.prx`. `python3 tools/check_conventions.py --base origin/main` passes. FreeType has no TrueType weight vector setter and no Adobe Multiple Master font is available, so a successful `FT_Set_MM_WeightVector` is not exercised. `docs/dev/debt/libfreetype.md` records this. `tools/pr_overlap.py --branch` reports: - #15408, for the same reasons as #15439; - #10606 and #10609, which also edit `libSceFreeType/include/GuestObjects.hpp`. That file merges cleanly with both; their remaining conflicts are in debt files this PR does not touch, and they already conflict with `main`. Not tested on hardware or with a title. ### 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: #15439, #15442, #15444 (land order: #15408, #15439, #15442, #15444, then this PR) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!15447
No description provided.