feat(libfreetype): implement the Multiple Masters getters #15442
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15442"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by VakzOs on 2026-11-03T10:11:25Z.
What
The legacy
libfreetypeexportsPS-iwpPa2tcandK9ZOPLPOqbYthrew. The verified NID name database names themFT_Get_MM_Blend_CoordinatesandFT_Get_MM_WeightVector, andtools/nid_names.pycomputes the same NIDs for those names. They are now implemented insrc/MultipleMasters.cpp.Both resolve the host
FT_Facebehind the guestFT_FaceRecfrom libSceFreeType and call the bundled FreeType 2.15.0. The console'sFT_Fixedis 64-bit and Windows' is 32-bit, so the values go through a native buffer and are copied back to the guest array only on success. The weight vector length is written back as FreeType writes it. Errors are FreeType's own, includingInvalid_Face_Handlefor a null face andInvalid_Argumentfor a face without Multiple Masters. FreeType is asked for at most 65536 entries, more than any face has axes or designs; guest entries beyond that repeat FreeType's own padding value, so a huge count needs no huge scratch array.Tested
Linux, GCC 13, Release: the new
guest_legacy_freetype_multiple_masterspasses. It opens FreeType's test fontsvarc-reset-only.ttf(one variation axis) andvarc-static-gvar.ttf(nofvar) through both the guest API and native FreeType. For counts 0, 1 and 3, and for weight vector lengths 0 and 2, it checks that results, copied values, untouched padding and lengths match native FreeType, with and without an output array. It also compares 65539 entries with native FreeType, which checks that the entries beyond the 65536-entry cap repeat FreeType's padding; this is an equivalence check, not a proof of the bound, since the uncapped version passes it too and a count nearUINT32_MAXwould need about 32 GiB with that version. It also checks the null-face result. Breaking the copy-back makes the test fail. The test needs FreeType's test fonts from the submodule, so it is registered only whenANYPS5_USE_SYSTEM_DEPSis off, as libSceFreeTypeOl does.python3 tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branchreports #15408 (libfreetype font metadata), for the same reasons as #15439: both addcore/libs/prx/libfreetype/CMakeLists.txtand touch adjacent lines. No export is shared.Not tested on hardware or with a title.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T11:38:35Z.
Review: APPROVED
Reviewed — approved
FT_Get_MM_Blend_Coordinates,FT_Get_MM_WeightVectorand the stackedFT_Gzip_Uncompress(from #15439) forward correctly to the bundled FreeType 2.15.0, and the new tests pass. The test fonts only have zero blend coordinates, so the Multiple Masters test does not check the values that get copied back.What I ran
Head
90223b33c2b4e213b30bba725b9a15cc15187b05,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged treeb1273630265df613b995fdd82cd0c1214c03f6bb. Debian 13 VM, GCC 14.2.0, Release, Ninja.Results
git diff --checkcheck_conventions.pylibs(script)main(guest_interfaces,guest_socket_options_multicast,unwrap_self_..._group,vector_constant_factor_tininess).guest_net_ctlis skipped onmaintoo.guest_legacy_freetype_gzipguest_legacy_freetype_multiple_masterspublic_headers*,guest_freetype_face_infoNegative control
The production sources are new files, and without the new
CMakeLists.txtthe tests are not even registered, so restoringmainproves nothing. I broke the code inside the merged tree instead:src/Gzip.cpp: I removed the*outputLength = lengthwrite-back.guest_legacy_freetype_gzipaborted (it fails, as it should).src/MultipleMasters.cpp, copy-back removed: I deleted both copy-back loops.guest_legacy_freetype_multiple_mastersaborted (it fails, as it should).src/MultipleMasters.cpp, zeros written: I made the copy-back write0instead ofnative[index].guest_legacy_freetype_multiple_mastersstill passed (see the first non-blocking finding).I then restored both files from the merged tree and rebuilt. Both tests pass again, and
git status --porcelainis empty.Findings
Blocking
None.
Non-blocking
The Multiple Masters test does not check the copied values.
core/libs/tests/GuestLegacyFreeTypeMultipleMasters.cpp:84expects every coordinate to be 0.varc-reset-only.ttfsits at its default instance, and the weight vector never succeeds on either font, which the debt entry says too. A copy-back that writes zeros, or truncatesFT_Fixed, therefore passes. That partly contradicts "Breaking the copy-back makes the test fail" in the description: removing the copy-back is caught, writing the wrong values is not.FT_Set_Var_Blend_Coordinates. The comparison would then use non-zero values.A guest-controlled count sizes the host allocation.
core/libs/prx/libfreetype/src/MultipleMasters.cpp:18and:29allocatenumCoords + 1(or*length + 1) hostFT_Fixedvalues before FreeType has checked the face. A bogus count such as0xFFFFFFFFthrowsstd::bad_alloc(32 GiB) through a VABI export. Native FreeType would just write into the guest's buffer. This is unlikely from a real title.T1_MAX_MM_AXIS/T1_MAX_MM_DESIGNS-sized buffer plus the guest count. Native FreeType's padding behaviour must stay the same.This PR also contains #15439's commits. The diff includes
de485286749aand557fcc76e754(FT_Gzip_Uncompress), and the description only mentions them throughDepends on: #15439. I reviewed them here as well: the FT_Memory bridge to the guest memory record and theFT_ULongrange check look correct, and the gzip test fails without the length write-back. After #15439 lands, rebase so this PR carries only the Multiple Masters commit.Not verified
FT_Fixed/FT_ULongare 32-bit: I did not build or run it. TheULONG_MAXbranch of the gzip test only compiles there.FT_Get_MM_WeightVectoron an Adobe Multiple Master font is not exercised, which the debt entry also says.libfreetypeandlibSceFreeTypeeach link their own static FreeType (--exclude-libs,ALL), and the getters run on a face created by the other copy. This works because both are built from the samefreetypetarget. I did not test it withANYPS5_USE_SYSTEM_DEPS=ON.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T12:23:17Z.
Review: APPROVED
Re-checked — approved
The new commit
bdc326089eaccaps the host scratch arrays of both Multiple Masters getters at 65536 entries and keeps FreeType's padding and*lenbehaviour. It adds a 65539-entry comparison against native FreeType and registers that test only whenANYPS5_USE_SYSTEM_DEPSis off. This resolves the one finding that touched the code. The other two findings are still open and are non-blocking.What changed since my last review
bdc326089eac("bound the Multiple Masters scratch arrays and skip their test with system deps"):src/MultipleMasters.cpp: FreeType is asked for at mostScratchLimit = 0x10000entries.native[used - 1], which is FreeType's padding value.nativeLengthuntouched, and FreeType's value otherwise.CheckLargeCountscompares 65539 entries with native FreeType, for both functions and both fonts.CMakeLists.txt: the Multiple Masters test is registered only whenANYPS5_USE_SYSTEM_DEPSis off, aslibSceFreeTypeOldoes for its own font-based test. Each test now gets its own WindowsPATHproperty.What I ran
Head
bdc326089eacc9b0d3fb0f8f656d0db14c6bd7e8,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged tree356b760655a7502b24e42fd8d7408732266f7055. Debian 13 VM, GCC 14.2.0, Release, Ninja.git diff --checkcheck_conventions.pylibs(script)mainfailures are unchanged.guest_net_ctlis skipped onmaintoo.guest_legacy_freetype_gzip,guest_legacy_freetype_multiple_masters,guest_freetype_face_infoguest_legacy_freetype_multiple_mastersaborted, so the test catches it*length = nativeLengthalways)guest_legacy_freetype_multiple_mastersaborted, so the test catches itgit status --porcelainemptyI also checked the new clamping against the bundled FreeType 2.15.0 sources (
src/base/ftmm.c,T1_Get_MM_BlendandT1_Get_MM_WeightVectorinsrc/type1/t1load.c, and the TrueType GX getter):0x8000for Type 1. Anfvaraxis count fits in 16 bits and Type 1 has at most 4 axes, so a 65536-entry request always ends in padding, and repeatingnative[used - 1]gives what native FreeType would write.requested < num_designs,used == requestedand FreeType writesnum_designsback.num_designs, which is at most 16. It can only equalusedwhenused == requested.len && !weightvectorcheck leavenativeLength == used, so the guest's length stays as it was.used - 1is never evaluated, because both loops run zero times.So
core/libs/prx/libfreetype/src/MultipleMasters.cpp:25,:36and:38match native FreeType in every case I traced.Previous findings
CheckLargeCountsadds coverage of the padding and of the length, but every coordinate is still 0. Line 97 ofcore/libs/tests/GuestLegacyFreeTypeMultipleMasters.cppstill expects zeros, and no non-default instance is set. A copy-back that writes zeros would still pass. The suggestion stands: callFT_Set_Var_Blend_Coordinateson both faces before comparing.ScratchLimitcaps the scratch vector at 65537FT_Fixedvalues (lines 21 and 32). The 65539-entry test and the two mutations above show that the behaviour beyond the cap still matches native FreeType.de485286749aand557fcc76e754are unchanged. Rebase once #15439 lands.New findings
Blocking
None.
Non-blocking
None.
Not verified
FT_FixedandFT_ULongare 32-bit: I did not build or run it, including the splitENVIRONMENT_MODIFICATIONproperties.ANYPS5_USE_SYSTEM_DEPS=ON: I did not configure it. I only read the CMake to confirm that the Multiple Masters test is not registered there and that the gzip test still is.FT_Get_MM_WeightVectoron an Adobe Multiple Master font is still not exercised, as the debt entry says.