Skip to content

LATX, feat: Add experimental font wrapper family - #402

Draft
LaurenIsACoder wants to merge 11 commits into
lat-opensource:masterfrom
LaurenIsACoder:lauren/kzt-font-family
Draft

LATX, feat: Add experimental font wrapper family#402
LaurenIsACoder wants to merge 11 commits into
lat-opensource:masterfrom
LaurenIsACoder:lauren/kzt-font-family

Conversation

@LaurenIsACoder

@LaurenIsACoder LaurenIsACoder commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

新增实验性的 font KZT 库族,受控直通 FreeType、Fontconfig 和 Xft。

  • 在启用现有 Cairo 原生直通时自动加入 font 依赖。
  • 在加载前检查 host 库和必要符号,检查失败时保持 guest 库翻译执行。
  • 为 FreeType、Fontconfig 和 Xft 的 guest 回调建立 bridge,并保存跨库字体对象的引用和所有权关系。
  • 对无法安全跨 ABI 调用的 FreeType 接口保持安全拒绝,不将 guest 回调地址直接传给 host 库。

已在 LoongArch 本地图形环境完成验证:

  • 正常 LAT 产品构建:ninja -C build64 latx-x86_64
  • FreeType 回调探针 20/20 成功。
  • Xft/FreeType 终结回调探针 20/20 成功。
  • gtkperf 在 LATX_KZT=1 LATX_KZT_ENABLE=font 下连续 3/3 成功。
  • gtkperf 在 LATX_KZT=1 LATX_KZT_ENABLE=cairo 下连续 3/3 成功;日志确认自动选择 font 并命中 Cairo、FreeType、Fontconfig 的 KZT wrapper。

未新增产品测试目标或提交临时探针。


Add the experimental font KZT library group for controlled native wrapping of FreeType, Fontconfig, and Xft.

  • Make the existing native Cairo path select font as a required dependency.
  • Preflight the host libraries and required symbols; keep guest-library translation when preflight fails.
  • Bridge guest callbacks in FreeType, Fontconfig, and Xft, while preserving references and ownership for font objects shared across those libraries.
  • Safely reject FreeType interfaces that cannot cross the ABI boundary, rather than passing guest callback addresses to host libraries.

Validated on a native LoongArch desktop environment:

  • Normal LAT product build: ninja -C build64 latx-x86_64.
  • FreeType callback probe: 20/20 successful runs.
  • Xft/FreeType finalizer callback probe: 20/20 successful runs.
  • gtkperf: 3/3 successful runs with LATX_KZT=1 LATX_KZT_ENABLE=font.
  • gtkperf: 3/3 successful runs with LATX_KZT=1 LATX_KZT_ENABLE=cairo; logs confirmed automatic font selection and KZT wrapper hits for Cairo, FreeType, and Fontconfig.

No product test targets or temporary probes are included.

Move the ELF64 guest export and host symbol checks out of the Cairo-specific preflight into a reusable helper. Cairo retains the same strict activation policy and rejection reasons.

Validated by a full LoongArch latx-x86_64 product build.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Add the integer, floating-point, aggregate, stack-argument, and variadic dispatch shapes required by the FreeType, Fontconfig, and Xft public ABIs.

The signatures were checked against the x86_64 guest headers and compiled as part of the LoongArch product build.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Add complete guest export catalogs for FreeType, Fontconfig, and Xft, and register them as one experimental font group. A whole-family preflight requires matching guest exports and host symbols before any member is activated.

Handle x86_64 variadics and by-value aggregates explicitly. Bridge synchronous FreeType outline and list callbacks, reject unsupported callback-bearing APIs without passing guest addresses to host code, and clear wrapper tracking state on unload. Xft variadic entry points are rebuilt through native Fontconfig and Xft APIs.

The implementation is derived in part from Box64's MIT-licensed wrappers with attribution retained, but corrects signatures against public headers and avoids its fixed-slot and global-stream fallback hazards.

Validated with a full LoongArch latx-x86_64 product build, direct FreeType/Fontconfig/Xft probes, a FreeType callback round trip, atomic preflight rejection, and real-display gtkperf.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Make Cairo activation depend on the experimental font family and run the same whole-family preflight before loading the native Cairo wrapper. If FreeType, Fontconfig, or Xft is incompatible, disable font and let dependency pruning disable Cairo before host objects can cross into a partial native stack.

The cairo_ft_* object crossings remain fail-closed until FT_Face and FcPattern ownership and lifetime rules are wired across the wrappers.

Validated by the LoongArch product build and atomic preflight rejection probe.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Custom wrappers can require host helper symbols that are not guaranteed by scanning the guest library exports alone. Let each wrapped library declare unconditional native prerequisites and reject the whole library family before activation when one is missing.

Cover the Cairo font-face helpers, the FreeType face lifetime calls, the Fontconfig FT_Face query, and the Xft helper calls used by custom wrappers.

Validated by the LoongArch product build.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Expose narrow inter-wrapper helpers for retaining host FT_Face objects, marking Cairo-borrowed faces, and reading an FcPattern FC_FT_FACE value.

Keep borrowed faces separate from caller-owned FreeType faces. FT_Done_Face now rejects a face while Cairo has lent it to guest code, and wrapper teardown clears the associated bookkeeping without handing guest pointers to native code.

Validated by the LoongArch product build and the FT_Face ownership probe.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Pass native cairo_font_options_t and FcPattern objects through cairo_ft_font_options_substitute and cairo_ft_font_face_create_for_pattern using the public Cairo argument order.

Retain pre-opened FT_Face objects with Cairo user data, and track the ownership and thread of faces borrowed by cairo_ft_scaled_font_lock_face until the matching unlock. Fail with a Cairo error face when the required lifetime reference cannot be established.

Validated by the LoongArch product build, native entry probes for the Cairo FT APIs, and three gtkperf runs without Pango warnings or X errors.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Pango can build FcFontSet containers with the guest allocator while storing host-native FcPattern pointers. Passing those containers to native Fontconfig lets the host allocator free guest memory.

Transfer guest-owned containers into host-owned storage before native destruction, and keep native-owned sets on the direct path.

Validated with the normal LAT product build and repeated LoongArch gtkperf runs using the font and Cairo groups.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
FcScandir executes its selector and comparator inside host Fontconfig. Passing guest function addresses directly would make LoongArch execute x86 code.

Use a thread-local call context and native thunks for guest callbacks while preserving native callbacks on the direct path. Nested scans restore the previous context.

Validated with the normal LAT product build and a LoongArch probe covering both callbacks with KZT disabled and the font group enabled.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Native FreeType can retain stream, memory, cache requester, debug hook, and FT_Generic callbacks after a wrapper returns. Synchronous raster callbacks also require native thunks. Guest function addresses cannot cross those boundaries directly.

Add per-object callback state, reference and destruction tracking, safe callback-slot exhaustion, and a translator bridge for guest-visible generic finalizer pointers. Reject module classes, log handlers, compressed streams, and internal TrueType entry points that still lack a safe ABI.

Validated with the normal LAT product build, deterministic reference-lifetime RED/GREEN coverage, GDB thunk-to-host evidence, and 20 repeated LoongArch callback-probe runs.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
XftLockFace exposes a host FT_Face whose public generic finalizers can be replaced by guest code. Xft may later destroy that face internally, outside the FreeType wrapper path.

Guard each exposed face before and after guest access, keep it borrowed while locked, and refresh the bridge before Xft closes fonts. A bounded per-thread lock stack fails safely on invalid nesting.

Validated with a deterministic LoongArch RED that hung in the unguarded native path, followed by 20/20 GREEN runs and GDB evidence for both guest-invoked and host-invoked finalizers.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant