From dd9f8e6d10f3b1b2fdf6a4702f38dc44b9cba2cd Mon Sep 17 00:00:00 2001 From: ruchirguitar Date: Wed, 2 Dec 2026 19:43:47 +0530 Subject: [PATCH] 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//` 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. --- Cargo.lock | 1 + docs/development.md | 5 +++-- xtask/Cargo.toml | 2 ++ xtask/src/main.rs | 5 +++-- xtask/src/web_fonts.rs | 47 +++++++++++++++++++++++++++++++++++++++++- 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d0216e2962..d1f40a61ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10418,6 +10418,7 @@ checksum = "9440ea3e5aeabb0ac63af70daf835274065238cdd0cec83418f417eae38bacee" name = "xtask" version = "0.25.1" dependencies = [ + "craft-fonts-build", "serde_json", ] diff --git a/docs/development.md b/docs/development.md index 77e4b736a5..4de0357860 100644 --- a/docs/development.md +++ b/docs/development.md @@ -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. | diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 7a5c83e8b5..53678d8216 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -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] diff --git a/xtask/src/main.rs b/xtask/src/main.rs index ce60771034..783c48fd49 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -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 { diff --git a/xtask/src/web_fonts.rs b/xtask/src/web_fonts.rs index b5f3e42d2e..67d36893b3 100644 --- a/xtask/src/web_fonts.rs +++ b/xtask/src/web_fonts.rs @@ -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//` 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, staging: Option) 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 { + 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> { @@ -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//`. + #[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)));