fribidi.cr

Typed Crystal paragraph bidi analysis using FriBidi

FriBidi for Crystal

require "fribidi" provides bounded, typed paragraph bidi analysis over the FriBidi C library. LibFriBidi contains the low-level FFI declarations; ordinary callers use FriBidi::Paragraph, which owns copied embedding levels and byte mappings and exposes no pointers.

paragraph = FriBidi::Paragraph.new("abc אבג")
paragraph.base_direction # => FriBidi::BaseDirection::LTR
paragraph.level(4).odd?  # => true
paragraph.visual_indices # => [0, 1, 2, 3, 6, 5, 4]

Indices returned by visual_indices identify Unicode scalar values, while byte_offset(index) maps them to UTF-8 source offsets. A subrange can be reordered for an already broken line without copying native pointers into the public API. Base direction can be automatic, LTR, or RTL. Inputs are limited to 65,536 UTF-8 bytes.

Install FriBidi and pkg-config using the target platform's dependency tooling. The wrapper was tested with FriBidi 1.0.16 on macOS arm64. FriBidi is LGPL-2.1-or-later; this Crystal wrapper is MIT. Applications that distribute the native library remain responsible for its license terms.

Run CRYSTAL_CACHE_DIR=/tmp/fribidi-spec crystal spec from this shard.

Repository

fribidi.cr

Owner
Statistic
  • 0
  • 0
  • 0
  • 1
  • 0
  • 1 day ago
  • November 30, 2026
License

MIT License

Links
Synced at

Wed, 02 Dec 2026 02:09:26 GMT

Languages