<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Building Folium]]></title><description><![CDATA[Building Folium]]></description><link>https://foliumcv.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 24 Nov 2026 12:54:57 GMT</lastBuildDate><atom:link href="https://foliumcv.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Arabic resumes with react-pdf: four shaping bugs, one font swap, and a PDF that ATS can read]]></title><description><![CDATA[What broke when I rendered Arabic, Urdu and other complex scripts, and how I measured the fixes]]></description><link>https://foliumcv.hashnode.dev/arabic-resumes-with-react-pdf-four-shaping-bugs-one-font-swap-and-a-pdf-that-ats-can-read</link><guid isPermaLink="true">https://foliumcv.hashnode.dev/arabic-resumes-with-react-pdf-four-shaping-bugs-one-font-swap-and-a-pdf-that-ats-can-read</guid><category><![CDATA[React]]></category><category><![CDATA[React]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[pdf]]></category><category><![CDATA[typography]]></category><dc:creator><![CDATA[Nahuel Giudizi]]></dc:creator><pubDate>Mon, 23 Nov 2026 07:09:53 GMT</pubDate><content:encoded><![CDATA[<p>I build <a href="https://foliumcv.com">Folium</a>, a free resume builder that works in 23 languages, including Arabic and Urdu written right to left. The live preview is drawn in the browser with <code>@react-pdf/renderer</code>. For Arabic, Urdu, Hindi, Bengali, Thai, Chinese and Japanese, the PDF you download is generated on the server by Chrome (Cloudflare Browser Rendering), because those scripts need a full shaping engine.</p>
<p>That split gave me two different classes of bugs. Here is what I found and how I checked each fix.</p>
<h2>Part 1: marks that fall off their letters (react-pdf, in the browser)</h2>
<p>Some fonts build a letter out of pieces. In Noto Naskh Arabic, <code>ف</code> is a body plus a dot, and the dot is a separate glyph with no character of its own. fontkit places that dot with an offset relative to the body. Thai vowels and tone marks and the signs in Hindi and Bengali work the same way.</p>
<p>In the browser preview, and in any PDF drawn on the client that contained such text (for example an English resume with an Arabic name), those marks came out wrong. I traced it to four separate problems in textkit and the renderer:</p>
<ol>
<li><strong>Slicing a run started at the wrong glyph.</strong> <code>glyphIndexAt</code> returns the <em>last</em> glyph of a letter that is built from pieces. When a line started with a letter that has dots, the slice began after its body, so <code>فاطمة</code> lost its first body and showed <code>اطمة</code> with a dot floating in front.</li>
<li><strong>Reversing a right-to-left run went glyph by glyph.</strong> Each dot ended up before its letter, while its offset had been computed for after. The fix reverses whole letters: a glyph without a character stays attached to the letter before it.</li>
<li><strong>The vertical offset of every glyph was overwritten.</strong> <code>resolveRunYOffset</code> set each glyph's <code>yOffset</code> to the superscript/subscript offset, which is almost always 0. Every mark lost its height. The fix adds to the glyph's own offset instead of replacing it.</li>
<li><strong>Offsets were drawn at the wrong scale.</strong> <code>renderGlyphs</code> scaled the advances to the text size but passed the x/y offsets through untouched, so they ended up divided by 1000 relative to the text. Each dot landed one letter width away (<code>تقني</code> rendered as <code>تمى</code>).</li>
</ol>
<p>All four are patched at install time by a script that replaces exact fragments of the library and fails loudly if a fragment is no longer there. I compared the result against Chrome (HarfBuzz) with the same font, and the glyph positions match.</p>
<h2>Part 2: a server PDF that looks right but reads wrong</h2>
<p>The server PDFs looked fine. The problem was invisible: applicant tracking systems read the text layer, not the picture, and for Arabic that layer was mostly broken.</p>
<p>I measured it with the sample resume in six templates, counting how many words come out intact when extracting text:</p>
<table>
<thead>
<tr>
<th>Font</th>
<th>Poppler (pdftotext)</th>
<th>pdf.js</th>
</tr>
</thead>
<tbody><tr>
<td>Noto Naskh Arabic</td>
<td>58%</td>
<td>2%</td>
</tr>
<tr>
<td>IBM Plex Sans Arabic</td>
<td>90.3%</td>
<td>67.9%</td>
</tr>
</tbody></table>
<p>Same pages, same templates, only the font changed. So Arabic moved to IBM Plex Sans Arabic, both in the preview and on the server. A few details mattered:</p>
<ul>
<li><strong>Kerning off on the server.</strong> With kerning enabled, pdftotext split <code>ر</code> + <code>ي</code> into two words in the bold weight. I disabled it only for the font stacks that start with Plex.</li>
<li><strong>A fallback only where Plex has gaps.</strong> Plex does not cover everything: Latin letters used in Turkish, Polish or Romanian names, the new Saudi riyal sign (U+20C1), some rare Arabic blocks. Naskh is added to the stack only when a resume actually contains one of those characters. The list of gaps is generated from the font files and a test checks it against them, so a font update cannot quietly break it.</li>
<li><strong>The license file travels with the font.</strong> Plex's <code>name</code> table does not include the license text, so the OFL file sits next to the TTFs.</li>
<li><strong>A fontkit cache bug.</strong> fontkit reused one shared object for glyph 0 (the "missing" glyph) and kept the characters of whoever asked first. Depending on the order, a missing <code>ş</code> could disappear or an invisible right-to-left mark could show up as a box. Each request now gets its own glyph 0.</li>
</ul>
<p>Urdu still uses Naskh: I have not measured it with Plex yet, and I don't want to change it without numbers.</p>
<h2>A lesson from Chinese and Japanese: test with the real renderer</h2>
<p>Earlier, a user reported missing text in a Chinese PDF opened on a phone. The <code>.otf</code> (CFF) fonts that the server's Chrome embedded were drawn fine by pdfium and pdf.js but not at all by MuPDF, which many Android viewers use. In Chinese, everything bold vanished; in Japanese, almost all the text did. My local Chrome produced a different kind of PDF with the same fonts, so it nearly sent me in the wrong direction. Converting to static TTF instances fixed it. Since then, every font for the server PDF is a static TTF, and I test with the actual Cloudflare renderer and open the result in MuPDF, pdfium and pdf.js.</p>
<h2>What is still not perfect</h2>
<ul>
<li>In the browser preview, the final period of a right-to-left line can show up at the start (a bidi issue in react-pdf).</li>
<li>Chrome's native PDF footer cannot use web fonts, so it falls back to a system font.</li>
</ul>
<p>If you generate PDFs in scripts other than Latin, my one piece of advice is to measure the text layer, not just look at the page. A PDF can look perfect and still be unreadable to the software that decides whether a human ever sees it.</p>
]]></content:encoded></item></channel></rss>