feat(libcairo): implement cairo_ft_font_options_substitute #16895

Merged
AlexWhitehouse merged 3 commits from upstream-pr/16895 into main 2026-11-11 14:56:42 +00:00
AlexWhitehouse commented 2026-11-07 20:54:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-07T20:54:39Z.


What

libcairo cairo_ft_font_options_substitute (NID ii895dyBjMo) threw cairo_ft_font_options_substitute not implemented. This PR ports it from Cairo 1.18.0, the version libcairo's existing code cites: cairo-ft-font.c, _cairo_ft_font_options_substitute and its public wrapper. The new FtFontOptions.cpp starts with that file's notice.

It adds Cairo font options to a Fontconfig pattern, through libfontconfig's existing exports (FcPatternGet, FcPatternAddBool, FcPatternAddInteger, FcPatternDel), in upstream's order:

  • antialias: if the pattern has no value, it adds one (false for CAIRO_ANTIALIAS_NONE). For anything other than subpixel antialiasing, it also replaces rgba with FC_RGBA_NONE.
  • rgba: if still absent, it adds one from the subpixel order (RGB, BGR, VRGB or VBGR; the default order maps to RGB) for subpixel antialiasing, or FC_RGBA_NONE otherwise.
  • hinting and hintstyle: if absent, they are added from the hint style (none, slight, medium, full).
  • Order and checks: each check uses the generic FcPatternGet, as upstream does, so a value already in the pattern is never overwritten. A failed add stops where upstream returns CAIRO_STATUS_NO_MEMORY.
  • Invalid options: a null or nil (error) options object does nothing, as the cairo_font_options_status check in the wrapper does.

Known gaps (debt): upstream also adds lcdfilter when the options' LCD filter isn't the default. This repo's font-options object has no LCD filter field and Cairo exports no setter for it, so the filter is always the default and that branch can't run; the new debt entry says so. Hint metrics are unused, as upstream. The NID is removed from the callable-exports table, and both counts that name the remaining exports now say 73, the stubs left in Export.cpp.

Tested

  • New test: guest_cairo_ft_font_options (core/libs/tests/GuestCairoFtFontOptions.cpp) creates options and patterns through the guest exports, calls the export, and reads antialias, rgba, hinting and hintstyle back through Fontconfig's getters. It covers:
    • every antialias, subpixel order and hint style mapping;
    • default options adding nothing;
    • values already in the pattern being kept;
    • rgba being replaced for non-subpixel antialiasing;
    • null and nil options.
  • Linux x86-64 (Ubuntu 26.04, GCC 15, Release):
    • on main, the test fails with cairo_ft_font_options_substitute not implemented;
    • with this PR, it passes, as do guest_cairo_font_options, guest_cairo_matrix, guest_cairo_surface, guest_fontconfig_objects and public_headers.
  • Windows 11: (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): libcairo links and loads with libfontconfig.prx, and the four Cairo and five Fontconfig tests pass (9/9) at 92464009ab, with no compiler or linker warnings in the changed files.
  • Mutation check: swapping the RGB and BGR mappings fails the rgba assertion.
  • Review follow-up (1974cff740): the substitution reads the options through CairoFontOptionsRead in FontOptions.cpp instead of copying the private storage by layout. The same Linux tests pass, and swapping the subpixel-order and hint-style fields in the reader fails the hinting assertion. The Windows test's three PATH entries are now one ENVIRONMENT_MODIFICATION list. ctest --show-only=json-v1 on a scratch project shows the old three-string form set only the first entry plus a stray property, and the joined form sets all three.
  • python3 tools/check_conventions.py --base origin/main: all checks passed.
  • python3 tools/pr_overlap.py: no open PR implements this export. #16892 implemented it until dc4fdb67af dropped it, along with its FontOptions.cpp reader; the two PRs now share only libcairo's count line.
    • #15208, #15430, #15675, #15679, #15681, #15685, #16892 and #16954 share libcairo's count lines, header additions or neighbouring stub removals.
    • After #14329, #15315, #16315, #15317 and #15324 merged, this branch was rebased onto main eaec74e322. Both counts were recounted against the 73 stubs left in Export.cpp; main's count lines still said 117 and 89. The same Linux tests pass, plus guest_cairo_regions, guest_cairo_context, guest_cairo_surface_user_data, guest_cairo_graphics_state and guest_cairo_path.
    • #14212 only removes the count.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5205754694 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16895). Originally posted by [AlexWhitehouse](https://github.com/AlexWhitehouse) on 2026-11-07T20:54:39Z. --- ### What libcairo `cairo_ft_font_options_substitute` (NID `ii895dyBjMo`) threw `cairo_ft_font_options_substitute not implemented`. This PR ports it from Cairo 1.18.0, the version libcairo's existing code cites: [`cairo-ft-font.c`](https://gitlab.freedesktop.org/cairo/cairo/-/blob/1.18.0/src/cairo-ft-font.c), `_cairo_ft_font_options_substitute` and its public wrapper. The new `FtFontOptions.cpp` starts with that file's notice. It adds Cairo font options to a Fontconfig pattern, through libfontconfig's existing exports (`FcPatternGet`, `FcPatternAddBool`, `FcPatternAddInteger`, `FcPatternDel`), in upstream's order: - **`antialias`:** if the pattern has no value, it adds one (false for `CAIRO_ANTIALIAS_NONE`). For anything other than subpixel antialiasing, it also replaces `rgba` with `FC_RGBA_NONE`. - **`rgba`:** if still absent, it adds one from the subpixel order (RGB, BGR, VRGB or VBGR; the default order maps to RGB) for subpixel antialiasing, or `FC_RGBA_NONE` otherwise. - **`hinting` and `hintstyle`:** if absent, they are added from the hint style (none, slight, medium, full). - **Order and checks:** each check uses the generic `FcPatternGet`, as upstream does, so a value already in the pattern is never overwritten. A failed add stops where upstream returns `CAIRO_STATUS_NO_MEMORY`. - **Invalid options:** a null or nil (error) options object does nothing, as the `cairo_font_options_status` check in the wrapper does. **Known gaps (debt):** upstream also adds `lcdfilter` when the options' LCD filter isn't the default. This repo's font-options object has no LCD filter field and Cairo exports no setter for it, so the filter is always the default and that branch can't run; the new debt entry says so. Hint metrics are unused, as upstream. The NID is removed from the callable-exports table, and both counts that name the remaining exports now say 73, the stubs left in `Export.cpp`. ### Tested - **New test:** `guest_cairo_ft_font_options` (`core/libs/tests/GuestCairoFtFontOptions.cpp`) creates options and patterns through the guest exports, calls the export, and reads `antialias`, `rgba`, `hinting` and `hintstyle` back through Fontconfig's getters. It covers: - every antialias, subpixel order and hint style mapping; - default options adding nothing; - values already in the pattern being kept; - `rgba` being replaced for non-subpixel antialiasing; - null and nil options. - **Linux x86-64** (Ubuntu 26.04, GCC 15, Release): - on `main`, the test fails with `cairo_ft_font_options_substitute not implemented`; - with this PR, it passes, as do `guest_cairo_font_options`, `guest_cairo_matrix`, `guest_cairo_surface`, `guest_fontconfig_objects` and `public_headers`. - **Windows 11:** (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): libcairo links and loads with `libfontconfig.prx`, and the four Cairo and five Fontconfig tests pass (9/9) at 92464009ab, with no compiler or linker warnings in the changed files. - **Mutation check:** swapping the RGB and BGR mappings fails the `rgba` assertion. - **Review follow-up (1974cff740):** the substitution reads the options through `CairoFontOptionsRead` in `FontOptions.cpp` instead of copying the private storage by layout. The same Linux tests pass, and swapping the subpixel-order and hint-style fields in the reader fails the `hinting` assertion. The Windows test's three PATH entries are now one `ENVIRONMENT_MODIFICATION` list. `ctest --show-only=json-v1` on a scratch project shows the old three-string form set only the first entry plus a stray property, and the joined form sets all three. - `python3 tools/check_conventions.py --base origin/main`: all checks passed. - **`python3 tools/pr_overlap.py`:** no open PR implements this export. #16892 implemented it until dc4fdb67af dropped it, along with its `FontOptions.cpp` reader; the two PRs now share only libcairo's count line. - #15208, #15430, #15675, #15679, #15681, #15685, #16892 and #16954 share libcairo's count lines, header additions or neighbouring stub removals. - After #14329, #15315, #16315, #15317 and #15324 merged, this branch was rebased onto `main` eaec74e322. Both counts were recounted against the 73 stubs left in `Export.cpp`; `main`'s count lines still said 117 and 89. The same Linux tests pass, plus `guest_cairo_regions`, `guest_cairo_context`, `guest_cairo_surface_user_data`, `guest_cairo_graphics_state` and `guest_cairo_path`. - #14212 only removes the count. ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gabichuuuuu commented 2026-11-07 22:15:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T22:15:41Z.

Review: COMMENTED


Read 92464009ab against main.

I compared FtFontOptions.cpp with Cairo 1.18.0 _cairo_ft_font_options_substitute and its wrapper, and the logic matches: the FcPatternGet == FcResultNoMatch presence checks, the FcPatternDel plus FC_RGBA_NONE path, the RGB and FULL defaults, the order of the four blocks, and the early return on a failed add. The nil/NULL early return matches cairo_font_options_status. The test's expected values match upstream, including out-of-range enums, and 123 is the right count against main's 124.

Overlap. #16892, opened two minutes earlier, also implements ii895dyBjMo (in FontFace.cpp), removes the same stub and edits the same count line, so the "no other open PR implements the same functions" box isn't accurate. Its version doesn't follow upstream (hinting from hint metrics, missing rgba, no presence checks), so this one should be the one kept; the two need coordinating.

CMakeLists.txt:46-49. set_tests_properties reads name/value pairs, so ENVIRONMENT_MODIFICATION gets only the libcairo entry, and the libfontconfig string becomes the name of a junk property whose value is the libc entry. It works today only because the prx libraries share one output directory. Joining the three into one ;-separated string fixes it.

FtFontOptions.cpp:43-59. The memcpy depends on the private CairoFontOptionsStorage field order in FontOptions.cpp, and the nil check calls cairo_font_options_copy(nullptr). A small reader in FontOptions.cpp would keep this from breaking silently when that struct grows, for example with the lcd_filter this PR records as debt.

Not run here; this is from reading the code against the 1.18.0 sources.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5815249183 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16895#pullrequestreview-5815249183). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-07T22:15:41Z. **Review:** COMMENTED --- Read `92464009ab` against `main`. I compared `FtFontOptions.cpp` with Cairo 1.18.0 `_cairo_ft_font_options_substitute` and its wrapper, and the logic matches: the `FcPatternGet == FcResultNoMatch` presence checks, the `FcPatternDel` plus `FC_RGBA_NONE` path, the RGB and FULL defaults, the order of the four blocks, and the early return on a failed add. The nil/NULL early return matches `cairo_font_options_status`. The test's expected values match upstream, including out-of-range enums, and 123 is the right count against `main`'s 124. **Overlap.** #16892, opened two minutes earlier, also implements `ii895dyBjMo` (in `FontFace.cpp`), removes the same stub and edits the same count line, so the "no other open PR implements the same functions" box isn't accurate. Its version doesn't follow upstream (hinting from hint metrics, missing `rgba`, no presence checks), so this one should be the one kept; the two need coordinating. **`CMakeLists.txt:46-49`.** `set_tests_properties` reads name/value pairs, so `ENVIRONMENT_MODIFICATION` gets only the libcairo entry, and the libfontconfig string becomes the name of a junk property whose value is the libc entry. It works today only because the prx libraries share one output directory. Joining the three into one `;`-separated string fixes it. **`FtFontOptions.cpp:43-59`.** The `memcpy` depends on the private `CairoFontOptionsStorage` field order in `FontOptions.cpp`, and the nil check calls `cairo_font_options_copy(nullptr)`. A small reader in `FontOptions.cpp` would keep this from breaking silently when that struct grows, for example with the `lcd_filter` this PR records as debt. Not run here; this is from reading the code against the 1.18.0 sources. 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!16895
No description provided.