Merge branch 'main' into PR #2371

# Conflicts:
#	docs/ui-parity.md
This commit is contained in:
FredApps committed 2026-11-26 19:02:12 +01:00
commit 22b85c371f
4 files changed
+130 -15

No files matched your search

+83 -4
View File
@@ -345,7 +345,10 @@ pub fn bind_faces(fonts: &mut egui::FontDefinitions, family: &str, faces: &[Face
let mut bound: Vec<String> = Vec::new();
for (bold, italic) in [(false, false), (true, false), (false, true), (true, true)] {
let Some(primary) = pick_face(faces, bold, italic) else { continue };
let role = role_key(family, bold, italic);
let mut chain: Vec<String> = Vec::new();
// The face the role's text is actually drawn in: the first one whose file could be read.
let mut drawn: Option<&Face> = None;
for face in [Some(primary), pick_face(faces, false, false)] {
let Some(face) = face else { continue };
let key = face_key(face);
@@ -359,12 +362,15 @@ pub fn bind_faces(fonts: &mut egui::FontDefinitions, family: &str, faces: &[Face
fonts.font_data.insert(key.clone(), std::sync::Arc::new(fd));
}
chain.push(key);
drawn.get_or_insert(face);
}
if chain.is_empty() {
continue;
}
let Some(drawn) = drawn else { continue };
// Imitate what the drawn face lacks: italic when it is upright; bold when it is the family's
// plain face (the family has no bold of its own, or the bold file couldn't be read).
let own_bold = pick_face(faces, false, italic).is_none_or(|plain| face_key(plain) != face_key(primary));
set_synthetic(&role, SLANT, italic && !drawn.italic);
set_synthetic(&role, BOLD, bold && (face_key(drawn) != face_key(primary) || !own_bold));
chain.extend(base.iter().cloned());
let role = role_key(family, bold, italic);
fonts.families.insert(egui::FontFamily::Name(role.clone().into()), chain);
bound.push(role);
}
@@ -389,6 +395,41 @@ pub fn is_bound(role: &str) -> bool {
bound().read().unwrap_or_else(std::sync::PoisonError::into_inner).contains(role)
}
/// Roles drawn with a face that lacks their slant or weight (Arial Black has one face only), as
/// `{role}|slant` and `{role}|bold`. Excel imitates the missing style (observed in its PDF: a cell in
/// Arial Black, bold italic, is slanted by 1/3 and outlined about 1/36 of its size thick).
static SYNTHETIC: OnceLock<std::sync::RwLock<HashSet<String>>> = OnceLock::new();
const SLANT: &str = "slant";
const BOLD: &str = "bold";
fn synthetic() -> &'static std::sync::RwLock<HashSet<String>> {
SYNTHETIC.get_or_init(|| std::sync::RwLock::new(HashSet::new()))
}
fn set_synthetic(role: &str, style: &str, on: bool) {
let mut set = synthetic().write().unwrap_or_else(|e| e.into_inner());
let key = format!("{role}|{style}");
if on {
set.insert(key);
} else {
set.remove(&key);
}
}
fn is_synthetic(role: &str, style: &str) -> bool {
is_bound(role) && synthetic().read().unwrap_or_else(|e| e.into_inner()).contains(&format!("{role}|{style}"))
}
/// Does italic text in this installed family have to be slanted when drawn (no italic face)?
pub fn is_slanted(family: &str, bold: bool) -> bool {
is_synthetic(&role_key(family, bold, true), SLANT)
}
/// Does bold text in this installed family have to be thickened when drawn (no face of its own)?
pub fn is_emboldened(family: &str, italic: bool) -> bool {
is_synthetic(&role_key(family, true, italic), BOLD)
}
/// Serializes tests that mutate the process-wide bound-family registry.
#[cfg(test)]
pub(crate) static TEST_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
@@ -490,6 +531,44 @@ mod tests {
let _ = std::fs::remove_dir_all(&dir);
}
#[test]
fn styles_a_family_has_no_face_for_are_imitated() {
let _g = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let dir = std::env::temp_dir().join(format!("gridcraft-fonts-synthetic-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).expect("temp dir");
// One font file stands in for every face; each face is its own (path, index) by its name.
let face = |family: &str, file: &str, weight: f32, italic: bool| {
let path = dir.join(file);
std::fs::write(&path, epaint_default_fonts::UBUNTU_LIGHT).expect("write");
Face { family: family.into(), names: vec![family.into()], path, index: 0, weight, italic }
};
let mut fonts = egui::FontDefinitions::default();
// Like Arial Black: one face, whatever its weight.
let mut bound = bind_faces(&mut fonts, "One Face", &[face("One Face", "one.ttf", 900.0, false)]);
let full = [
face("Full", "full.ttf", 400.0, false),
face("Full", "full-b.ttf", 700.0, false),
face("Full", "full-i.ttf", 400.0, true),
face("Full", "full-bi.ttf", 700.0, true),
];
bound.extend(bind_faces(&mut fonts, "Full", &full));
// Bold and italic faces whose files can't be read: the regular face draws them, imitated.
let gone = |file: &str, weight: f32, italic: bool| Face { path: dir.join(file), ..face("Gone", "gone.ttf", weight, italic) };
let broken = [face("Gone", "gone.ttf", 400.0, false), gone("missing-b.ttf", 700.0, false), gone("missing-i.ttf", 400.0, true)];
bound.extend(bind_faces(&mut fonts, "Gone", &broken));
set_bound(bound);
assert!(is_slanted("One Face", false) && is_slanted("One Face", true));
assert!(is_emboldened("One Face", false) && is_emboldened("One Face", true));
assert!(is_slanted("Gone", false) && is_emboldened("Gone", false), "the regular face stands in, imitated");
assert!(!is_slanted("Full", false) && !is_slanted("Full", true), "its own italic faces are drawn as they are");
assert!(!is_emboldened("Full", false) && !is_emboldened("Full", true), "its own bold faces are drawn as they are");
assert!(!is_slanted("Not Bound", false) && !is_emboldened("Not Bound", false));
set_bound([]);
assert!(!is_slanted("One Face", false) && !is_emboldened("One Face", false), "nothing is imitated once unbound");
let _ = std::fs::remove_dir_all(&dir);
}
/// A font that is just a table directory and a `name` table holding `records` as
/// `(Windows language id, name id, text)`: all [`file_faces`] reads.
#[cfg(not(target_arch = "wasm32"))]
+19
View File
@@ -230,6 +230,25 @@ pub(super) fn merged_edges(wb: &Workbook, si: usize, sh: &Sheet, geo: &Geo, area
out
}
/// One cell's text as a layout job, wrapped at `wrap` (`f32::INFINITY`: one line). `slant` draws it
/// oblique, for an italic cell whose font has no italic face (see [`crate::fonts::is_slanted`]).
pub(super) fn cell_job(text: String, font: FontId, color: Color32, wrap: f32, slant: bool) -> egui::text::LayoutJob {
let mut job = egui::text::LayoutJob::simple(text, font, color, wrap);
for section in &mut job.sections {
section.format.italics = slant;
}
job
}
/// Paints one cell's text; `bold_dx` > 0 paints it again that far right, to thicken a bold cell
/// whose font has no bold face (see [`crate::fonts::is_emboldened`]).
pub(super) fn paint_cell_galley(p: &Painter, pos: Pos2, galley: std::sync::Arc<egui::Galley>, color: Color32, bold_dx: f32) {
if bold_dx > 0.0 {
p.galley(pos + egui::vec2(bold_dx, 0.0), galley.clone(), color);
}
p.galley(pos, galley, color);
}
/// The smaller font that makes `text` fit in `room` points of width (Shrink to fit), or `None`
/// when it already fits at its own size.
pub(super) fn shrink_font(p: &Painter, text: &str, font: &FontId, room: f32) -> Option<FontId> {
+26 -10
View File
@@ -1,7 +1,7 @@
use super::active_row::paint_active_row;
use super::cell_paint::{
Look, MergedArea, cell_text_y, center_across_end, col32, display_text, galley_baseline_bounds, look, merged_edges, paint_border, paint_cf_icon,
painted_halign, rotated_text_pos, shrink_font, wrapped_cell_text_y,
Look, MergedArea, cell_job, cell_text_y, center_across_end, col32, display_text, galley_baseline_bounds, look, merged_edges, paint_border,
paint_cell_galley, paint_cf_icon, painted_halign, rotated_text_pos, shrink_font, wrapped_cell_text_y,
};
use super::geo::Geo;
use super::tables::{filter_button_rect, paint_filter_button};
@@ -352,6 +352,11 @@ fn paint_cell(q: &QuadrantPaint<'_>, painted: &(CellRef, Rect, Look, Option<CfLo
let size = st.font.size * 96.0 / 72.0 * z;
let fam = theme::cell_family(&st.font.name, st.font.bold, st.font.italic);
let font = FontId::new(size, fam);
let slant = st.font.italic && crate::fonts::is_slanted(&st.font.name, st.font.bold);
let embolden = st.font.bold && crate::fonts::is_emboldened(&st.font.name, st.font.italic);
// How far the second impression of imitated bold sits from the first, by the size painted.
let ppp = p.ctx().pixels_per_point();
let bold_dx = |size: f32| if embolden { (size / 36.0).max(1.0 / ppp) } else { 0.0 };
// Digits fit by the cell's own font and size, not the default 11pt (9pt marks in narrow columns).
let char_w = p.layout_no_wrap("0".to_string(), font.clone(), Color32::PLACEHOLDER).size().x.max(1.0);
let avail_w = rect.right() - text_left;
@@ -380,7 +385,7 @@ fn paint_cell(q: &QuadrantPaint<'_>, painted: &(CellRef, Rect, Look, Option<CfLo
// Rotated text wraps along its own direction (below), not across the column width.
if !rotated && (st.align.wrap || st.align.h == HAlign::Justify) {
let wrap_w = (rect.width() - 2.0 * pad - indent).max(4.0);
let mut job = egui::text::LayoutJob::simple(text.clone(), font.clone(), color, wrap_w);
let mut job = cell_job(text.clone(), font.clone(), color, wrap_w, slant);
job.direction = direction;
job.halign_min_is_start = false;
job.halign = match painted_halign(halign, geo.rtl) {
@@ -397,7 +402,7 @@ fn paint_cell(q: &QuadrantPaint<'_>, painted: &(CellRef, Rect, Look, Option<CfLo
let (text_top, text_bottom) = galley_baseline_bounds(&galley);
let y = wrapped_cell_text_y(st.align.v, *rect, text_bottom - text_top, z) - text_top;
let text_clip = wrapped_text_clip(p, *rect, &galley, y, st.align.v);
p.with_clip_rect(text_clip).galley(pos2(x, y), galley, color);
paint_cell_galley(&p.with_clip_rect(text_clip), pos2(x, y), galley, color, bold_dx(size));
return;
}
// Wrap Text off: Excel ignores the line breaks and draws the whole string on one line.
@@ -412,7 +417,7 @@ fn paint_cell(q: &QuadrantPaint<'_>, painted: &(CellRef, Rect, Look, Option<CfLo
let shrunk = small.is_some();
let font = small.unwrap_or(font);
let layout = |text: String| {
let mut job = egui::text::LayoutJob::simple(text, font.clone(), color, f32::INFINITY);
let mut job = cell_job(text, font.clone(), color, f32::INFINITY, slant);
job.direction = direction;
job.halign_min_is_start = false;
p.layout_job(job)
@@ -507,18 +512,16 @@ fn paint_cell(q: &QuadrantPaint<'_>, painted: &(CellRef, Rect, Look, Option<CfLo
let angle = -(st.align.rotation as f32).to_radians();
// Upright (±90°) wrapped text wraps to the row height: lines then stack across the column.
let galley = if st.align.wrap && st.align.rotation.abs() == 90 {
let mut job = egui::text::LayoutJob::simple(text.clone(), font.clone(), color, (rect.height() - 2.0 * pad).max(4.0));
let mut job = cell_job(text.clone(), font.clone(), color, (rect.height() - 2.0 * pad).max(4.0), slant);
job.direction = direction;
p.layout_job(job)
} else {
galley.clone()
};
let pos = rotated_text_pos(*rect, galley.size(), angle, halign, st.align.v, pad, indent);
let mut shape = egui::epaint::TextShape::new(pos, galley, color);
shape.angle = angle;
cp.add(shape);
paint_rotated_galley(&cp, pos, galley, color, angle, bold_dx(font.size));
} else {
cp.galley(pos2(x, y), galley.clone(), color);
paint_cell_galley(&cp, pos2(x, y), galley.clone(), color, bold_dx(font.size));
}
paint_text_decorations(
&cp,
@@ -526,6 +529,19 @@ fn paint_cell(q: &QuadrantPaint<'_>, painted: &(CellRef, Rect, Look, Option<CfLo
);
}
/// Paints rotated cell text; `bold_dx` > 0 first paints it that far along the text's own
/// direction, the second impression of imitated bold.
fn paint_rotated_galley(cp: &Painter, pos: Pos2, galley: std::sync::Arc<egui::Galley>, color: Color32, angle: f32, bold_dx: f32) {
if bold_dx > 0.0 {
let mut thick = egui::epaint::TextShape::new(pos + bold_dx * egui::vec2(angle.cos(), angle.sin()), galley.clone(), color);
thick.angle = angle;
cp.add(thick);
}
let mut shape = egui::epaint::TextShape::new(pos, galley, color);
shape.angle = angle;
cp.add(shape);
}
struct TextDecoration {
x: f32,
y: f32,
+2 -1
View File
@@ -1,6 +1,6 @@
# UI parity
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (File › Print › Settings: Print Selection; earlier: File › Print › Settings: Print Selection; Page Up and Ctrl+Up into frozen rows, Ctrl+Left and Alt+Page Up into frozen columns bring the scrolled area back; Auto Fill Options button after a left-drag of the fill handle (#1403); Show Outline Symbols, Ctrl+8; a too-wide number in a repeat-fill format such as Accounting shows #### instead of losing its leading digits; Esc and Enter close a data validation alert over the cell editor; Ctrl+Enter fill gives each cell the automatic number format typing gives it; keytip letters typed with Alt held, #1846; Number Stored as Text indicator and Convert to Number; earlier: AutoFit Column Width measures a table's header in the table style's bold font; earlier: ribbon number formats widen columns nobody sized by hand, #1077; earlier: a leading + or - starts a formula, #2023; earlier: AutoSum on one cell proposes its range in the editor, #1834; earlier: Quick Analysis, Ctrl+Q (#791); earlier: validation list rows keep to their slot height whatever the font, and the "More entries not shown" note is translated; earlier: the searched validation list shows its eight rows, keeps the highlight in view and opens above a cell near the bottom of the window; earlier: the dropdown arrow's full list reads its source once within the same budget, draws only its visible rows and shows eight of them; earlier: a searched validation list reads at most 200,000 cells of its source; earlier: Find and Replace keeps workbook Undo/Redo available while a button has keyboard focus; text fields keep their own Undo; earlier: punctuation shortcuts follow the keyboard layout's characters; earlier: preserve centered emoji and symbol fallback placement; earlier: preserve leading and trailing blank cell lines; earlier: align wrapped and unwrapped cells; earlier: CJK title baseline regression and mixed-script rendering validation; earlier: form controls: buttons, sliders and spin buttons on the sheet; earlier: Highlight the active cell's row, a global preference in File › Options › General; earlier: a linked cell's menu edits, opens or removes the link; earlier: Display options for this workbook: sheet tabs and scroll bars; earlier: dragging over row or column headers in point mode extends the reference; earlier: a picture on the system clipboard pastes as a floating picture at the active cell with Cmd/Ctrl+V or Paste (#699); earlier: frozen columns keep their text, gridlines and merged borders whole while the sheet scrolls (#2544); earlier: every Paste Special option has its access key; earlier: the Draw tab's live stroke preview uses the pen's colour and thickness; earlier: copy quotes only cells with a tab or line break, as Excel does; earlier: Ctrl+. Next Corner of Selection; earlier: dragging the selection's border onto data asks before replacing it; earlier: RefEdit reference boxes in dialogs: Goal Seek, Solver and Data Analysis use them, the arrow keys select while a dialog is collapsed and F4 cycles a reference's anchors; earlier: Python cells: Python mode in the formula bar; earlier: Insert › Equation and the equation editor; earlier: every floating object selects, resizes from eight handles and deletes with the keyboard; earlier: Formulas › Error Checking › Trace Error; trace arrows stay through a zoom (#3097); earlier: Page Setup sets the page order, Down, then over or Over, then down, which printing, the print preview, Page Break Preview and Page Layout view follow; earlier: Formulas › Function Library as labelled buttons with category menus; Recently Used and the Insert Function categories; Esc leaves a File-page text field before closing the view; earlier: checkbox cells print as boxes; Ctrl+arrow and Ctrl+Shift+arrow while pointing a formula reference; editing a hyperlink loads its existing fields; AutoSum over a selected row puts its total to the right; ribbon catalog count 276 / 292; earlier: typing into a cell with a list validation searches its dropdown; Enter/Tab take the highlighted entry) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (File › Print › Settings: Print Selection; earlier: italic and bold in a font with one face, such as Arial Black, are slanted and thickened as Excel does; earlier: AutoFit Column Width measures a table's header in the table style's bold font; earlier: ribbon number formats widen columns nobody sized by hand, #1077; earlier: a leading + or - starts a formula, #2023; earlier: AutoSum on one cell proposes its range in the editor, #1834; earlier: Quick Analysis, Ctrl+Q (#791); earlier: validation list rows keep to their slot height whatever the font, and the "More entries not shown" note is translated; earlier: the searched validation list shows its eight rows, keeps the highlight in view and opens above a cell near the bottom of the window; earlier: the dropdown arrow's full list reads its source once within the same budget, draws only its visible rows and shows eight of them; earlier: a searched validation list reads at most 200,000 cells of its source; earlier: Find and Replace keeps workbook Undo/Redo available while a button has keyboard focus; text fields keep their own Undo; earlier: punctuation shortcuts follow the keyboard layout's characters; earlier: preserve centered emoji and symbol fallback placement; earlier: preserve leading and trailing blank cell lines; earlier: align wrapped and unwrapped cells; earlier: CJK title baseline regression and mixed-script rendering validation; earlier: form controls: buttons, sliders and spin buttons on the sheet; earlier: Highlight the active cell's row, a global preference in File › Options › General; earlier: a linked cell's menu edits, opens or removes the link; earlier: Display options for this workbook: sheet tabs and scroll bars; earlier: dragging over row or column headers in point mode extends the reference; earlier: a picture on the system clipboard pastes as a floating picture at the active cell with Cmd/Ctrl+V or Paste (#699); earlier: frozen columns keep their text, gridlines and merged borders whole while the sheet scrolls (#2544); earlier: every Paste Special option has its access key; earlier: the Draw tab's live stroke preview uses the pen's colour and thickness; earlier: copy quotes only cells with a tab or line break, as Excel does; earlier: Ctrl+. Next Corner of Selection; earlier: dragging the selection's border onto data asks before replacing it; earlier: RefEdit reference boxes in dialogs: Goal Seek, Solver and Data Analysis use them, the arrow keys select while a dialog is collapsed and F4 cycles a reference's anchors; earlier: Python cells: Python mode in the formula bar; earlier: Insert › Equation and the equation editor; earlier: every floating object selects, resizes from eight handles and deletes with the keyboard; earlier: Formulas › Error Checking › Trace Error; trace arrows stay through a zoom (#3097); earlier: Page Setup sets the page order, Down, then over or Over, then down, which printing, the print preview, Page Break Preview and Page Layout view follow; earlier: Formulas › Function Library as labelled buttons with category menus; Recently Used and the Insert Function categories; Esc leaves a File-page text field before closing the view; earlier: checkbox cells print as boxes; Ctrl+arrow and Ctrl+Shift+arrow while pointing a formula reference; editing a hyperlink loads its existing fields; AutoSum over a selected row puts its total to the right; ribbon catalog count 276 / 292; earlier: typing into a cell with a list validation searches its dropdown; Enter/Tab take the highlighted entry) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4
Interaction, controls and feel, against Excel. Part of [target-app-parity.md](target-app-parity.md).
**UI/UX fidelity: ~55% ready, 50–80 h** (estimated). Ribbon command coverage is measured
@@ -310,6 +310,7 @@ scrollbar bugs 2–4 · pixel/feel pass against observed Excel 7–12.
| 2026-10-31 | minor | Recently Used lists the functions most recently entered in a formula from any source, kept with the preferences; the Insert Function dialog is titled as in Excel, its category list (Most Recently Used, All, each category) works, and its category column follows the widest name shown |
| 2026-10-31 | minor | Formulas › Function Library: Insert Function, the AutoSum split button and three columns of labelled small buttons with category colours; category menus end with Insert Function…; More Functions cascades; Home › Editing shares the AutoSum menu; MR key tip for Recently Used |
| 2026-10-31 | minor | CJK fallback text shares the Latin baseline in cells, editors and window titles; fixed row heights and clipping remain workbook-controlled |
| 2026-10-30 | minor | Italic and bold in an installed font that has no face for them (Arial Black has a single face) are imitated on the grid, as Excel does: the text is slanted and drawn a second time a little to the right (about 1/36 of the size, at least one pixel). Observed in Excel's PDF of a cell in Arial Black, bold italic: oblique by 1/3 and outlined 0.23 pt thick at 9 pt. egui's slant is fixed at about 1/4. Print and PDF still use the standard PDF fonts (`fonts.rs` test) |
| 2026-10-30 | minor | Checkbox cells print and export to PDF as boxes, as on screen: unchecked white with a grey outline, checked green with a white tick (#2972). They printed their value as TRUE or FALSE; other values in a checkbox cell still print as text |
| 2026-10-29 | minor | Formula pointing from the keyboard: Ctrl+arrow (⌘arrow) moves the pointed cell to the edge of its data and Ctrl+Shift+arrow (⌘⇧arrow) extends the pointed range there, as the same keys move and extend the selection, so typing `=COUNTIF(`, clicking the top of a column and pressing ⌘⇧↓ points at the whole column of data; the keys used to move or extend by one cell. A range reaching the sheet edge is written as whole columns or rows (`A:B`). The editor reads the modifiers of the arrow's own key event, so a keystroke pressed and released within one frame (a control client's `ui.key`, an automation tool) keeps its Shift and Ctrl |
| 2026-10-29 | minor | Insert Hyperlink opens with an existing link's address, display text and ScreenTip (#2876). An address-only edit preserves the cell's content and formula; Cancel leaves the link unchanged, and Undo restores the edit |