mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 12:38:18 +00:00
Merge pull request #7134 from dotCooCoo/feat/web-korean-devanagari-fonts
Web: Korean and Hindi interface text draws with real glyphs
This commit is contained in:
@@ -142,7 +142,7 @@ fn send(method: &str, params: Value) -> Pin<Box<dyn Future<Output = Value>>> {
|
||||
})
|
||||
}
|
||||
|
||||
async fn sleep(ms: i32) {
|
||||
pub(crate) async fn sleep(ms: i32) {
|
||||
let promise = js_sys::Promise::new(&mut |resolve, _| {
|
||||
if let Some(window) = web_sys::window() {
|
||||
let _ = window.set_timeout_with_callback_and_timeout_and_arguments_0(&resolve, ms);
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
//! Which `demand` web faces (`crates/text/web-fonts.txt`) to fetch: each face is fetched at most
|
||||
//! once at a time and never again once it loaded. A face whose fetch failed is fetched again after
|
||||
//! a wait that doubles with each failure, and not after [`MAX_TRIES`] failures.
|
||||
|
||||
/// The wait after a face's first failed fetch before it is fetched again (ms).
|
||||
const RETRY_MS: i32 = 30_000;
|
||||
/// Failed fetches of a face after which it is not fetched again this session.
|
||||
pub(crate) const MAX_TRIES: u32 = 5;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
enum State {
|
||||
Idle,
|
||||
/// Being fetched, after `tries` failed fetches.
|
||||
Loading {
|
||||
tries: u32,
|
||||
},
|
||||
Loaded,
|
||||
/// `tries` fetches failed, the last at `failed_at` (ms); the next may start at `retry_at`, or
|
||||
/// at once when the clock reads earlier than `failed_at`.
|
||||
Failed {
|
||||
tries: u32,
|
||||
failed_at: f64,
|
||||
retry_at: f64,
|
||||
},
|
||||
}
|
||||
|
||||
/// The fetch state of each face of a web font list, by index.
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct Demand {
|
||||
states: Vec<State>,
|
||||
}
|
||||
|
||||
impl Demand {
|
||||
/// Of the faces `wanted` (indexes into the list), the ones to fetch at time `now` (ms): not
|
||||
/// loaded, not being fetched, and not waiting to be fetched again. They are marked as being
|
||||
/// fetched.
|
||||
pub(crate) fn start(&mut self, wanted: &[usize], now: f64) -> Vec<usize> {
|
||||
let mut out = Vec::new();
|
||||
for &i in wanted {
|
||||
if self.states.len() <= i {
|
||||
self.states.resize(i + 1, State::Idle);
|
||||
}
|
||||
let Some(state) = self.states.get_mut(i) else { continue };
|
||||
let tries = match *state {
|
||||
State::Idle => Some(0),
|
||||
State::Loading { .. } | State::Loaded => None,
|
||||
State::Failed { tries, failed_at, retry_at } => (tries < MAX_TRIES && (now >= retry_at || now < failed_at)).then_some(tries),
|
||||
};
|
||||
if let Some(tries) = tries {
|
||||
*state = State::Loading { tries };
|
||||
out.push(i);
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The fetch of face `i` started by [`Demand::start`] ended at `now` (ms): loaded when `ok`.
|
||||
/// Returns the wait (ms) after which a failed face may be fetched again, or `None` when it
|
||||
/// loaded or has failed [`MAX_TRIES`] times.
|
||||
pub(crate) fn finished(&mut self, i: usize, ok: bool, now: f64) -> Option<i32> {
|
||||
let state = self.states.get_mut(i)?;
|
||||
let State::Loading { tries } = *state else { return None };
|
||||
if ok {
|
||||
*state = State::Loaded;
|
||||
return None;
|
||||
}
|
||||
let tries = tries + 1;
|
||||
let wait = RETRY_MS << (tries - 1).min(4);
|
||||
*state = State::Failed { tries, failed_at: now, retry_at: now + f64::from(wait) };
|
||||
(tries < MAX_TRIES).then_some(wait)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_face_is_fetched_once_and_kept() {
|
||||
let mut d = Demand::default();
|
||||
assert_eq!(d.start(&[2], 0.0), [2]);
|
||||
assert!(d.start(&[2], 1.0).is_empty(), "already being fetched");
|
||||
assert_eq!(d.finished(2, true, 2.0), None, "loaded: no retry");
|
||||
assert!(d.start(&[2], 1e9).is_empty(), "loaded: never fetched again");
|
||||
assert_eq!(d.start(&[0, 2, 1], 3.0), [0, 1], "other faces start on their own");
|
||||
assert_eq!(d.finished(7, false, 4.0), None, "a face never started");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failed_face_waits_longer_after_each_failure_and_then_stops() {
|
||||
let mut d = Demand::default();
|
||||
let mut now = 0.0;
|
||||
// The wait after the 1st, 2nd, ... failure: doubling, up to 16 times the first.
|
||||
for wait in [1, 2, 4, 8].map(|k| k * RETRY_MS) {
|
||||
assert_eq!(d.start(&[0], now), [0], "at {now}");
|
||||
assert_eq!(d.finished(0, false, now), Some(wait), "the wait after the failure at {now}");
|
||||
assert!(d.start(&[0], now + f64::from(wait) - 1.0).is_empty(), "waits {wait} ms after the failure at {now}");
|
||||
now += f64::from(wait);
|
||||
}
|
||||
// The fifth fetch, and after it fails, none.
|
||||
assert_eq!(d.start(&[0], now), [0]);
|
||||
assert_eq!(d.finished(0, false, now), None, "no retry after {MAX_TRIES} failures");
|
||||
assert!(d.start(&[0], now + 1e12).is_empty(), "no fetch after {MAX_TRIES} failures");
|
||||
// A later success after failures keeps the face.
|
||||
let mut d = Demand::default();
|
||||
d.start(&[1], 0.0);
|
||||
assert_eq!(d.finished(1, false, 0.0), Some(RETRY_MS));
|
||||
assert_eq!(d.start(&[1], f64::from(RETRY_MS)), [1]);
|
||||
assert_eq!(d.finished(1, true, f64::from(RETRY_MS)), None);
|
||||
assert!(d.start(&[1], 1e12).is_empty());
|
||||
}
|
||||
|
||||
/// While a face is fetched again after a failure, neither the interface asking for its script
|
||||
/// again nor the retry timer starts a second fetch of it.
|
||||
#[test]
|
||||
fn a_face_being_fetched_again_is_not_fetched_twice_at_once() {
|
||||
let mut d = Demand::default();
|
||||
d.start(&[0], 0.0);
|
||||
assert_eq!(d.finished(0, false, 0.0), Some(RETRY_MS));
|
||||
let retry = f64::from(RETRY_MS);
|
||||
assert_eq!(d.start(&[0, 0], retry), [0], "one fetch for a face wanted twice");
|
||||
assert!(d.start(&[0], retry + 1.0).is_empty(), "the interface asking again");
|
||||
assert!(d.start(&[0], retry + 1_000.0).is_empty(), "the retry timer");
|
||||
assert_eq!(d.finished(0, true, retry + 2_000.0), None);
|
||||
assert!(d.start(&[0], 1e12).is_empty(), "loaded");
|
||||
}
|
||||
|
||||
/// A clock that reads earlier than the failure (one set back meanwhile) does not hold the
|
||||
/// retry back: the timer that asks for it has waited already.
|
||||
#[test]
|
||||
fn a_clock_set_back_after_a_failure_does_not_stop_the_retry() {
|
||||
let mut d = Demand::default();
|
||||
let failed_at = 1e12;
|
||||
d.start(&[0], failed_at);
|
||||
assert_eq!(d.finished(0, false, failed_at), Some(RETRY_MS));
|
||||
assert!(d.start(&[0], failed_at + 1.0).is_empty(), "still waiting");
|
||||
assert_eq!(d.start(&[0], failed_at - 3_600_000.0), [0], "the clock went back an hour");
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,22 @@
|
||||
//! Craft-fonts faces served beside the wasm (`fonts/<sha16>/…`, copied by
|
||||
//! `cargo xtask web-fonts`) instead of embedded: [`load_startup_fonts`] fetches the `startup`
|
||||
//! ones before the app starts, [`spawn_background_fonts`] the rest once it runs. The browser checks
|
||||
//! each file against its SHA-256 (Subresource Integrity). A face that fails is logged and skipped:
|
||||
//! the app runs without it. With `WEB_FONTS` empty (built without craft-fonts) both do nothing.
|
||||
//! ones before the app starts, [`spawn_background_fonts`] the `background` ones once it runs, and
|
||||
//! [`want_chars`] a `demand` face (Korean, Devanagari) when the interface language or the
|
||||
//! interface's own text needs its script. The browser checks each file against its SHA-256
|
||||
//! (Subresource Integrity). A face that fails is logged and skipped: the app runs without it. With
|
||||
//! `WEB_FONTS` empty (built without craft-fonts) these do nothing.
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
|
||||
use vectorcraft_text::craft_fonts::demand_fonts;
|
||||
use vectorcraft_text::{FontDb, WEB_FONTS, WebFont};
|
||||
use wasm_bindgen::JsCast as _;
|
||||
use wasm_bindgen::closure::Closure;
|
||||
use wasm_bindgen_futures::JsFuture;
|
||||
|
||||
use crate::demand::Demand;
|
||||
|
||||
/// Per startup face: the page shows its loading text meanwhile.
|
||||
const STARTUP_TIMEOUT_MS: i32 = 20_000;
|
||||
/// Per background face.
|
||||
@@ -22,12 +27,49 @@ const BACKGROUND_PARALLEL: usize = 4;
|
||||
thread_local! {
|
||||
/// The background fetch runs once per page, though a graphics restart creates the app again.
|
||||
static BACKGROUND_STARTED: Cell<bool> = const { Cell::new(false) };
|
||||
/// The `demand` faces' fetches.
|
||||
static DEMAND: RefCell<Demand> = RefCell::new(Demand::default());
|
||||
/// The running app's context, asked for a frame when a `demand` face arrives (none before the
|
||||
/// app starts: its first frame looks through the faces loaded by then).
|
||||
static REPAINT: RefCell<Option<egui::Context>> = const { RefCell::new(None) };
|
||||
}
|
||||
|
||||
/// Fetch, in the background, the `demand` faces for the scripts of `chars` that are not loaded or
|
||||
/// being fetched. Each one that arrives asks the app for a frame, and the interface draws those
|
||||
/// characters with it from then on. Set as the interface's missing-glyph handler
|
||||
/// (`vectorcraft_ui_egui::on_missing_glyphs`), and called with the interface language's name
|
||||
/// before the app starts.
|
||||
pub fn want_chars(chars: &[char]) {
|
||||
let wanted = demand_fonts(WEB_FONTS, chars.iter().copied());
|
||||
if !wanted.is_empty() {
|
||||
fetch_demand(&wanted);
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch the `demand` faces `wanted` (indexes into `WEB_FONTS`) that [`Demand::start`] lets start.
|
||||
/// A face whose fetch fails is fetched again after the wait [`Demand::finished`] gives.
|
||||
fn fetch_demand(wanted: &[usize]) {
|
||||
for i in DEMAND.with(|d| d.borrow_mut().start(wanted, vectorcraft_ui_egui::now_ms())) {
|
||||
let Some(f) = WEB_FONTS.get(i) else { continue };
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
let ok = load(f, BACKGROUND_TIMEOUT_MS).await;
|
||||
let retry = DEMAND.with(|d| d.borrow_mut().finished(i, ok, vectorcraft_ui_egui::now_ms()));
|
||||
if ok && let Some(ctx) = REPAINT.with(|r| r.borrow().clone()) {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
if let Some(wait) = retry {
|
||||
// A second longer, so a clock the browser coarsens still reads the wait as over.
|
||||
crate::api::sleep(wait.saturating_add(1_000)).await;
|
||||
fetch_demand(&[i]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch and register the `startup` faces (one after the other). Returns how many loaded.
|
||||
pub async fn load_startup_fonts() -> usize {
|
||||
let mut loaded = 0;
|
||||
for f in WEB_FONTS.iter().filter(|f| f.startup) {
|
||||
for f in WEB_FONTS.iter().filter(|f| f.startup && !f.demand) {
|
||||
if load(f, STARTUP_TIMEOUT_MS).await {
|
||||
loaded += 1;
|
||||
}
|
||||
@@ -36,13 +78,14 @@ pub async fn load_startup_fonts() -> usize {
|
||||
}
|
||||
|
||||
/// Fetch and register the `background` faces, [`BACKGROUND_PARALLEL`] at a time, asking `ctx` for
|
||||
/// a frame after each so the font menus and the canvas pick it up. Only the first call does
|
||||
/// anything.
|
||||
/// a frame after each so the font menus and the canvas pick it up. Only the first call fetches
|
||||
/// anything; each call makes `ctx` the context a `demand` face asks for a frame.
|
||||
pub fn spawn_background_fonts(ctx: egui::Context) {
|
||||
REPAINT.with(|r| *r.borrow_mut() = Some(ctx.clone()));
|
||||
if BACKGROUND_STARTED.with(|s| s.replace(true)) {
|
||||
return;
|
||||
}
|
||||
let queue: Rc<Vec<&'static WebFont>> = Rc::new(WEB_FONTS.iter().filter(|f| !f.startup).collect());
|
||||
let queue: Rc<Vec<&'static WebFont>> = Rc::new(WEB_FONTS.iter().filter(|f| !f.startup && !f.demand).collect());
|
||||
let next = Rc::new(Cell::new(0usize));
|
||||
for _ in 0..BACKGROUND_PARALLEL.min(queue.len()) {
|
||||
let (queue, next, ctx) = (queue.clone(), next.clone(), ctx.clone());
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod api;
|
||||
#[cfg(any(target_arch = "wasm32", test))]
|
||||
mod demand;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod fonts;
|
||||
#[cfg(any(target_arch = "wasm32", test))]
|
||||
|
||||
@@ -81,6 +81,11 @@ pub fn start() {
|
||||
return;
|
||||
};
|
||||
detect_language();
|
||||
// The face for a Korean or Hindi browser language (or `?lang=`) starts loading now, beside the
|
||||
// startup fonts, without holding up the start. Text in those scripts painted later (a saved
|
||||
// interface language, another one chosen, a layer or file name) has its face fetched then.
|
||||
vectorcraft_ui_egui::on_missing_glyphs(crate::fonts::want_chars);
|
||||
crate::fonts::want_chars(&i18n::system_lang().name().chars().collect::<Vec<_>>());
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
// Before the first frame, which looks for copies a crash left behind.
|
||||
let locks = WebLocks::start(RECOVERY_PREFIX).await;
|
||||
|
||||
@@ -125,16 +125,19 @@ fn web_font_entries(dir: &Path) -> Result<(String, Vec<String>), String> {
|
||||
missing.push(format!("{} {}", e.family, e.style));
|
||||
continue;
|
||||
};
|
||||
let (Some(file), Some(sha)) = (row.get(2), row.get(6)) else {
|
||||
let (Some(file), Some(scripts), Some(sha)) = (row.get(2), row.get(3), row.get(6)) else {
|
||||
return Err(format!("malformed manifest row for {} {}", e.family, e.style));
|
||||
};
|
||||
let integrity = web_fonts::sri(sha).ok_or_else(|| format!("bad sha256 for {} {}", e.family, e.style))?;
|
||||
let scripts: Vec<String> = scripts.split(',').map(|s| format!("{:?}", s.trim())).collect();
|
||||
let _ = writeln!(
|
||||
out,
|
||||
" WebFont {{ family: {:?}, style: {:?}, startup: {}, url: {:?}, integrity: {:?} }},",
|
||||
" WebFont {{ family: {:?}, style: {:?}, startup: {}, demand: {}, scripts: &[{}], url: {:?}, integrity: {:?} }},",
|
||||
e.family,
|
||||
e.style,
|
||||
e.startup,
|
||||
e.demand,
|
||||
scripts.join(", "),
|
||||
web_fonts::url(sha, file),
|
||||
integrity,
|
||||
);
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
/// One line of `web-fonts.txt`: `when | family | style`.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Listed<'a> {
|
||||
/// `startup` (fetched before the app starts) rather than `background`.
|
||||
/// `startup` (fetched before the app starts).
|
||||
pub startup: bool,
|
||||
/// `demand` (fetched when the interface needs a character of one of the face's scripts).
|
||||
/// Neither this nor `startup`: `background`.
|
||||
pub demand: bool,
|
||||
pub family: &'a str,
|
||||
pub style: &'a str,
|
||||
}
|
||||
@@ -23,15 +26,16 @@ pub fn parse_list(text: &str) -> Result<Vec<Listed<'_>>, String> {
|
||||
let [when, family, style] = fields.as_slice() else {
|
||||
return Err(format!("web-fonts.txt line {}: expected `when | family | style`", i + 1));
|
||||
};
|
||||
let startup = match *when {
|
||||
"startup" => true,
|
||||
"background" => false,
|
||||
other => return Err(format!("web-fonts.txt line {}: `{other}` is neither startup nor background", i + 1)),
|
||||
let (startup, demand) = match *when {
|
||||
"startup" => (true, false),
|
||||
"background" => (false, false),
|
||||
"demand" => (false, true),
|
||||
other => return Err(format!("web-fonts.txt line {}: `{other}` is not startup, background or demand", i + 1)),
|
||||
};
|
||||
if family.is_empty() || style.is_empty() {
|
||||
return Err(format!("web-fonts.txt line {}: empty family or style", i + 1));
|
||||
}
|
||||
out.push(Listed { startup, family, style });
|
||||
out.push(Listed { startup, demand, family, style });
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
@@ -105,12 +109,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn list_parsing() {
|
||||
let l = parse_list("# c\n\nstartup | Noto Sans Arabic | Regular\nbackground | Amiri | Bold Italic\n").unwrap();
|
||||
let l =
|
||||
parse_list("# c\n\nstartup | Noto Sans Arabic | Regular\nbackground | Amiri | Bold Italic\ndemand | NanumGothic | Regular\n").unwrap();
|
||||
assert_eq!(
|
||||
l,
|
||||
[
|
||||
Listed { startup: true, family: "Noto Sans Arabic", style: "Regular" },
|
||||
Listed { startup: false, family: "Amiri", style: "Bold Italic" }
|
||||
Listed { startup: true, demand: false, family: "Noto Sans Arabic", style: "Regular" },
|
||||
Listed { startup: false, demand: false, family: "Amiri", style: "Bold Italic" },
|
||||
Listed { startup: false, demand: true, family: "NanumGothic", style: "Regular" }
|
||||
]
|
||||
);
|
||||
assert!(parse_list("soon | A | B").unwrap_err().contains("line 1"));
|
||||
|
||||
@@ -19,8 +19,13 @@ pub struct CraftFont {
|
||||
pub struct WebFont {
|
||||
pub family: &'static str,
|
||||
pub style: &'static str,
|
||||
/// Fetched before the app starts (a fallback the first frame needs), else in the background.
|
||||
/// Fetched before the app starts (a fallback the first frame needs).
|
||||
pub startup: bool,
|
||||
/// Fetched only when the interface needs a character of one of [`WebFont::scripts`] (see
|
||||
/// [`demand_fonts`]). With neither this nor `startup`, fetched in the background.
|
||||
pub demand: bool,
|
||||
/// ISO 15924 scripts the face is for (its craft-fonts manifest row), e.g. `"Hang"`.
|
||||
pub scripts: &'static [&'static str],
|
||||
/// Site-relative URL, `fonts/<first 16 hex digits of the SHA-256>/<file name>`.
|
||||
pub url: &'static str,
|
||||
/// Subresource Integrity value, `sha256-<base64>`; the browser rejects other bytes.
|
||||
@@ -106,10 +111,65 @@ pub fn japanese_ui_fonts(bold: bool) -> Vec<&'static CraftFont> {
|
||||
v
|
||||
}
|
||||
|
||||
/// The script of `c` that a `demand` web face is fetched for: `"Hang"` for Hangul (jamo,
|
||||
/// compatibility jamo, syllables and the halfwidth forms) and `"Deva"` for Devanagari (with its
|
||||
/// extended blocks and the Vedic extensions). `None` for every other character.
|
||||
pub fn demand_script(c: char) -> Option<&'static str> {
|
||||
match c as u32 {
|
||||
0x1100..=0x11FF | 0x3130..=0x318F | 0xA960..=0xA97F | 0xAC00..=0xD7FF | 0xFFA0..=0xFFDC => Some("Hang"),
|
||||
0x0900..=0x097F | 0x1CD0..=0x1CFF | 0xA8E0..=0xA8FF | 0x11B00..=0x11B5F => Some("Deva"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The indexes in `fonts` of the `demand` faces for the scripts of `chars` (by
|
||||
/// [`demand_script`]), each once, in `fonts` order.
|
||||
pub fn demand_fonts(fonts: &[WebFont], chars: impl IntoIterator<Item = char>) -> Vec<usize> {
|
||||
let mut scripts: Vec<&str> = Vec::new();
|
||||
for s in chars.into_iter().filter_map(demand_script) {
|
||||
if !scripts.contains(&s) {
|
||||
scripts.push(s);
|
||||
}
|
||||
}
|
||||
fonts.iter().enumerate().filter(|(_, f)| f.demand && f.scripts.iter().any(|s| scripts.contains(s))).map(|(i, _)| i).collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn web_font(family: &'static str, startup: bool, demand: bool, scripts: &'static [&'static str]) -> WebFont {
|
||||
WebFont { family, style: "Regular", startup, demand, scripts, url: "", integrity: "" }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn demand_scripts_of_hangul_and_devanagari() {
|
||||
for c in ['한', '국', 'ㄱ', 'ᄀ', 'ᄀ'] {
|
||||
assert_eq!(demand_script(c), Some("Hang"), "{c}");
|
||||
}
|
||||
for c in ['ह', 'ि', '्', '़', '।', '\u{A8F2}'] {
|
||||
assert_eq!(demand_script(c), Some("Deva"), "{c}");
|
||||
}
|
||||
for c in ['A', 'é', 'ا', 'ก', 'ა', '日', 'ロ', '中'] {
|
||||
assert_eq!(demand_script(c), None, "{c}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn demand_fonts_follow_the_scripts_painted() {
|
||||
let fonts = [
|
||||
web_font("Arabic", true, false, &["Arab"]),
|
||||
web_font("Picked", false, false, &["Hang"]),
|
||||
web_font("Korean", false, true, &["Hang", "Kore"]),
|
||||
web_font("Devanagari", false, true, &["Deva"]),
|
||||
];
|
||||
assert_eq!(demand_fonts(&fonts, "한국어".chars()), [2], "Korean fetches only the Korean face");
|
||||
assert_eq!(demand_fonts(&fonts, "हिन्दी".chars()), [3], "Hindi fetches only the Devanagari face");
|
||||
assert_eq!(demand_fonts(&fonts, "हिन्दी 한국어 Layer".chars()), [2, 3], "each once, in list order");
|
||||
assert!(demand_fonts(&fonts, "English العربية 日本語".chars()).is_empty(), "other scripts fetch nothing");
|
||||
assert!(demand_fonts(&[], "한국어".chars()).is_empty(), "built without craft-fonts: nothing to fetch");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn document_fonts_keep_script_priority_and_include_every_face_once() {
|
||||
let font = |family, style, scripts| CraftFont { family, style, scripts, bytes: &[] };
|
||||
@@ -157,7 +217,9 @@ mod tests {
|
||||
.collect();
|
||||
assert_eq!(WEB_FONTS.len(), listed.len());
|
||||
for (l, w) in listed.iter().zip(WEB_FONTS) {
|
||||
assert_eq!((l.family, l.style, l.startup), (w.family, w.style, w.startup));
|
||||
assert_eq!((l.family, l.style, l.startup, l.demand), (w.family, w.style, w.startup, w.demand));
|
||||
let face = CRAFT_FONTS.iter().find(|f| f.family == w.family && f.style == w.style);
|
||||
assert_eq!(face.map(|f| f.scripts), Some(w.scripts), "{} {}: the manifest's scripts", w.family, w.style);
|
||||
let (dir, name) = w.url.strip_prefix("fonts/").and_then(|r| r.split_once('/')).unwrap();
|
||||
assert!(dir.len() == 16 && dir.bytes().all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b)), "{}", w.url);
|
||||
assert!(name.ends_with(".ttf") || name.ends_with(".otf"), "{}", w.url);
|
||||
@@ -169,5 +231,11 @@ mod tests {
|
||||
let expected: Vec<_> =
|
||||
["Noto Sans Arabic", "Noto Sans Thai", "Noto Sans Georgian"].into_iter().filter(|n| CRAFT_FONTS.iter().any(|f| f.family == *n)).collect();
|
||||
assert_eq!(startup, expected);
|
||||
// Korean and Devanagari faces are fetched only on demand, never at startup or in the
|
||||
// background queue every session runs.
|
||||
let demand: Vec<_> = WEB_FONTS.iter().filter(|w| w.demand).map(|w| w.family).collect();
|
||||
let expected: Vec<_> = ["NanumGothic", "Noto Sans Devanagari"].into_iter().filter(|n| CRAFT_FONTS.iter().any(|f| f.family == *n)).collect();
|
||||
assert_eq!(demand, expected);
|
||||
assert!(WEB_FONTS.iter().all(|w| !(w.startup && w.demand)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1505,6 +1505,19 @@ fn remapped_source_sans(family: &str, postscript: &str, mapping: &[(char, char)]
|
||||
Some(builder.build())
|
||||
}
|
||||
|
||||
/// The family of [`private_use_font`].
|
||||
pub const PRIVATE_USE_FAMILY: &str = "Private Use Sans";
|
||||
|
||||
/// The character [`private_use_font`] maps: the first code point of Supplementary Private Use
|
||||
/// Area-A, which no bundled or craft-fonts face covers.
|
||||
pub const PRIVATE_USE_CHAR: char = '\u{F0000}';
|
||||
|
||||
/// A face that maps only [`PRIVATE_USE_CHAR`] to the bundled Source Sans 3 `H` outline, for tests
|
||||
/// that need a character no other font covers, with or without craft-fonts.
|
||||
pub fn private_use_font() -> Option<Vec<u8>> {
|
||||
remapped_source_sans(PRIVATE_USE_FAMILY, "PrivateUseSans-Regular", &[(PRIVATE_USE_CHAR, 'H')])
|
||||
}
|
||||
|
||||
/// The family of [`large_cmap_font`].
|
||||
pub const LARGE_CMAP_FAMILY: &str = "Largecmap Sans";
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
# One face per line: when | family | style (family and style as in craft-fonts' fonts/manifest.txt).
|
||||
# startup = fetched before the app starts (fallbacks the first frame needs)
|
||||
# background = fetched after the app starts (fonts users pick by name)
|
||||
# demand = fetched only when the interface language or the interface's own text needs one of
|
||||
# the face's scripts (Korean, Hindi)
|
||||
# Read by build.rs (the WEB_FONTS table) and `cargo xtask web-fonts` (copies the files, a Trunk hook).
|
||||
startup | Noto Sans Arabic | Regular
|
||||
startup | Noto Sans Thai | Regular
|
||||
@@ -36,3 +38,5 @@ background | Reem Kufi | Regular
|
||||
background | Aref Ruqaa | Regular
|
||||
background | Aref Ruqaa | Bold
|
||||
background | Gulzar | Regular
|
||||
demand | NanumGothic | Regular
|
||||
demand | Noto Sans Devanagari | Regular
|
||||
|
||||
@@ -100,7 +100,7 @@ fn plural_polish(n: u64) -> usize {
|
||||
pub static LANGUAGES: [LangInfo; 29] = [
|
||||
LangInfo { code: "en", name: "English", source: "", plural: plural_one_other, complete_menus: false, catalog: OnceLock::new() },
|
||||
// Hindi shares the integer zero/one rule with French. Desktop UI fonts are loaded lazily
|
||||
// from installed faces by ui_fonts; the web needs a Devanagari font in its font set.
|
||||
// from installed faces by ui_fonts; the web fetches a Devanagari craft-fonts face on demand.
|
||||
LangInfo {
|
||||
code: "hi",
|
||||
name: "हिन्दी",
|
||||
|
||||
@@ -1124,6 +1124,36 @@ fn bundled_fonts_cover_the_catalogs() {
|
||||
assert!(missing.is_empty(), "characters without a glyph: {missing:#?}");
|
||||
}
|
||||
|
||||
/// The faces the web build fetches on demand (`web-fonts.txt`: NanumGothic for Korean, Noto Sans
|
||||
/// Devanagari for Hindi) cover every character of their scripts that a catalog or a language name
|
||||
/// uses. Checked where the craft-fonts checkout has them (the desktop build embeds every face).
|
||||
#[test]
|
||||
fn web_demand_fonts_cover_the_catalogs() {
|
||||
use vectorcraft_text::craft_fonts::demand_script;
|
||||
let demand: Vec<_> = vectorcraft_text::WEB_FONTS.iter().filter(|w| w.demand).collect();
|
||||
if demand.is_empty() {
|
||||
eprintln!("skipped: built without craft-fonts, or one without NanumGothic and Noto Sans Devanagari");
|
||||
return;
|
||||
}
|
||||
let mut chars: std::collections::BTreeSet<char> = LANGUAGES.iter().flat_map(|l| l.name.chars()).collect();
|
||||
for l in LANGUAGES.iter().filter(|l| !l.source.is_empty()) {
|
||||
let (entries, _) = parse_entries(l.source);
|
||||
chars.extend(entries.iter().flat_map(|(_, _, tr)| tr.chars()));
|
||||
}
|
||||
let mut missing = std::collections::BTreeMap::new();
|
||||
for w in demand {
|
||||
let Some(f) = vectorcraft_text::CRAFT_FONTS.iter().find(|f| f.family == w.family && f.style == w.style) else { continue };
|
||||
let db = vectorcraft_text::FontDb::with_font_dirs(vec![]);
|
||||
db.add_font(f.bytes.to_vec());
|
||||
let face = db.face(f.family, f.style).expect("the craft-fonts face loads");
|
||||
let gone: String = chars.iter().filter(|c| demand_script(**c).is_some_and(|s| w.scripts.contains(&s)) && !face.covers(**c)).collect();
|
||||
if !gone.is_empty() {
|
||||
missing.insert(w.family, gone);
|
||||
}
|
||||
}
|
||||
assert!(missing.is_empty(), "characters the web's demand faces lack: {missing:#?}");
|
||||
}
|
||||
|
||||
/// The Traditional Chinese catalog holds no Simplified-only characters (a translation written
|
||||
/// in the wrong script would read as a typo to every user).
|
||||
#[test]
|
||||
|
||||
@@ -129,6 +129,7 @@ pub use services::{
|
||||
};
|
||||
use state::{GeometryStamp, InputGeneration, PendingScreenshot, QueuedScreenshot};
|
||||
pub(crate) use state::{InputFrame, take_frame_once};
|
||||
pub use ui_fonts::on_missing_glyphs;
|
||||
|
||||
pub struct VectorcraftApp {
|
||||
pub session: Session,
|
||||
|
||||
+216
-24
@@ -6,71 +6,154 @@
|
||||
//! don't have, an installed font covering it is looked for (in the background on native) and added
|
||||
//! to egui's families as their last fallback, on the baseline of each family's first face, from
|
||||
//! the next frame on. Text the UI fonts cover costs no font loading or memory. On the web, which
|
||||
//! has no system fonts, such characters stay missing-glyph boxes (Japanese too, unless built with
|
||||
//! craft-fonts).
|
||||
//! has no system fonts, the shell is told which characters no loaded font covers
|
||||
//! ([`on_missing_glyphs`]) and fetches a face for them (Korean, Devanagari) when it has one; until
|
||||
//! a face arrives they stay missing-glyph boxes (Japanese too, unless built with craft-fonts).
|
||||
//! Characters no font covered are looked for again whenever the font database changes.
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, OnceLock};
|
||||
|
||||
use egui::epaint::Shape;
|
||||
use egui::epaint::text::{FontInsert, FontPriority, InsertFontFamily};
|
||||
use egui::{FontData, FontDefinitions, FontFamily, FontId, FontTweak, LayerId};
|
||||
use vectorcraft_text::{FontDb, FontFace};
|
||||
|
||||
/// Called with the painted characters no loaded or installed font covers.
|
||||
static MISSING_GLYPHS: OnceLock<fn(&[char])> = OnceLock::new();
|
||||
|
||||
/// Have `f` called (on the UI thread, after a frame) with the characters the interface painted
|
||||
/// that no loaded or installed font covers, so it can load a font for them: the web shell fetches
|
||||
/// its `demand` craft-fonts faces. A character is reported again only after the fonts change and it
|
||||
/// is still not covered. The first call sets it; later calls are ignored.
|
||||
pub fn on_missing_glyphs(f: fn(&[char])) {
|
||||
let _ = MISSING_GLYPHS.set(f);
|
||||
}
|
||||
|
||||
/// What one search for fallback faces found.
|
||||
struct Found {
|
||||
/// The faces covering the characters looked for, each once.
|
||||
faces: Vec<Arc<FontFace>>,
|
||||
/// The characters no face covers.
|
||||
uncovered: Vec<char>,
|
||||
/// [`FontDb::generation`] when the search started.
|
||||
generation: u64,
|
||||
}
|
||||
|
||||
/// Look in `db` for the faces covering `chars`, each through `lookup`.
|
||||
fn search(db: &FontDb, chars: Vec<char>, lookup: impl Fn(&FontDb, char) -> Option<Arc<FontFace>>) -> Found {
|
||||
// Read before the lookups: when a font is added during them, the generation kept is older than
|
||||
// the database's, and the characters not found are looked for again.
|
||||
let generation = db.generation();
|
||||
let (mut faces, mut uncovered): (Vec<Arc<FontFace>>, Vec<char>) = (vec![], vec![]);
|
||||
for c in chars {
|
||||
match lookup(db, c) {
|
||||
Some(f) if !faces.iter().any(|x| x.id() == f.id()) => faces.push(f),
|
||||
Some(_) => {}
|
||||
None => uncovered.push(c),
|
||||
}
|
||||
}
|
||||
Found { faces, uncovered, generation }
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct UiFonts {
|
||||
/// Characters looked at already: the UI fonts have them, a fallback was added (or is being
|
||||
/// looked for), or no font has them.
|
||||
seen: HashSet<char>,
|
||||
/// Characters no font covered at the last search: looked for again once the font database's
|
||||
/// generation is no longer [`UiFonts::searched`].
|
||||
uncovered: HashSet<char>,
|
||||
/// The font database's generation when the last search started.
|
||||
searched: u64,
|
||||
/// The fonts added to egui, by name.
|
||||
added: HashSet<String>,
|
||||
/// The faces covering the characters being looked for (native: looked for on a thread).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pending: Option<std::sync::mpsc::Receiver<Vec<Arc<FontFace>>>>,
|
||||
pending: Option<std::sync::mpsc::Receiver<Found>>,
|
||||
/// The search thread can't be created (tests).
|
||||
#[cfg(all(test, not(target_arch = "wasm32")))]
|
||||
spawn_fails: bool,
|
||||
}
|
||||
|
||||
impl UiFonts {
|
||||
/// After a frame is laid out: add the fallback fonts found since the last frame, and look for
|
||||
/// fonts covering the characters this frame painted that the UI fonts lack.
|
||||
pub(crate) fn frame(&mut self, ctx: &egui::Context) {
|
||||
self.frame_in(ctx, FontDb::global(), MISSING_GLYPHS.get().copied().unwrap_or(|_| {}));
|
||||
}
|
||||
|
||||
/// [`UiFonts::frame`] looking through `db`, reporting uncovered characters to `report`.
|
||||
fn frame_in(&mut self, ctx: &egui::Context, db: &'static FontDb, report: fn(&[char])) {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if let Some(faces) = self.pending.as_ref().and_then(|rx| rx.try_recv().ok()) {
|
||||
if let Some(found) = self.pending.as_ref().and_then(|rx| rx.try_recv().ok()) {
|
||||
self.pending = None;
|
||||
self.install(ctx, &faces);
|
||||
self.found(ctx, found, report);
|
||||
}
|
||||
let mut missing = self.missing(ctx);
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let idle = self.pending.is_none();
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let idle = true;
|
||||
// A font added since (a web face fetched for them) may cover them now.
|
||||
let retry: Vec<char> =
|
||||
if idle && !self.uncovered.is_empty() && db.generation() != self.searched { self.uncovered.drain().collect() } else { vec![] };
|
||||
if !retry.is_empty() {
|
||||
missing.extend_from_slice(&retry);
|
||||
missing.sort_unstable();
|
||||
missing.dedup();
|
||||
}
|
||||
let missing = self.missing(ctx);
|
||||
if missing.is_empty() {
|
||||
return;
|
||||
}
|
||||
let find = move || {
|
||||
let mut faces: Vec<Arc<FontFace>> = vec![];
|
||||
for c in missing {
|
||||
if let Some(f) = FontDb::global().face_covering(c)
|
||||
&& !faces.iter().any(|x| x.id() == f.id())
|
||||
{
|
||||
faces.push(f);
|
||||
}
|
||||
}
|
||||
faces
|
||||
};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let looked_for = missing.clone();
|
||||
let find = move || search(db, missing, FontDb::face_covering);
|
||||
// Native: the installed fonts are read off the UI thread. Characters met meanwhile wait for
|
||||
// the next search (they aren't marked seen until then).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
let repaint = ctx.clone();
|
||||
let spawned = std::thread::Builder::new().name("ui-font-fallback".into()).spawn(move || {
|
||||
let spawned = self.spawn_search(move || {
|
||||
// The receiver is gone only when the app is.
|
||||
let _ = tx.send(find());
|
||||
repaint.request_repaint();
|
||||
});
|
||||
if spawned.is_ok() {
|
||||
self.pending = Some(rx);
|
||||
} else {
|
||||
// Not looked for: the characters met this frame are looked for when painted again,
|
||||
// and the ones no font covered wait for the fonts to change again.
|
||||
for c in looked_for.iter().filter(|c| !retry.contains(c)) {
|
||||
self.seen.remove(c);
|
||||
}
|
||||
self.uncovered.extend(retry);
|
||||
}
|
||||
}
|
||||
// The web has only the loaded fonts to look through: quick, on this thread.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
self.install(ctx, &find());
|
||||
self.found(ctx, find(), report);
|
||||
}
|
||||
|
||||
/// Run `search` on a thread of its own.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn spawn_search(&self, search: impl FnOnce() + Send + 'static) -> std::io::Result<()> {
|
||||
#[cfg(test)]
|
||||
if self.spawn_fails {
|
||||
return Err(std::io::Error::other("no thread for the font search"));
|
||||
}
|
||||
std::thread::Builder::new().name("ui-font-fallback".into()).spawn(search).map(|_| ())
|
||||
}
|
||||
|
||||
/// Add the faces a search found, and keep (and report) the characters it found no face for.
|
||||
fn found(&mut self, ctx: &egui::Context, found: Found, report: fn(&[char])) {
|
||||
self.install(ctx, &found.faces);
|
||||
self.searched = found.generation;
|
||||
if !found.uncovered.is_empty() {
|
||||
report(&found.uncovered);
|
||||
self.uncovered.extend(found.uncovered);
|
||||
}
|
||||
}
|
||||
|
||||
/// Characters painted this frame that the UI fonts lack and haven't been looked for, now
|
||||
@@ -135,8 +218,14 @@ impl UiFonts {
|
||||
/// Wait for the font search running, if any, and add what it found (tests).
|
||||
#[cfg(test)]
|
||||
pub(crate) fn finish(&mut self, ctx: &egui::Context) {
|
||||
if let Some(faces) = self.pending.take().and_then(|rx| rx.recv().ok()) {
|
||||
self.install(ctx, &faces);
|
||||
self.finish_with(ctx, |_| {});
|
||||
}
|
||||
|
||||
/// [`UiFonts::finish`], reporting uncovered characters to `report` (tests).
|
||||
#[cfg(test)]
|
||||
fn finish_with(&mut self, ctx: &egui::Context, report: fn(&[char])) {
|
||||
if let Some(found) = self.pending.take().and_then(|rx| rx.recv().ok()) {
|
||||
self.found(ctx, found, report);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -399,8 +488,111 @@ mod tests {
|
||||
for c in installed {
|
||||
assert!(has_glyph(&ctx, c), "{c} has a glyph");
|
||||
}
|
||||
// Looked for once: a later frame starts no search.
|
||||
// Looked for once: a later frame starts no search, unless characters no font covered are
|
||||
// looked for again because the fonts changed (other tests add fonts meanwhile).
|
||||
let searched = fonts.searched;
|
||||
frame(&ctx, &mut fonts, text);
|
||||
assert!(fonts.pending.is_none());
|
||||
assert!(fonts.pending.is_none() || FontDb::global().generation() != searched, "a search with the fonts unchanged");
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static REPORTED: std::cell::RefCell<Vec<char>> = const { std::cell::RefCell::new(Vec::new()) };
|
||||
}
|
||||
|
||||
fn report(chars: &[char]) {
|
||||
REPORTED.with(|r| r.borrow_mut().extend_from_slice(chars));
|
||||
}
|
||||
|
||||
/// Run a frame painting `text` with fallbacks looked for in `db`, then wait for the search.
|
||||
fn frame_in(ctx: &egui::Context, fonts: &mut UiFonts, text: &str, db: &'static FontDb) {
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
ui.label(text);
|
||||
fonts.frame_in(ui.ctx(), db, report);
|
||||
});
|
||||
out.textures_delta.clear();
|
||||
fonts.finish_with(ctx, report);
|
||||
}
|
||||
|
||||
/// A character painted while no font covers it is reported once, and draws once a font that
|
||||
/// covers it is added (as the web fetches one), with no further search while the fonts stay
|
||||
/// the same. The character is a private-use one, which no craft-fonts face covers either (the
|
||||
/// database holds them when the build embeds craft-fonts).
|
||||
#[test]
|
||||
fn a_font_added_later_draws_characters_painted_before_it() {
|
||||
use vectorcraft_text::test_fonts::{PRIVATE_USE_CHAR, PRIVATE_USE_FAMILY, private_use_font};
|
||||
let db: &'static FontDb = Box::leak(Box::new(FontDb::with_font_dirs(vec![])));
|
||||
// Scanned first, as the app's database is at startup: a first scan during the search would
|
||||
// change the generation and start one more search.
|
||||
db.families();
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let mut fonts = UiFonts::default();
|
||||
let text = format!("Layer {PRIVATE_USE_CHAR}");
|
||||
frame_in(&ctx, &mut fonts, &text, db);
|
||||
assert!(!has_glyph(&ctx, PRIVATE_USE_CHAR), "no font covers the character yet");
|
||||
assert_eq!(REPORTED.with(|r| r.borrow().clone()), [PRIVATE_USE_CHAR], "reported once");
|
||||
frame_in(&ctx, &mut fonts, &text, db);
|
||||
assert!(fonts.pending.is_none() && REPORTED.with(|r| r.borrow().len()) == 1, "no new search while the fonts are the same");
|
||||
db.add_font(private_use_font().expect("the test face builds"));
|
||||
assert!(db.face(PRIVATE_USE_FAMILY, "Regular").is_some());
|
||||
// The next frame looks again and adds the face; the one after draws with it.
|
||||
frame_in(&ctx, &mut fonts, &text, db);
|
||||
frame_in(&ctx, &mut fonts, &text, db);
|
||||
assert!(has_glyph(&ctx, PRIVATE_USE_CHAR), "the added face draws the character");
|
||||
assert!(fonts.uncovered.is_empty());
|
||||
assert_eq!(REPORTED.with(|r| r.borrow().len()), 1, "a covered character is not reported again");
|
||||
}
|
||||
|
||||
/// A font added while a search runs (another thread loading one) leaves the search's generation
|
||||
/// older than the database's, so the next frame looks again for the characters it did not find.
|
||||
#[test]
|
||||
fn a_font_added_during_a_search_has_its_characters_looked_for_again() {
|
||||
use vectorcraft_text::test_fonts::{PRIVATE_USE_CHAR, private_use_font};
|
||||
let db: &'static FontDb = Box::leak(Box::new(FontDb::with_font_dirs(vec![])));
|
||||
let found = search(db, vec![PRIVATE_USE_CHAR], |db, c| {
|
||||
let face = db.face_covering(c);
|
||||
db.add_font(private_use_font().expect("the test face builds"));
|
||||
face
|
||||
});
|
||||
assert_eq!(found.uncovered, [PRIVATE_USE_CHAR], "the lookup ran before the font was added");
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let mut fonts = UiFonts::default();
|
||||
fonts.found(&ctx, found, |_| {});
|
||||
// Painted before: the character is looked for again only because the fonts changed.
|
||||
fonts.seen.insert(PRIVATE_USE_CHAR);
|
||||
let text = format!("Layer {PRIVATE_USE_CHAR}");
|
||||
frame_in(&ctx, &mut fonts, &text, db);
|
||||
frame_in(&ctx, &mut fonts, &text, db);
|
||||
assert!(has_glyph(&ctx, PRIVATE_USE_CHAR), "the added face draws the character");
|
||||
assert!(fonts.uncovered.is_empty());
|
||||
}
|
||||
|
||||
/// A search whose thread can't be created leaves its characters to be looked for later: a
|
||||
/// character painted for the first time is looked for when it is painted again, and one no font
|
||||
/// covered stays waiting for the fonts to change.
|
||||
#[test]
|
||||
fn a_search_that_cannot_start_keeps_its_characters() {
|
||||
use vectorcraft_text::test_fonts::{PRIVATE_USE_CHAR, private_use_font};
|
||||
let db: &'static FontDb = Box::leak(Box::new(FontDb::with_font_dirs(vec![])));
|
||||
db.families();
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let mut fonts = UiFonts { spawn_fails: true, ..UiFonts::default() };
|
||||
let text = format!("Layer {PRIVATE_USE_CHAR}");
|
||||
frame_in(&ctx, &mut fonts, &text, db);
|
||||
assert!(fonts.pending.is_none() && !fonts.seen.contains(&PRIVATE_USE_CHAR), "not looked for yet");
|
||||
fonts.spawn_fails = false;
|
||||
frame_in(&ctx, &mut fonts, &text, db);
|
||||
assert!(fonts.uncovered.contains(&PRIVATE_USE_CHAR), "looked for when painted again");
|
||||
db.add_font(private_use_font().expect("the test face builds"));
|
||||
fonts.spawn_fails = true;
|
||||
frame_in(&ctx, &mut fonts, &text, db);
|
||||
assert!(fonts.uncovered.contains(&PRIVATE_USE_CHAR), "still waiting to be looked for again");
|
||||
fonts.spawn_fails = false;
|
||||
frame_in(&ctx, &mut fonts, &text, db);
|
||||
frame_in(&ctx, &mut fonts, &text, db);
|
||||
assert!(has_glyph(&ctx, PRIVATE_USE_CHAR), "the added face draws the character");
|
||||
assert!(fonts.uncovered.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -809,7 +809,8 @@ macOS cursor delivery (#2292) is narrowed to a native host adapter using the exi
|
||||
- **Evidence:** Brazilian Portuguese catalog complete under the tests (menus, literals, messages; one|other plurals; #1914). Vietnamese catalog complete under the tests (menus, literals, messages; one plural form). Czech render-site bypasses reduced in file dialogs, diagnostics, preset names and contributor tooltips; gradient grammar and printer-mark context corrected (see [localization-parity.md](localization-parity.md)). Native review and the remaining missing-language work remain.
|
||||
|
||||
- **Missing:** Arabic catalog and right-to-left layout; current gaps in other catalogs and native
|
||||
review; Hindi wording/layout review and a web Devanagari font; a Korean UI font for the web.
|
||||
review; Hindi wording/layout review. The web build fetches NanumGothic for Korean and Noto Sans
|
||||
Devanagari for Hindi when the interface needs them (`crates/text/web-fonts.txt`, `demand`).
|
||||
Hindi now has a catalog and the pinned egui fork shapes Devanagari. Indonesian already has a
|
||||
catalog (see [localization-parity.md](localization-parity.md)); it is not an absent language.
|
||||
- **Estimate:** 50–85 h plus human review (Brazilian Portuguese completed 2026-10-14).
|
||||
|
||||
@@ -131,9 +131,12 @@ The pinned egui fork shapes Devanagari with HarfRust. The desktop's existing `Ui
|
||||
finds an installed covering face, such as Nirmala UI, Kohinoor Devanagari or Noto Sans Devanagari.
|
||||
If a `CRAFT_FONTS_DIR` build includes a face tagged `Deva`, it is also installed at the end of
|
||||
each UI font family. No font binaries are added to this repository. Without either an embedded
|
||||
or installed covering face, Hindi cannot display correctly. The web has no system fonts and
|
||||
needs a Devanagari face supplied through craft-fonts; this catalog alone does not supply one.
|
||||
or installed covering face, Hindi cannot display correctly. The web has no system fonts. A web
|
||||
build made with craft-fonts serves Noto Sans Devanagari Regular beside the wasm and fetches it
|
||||
when the interface language is Hindi or the interface paints Devanagari
|
||||
(`crates/text/web-fonts.txt`, `demand`); until it arrives, Devanagari draws as missing-glyph boxes.
|
||||
Other languages do not fetch it.
|
||||
|
||||
Before release: native-speaker review of the draft (especially less common labels and error
|
||||
messages), visual checks for clipped labels and matras at different UI scales, and a web-font
|
||||
build. Reviewers should use this glossary to make terminology corrections consistently.
|
||||
messages), and visual checks for clipped labels and matras at different UI scales, on the
|
||||
desktop and on the web. Reviewers should use this glossary to make terminology corrections consistently.
|
||||
|
||||
@@ -31,7 +31,7 @@ Chinese by `imachus`). Georgian and the original Gujarati catalog are recorded a
|
||||
| English | `en` | source, 100% | all | Latin | — | full | — |
|
||||
| Simplified Chinese (Mandarin) | `zh-hans` | 5,102 rows, 791 of them `@msg` (counted 2026-10-21): menus, `tl!` literals and messages complete when counted | all (3,554 `@msg` and 48 `@msgplural` rows, counted 2026-11-13: the untranslated report lists 55 missing messages for it, which open #7116, #7211, #7330, #7378 and #7405 translate) | CJK UI font from craft-fonts (BIZ UDPGothic) when embedded, else a system font; IME with marked text at the caret; vertical type partial ([type-parity.md](type-parity.md)) | no | full | — (review) |
|
||||
| Spanish | `es` | 4,009 / 4,020 (99.7%) | all (604 messages) | Latin | no | full | — (review) |
|
||||
| Hindi | `hi` | 8,782 rows (2026-11-13): 3,014 `@msg`, 47 `@msgplural`, 41 `@plural`; the untranslated report on main `f793044f83` (2026-11-14) lists 676 missing rows for it: 608 in its own section and 68 that every checked language lacks | menus, dialogs, tooltips and scanned messages; contributor-approved loanword terminology; agent wording pass | UI and document text shape with HarfRust; installed desktop Devanagari fallback, or a `Deva` craft-fonts face; web font still needed | contributor terminology review; 2026-11-13 wording pass on messages and longer labels, and a word-sense pass on short labels, with a glossary-term test; wider proofread welcome | complete catalog, machine-assisted draft | reported missing rows, native review, layout and web font |
|
||||
| Hindi | `hi` | 8,782 rows (2026-11-13): 3,014 `@msg`, 47 `@msgplural`, 41 `@plural`; the untranslated report on main `f793044f83` (2026-11-14) lists 676 missing rows for it: 608 in its own section and 68 that every checked language lacks | menus, dialogs, tooltips and scanned messages; contributor-approved loanword terminology; agent wording pass | UI and document text shape with HarfRust; installed desktop Devanagari fallback, or a `Deva` craft-fonts face; the web fetches Noto Sans Devanagari when the interface needs it | contributor terminology review; 2026-11-13 wording pass on messages and longer labels, and a word-sense pass on short labels, with a glossary-term test; wider proofread welcome | complete catalog, machine-assisted draft | reported missing rows, native review and layout |
|
||||
| Gujarati | `gu` | 4,673 rows (2026-11-14): original 4,286 unchanged; all 387 additions contributor-reviewed and approved | menus and dialogs; status/error messages partial | installed Gujarati fonts on desktop; optional `Gujr` craft-fonts fallback; no Gujarati face in the pinned CI/release fonts or web startup list | original catalog reviewed by a native speaker; all 387 later additions approved by the contributor, with 11 wording corrections | contributor-reviewed catalog | remaining messages and a bundled Gujarati web font |
|
||||
| Arabic | `ar` | 0 | none | document text: bidi layout and Paragraph Direction; interface: no right-to-left layout, no Arabic shaping in egui | no | none | 25–40 |
|
||||
| French | `fr` | 9,166 rows, 3,436 of them `@msg` and 48 `@msgplural` (counted 2026-11-13): the untranslated report lists 178 missing messages for it | all | Latin | no | full | — (review) |
|
||||
@@ -39,13 +39,13 @@ Chinese by `imachus`). Georgian and the original Gujarati catalog are recorded a
|
||||
| Indonesian | `id` | 6,825 rows, 1,036 of them `@msg` and 47 `@msgplural` (counted 2026-11-14 on `main` at `676f0524cc`): the untranslated report lists 60 missing menu strings, 35 `tl!` literals and 13 undo labels for it; not in `COMPLETE_MESSAGES`, and checked against the same scanned messages it lacks 2,508; one plural form | most dialogs and tooltips; status and error messages partial | Latin | no | full | — (review) |
|
||||
| Japanese | `ja` | 4,004 / 4,020 (99.6%) | partial (3,562 `@msg` and 49 `@msgplural` rows, counted 2026-11-14: the untranslated report lists 98 messages without a Japanese row, 77 of which every complete-message language lacks; open #7116 and #7211 translate 35 of them) | CJK UI font as above; Japanese IME; vertical type partial; Japanese crop marks and composition settings | no | full | — (review) |
|
||||
| German | `de` | 3,952 / 4,020 (98%; menus, literals and messages complete when counted) | all (3,563 `@msg` and 48 `@msgplural` rows, counted 2026-11-13: the untranslated report lists 52 missing messages for it, which open #7116, #7211 and #7378 translate) | Latin | contributor-written, not reviewed | full | — (review) |
|
||||
| Korean | `ko` | 4,870 rows (counted 2026-10-21): menus, `tl!` literals and messages complete when counted; one plural form | all (3,438 `@msg` and 48 `@msgplural` rows, counted 2026-11-13: the untranslated report lists 39 missing messages for it) | Hangul from an installed system font on the desktop (Apple SD Gothic Neo, Malgun Gothic, Noto Sans CJK KR…); the web build has no Korean UI font yet (craft-fonts); IME path exists | no (AI-drafted) | full | — (review; web font) |
|
||||
| Korean | `ko` | 4,870 rows (counted 2026-10-21): menus, `tl!` literals and messages complete when counted; one plural form | all (3,438 `@msg` and 48 `@msgplural` rows, counted 2026-11-13: the untranslated report lists 39 missing messages for it) | Hangul from an installed system font on the desktop (Apple SD Gothic Neo, Malgun Gothic, Noto Sans CJK KR…); the web build fetches NanumGothic from craft-fonts when the interface needs it; IME path exists | no (AI-drafted) | full | — (review) |
|
||||
| Vietnamese | `vi` | 4,886 rows (counted 2026-10-21): menus, `tl!` literals and messages complete when counted; one plural form; 4,046 plain + 18 `@plural` + 28 contextual + 794 `@msg` | dialogs and tooltips all; messages partial (1,750 `@msg` and 49 `@msgplural` rows, counted 2026-11-14: the untranslated report lists 1,875 messages without a Vietnamese row, 53 of which open #7211, #7378, #7405 and #7434 translate) | Latin with Vietnamese diacritics (stacked marks attach in precomposed, decomposed and keyboard forms, #4491; glyph tests pass) | contributor is a Vietnamese speaker; AI-assisted draft, further native review welcome | full | — (review) |
|
||||
|
||||
**Historical 12-language score: ~82%** (equal weights: 100 + 85 + 100 + 0 + 0 + 100 + 100 + 100 + 100 + 98 + 100 + 100, over 12).
|
||||
**To `full` for all twelve: ~50–85 h** (historical estimate, not re-scored here). Hindi now has
|
||||
a catalog that the tests count as complete, and UI shaping; its remaining work is the rows the
|
||||
untranslated report lists for it, native review, layout checking and the web font. Arabic still needs its catalog and right-to-left interface. Each new Latin-script catalog is ~4,000 rows; the existing ones were written in a few agent hours each
|
||||
untranslated report lists for it, native review and layout checking. Arabic still needs its catalog and right-to-left interface. Each new Latin-script catalog is ~4,000 rows; the existing ones were written in a few agent hours each
|
||||
plus review. Native-speaker review is human work and isn't in the hours.
|
||||
|
||||
## Other shipped languages
|
||||
|
||||
@@ -1639,6 +1639,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
Burasagari ([the help page](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html)) leaves a right-to-left paragraph's comma or full stop inside its line, which then ends at a break where it fits with the mark, and in a left-to-right line with right-to-left text and a tab it hangs a mark only when the mark is drawn at the line's right end and the rest of the line fits as drawn; otherwise the line ends at the latest break that fits as drawn. Both are VectorCraft's own rules (`crates/text/src/layout/wrapping_tests.rs`, `crates/text/src/tests/hang.rs`). Scores and estimates are unchanged.
|
||||
The Paragraph panel's Mojikumi Set lists the five predefined sets the help page names (None, YakumonoHankaku, GyomatsuYakumonoHankaku, GyomatsuYakumonoZenkaku and YakumonoZenkaku), then Line-end Punctuation Half Width, and `text.setFormat {mojikumi}` takes each of them. YakumonoHankaku sets every bracket, comma and full stop half width and takes a quarter em off each side of a middle dot; GyomatsuYakumonoHankaku keeps punctuation full width inside a line, sets an opening bracket flush at a line's start and a closing mark half width at its end, and takes the quarter em after a middle dot off at a line's end; GyomatsuYakumonoZenkaku keeps punctuation full width and adds a quarter em between Japanese and Latin text; YakumonoZenkaku sets characters as None does. These widths are VectorCraft's own rules, from the help page's one-line description of each set. Both composers and vertical type measure each line as it is set, the sets save with the document and paragraph styles, and a `.ai` save reports the new sets as left out (`crates/text/src/tests/vertical.rs`, `crates/ui-egui/src/panels/paragraph/tests.rs`). Scores and estimates are unchanged.
|
||||
Interface text in characters the interface's fonts lack, drawn in a bundled Japanese, Georgian or Devanagari face or in an installed font that covers them, sits on the baseline of the Latin text beside it, monospace text included (#5816; `crates/ui-egui/src/ui_fonts.rs`, `crates/ui-egui/src/theme.rs`).
|
||||
On the web, Korean and Hindi interface text draws with real glyphs: a web build made with craft-fonts fetches NanumGothic for Hangul (about 2 MB) or Noto Sans Devanagari (about 280 KB) only when the interface language or the interface's own text (a layer or file name, the language picker) needs that script. The frame after the face arrives adds it to the interface fonts, and the frame after that draws the characters painted before it with that face. Sessions in other languages do not download them at startup. After a failed fetch the next try comes about 30 seconds later, and the wait doubles after each further failure, for at most five tries (`crates/text/web-fonts.txt`, `apps/vectorcraft-web/src/fonts.rs`, `apps/vectorcraft-web/src/demand.rs`, `crates/ui-egui/src/ui_fonts.rs`).
|
||||
Character panel menu › Standard Vertical Roman Alignment (with the East Asian options; `text.setFormat` or `text.setRangeStyle {standardVerticalRoman}`, off by default) stands the selected Latin letters, digits and other half-width characters upright one below the other in vertical type instead of rotating them ([formatting Asian characters](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html)); spaces keep their width, tate-chu-yoko blocks stay across the column, and Character Style Options gives it its own checkbox beside Character Alignment.
|
||||
The Glyphs panel menu (with the East Asian options) offers Traditional, Expert, JIS 04, JIS 90, JIS 78 and JIS 83 Forms, Monospaced Full-Width, Half-Width, Third-Width and Quarter-Width Forms, and Revert To Default Forms ([formatting Asian characters](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html)); each draws the selected characters with the font's OpenType feature for that form (`trad`, `expt`, `jp04`, `jp90`, `jp78`, `jp83`, `fwid`, `hwid`, `twid`, `qwid`), one form at a time, and a form none of the faces that draw the selected text has a feature for (in `GSUB`, or for the width forms `GSUB` or `GPOS`) is disabled. A form other than the default takes away a character's glyph choice, and with a width form Proportional Metrics' `palt` is not applied and the font's pair kerning is off. `text.setFormat` and `text.setRangeStyle {glyphForm}` set it; the native file, character styles, the canvas, PDF and SVG (`font-feature-settings`) keep it (`tests::typo::glyph_forms_draw_the_fonts_east_asian_forms`, `typecmd::area_tests::glyph_form_is_one_character_attribute_saved_only_when_set`, `typecmd::area_tests::a_glyph_form_takes_away_the_characters_glyph_choice`, `features::tests::width_forms_turn_off_proportional_metrics`, `panels::glyphs` tests).
|
||||
Character panel menu › Tate-chu-yoko Settings… (with the East Asian options; `ui.tateChuYokoSettings`, `text.setFormat` or `text.setRangeStyle {tcyUpDown, tcyLeftRight}`, in points, 0 by default) moves a marked tate-chu-yoko block in vertical type up by a positive Up/Down and right by a positive Left/Right ([format East Asian characters in vertical text](https://helpx.adobe.com/illustrator/desktop/design-with-text/edit-format-text/format-east-asian-characters-in-vertical-text.html), [formatting Asian characters](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html)); the block moves as one piece with its first character's values and keeps its one em down the column, on a vertical path it moves toward the path's start and to the path's left, automatic digit blocks do not move, Reset Panel sets both back to 0, and character styles and the native file keep them.
|
||||
|
||||
Reference in New Issue
Block a user