Skip to content

Update icu4x to version 2.2 - #8406

Merged
laurmaedje merged 2 commits into
typst:mainfrom
isuffix:upgrade-icu4x
Jun 4, 2026
Merged

laurmaedje merged 2 commits into
typst:mainfrom
isuffix:upgrade-icu4x

Conversation

@isuffix

@isuffix isuffix commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Updates icu4x to version 2.2.0 and uses constant compiled data instead of postcard data where possible.

This depends on the updated postcard data for CJ line segmenting in my fork of typst-assets, but can target the official repo once typst/typst-assets#20 lands.

Closes #7834
Based on work by @mohtakver in #7412
Adds the test from #7652 by @eltos, closing #1920
Supersedes #8396 by @Drodt, unblocking work on typst/hayagriva#314
Finally unblocks #7350, which I will be rebasing on top of this branch

Why did this take so long?
We currently run patched line segmenter data for icu4x v1.4 that were generated by @peng1999 for #1355. These data apply custom line break properties to curly quotes (“, U+201C and ”, U+201D) for the line segmenter so that there are only line break opportunities on the outside of the quotes, which is important for good linebreaking in Chinese and Japanese.

However, postcard blobs from icu4x v1.x are incompatible with v2.x. So to avoid regressing linebreaking for Chinese/Japanese, updating icu4x has stalled on regenerating the postcard data, which is a huge hassle, but I have persevered! Fixing this required researching and understanding the original problem, the original fix to the problem, how icu4x data loading works, how icu4x data generation changed in version 2, recovering from dead ends like using the unstable neo line segmenter, and incorporating all of those fixes together in the current Typst repo.

Wait, what was that about an unstable neo line segmenter? I'm so glad you asked!

  • icu4x v2.2 was originally going to use Unicode 17 for their line segmenter, but reverted the change a few days before the release when issues were found
  • There has also been work (by @robertbastian) on a new unstable, "neo" line segmenter that would allow for various improvements
  • With Unicode 17, the neo segmenter correctly handles linebreaking around quotes in Chinese and Japanese
  • So I originally looked into just using a git revision in the Cargo.toml targeting the neo line segmenter Unicode 17 update
  • But when we publish the Typst crates on crates.io, we can't include any git dependencies
  • So we would either need to ask icu4x to make a patch release containing the new line segmenter, which would be a massive imposition
  • Or we can wait until the next icu4x release, but that could take any number of months
  • Or I can roll up my sleeves and figure out how to port the CJ segmenter patch to v2.2

So, I finally caved to the last option and made this PR. However I will be very excited for the CJ segmenter patch to be made obsolete by a future version of icu4x!

@isuffix isuffix added the dependencies Pull requests that update a dependency file label Jun 2, 2026
@laurmaedje laurmaedje added the waiting-on-review This PR is waiting to be reviewed. label Jun 4, 2026
@laurmaedje

Copy link
Copy Markdown
Member

FYI: I'm currently rebasing this and preparing for merge. I've decided to squash the latter two commits (to not have an intermediate bad state on main) and to reorder the test commit to the back (to not have a wrong test reference). I think your commit structure was useful for review, but I prefer the other structure on main.

isuffix and others added 2 commits June 4, 2026 15:10
@laurmaedje

Copy link
Copy Markdown
Member

Parts of ixu4x 1.5 were still in the dependency tree. I manage to get rid of it by running cargo update -p idna_adapter (c.f. their docs). :)

@laurmaedje
laurmaedje merged commit 7152b97 into typst:main Jun 4, 2026
9 checks passed
@laurmaedje

Copy link
Copy Markdown
Member

Thanks!

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 waiting-on-review This PR is waiting to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update to icu4x 2.x

2 participants