mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
Web: the site publishes the interface's served fonts under fonts/ui/
The web interface font stack fetches its craft-fonts faces from the `fonts/ui/` URLs in SERVED_FONTS, but only crates/text/build.rs's OUT_DIR held those files: the Trunk hook copied the `fonts/<sha16>/` faces alone. On a built site every served interface face (Noto Sans Arabic, Thai and Georgian, NanumGothic, Noto Sans Devanagari) failed to load, and the interface drew those scripts as missing-glyph boxes. `cargo xtask web-fonts` now also publishes the `startup` and `demand` faces of crates/text/web-fonts.txt under `fonts/ui/`, licence beside each, with the same craft-fonts-build `Embed::serve` that build.rs uses, so the files match the table's URLs and integrity values. Test: publishes_the_interface_faces_at_their_served_urls. Fixes #10567.
This commit is contained in:
1 parent
fa5c9e9674
commit
dd9f8e6d10
5 files changed
+55
-5
No files matched your search
Generated
+1
@@ -10418,6 +10418,7 @@ checksum = "9440ea3e5aeabb0ac63af70daf835274065238cdd0cec83418f417eae38bacee"
|
||||
name = "xtask"
|
||||
version = "0.25.1"
|
||||
dependencies = [
|
||||
"craft-fonts-build",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
|
||||
+3
-2
@@ -178,8 +178,8 @@ CRAFT_FONTS_DIR="$PWD/../craft-fonts" cargo xtask ci # also runs the Japanese-
|
||||
that face lacks and that doesn't fit a Latin row, such as Georgian), then the other scripts'
|
||||
faces, then the installed fonts it finds for other scripts on the desktop. On the web the
|
||||
`startup` and `demand` faces of `crates/text/web-fonts.txt` are served under `fonts/ui/`
|
||||
instead: the stack fetches the UI language's at once and the others the first time text needs
|
||||
them.
|
||||
instead (`cargo xtask web-fonts`, the Trunk hook, publishes them there): the stack fetches the UI
|
||||
language's at once and the others the first time text needs them.
|
||||
- Document tab titles: desktop builds also embed the Noto Sans Condensed SemiBold row of the
|
||||
checkout's opt-in `fonts/latin-manifest.txt` (`Embed::tab_face` in `crates/text/build.rs`).
|
||||
The interface font stack draws document tab titles in it, scaled to the x-height of the
|
||||
@@ -579,6 +579,7 @@ Scores and hour estimates are unchanged.
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-12-02 | patch | Fonts (#10567): the Trunk hook `cargo xtask web-fonts` also publishes the interface's `startup` and `demand` faces under `fonts/ui/`, where `SERVED_FONTS` points; before, the site lacked them and the web interface drew those scripts as missing-glyph boxes. |
|
||||
| 2026-11-24 | minor | Fonts: the interface font stack is the framework's, set up by `ui_fonts()` and installed by `embed::install` (craft-fonts faces, the web's served faces, embedders); `theme::install_fonts` is gone and `interface-fonts` changes nothing. |
|
||||
| 2026-11-12 | minor | Tests (#6860): compare preset refusal roots after canonicalization and Windows display normalization; canonicalize the script fixture base before constructing `MAIN`. This keeps macOS `/var` → `/private/var` aliases from masking the case-sensitivity checks; no production-code change. |
|
||||
| 2026-11-12 | minor | Compile the clipboard failure helper only for Linux/BSD worker callers and unit tests; keep production macOS free of the unused helper without suppressing workspace dead-code warnings. |
|
||||
|
||||
@@ -10,6 +10,8 @@ workspace = true
|
||||
|
||||
[dependencies]
|
||||
serde_json = { workspace = true }
|
||||
# The interface faces the web site serves under fonts/ui/, written as crates/text/build.rs serves them.
|
||||
craft-fonts-build = { workspace = true }
|
||||
|
||||
# The files of other crates that this crate compiles, for CI's test selection.
|
||||
[package.metadata.craft]
|
||||
|
||||
+3
-2
@@ -71,8 +71,9 @@ commands:
|
||||
and built-in tests its interpreter supports and the String, Number, RegExp
|
||||
and Date built-ins tests, printing the counts; then fetch json2.js into
|
||||
corpus/json2 (sha256 verified) and run it
|
||||
web-fonts copy the craft-fonts faces in crates/text/web-fonts.txt into the web site (the Trunk
|
||||
post_build hook; a no-op without CRAFT_FONTS_DIR)
|
||||
web-fonts copy the craft-fonts faces in crates/text/web-fonts.txt into the web site, the
|
||||
interface's startup and demand faces also under fonts/ui/ (the Trunk post_build
|
||||
hook; a no-op without CRAFT_FONTS_DIR)
|
||||
";
|
||||
|
||||
fn main() -> ExitCode {
|
||||
|
||||
+46
-1
@@ -1,7 +1,9 @@
|
||||
//! `cargo xtask web-fonts`: the Trunk `post_build` hook (`apps/*-web/Trunk.toml`). Copies the
|
||||
//! craft-fonts faces listed in `crates/text/web-fonts.txt` from `$CRAFT_FONTS_DIR` into the site,
|
||||
//! each at `fonts/<first 16 hex digits of its SHA-256>/<file>` with its licence beside it: the URLs
|
||||
//! `crates/text/build.rs` puts in `WEB_FONTS` (both use `crates/text/build/web_fonts.rs`).
|
||||
//! `crates/text/build.rs` puts in `WEB_FONTS` (both use `crates/text/build/web_fonts.rs`). The
|
||||
//! `startup` and `demand` faces are also published under `fonts/ui/`, where the interface font stack
|
||||
//! fetches them (`SERVED_FONTS`), with the craft-fonts-build `Embed::serve` that build.rs uses.
|
||||
//!
|
||||
//! A no-op without `CRAFT_FONTS_DIR`. A listed face the checkout lacks (an older craft-fonts) is
|
||||
//! skipped with a warning, as `build.rs` does; a file whose SHA-256 doesn't match the manifest is an
|
||||
@@ -31,9 +33,35 @@ fn run_with(root: &Path, craft_fonts: Option<PathBuf>, staging: Option<PathBuf>)
|
||||
eprintln!("warning: web build won't fetch {} (not in CRAFT_FONTS_DIR={}; an older craft-fonts?)", skipped.join(", "), dir.display());
|
||||
}
|
||||
println!("web-fonts: copied {copied} font(s) into {}", staging.join("fonts").display());
|
||||
let served = serve(&root.join("crates/text/web-fonts.txt"), &dir, &staging)?;
|
||||
println!("web-fonts: published {served} interface font(s) into {}", staging.join(SERVED_URL).display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Where the site serves the interface font stack's faces: the URL prefix `crates/text/build.rs`
|
||||
/// gives them in `SERVED_FONTS`.
|
||||
const SERVED_URL: &str = "fonts/ui/";
|
||||
|
||||
/// Publish the faces the web interface's font stack fetches (the list's `startup` and `demand`
|
||||
/// lines) into `site` at their `fonts/ui/…` URLs. `crates/text/build.rs` serves the same faces with
|
||||
/// the same craft-fonts-build `Embed::serve` into its `OUT_DIR`, for the URLs, sizes and integrity
|
||||
/// values of `SERVED_FONTS`; this puts the files where those URLs point. Returns how many faces.
|
||||
fn serve(list_path: &Path, dir: &Path, site: &Path) -> Result<usize, String> {
|
||||
let list = std::fs::read_to_string(list_path).map_err(|e| format!("{}: {e}", list_path.display()))?;
|
||||
let faces: Vec<(String, String)> =
|
||||
list::parse_list(&list)?.into_iter().filter(|e| e.startup || e.demand).map(|e| (e.family.to_owned(), e.style.to_owned())).collect();
|
||||
// build.rs's table is the one the app uses; this copy, and Embed's hash cache beside it, go.
|
||||
let scratch = std::env::temp_dir().join(format!("vectorcraft-web-fonts-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&scratch).map_err(|e| format!("{}: {e}", scratch.display()))?;
|
||||
let served = craft_fonts_build::Embed::new()
|
||||
.dir(dir)
|
||||
.filter(move |f| faces.iter().any(|(family, style)| f.family == *family && f.style == *style))
|
||||
.serve(site.join(SERVED_URL), SERVED_URL)
|
||||
.write(scratch.join("served.rs"));
|
||||
let _ = std::fs::remove_dir_all(&scratch);
|
||||
served.map(|faces| faces.len()).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Copy the faces `list_path` names from the craft-fonts checkout `dir` into `site` (at their
|
||||
/// `fonts/…` URLs). Returns how many were copied and the listed faces the checkout lacks.
|
||||
fn copy(list_path: &Path, dir: &Path, site: &Path) -> Result<(usize, Vec<String>), String> {
|
||||
@@ -120,6 +148,23 @@ mod tests {
|
||||
assert_eq!(skipped, ["Missing Sans Bold"], "a face the checkout lacks is skipped, not an error");
|
||||
}
|
||||
|
||||
/// The interface font stack fetches `startup` and `demand` faces from `fonts/ui/` (build.rs's
|
||||
/// `SERVED_FONTS`), so the site holds them there, licence beside; `background` faces are only
|
||||
/// fetched from `fonts/<sha16>/`.
|
||||
#[test]
|
||||
fn publishes_the_interface_faces_at_their_served_urls() {
|
||||
let (list, dir, site, _) = fixture("serve", None);
|
||||
assert_eq!(serve(&list, &dir, &site).unwrap(), 1);
|
||||
let at = site.join("fonts/ui/a");
|
||||
assert_eq!(std::fs::read(at.join("A-Regular.ttf")).unwrap(), b"font bytes");
|
||||
assert_eq!(std::fs::read(at.join("OFL.txt")).unwrap(), b"licence");
|
||||
|
||||
let (list, dir, site, _) = fixture("serve-background", None);
|
||||
std::fs::write(&list, "background | A Sans | Regular\n").unwrap();
|
||||
assert_eq!(serve(&list, &dir, &site).unwrap(), 0);
|
||||
assert!(!site.join("fonts/ui/a/A-Regular.ttf").exists(), "a background face is not an interface face");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_file_that_does_not_match_its_manifest_hash_is_an_error() {
|
||||
let (list, dir, site, _) = fixture("mismatch", Some(&"0".repeat(64)));
|
||||
|
||||
Reference in new issue
Block a user