Compare commits

...
Author SHA1 Message Date
autocraft-bot[bot] 3916dc6bdc Merge main (2d9790c3) into the pull request
I resolved the merge in Cargo.lock, apps/wordcraft-cli/src/main.rs, crat

I resolved the merge in Cargo.lock, apps/wordcraft-cli/src/main.rs, crates/fonts/src/word.rs and docs/layout-parity.md, and no conflict markers remain. `cargo fmt --check` and clippy (fonts and CLI, all targets) are clean, and the 28 `word::` tests in the fonts crate pass. I didn't run the CLI crate's own tests. In Cargo.lock I kept both `wordcraft-fonts` and main's `wordcraft-geom` in the CLI's dependency list; I edited it by hand because the crate fetch failed on the markers. In main.rs I took main's `run_convert` and added the `report_missing_metric_fonts()` call after the input is opened. In word.rs I kept the PR's substitute lists, dropped the local `SYMBOL` const because main now has a module-level one, and added `resolve_with_db`, which main's `resolve` now calls. Both sets of tests are kept. In layout-parity.md I took main's header with the PR's change note added, put the PR's changelog row on top, and added the PR's sentence to the first of main's three Default font metrics rows. Main's table repeats some rows in slightly different forms, which I left as they are.
2026-12-04 08:19:33 +00:00
autocraft-bot[bot] ead0870d33 I updated docs/layout-parity.md, the only file changed. I changed no Rus
I updated docs/layout-parity.md, the only file changed. I changed no Rust code, so I did not run fmt, clippy or tests; only the doc was edited. (1) The header now reads "Last updated 2026-11-05" and its Change field leads with this change. (2) The "Default font metrics" checklist row now says that `wordcraft-cli convert` reports a core family (Times New Roman, Arial, Courier New, Calibri, Cambria) with no font and no open metric twin, naming the family drawn instead. It points to `fonts::word::missing_metric_fonts`. (3) I added a revision-history row dated 2026-11-05. It records the fallback and the author's page-count measurement: 120 two-line paragraphs are 6 pages in Word, 8 with no twin and 6 with Liberation Serif; 90 one-line paragraphs are 3 pages in all three. The row says these figures are the PR author's, that only page counts were compared, and that the Liberation files are still in open craft-fonts PRs. The row names the tests that exist: `core_font_notice_uses_the_actual_installed_face`, `a_listed_but_uninstalled_carlito_does_not_hide_the_chosen_fallback` and `missing_calibri_without_carlito_reports_the_drawn_fallback`. It does not name `a_missing_core_font_is_reported_only_without_a_metric_twin`, which does not exist. That wrong test name is still in the PR description, which I cannot edit; the author needs to fix it there.
2026-12-02 20:14:34 +00:00
Harrison Booth 0aaef7a5bd Merge origin/main into metric font work 2026-11-05 03:23:57 -06:00
Harrison Booth be5fe3d36f Merge remote-tracking branch 'origin/main' into upkeep-4619 2026-11-04 19:21:43 -06:00
Harrison Booth f053740960 Format metric font fallback iterator 2026-11-04 17:24:52 -06:00
Harrison Booth 7581392111 merge latest origin main 2026-11-04 17:21:15 -06:00
Harrison Booth 04e8e61e82 Merge latest main into metric font reporting 2026-11-04 07:56:35 -06:00
Harrison Booth bf95e83642 Merge remote-tracking branch 'origin/main' into wc-metric-fonts 2026-11-04 05:34:28 -06:00
Harrison Booth bec88fd149 Fonts: cover Calibri fallback without Carlito 2026-11-04 05:34:28 -06:00
Harrison Booth 1b34471bc8 Fonts: test missing core font fallbacks 2026-11-04 05:26:49 -06:00
Harrison Booth 44badab540 Merge remote-tracking branch 'origin/main' into wc-metric-fonts 2026-11-03 22:04:37 -06:00
Harrison Booth e209b4f6fd Format metric font resolution helper 2026-11-03 18:44:59 -06:00
Harrison Booth 68de4560b5 Merge origin/main and fix core font notices 2026-11-03 18:23:49 -06:00
Harrison Booth b1c6aafc33 Merge origin/main into wc-metric-fonts 2026-10-28 15:49:25 -05:00
Harrison Booth 45299ba839 wc-upkeep-6: report resolved font substitutions 2026-10-28 15:04:32 -05:00
Harrison Booth 78ea592cf4 Fonts: a metric twin counts only when resolution draws it; prefer Arimo, Tinos and Cousine; docs 2026-10-27 19:14:00 -05:00
Harrison Booth c1a20368dc Merge origin/main into wc-metric-fonts 2026-10-27 19:13:00 -05:00
Harrison Booth 32d4d32292 Fonts: say which Word core font drew in place of a missing one, and when no metric twin is installed 2026-10-27 15:07:56 -05:00
6 changed files with 115 additions and 11 deletions
+1
View File
@@ -16,6 +16,7 @@ workspace = true
[dependencies]
wordcraft-doc = { workspace = true }
wordcraft-engine = { workspace = true }
wordcraft-fonts = { workspace = true }
wordcraft-render = { workspace = true }
wordcraft-mcp = { workspace = true }
wordcraft-zotero = { workspace = true }
+11
View File
@@ -523,6 +523,7 @@ fn run_convert(rest: &[String], open: impl Fn(&str, Option<&str>) -> Result<Sess
}
let password = password_from(rest)?;
let mut s = open(&i, password.as_deref())?;
report_missing_metric_fonts();
if rest.iter().any(|a| a == "--update-fields") {
update_fields(&mut s)?;
}
@@ -563,6 +564,16 @@ fn run_source_paths(rest: &[String], script: Option<&script::Script>) -> (Option
(from_file, from_template)
}
fn report_missing_metric_fonts() {
for (word, used) in wordcraft_fonts::word::missing_metric_fonts() {
use std::io::Write as _;
let _ = writeln!(
std::io::stderr().lock(),
"note: {word} and its metric-compatible twins aren't installed; the primary family is {used}, so lines and pages may not match Word's; uncovered characters may use glyph fallback"
);
}
}
/// Run the subcommand named by `args` (the command line after the program name). Files named
/// there are opened by their real names, which may not be valid Unicode.
fn run<S: AsRef<OsStr>>(args: &[S]) -> Result<(), Failure> {
+2 -2
View File
@@ -14933,7 +14933,7 @@ fn export_png_refuses_a_path_that_is_not_png() {
#[test]
fn ime_body_epoch_marks_body_replacements_not_edits() {
let mut s = s();
let id = s.document_id();
let document_id = s.document_id();
run(&mut s, "text.insert", json!({"text": "one"}));
let first = s.ime_body_epoch();
run(&mut s, "text.insert", json!({"text": " two"}));
@@ -14942,7 +14942,7 @@ fn ime_body_epoch_marks_body_replacements_not_edits() {
run(&mut s, "document.setText", json!({"text": "same text"}));
let replaced = s.ime_body_epoch();
assert!(replaced > first, "setText replaces the body under the same document id");
assert_eq!(s.document_id(), id, "the document id itself is unchanged");
assert_eq!(s.document_id(), document_id, "the document id itself is unchanged");
// The same text again still replaces the body: a composition must not survive on content
// equality.
+14
View File
@@ -483,3 +483,17 @@ fn named_instances_and_collection_members_are_capped() {
// (under 0.1 s on a loaded machine) only backs up "read once", with room for a busy CI.
assert!(started.elapsed() < std::time::Duration::from_secs(10), "{:?}", started.elapsed());
}
#[test]
fn missing_calibri_without_carlito_reports_the_drawn_fallback() {
let db = FontDb::with_font_dirs(Vec::new());
db.set_system_fallback(false);
db.faces.write().unwrap().retain(|face| !face.family.eq_ignore_ascii_case("Carlito"));
assert!(!db.has_family("Carlito"));
let missing = crate::word::missing_metric_fonts_in(&db);
let used = missing.iter().find(|(family, _)| *family == "Calibri").map_or("", |(_, used)| used.as_str());
assert!(!used.is_empty(), "Calibri should be reported without Carlito");
assert_ne!(used, "Carlito");
assert!(db.has_family(used), "the notice names the face actually drawn");
}
+84 -7
View File
@@ -76,10 +76,10 @@ fn substitutes_by_name(family: &str) -> (&'static [&'static str], bool) {
}
}
const SERIF: &[&str] = &["Caladea", "Times New Roman", "Liberation Serif", "Georgia", "Noto Serif", "DejaVu Serif", "Source Serif 4"];
const MONO: &[&str] = &["Courier New", "Liberation Mono", "Menlo", "Consolas", "DejaVu Sans Mono", "JetBrains Mono"];
const ARIAL: &[&str] = &["Liberation Sans", "Helvetica", "Helvetica Neue", "Arimo", "Source Sans 3"];
const ARIAL_UNICODE: &[&str] = &["Arial", "Liberation Sans", "Helvetica", "Helvetica Neue", "Arimo", "Source Sans 3"];
const TIMES: &[&str] = &["Liberation Serif", "Times", "Tinos", "Source Serif 4"];
const MONO: &[&str] = &["Courier New", "Liberation Mono", "Cousine", "Menlo", "Consolas", "DejaVu Sans Mono", "JetBrains Mono"];
const ARIAL: &[&str] = &["Liberation Sans", "Arimo", "Helvetica", "Helvetica Neue", "Source Sans 3"];
const ARIAL_UNICODE: &[&str] = &["Arial", "Liberation Sans", "Arimo", "Helvetica", "Helvetica Neue", "Source Sans 3"];
const TIMES: &[&str] = &["Liberation Serif", "Tinos", "Times", "Source Serif 4"];
// Persian / Arabic document fonts. Naskh (book) faces such as B Nazanin, B Lotus, B Zar and
// Traditional Arabic, then the sans faces (B Yekan, B Titr, IRANSans) people use for
// headings and screens. Open fonts with full Persian coverage first.
@@ -494,6 +494,37 @@ fn substitute(db: &FontDb, family: &str) -> Option<&'static str> {
.or_else(|| installed.first().copied())
}
/// Word's core families, each with the open fonts that share its metrics. Without the family or
/// a twin, text set in it wraps and paginates differently from Word (Times New Roman drawn in a
/// wider serif fits fewer lines to a page).
const CORE_METRIC_FONTS: &[(&str, &[&str])] = &[
("Times New Roman", &["Liberation Serif", "Tinos"]),
("Arial", &["Liberation Sans", "Arimo"]),
("Courier New", &["Liberation Mono", "Cousine"]),
("Calibri", &["Carlito"]),
("Cambria", &["Caladea"]),
];
/// Word's core families not drawn with themselves or a metric twin, paired with the primary
/// resolved family. Glyphs the primary family cannot draw may still use glyph fallback.
pub fn missing_metric_fonts() -> Vec<(&'static str, String)> {
missing_metric_fonts_in(FontDb::global())
}
pub(crate) fn missing_metric_fonts_in(db: &FontDb) -> Vec<(&'static str, String)> {
CORE_METRIC_FONTS
.iter()
.filter_map(|(word, twins)| {
let resolved = resolve_with_db(db, word, false, false);
if has_metric_resolution(db.has_family(word), twins, &resolved.face.family) { None } else { Some((*word, resolved.face.family.clone())) }
})
.collect()
}
fn has_metric_resolution(installed_word_font: bool, twins: &[&str], resolved_family: &str) -> bool {
installed_word_font || twins.iter().any(|twin| resolved_family.eq_ignore_ascii_case(twin))
}
fn style_name(bold: bool, italic: bool) -> &'static str {
match (bold, italic) {
(false, false) => "Regular",
@@ -705,9 +736,7 @@ pub fn resolve(family: &str, bold: bool, italic: bool) -> Resolved {
return *r;
}
}
let (fam, substituted) = resolve_family(db, family);
let face = db.face(&fam, style_name(bold, italic));
let r = Resolved { synth_bold: bold && face.weight < 600.0, synth_italic: italic && !face.italic, substituted, face: FaceRef::of(&face) };
let r = resolve_with_db(db, family, bold, italic);
if cacheable {
let mut c = cache.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
if c.0 == generation {
@@ -728,6 +757,12 @@ pub fn resolve(family: &str, bold: bool, italic: bool) -> Resolved {
r
}
fn resolve_with_db(db: &FontDb, family: &str, bold: bool, italic: bool) -> Resolved {
let (fam, substituted) = resolve_family(db, family);
let face = db.face(&fam, style_name(bold, italic));
Resolved { synth_bold: bold && face.weight < 600.0, synth_italic: italic && !face.italic, substituted, face: FaceRef::of(&face) }
}
/// A line's (ascent, descent) from hhea values, both positive: the line gap goes above the ascent.
fn hhea_line(ascender: i16, descender: i16, line_gap: i16) -> (f64, f64) {
(f64::from(ascender) + f64::from(line_gap.max(0)), f64::from(descender).abs())
@@ -1094,6 +1129,48 @@ mod tests {
}
}
#[test]
fn core_font_notice_uses_the_actual_installed_face() {
const SERIF: &[u8] = include_bytes!("../../../assets/fonts/SourceSerif4-Regular.ttf");
let database = |name: Option<&str>| {
let db = FontDb::with_font_dirs(Vec::new());
db.set_system_fallback(false);
if let Some(name) = name {
assert_eq!(db.add_document_fonts(vec![(SERIF.to_vec(), name.to_owned())]), 1);
}
db
};
let original = database(Some("Times New Roman"));
assert!(missing_metric_fonts_in(&original).iter().all(|(family, _)| *family != "Times New Roman"));
assert_eq!(resolve_with_db(&original, "Times New Roman", false, false).face.family, "Times New Roman");
let twin = database(Some("Liberation Serif"));
assert!(missing_metric_fonts_in(&twin).iter().all(|(family, _)| *family != "Times New Roman"));
assert_eq!(resolve_with_db(&twin, "Times New Roman", false, false).face.family, "Liberation Serif");
let fallback = database(None);
assert_eq!(
missing_metric_fonts_in(&fallback).iter().find(|(family, _)| *family == "Times New Roman"),
Some(&("Times New Roman", "Source Serif 4".to_owned()))
);
assert_eq!(resolve_with_db(&fallback, "Times New Roman", false, false).face.family, "Source Serif 4");
let no_carlito = database(Some("DejaVu Sans"));
assert!(!no_carlito.has_family("Carlito"));
assert_eq!(resolve_with_db(&no_carlito, "Calibri", false, false).face.family, "DejaVu Sans");
assert_eq!(
missing_metric_fonts_in(&no_carlito).iter().find(|(family, _)| *family == "Calibri"),
Some(&("Calibri", "DejaVu Sans".to_owned()))
);
}
#[test]
fn a_listed_but_uninstalled_carlito_does_not_hide_the_chosen_fallback() {
assert!(!has_metric_resolution(false, &["Carlito"], "DejaVu Sans"));
assert!(has_metric_resolution(false, &["Carlito"], "Carlito"));
}
/// Semicolon-separated fallback lists resolve to the first installed family, or to a
/// candidate's substitute when no listed family is installed.
#[test]
File diff suppressed because one or more lines are too long