The Technical Debt of Arabic Typography Rendering
The Gap Between Digital Rendering and Classical Arabic Typography
Modern web browsers cannot natively perform proper Arabic justification. While Latin scripts justify text by stretching spaces between words, classical Arabic typography uses taṭwīl (or kashida)—the elongation of the connecting strokes within words themselves to fill a line to the margin.
Because modern layout engines treat Arabic justification as a spacing problem rather than a shaping problem, they produce "ragged" edges or unsightly gaps between words. This failure is not a lack of theoretical knowledge—the rules for proportional script (al-khaṭṭ al-mansūb) were codified by the 10th-century vizier Ibn Muqla—but a structural failure in how browser engines handle text breaks and glyph stretching.
The Complexity of Contextual Shaping
Arabic is inherently cursive; there is no distinction between print and handwriting. Every letter changes shape based on its position relative to its neighbors, requiring four distinct forms: isolated, initial, medial, and final.
The Role of the Shaping Engine
To render Arabic correctly, software must use a shaping engine (such as HarfBuzz) to translate abstract Unicode codepoints into specific glyphs at render time. This process involves applying OpenType features:
isol,init,medi,fina: Positional shapes.rlig: Required ligatures (e.g., the lām-alif), without which the text is considered illiterate.markandmkmk: Stacking vowel signs.
Without a shaping engine, text renders as a series of disconnected isolated letters laid out left-to-right, a common failure in older PDF generators, some plotting libraries (like matplotlib), and receipt printers.
Legacy Encoding Debt
Unicode contains "Arabic Presentation Forms" (U+FB50 through U+FEFF), which store the shapes themselves rather than the abstract letters. These were included for round-trip compatibility with 8-bit code pages. This creates significant technical debt: two strings can look identical on screen but fail a search query because one is encoded as abstract letters and the other as presentation shapes. Resolving this requires NFKC normalization to collapse shapes back into their base letters.
Bidirectional (Bidi) Layout and the "Lying" Cursor
Mixed-content Arabic (text containing Latin characters, numbers, or URLs) is governed by the Unicode Bidirectional Algorithm (UAX #9). This algorithm assigns characters "directional personalities" (Strong RTL, Strong LTR, Weak, or Neutral) and reorders them for display.
The Cursor Boundary Problem
Because the visual order on screen differs from the logical order in memory, text editors often struggle with caret placement at run boundaries. This results in the cursor "jumping" or "doubling back" when navigating mixed-script text.
Numerical Weakness
Digits are classified as "weak" characters. Under rule W2 of UAX #9, a digit is reclassified as an ARABIC NUMBER if preceded by Arabic letters, and a EUROPEAN NUMBER otherwise. This leads to common rendering bugs, such as phone numbers (e.g., "010-1234-5678") being reversed on screen because the hyphens are treated as neutral and the number runs swap places around them.
The History of Technical Compromise
The history of Arabic printing is a series of simplifications to fit the script into the limitations of the machine:
- 1514 (Fano): The first movable type Arabic book was set by non-speakers, resulting in detached letters and drifting dots.
- 1924 (Cairo Qurʾān): The Bulaq/Amiria Press achieved high-fidelity rendering using hundreds of separate metal sorts for positional forms and ligatures.
- 1958 (Simplified Arabic): To fit the 90-channel magazine of Linotype machines, Kamel Mrowa and Linotype merged initial forms into medials and final forms into isolateds, dropping most ligatures. This "Simplified Arabic" became the global standard for newsrooms due to cost and speed.
The Current State of Open-Source Infrastructure
Much of the working Arabic text stack is the result of unpaid volunteer effort rather than commercial investment:
- Amiri Font: Created by Khaled Hosny, this OFL font revives the Bulaq Press face and includes a curvilinear kashida for manual elongation.
- HarfBuzz: The shaping engine used by Chrome and Android, heavily developed by Behdad Esfahbod and Khaled Hosny.
- The Justification Standoff: Despite the W3C's Arabic Layout Requirements task force, the
jstfOpenType table (which allows fonts to declare justification priorities) remains largely unread by engines and unshipped by foundries.
"The browser vendors took HarfBuzz when it was free and finished, and have contributed approximately nothing toward the justification work that would let the scribes' system finally run on a screen."