Oregami
Repositories/oxedyne/daimond

oxedyne/daimond/dev/probe_typstwarn.mjs

2.4 KiB, 1 run

created by r2519314175:113, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1// probe_typstwarn.mjs — does a SUCCESSFUL compile carry warnings, and does an
2// unknown font family produce one?
3//
4// This decides how fonts are policed. A scanner over the source that guesses at
5// which families a document asks for will always be approximate; typst's own
6// "unknown font family" warning, if it reaches us, is authoritative and cannot
7// be fooled by a family named through a variable.
8import { open } from './harness.mjs';
9
10const s = await open({ name: 'typstwarnprobe' });
11const p = s.page;
12await p.waitForTimeout(1200);
13
14const out = await p.evaluate(async () => {
15 const VENDOR = new URL('/vendor/typst/', location.href);
16 const mod = await import(new URL('typst_ts_web_compiler.mjs', VENDOR).href);
17 await mod.default(new URL('typst_ts_web_compiler_bg.wasm', VENDOR));
18 const b = new mod.TypstCompilerBuilder();
19 b.set_dummy_access_model();
20 for (const n of ['LibertinusSerif-Regular.otf', 'LibertinusSerif-Bold.otf',
21 'LibertinusSerif-Italic.otf', 'LibertinusSerif-BoldItalic.otf', 'NewCMMath-Regular.otf']) {
22 const r = await fetch(new URL('fonts/' + n, VENDOR));
23 await b.add_raw_font(new Uint8Array(await r.arrayBuffer()));
24 }
25 const c = await b.build();
26 const shape = (r) => ({
27 keys: r && typeof r === 'object' && !(r instanceof Uint8Array) ? Object.keys(r) : String(typeof r),
28 diag: r && r.diagnostics ? JSON.stringify(r.diagnostics).slice(0, 700) : '(none)',
29 bytes: (r instanceof Uint8Array ? r : (r && (r.result || r.artifact)))?.length || 0,
30 });
31 const res = {};
32 c.reset_shadow();
33 // A family the compiler has never heard of, named directly.
34 c.add_source('/a.typ', '#set text(font: "Radley")\n= Hello\n\nBody text here.\n');
35 res.unknownDirect = shape(c.compile('/a.typ', undefined, 'pdf', 3));
36 // The same family reached through a variable, which no source scanner sees.
37 c.add_source('/b.typ', '#let f = "Radley"\n#set text(font: f)\n= Hello\n\nBody.\n');
38 res.unknownViaVar = shape(c.compile('/b.typ', undefined, 'pdf', 3));
39 // A clean document, for the control.
40 c.add_source('/c.typ', '= Hello\n\nBody.\n');
41 res.clean = shape(c.compile('/c.typ', undefined, 'pdf', 3));
42 // And a package import, which this build has no registry for.
43 c.add_source('/d.typ', '#import "@preview/cetz:0.3.4"\n= Hello\n');
44 res.packageImport = shape(c.compile('/d.typ', undefined, 'pdf', 3));
45 return res;
46});
47
48console.log(JSON.stringify(out, null, 2));
49await s.close();