From e37e44d86961354a3e1a1706d60d1a3eb72f9568 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Wed, 18 Nov 2026 21:02:55 +0000 Subject: [PATCH] ribbon-w7: net change of 2 commits - ribbon-w7: written from its sheet - ribbon-w7: review fixes (review-1) --- crates/font-manager/src/missing.rs | 4 +- crates/font-manager/src/picker.rs | 89 ++++++++++++++++++---- crates/font-manager/src/picker/rows.rs | 86 ++++++++++++++++----- crates/font-manager/src/picker/stories.rs | 57 ++++++++++++-- crates/font-manager/tests/it/picker.rs | 91 ++++++++++++++++++++++- 5 files changed, 287 insertions(+), 40 deletions(-) diff --git a/crates/font-manager/src/missing.rs b/crates/font-manager/src/missing.rs index 728428829..ec9d859d1 100644 --- a/crates/font-manager/src/missing.rs +++ b/crates/font-manager/src/missing.rs @@ -47,7 +47,9 @@ craft_ui::words! { warning: template "missingFonts.warning" = "font '{family}' is not installed; text may render using a fallback face"; /// The note for a shown font that is not installed, with `{family}` the missing family and `{face}` the face shown /// in its place. - shown_as: template "missingFonts.shownAs" = "{family} is not installed; shown as {face}"; + shown_as: template "missingFonts.shownAs" = "{family} isn't installed on this computer, so its text is shown in {face}. Line breaks and page count can differ from where the document was made."; + /// The advice that follows the note when the host's list has a row that adds a font. + add_font: "missingFonts.addFont" = "If you have the font file, add it with Add Font… at the end of this list."; missing_font: template "missingFonts.missingFont" = "{font} ({status})"; installed_style: template "missingFonts.installedStyle" = "{status} ({style})"; font_status: template "missingFonts.fontStatus" = "{font}: {status}"; diff --git a/crates/font-manager/src/picker.rs b/crates/font-manager/src/picker.rs index 8e9b42888..fc607adf7 100644 --- a/crates/font-manager/src/picker.rs +++ b/crates/font-manager/src/picker.rs @@ -14,7 +14,6 @@ use craft_behavior::{Codec, EditEvent, IconId, Mixed, NotAValue, PartKey, Sense, use craft_behavior::{HitLevel, HitPriority, NavMove, Preview}; use craft_font_catalog::Catalog; use craft_host::Section; -use craft_ui::buttons::IconButton; use craft_ui::contract::{ Bind, Common, Component, Cx, Edit as _, EditResponse, Focus as _, Input, MeasureCx, Outcome, OverlayUi, Overlays as _, PaintUi, PartsCx, Pointer as _, Props as _, Remember as _, Role, WordSetCx as _, @@ -27,6 +26,7 @@ use craft_ui::text::{Adornment, place, reserve}; use egui::{Rect, Response, Vec2}; use serde::{Deserialize, Serialize}; +use crate::missing::{DocumentFont, FontStatus, MissingFontsWords, document_fonts}; use rank::{Info, infos, shown_name}; craft_ui::words! { @@ -312,6 +312,17 @@ pub enum FontPickerKind { Plain, } +/// What the note of a shown font that is not installed advises. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] +pub enum MissingAdvice { + /// The note alone. + #[default] + None, + /// The note, then the advice to add the font file with the host's Add Font row. + AddFont, +} + /// What a [`FontPicker`] reports. #[derive(Debug)] #[non_exhaustive] @@ -351,6 +362,9 @@ const TEXT: PartKey = PartKey::new("text"); /// The chevron that opens and closes the list. const CHEVRON: PartKey = PartKey::new("chevron"); const CHEVRON_ICON: &str = "chevron_down"; +/// The mark before the chevron of a shown font that is not installed; its tooltip is the note. +const WARNING: PartKey = PartKey::new("missing"); +const WARNING_ICON: &str = "warning"; /// The popup the chevron and Alt+Down toggle. const POPUP: &str = "list"; /// The star at the end of a row. @@ -367,6 +381,8 @@ fn text_key() -> TextKey { struct FamilyCodec { infos: Arc, language: String, + /// A typed name that is no installed family is a value too (Word's font box applies it as typed). + free: bool, } impl FamilyCodec { @@ -382,13 +398,18 @@ impl Codec for FamilyCodec { self.infos.families.get(family).map_or_else(|| family.clone(), |info| self.shown(family, info)) } - /// A family whose name, shown or in the catalog, is the text apart from case. + /// A family whose name, shown or in the catalog, is the text apart from case; for a `free` codec, else the + /// trimmed text when it is not empty. fn parse(&self, text: &str, _: &String) -> Result { let wanted = text.trim().to_lowercase(); let named = |(family, info): (&String, &Info)| { (family.to_lowercase() == wanted || self.shown(family, info).to_lowercase() == wanted).then(|| family.clone()) }; - self.infos.families.iter().find_map(named).ok_or(NotAValue) + match self.infos.families.iter().find_map(named) { + Some(family) => Ok(family), + None if self.free && !wanted.is_empty() => Ok(text.trim().to_owned()), + None => Err(NotAValue), + } } fn sample(&self, current: &String) -> std::borrow::Cow<'_, str> { @@ -480,16 +501,17 @@ pub struct FontPicker<'a> { served: &'a [String], /// How the list is laid out: the library picker, or Word's plain font box. #[prop] - #[allow(dead_code)] // P3(ribbon-w7): rb.R21 kind: FontPickerKind, - /// Action rows above the families (the `Plain` box), reported through `FontPickerOutput::action`. + /// Action rows after the families (the `Plain` box), reported through `FontPickerOutput::action`. #[prop] - #[allow(dead_code)] // P3(ribbon-w7): rb.R21 actions: &'a [Label], /// The face the shown font is displayed in when it is not installed, for the note beside it. #[prop] - #[allow(dead_code)] // P3(ribbon-w7): rb.R21 shown_as: Option<&'a str>, + /// What the note advises beyond naming the face; `AddFont` when an action row adds a font. + #[prop] + advice: MissingAdvice, + action: Option, } impl<'a> FontPicker<'a> { @@ -510,16 +532,41 @@ impl<'a> FontPicker<'a> { kind: FontPickerKind::default(), actions: &[], shown_as: None, + advice: MissingAdvice::default(), + action: None, } .label(label) } - fn trailing(name: Label) -> [Adornment; 1] { - [Adornment::button(CHEVRON, IconSpec::svg(IconId::new(CHEVRON_ICON)), name)] + /// The adornments at the end of the field: the missing mark when `missing`, then the chevron. The mark is a glyph + /// whose part carries the note. + fn trailing(name: Label, missing: bool) -> Vec { + let mut all = Vec::with_capacity(2); + if missing { + all.push(Adornment::glyph(IconSpec::svg(IconId::new(WARNING_ICON)))); + } + all.push(Adornment::button(CHEVRON, IconSpec::svg(IconId::new(CHEVRON_ICON)), name)); + all + } + + /// The note for `family` when it is shown in another face because the catalog lacks it, by the rule the Missing + /// Fonts dialog uses: the missing-font sentence, then the advice the host chose. + fn missing_note(&self, family: &str, words: &MissingFontsWords) -> Option