Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 3 min read

The Subset Font That Turned My Arabic Text Into Empty Boxes

I was rendering product images for my shop: Arabic text, the brand name "STYLE POINT", and prices. Some words came out fine. Others came out as empty boxes. No error, no warning β€” just tofu where letters should be. It t

I was rendering product images for my shop: Arabic text, the brand name "STYLE POINT", and prices. Some words came out fine. Others came out as empty boxes. No error, no warning β€” just tofu where letters should be.

It took me a while to realize the bug wasn't in my code at all. It was in the font file.

The symptom: some words render, some don't

The broken words had something in common, but it wasn't obvious at first. "STYLE POINT" showed as boxes. Prices (digits) showed as boxes. The Arabic word "ΨͺΨ΄ΩƒΩŠΩ„Ψ©" showed as boxes β€” while other Arabic words rendered perfectly.

Three different kinds of text, all broken. That pattern was the clue: the problem wasn't the text, the layout, or the rendering library. It was the font itself.

The cause: a subset font

The font I was using, Cairo-Bold in .woff2 format, was a subset. A subset font is a font file with most glyphs stripped out to make it smaller β€” it only contains the characters the person who built it thought you'd need.

This one was missing:

  • Latin capital letters (so "STYLE POINT" became boxes)
  • Digits (so prices became boxes)
  • The Arabic letter Ψ© in its final form (U+FE93) β€” so words like "ΨͺΨ΄ΩƒΩŠΩ„Ψ©" broke, even though other Arabic words were fine

That last one is the cruelest kind of font bug: it doesn't break all Arabic, just the words that happen to end in Ψ©. Everything looks fine until exactly the wrong word shows up.

The fix: build one full font, and let the shaper do its job

I fixed it in two steps.

First, I built a complete font. Using fontTools, I merged the full Arabic and Latin versions of Cairo Bold (weight 700) into a single file, Cairo-Bold-full.ttf. One font file, every glyph I need, no more guessing which characters survived the subsetting.

Second, I stopped reshaping Arabic text by hand. I had been using a reshaping library to connect Arabic letters before drawing. I switched to letting Pillow do it natively, with proper shaping support (raqm/harfbuzz) and right-to-left direction:

from PIL import ImageFont, ImageDraw

font = ImageFont.truetype("Cairo-Bold-full.ttf", 84)
draw.text((x, y), "ΨͺΨ΄ΩƒΩŠΩ„Ψ© STYLE POINT 250",
          font=font, fill="white",
          direction="rtl", language="ar")

With the full font and native shaping, everything renders: Arabic, Latin capitals, digits, mixed text on the same line.

The lesson I now apply everywhere

Two rules I never break anymore:

  1. Never trust a font you didn't verify. A font file that works for your test words can still be missing the exact glyphs your real content needs. Check the full font, not the demo.
  2. Never rely on local() for Arabic fonts. In my YouTube pipeline I had the same class of bug: the system font wasn't guaranteed to exist. Now I always bundle a real Arabic .woff2 with @font-face (Cairo Bold for titles) β€” the font ships with the project, or it doesn't ship at all.

The bug looked like a rendering problem. It was a supply-chain problem: the asset I depended on was incomplete, and nothing told me so. The empty boxes were the only warning I got β€” and honestly, I was lucky to get even that.

I'm Wahib El Khadiri, a junior full-stack developer from KΓ©nitra, Morocco. I build with React, Node.js and Laravel, contribute to open source, and teach React in Darija on YouTube. Portfolio: https://wahib-portfolio.netlify.app β€” GitHub: https://github.com/WAHIB-EL-KHADIRI

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.