[PR #2534] [MERGED] Draw Arabic, Persian and Hebrew text joined and right to left #4404

Closed
opened 2026-11-03 04:16:54 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2534
Author: @kacpherek
Created: 10/26/2026
Status: ✅ Merged
Merged: 10/27/2026
Merged by: @ludovic111

Base: main ← Head: feat/bidi-text


📝 Commits (4)

  • 26aef75 Shape and reorder right-to-left text before drawing it
  • 8a5d7bb Leave the extended Arabic letters unshaped, as ICU does
  • 9ada76e Restore the lam-alef madda and hamza ligature rows in FORMS
  • 6b5963d Merge main into feat/bidi-text

📊 Changes

9 files changed (+344 additions, -5 deletions)

View changed files

📝 Cargo.lock (+7 -0)
📝 crates/horizon-client-core/src/lang.rs (+18 -1)
📝 crates/horizon-client/Cargo.toml (+1 -0)
➕ crates/horizon-client/src/bidi.rs (+302 -0)
📝 crates/horizon-client/src/block_entity_render.rs (+2 -0)
📝 crates/horizon-client/src/font.rs (+8 -3)
📝 crates/horizon-client/src/game/names.rs (+3 -1)
📝 crates/horizon-client/src/hud.rs (+2 -0)
📝 crates/horizon-client/src/lib.rs (+1 -0)

📄 Description

What and why

Persian, Arabic and Hebrew text was drawn letter by letter in typing order, so letters stayed unjoined and lines read left to right. Vanilla runs every string through Language.getVisualOrder before drawing it.

This adds that step (crates/horizon-client/src/bidi.rs):

  • Arabic letters are shaped into their joined forms (isolated, initial, medial, final), including lam-alef ligatures and diacritics between joined letters. The extended letters (پ چ ژ ک گ ی and the rest of U+0679 to U+06D3) keep their base glyph, as in vanilla (icu4j leaves them unshaped), but they still join the letters next to them.
  • The text is reordered with the Unicode bidirectional algorithm. The paragraph direction follows the first strong character, or right to left for a language with bidirectional set.
  • Characters in right-to-left runs are mirrored (brackets and the other Bidi_Mirrored characters).
  • Each character keeps its style.
  • Text without right-to-left characters is returned as is, without allocating.

It is applied where text becomes glyphs: GUI and chat text (HudBatch::text_styled), name tags and text displays, and sign lines. Font::width and Font::width_text measure the shaped text, so centring and boxes match what is drawn. Line wrapping still measures the logical text, as StringSplitter does.

New dependency: unicode-bidi 0.3.18 (MIT or Apache-2.0, no dependencies of its own). The shaping table is written here, not taken from a crate.

Fixes #2497.

Vanilla reference

  • FormattedBidiReorder.reorder and shape (ArabicShaping(LETTERS_SHAPE), ICU Bidi with DEFAULT_LTR / DEFAULT_RTL)
  • ClientLanguage.getVisualOrder and defaultRightToLeft (LanguageInfo.bidirectional)
  • SubStringSource (styles per character, mirrored characters in reversed runs)
  • UCharacter.getMirror
  • Component.getVisualOrderText for name tags and signs

The joining table, forms and mirror pairs were generated from ICU's behaviour. The Rust code was compared on random strings (shaping, and the whole shape, reorder and mirror pipeline, in both default directions) with ICU4C, not with icu4j, which vanilla uses. The results matched apart from where ICU puts the explicit embedding controls (U+202A to U+202E) themselves, which are glyph boxes in unifont, and the extended letters above, whose shaping differs between the two. After the review these were fixed to follow icu4j, and spot-checked with icu4j-78.3 (0628 067E 0628 gives FE91 067E FE90, 0686 0627 gives 0686 FE8E).

One thing kept from vanilla on purpose: a lam-alef ligature makes the text one character shorter, and vanilla then takes styles by position in the shaped text, so in text with several styles the ones after a ligature shift by one character.

Self-check

cargo check -p horizon-client passes; clippy with warnings denied is clean, and the existing lang and font tests pass. In game (offscreen, single player): /tellraw @s "سلام دنیا", "مرحبا بالعالم" and a mixed line Hello سلام (دنیا) 123 show joined letters, right to left, with the number and brackets in the right places. A sign with Arabic and Persian lines shows the same, and a named pig shows a mixed name tag in the right order.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/2534 **Author:** [@kacpherek](https://github.com/kacpherek) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/27/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/bidi-text` --- ### 📝 Commits (4) - [`26aef75`](https://github.com/horizon-rust/horizon/commit/26aef75d7cea8a22c846be52f6263b9cab6ccf5b) Shape and reorder right-to-left text before drawing it - [`8a5d7bb`](https://github.com/horizon-rust/horizon/commit/8a5d7bb78d35b6974b97f5487f7d51b047b8ab71) Leave the extended Arabic letters unshaped, as ICU does - [`9ada76e`](https://github.com/horizon-rust/horizon/commit/9ada76e00a53c83f164a7996246fffa7ee419e62) Restore the lam-alef madda and hamza ligature rows in FORMS - [`6b5963d`](https://github.com/horizon-rust/horizon/commit/6b5963d11108071372d49181272a5c521a7b35ed) Merge main into feat/bidi-text ### 📊 Changes **9 files changed** (+344 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+7 -0) 📝 `crates/horizon-client-core/src/lang.rs` (+18 -1) 📝 `crates/horizon-client/Cargo.toml` (+1 -0) ➕ `crates/horizon-client/src/bidi.rs` (+302 -0) 📝 `crates/horizon-client/src/block_entity_render.rs` (+2 -0) 📝 `crates/horizon-client/src/font.rs` (+8 -3) 📝 `crates/horizon-client/src/game/names.rs` (+3 -1) 📝 `crates/horizon-client/src/hud.rs` (+2 -0) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) </details> ### 📄 Description ## What and why Persian, Arabic and Hebrew text was drawn letter by letter in typing order, so letters stayed unjoined and lines read left to right. Vanilla runs every string through `Language.getVisualOrder` before drawing it. This adds that step (`crates/horizon-client/src/bidi.rs`): - Arabic letters are shaped into their joined forms (isolated, initial, medial, final), including lam-alef ligatures and diacritics between joined letters. The extended letters (پ چ ژ ک گ ی and the rest of U+0679 to U+06D3) keep their base glyph, as in vanilla (icu4j leaves them unshaped), but they still join the letters next to them. - The text is reordered with the Unicode bidirectional algorithm. The paragraph direction follows the first strong character, or right to left for a language with `bidirectional` set. - Characters in right-to-left runs are mirrored (brackets and the other `Bidi_Mirrored` characters). - Each character keeps its style. - Text without right-to-left characters is returned as is, without allocating. It is applied where text becomes glyphs: GUI and chat text (`HudBatch::text_styled`), name tags and text displays, and sign lines. `Font::width` and `Font::width_text` measure the shaped text, so centring and boxes match what is drawn. Line wrapping still measures the logical text, as `StringSplitter` does. New dependency: `unicode-bidi` 0.3.18 (MIT or Apache-2.0, no dependencies of its own). The shaping table is written here, not taken from a crate. Fixes #2497. ## Vanilla reference - `FormattedBidiReorder.reorder` and `shape` (`ArabicShaping(LETTERS_SHAPE)`, ICU `Bidi` with `DEFAULT_LTR` / `DEFAULT_RTL`) - `ClientLanguage.getVisualOrder` and `defaultRightToLeft` (`LanguageInfo.bidirectional`) - `SubStringSource` (styles per character, mirrored characters in reversed runs) - `UCharacter.getMirror` - `Component.getVisualOrderText` for name tags and signs The joining table, forms and mirror pairs were generated from ICU's behaviour. The Rust code was compared on random strings (shaping, and the whole shape, reorder and mirror pipeline, in both default directions) with ICU4C, not with icu4j, which vanilla uses. The results matched apart from where ICU puts the explicit embedding controls (U+202A to U+202E) themselves, which are glyph boxes in unifont, and the extended letters above, whose shaping differs between the two. After the review these were fixed to follow icu4j, and spot-checked with icu4j-78.3 (`0628 067E 0628` gives `FE91 067E FE90`, `0686 0627` gives `0686 FE8E`). One thing kept from vanilla on purpose: a lam-alef ligature makes the text one character shorter, and vanilla then takes styles by position in the shaped text, so in text with several styles the ones after a ligature shift by one character. ## Self-check `cargo check -p horizon-client` passes; clippy with warnings denied is clean, and the existing `lang` and `font` tests pass. In game (offscreen, single player): `/tellraw @s "سلام دنیا"`, `"مرحبا بالعالم"` and a mixed line `Hello سلام (دنیا) 123` show joined letters, right to left, with the number and brackets in the right places. A sign with Arabic and Persian lines shows the same, and a named pig shows a mixed name tag in the right order. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:16:54 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#4404
No description provided.