Merge pull request #10568 from ruchirguitar/fix/web-served-fonts

Web: the site publishes the interface's served fonts under fonts/ui/
This commit is contained in:
BFlat authored and GitHub committed 2026-12-03 23:14:15 +07:00
commit 9daf4163eb
5 files changed
+69 -5

No files matched your search

Generated
+2
View File
@@ -10437,7 +10437,9 @@ checksum = "9440ea3e5aeabb0ac63af70daf835274065238cdd0cec83418f417eae38bacee"
name = "xtask"
version = "0.25.1"
dependencies = [
"craft-fonts-build",
"serde_json",
"tempfile",
]
[[package]]
+3 -2
View File
@@ -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
@@ -583,6 +583,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. |
+5
View File
@@ -10,6 +10,11 @@ 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 private scratch folder web-fonts writes the served-faces table to. Already in Cargo.lock
# (the apps use it), so this adds no new crate.
tempfile = "3"
# The files of other crates that this crate compiles, for CI's test selection.
[package.metadata.craft]
+3 -2
View File
@@ -73,8 +73,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 {
+56 -1
View File
@@ -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,40 @@ 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, None)?;
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. `required` overrides
/// `CRAFT_FONTS_REQUIRED`, which decides it otherwise, as in build.rs. Returns how many faces.
fn serve(list_path: &Path, dir: &Path, site: &Path, required: Option<bool>) -> 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.
// A private folder this call creates (random name, created exclusively, owner-only on Unix)
// and removes when `scratch` drops, so nothing another process made is reused or removed.
let scratch = tempfile::Builder::new().prefix("vectorcraft-web-fonts-").tempdir().map_err(|e| format!("scratch folder: {e}"))?;
let embed = craft_fonts_build::Embed::new().dir(dir);
let embed = match required {
Some(required) => embed.required(required),
None => embed,
};
let served = embed
.filter(move |f| faces.iter().any(|(family, style)| f.family == *family && f.style == *style))
.serve(site.join(SERVED_URL), SERVED_URL)
.write(scratch.path().join("served.rs"));
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 +153,28 @@ 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, Some(false)).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-demand", None);
std::fs::write(&list, "demand | A Sans | Regular\n").unwrap();
assert_eq!(serve(&list, &dir, &site, Some(false)).unwrap(), 1);
assert!(site.join("fonts/ui/a/A-Regular.ttf").exists(), "a face fetched on demand is an interface face");
let (list, dir, site, _) = fixture("serve-background", None);
std::fs::write(&list, "background | A Sans | Regular\n").unwrap();
assert_eq!(serve(&list, &dir, &site, Some(false)).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)));