Font menu: Small, Medium and Large set the sample size from inside the menu

Part of #6889. While the samples are shown, a row under the filters
offers Small, Medium and Large, as the font browser overview and the
user guide describe the sample size control. With Enable in-menu font
previews off, the row is not shown, as the user guide describes.

VectorCraft's own rules: a click sets Preferences › Type › Font Preview
Size (`fontPreviewSize`), so every font menu takes the new row height,
and the host writes the preferences file as it does when Preferences is
confirmed. The current size is selected, and a click on it changes
nothing. A saved value that is none of the three sizes shows Medium,
and a click replaces it. The change adds no undo step and leaves a font
previewed on the selected type in place.

https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/font-options-overview.html
https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=485

Docs: docs/target-app-parity.md evidence line.
This commit is contained in:
dotCooCoo
2026-11-17 07:23:19 -08:00
parent 0f8040ef59
commit d080f0fb85
4 changed files with 158 additions and 12 deletions
+1
View File
@@ -576,6 +576,7 @@ impl VectorcraftApp {
self.ime_caret_rect = None;
scrub::begin_frame(self, &ctx);
font_menu::end_stale_preview(self, &ctx);
font_menu::apply_preview_size(self, &ctx);
tools_float::track(self, &ctx);
// A selection move released over a panel ends before any panel sees the release (#2826).
canvas::release_over_panel(self, &ctx);
+70 -12
View File
@@ -13,9 +13,11 @@
//! they look to it ([`vectorcraft_text::FontDb::similar_families`]), that family first and without the Recent
//! Fonts section, until the ≈ chip under the filters clears it or the menu closes. The Font
//! Technology filter's Variable lists only variable font families. Preferences › Type › Enable
//! in-menu font previews and Font Preview Size turn the samples off or size the rows. The menu lays
//! out its filters on the same five rows wherever it opens. However narrow its field, it opens at
//! least wide enough for those rows and for a family name up to 220 points wide with its sample
//! in-menu font previews and Font Preview Size turn the samples off or size the rows. While the
//! samples are shown, a row under the filters sets Font Preview Size to Small, Medium or Large
//! ([`apply_preview_size`]), which sizes the rows of every font menu. The menu lays
//! out its filters on the same five rows wherever it opens, with the size row under them while the
//! samples are shown. However narrow its field, it opens at least wide enough for those rows and for a family name up to 220 points wide with its sample
//! beside it, up to 60% of the window; each sample fills its row's height. Recently used families
//! appear first, in the order they were last applied, within the same search and filters as the
//! remaining families. In the Character and Properties panels and the Control bar,
@@ -185,11 +187,7 @@ impl Default for MenuLook<'static> {
impl<'a> MenuLook<'a> {
pub fn of(app: &'a VectorcraftApp) -> Self {
let row = match app.session.prefs.font_preview_size.as_str() {
"small" => 20.0,
"large" => 32.0,
_ => ROW,
};
let row = preview_row(&app.session.prefs.font_preview_size);
Self {
samples: app.session.prefs.font_preview,
on_white: app.session.prefs.font_samples_on_white,
@@ -211,6 +209,22 @@ impl<'a> MenuLook<'a> {
/// Height of a row, in points (Font Preview Size: Medium).
const ROW: f32 = 24.0;
/// Font Preview Size's values (Preferences › Type), each with the row height it gives.
const PREVIEW_SIZES: [(&str, f32); 3] = [("small", 20.0), ("medium", ROW), ("large", 32.0)];
/// The row height of Font Preview Size `size`: Medium's for a value it does not have.
fn preview_row(size: &str) -> f32 {
PREVIEW_SIZES.iter().find(|(key, _)| *key == size).map_or(ROW, |(_, row)| *row)
}
/// The label of Font Preview Size `size`, as Preferences names it.
fn preview_size_label(size: &str) -> &'static str {
match size {
"small" => tl!("Small"),
"large" => tl!("Large"),
_ => tl!("Medium"),
}
}
/// Width of the star at the end of a family's row.
const STAR: f32 = 18.0;
/// Width of the Show Similar Fonts button before the star.
@@ -1307,7 +1321,7 @@ fn header<'s>(ui: &mut Ui, db: &'s vectorcraft_text::FontDb, state_id: egui::Id,
ui.memory_mut(|m| m.request_focus(field.with("edit")));
}
let query = widgets::search_field(ui, field, tl!("Search")).to_lowercase();
let refilter = filters(ui, st, &t, look.document.is_some());
let refilter = filters(ui, st, &t, look.document.is_some(), look.samples.then_some(look.row));
let added = added_families(db, st, look);
// On the system clock, the list is drawn again when a family's 30 days end.
if let (Some(at), None) = (added.as_ref().and_then(|a| a.recheck_at), look.clock)
@@ -1440,9 +1454,11 @@ fn filter_rows() -> [Vec<Chip>; 5] {
}
/// The filters on their rows ([`filter_rows`]): a row wraps only where the menu is narrower than
/// it. The Document filter is unavailable without a `document`. Records in `st` the width of the
/// widest row unwrapped; whether a filter changed.
fn filters(ui: &mut Ui, st: &mut MenuState, t: &Tokens, document: bool) -> bool {
/// it. The Document filter is unavailable without a `document`. With `row` (the rows' height while
/// samples are shown), a row under them offers Font Preview Size's values, the one of that height
/// selected; a click on one asks for it ([`apply_preview_size`]). Records in `st` the width of the
/// widest row unwrapped, the size row included; whether a filter changed.
fn filters(ui: &mut Ui, st: &mut MenuState, t: &Tokens, document: bool, row: Option<f32>) -> bool {
let mut refilter = false;
let mut widest = 0.0_f32;
for row in filter_rows() {
@@ -1492,6 +1508,23 @@ fn filters(ui: &mut Ui, st: &mut MenuState, t: &Tokens, document: bool) -> bool
widest = widest.max(width);
});
}
if let Some(row) = row {
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing = vec2(4.0, 2.0);
let gap = ui.spacing().item_spacing.x;
let text = |s: &str| egui::RichText::new(s).size(FILTER_SIZE);
let mut width = ui.label(text(tl!("Font Preview Size")).color(t.text_dim)).rect.width();
for (size, height) in PREVIEW_SIZES {
let on = (height - row).abs() < 0.5;
let resp = ui.selectable_label(on, text(preview_size_label(size)));
width += gap + resp.rect.width();
if resp.clicked() {
ui.data_mut(|d| d.insert_temp(preview_size_id(), size));
}
}
widest = widest.max(width);
});
}
st.filters = widest;
// While Show Similar Fonts orders the list: the family it orders by, which clears it. Its
// width is left out of the widest row: a long name wraps instead of widening the menu.
@@ -2027,6 +2060,31 @@ fn open_id() -> egui::Id {
egui::Id::unique("font-menu-open")
}
/// The id under which a font menu keeps the Font Preview Size its buttons asked for, until
/// [`apply_preview_size`] sets it.
fn preview_size_id() -> egui::Id {
egui::Id::unique("font-menu-preview-size")
}
/// Set the Font Preview Size (Preferences › Type) that a font menu's Small, Medium or Large button
/// asked for in the last pass, which sizes the rows of every font menu, and have the host write the
/// preferences file as it does when Preferences is confirmed. Nothing runs when it is already that
/// size; a saved value that is none of the sizes is replaced. The shell calls it at the start of
/// each frame.
pub(crate) fn apply_preview_size(app: &mut VectorcraftApp, ctx: &egui::Context) {
let Some(size) = ctx.data_mut(|d| d.remove_temp::<&'static str>(preview_size_id())) else { return };
if app.session.prefs.font_preview_size == size {
return;
}
match app.run("prefs.set", json!({"key": "fontPreviewSize", "value": size})) {
Ok(_) => {
crate::prefs_dialog::snapshot(app);
app.prefs_changed = true;
}
Err(e) => app.ui.status = e,
}
}
/// Undo a preview whose menu is gone (its panel wasn't drawn: the text was deselected, the panel
/// closed) or is closing (Escape, a press outside the menu), before anything else sees this
/// frame's input: the canvas must not act inside the preview's interaction (a drag would be
+86
View File
@@ -1468,3 +1468,89 @@ fn the_recently_added_filter_lists_a_font_installed_just_now() {
assert!(st.rows.is_empty(), "31 days later: {:?}", st.rows);
std::fs::remove_dir_all(&dir).unwrap();
}
/// While the samples are shown, a row under the filters offers Font Preview Size's Small, Medium
/// and Large at every size of the rows: a click on one asks for that size ([`super::apply_preview_size`]
/// leaves the rows' own size as it is). Without samples the row is not drawn.
#[test]
fn the_preview_size_row_asks_for_the_size_clicked() {
// The bundled fonts alone: fonts that tests running alongside add stay out of the rows.
let db = vectorcraft_text::FontDb::with_font_dirs(vec![]);
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
let mut st = super::MenuState::default();
for size in ["small", "medium", "large"] {
let look = super::MenuLook { row: super::preview_row(size), ..Default::default() };
let shapes = settle_menu_of(&ctx, &db, &mut st, look, vec![]);
assert!(text_at(&shapes, |t| t == "Font Preview Size").is_some(), "the row is drawn at {size}");
let mut click = |label: &str| {
let shapes = settle_menu_of(&ctx, &db, &mut st, look, vec![]);
let at = text_at(&shapes, |t| t == label).unwrap_or_else(|| panic!("{label} is drawn at {size}"));
let button =
|pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
settle_menu_of(&ctx, &db, &mut st, look, vec![egui::Event::PointerMoved(at), button(true)]);
settle_menu_of(&ctx, &db, &mut st, look, vec![button(false)]);
ctx.data_mut(|d| d.remove_temp::<&'static str>(super::preview_size_id()))
};
assert_eq!(click("Large"), Some("large"), "at {size}");
assert_eq!(click("Small"), Some("small"), "at {size}");
assert_eq!(click("Medium"), Some("medium"), "at {size}");
}
let look = super::MenuLook { row: super::preview_row("medium"), ..Default::default() };
let shapes = settle_menu_of(&ctx, &db, &mut st, super::MenuLook { samples: false, ..look }, vec![]);
assert!(text_at(&shapes, |t| t == "Font Preview Size").is_none(), "without samples the row is not drawn");
super::wait_for_samples(&ctx);
}
/// The size a font menu's button asked for becomes Font Preview Size, which sizes every font
/// menu's rows, and the host is asked to write the preferences file. The document is left as it
/// was: a font previewed on the selected type stays previewed, and the change adds no undo step.
#[test]
fn a_preview_size_asked_for_sets_the_preference_and_keeps_the_preview() {
let ctx = egui::Context::default();
let mut app = app_with_type(&[]);
let id = app.run("text.create", serde_json::json!({"x": 20, "y": 90, "text": "Size", "font": "Inter"})).unwrap()["id"].as_u64().unwrap();
app.run("select.set", serde_json::json!({"ids": [id]})).unwrap();
let font = |app: &crate::VectorcraftApp| match &app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().kind {
vectorcraft_doc::NodeKind::Text(t) => t.first_style().font_family,
_ => String::new(),
};
super::apply(&mut app, &ctx, super::FontPick::Preview("Source Serif 4".into(), None));
assert_eq!(font(&app), "Source Serif 4");
assert_eq!(super::MenuLook::of(&app).row, super::preview_row("medium"));
assert!(!app.take_prefs_changed(), "nothing to write yet");
let undo_depth = |app: &crate::VectorcraftApp| app.session.doc().unwrap().history.undo.len();
let depth = undo_depth(&app);
// The rows' own size: nothing changes.
ctx.data_mut(|d| d.insert_temp(super::preview_size_id(), "medium"));
super::apply_preview_size(&mut app, &ctx);
assert_eq!(app.session.prefs.font_preview_size, "medium");
assert!(!app.take_prefs_changed(), "nothing to write for the size the rows have");
ctx.data_mut(|d| d.insert_temp(super::preview_size_id(), "large"));
super::apply_preview_size(&mut app, &ctx);
assert_eq!(app.session.prefs.font_preview_size, "large");
assert_eq!(undo_depth(&app), depth, "the size is not an undo step");
assert_eq!(super::MenuLook::of(&app).row, super::preview_row("large"));
assert!(app.take_prefs_changed(), "the host is asked to write the preferences file");
assert_eq!(app.ui.engine_prefs["fontPreviewSize"], "large");
assert!(app.session.in_interaction(), "the preview is still open");
assert_eq!(font(&app), "Source Serif 4", "the preview stays on the type");
// Asked for once, applied once.
super::apply_preview_size(&mut app, &ctx);
assert_eq!(app.session.prefs.font_preview_size, "large");
assert!(!app.take_prefs_changed(), "nothing more to write");
// A saved value that is none of the sizes draws Medium's rows, and Medium replaces it.
app.session.prefs.font_preview_size = "huge".into();
assert_eq!(super::MenuLook::of(&app).row, super::preview_row("medium"));
ctx.data_mut(|d| d.insert_temp(super::preview_size_id(), "medium"));
super::apply_preview_size(&mut app, &ctx);
assert_eq!(app.session.prefs.font_preview_size, "medium");
assert!(app.take_prefs_changed(), "the replaced value is written");
super::apply(&mut app, &ctx, super::FontPick::EndPreview);
assert_eq!(font(&app), "Inter");
app.run("edit.undo", serde_json::json!({})).unwrap();
assert!(
app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).is_none(),
"undo takes the type away: no step was added for the size"
);
}
+1
View File
@@ -1882,6 +1882,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
The font menu's Font Technology › Variable (under the kind filter, as [Find, apply, and adjust variable fonts](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/find-apply-and-adjust-variable-fonts.html) places Variable in the classification filter's Font Technology section) lists only the families with variation axes, a family with a variable file beside static ones included, and works together with the script, kind, ★ and search filters; it stays set from one opening to the next. Measured by `font_menu::tests::the_variable_filter_lists_only_variable_families`, `font_menu::tests::the_variable_filter_is_named_as_fonts_are`, `tests_axes::a_family_with_variation_axes_is_variable` and `tests_sysfonts::a_family_with_a_variable_file_beside_static_ones_is_variable`.
The font menu's Document filter (beside ★) lists only the families that type in the current document is set in, as the quick filter for fonts used in the document does on the [font browser overview](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/font-options-overview.html). It works together with the search, script, kind, Variable and ★ filters, Recent Fonts and Show Similar Fonts, steers the closed field's wheel, follows edits and undo while the menu is open, and is shared by every font menu for the session like the other filters. VectorCraft's own rules: hidden, locked, masked, symbol, pattern and graph design type counts, styles no type uses do not, a composite font lists under its own name, a family the document names but this computer lacks is not listed (Find Font reports it), a document without available fonts lists nothing with its own message, and with no document open the filter is unavailable. Measured by `font_menu::tests::the_document_filter_lists_the_families_the_documents_type_uses`, `font_menu::tests::the_document_filter_combines_with_the_others_and_follows_edits`, `font_menu::tests::the_document_filter_counts_type_in_graph_designs` and `font_menu::tests::the_document_filter_on_an_empty_document_or_none`.
The font menu's Recently Added filter (on its own row under Font Technology) lists only the installed families added in the last 30 days, the newest at the top, as the [user guide](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=486) and the [font browser overview](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/font-options-overview.html) describe it (`vectorcraft_text::FontDb::recently_added`). It works together with the search, script, kind, Variable, ★ and Document filters, lists only the families every active filter matches, steers the closed field's wheel, and is shared by every font menu for the session like the other filters. VectorCraft's own rules: a family is dated by the creation time of its newest font file on this computer (a file the file system keeps no creation time for, or one dated in the future, does not count), the 30th day is included, families added at the same instant are in name order, the recently used families appear in that order without the Recent Fonts section, Show Similar Fonts orders only the families the filter lists, a family leaves the list when its 30 days end while the menu is open, an empty list keeps the filter on and says no fonts match, and fonts bundled with the app or loaded from documents are never listed. Measured by `font_menu::tests::the_recently_added_filter_lists_new_families_newest_first`, `font_menu::tests::the_recently_added_filter_drops_families_as_their_30_days_end`, `font_menu::tests::the_recently_added_filter_lists_a_font_installed_just_now`, `tests::recently_added::families_added_in_the_last_30_days_are_listed_newest_first`, `tests::recently_added::a_family_is_dated_by_its_newest_valid_file` and `tests::sysfonts::installed_fonts_are_recently_added_by_their_files_creation_time`.
While the samples are shown, the font menu's row under the filters sets the sample size to Small, Medium or Large from inside the menu, as the [font browser overview](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/font-options-overview.html) and the [user guide](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=485) describe the sample size control; with Enable in-menu font previews off, the row is not shown, as the user guide describes. VectorCraft's own rules: the row sits under the filters and sets Preferences › Type › Font Preview Size (`fontPreviewSize`), so every font menu takes the new row height, the Composite Fonts and Dimension dialogs' included; the current size is selected and a click on it changes nothing; a saved value that is none of the three sizes shows Medium and a click replaces it; the change adds no undo step and leaves a font previewed on the selected type in place. Measured by `font_menu::tests::the_preview_size_row_asks_for_the_size_clicked` and `font_menu::tests::a_preview_size_asked_for_sets_the_preference_and_keeps_the_preview`.
The font database looks up a name that is neither a loaded nor an installed family among the other names of the loaded and installed fonts once for each style it is asked in, and keeps the answer until fonts are added or rescanned. Laying out a story of 1,000 paragraphs set in a font that is not installed, with 400 more fonts loaded, takes a median of 56 to 71 ms instead of 409 to 507 ms on Windows 11 (`CRAFT_FONTS_DIR=<craft-fonts checkout> cargo test --release -p vectorcraft-text --lib missing_font_story_layout_timing -- --ignored --nocapture`).
A font family removed while the app runs leaves the font menus when the app scans the font folders again (when its window comes to the front after a font folder changed, or Refresh Font List), also when type had used it: that type then draws in the fallback font and Find Font lists the font as missing, until the font is installed again and the folders are scanned.
- **Files (M4):**