Skip to content

Share UTF-8 sources across styled text layouts - #93

Merged
elcritch merged 8 commits into
mainfrom
feat/borrowed-utf8-text-spans
Sep 23, 2026
Merged

elcritch merged 8 commits into
mainfrom
feat/borrowed-utf8-text-spans

Conversation

@elcritch

@elcritch elcritch commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Bump FigDraw to 0.42.0 and add a typesetting API that accepts one shared Utf8Runes source, compact StyledTextRun byte ranges, and a separate style table.
  • Retain the shared source in layouts. Harfbuzzy borrows source spans while shaping, and Pixie reuses the original source for display and maps glyph ranges back to source bytes.
  • Preserve the exact low-level Pixie typeset and convertArrangement proc signatures. Align fonts and colors with the spans Pixie keeps when a styled run consists only of filtered controls, in both owned and shared paths.
  • Make borrowing bytes from nil Utf8Runes raise ValueError instead of dereferencing nil.
  • Add validation and regression coverage for UTF-8 ranges, style IDs, filtered controls, case conversion, nil byte access, and legacy proc types.
  • Add tools/bench_text_source_rss.nim to compare retained input memory for owned strings and shared runs.

Memory example

With a 16 MiB source and 65,536 runs, three macOS RSS samples measured about 25,376 KiB of additional RSS for owned run strings versus 1,296 KiB for shared source runs. This measures retained input representation, not full typesetting peak memory. Pixie's current span API still materializes temporary strings during layout.

Verification

  • atlas-run tests (45/45 static test targets passed)
  • nim r -d:figdrawTextBackend=harfbuzzy tests/tfontutils.nim
  • atlas-run tests --compile-only examples/siwin_text.nim
  • Merenda atlas-run tests tnimkit against this branch
  • /Volumes/projects/nims/Nim/bin/nim build_dynlib (Nim 2.3.1; native ABI and library staged)
  • NIMFLAGS=-d:useNativeDynlib atlas-run tests dynlib_api dynlib_renderfragments native_ui_scale siwin_redraw (4/4 passed, including the new borrowed-span ABI test)

The default Nim 2.2.12 install lacks compiler source required by Binny, so the dynlib build used the local Nim 2.3.1 checkout.

@elcritch
elcritch merged commit 2a80d96 into main Sep 23, 2026
8 checks passed
@elcritch
elcritch deleted the feat/borrowed-utf8-text-spans branch September 23, 2026 11:46
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