mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-06-22 04:11:55 +10:00
fix: add special hyphenation callback for Chinese script in PDF font registration
This commit is contained in:
@@ -58,6 +58,7 @@ export default defineConfig({
|
||||
|
||||
server: {
|
||||
host: true,
|
||||
strictPort: true,
|
||||
port: Number.parseInt(process.env.PORT ?? "3000", 10),
|
||||
},
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ describe("registerFonts", () => {
|
||||
|
||||
it("registers CJK PDF fallbacks for normal and italic text styles", async () => {
|
||||
const registerSpy = vi.spyOn(Font, "register").mockImplementation(() => {});
|
||||
vi.spyOn(Font, "registerHyphenationCallback").mockImplementation(() => {});
|
||||
const cjkFallbackSource = getWebFontSource("Noto Serif SC", "400", false);
|
||||
const { registerFonts } = await import("./use-register-fonts");
|
||||
|
||||
@@ -71,6 +72,7 @@ describe("registerFonts", () => {
|
||||
|
||||
it("uses the full CJK font source for synthetic italic variants when the CJK font is primary", async () => {
|
||||
const registerSpy = vi.spyOn(Font, "register").mockImplementation(() => {});
|
||||
vi.spyOn(Font, "registerHyphenationCallback").mockImplementation(() => {});
|
||||
const cjkFallbackSource = getWebFontSource("Noto Serif SC", "400", false);
|
||||
const { registerFonts } = await import("./use-register-fonts");
|
||||
|
||||
|
||||
@@ -65,6 +65,11 @@ const resolvePdfTypography = (typography: Typography): Typography => {
|
||||
};
|
||||
|
||||
export const registerFonts = (typography: Typography): PdfTypography => {
|
||||
Font.registerHyphenationCallback((word) => {
|
||||
if (word.match(/\p{Script=Han}/u)) return word.split("").flatMap((l) => [l, ""]);
|
||||
return [word];
|
||||
});
|
||||
|
||||
const pdfTypography = resolvePdfTypography(typography);
|
||||
const bodyFontFamily = pdfTypography.body.fontFamily;
|
||||
const headingFontFamily = pdfTypography.heading.fontFamily;
|
||||
|
||||
Reference in New Issue
Block a user