6 ms·
The experience of rendering Arabic typography and its technical debt
- adam_rida 5mo agovery interesting, arabic is a good reminder that text rendering is mostly solved for the scripts that shaped the defaults. The hard part is that typography, shaping, bidi behavior, font fallback, search, and the editor model all leak into each other. You cannot fix one layer cleanly when the assumptions are wrong in all of them.
- yorwba 5mo agoA more academic treatment of justifying Arabic-script text can be found in https://quod.lib.umich.edu/j/jep/3336451.0023.104?view=text;rgn=main https://quod.lib.umich.edu/j/jep/3336451.0023.104?view=text;...
- mackeye 5mo agoawesome article! i appreciated the alternatives and misc. workarounds to OT/unicode typesetting toward the end, very helpful :D (go blue!)
- tensegrist 5mo ago[flagged]
- deleted 5mo ago[deleted]
- masfuerte 5mo agoSame, and it is a shame. Reading it is wearisome.
- creesch 5mo agoThat might be because of translations from Arabic. The article was also posted on a different website where the author responded > the Kashida section was contributed to this post from a talk in Arabic of Nawal Hadeed, which she translated and added to the post herself. Although I'm unsure of LLM usage in the translation process, looking at the original Arabic I felt some change in tone while editing the post. I could have either declined the translation and never have this documented, procrastinate in translating it myself (which has been ongoing for a while), or publish as it is. I found the last least damaging.
- mohamedkoubaa 5mo agoI'd like to see some more mainstream usage of disconnected fonts for Arabic, for example like these: https://www.arabaddigital.com/en/article/2100-Quarantining-on-Disconnected-Arabic-Fonts-Kameel-Hawa-s-new-take-at-the-art-of-shaping-Arabic-letters https://www.arabaddigital.com/en/article/2100-Quarantining-o...
- amdivia 5mo agoThis was once attempted, and in a way such that each letter needed only one character no matter it's position in the word Unfortunately it died https://worksthatwork.com/6/unified-arabic https://worksthatwork.com/6/unified-arabic
- mohamedkoubaa 5mo agoI actually like that they depend on position, it even carries semantic information when reading because of how conjugation works so it actually helps you read faster
- jansan 5mo agoVery interesting. I just implemented a text shaper and renderer from scratch with support for complex scripts like Arabic, Nastaliq and Indic (will soon post about it here on HN). Now that you write about it, the lack of stretching really is a deficiency in the OpenType spec. If you want a solution for this it has to happen in the rendering step, not the shaping (which is HarfBuzz's main task). The shaper has no information about the available space, but when rendering you could stretch individual glyphs to the desired width, similar to adjusting the width of whitespace in Latin, but more complex, because you actually have to modify the glyphs with a scale transform. I am not an expert on Arabic script by any means, but this should be possible IMO. It would at least be an interesting experiment. Of course the JSTF table would be the right way to do it, but there seems to be a lot of confusion around it. Maybe in the age of LLMs we can give it another shot.
- amluto 5mo agoIt does seem like a KP-like algorithm ought to be able to optimize the break positions without extreme algorithmic difficulty aside from the inputs being considerably more complex than for Latin block print: the cost function for a proposed line is a straightforward [0] calculable function of the contents of the line, and I think one could make a dynamic programming algorithm that tracks, for each input position, the cost of the optimal layout of all text up to that position with a break at that position. This gives an algorithm that takes cubic time. (For input length n, you need to fill in n values in the table. Each value scans the entire table before that position and does a calculation with complexity linear in the proposed line length.) As a practical matter, there’s an input length n and there is some upper bound B on a credible line length as measured in code points, so there are only at most n*B credible proposed lines to evaluate, which also limits the useful look back on the table to B positions, so I think the time complexity could be reduced to O(n*B^2) without making the results worse on reasonable inputs, and this is probably quite tolerable. [0] Straightforward once you’ve implemented the whole Arabic rendering stack, anyway. I am certainly not qualified to calculate this function :)
- alfiedotwtf 5mo ago> but when rendering you could stretch individual glyphs to the desired width “Individual glyphs” :) It’s Arabic, so you wouldn’t stretch a single glyph, id would have to e done after shaping so you can work out the next run (either a single Aleph or the joined characters) in order to know what is stretchable (then throw it to your layout step)
- amluto 5mo agoIs this a small typo? > The relevant rule, W2 of UAX #9, reclassifies a digit as an ARABIC NUMBER if any of the previous strong characters in the paragraph were Arabic letters, and as a EUROPEAN NUMBER otherwise. Both render their internal digits left-to-right, which is correct: numbers everywhere on Earth are read most-significant-first. Does the author mean most-significant-on-the-left? The statement as written is a statement about the order in which one reads or perhaps thinks the number, whereas I think the author is discussing how numbers, including collections of numbers delimited by hyphens and such, should be laid out on the page.
- slim 5mo agoI think he's talking about the rendering algorithm with regards to the stream of text. essentially saying rendering direction should follow reading convention. on the other hand, in formal arabic, it's not unusual that numers are read in clusters from least significant to most significant (right to left). 1984 would be read : eighty four and nine hundred and a thousand. not sure if the author is aware of this
- slim 5mo agoactually : four and eighty and nine hundred and a thousand
- khaled 5mo agoNumbers below 100 are always read from right to left even in vernacular/informal/dialectical Arabic.
- amluto 5mo ago> rendering direction should follow reading convention. What does that even mean in this context? In a strictly LTR language, sure, you read left-to-right and the glyphs are rendered left-to-right. But the whole discussion is about bidirectional text, where the text is rendered by a complex algorithm. What is the “rendering direction”? I know just enough about some RTL languages to know that one can absolutely intersperse RTL text with, say, and English phrase, and you still read the first (leftmost in the group) English sound first and so on :)
- throw-the-towel 5mo agoThis article is wonderful. It's interesting, it's captivating, full with detail, and to think I never gave much thought about Arabic rendering before. This part nearly had me chuckle audibly: He says yes. The result is "Simplified Arabic": initial fused into medial, final into isolated, ligatures dropped. It conquers the Arab newsroom in a generation. Mrowa is assassinated at his desk eight years later, by an unrelated faction, in an unrelated dispute. Also, it's depressing how hundreds of millions of people couldn't even get their language typeset on a computer, and our industry meanwhile was busy building AI-native AI for your groceries (have we mentioned it has AI btw?) and similar performative bullshit.
- slim 5mo agomaybe AI will solve this ?
- kg 5mo agoAI can probably solve "how do we get good shaper implementations into software", provided a good enough spec and test suite are available, but it won't solve "how do we convince stakeholders to value supporting languages spoken by massive numbers of people", most likely
- gwern 5mo ago> Also, it's depressing how hundreds of millions of people couldn't even get their language typeset on a computer, and our industry meanwhile was busy building AI-native AI for your groceries (have we mentioned it has AI btw?) and similar performative bullshit. AI also brought you this "wonderful" article, I would note.
- evmar 5mo agoOne thing I sometimes think about when I think about text layout problems is how the text we use also has a bunch of complexities that we can take for granted. Think of variable width characters and kerning and ligatures and hyphenation and justification. Imagine computers had been won by a CJK language, which have none of these problems. You could imagine a similar article about how exotic and difficult English layout is.
- deleted 5mo ago[deleted]
- retrac 5mo agoBoth Latin and Chinese have been modified by the technology used to write them. When carved in stone the lines are much straighter. When written with brush or pen they became semi-cursive. When printing was introduced, they became grid-like and regular. What westerners who are passingly familiar would think of as the standard Chinese typeface - the strict square grid with straight-line characters - arises in part from printing technology. Easy to carve that into wood blocks, and easy to line up the slots into a grid. Latin was similarly morphed to fit into the realities of printing in the 1500s. And is still being morphed. Notice how numbers 123... are in-line and at the same height as the letters. That's a very modern convention, typewriter and computer influence on our orthography. Traditionally digits were more likely to appear as subscript, off-centre.
- nagaiaida 5mo agowhat selective pressures against oldstyle numerals with ascenders/descenders existed that wouldn't have equally applied to letterforms with those same features? (aha i have found the answer to my own question: miniaturization for fractions in phototypesetting)
- adgjlsfhk1 5mo agothe other part is that numbers and symbols were very much not the priority. The printing press was for books, magazines etc. math remained hand written until the computer
- VeninVidiaVicii 5mo agoDisclaimer: I’m not fluent in Arabic by any means, but the stretched out to both margins style looks very Quranic to me. I don’t think it looks appropriate for say, a message about my DoorDasher.
- ramblurr 5mo agoBut a message about your Door dasher also likely wouldn't be justified.
- slim 5mo agoInternet Explorer 5.5 implements text-justify: kashida. For one brief, weird browser-quarter Microsoft is the only software vendor on earth that can justify Arabic correctly on a screen.
- evilturnip 5mo agoArabic script is a great test to see if your terminal/renderer/UI can handle anything: contexual shaping, cursive connectivity, bidirectional text layout, diacritics and vertical displacement. I went down this rabbit-hole awhile back and it made me really appreciate the complexity of the script.
- kqr 5mo agoThis explains a lot of why I think Arabic looks so beautiful on the page. I also love the way it can sound when spoken. Shame I don't have reason good enough to take the years I would need to learn it.
- jazzyb 5mo agoLearning language is like learning poetry. Your appreciation of the thing grows proportionally with the practice. Which means you don't need to learn to fluency to appreciate Arabic. Even modest practice, just learning to write the alphabet, will increase your appreciation for the language if that's what you'd like to do.
- Obscurity4340 5mo agoHave experienced this with a bilingual relative whos language i have learned bits and pieces of both of us enjoy it. They give you little challenges from time to time too which is fun
- qingcharles 5mo agoIt's funny -- I hate the way Arabic sounds when spoken, even though I agree it looks pretty. To my ears French and Japanese sound the nicest.
- samat 5mo agoI feel so sorry for Arabs now, just read that paragraph about everyday experience of trying to write English-Arabic text in the mail or any other editor. > I have watched senior engineers, fluent in both Arabic and English, give up on writing a long email in Outlook on a Wednesday afternoon because the cursor would not behave, and switch to Arabic-only or English-only because the cognitive cost of fighting the editor exceeded the cost of monolingual phrasing. Actually I remember very well suffering this while using Facebook for the first time in my life, and I could not register; I was very slow typer that when I reached the moment the cursor does this weird thing, I would just stare at it and never progress. > This is the ordinary experience of writing mixed Arabic-English text in 2026, in every major editor, email client, and chat application I know of. The pettier cousins are everywhere too, and I collect them: a range like 10–20 silently reading as twenty-to-ten, because digits are weak and the dash is neutral; a trailing exclamation mark teleporting to the far end of the line; a password, toggled visible, displaying in an order that does not match what was typed. None of these are anyone's bug, exactly. My own Cyrillic struggles are nothing in comparison.
- khoirul 5mo agoMonday's editor does this even for English text!
- dhosek 5mo agoThe complexities of mixed LR and RL text are quite astonishing since it’s not really even a case of just switching modes when switching scripts since double-nested (or more) texts can change the semantics of line breaks. This article provides a good overview: https://tug.org/TUGboat/tb08-1/tb17knutmix.pdf https://tug.org/TUGboat/tb08-1/tb17knutmix.pdf [1] In college [2], when I wanted to quote some texts from Exodus in Hebrew in a paper that I wrote, I ended up avoiding the issue by hand-reversing the letter order and manually breaking lines. 8 bits is insufficient to cover all the possible combinations of letters and vowel markings so the font didn’t include any vowel markings and only did dageshim for בּ and פּ if I recall correctly. ⸻ 1. As an aside, it would have been really nice if Unicode provided a R-L mirrored Latin alphabet to make it easier for monolingual developers to grasp the complexities surrounding mixed directional typesetting. I suppose it could still be added, although Unicode tends towards conservatism on adding additional characters. 2. This was 1990, well before Unicode in the era of a hundred or so 8-bit character encodings, most of which were not implemented widely. I also had to type the text using the arbitrary ASCII-Hebrew mapping of the font I was using which, among other things, led me to discover that letter frequency in Hebrew is much more uniform than it is in English.
- Georgelemental 5mo agoSee also: https://notarabic.com/ https://notarabic.com/
- qingcharles 5mo agoI could write all day about how badly RtL languages are treated on electronic devices. Most interfaces just slop RtL text into an interface that is otherwise the totally wrong way around. One thing that amuses me is that people share these "safe zone" templates for short form video to make sure your content isn't hidden behind the buttons: https://imgur.com/a/MrIQZen https://imgur.com/a/MrIQZen But look over the shoulder of someone using the Arabic version of TikTok and you'll realize how flawed that is: https://imgur.com/a/5iLXd2o https://imgur.com/a/5iLXd2o
- anal_reactor 5mo agoTo me it sounds like it's high time Arabic got a new script that's compatible with computers. I've seen some Lebanese people use mix of Latin letters and digits to type, so the idea isn't entirely stupid.
- amake 5mo agoComputers are tools that exist to serve humans. Humans should never be asked to become subservient to computers. Your suggestion is ludicrous and risible.
- anal_reactor 5mo agoYeah cool then enjoy your text being broken
- amake 5mo agoEnjoy being a slave to a machine, I guess?
- anal_reactor 5mo agoThe ability to adapt to changing environment is one of core properties of life. You cannot un-invent the printing press. Imagine making an argument "nooooo you cannot print books, it takes away the human element" and then "nooooo you cannot write down stories, it takes away the human element" and then being obliberated by a civilization that embraced new inventions instead of rejecting them based on "no means no".
- NooneAtAll3 5mo ago> Editable; go on, click in. Place the caret at the start of the line, hold the Left arrow, and enjoy the moment it reaches the version number, where it will jump, double back, or sail through depending on your browser. what's missing here is "use shift + arrow keys for selection" Firefox manages movement just fine. Selection tho? oh boi
- jrdres 5mo agoBelieve it or not, there once was an 8-bit computer with native Arabic. It was a version of the Z-80 MSX series by Al Alamiah called Sakhr. It seems it could switch between English, Arabic, or mixed. (In fact, this was mentioned in the OP.) I'm curious how it handled mixed entry. https://forum.vcfed.org/index.php?threads/bought-a-al-alamiah-ax230-msx-r-%D9%83%D9%85%D8%A8%D9%8A%D9%88%D8%AA%D8%B1-%D8%B5%D8%AE%D8%B1-very-rare-personal-computer.59512/ https://forum.vcfed.org/index.php?threads/bought-a-al-alamia... https://www.msx.org/wiki/Sakhr_AX-230 https://www.msx.org/wiki/Sakhr_AX-230