@devries-cameron20 / t3code-1 / commits / 6464729c56
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): improve PowerPoint slide font rendering (#34453)

Co-authored-by: Cursor <cursoragent@cursor.com>

Yash Singh committed Nov 11, 2026 at 16:12 UTC 6464729c564337aca536e2957c8df0ce3a0a275b
6 files changed +99 -11
apps/web/package.json
+1 -1
@@ -16,7 +16,7 @@
16 "@betteroffice/docx": "0.4.3",
17 "@betteroffice/fonts": "0.4.0",
18 "@betteroffice/fonts-cjk": "0.4.0",
19 - "@betteroffice/pptx": "0.2.0",
19 + "@betteroffice/pptx": "0.5.1",
20 "@betteroffice/xlsx": "0.5.1",
21 "@clerk/clerk-js": "catalog:",
22 "@clerk/electron": "catalog:",
apps/web/src/components/files/office/slide-fonts.browser.test.ts new
+67
@@ -0,0 +1,67 @@
1 +import JSZip from "jszip";
2 +import { initWasm, openPresentation } from "@betteroffice/pptx";
3 +import { expect, it } from "vite-plus/test";
4 +import { slideFonts } from "./slide-fonts";
5 +import { deckText } from "./slide-text";
6 +
7 +const namespaces =
8 + 'xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"';
9 +
10 +function relationships(type: string, target: string) {
11 + return `<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/${type}" Target="${target}"/></Relationships>`;
12 +}
13 +
14 +/** A one-slide deck whose text box has one paragraph per run, each in its own family. */
15 +async function deck(runs: readonly { text: string; family: string }[]) {
16 + const paragraphs = runs
17 + .map(
18 + (run) =>
19 + `<a:p><a:r><a:rPr lang="en-US" sz="2400"><a:latin typeface="${run.family}"/></a:rPr><a:t>${run.text}</a:t></a:r></a:p>`,
20 + )
21 + .join("");
22 +
23 + return new JSZip()
24 + .file(
25 + "[Content_Types].xml",
26 + '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/><Override PartName="/ppt/slides/slide1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/></Types>',
27 + )
28 + .file("_rels/.rels", relationships("officeDocument", "ppt/presentation.xml"))
29 + .file(
30 + "ppt/presentation.xml",
31 + `<p:presentation ${namespaces}><p:sldIdLst><p:sldId id="256" r:id="rId1"/></p:sldIdLst><p:sldSz cx="9144000" cy="5143500"/></p:presentation>`,
32 + )
33 + .file("ppt/_rels/presentation.xml.rels", relationships("slide", "slides/slide1.xml"))
34 + .file(
35 + "ppt/slides/slide1.xml",
36 + `<p:sld ${namespaces}><p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr/><p:sp><p:nvSpPr><p:cNvPr id="2" name="Text"/><p:cNvSpPr txBox="1"/><p:nvPr/></p:nvSpPr><p:spPr><a:xfrm><a:off x="457200" y="457200"/><a:ext cx="8229600" cy="2000000"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></p:spPr><p:txBody><a:bodyPr/>${paragraphs}</p:txBody></p:sp></p:spTree></p:cSld></p:sld>`,
37 + )
38 + .generateAsync({ type: "uint8array" });
39 +}
40 +
41 +it("lays slide text out with heavy stand-ins and script fallbacks, and draws text no bundled face covers whole", async () => {
42 + await initWasm();
43 + const bytes = await deck([
44 + { text: "Plain", family: "Arial" },
45 + { text: "Heavy", family: "Arial Black" },
46 + { text: "日本語のテキスト", family: "Times New Roman" },
47 + { text: "ภาษาไทย", family: "Arial" },
48 + ]);
49 + const handle = openPresentation(bytes);
50 + const fonts = slideFonts(handle, document.fonts);
51 +
52 + await fonts.load(deckText(bytes, handle.snapshot()));
53 +
54 + const frame = await fonts.layout(0);
55 + const [plain, heavy, japanese, thai] = frame.primitives.flatMap((primitive) =>
56 + primitive.kind === "textBox" ? primitive.lines.flatMap((line) => line.runs) : [],
57 + );
58 +
59 + // Arial Black's only stand-in is a bold face, which its regular text draws with rather than Arial's.
60 + expect(heavy?.fontFamily).not.toBe(plain?.fontFamily);
61 + expect(plain?.glyphs).toHaveLength(5);
62 + expect(japanese?.fontFamily).not.toBe(plain?.fontFamily);
63 + expect(japanese?.glyphs.length).toBeGreaterThan(0);
64 + expect(japanese?.glyphs.some((glyph) => glyph.glyphId === 0)).toBe(false);
65 + expect(thai?.text).toBe("ภาษาไทย");
66 + expect(thai?.glyphs).toEqual([]);
67 +});
apps/web/src/components/files/office/slide-fonts.ts
+10 -2
@@ -38,8 +38,13 @@ export function slideFonts(deck: PresentationHandle, fonts: FontFaceSet) {
38
39 if (!source) return;
40
41 - // A family without the requested style gets the face it has, which the browser then slants or emboldens.
42 - const style = { bold: source.weight === 700, italic: source.style === "italic" };
41 + // A family without the requested style gets the face it has, which the browser then slants or emboldens. The engine
42 + // draws a bold run with a family's regular face but never the reverse, so a heavier stand-in, such as Arial Black's
43 + // bold one, registers at the requested style.
44 + const style = {
45 + bold: requested.bold && source.weight === 700,
46 + italic: requested.italic && source.style === "italic",
47 + };
48 // The worker holds this deck's faces alone, so the names only need to differ from each other.
49 const css = names.get(wantKey(want)) ?? `slide-${names.size}`;
50 const key = faceKey(want, style);
@@ -119,6 +124,9 @@ export function slideFonts(deck: PresentationHandle, fonts: FontFaceSet) {
124 runs: line.runs.map((run) => ({
125 ...run,
126 fontFamily: faces.get(run.fontId)?.css ?? run.fontFamily,
127 + // The engine places glyphs no bundled face has, such as Thai ones or emoji, a missing glyph's width apart,
128 + // but the browser draws them from its own fonts. Without positions a run is drawn whole.
129 + glyphs: run.glyphs.some((glyph) => glyph.glyphId === 0) ? [] : run.glyphs,
130 })),
131 })),
132 };
apps/web/src/components/files/office/slide-text.ts
+15 -2
@@ -11,7 +11,7 @@ export type FontStyle = { readonly bold: boolean; readonly italic: boolean };
11 export type DeckFamily = { readonly name: string; readonly styles: readonly FontStyle[] };
12
13 /** The scripts the bundled Latin faces may lack, which have a bundled fallback face. */
14 -export type FallbackScript = "hebrew" | "arabic";
14 +export type FallbackScript = "hebrew" | "arabic" | "cjk-jp" | "cjk-kr" | "cjk-sc";
15
16 /** What a deck's text needs from the fonts, and which slides it hides. */
17 export type DeckText = {
@@ -125,8 +125,21 @@ const decodeInspected = Schema.decodeUnknownOption(Inspected);
125 const scriptRanges: readonly (readonly [FallbackScript, RegExp])[] = [
126 ["hebrew", /[\u0590-\u05FF\uFB1D-\uFB4F]/u],
127 ["arabic", /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/u],
128 + ["cjk-jp", /[\u3040-\u30FF\u31F0-\u31FF\uFF66-\uFF9F]/u],
129 + ["cjk-kr", /[\u1100-\u11FF\u3130-\u318F\uAC00-\uD7AF]/u],
130 ];
131
132 +const hanRange = /[\u3000-\u303F\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF\uFF00-\uFFEF]/u;
133 +
134 +function scripts(text: string): FallbackScript[] {
135 + const found = scriptRanges.flatMap((entry) => (entry[1].test(text) ? [entry[0]] : []));
136 +
137 + // The Japanese and Korean faces also draw the Chinese characters their text mixes in.
138 + return hanRange.test(text) && !found.some((script) => script.startsWith("cjk-"))
139 + ? [...found, "cjk-sc"]
140 + : found;
141 +}
142 +
143 /**
144 * Reads the families, styles and scripts a deck's text uses, from its slides, layouts, masters and theme. When the
145 * engine's inspection does not decode, the slides' own runs stand in, without theme fonts or hidden flags.
@@ -396,7 +409,7 @@ function summarize(
409 (left, right) => styleRank(left) - styleRank(right),
410 ),
411 })),
399 - scripts: scriptRanges.flatMap((entry) => (entry[1].test(text) ? [entry[0]] : [])),
412 + scripts: scripts(text),
413 hidden,
414 };
415 }
pnpm-lock.yaml
+5 -5
@@ -1026,8 +1026,8 @@ importers:
1026 specifier: 0.4.0
1027 version: 0.4.0
1028 '@betteroffice/pptx':
1029 - specifier: 0.2.0
1030 - version: 0.2.0
1029 + specifier: 0.5.1
1030 + version: 0.5.1
1031 '@betteroffice/xlsx':
1032 specifier: 0.5.1
1033 version: 0.5.1
@@ -3271,8 +3271,8 @@ packages:
3271 '@betteroffice/fonts-cjk':
3272 optional: true
3273
3274 - '@betteroffice/pptx@0.2.0':
3275 - resolution: {integrity: sha512-pNPQ58tlA+pVibERbLdQNskvP7a0GIMf4jhkCU/gPp8043Ichf6gB3PSb4ra9sfqoIaWqOaZKCWyptovA2+Q0A==}
3274 + '@betteroffice/pptx@0.5.1':
3275 + resolution: {integrity: sha512-2Rn51fx1GCDfcus1Ly2giDk7CnhLmWjJFPq3QL2DiBAF2BF+A5R9PdRDHYX5gQm0sfWK97C2osTmR3/klJKF2Q==}
3276
3277 '@betteroffice/xlsx@0.5.1':
3278 resolution: {integrity: sha512-UHOnzcMML6Ud9D1M4d8FZKmw3AAg2/DttE/sVxM858SgiIpOtzGOqlh62RM9/8y/JW8bR8t+wN69EX8UJvR8EQ==}
@@ -13477,7 +13477,7 @@ snapshots:
13477 optionalDependencies:
13478 '@betteroffice/fonts-cjk': 0.4.0
13479
13480 - '@betteroffice/pptx@0.2.0': {}
13480 + '@betteroffice/pptx@0.5.1': {}
13481
13482 '@betteroffice/xlsx@0.5.1': {}
13483
third-party-licenses.config.json
+1 -1
@@ -270,7 +270,7 @@
270 },
271 {
272 "name": "@betteroffice/pptx",
273 - "version": "0.2.0",
273 + "version": "0.5.1",
274 "license": "Apache-2.0",
275 "sourceUrl": "https://github.com/openooxml/betteroffice",
276 "generatedNotice": {