Skip to content

Add Arabic text shaping for PDF export#22656

Open
alghanim wants to merge 1 commit intoopf:devfrom
alghanim:feature/pdf-arabic-shaping
Open

Add Arabic text shaping for PDF export#22656
alghanim wants to merge 1 commit intoopf:devfrom
alghanim:feature/pdf-arabic-shaping

Conversation

@alghanim
Copy link
Copy Markdown

@alghanim alghanim commented Apr 2, 2026

Summary

  • Add Exports::PDF::Common::ArabicShaping module that converts Arabic characters to Unicode Presentation Forms based on joining context
  • Intercept all Prawn text methods (text, draw_text, formatted_text, text_box, make_cell) on the PDF document instance
  • Supports all standard Arabic letters, extended Arabic (Farsi, Urdu), Lam-Alef ligatures, and diacritical marks
  • Zero performance impact on non-Arabic text (early return)
  • Upstream PR on Prawn: Add Arabic text shaping support prawnpdf/prawn#1392

Context

Arabic is a cursive script where characters must connect based on position. Prawn uses ttfunk for font parsing but does not run the OpenType shaping engine, rendering all Arabic characters in isolated form — completely unreadable.

Test plan

  • Export work package with Arabic title/description to PDF — characters connected
  • Export work package table with Arabic content — cells render correctly
  • Mixed Arabic/English text displays correctly
  • Arabic with diacritics renders correctly
  • Lam-Alef combinations form ligatures
  • Non-Arabic exports unaffected

Prawn does not perform OpenType text shaping, so Arabic characters
render as disconnected isolated glyphs. This adds a shaping module
that converts Arabic characters to their Unicode Presentation Forms
(initial/medial/final/isolated) before Prawn renders them.

Features:
- All standard Arabic letters (U+0621-U+064A)
- Extended Arabic (Farsi, Urdu: Peh, Tcheh, Gaf, etc.)
- Lam-Alef mandatory ligatures
- Diacritical marks preservation
- Intercepts all Prawn text methods via document singleton

See also: prawnpdf/prawn#1392 for upstream PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant