Skip to content

refactor: shape text with HarfRust and draw glyphs with Skrifa - #230

Merged
chenyme merged 6 commits into
devfrom
refactor/replace-swash
Dec 5, 2026
Merged

chenyme merged 6 commits into
devfrom
refactor/replace-swash

Conversation

@chenyme

@chenyme chenyme commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

What this changes

Text shaping, glyph drawing and a few hand-written Unicode and image routines move to maintained implementations. Refs DEEIX-AI/Winc#953, where a Devanagari reph crashed the old shaper.

  • Shaping: HarfRust (the HarfBuzz port) replaces the old shaper. Indic scripts, Sinhala, Telugu, Khmer, Myanmar and Thai join and place their marks as the system does; a reph such as र्क no longer drops or panics; fonts that shape only through morx, such as Thai's Thonburi on macOS, are used directly, so the stand-in fonts for them are gone; emoji sequences such as families show as one picture on Windows. Shape plans are cached per font and settings.
  • Fonts and glyphs: Skrifa's font model reads fonts, outlines and hinting, sharing one read-fonts with HarfRust. Color glyphs are drawn here: solid COLR layers, and sbix/CBDT images through a small PNG decoder. Optical sizes follow the font's avar and stay within the axis. zeno is used directly.
  • Line breaking: icu_segmenter applies the Unicode line breaking rules, with the strict rules for CJK punctuation. Lines also break after hyphens and at zero-width spaces, never at no-break spaces or within numbers. word-break still adds the dictionaries for Thai, Lao, Khmer and Myanmar.
  • Emoji: presentation and skin-tone bases come from Unicode 18 data instead of a hand-kept table.
  • PNG: one decoder and encoder serve emoji, Bitmap::from_png and the clipboard; the png crate is no longer a dependency. The png feature is kept and does nothing, so builds that enable it still work.
  • Scaling: images and emoji bitmaps share one area-averaging scaler.
  • The hello size budget moves from 2.5 MB to 3.0 MB.

Measurements

macOS, Apple M4 Pro, release builds, scale 2. "Before" is dev at 3bd810c, "after" is this branch. Frame times are medians of 4 runs of cpui-bench, as p50 / p95.

Before After
hello executable 2,504,784 bytes (2.39 MB) 2,952,128 bytes (2.82 MB)
Idle memory, list window 28.0–28.6 MB 28.1–28.4 MB
Peak memory in the first 2 s, list window 28.2–28.7 MB 28.3–28.7 MB
Idle memory, hello window 28.1–28.4 MB 28.6 MB
Time to window, hello 52–54 ms 53–64 ms
Frame re-laying out 8 lines of mixed scripts, p50 / p95 0.24–0.25 / 0.29 ms 0.21–0.22 / 0.24–0.26 ms
First frame, fonts opened and text shaped and drawn 14.0–14.8 ms 14.3–15.6 ms
cpui-bench frame, p50 / p95 (ms) Before After Budget
Idle, 800×600 0.004 / 0.004 0.004 / 0.005 0.02
Hover, 800×600 0.022 / 0.026 0.022 / 0.022 0.05
Typing, 800×600 0.072 / 0.090 0.073 / 0.088 0.20
Full frame, 800×600 0.103 / 0.117 0.102 / 0.112 0.25
Arabic full frame, 800×600 0.135 / 0.151 0.137 / 0.151 0.55
List scroll, 800×600 0.189 / 0.215 0.189 / 0.212 0.50
Tree scroll, 10,000 rows 0.627 / 1.114 0.612 / 1.097 2.30
Open select, 1,000 options 0.048 / 0.053 0.046 / 0.054 0.12
Typing, 10,000-line input 0.804 / 0.982 0.780 / 0.975 2.25
List scroll, 6K 0.530 / 0.636 0.514 / 0.619 1.25
List full frame, 6K 0.512 / 0.621 0.520 / 0.636 1.35
Subpixel list frame, 6K 0.599 / 0.727 0.617 / 0.728 2.00
Cards scroll, 800×600 0.307 / 0.356 0.303 / 0.349 2.85
Cards scroll, 6K 0.955 / 1.007 0.944 / 0.996 4.55

The size grows by 436 KB, mostly HarfRust (about 374 KB of code, its AAT support included) and the read-fonts font model. Specimens of every script were drawn before and after on macOS, Linux and Windows; Latin and CJK on Linux are identical pixel for pixel, hinting included.

Checks

See CONTRIBUTING.md for the details.

  • scripts/check.sh passes
  • Public items have documentation with an example
  • CHANGELOG.md is updated for a change users will notice
  • Guides are updated in both docs/ and docs/zh-CN/, if they are affected
  • cargo run --release -p cpui-bench stays within budget, if per-frame code changed
  • Platforms this was run on: macOS, Linux (container), Windows 11; iOS, Android and the browser checked
  • I have read and agree to the Contributor License Agreement

@chenyme
chenyme merged commit 6a03c16 into dev Dec 5, 2026
14 checks passed
@chenyme
chenyme deleted the refactor/replace-swash branch December 5, 2026 17:57
@chenyme chenyme self-assigned this Dec 5, 2026
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