feat(web): self-host Japanese font and load on-demand without external CDN

- Bundle BIZ UDPGothic Regular (SIL OFL 1.1) exclusively in solvecraft-web dist

- Remove external jsDelivr CDN fallback; fetch font solely from same-origin ./fonts/

- Fetch Japanese font on-demand only when UI language is set to Japanese

- Gracefully fall back to English UI on fetch failure to prevent tofu glyphs

- Update ATTRIBUTION.md, NOTICE, and THIRD-PARTY-LICENSES.txt
This commit is contained in:
Phaiz Mithriln authored and bherbruck committed 2026-10-12 10:06:50 -04:00
1 parent 1fee62dd54
commit 4fbf19f2f9
9 files changed
+306 -37

No files matched your search

+1
View File
@@ -26,6 +26,7 @@ Generated-in-code assets are original and have no file to list:
| docs/book/src/generated/revolve.png | SolveCraft contributors | rendered by `cargo xtask book` (`solvecraft-cli snapshot docs/book/scripts/revolve.json`; gitignored) | MIT OR Apache-2.0 | | docs/book/src/generated/revolve.png | SolveCraft contributors | rendered by `cargo xtask book` (`solvecraft-cli snapshot docs/book/scripts/revolve.json`; gitignored) | MIT OR Apache-2.0 |
| docs/book/src/generated/sheet-metal.png | SolveCraft contributors | rendered by `cargo xtask book` (`solvecraft-cli snapshot docs/book/scripts/sheet-metal.json`; gitignored) | MIT OR Apache-2.0 | | docs/book/src/generated/sheet-metal.png | SolveCraft contributors | rendered by `cargo xtask book` (`solvecraft-cli snapshot docs/book/scripts/sheet-metal.json`; gitignored) | MIT OR Apache-2.0 |
| crates/sketch/fonts/LiberationSans-Regular.ttf | Red Hat, Inc. (Liberation Fonts 2.x; digitized data Google) | https://github.com/liberationfonts (Debian fonts-liberation), unmodified; licence text in crates/sketch/fonts/OFL.txt; used for sketch Text outlines | SIL OFL 1.1 | | crates/sketch/fonts/LiberationSans-Regular.ttf | Red Hat, Inc. (Liberation Fonts 2.x; digitized data Google) | https://github.com/liberationfonts (Debian fonts-liberation), unmodified; licence text in crates/sketch/fonts/OFL.txt; used for sketch Text outlines | SIL OFL 1.1 |
| apps/solvecraft-web/fonts/BIZUDPGothic-Regular.ttf | The BIZ UDGothic Project Authors | https://github.com/googlefonts/morisawa-biz-ud-gothic (Google Fonts), unmodified; licence text in apps/solvecraft-web/fonts/OFL.txt; used for web UI Japanese font | SIL OFL 1.1 |
## Code adapted from sibling projects ## Code adapted from sibling projects
+3 -2
View File
@@ -19,8 +19,9 @@ licensed MIT OR Apache-2.0; ATTRIBUTION.md lists the files.
The release packaging (.github/workflows/release.yml, packaging/) is adapted from PhotoCraft The release packaging (.github/workflows/release.yml, packaging/) is adapted from PhotoCraft
(https://github.com/storytold/photocraft), licensed under the Apache License 2.0. (https://github.com/storytold/photocraft), licensed under the Apache License 2.0.
None of the bundled assets come from third parties: every icon is drawn in code. The per-file Most bundled assets are drawn in code or contributed originally; third-party fonts (Liberation Sans
list is in ATTRIBUTION.md. for sketch text, BIZ UDPGothic for web Japanese display) are licensed under SIL OFL 1.1. The
per-file list is in ATTRIBUTION.md.
SolveCraft is an independent project and is not affiliated with, sponsored by or endorsed by SolveCraft is an independent project and is not affiliated with, sponsored by or endorsed by
Autodesk, Inc. Autodesk and Fusion are trademarks of Autodesk, Inc.; they are used here only to Autodesk, Inc. Autodesk and Fusion are trademarks of Autodesk, Inc.; they are used here only to
+110
View File
@@ -13345,3 +13345,113 @@ truck-geotrait 0.4.0: Apache-2.0 (https://github.com/ricosjp/truck)
truck-modeling 0.6.0: Apache-2.0 (https://github.com/ricosjp/truck) truck-modeling 0.6.0: Apache-2.0 (https://github.com/ricosjp/truck)
truck-polymesh 0.6.0: Apache-2.0 (https://github.com/ricosjp/truck) truck-polymesh 0.6.0: Apache-2.0 (https://github.com/ricosjp/truck)
truck-topology 0.6.0: Apache-2.0 (https://github.com/ricosjp/truck) truck-topology 0.6.0: Apache-2.0 (https://github.com/ricosjp/truck)
================================================================================
Bundled fonts (SIL Open Font License, Version 1.1)
================================================================================
- LiberationSans-Regular.ttf (crates/sketch/fonts/LiberationSans-Regular.ttf)
Copyright 2012 Red Hat, Inc. (Liberation Fonts 2.x; digitized data Google)
Source: https://github.com/liberationfonts
- BIZUDPGothic-Regular.ttf (apps/solvecraft-web/fonts/BIZUDPGothic-Regular.ttf)
Copyright 2022 The BIZ UDGothic Project Authors (https://github.com/googlefonts/morisawa-biz-ud-mincho)
Source: https://github.com/googlefonts/morisawa-biz-ud-gothic
================================================================================
SIL OPEN FONT LICENSE Version 1.1
================================================================================
Copyright 2022 The BIZ UDGothic Project Authors (https://github.com/googlefonts/morisawa-biz-ud-mincho)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file not shown.
+93
View File
@@ -0,0 +1,93 @@
Copyright 2022 The BIZ UDGothic Project Authors (https://github.com/googlefonts/morisawa-biz-ud-mincho)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
+2
View File
@@ -5,6 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>SolidCraft</title> <title>SolidCraft</title>
<link data-trunk rel="rust" data-bin="solvecraft-web" data-wasm-opt="z" data-weak-refs /> <link data-trunk rel="rust" data-bin="solvecraft-web" data-wasm-opt="z" data-weak-refs />
<link data-trunk rel="copy-file" href="fonts/BIZUDPGothic-Regular.ttf" data-target-path="fonts" />
<link data-trunk rel="copy-file" href="fonts/OFL.txt" data-target-path="fonts" />
<style> <style>
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #e8ebf0; } html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #e8ebf0; }
#solvecraft_canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; } #solvecraft_canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
+65 -27
View File
@@ -46,6 +46,18 @@ mod web {
on_unload.forget(); on_unload.forget();
} }
const JAPANESE_FONT_PATH: &str = "./fonts/BIZUDPGothic-Regular.ttf";
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum FontStatus {
Unloaded,
Loading,
Installed,
Failed,
}
type FontLoadResult = Rc<std::cell::RefCell<Option<Result<Vec<u8>, String>>>>;
struct Shell { struct Shell {
app: SolveApp, app: SolveApp,
files: Rc<Files>, files: Rc<Files>,
@@ -58,6 +70,8 @@ mod web {
rename_focus: bool, rename_focus: bool,
/// The start page's recent designs were filled from the stored ones. /// The start page's recent designs were filled from the stored ones.
recents_synced: bool, recents_synced: bool,
font_status: FontStatus,
font_result: FontLoadResult,
} }
impl Shell { impl Shell {
@@ -304,10 +318,59 @@ mod web {
} }
files::autosave(&self.files, None); files::autosave(&self.files, None);
} }
/// Check language preference and manage on-demand Japanese font loading.
fn tick_font(&mut self, ctx: &egui::Context) {
if self.font_status == FontStatus::Loading {
if let Some(res) = self.font_result.borrow_mut().take() {
match res {
Ok(bytes) => {
if solvecraft_ui_egui::fonts::install_cjk_font(ctx, bytes) {
log::info!("loaded web Japanese font from {JAPANESE_FONT_PATH}");
self.font_status = FontStatus::Installed;
ctx.request_repaint();
} else {
log::warn!("failed to install Japanese font: invalid font data; falling back to English");
self.font_status = FontStatus::Failed;
self.app.preferences.language = "en".to_string();
ctx.request_repaint();
}
}
Err(err) => {
log::warn!("failed to fetch Japanese font from {JAPANESE_FONT_PATH}: {err}; falling back to English");
self.font_status = FontStatus::Failed;
self.app.preferences.language = "en".to_string();
ctx.request_repaint();
}
}
}
}
if self.app.preferences.language == "ja" {
match self.font_status {
FontStatus::Unloaded => {
self.font_status = FontStatus::Loading;
let slot = self.font_result.clone();
let ctx_clone = ctx.clone();
wasm_bindgen_futures::spawn_local(async move {
let res = fetch_font_bytes(JAPANESE_FONT_PATH).await;
*slot.borrow_mut() = Some(res);
ctx_clone.request_repaint();
});
}
FontStatus::Failed => {
// Prevent tofu glyphs if font loading failed
self.app.preferences.language = "en".to_string();
}
FontStatus::Loading | FontStatus::Installed => {}
}
}
}
} }
impl eframe::App for Shell { impl eframe::App for Shell {
fn logic(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn logic(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
self.tick_font(ctx);
self.app.logic(ctx); self.app.logic(ctx);
self.files_tick(ctx); self.files_tick(ctx);
UNSAVED.with(|u| u.set(solvecraft_ui_egui::documents::any_dirty(&self.app))); UNSAVED.with(|u| u.set(solvecraft_ui_egui::documents::any_dirty(&self.app)));
@@ -347,32 +410,6 @@ mod web {
Ok(uint8_arr.to_vec()) Ok(uint8_arr.to_vec())
} }
/// Load Japanese/CJK fallback font in the browser.
fn load_web_fonts(ctx: egui::Context) {
wasm_bindgen_futures::spawn_local(async move {
let urls = [
"./fonts/BIZUDPGothic-Regular.ttf",
"./fonts/NotoSansCJKjp-Regular.otf",
"https://cdn.jsdelivr.net/gh/googlefonts/morisawa-biz-ud-gothic@main/fonts/ttf/BIZUDPGothic-Regular.ttf",
];
for url in urls {
match fetch_font_bytes(url).await {
Ok(bytes) => {
if solvecraft_ui_egui::fonts::install_cjk_font(&ctx, bytes) {
log::info!("loaded web CJK font from {url}");
ctx.request_repaint();
break;
}
}
Err(err) => {
log::debug!("fetching font from {url} failed: {err}");
}
}
}
});
}
pub fn start() { pub fn start() {
eframe::WebLogger::init(log::LevelFilter::Info).ok(); eframe::WebLogger::init(log::LevelFilter::Info).ok();
wasm_bindgen_futures::spawn_local(async { wasm_bindgen_futures::spawn_local(async {
@@ -395,7 +432,6 @@ mod web {
options, options,
Box::new(move |cc| { Box::new(move |cc| {
solvecraft_ui_egui::fonts::setup_fonts(&cc.egui_ctx); solvecraft_ui_egui::fonts::setup_fonts(&cc.egui_ctx);
load_web_fonts(cc.egui_ctx.clone());
let files = Rc::new(Files::default()); let files = Rc::new(Files::default());
files::start(&files); files::start(&files);
let panel = files.clone(); let panel = files.clone();
@@ -439,6 +475,8 @@ mod web {
renaming: None, renaming: None,
rename_focus: false, rename_focus: false,
recents_synced: false, recents_synced: false,
font_status: FontStatus::Unloaded,
font_result: Rc::new(std::cell::RefCell::new(None)),
})) }))
}), }),
) )
+10 -5
View File
@@ -31,11 +31,16 @@ Standalone translated panels enter the same scope. Measure rendered text to size
widgets; UTF-8 byte lengths do not describe their displayed width. widgets; UTF-8 byte lengths do not describe their displayed width.
The desktop host tries system CJK fonts across Windows, macOS and Linux, as well as an optional The desktop host tries system CJK fonts across Windows, macOS and Linux, as well as an optional
`CRAFT_FONTS_DIR` font pack, and skips files that cannot be parsed. No system fonts are redistributed. `CRAFT_FONTS_DIR` font pack, and skips files that cannot be parsed. No fonts are redistributed
Japanese glyph coverage on desktop depends on installed system fonts or craft-fonts. In the browser, in native desktop distribution packages; native builds rely entirely on existing operating system fonts
`solvecraft-web` asynchronously loads a licensed CJK font (trying self-hosted `./fonts/` first, then or craft-fonts.
falling back to a public CDN) and installs it into egui once fetched so that localized text renders
seamlessly without requiring local system font access. In the browser, `solvecraft-web` bundles a self-hosted Japanese font (`BIZUDPGothic-Regular.ttf`, licensed
under SIL OFL 1.1) within the web distribution artifacts only. The font is loaded asynchronously from the same
origin (`./fonts/BIZUDPGothic-Regular.ttf`) on-demand when the interface language is set to Japanese, without
contacting any external CDNs or third-party servers. For users with an English interface, no font download
occurs. If font loading fails, the web interface gracefully falls back to English to prevent missing glyphs
(tofu). This bundled font specifically targets Japanese; Korean (Hangul) and Chinese scripts are not covered.
The current messages support named substitution, not locale-specific plural selection, The current messages support named substitution, not locale-specific plural selection,
number/date formatting, or right-to-left layout and shaping. Add those capabilities when number/date formatting, or right-to-left layout and shaping. Add those capabilities when
+22 -3
View File
@@ -88,8 +88,7 @@ fn generate(root: &Path) -> Result<String, String> {
}); });
} }
crates.sort_by(|a, b| (&a.name, &a.version).cmp(&(&b.name, &b.version))); crates.sort_by(|a, b| (&a.name, &a.version).cmp(&(&b.name, &b.version)));
let _ = root; Ok(render(root, &crates))
Ok(render(&crates))
} }
/// The licence and notice files at the top of a crate's package (and its `license-file`). /// The licence and notice files at the top of a crate's package (and its `license-file`).
@@ -117,7 +116,7 @@ fn licence_files(dir: &Path, p: &Value) -> Vec<(String, String)> {
.collect() .collect()
} }
fn render(crates: &[Crate]) -> String { fn render(root: &Path, crates: &[Crate]) -> String {
let rule = "=".repeat(80); let rule = "=".repeat(80);
let mut out = format!( let mut out = format!(
"Third-party software in SolidCraft\n\nSolidCraft (the desktop app, solvecraft-cli and the web app) is built from the {} crates below.\n\ "Third-party software in SolidCraft\n\nSolidCraft (the desktop app, solvecraft-cli and the web app) is built from the {} crates below.\n\
@@ -158,6 +157,26 @@ fn render(crates: &[Crate]) -> String {
); );
} }
} }
// Bundled font licences (SIL Open Font License, Version 1.1)
let font_rule = "=".repeat(80);
out += &format!(
"\n{font_rule}\nBundled fonts (SIL Open Font License, Version 1.1)\n{font_rule}\n\n\
- LiberationSans-Regular.ttf (crates/sketch/fonts/LiberationSans-Regular.ttf)\n \
Copyright 2012 Red Hat, Inc. (Liberation Fonts 2.x; digitized data Google)\n \
Source: https://github.com/liberationfonts\n\n\
- BIZUDPGothic-Regular.ttf (apps/solvecraft-web/fonts/BIZUDPGothic-Regular.ttf)\n \
Copyright 2022 The BIZ UDGothic Project Authors (https://github.com/googlefonts/morisawa-biz-ud-mincho)\n \
Source: https://github.com/googlefonts/morisawa-biz-ud-gothic\n\n"
);
let ofl_path = root.join("apps/solvecraft-web/fonts/OFL.txt");
let fallback_path = root.join("crates/sketch/fonts/OFL.txt");
let ofl_text = std::fs::read_to_string(&ofl_path).or_else(|_| std::fs::read_to_string(&fallback_path)).unwrap_or_default();
let ofl_clean = ofl_text.replace("\r\n", "\n").trim().to_string();
if !ofl_clean.is_empty() {
out += &format!("{font_rule}\nSIL OPEN FONT LICENSE Version 1.1\n{font_rule}\n\n{ofl_clean}\n");
}
out out
} }