feat(libSceFreeType): implement FT_Get_Kerning #8558

Merged
Filip722 merged 7 commits from upstream-pr/8558 into main 2026-10-23 12:13:22 +00:00
Filip722 commented 2026-10-20 16:33:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Filip722 on 2026-10-20T16:33:56Z.


What

FT_Get_Kerning is missing from the existing FreeType guest bridge, so imports of its known NID cannot resolve to a guest-safe implementation. This adds pair kerning through the bundled FreeType 2.13.3 backend.

  • Translate guest faces and copy native results into the LP64 guest vector, including on hosts with 32-bit long.
  • Preserve FreeType's scaling, rounding, missing-pair behavior, null-argument errors and output-write behavior. SFNT left glyph indices above the 16-bit range return a zero vector, preserving LP64 lookup behavior on Windows instead of truncating the pair key; right indices retain native behavior.
  • Extend the existing generated-font test with a negative kerning pair and record the unverified console ABI/version assumptions.

The name/NID LPtlB241JSg comes from the PS5 3.20 inventory. Behavior follows bundled FreeType's implementation. No game unblock or hardware equivalence is claimed.

Tested

Debian GNU/Linux 13 x86-64, GCC 15.2.0, Release with BUILD_TESTING=ON, using bundled FreeType 2.13.3.

All system libraries built successfully with cmake --build build --target libs guest_freetype_tests --parallel 2. The final focused CTest passed, and the packaged libSceFreeType.prx exports LPtlB241JSg. Changed-translation-unit checks and repository conventions passed.

The focused guest_freetype regression compares the adapter with native FreeType and checks explicit expected negative values for unscaled, fitted and unfitted kerning. It covers small-size rounding, absent pairs, a font without a kerning table, out-of-range glyph indices, null arguments and preserved output on a null face. A temporary always-zero output mutation failed; restoring the adapter passed.

The review follow-up adds (0x10001, 1) and (0x7FFF0001, 1) zero-result checks in all four modes at both tested sizes, plus (1, 0x10001) to preserve the distinct right-index behavior. The updated focused Linux test, packaged-library rebuild and conventions checks passed.

Rebased onto 7d7b097407 on 2026-10-21. The existing kerning implementation and regression cases are unchanged; tests now use upstream’s shared font fixture, and both debt entries are retained. Rebuilt the FreeType library and both focused test executables; guest_freetype and guest_freetype_charmap passed, along with conventions and whitespace checks.

Windows and PS5 hardware were not tested. The existing guest layout and backend-version assumptions remain documented in the library debt file.

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:4939028553 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8558). Originally posted by [Filip722](https://github.com/Filip722) on 2026-10-20T16:33:56Z. --- ### What `FT_Get_Kerning` is missing from the existing FreeType guest bridge, so imports of its known NID cannot resolve to a guest-safe implementation. This adds pair kerning through the bundled FreeType 2.13.3 backend. - Translate guest faces and copy native results into the LP64 guest vector, including on hosts with 32-bit `long`. - Preserve FreeType's scaling, rounding, missing-pair behavior, null-argument errors and output-write behavior. SFNT left glyph indices above the 16-bit range return a zero vector, preserving LP64 lookup behavior on Windows instead of truncating the pair key; right indices retain native behavior. - Extend the existing generated-font test with a negative kerning pair and record the unverified console ABI/version assumptions. The name/NID `LPtlB241JSg` comes from the [PS5 3.20 inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceFreeTypeOt.c). Behavior follows [bundled FreeType's implementation](https://github.com/freetype/freetype/blob/42608f77f20749dd6ddc9e0536788eaad70ea4b5/src/base/ftobjs.c#L3610-L3683). No game unblock or hardware equivalence is claimed. ### Tested Debian GNU/Linux 13 x86-64, GCC 15.2.0, Release with `BUILD_TESTING=ON`, using bundled FreeType 2.13.3. All system libraries built successfully with `cmake --build build --target libs guest_freetype_tests --parallel 2`. The final focused CTest passed, and the packaged `libSceFreeType.prx` exports `LPtlB241JSg`. Changed-translation-unit checks and repository conventions passed. The focused `guest_freetype` regression compares the adapter with native FreeType and checks explicit expected negative values for unscaled, fitted and unfitted kerning. It covers small-size rounding, absent pairs, a font without a kerning table, out-of-range glyph indices, null arguments and preserved output on a null face. A temporary always-zero output mutation failed; restoring the adapter passed. The review follow-up adds `(0x10001, 1)` and `(0x7FFF0001, 1)` zero-result checks in all four modes at both tested sizes, plus `(1, 0x10001)` to preserve the distinct right-index behavior. The updated focused Linux test, packaged-library rebuild and conventions checks passed. Rebased onto `7d7b097407` on 2026-10-21. The existing kerning implementation and regression cases are unchanged; tests now use upstream’s shared font fixture, and both debt entries are retained. Rebuilt the FreeType library and both focused test executables; `guest_freetype` and `guest_freetype_charmap` passed, along with conventions and whitespace checks. Windows and PS5 hardware were not tested. The existing guest layout and backend-version assumptions remain documented in the library debt file. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
nikowolf123 commented 2026-10-20 19:04:43 +00:00 (Migrated from github.com)

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


On Windows, a left glyph index above 0xFFFF returns the kerning of a different glyph pair instead of {0, 0}.

Export.cpp#L103 passes leftGlyph to FreeType unchanged. FreeType's kern lookup builds its key as ((FT_ULong)(g1) << 16) | (g2) (ttkern.c#L39). FT_ULong is unsigned long (fttypes.h#L256), which is 32 bits on Windows, so the top 16 bits of the left index are dropped there. Where long is 64 bits, the key is above 0xFFFFFFFF and matches no pair. That covers Linux and the LP64 console library that the existing debt entry assumes.

I built the test's kern font (one pair, (1, 1) = -73) against the bundled FreeType 2.13.3 on both hosts. At 100 ppem, FT_Get_Kerning(face, 0x10001, 1, mode, &v) gives:

  • Linux: x = 0 in every mode
  • Windows (WinLibs GCC): x = -73 unscaled, -448 default and -467 unfitted. 0x7FFF0001 gives the same values.

The test's 0xFFFFFFFF case does not catch this, because its truncated key is 0xFFFF0001. Real fonts never have glyph indices this high. Still, the library already narrows out-of-range face indices and character codes the way the 64-bit build does. Placed after the null check on line 101, this returns what the 64-bit build returns. The FT_IS_SFNT check leaves other font formats to FreeType:

if (sizeof(FT_ULong) < 8 && leftGlyph > 0xFFFF && FT_IS_SFNT(owner->host)) {
    *kerning = {0, 0};
    return 0;
}

With this change, Windows matched Linux on ten pairs, including the ones above, in all four of the test's modes at 100 and 12 ppem. Adding a separate (0x10001, 1) check that expects {0, 0} lets the Windows CI job cover this. That check can't go into the existing two-sided loop: FreeType itself matches (1, 0x10001) to the (1, 1) pair on every host.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298907191 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8558#issuecomment-6298907191). Originally posted by [nikowolf123](https://github.com/nikowolf123) on 2026-10-20T19:04:43Z. --- On Windows, a left glyph index above `0xFFFF` returns the kerning of a different glyph pair instead of `{0, 0}`. [Export.cpp#L103](https://github.com/boykopovar/AnyPS5/blob/3012f7db00f9a1f8ffc89026a033a31d08b60dc1/core/libs/prx/libSceFreeType/Export.cpp#L103) passes `leftGlyph` to FreeType unchanged. FreeType's `kern` lookup builds its key as `((FT_ULong)(g1) << 16) | (g2)` ([ttkern.c#L39](https://github.com/freetype/freetype/blob/42608f77f20749dd6ddc9e0536788eaad70ea4b5/src/sfnt/ttkern.c#L39)). `FT_ULong` is `unsigned long` ([fttypes.h#L256](https://github.com/freetype/freetype/blob/42608f77f20749dd6ddc9e0536788eaad70ea4b5/include/freetype/fttypes.h#L256)), which is 32 bits on Windows, so the top 16 bits of the left index are dropped there. Where `long` is 64 bits, the key is above `0xFFFFFFFF` and matches no pair. That covers Linux and the LP64 console library that the [existing debt entry](https://github.com/boykopovar/AnyPS5/blob/3012f7db00f9a1f8ffc89026a033a31d08b60dc1/docs/dev/debt/libSceFreeType.md#L7) assumes. I built the test's kern font (one pair, (1, 1) = -73) against the bundled FreeType 2.13.3 on both hosts. At 100 ppem, `FT_Get_Kerning(face, 0x10001, 1, mode, &v)` gives: - Linux: `x = 0` in every mode - Windows (WinLibs GCC): `x = -73` unscaled, `-448` default and `-467` unfitted. `0x7FFF0001` gives the same values. The test's `0xFFFFFFFF` case does not catch this, because its truncated key is `0xFFFF0001`. Real fonts never have glyph indices this high. Still, the library already narrows out-of-range face indices and character codes the way the 64-bit build does. Placed after the null check on line 101, this returns what the 64-bit build returns. The `FT_IS_SFNT` check leaves other font formats to FreeType: ```cpp if (sizeof(FT_ULong) < 8 && leftGlyph > 0xFFFF && FT_IS_SFNT(owner->host)) { *kerning = {0, 0}; return 0; } ``` With this change, Windows matched Linux on ten pairs, including the ones above, in all four of the test's modes at 100 and 12 ppem. Adding a separate `(0x10001, 1)` check that expects `{0, 0}` lets the Windows CI job cover this. That check can't go into the existing two-sided loop: FreeType itself matches `(1, 0x10001)` to the (1, 1) pair on every host.
Filip722 commented 2026-10-20 19:07:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Filip722 on 2026-10-20T19:07:46Z.


Thanks for the cross-platform reproduction. Fixed in 13521a96f. SFNT left indices above std::numeric_limits<std::uint16_t>::max() now produce {0, 0} after null validation. The guard applies on both hosts, preserving LP64 behavior and allowing the Linux test to exercise it; other font formats still delegate to FreeType.

Added (0x10001, 1) and (0x7FFF0001, 1) checks in all four modes at 100 and 12 ppem, plus (1, 0x10001) to ensure the right-index behavior remains unchanged. The focused Linux test, packaged-library rebuild and conventions checks passed. I have not run Windows locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298974329 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8558#issuecomment-6298974329). Originally posted by [Filip722](https://github.com/Filip722) on 2026-10-20T19:07:46Z. --- Thanks for the cross-platform reproduction. Fixed in 13521a96f. SFNT left indices above `std::numeric_limits<std::uint16_t>::max()` now produce `{0, 0}` after null validation. The guard applies on both hosts, preserving LP64 behavior and allowing the Linux test to exercise it; other font formats still delegate to FreeType. Added `(0x10001, 1)` and `(0x7FFF0001, 1)` checks in all four modes at 100 and 12 ppem, plus `(1, 0x10001)` to ensure the right-index behavior remains unchanged. The focused Linux test, packaged-library rebuild and conventions checks passed. I have not run Windows locally.
ycbuzi commented 2026-10-21 06:58:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T06:58:35Z.


Windows run of 256ab6609a merged onto main ec7eacc62d (8474a1fd04, clean), one of the hosts the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON.

Built libSceFreeType and guest_freetype_tests with no errors or warnings; ctest --repeat until-fail:2 on guest_freetype: passes on both repeats. Windows is the LLP64 host where the left index above 0xFFFF picked another pair's kerning; at this head the 0x10001 and 0x7FFF0001 left-index checks are part of guest_freetype, so they ran here. Not run: the negative control against main's library, a title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310062479 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8558#issuecomment-6310062479). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T06:58:35Z. --- Windows run of 256ab6609a merged onto `main` ec7eacc62d (8474a1fd04, clean), one of the hosts the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, `BUILD_TESTING=ON`. Built `libSceFreeType` and `guest_freetype_tests` with no errors or warnings; `ctest --repeat until-fail:2` on `guest_freetype`: passes on both repeats. Windows is the LLP64 host where the left index above `0xFFFF` picked another pair's kerning; at this head the `0x10001` and `0x7FFF0001` left-index checks are part of `guest_freetype`, so they ran here. Not run: the negative control against `main`'s library, a title.
Ondra97 commented 2026-10-22 03:31:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-22T03:31:30Z.


I opened #9588 for FT_Glyph_Get_CBox. I declared #8558 for merge order because the included outline dependency and this PR share a debt insertion. Retain both kerning and control-box entries during the rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331994400 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8558#issuecomment-6331994400). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-22T03:31:30Z. --- I opened #9588 for FT_Glyph_Get_CBox. I declared #8558 for merge order because the included outline dependency and this PR share a debt insertion. Retain both kerning and control-box entries during the rebase.
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!8558
No description provided.