forked from 1b-agent/opencadstudio-upstream
feat(web): lazy per-script font loading for international CAD text
The web build has no system-font access, so CAD text in non-Latin scripts (Cyrillic, Greek, CJK, …) rendered as nothing — build_fallback was a hard None on wasm (#141). Instead, ship per-script Noto subsets under web/fonts (one alphabet per file, SIL OFL 1.1) and fetch them lazily over HTTP the first time a drawing uses that script, then outline glyphs with ttf-parser. - web_font: Script enum + script_of (char → script font), a per-script store with lazy fetch, and a pending queue drained by the app loop. - CJK is split by language (chinese/japanese/korean). Han ideographs share code points but differ by language, so the shared block is routed by the document's $DWGCODEPAGE (932→JP, 949→KR, GB/936→CN); kana is always Japanese, Hangul always Korean. Re-tessellates when the language changes. - build_fallback (wasm) outlines from the fetched subset; clear_fallback_cache lets glyphs that missed while a font was in flight reappear on load. - PollWebFonts subscription (web only) + WebFontLoaded message drive fetches. - Trunk copy-dir serves web/fonts; nothing is bundled into the native binary (desktop keeps using system fonts). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
d36cc9786f
commit
54106ca9b0
21 files changed
+453
-5
No files matched your search
+6
-1
@@ -91,8 +91,12 @@ serde_json = "1"
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
console_error_panic_hook = "0.1"
|
||||
wasm-bindgen = "0.2"
|
||||
# fetch() returns a JS Promise; bridge it to a Rust future for the per-script
|
||||
# web font loader (#141).
|
||||
wasm-bindgen-futures = "0.4"
|
||||
js-sys = "0.3"
|
||||
# window.open (external URLs) + Blob/anchor file downloads (Save).
|
||||
# window.open (external URLs) + Blob/anchor file downloads (Save) + fetch()
|
||||
# (Response) for the lazy per-script web font loader (#141).
|
||||
web-sys = { version = "0.3", features = [
|
||||
"Window",
|
||||
"Navigator",
|
||||
@@ -101,6 +105,7 @@ web-sys = { version = "0.3", features = [
|
||||
"HtmlAnchorElement",
|
||||
"Blob",
|
||||
"Url",
|
||||
"Response",
|
||||
] }
|
||||
# Browsers without WebGPU (e.g. Firefox by default) need wgpu's WebGL2 backend;
|
||||
# `webgl` enables it. `fira-sans` embeds the default UI font — the web has no
|
||||
|
||||
Reference in new issue
Block a user