Skip to content

Buffer class for text input (Phase 4) - #9

Merged
hasanzakeri merged 3 commits into
mainfrom
phase-4-buffer
Apr 25, 2026
Merged

hasanzakeri merged 3 commits into
mainfrom
phase-4-buffer

Conversation

@hasanzakeri

Copy link
Copy Markdown
Owner

Summary

  • Adds Buffer — the Pythonic entry point for feeding text into the shaping pipeline.
  • Wraps harfrust's UnicodeBuffer behind Option<UnicodeBuffer> so the consumption pattern (ValueError on use-after-shape) is wired in before any consumer exists. Phase 5's Font.shape() will call the pub(crate) take_inner / restore hooks without further refactor.
  • Exposes the operations Phase 5 will need: add_str, add(codepoint, cluster=0), clear, reset_clusters, guess_segment_properties, reserve,set_pre_context / set_post_context, and direction / script / language properties. language returns None when unset, matching upstream.

Out of scope

  • The actual buffer-consumption code path — has to wait for Font.shape() in Phase 5.

Test plan

  • cargo fmt --all --check
  • cargo clippy --all -- -D warnings
  • cargo test --all
  • uv run maturin develop
  • uv run ruff check && uv run ruff format --check
  • uv run pytest — 81 passed (25 new, 56 pre-existing)

  Pythonic Buffer class backed by Option<UnicodeBuffer>, which
  establishes the consumption pattern for Phase 5 shape() without
  yet exposing a consumer. Covers the operations needed to drive
  shaping end-to-end: text accumulation, direction/script/language
  properties, guess_segment_properties, context setters, and clear.
  Adds a Buffer test covering set_not_found_variation_selector_glyph,
  which was exposed but previously unexercised. Marks the Direction
  label match inside Buffer.__repr__ with a comment pointing at the
  equivalent (private) match in PyDirection::__repr__, so the next
  edit to either keeps them in sync. Expands the TestContext header
  to spell out why pre/post context tests only assert that the call
  doesn't raise.
@hasanzakeri
hasanzakeri merged commit 7d65c9f into main Apr 25, 2026
2 checks passed
@hasanzakeri
hasanzakeri deleted the phase-4-buffer branch April 25, 2026 18:55
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