Skip to content

Harfbuzzy#48

Merged
elcritch merged 31 commits into
mainfrom
harfbuzzy
Jun 19, 2026
Merged

Harfbuzzy#48
elcritch merged 31 commits into
mainfrom
harfbuzzy

Conversation

@elcritch

Copy link
Copy Markdown
Owner

Summary

Adds an optional Harfbuzzy-backed text shaping path while keeping Pixie as the default text backend. The branch moves FigDraw text layout toward glyph-id-first rendering, adds source-range and caret mapping helpers for shaped text, and includes a Windy demo for Arabic/Hebrew shaping using bundled OFL Noto fonts.

Changes

  • Adds figdrawTextBackend compile-time backend selection:
    • pixie remains the default.
    • hybrid uses Harfbuzzy layout with Pixie-compatible rasterization.
    • harfbuzzy uses Harfbuzzy shaping plus glyph-id rasterization.
  • Adds backend-neutral glyph layout data:
    • FontGlyphId
    • GlyphSourceRange
    • ArrangedGlyph
    • GlyphArrangement.sourceRunes
    • GlyphArrangement.arrangedGlyphs
  • Adds source mapping and caret APIs:
    • glyph/source range lookup by rune or byte range
    • selection rects by source range
    • point-to-glyph/source hit testing
    • source insertion index caret positions
  • Splits text backend logic into Pixie and Harfbuzzy adapters.
  • Adds Harfbuzzy shaping support for:
    • shaped glyph ids
    • cluster/source mapping
    • wrapping at shaped glyph boundaries
    • CJK/Kana/Hangul adjacent wrapping
    • combining marks
    • mixed LTR/RTL runs
    • Arabic and Hebrew marks
  • Adds glyph-id rasterization through HarfBuzz draw callbacks.
  • Updates glyph cache identity to use fontId + glyphId.
  • Adds docs in docs/font_shaping.md.
  • Adds examples/windy_text_shaping_demo.nim, defaulted to Harfbuzzy via examples/windy_text_shaping_demo.nims.
  • Bundles OFL-licensed Noto Naskh Arabic and Noto Sans Hebrew fonts for the demo.

Testing

Ran:

  • nim r -d:figdrawTextBackend=harfbuzzy tests/tfontutils.nim
  • nim r -d:figdrawTextBackend=hybrid tests/tfontutils.nim
  • nim r tests/tfontutils.nim
  • nim test
  • nim r -d:figdraw.runOnce examples/windy_text_shaping_demo.nim

Also verified the demo sidecar .nims loads and reports backend=harfbuzzy.

Notes

The Harfbuzzy integration is compile-time gated and does not expose HarfBuzz handles through FigDraw’s public node APIs. Pixie remains the default backend.

@elcritch elcritch merged commit 692975d into main Jun 19, 2026
3 checks passed
@elcritch elcritch deleted the harfbuzzy branch June 19, 2026 03:42
@elcritch elcritch restored the harfbuzzy branch June 19, 2026 03:43
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