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

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">
<title>SolidCraft</title>
<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>
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; }
+65 -27
View File
@@ -46,6 +46,18 @@ mod web {
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 {
app: SolveApp,
files: Rc<Files>,
@@ -58,6 +70,8 @@ mod web {
rename_focus: bool,
/// The start page's recent designs were filled from the stored ones.
recents_synced: bool,
font_status: FontStatus,
font_result: FontLoadResult,
}
impl Shell {
@@ -304,10 +318,59 @@ mod web {
}
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 {
fn logic(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
self.tick_font(ctx);
self.app.logic(ctx);
self.files_tick(ctx);
UNSAVED.with(|u| u.set(solvecraft_ui_egui::documents::any_dirty(&self.app)));
@@ -347,32 +410,6 @@ mod web {
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() {
eframe::WebLogger::init(log::LevelFilter::Info).ok();
wasm_bindgen_futures::spawn_local(async {
@@ -395,7 +432,6 @@ mod web {
options,
Box::new(move |cc| {
solvecraft_ui_egui::fonts::setup_fonts(&cc.egui_ctx);
load_web_fonts(cc.egui_ctx.clone());
let files = Rc::new(Files::default());
files::start(&files);
let panel = files.clone();
@@ -439,6 +475,8 @@ mod web {
renaming: None,
rename_focus: false,
recents_synced: false,
font_status: FontStatus::Unloaded,
font_result: Rc::new(std::cell::RefCell::new(None)),
}))
}),
)