Unicode 17 paragraph layout, line breaking and word/sentence segmentation
Dependencies
moon add ShiChengxu/moonlayout@0.2.0let style = @ml.LayoutStyle::new(16, wrap_algorithm=Optimal, alignment=Justify)
let hyphenator = @ml.Liang::english() // 编译一次,重复使用
let lines = @ml.layout_hyphenated("Hyphenation improves narrow paragraphs.", style, hyphenator)
for line in lines {
println(line.aligned_text)
}let result = @integration.layout(
"שלום 123 A",
@ml.LayoutStyle::new(16),
normalization=NFKC,
bidi=true,
)
for line in result.lines {
println(line.aligned_text)
}moon run examples/wrap_terminal
moon run examples/cjk_mixed
moon run examples/justify_paragraph
moon run examples/word_boundaries
moon run examples/hyphen_wrap
moon run examples/optimal_wrap
moon run examples/bidi_paragraph
moon run examples/markdown_likepython scripts/verify.py
moon bench -p ShiChengxu/moonlayout/benchmarks --target native --releasefn display_width(s : String, ambiguous_wide? : Bool, tab_width? : Int) -> Intfn is_breakable_at(s : String, byte_index : Int) -> Boolfn[H : Hyphenator] layout_hyphenated(text : String, style : LayoutStyle, hyphenator : H) -> Array[Line]fn optimal_wrap(s : String, max_width : Int, opts? : WrapOptions, optimal? : OptimalOptions) -> Array[Line]fn[H : Hyphenator] wrap_hyphenated(s : String, max_width : Int, hyphenator : H, algorithm? : WrapAlgorithm, opts? : WrapOptions, optimal? : OptimalOptions) -> Array[Line]Install
Download zipUnicode 17 paragraph layout, line breaking and word/sentence segmentation
Dependencies