Skip to content

feat: right-to-left text in the order it reads - #129

Merged
anderix merged 1 commit into
mainfrom
right-to-left-76
Nov 11, 2026
Merged

anderix merged 1 commit into
mainfrom
right-to-left-76

Conversation

@anderix

@anderix anderix commented Nov 11, 2026

Copy link
Copy Markdown
Member

Hebrew and Arabic were drawn in the wrong order. egui 0.37 has no bidirectional algorithm: it shapes each run with a guessed direction, so a whole run flipped, Latin and digits with it (fed cba, 4202), and a paragraph took its direction from its first letter.

  • odox_core::bidi wraps unicode-bidi (new dependency, Servo's, default features only): a paragraph's direction comes from style:writing-mode (read into ParagraphProperties::right_to_left), never from its first letter, as LibreOffice reads it; each line's runs come out in visual order.
  • Window (all three: Flow for text and slides, cells in Odox Grid): a paragraph that needs it is broken into lines here — egui breaks lines by glyph position, and a turned word scrambles that, splitting words — and each line handed to egui in visual order: a right-to-left word as written for the shaper to turn, the spaces and punctuation between words turned here with brackets mirrored. Plain left-to-right paragraphs take the old path untouched.
  • Read-only: what is drawn no longer lines up with the text the page editor edits, so such a paragraph is read, not edited; hovering it in edit mode says so (German added). Editing is Edit text that reads right to left #128.
  • PDF: a stretch reading right to left is shaped right to left by rustybuzz, its glyphs kept in written order for line breaking, and each line drawn in visual order; the text a reader gets stays in written order.
  • Alignment: measured, LibreOffice aligns start (and no alignment) to the left margin even in a right-to-left paragraph, and end to the right; that is what the existing mapping already does, so it is unchanged.
  • Fallback faces (odox_fonts::faces_with): the generic monospace family no longer comes before everything else, and faces in the variant's weight and slant that are proportional come before the rest. Arabic was falling back to DejaVu Sans Mono, and bold faces turned up for regular text; both the window and the PDF use this.

New corpus fixture directions.odt; compared side by side with LibreOffice's rendering in the window and in the PDF, the same order on every line. Tests: the bidi runs in odox-core, a line's visual glyph order in odox-pdf, and veraPDF on the fixture.

Closes #76.

…r the Unicode bidirectional algorithm gives, in the direction its paragraph says
@anderix
anderix merged commit 913a8aa into main Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Right-to-left text is drawn left to right

1 participant