Repository navigation
Print Chinese, Japanese and Korean text in PDF exports - #631
Merged
Merged
Conversation
PDF exports embedded only the document's font, so Chinese, Japanese and Korean text came out blank, silently. Text the current face lacks now falls back to Noto Sans SC (Han and kana) or Noto Sans KR (Hangul). - FallbackDoc stands in front of the document the layout draws on and splits each string into runs by font. Text the face covers goes straight through, so Latin documents export byte for byte as before. - The layout measures the fallback fonts from fallbackMetrics.json, generated from the fonts with jsPDF's own parser. Paper Mode never downloads them, and an export fetches one only when its text needs it. The fonts are hashed assets, never precached, and kept by the service worker after their first fetch. - CJK text breaks between characters, with basic kinsoku rules. A space that doesn't fit ends a line instead of opening the next one, which also fixes Latin lines that began with a space. - jsPDF can't draw characters outside the BMP (most emoji), and scripts that need shaping (Arabic, Hebrew, Indic) aren't covered. The export now says what it left out instead of dropping it silently. Assisted-by: Opus 5.5
From the review: wrapTokens dropped the spaces a paragraph opens with, so a wrapped code line with CJK in it lost its indentation. MeasureDoc now carries the fallbackFonts flag of what it measures with, so a heading's look-ahead never shares width-cache entries with a plain document. Contents labels shorten by characters, never inside a UTF-16 pair, and the two base64 helpers are one. Assisted-by: Opus 5.5
This was referenced Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
PDF exports embedded only the document's font, so Chinese, Japanese and Korean text came out blank, with no warning. Now any text the current face lacks falls back:
Noto Sans SC Regular (Han and kana) covers Chinese and Japanese.
Noto Sans KR Regular covers Hangul, which SC doesn't have.
FallbackDoc(src/utils/pdfExport/fallbackDoc.ts) stands in front of the document the layout draws on. It splits each string into runs by font, then measures and draws each run in its font.PDF_DUMP_DIRbefore and after.Measuring never needs the font files.
fallbackMetrics.json(6.6 KB) holds each character's width as jsPDF measures it.scripts/gen-pdf-fallback-metrics.tsgenerates it from the fonts with jsPDF's own parser, and a drift test fails until it's regenerated.Fonts are hashed assets (
src/assets/fonts/noto-sans-{sc,kr}/, OFL, licence beside each).Line breaking (
lineBreaks.ts):The export says what it left out. jsPDF can't draw characters outside the BMP whatever the font, because it reads only BMP cmaps and encodes text in 16-bit units, and most emoji are out there. Scripts that need shaping (Arabic, Hebrew, the Indic scripts) aren't covered either.
Known limits (in the guide)
Size
dist: +16.7 MB for the two fonts (10.5 and 6.2 MB). The PWA never precaches them; the desktop installer carries them.Verification
FallbackDoc(11), including table widths equal to jsPDF's with the fonts loaded, to nine places;scripts/cjkdocument: 5 pages, with contents, outline, a mixed-script line, a list, a table and code.paginate()matches the export.noteMissing's early return while measuring only saves a scan, becausecount()guards too.tscclean; the suite passes 5,547 tests in 516 files;bun run buildpasses. The OSS leak grep is clean.Assisted-by: Opus 5.5