feat(libfreetype): implement FT_Face_Properties and FT_Palette_Set_Foreground_Color #15444
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15444"
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:19:43Z.
What
The legacy
libfreetypeexportsVKuZXhyjtooandNbFQEYieSS0threw. The verified NID name database names themFT_Face_PropertiesandFT_Palette_Set_Foreground_Color, andtools/nid_names.pycomputes the same NIDs for those names. They are now implemented insrc/FaceSettings.cpp.Both resolve the host
FT_Facebehind the guestFT_FaceRecfrom libSceFreeType and call the bundled FreeType 2.15.0 on it. Properties use the console's 16-byteFT_Parameter(a 64-bitFT_ULongtag and a data pointer). They are converted and passed to FreeType one at a time, so, as in FreeType, nothing after the first rejected entry is read and no scratch array is allocated. On Windows a tag above 32 bits becomes 0 and is rejected as unknown, the same result as on Linux. The colour is the 4-byte BGRAFT_Colorpassed by value. Results are FreeType's own:Unimplemented_FeatureforFT_PARAM_TAG_LCD_FILTER_WEIGHTS, because subpixel rendering is disabled;Invalid_Argumentfor an unknown tag and for a non-zero count with no array.One difference: a null face returns
Invalid_Face_HandlefromFT_Face_Properties. FreeType would dereference it.docs/dev/debt/libfreetype.mdrecords the unverified console version and build options, and that rendering with these settings is not tested.Tested
Linux, GCC 13, Release: the new
guest_legacy_freetype_face_settingspasses. It opens FreeType's test fontvarc-reset-only.ttfthrough the guest API and checks the host face's state after each call:UINT32_MAXon a two-entry array whose second tag is unknown, which stops there;The test includes FreeType's private headers and uses the submodule's test fonts, so it is registered only when
ANYPS5_USE_SYSTEM_DEPSis off, as libSceFreeTypeOl does. Swapping the colour channels or truncating tags to 32 bits makes the test fail. The patched module exportsVKuZXhyjtooandNbFQEYieSS0and noFT_*symbols.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 mashingaan on 2026-11-03T10:30:21Z.
Review: COMMENTED
One Windows-specific boundary issue: this guest wrapper accepts 64-bit lengths, but
FT_ULongisunsigned long, which is 32-bit on Windows. Both casts here can silently truncate values aboveULONG_MAXbefore FreeType receives them. Please reject either unrepresentable length before casting so Windows does not interpret a different input size or output capacity than the guest supplied. A focused Windows check atULONG_MAX + 1would cover this boundary.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T11:36:45Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The wrappers behave like the bundled FreeType 2.15.0, and the new tests pass and fail when the production code is mutated. One problem blocks: the new face-settings test includes FreeType's private
internal/headers without a guard, so it cannot compile in the documentedANYPS5_USE_SYSTEM_DEPS=ONbuild.What I ran
Head
c6c86c1a942e94ea047276b60f1bd747142cc5cc,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged with--no-ffin a clean worktree. The diff also carries the commits of the stacked #15439 (gzip) and #15442 (Multiple Masters), so this review covers all three.Results
git diff --checkcheck_conventions.pyguest_legacy_freetype_gzipguest_legacy_freetype_multiple_mastersguest_legacy_freetype_face_settingsmaintoo (guest_interfaces,guest_socket_options_multicast,unwrap_self_..._group,vector_constant_factor_tininess), andguest_net_ctlis skipped onmaintoo. None of these comes from this PR.Negative control
The production files are new, so restoring
mainonly removes the functions and the test would fail to link, which proves nothing. I mutatedsrc/FaceSettings.cppinstead, in the two ways the description names:FT_Color{color.red, color.green, color.blue, color.alpha}):guest_legacy_freetype_face_settingsfails (Subprocess aborted).HostTagreturnsstatic_cast<std::uint32_t>(tag)): the test fails (Subprocess aborted).After that I restored the merged file and rebuilt. All three tests pass again, and
git status --porcelainis empty.Findings
Blocking
The face-settings test cannot build with
ANYPS5_USE_SYSTEM_DEPS=ON.core/libs/tests/GuestLegacyFreeTypeFaceSettings.cpp:7-8includes<freetype/internal/ftobjs.h>and<freetype/internal/tttypes.h>.core/libs/prx/libfreetype/CMakeLists.txt:29-37registers the test whatever the setting.PATTERN "internal" EXCLUDEin the install rules of the FreeType submodule'sCMakeLists.txt). A distributionlibfreetype-devtherefore does not have them.libSceFreeTypeOl, which includes the same headers, is wrapped inif(NOT ANYPS5_USE_SYSTEM_DEPS)(core/libs/prx/libSceFreeTypeOl/CMakeLists.txt:1).freetypeis not listed among the submodules that "always stay bundled" (docs/dev/BUILD.md:160). SoFREETYPE_TEST_FONTS, which points into3rdparty/freetype/tests/data, can also be missing. That hits the Multiple Masters test as well.if(NOT ANYPS5_USE_SYSTEM_DEPS), aslibSceFreeTypeOldoes. Or check the face state without the private headers.I could not build this configuration because no system FreeType is installed on this machine. The finding rests on FreeType's install rules and the existing guard.
Non-blocking
src/FaceSettings.cpp:25-28allocatesnumProperties + 1host entries and copies every guest entry before FreeType runs. FreeType itself stops at the firstUnimplemented_FeatureorInvalid_Argumententry (ftobjs.cFT_Face_Properties) and never reads past it.UINT32_MAXasks for about 64 GiB. The resultingstd::bad_allocwould then cross anextern "C"guest boundary.src/MultipleMasters.cpp:18and:29do the same fornumCoordsand*length.Gzip.cppis fixed in557fcc76e7: both lengths are checked againstnumeric_limits<FT_ULong>::max()before the casts (src/Gzip.cpp:34). TheULONG_MAX + 1test sits underif constexprand only runs whereunsigned longis 32-bit, so on this Linux machine that branch is compiled out. I confirm the code fix by reading it, not by running it.Not verified
ANYPS5_USE_SYSTEM_DEPS=ONbuilds: no system FreeType here.FT_ULongpaths and theENVIRONMENT_MODIFICATIONPATH setup.tools/nid_names.py: I did not run it.To get this to a good state
guest_legacy_freetype_face_settings(andguest_legacy_freetype_multiple_masters, which needs the submodule's test fonts) withif(NOT ANYPS5_USE_SYSTEM_DEPS), or drop the private-header dependency.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T12:18:54Z.
Review: APPROVED
Re-checked — approved
Since my last review there are two new commits.
bdc326089ecaps the Multiple Masters scratch arrays and skips that test when system deps are used.3a1af1e45epasses face properties to FreeType one at a time and puts the face-settings test inside the same system-deps guard. With these, my blocking finding is resolved.What changed since my last review
The previous review was of
c6c86c1a942e94ea047276b60f1bd747142cc5cc.bdc326089e(stacked #15442):guest_legacy_freetype_multiple_mastersis now registered only underif(NOT ANYPS5_USE_SYSTEM_DEPS).cd2049bc6a: rebased. The face-settings test is now registered inside the same guard.3a1af1e45e:FT_Face_Propertiesdrops thenumProperties + 1scratch vector. Each entry is converted and passed on its own, and the loop returns at the first error. The test adds a call with a count ofUINT32_MAXon a two-entry array whose second tag is unknown.docs/dev/debt/libfreetype.mdare updated to match.What I ran
Head
3a1af1e45e547147e017bfa8a72d2b5c848b74c6,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged with--no-ff(treec35a11d33883d9d0ba6c34cbd3469f87ebc41632) in a clean worktree.git diff --checkcheck_conventions.pyguest_interfaces,guest_socket_options_multicast,unwrap_self_…_group,vector_constant_factor_tininess) and theguest_net_ctlskip also happen onmain; none comes from this PR.guest_legacy_freetype_gzip/_multiple_masters/_face_settingsNegative control (pre-fix production files, new tests):
guest_legacy_freetype_face_settingsfails with ***Timeout (21.66 s): the old copy loop runs over theUINT32_MAXcount.guest_legacy_freetype_multiple_mastersstill passes. See non-blocking 1.After restoring the merged files and rebuilding, all three tests pass and
git status --porcelainis empty.Previous findings
ANYPS5_USE_SYSTEM_DEPS=ON. Resolved.if(NOT ANYPS5_USE_SYSTEM_DEPS), atcore/libs/prx/libfreetype/CMakeLists.txt:23-51. This is the same guardlibSceFreeTypeOluses.guest_legacy_freetype_gzipstays unconditional. It uses only public headers and embedded data.core/libs/prx/libfreetype/src/FaceSettings.cpp:25-29now converts and passes one entry at a time.FT_Face_Properties(inftobjs.c). The results match:Unimplemented_FeatureorInvalid_Argument. Earlier entries stay applied, which is what the test checks withrandom_seed == 7.Invalid_Argument.Ok.UINT32_MAXtest atcore/libs/tests/GuestLegacyFreeTypeFaceSettings.cpp:63-64fails against the old code, as the author said.MultipleMasters.cpptheused - 1index is reached only when the count is non-zero.nativeLength == used ? requested : nativeLength) matchesT1_Get_MM_WeightVector:num_designs, which is at most 16, so it can never equal a capped 65536;New findings
Blocking
None.
Non-blocking
CheckLargeCounts(core/libs/tests/GuestLegacyFreeTypeMultipleMasters.cpp:67-79) passes with the uncapped code from90223b33c2too. It checks that the results match FreeType's padding beyond the cap, not that the allocation is bounded.UINT32_MAX) would itself need about 32 GiB with the old code.Not verified
ANYPS5_USE_SYSTEM_DEPS=ONbuilds: no system FreeType on this machine.FT_ULongtag and length paths, and theENVIRONMENT_MODIFICATIONPATH setup.tools/nid_names.pyNID-to-name mapping: I did not run it.