Skip to content

feat(doctor-report): draw Han characters in a Han font - #1670

Closed
Remedy233 wants to merge 1 commit into
MBombeck:release/v1.50.0from
Remedy233:feat/150-pdf-han-font
Closed

Remedy233 wants to merge 1 commit into
MBombeck:release/v1.50.0from
Remedy233:feat/150-pdf-han-font

Conversation

@Remedy233

Copy link
Copy Markdown

What this does

Embeds a Simplified Chinese font so the doctor-report PDF can draw Han
characters, and only when the report actually contains them.

Until now the PDF was drawn with the built-in Helvetica-family base fonts, which
carry no CJK glyphs: a report whose name or notes contained Chinese rendered as
blanks. Embedding a Han font unconditionally would add megabytes to every PDF,
including the ones that are pure ASCII, so the font is embedded only when the
document text contains a Han code point.

What is added

  • Two subset-free TTFs under public/fonts/: ReportSansSC-Regular.ttf and
    ReportSansSC-Bold.ttf (4.67 MB together), derived from Noto Sans SC.
  • The measurement shows the report needs 9,455 glyphs for GB2312 plus CJK
    punctuation, which is what these files carry.
  • The font is registered with jsPDF only when containsHan(text) is true; the
    Helvetica path is unchanged otherwise.

Evidence

Probed the built fonts with fontTools: 9,455 glyphs, covering 血压酮,
、。「」, %1, and — because a Chinese report still contains Latin and
Greek — ł, Ω, Ж, →, ².

A stub-jsPDF harness imported the real fonts.ts and asserted the embedding
decision: 23 assertions, 0 failures, including "ASCII report embeds no
font" and "one Han character embeds both weights when bold is used".

Checks

  • tsc --noEmit: clean
  • 23 harness assertions, 0 failures

Note on reproducibility

Rebuilding the TTF from the same Noto source is not byte-identical: only
head.modified differs, so I am not claiming a reproducible build here. The
committed bytes are the ones the harness measured.

Depends on

Nothing.

Chinese arrived with no glyphs: jsPDF has no per-glyph fallback, so every
character in a medication name, a note, a lab name, or the report's own
labels drew as a notdef box.

ReportSansSC-{Regular,Bold} is built the way the Korean pair is, from Noto
Sans plus Noto Sans SC: 2.3 MB a weight, the characters GB2312 defines plus
CJK punctuation, read only for a document that holds a Han character or is
drawn for zh-CN.

Two places where the change is not just a third file:

- the GB2312 set is read from the codec (lead 0xA1-0xF7, trail 0xA1-0xFE),
  not from a hand-copied table of 6,763 characters, which is a transcription
  that can be wrong in one row and silent about it;
- the emergency card kept its own copy of the Hangul regex, which is the
  drift the fold module warns about. Both callers now ask reportFontScript()
  for the script, and registration takes that instead of a boolean.

Han wins over Hangul when a document holds both: only one of the two files
can be registered, and Han is the one that would otherwise be boxes.
@Remedy233

Copy link
Copy Markdown
Author

Superseded by #1664. The maintainer added the Han font to the doctor report and the emergency card inside #1664, with a test that every report string of every language has a glyph. This PR carries the same two faces for one report path and no glyph coverage, so it would be a duplicate of work already in review. What survives from here is the observation that made the PR: a report with Chinese data drew boxes, and the fix belongs in the report renderer rather than in the locale. That is now true in #1664. Closing rather than rebasing: nothing in this branch is missing from #1664, and a second copy of a 4.7 MB font pair costs review attention without adding a caller.

@Remedy233 Remedy233 closed this Nov 28, 2026
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