Skip to content

Update ICU4X to 2.4, remove now-unneeded CJ_SEGMENTER - #9003

Closed
Manishearth wants to merge 1 commit into
typst:mainfrom
Manishearth:icu4xup
Closed

Manishearth wants to merge 1 commit into
typst:mainfrom
Manishearth:icu4xup

Conversation

@Manishearth

Copy link
Copy Markdown

Fixes #9002

@Manishearth

Copy link
Copy Markdown
Author

Someone should also remove the asset from typst-assets.

@MDLC01 MDLC01 added dependencies Pull requests that update a dependency file i18n About language- or script-specific features. May need attention from native speakers. labels Oct 25, 2026
@YDX-2147483647

YDX-2147483647 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

It looks like the tests disagree with you.

The CJ segmenter patch changes the properties of U+201C “ and U+201D ”, so that lines can be broken before “ and after ”, even without spaces.
The following is the test report for this PR. As you can see, after removing the patch, the problem reappears.

Screenshot of the test report 图片

Note that I'm just saying that this PR introduces a regression at present.
I don't know whether the CJ segmenter is still needed for Unicode 18. After all, https://util.unicode.org/UnicodeJsps/breaks.jsp now produces the correct results for 人。“([唐] and 经》:“有.

Screenshot of util.unicode.org 图片

Links to icu4x issues:

Update

If we switch to the neo segmenter, then the above two tests pass. It even resolves #6774.

However, another three tests fail:

  • linebreak-link-ip-host (added in Fix line breaking for hosts starting with a digit #8039)

    This change is acceptable, because the output becomes better. The changed line even has a comment saying This case is not yet ideal.

  • issue-4468-linebreak-thai (added in Fix repetition of Thai characters #4977) and linebreak-thai (added in Use icu4x for linebreaking algorithm #1355)

    It seems that all line breaking opportunities are lost.
    According to docs.rs, the neo segmenter does not support Thai.

    pub const fn new_neo_for_non_complex_scripts(options: …) -> …
    …no support for scripts requiring complex context dependent line breaks (Khmer, Lao, Myanmar, Thai).

    Line segmenter is currently compatible with Unicode Standard Annex #14 (version 15.1.0). The *_17_* constructors, which require the unstable Cargo feature, implement version 17.0.0. The *_neo_* constructors, which require the unstable Cargo feature, implement version 18.0.0 .

Screenshot of the test report 截图 2026-10-26 09 48 01
Code to switch to the neo segmenter
diff --git a/Cargo.toml b/Cargo.toml
index ea6ffbf9b..b0a836d15 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -71,7 +71,7 @@ hypher = "0.1.8"
 icu_collator = { version = "2.4.0" }
 icu_properties = { version = "2.4.0" }
 icu_provider = { version = "2.4.0", features = ["sync"] }
-icu_segmenter = { version = "2.4.0" }
+icu_segmenter = { version = "2.4.0", features = ["unstable"] }
 image = { version = "0.25.5", default-features = false, features = ["png", "jpeg", "gif", "webp"] }
 indexmap = { version = "2", features = ["serde", "rayon"] }
 infer = { version = "0.19.0", default-features = false }
diff --git a/crates/typst-layout/src/inline/linebreak.rs b/crates/typst-layout/src/inline/linebreak.rs
index 148a00b6c..6acbd4aa7 100644
--- a/crates/typst-layout/src/inline/linebreak.rs
+++ b/crates/typst-layout/src/inline/linebreak.rs
@@ -35,7 +35,7 @@ const BOUND_EPS: f64 = 1e-3;

 /// The general line break segmenter.
 static SEGMENTER: LazyLock<LineSegmenterBorrowed> =
-    LazyLock::new(|| LineSegmenter::new_lstm(LineBreakOptions::default()));
+    LazyLock::new(|| LineSegmenter::new_neo_for_non_complex_scripts(LineBreakOptions::default()));

 /// The Unicode line break properties for each code point.
 const LINEBREAK_DATA: CodePointMapDataBorrowed<LineBreak> =

@Manishearth

Copy link
Copy Markdown
Author

Aha, I see the problem. The updated ICU4X APIs are still on the old engine, ICU4X 2.4 has new_17 and neo APIs for Unicode 17 and 18 respectively. Both those sets of APIs are still unstable. So you're stuck with this until ICU4X stabilizes new APIs, hopefully in the next release.

Unless you're okay using unstable APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file i18n About language- or script-specific features. May need attention from native speakers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICU4X 2.4 is released with Unicode 17.0 and 18.0 data

3 participants