Skip to content

Print emoji in PDF exports as pictures (DSK-247) - #636

Merged
QR-Madness merged 1 commit into
masterfrom
dsk-247-emoji-images
Dec 1, 2026
Merged

QR-Madness merged 1 commit into
masterfrom
dsk-247-emoji-images

Conversation

@QR-Madness

Copy link
Copy Markdown
Collaborator

What

The last part of DSK-247. CJK text has printed since #631; emoji were still left out, with a notice. jsPDF can't draw a character outside the BMP with any font, and most emoji live there. The founder chose pictures.

  • Each emoji is drawn as the browser draws it, in colour, one em square on the text's baseline. It isn't selectable or searchable; the guide says so.
  • Every emoji takes the same width, 1.2 em. So a layout wraps the same on every machine, whatever its emoji font: the export's, Paper Mode's, a test's.
    • Only drawing needs the pictures. The export makes them first, asynchronously, through OffscreenCanvas (src/utils/pdfExport/emoji.ts).
    • FallbackDoc then draws from the map, with one copy of each picture per file (alias).
  • Text that may hold emoji is split by grapheme cluster (Intl.Segmenter), so a family, a flag or a keycap stays one character, in layout and at line breaks. breakOversizedWord splits by cluster too. For other text, that's the same as before.
  • A symbol a font already has, such as ©, stays text. A cluster becomes a picture only when it's outside the BMP, asks for emoji presentation (U+FE0F), or has no font.
  • Where there's no canvas (tests, some workers), emoji keep their space and are reported, as before.

Verification

  • Tests:
    • emoji.test.ts (6): clusters, which clusters are pictures, gathering, no canvas;
    • fallbackDoc.test.ts, 5 new: pictures on the baseline with joiners kept whole; the fixed width; a missing picture keeps its space and is reported; © stays text; nothing drawn while measuring;
    • lineBreaks.test.ts: a family emoji is never split.
  • Mutations: 4 of 4 caught: no emoji as a picture, a 1 em advance, splitting by code point, pictures off the baseline.
  • Golden: all 30 golden exports are byte-identical to master, compared with PDF_DUMP_DIR.
  • In the browser (local dev server; the exporter called in the page, so nothing downloaded):
    • A paragraph with 😀 👨‍👩‍👧 🇨🇦 1️⃣ exports with nothing left out.
    • pdf.js reads the text as "Emoji test done", and the rendered page has all four pictures in their slots on the text line: 😀 and the flag in colour; the keycap grey, as this machine's emoji font draws it.
  • Suites: tsc is clean; the suite passes 5,629 tests in 518 files. The OSS leak grep is clean.

Closes the issue: CJK shipped in #631, and this adds emoji. Complex scripts (Arabic, Hebrew, Indic) are a follow-up in the backlog.

Assisted-by: Opus 5.5

jsPDF can't draw a character outside the BMP with any font, so emoji
were left out of PDFs, with a notice. The founder chose pictures: each
emoji is now drawn as the browser draws it, in colour, one em square on
the text's baseline. It isn't selectable or searchable.

- Every emoji takes the same width, 1.2 em, so a layout (the export's,
  Paper Mode's, a test's) wraps the same on every machine. Only drawing
  needs the pictures; the export makes them first, through
  OffscreenCanvas, and FallbackDoc draws from the map, one copy of each
  picture per file.
- Text that may hold emoji is split by grapheme cluster, so a family, a
  flag or a keycap stays one character, in layout and at line breaks.
- A symbol a font has, such as (c), stays text. Where there's no canvas
  (tests), emoji keep their space and are reported, as before.

Assisted-by: Opus 5.5
@QR-Madness
QR-Madness merged commit a2f9919 into master Dec 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant