A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!
TypeScript agent-skillsaidsh-pluginhacktoberfestjavascriptmcp-serverreactresume-builderself-hostedtypescript
fix(pdf): use correct font fallback for Unicode arrows (#3617)
Anirudh Sharma53fa9ba74364
diff --git a/packages/fonts/src/index.test.ts b/packages/fonts/src/index.test.tsindex eb3d38aa9..3b06e7b6f 100644--- a/packages/fonts/src/index.test.ts+++ b/packages/fonts/src/index.test.ts@@ -2,6 +2,12 @@ import { describe, expect, it } from "vitest";import { getFont, getPdfFallbackFontFamilies, resolveBoldFontWeight, resolveLegacyFontAlias } from "./index";describe("getPdfFallbackFontFamilies", () => {+ it("uses separate fonts for arrows and other text symbols", () => {+ expect(getPdfFallbackFontFamilies("Times-Roman", { scripts: ["arrows"] })).toEqual([+ "Noto Sans Symbols",+ "Noto Serif",+ ]);+ });it("orders the locale script first, then content scripts (mixed RTL + CJK resume)", () => {expect(getPdfFallbackFontFamilies("Helvetica", { locale: "ko-KR", scripts: ["arabic"] })).toEqual(["Noto Sans KR",diff --git a/packages/fonts/src/index.ts b/packages/fonts/src/index.tsindex 185b77f1e..92b104923 100644--- a/packages/fonts/src/index.ts+++ b/packages/fonts/src/index.ts@@ -85,6 +85,8 @@ const scriptFonts: Record<Script, { serif: string; sansSerif: string }> = {// Monochrome outlines (TrueType glyf, not CBDT bitmaps) so react-pdf can// embed them; the serif/sans distinction is meaningless for emoji (#3321).emoji: { serif: "Noto Emoji", sansSerif: "Noto Emoji" },+ // Basic arrows such as → live in Symbols, not Symbols 2 (#3608).+ arrows: { serif: "Noto Sans Symbols", sansSerif: "Noto Sans Symbols" },// Text symbols (★, ☆, ●, ■, ◆, ✦, ✓) that aren't emoji (#3581).symbols: { serif: "Noto Sans Symbols 2", sansSerif: "Noto Sans Symbols 2" },};diff --git a/packages/pdf/src/forme/arrows.integration.test.ts b/packages/pdf/src/forme/arrows.integration.test.tsnew file mode 100644index 000000000..2a5c604a0--- /dev/null+++ b/packages/pdf/src/forme/arrows.integration.test.ts@@ -0,0 +1,37 @@+import { expect, it } from "vitest";+import * as forme from "@formepdf/core";+import { getDocument, OPS } from "pdfjs-dist/legacy/build/pdf.mjs";+import { act } from "react";+import { defaultResumeData } from "@reactive-resume/schema/resume/default";+import { renderResume } from "./render";++it("preserves arrows with a standard PDF font", { timeout: 60_000 }, async () => {+ const data = structuredClone(defaultResumeData);+ data.picture.hidden = true;+ data.metadata.template = "onyx";+ data.metadata.typography.body.fontFamily = "Times-Roman";+ data.metadata.typography.heading.fontFamily = "Times-Roman";+ data.metadata.layout.pages = [{ fullWidth: true, main: ["summary"], sidebar: [] }];+ data.summary.hidden = false;+ data.summary.content = "<p>Hours → Minutes; <strong>Hours → Minutes</strong>; <em>Hours → Minutes</em></p>";++ const engine = { renderSerializedDocWithLayout: forme.renderSerializedDocWithLayout };+ const result = await act(() => renderResume(engine, { data }));+ const task = getDocument({ data: result.pdf });+ try {+ const page = await (await task.promise).getPage(1);+ const operators = await page.getOperatorList();+ const arrows = operators.fnArray.flatMap((operation, index) =>+ operation === OPS.showText+ ? operators.argsArray[index][0].filter((glyph: { unicode?: string }) => glyph?.unicode === "→")+ : [],+ );+ expect(arrows).toHaveLength(3);+ for (const arrow of arrows) {+ expect(arrow.isInFont).toBe(true);+ expect(arrow.width).toBeGreaterThan(0);+ }+ } finally {+ await task.destroy();+ }+});diff --git a/packages/pdf/src/hooks/use-register-fonts.test.ts b/packages/pdf/src/hooks/use-register-fonts.test.tsindex 3dc91044a..e0ae8c855 100644--- a/packages/pdf/src/hooks/use-register-fonts.test.ts+++ b/packages/pdf/src/hooks/use-register-fonts.test.ts@@ -102,7 +102,20 @@ describe("resolvePdfFonts", () => {expect(registered).not.toContainEqual(expect.objectContaining({ family: "Noto Serif SC" }));});- it("registers the Noto Sans Symbols 2 fallback for text symbols like arrows (#3608)", () => {+ it("registers the Noto Sans Symbols fallback for arrows without downloading Symbols 2", () => {+ const { registered, registerFonts } = withRegistry();+ const pdfTypography = registerFonts(typography, "en-US", false, new Set(["arrows"]));+ expect(pdfTypography.body.fontFamily).toEqual(["IBM Plex Serif", "Noto Sans Symbols", "Noto Serif"]);+ expect(registered).toContainEqual({+ family: "Noto Sans Symbols",+ weight: 400,+ italic: false,+ src: getWebFontSource("Noto Sans Symbols", "400", false),+ });+ expect(registered).not.toContainEqual(expect.objectContaining({ family: "Noto Sans Symbols 2" }));+ });++ it("registers the Noto Sans Symbols 2 fallback for text symbols like stars", () => {const symbolsSource = getWebFontSource("Noto Sans Symbols 2", "400", false);const { registered, registerFonts } = withRegistry();@@ -198,13 +211,18 @@ describe("resumeContentScripts", () => {expect(scripts.size).toBe(1);});- it("detects text-symbol arrows for the symbols fallback (#3608)", () => {- // U+2192 (→) lives in the Arrows block U+2190–U+21FF, which the symbols- // detector must include so Noto Sans Symbols 2 covers it.+ it("detects text-symbol arrows for the dedicated arrows fallback (#3608)", () => {+ // U+2192 (→) needs Noto Sans Symbols; Symbols 2 does not contain it.const scripts = resumeContentScripts(withSummary("Hours → Minutes"));- expect(scripts.has("symbols")).toBe(true);+ expect(scripts.has("arrows")).toBe(true);// The arrow is a text symbol, not emoji or any other script.expect(scripts.size).toBe(1);+ // U+21E6 (⇦) is outside Noto Sans Symbols, so it stays on Symbols 2.+ expect(resumeContentScripts(withSummary("⇦"))).toEqual(new Set(["symbols"]));+ });++ it("keeps pictographic arrows on the emoji fallback without extra text-symbol fonts", () => {+ expect(resumeContentScripts(withSummary("↔️ ↩️"))).toEqual(new Set(["emoji"]));});it("detects multiple scripts in mixed content", () => {diff --git a/packages/pdf/src/hooks/use-register-fonts.ts b/packages/pdf/src/hooks/use-register-fonts.tsindex dcc236f3b..f683b1c41 100644--- a/packages/pdf/src/hooks/use-register-fonts.ts+++ b/packages/pdf/src/hooks/use-register-fonts.ts@@ -166,11 +166,11 @@ const thaiRegex = /[-]/;// same reason: without it, keycap-only content falls back to a font without// the enclosure mark and renders garbled.const emojiRegex = /[\u{1F1E6}-\u{1F1FF}]|\u{20E3}|\p{Extended_Pictographic}/u;-// Arrows, Geometric Shapes, Miscellaneous Symbols, Dingbats and Miscellaneous-// Symbols and Arrows: text symbols like → (U+2192) and ★ (U+2605) that Latin-// fonts and Noto Emoji lack (#3581, #3608). Pictographs in these blocks-// (☀, ✔, ⭐) are emoji and already resolve to Noto Emoji.-const symbolsRegex = /(?!\p{Extended_Pictographic})[←-⇿■-➿⬀-⯿]/u;+// Basic arrows U+2190–U+2199 need Noto Sans Symbols; Symbols 2 has ★ but no → (#3608).+const arrowsRegex = /(?!\p{Extended_Pictographic})[←-↙]/u;+// The rest of the Arrows block, Geometric Shapes, Miscellaneous Symbols, Dingbats and Miscellaneous Symbols+// and Arrows need Symbols 2 (#3581). Pictographs (☀, ✔, ⭐) use Noto Emoji instead.+const symbolsRegex = /(?!\p{Extended_Pictographic})[↚-⇿■-➿⬀-⯿]/u;const scriptDetectors: { script: Script; regex: RegExp }[] = [{ script: "hangul", regex: hangulRegex },@@ -180,6 +180,7 @@ const scriptDetectors: { script: Script; regex: RegExp }[] = [{ script: "hebrew", regex: hebrewRegex },{ script: "thai", regex: thaiRegex },{ script: "emoji", regex: emojiRegex },+ { script: "arrows", regex: arrowsRegex },{ script: "symbols", regex: symbolsRegex },];diff --git a/packages/utils/src/locale.ts b/packages/utils/src/locale.tsindex cac9c314e..3f98d84c3 100644--- a/packages/utils/src/locale.ts+++ b/packages/utils/src/locale.ts@@ -108,6 +108,7 @@ export type Script =| "hebrew"| "thai"| "emoji"+ | "arrows"| "symbols";// The CJK subset of `Script`. CJK needs extra per-character line breaking that