Use true bold fonts for PDF rendering instead of stroke-based fake bold#335
Conversation
There was a problem hiding this comment.
Code Review
This pull request replaces the stroke-based faux bold rendering in PDF generation with real bold fonts (cjk-bold and sans-bold) to prevent character overlapping and spacing issues. The changes involve updating the font build script, loading the new bold font files, and registering them in the PDF renderer. The reviewer suggested optimizing the font loading process in scripts/pdf/main.ts by reading the files in parallel using Promise.all instead of sequentially.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const fontMono = ( | ||
| await readFile(path.join(ROOT, "assets/fonts/zigcourse-mono.ttf")) | ||
| ).toString("base64"); | ||
| const fontCjkBold = ( | ||
| await readFile(path.join(ROOT, "assets/fonts/zigcourse-cjk-bold.ttf")) | ||
| ).toString("base64"); | ||
| const fontSansBold = ( | ||
| await readFile(path.join(ROOT, "assets/fonts/zigcourse-sans-bold.ttf")) | ||
| ).toString("base64"); |
There was a problem hiding this comment.
These font files are read sequentially using await. Since they are independent I/O operations, we can load them in parallel using Promise.all to improve build performance.
const [fontMono, fontCjkBold, fontSansBold] = await Promise.all([
readFile(path.join(ROOT, "assets/fonts/zigcourse-mono.ttf")).then((b) => b.toString("base64")),
readFile(path.join(ROOT, "assets/fonts/zigcourse-cjk-bold.ttf")).then((b) => b.toString("base64")),
readFile(path.join(ROOT, "assets/fonts/zigcourse-sans-bold.ttf")).then((b) => b.toString("base64")),
]);采纳 PR #335 review 建议:5 份字体相互独立,用 Promise.all 并行读取, 并抽出 readFontB64 去掉 5 段重复的 readFile().toString() 样板。
|
是因为要产生 pdf 和 epub |
|
把图片嵌入 |
|
这里的 request 你可以不管,ai 自己发起的 |
用新的竖版书封面(course/.vitepress/epub/cover.png)替换旧的横版插画, 居中并限定宽度展示;简介补上英文副标题与 PDF/EPUB 离线版本说明。
采纳 PR #335 review 建议:5 份字体相互独立,用 Promise.all 并行读取, 并抽出 readFontB64 去掉 5 段重复的 readFile().toString() 样板。
Summary
Technical Details
Previously, bold text was rendered by applying
fillThenStrokerendering mode to normal-weight fonts, which expands the glyph outline. This causes problems in CJK text where the expanded strokes eat into inter-character spacing, leading to overlapping or squeezed characters.This change uses actual bold font files (wght:700) for CJK and Sans fonts:
zigcourse-cjk-bold.ttf: Noto Serif SC at weight 700zigcourse-sans-bold.ttf: Inter at weight 700By using true bold glyphs:
getTextWidth()returns the correct advance width for bold fontsFont subsetting reuses the same variable font sources; the fetch cache prevents re-downloading when pinning different weight axes.