feat(libcairo): implement FreeType font-face lifetime APIs #16892
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16892"
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 hyvvs on 2026-11-07T20:52:33Z.
What
Implement five Cairo FreeType/font-face exports:
cairo_ft_font_face_create_for_ft_faceretains the guest FreeType face withFT_Reference_Face_nid_postfixand releases it when the final Cairo font-face reference is destroyed.cairo_font_face_referenceandcairo_font_face_destroyprovide owned, reference-counted font-face lifetime.cairo_font_face_set_user_dataandcairo_font_face_get_user_dataimplement pointer-identity keys, replacement/removal, guest destroy callbacks, finalization order and reentrant-finalizer status.The implementation uses the repository's pinned FreeType submodule at
37515cf56ba3349656049edbed89ffc6f6466f2d.cairo_ft_font_options_substituteis intentionally excluded from this change. Its existing throwing stub is retained here; PR #16895 owns the functional Fontconfig option-substitution implementation.Lifetime constraint
The Cairo font face retains its
FT_Face, but the caller must keep the owningFT_Libraryalive until the Cairo font face is destroyed. This PR does not claim scaled-font creation or glyph rasterization.Tested
59849abb57.59849abb57.59849abb57, four focused executables built, and CTest matrix, font options, font face, and regions passed 4/4 with ASAN_OPTIONS=detect_leaks=1 and UBSAN_OPTIONS=halt_on_error=1. The earlier standalone head had also passed four focused tests, including surface.python -I tools/check_conventions.py --base upstream/main --head HEADpassed.git diff --checkpassed.d03beaf110, retaining both FreeType font-face and six newly merged region exports; on that head, conventions and whitespace checks passed. Six files in the new PR-specific diff.The original overlap scan covered 1,758 open PRs at initial publication. It found 13 shared-file relationships and no same-export claims. Two comparisons failed closed because #14212 and #15681 conflict with the base; I manually reviewed the relevant libcairo hunks. #14212's callable-export wording matches this branch, while #15681's shared CMake/export/inventory/debt files implement distinct context/pattern APIs and remain an integration dependency. #16895 now shares only the debt document; the duplicate font-options implementation has been removed from this branch.
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 gabichuuuuu on 2026-11-07T22:15:40Z.
Review: COMMENTED
Read
38fc893a0cagainstmain.cairo_ft_font_options_substitutedoesn't match Cairo 1.18.0. In_cairo_ft_font_options_substitute(src/cairo-ft-font.c),FC_HINTINGis set fromhint_style != CAIRO_HINT_STYLE_NONE, inside thehint_style != DEFAULTblock; hint metrics are never read there.FontFace.cpp:153derives it fromhintMetrics, so FULL with METRICS_OFF giveshinting=falsewhere upstream gives true, and NONE with default metrics adds nothing where upstream addshinting=false. Upstream also addsrgba=FC_RGBA_NONEfor every non-default, non-subpixel antialias (deleting any existingrgbawhen it addsantialias) andFC_RGBA_RGBfor subpixel with the default order; line 149 adds nothing in those cases. Every add upstream is guarded byFcPatternGet(...) == FcResultNoMatch, while here a value already in the pattern gets a second one appended, since this repo'sFcPatternAdd*appends (libfontconfig/Objects.cpp:201). Out-of-range enums go in unchanged instead of mapping to FULL/RGB.GuestCairoFontFace.cpp:150and:165assert the non-upstream results. #16895 ports this export faithfully, and both PRs remove the same stub and edit the same count line, so I'd drop it from this one.Status values.
kInvalidStatus = 12isCAIRO_STATUS_SURFACE_FINISHEDincairo.h(INVALID_STATUSis 6), andkUserFontError = 51is pastCAIRO_STATUS_LAST_STATUS(45). Upstream returns_cairo_font_face_nil(NO_MEMORY) for anycreate_from_facefailure, and has no reentrant-finalizer status:__putleaves the count at 1 while user data is finalized, soset_user_datafrom a destroy callback falls through to the array code. I'd returnNoMemoryFace()on theFT_Reference_Facefailure and throwNotImplemented_nid_no_patch(with a debt entry) for the reentrant case, rather than invent a code.Same
FT_Face, different objects. Upstream caches font faces byFT_Faceandload_flags, so callingcreate_for_ft_face(f, 0)twice returns the same face with refcount 2, and user data set through one handle is visible through the other. This PR allocates a new face each time.Smaller things.
docs/dev/debt/libcairo.md:5still says "other 124 pending" (118 after this PR). The body is missing the template's Tested section and checklist (Fixes, Unblocks, GPUs tested, AI-assisted).Not run here; this is from reading the code against the 1.18.0 sources.
AI-assisted: yes.
Pull request closed