From 17aae2da04d3cf94c113182711753afa5a7581f2 Mon Sep 17 00:00:00 2001 From: DerKarussellbremser <67138735+DerKarussellbremser@users.noreply.github.com> Date: Sat, 24 Oct 2026 11:41:23 +0200 Subject: [PATCH 1/7] Grid: italic and bold in a one-face font are slanted and thickened, as in Excel Arial Black has a single face. A cell in Arial Black, bold italic, drew it upright and at its own weight; Excel slants it and thickens it (observed in its PDF: oblique by 1/3, outlined 0.23 pt at 9 pt). fonts.rs notes, while it binds a family's roles, which italic roles got an upright face and which bold roles got the plain face; the grid then lays such text out with egui's italics and paints it a second time about 1/36 of its size to the right. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KKbbMZpkzQuncTpqAyhkp9 --- crates/ui-egui/src/fonts.rs | 70 ++++++++++++++++++++++++++++++++++++- crates/ui-egui/src/grid.rs | 37 +++++++++++++++----- docs/ui-parity.md | 3 +- 3 files changed, 100 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/fonts.rs b/crates/ui-egui/src/fonts.rs index 1a381b9d46..11125a9b04 100644 --- a/crates/ui-egui/src/fonts.rs +++ b/crates/ui-egui/src/fonts.rs @@ -325,6 +325,13 @@ pub fn bind_faces(fonts: &mut egui::FontDefinitions, family: &str, faces: &[Face let mut bound: Vec = 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); + if italic && !primary.italic { + mark_synthetic(&role, SLANT); + } + if bold && pick_face(faces, false, italic).is_some_and(|plain| face_key(plain) == face_key(primary)) { + mark_synthetic(&role, BOLD); + } let mut chain: Vec = Vec::new(); for face in [Some(primary), pick_face(faces, false, false)] { let Some(face) = face else { continue }; @@ -344,7 +351,6 @@ pub fn bind_faces(fonts: &mut egui::FontDefinitions, family: &str, faces: &[Face continue; } 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); } @@ -374,6 +380,35 @@ pub fn is_bound(role: &str) -> bool { bound().read().unwrap_or_else(|e| e.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>> = OnceLock::new(); +const SLANT: &str = "slant"; +const BOLD: &str = "bold"; + +fn synthetic() -> &'static std::sync::RwLock> { + SYNTHETIC.get_or_init(|| std::sync::RwLock::new(HashSet::new())) +} + +fn mark_synthetic(role: &str, style: &str) { + synthetic().write().unwrap_or_else(|e| e.into_inner()).insert(format!("{role}|{style}")); +} + +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(()); @@ -473,6 +508,39 @@ 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)); + 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("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"))] diff --git a/crates/ui-egui/src/grid.rs b/crates/ui-egui/src/grid.rs index b485104b1d..ce5545b8c6 100644 --- a/crates/ui-egui/src/grid.rs +++ b/crates/ui-egui/src/grid.rs @@ -1242,6 +1242,9 @@ pub(crate) fn paint_quadrant( 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); + let bold_dx = if embolden { (size / 36.0).max(1.0 / p.ctx().pixels_per_point()) } 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; @@ -1268,7 +1271,7 @@ pub(crate) fn paint_quadrant( // 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.halign = match halign { HAlign::Center | HAlign::CenterAcross => egui::Align::Center, HAlign::Right => egui::Align::RIGHT, @@ -1281,7 +1284,7 @@ pub(crate) fn paint_quadrant( _ => text_left + pad + indent, }; let y = wrapped_cell_text_y(st.align.v, *rect, galley.size().y, z); - p.with_clip_rect(rect.intersect(p.clip_rect())).galley(pos2(x, y), galley, color); + paint_cell_galley(&p.with_clip_rect(rect.intersect(p.clip_rect())), pos2(x, y), galley, color, bold_dx); continue; } // Wrap Text off: Excel ignores the line breaks and draws the whole string on one line. @@ -1295,7 +1298,7 @@ pub(crate) fn paint_quadrant( .flatten(); let shrunk = small.is_some(); let font = small.unwrap_or(font); - let mut galley = p.layout_no_wrap(first_line.clone(), font.clone(), color); + let mut galley = p.layout_job(cell_job(first_line.clone(), font.clone(), color, f32::INFINITY, slant)); let mut w = galley.size().x; // Numbers and dates never overflow: they show #### when too narrow. let hashed = !shrunk && (numeric || matches!(v, Value::Number(_))) && w > avail_w - 2.0 * pad && st.align.h != HAlign::Fill; @@ -1303,7 +1306,7 @@ pub(crate) fn paint_quadrant( // Measured on `#` itself: it is wider than `0` in some fonts, and #### must fit its cell. let hash_w = p.layout_no_wrap("#".to_string(), font.clone(), color).size().x.max(1.0); let n = ((avail_w - 2.0 * pad) / hash_w).floor().max(1.0) as usize; - galley = p.layout_no_wrap("#".repeat(n), font.clone(), color); + galley = p.layout_job(cell_job("#".repeat(n), font.clone(), color, f32::INFINITY, slant)); w = galley.size().x; } // Repeat fill (`*` in number formats) / Fill alignment. A number already shown as #### keeps @@ -1319,7 +1322,7 @@ pub(crate) fn paint_quadrant( if first_line.is_char_boundary(pos) { s.insert_str(pos, &ch.to_string().repeat(n)); } - galley = p.layout_no_wrap(s, font.clone(), color); + galley = p.layout_job(cell_job(s, font.clone(), color, f32::INFINITY, slant)); w = galley.size().x; } // Center Across Selection: the text is centred over this cell and the empty cells to its right that also use it. @@ -1381,8 +1384,7 @@ pub(crate) fn paint_quadrant( 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 job = egui::text::LayoutJob::simple(text.clone(), font.clone(), color, (rect.height() - 2.0 * pad).max(4.0)); - p.layout_job(job) + p.layout_job(cell_job(text.clone(), font.clone(), color, (rect.height() - 2.0 * pad).max(4.0), slant)) } else { galley.clone() }; @@ -1391,7 +1393,7 @@ pub(crate) fn paint_quadrant( shape.angle = angle; cp.add(shape); } else { - cp.galley(pos2(x, y), galley.clone(), color); + paint_cell_galley(&cp, pos2(x, y), galley.clone(), color, bold_dx); } let baseline = y + gh * 0.82; match st.font.underline { @@ -1604,6 +1606,25 @@ fn merged_edges( 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`]). +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`]). +fn paint_cell_galley(p: &Painter, pos: Pos2, galley: std::sync::Arc, 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. fn shrink_font(p: &Painter, text: &str, font: &FontId, room: f32) -> Option { diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 5d5f1efeee..49c18d66bc 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-23 · **Change:** minor (New Formatting Rule's formula box takes references clicked or dragged on the grid, #2348; 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) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-24 · **Change:** minor (italic and bold in a font with one face, such as Arial Black, are slanted and thickened as Excel does; New Formatting Rule's formula box takes references clicked or dragged on the grid, #2348; 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) · **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 @@ -178,6 +178,7 @@ scrollbar bugs 2–4 · pixel/feel pass against observed Excel 7–12. | Date | Change | Summary | |---|---|---| +| 2026-10-24 | 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-23 | minor | Conditional Formatting ▸ New Rule, formula: clicking a cell on the grid writes its absolute reference at the formula box's caret (`=$B$2`, an empty box starts with `=`), a drag writes a range (`$B$2:$C$4`) and a second click replaces the reference just written, as in Excel ("Selecting cells on the worksheet inserts absolute cell references"). The selection the rule applies to doesn't move, and the box keeps the keyboard. After an operand (`=A1>5`) the click does nothing (#2348) | | 2026-10-23 | minor | Frozen panes: Page Up, Ctrl+Up and Shift variants that move from the scrolled rows into the frozen ones bring the scrolled rows back to the top, so the rows in between are seen again (Page Up from far down used to end on row 1 with the view still a page down); Ctrl+Left and Alt+Page Up do the same for frozen columns. Other ways of selecting a frozen cell (click, Find, Go To, Undo, formula pointing) leave the view where it is | | 2026-10-23 | minor | After a left-drag of the fill handle an Auto Fill Options button sits below the filled cells; its menu redoes the fill as Copy Cells, Fill Series, Fill Formatting Only or Fill Without Formatting (undoes the drag's fill, then `edit.autoFill` in that mode). It goes away when the workbook changes or the selection moves (#1403) | From c4ef580a22a5c276a76e94401085bef5b7a932db Mon Sep 17 00:00:00 2001 From: DerKarussellbremser <67138735+DerKarussellbremser@users.noreply.github.com> Date: Sat, 24 Oct 2026 14:41:41 +0200 Subject: [PATCH 2/7] Grid: imitate the styles of the face actually drawn; bold for shrunk and rotated text Review fixes. The slant and bold markers are now set from the face the role is drawn in (the first whose file could be read), so a family whose bold or italic file is missing gets them imitated too, and a later binding that no longer needs a marker removes it. The bold offset follows the size that is painted after Shrink to Fit, and rotated text gets its second impression along its own direction. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KKbbMZpkzQuncTpqAyhkp9 --- crates/ui-egui/src/fonts.rs | 33 ++++++++++++++++++++++----------- crates/ui-egui/src/grid.rs | 15 ++++++++++++--- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/crates/ui-egui/src/fonts.rs b/crates/ui-egui/src/fonts.rs index 11125a9b04..a785c65b2e 100644 --- a/crates/ui-egui/src/fonts.rs +++ b/crates/ui-egui/src/fonts.rs @@ -326,13 +326,9 @@ pub fn bind_faces(fonts: &mut egui::FontDefinitions, family: &str, faces: &[Face 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); - if italic && !primary.italic { - mark_synthetic(&role, SLANT); - } - if bold && pick_face(faces, false, italic).is_some_and(|plain| face_key(plain) == face_key(primary)) { - mark_synthetic(&role, BOLD); - } let mut chain: Vec = 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); @@ -346,10 +342,14 @@ 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()); fonts.families.insert(egui::FontFamily::Name(role.clone().into()), chain); bound.push(role); @@ -391,8 +391,14 @@ fn synthetic() -> &'static std::sync::RwLock> { SYNTHETIC.get_or_init(|| std::sync::RwLock::new(HashSet::new())) } -fn mark_synthetic(role: &str, style: &str) { - synthetic().write().unwrap_or_else(|e| e.into_inner()).insert(format!("{role}|{style}")); +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 { @@ -530,9 +536,14 @@ mod tests { 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)); diff --git a/crates/ui-egui/src/grid.rs b/crates/ui-egui/src/grid.rs index ce5545b8c6..7bf2b15b4b 100644 --- a/crates/ui-egui/src/grid.rs +++ b/crates/ui-egui/src/grid.rs @@ -1244,7 +1244,9 @@ pub(crate) fn paint_quadrant( 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); - let bold_dx = if embolden { (size / 36.0).max(1.0 / p.ctx().pixels_per_point()) } else { 0.0 }; + // 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; @@ -1284,7 +1286,7 @@ pub(crate) fn paint_quadrant( _ => text_left + pad + indent, }; let y = wrapped_cell_text_y(st.align.v, *rect, galley.size().y, z); - paint_cell_galley(&p.with_clip_rect(rect.intersect(p.clip_rect())), pos2(x, y), galley, color, bold_dx); + paint_cell_galley(&p.with_clip_rect(rect.intersect(p.clip_rect())), pos2(x, y), galley, color, bold_dx(size)); continue; } // Wrap Text off: Excel ignores the line breaks and draws the whole string on one line. @@ -1389,11 +1391,18 @@ pub(crate) fn paint_quadrant( galley.clone() }; let pos = rotated_text_pos(*rect, galley.size(), angle, painted_halign(st.align.h, geo.rtl), st.align.v, pad, indent); + // Imitated bold: the second impression along the text's own direction. + let d = bold_dx(font.size); + if d > 0.0 { + let mut thick = egui::epaint::TextShape::new(pos + d * 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); } else { - paint_cell_galley(&cp, pos2(x, y), galley.clone(), color, bold_dx); + paint_cell_galley(&cp, pos2(x, y), galley.clone(), color, bold_dx(font.size)); } let baseline = y + gh * 0.82; match st.font.underline { From 2a506bfc851c6f0821e84be7c7d5acdab5ce722a Mon Sep 17 00:00:00 2001 From: alehel Date: Wed, 11 Nov 2026 09:04:00 +0000 Subject: [PATCH 3/7] model::paper: one paper-size table for print layout and XLSX Paper names and sizes now live in one table, `gridcraft_model::paper` (`canonical`, `size_pt`, `for_size`). The engine's `known_paper` and the XLSX writer's alias list read it instead of keeping their own copies. - Page Setup and `pageLayout.size` store a known paper under its table name (`11x17` -> `Tabloid`, `b5-jis` -> `B5`), so every file format finds it. - XLSX paper id 34 (ECMA-376 "B5 envelope, 176 x 250 mm", the ISO B5 size) reads as `B5 (ISO)`; `B5 (ISO)` now saves with paperSize 34 instead of none. `Envelope B5` is still accepted as an alias. - Statement, Envelope #10 and Envelope DL print on their own size. - `PrintSettings::paper` documents an empty name as "the file stated no paper": layout falls back to Letter and XLSX writes no paperSize. New sheets still default to Letter. --- crates/engine/src/cmd/print.rs | 7 +- crates/engine/src/cmd/print/layout.rs | 39 +--------- crates/engine/src/cmd/print/tests.rs | 28 +++++++ crates/engine/src/cmd/view.rs | 4 +- crates/model/src/features/print.rs | 5 +- crates/model/src/lib.rs | 1 + crates/model/src/paper.rs | 108 ++++++++++++++++++++++++++ crates/xlsx/src/tables.rs | 26 ++----- crates/xlsx/src/tests/roundtrip.rs | 19 +++++ docs/architecture.md | 5 +- docs/file-format-parity.md | 3 +- 11 files changed, 181 insertions(+), 64 deletions(-) create mode 100644 crates/model/src/paper.rs diff --git a/crates/engine/src/cmd/print.rs b/crates/engine/src/cmd/print.rs index b3ce40d583..a76f45c5e8 100644 --- a/crates/engine/src/cmd/print.rs +++ b/crates/engine/src/cmd/print.rs @@ -39,7 +39,7 @@ type PicCache = std::collections::HashMap<(usize, usize), Option<(Vec, u32, use layout::bands; pub(crate) use layout::split_bands; pub use layout::{PrintOptions, SheetLayout, layout_sheet, layouts, paper_size, print_range}; -use layout::{known_paper, seg_size, segments}; +use layout::{seg_size, segments}; use objects::draw_objects; #[cfg(test)] use text::{center_across_width, wrap_lines}; @@ -258,8 +258,9 @@ fn page_setup(s: &mut Session, p: &Json) -> Result { let paper = match str_param(p, "paper") { None => None, Some(name) => { - known_paper(name).ok_or_else(|| bad(CMD, format!("unknown paper size `{name}`")))?; - Some(name.trim().to_string()) + // Stored under its table name, which every file format knows. + let paper = gridcraft_model::paper::canonical(name).ok_or_else(|| bad(CMD, format!("unknown paper size `{name}`")))?; + Some(paper.to_string()) } }; let margin_src = p.get("margins").filter(|m| m.is_object()).unwrap_or(p); diff --git a/crates/engine/src/cmd/print/layout.rs b/crates/engine/src/cmd/print/layout.rs index 0f484f8755..3c21ed1154 100644 --- a/crates/engine/src/cmd/print/layout.rs +++ b/crates/engine/src/cmd/print/layout.rs @@ -9,43 +9,10 @@ pub(super) const DENSE_BLOCK: u64 = 60_000; // ---------------------------------------------------------------- paper -/// Paper size in points (portrait) for a paper name; unknown names fall back to Letter. +/// Paper size in points, as named (see `gridcraft_model::paper`); unknown names, and the empty +/// name of a file that stated no paper, fall back to Letter. pub fn paper_size(name: &str) -> (f32, f32) { - known_paper(name).unwrap_or((612.0, 792.0)) -} - -/// Paper sizes in points, portrait. `B4`/`B5`/`B6` are the **JIS** sizes Japanese Excel and its -/// e-mail attachments use (257×364, 182×257 and 128×182 mm); the ISO B series stays reachable as -/// `B4 (ISO)`/`B5 (ISO)`/`B6 (ISO)`. The Japanese postcards and envelopes are the JIS ones too. -pub(super) fn known_paper(name: &str) -> Option<(f32, f32)> { - // Spaces, hyphens, underscores and parentheses don't matter: `B5 (JIS)`, `b5-jis` and `b5` - // are one name. - let n = name.trim().to_ascii_lowercase().replace([' ', '-', '_', '(', ')'], ""); - Some(match n.as_str() { - "letter" | "usletter" => (612.0, 792.0), - "legal" | "uslegal" => (612.0, 1008.0), - "a4" => (595.28, 841.89), - "a3" => (841.89, 1190.55), - "a5" => (419.53, 595.28), - "a6" => (297.64, 419.53), - "tabloid" | "11x17" => (792.0, 1224.0), - "ledger" => (1224.0, 792.0), - "executive" => (522.0, 756.0), - "b4" | "b4jis" => (728.50, 1031.81), - "b5" | "b5jis" => (515.91, 728.50), - "b6" | "b6jis" => (362.83, 515.91), - "b4iso" => (708.66, 1000.63), - "b5iso" => (498.90, 708.66), - "b6iso" => (354.33, 498.90), - "japanesepostcard" | "postcard" => (283.46, 419.53), - "japanesedoublepostcard" | "doublepostcard" => (419.53, 566.93), - "japaneseenvelope#3" | "chou#3" => (340.16, 666.14), - // 長形4号 is 90×205 mm; 90×225 mm is 長形40号, a different envelope, so it stays out. - "japaneseenvelope#4" | "chou#4" => (255.12, 581.10), - "japaneseenvelopekaku#2" | "kaku#2" => (680.31, 941.10), - "japaneseenvelopekaku#3" | "kaku#3" => (612.28, 785.20), - _ => return None, - }) + gridcraft_model::paper::size_pt(name).unwrap_or((612.0, 792.0)) } // ---------------------------------------------------------------- layout diff --git a/crates/engine/src/cmd/print/tests.rs b/crates/engine/src/cmd/print/tests.rs index 3230604702..ee22e14e20 100644 --- a/crates/engine/src/cmd/print/tests.rs +++ b/crates/engine/src/cmd/print/tests.rs @@ -631,6 +631,34 @@ fn page_setup_paper_sizes_reach_the_pdf_page() { assert!(s.execute("pageLayout.pageSetup", json!({"paper": "Napkin"})).is_err()); } +/// An empty paper name means the file stated none; it prints on Letter. +#[test] +fn an_unstated_paper_prints_on_letter() { + let mut wb = gridcraft_model::Workbook::new(); + std::sync::Arc::make_mut(&mut wb.sheets[0]).set_value(CellRef::new(0, 0), gridcraft_core::Value::Text("x".into())); + std::sync::Arc::make_mut(&mut wb.sheets[0]).print.paper = String::new(); + let layouts = super::layout::layouts(&wb, &super::layout::PrintOptions::default()); + let l = &layouts[0]; + assert_eq!((l.page_w, l.page_h), (612.0, 792.0)); + assert_eq!(paper_size(""), (612.0, 792.0)); +} + +/// Both commands that set the paper store a known one under its table name, so every file +/// format finds it. +#[test] +fn paper_size_commands_store_the_table_name() { + let mut s = s(); + s.execute("pageLayout.size", json!({"paper": "b5-jis"})).unwrap(); + assert_eq!(s.doc().unwrap().wb.sheets[0].print.paper, "B5"); + s.execute("pageLayout.pageSetup", json!({"paper": "11x17"})).unwrap(); + assert_eq!(s.doc().unwrap().wb.sheets[0].print.paper, "Tabloid"); + // Statement and the envelopes Excel names now print on their own size. + s.execute("pageLayout.pageSetup", json!({"paper": "Envelope DL"})).unwrap(); + assert_eq!(paper_size("Statement"), (396.0, 612.0)); + // A new workbook still prints on Letter. + assert_eq!(gridcraft_model::Workbook::new().sheets[0].print.paper, "Letter"); +} + #[test] fn hostile_settings_never_panic_and_cap_pages() { let mut s = s(); diff --git a/crates/engine/src/cmd/view.rs b/crates/engine/src/cmd/view.rs index 3631d0e561..d6d56b0509 100644 --- a/crates/engine/src/cmd/view.rs +++ b/crates/engine/src/cmd/view.rs @@ -296,7 +296,9 @@ fn orientation(s: &mut Session, p: &Json) -> Result { } fn paper(s: &mut Session, p: &Json) -> Result { - let paper = str_param(p, "paper").unwrap_or("Letter").to_string(); + // A known paper is stored under its table name; any other name is kept (it prints on Letter). + let name = str_param(p, "paper").unwrap_or("Letter"); + let paper = gridcraft_model::paper::canonical(name).unwrap_or(name).to_string(); edit(s, |cx| { let si = cx.sheet_index(); cx.sheet_mut(si)?.print.paper = paper.clone(); diff --git a/crates/model/src/features/print.rs b/crates/model/src/features/print.rs index 694c2ac6da..049ac454d0 100644 --- a/crates/model/src/features/print.rs +++ b/crates/model/src/features/print.rs @@ -11,7 +11,10 @@ pub enum Orientation { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct PrintSettings { pub orientation: Orientation, - /// Paper size name (`Letter`, `A4`, `Legal`…). + /// Paper size name (`Letter`, `A4`, `Legal`…; see [`crate::paper`]), or empty when the file + /// stated none: the printer's or locale's paper then, which an ODF file leaves to the + /// application. Print layout falls back to Letter and XLSX writes no `paperSize`. New sheets + /// default to Letter. pub paper: String, /// Margins in inches: left, right, top, bottom, header, footer. pub margins: [f32; 6], diff --git a/crates/model/src/lib.rs b/crates/model/src/lib.rs index 35cfa315f8..65f2e819c7 100644 --- a/crates/model/src/lib.rs +++ b/crates/model/src/lib.rs @@ -9,6 +9,7 @@ pub mod cell; mod cellmap; pub mod features; pub mod macros; +pub mod paper; pub mod password; pub mod preserved; pub mod python; diff --git a/crates/model/src/paper.rs b/crates/model/src/paper.rs new file mode 100644 index 0000000000..b3068e6aab --- /dev/null +++ b/crates/model/src/paper.rs @@ -0,0 +1,108 @@ +//! Paper sizes by name: the names `PrintSettings::paper` holds, with their sizes. File formats +//! (XLSX paper ids, ODF page sizes) and print layout all read this one table. + +/// Paper names and sizes in points, width then height, as the paper is named: Ledger is +/// Tabloid turned on its side. Each size has one name, so a size reads back as the name it was +/// saved under. `B4`/`B5`/`B6` are the **JIS** sizes Japanese Excel uses (257×364, 182×257 and +/// 128×182 mm); the ISO B series is `B4 (ISO)`/`B5 (ISO)`/`B6 (ISO)`. The Japanese postcards and +/// envelopes are the JIS ones too. +pub const PAPERS: [(&str, f32, f32); 24] = [ + ("Letter", 612.0, 792.0), + ("Legal", 612.0, 1008.0), + ("A4", 595.28, 841.89), + ("A3", 841.89, 1190.55), + ("A5", 419.53, 595.28), + ("A6", 297.64, 419.53), + ("Tabloid", 792.0, 1224.0), + ("Ledger", 1224.0, 792.0), + ("Executive", 522.0, 756.0), + ("Statement", 396.0, 612.0), + ("B4", 728.50, 1031.81), + ("B5", 515.91, 728.50), + ("B6", 362.83, 515.91), + ("B4 (ISO)", 708.66, 1000.63), + ("B5 (ISO)", 498.90, 708.66), + ("B6 (ISO)", 354.33, 498.90), + ("Envelope #10", 297.0, 684.0), + ("Envelope DL", 311.81, 623.62), + ("Japanese Postcard", 283.46, 419.53), + ("Japanese Double Postcard", 419.53, 566.93), + ("Japanese Envelope #3", 340.16, 666.14), + // 長形4号 is 90×205 mm; 90×225 mm is 長形40号, a different envelope, so it stays out. + ("Japanese Envelope #4", 255.12, 581.10), + ("Japanese Envelope Kaku #2", 680.31, 941.10), + ("Japanese Envelope Kaku #3", 612.28, 785.20), +]; + +/// Other spellings of the names above, in [`key`] form. +const ALIASES: [(&str, &str); 13] = [ + // The B5 envelope is ISO B5 itself (176×250 mm): one size, one name. + ("envelopeb5", "B5 (ISO)"), + ("usletter", "Letter"), + ("uslegal", "Legal"), + ("11x17", "Tabloid"), + ("b4jis", "B4"), + ("b5jis", "B5"), + ("b6jis", "B6"), + ("postcard", "Japanese Postcard"), + ("doublepostcard", "Japanese Double Postcard"), + ("chou#3", "Japanese Envelope #3"), + ("chou#4", "Japanese Envelope #4"), + ("kaku#2", "Japanese Envelope Kaku #2"), + ("kaku#3", "Japanese Envelope Kaku #3"), +]; + +/// A name as compared: spaces, hyphens, underscores and parentheses don't matter, nor does case +/// (`B5 (JIS)`, `b5-jis` and `b5jis` are one name). +fn key(name: &str) -> String { + name.trim().to_ascii_lowercase().replace([' ', '-', '_', '(', ')'], "") +} + +/// The paper `name` stands for, under its table name. +pub fn canonical(name: &str) -> Option<&'static str> { + // No paper name is long; a huge one (from a file or a command) is not worth folding. + if name.len() > 64 { + return None; + } + let k = key(name); + PAPERS.iter().map(|(n, _, _)| *n).find(|n| key(n) == k).or_else(|| ALIASES.iter().find(|(a, _)| *a == k).map(|(_, n)| *n)) +} + +/// The size of paper `name` in points (width, height). +pub fn size_pt(name: &str) -> Option<(f32, f32)> { + let n = canonical(name)?; + PAPERS.iter().find(|(p, _, _)| *p == n).map(|(_, w, h)| (*w, *h)) +} + +/// The paper of a page `width` × `height` points, within 2 mm: as it stands, else turned. +pub fn for_size(width: f32, height: f32) -> Option<&'static str> { + let near = |a: f32, b: f32| (a - b).abs() < 5.67; + let find = |w: f32, h: f32| PAPERS.iter().find(|(_, pw, ph)| near(*pw, w) && near(*ph, h)).map(|(n, _, _)| *n); + find(width, height).or_else(|| find(height, width)) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn names_and_sizes() { + assert_eq!(size_pt("b5-jis"), Some((515.91, 728.50))); + assert_eq!(size_pt("US Letter"), Some((612.0, 792.0))); + assert_eq!(size_pt("nonsense"), None); + assert_eq!(for_size(1224.0, 792.0), Some("Ledger")); + assert_eq!(for_size(792.0, 1224.0), Some("Tabloid")); + assert_eq!(for_size(842.0, 595.0), Some("A4")); + assert_eq!(canonical("ledger"), Some("Ledger")); + assert_eq!(canonical(""), None); + assert_eq!(canonical(&"A4".repeat(1000)), None); + } + + #[test] + fn every_size_reads_back_as_its_name() { + for (name, w, h) in PAPERS { + assert_eq!(for_size(w, h), Some(name), "{name}"); + } + assert_eq!(canonical("Envelope B5"), Some("B5 (ISO)")); + } +} diff --git a/crates/xlsx/src/tables.rs b/crates/xlsx/src/tables.rs index 3cfd84c2dc..2ad41e9d4f 100644 --- a/crates/xlsx/src/tables.rs +++ b/crates/xlsx/src/tables.rs @@ -57,7 +57,8 @@ pub use gridcraft_core::color::INDEXED; /// Paper sizes (`pageSetup paperSize`) we name. ID 12/13 are the JIS B4/B5 that /// `pageLayout.pageSetup` calls `B4`/`B5`; 42 is ISO B4, and 43–88 are the Japanese postcards, -/// envelopes and B6. The engine's `known_paper` uses the same names and sizes. +/// envelopes and B6. Their sizes are in `gridcraft_model::paper`, under the same names. 34 is +/// ECMA-376's "B5 envelope (176 mm by 250 mm)": the ISO B5 size, so it reads as `B5 (ISO)`. const PAPERS: [(u32, &str); 23] = [ (1, "Letter"), (3, "Tabloid"), @@ -72,7 +73,7 @@ const PAPERS: [(u32, &str); 23] = [ (13, "B5"), (20, "Envelope #10"), (27, "Envelope DL"), - (34, "Envelope B5"), + (34, "B5 (ISO)"), (42, "B4 (ISO)"), (43, "Japanese Postcard"), (69, "Japanese Double Postcard"), @@ -88,25 +89,10 @@ pub fn paper_name(id: u32) -> Option<&'static str> { PAPERS.iter().find(|(i, _)| *i == id).map(|(_, n)| *n) } -/// The file ID for a paper name. Spelling is loose like `known_paper`'s — spaces, hyphens, -/// underscores and parentheses don't matter, and the JIS/ISO and Japanese-envelope spellings the -/// page-setup commands take are folded onto the name in [`PAPERS`]. +/// The file ID for a paper name, spelled any way [`gridcraft_model::paper::canonical`] takes. pub fn paper_id(name: &str) -> Option { - let norm = |s: &str| s.trim().to_ascii_lowercase().replace([' ', '-', '_', '(', ')'], ""); - let normalized = norm(name); - let alias = match normalized.as_str() { - "b4jis" => "b4", - "b5jis" => "b5", - "b6jis" => "b6", - "postcard" => "japanesepostcard", - "doublepostcard" => "japanesedoublepostcard", - "chou#3" => "japaneseenvelope#3", - "chou#4" => "japaneseenvelope#4", - "kaku#2" => "japaneseenvelopekaku#2", - "kaku#3" => "japaneseenvelopekaku#3", - other => other, - }; - PAPERS.iter().find(|(_, n)| norm(n) == alias).map(|(i, _)| *i) + let name = gridcraft_model::paper::canonical(name)?; + PAPERS.iter().find(|(_, n)| *n == name).map(|(i, _)| *i) } /// Functions introduced after Excel 2007 that files store with the `_xlfn.` prefix. Entries with diff --git a/crates/xlsx/src/tests/roundtrip.rs b/crates/xlsx/src/tests/roundtrip.rs index 4eb6c3cfe2..4bcb39a041 100644 --- a/crates/xlsx/src/tests/roundtrip.rs +++ b/crates/xlsx/src/tests/roundtrip.rs @@ -1421,6 +1421,25 @@ fn japanese_paper_sizes_round_trip() { assert_eq!(back.sheet(0).unwrap().print.paper, "B5"); } +/// The paper names every spelling folds onto keep their file id: `11x17` is Tabloid (3), and +/// ISO B5 is id 34 (ECMA-376's 176×250 mm "B5 envelope"), read back as `B5 (ISO)`. An empty +/// paper (the file stated none) writes no `paperSize`, so the reader's own paper applies. +#[test] +fn paper_names_keep_their_xlsx_id_and_an_unstated_paper_writes_none() { + for (paper, id, back_as) in [("11x17", 3, "Tabloid"), ("US Legal", 5, "Legal"), ("B5 (ISO)", 34, "B5 (ISO)"), ("Envelope B5", 34, "B5 (ISO)")] { + let mut wb = Workbook::new(); + wb.sheet_mut(0).unwrap().print.paper = paper.into(); + let bytes = write_xlsx(&wb).unwrap(); + assert!(sheet1_xml(&bytes).0.contains(&format!("paperSize=\"{id}\"")), "{paper}"); + let (back, _) = read_xlsx(&bytes).unwrap(); + assert_eq!(back.sheet(0).unwrap().print.paper, back_as); + } + let mut wb = Workbook::new(); + wb.sheet_mut(0).unwrap().print.paper = String::new(); + let (xml, _) = sheet1_xml(&write_xlsx(&wb).unwrap()); + assert!(!xml.contains("paperSize"), "{xml}"); +} + /// A table's dropdown filter lives in `sheet.autofilter` (the engine's only live filter state), /// not in `Table::filter`. Writing used to suppress the sheet `` because a table /// intersects it and write the table part from `Table::filter`, which was empty: the criteria diff --git a/docs/architecture.md b/docs/architecture.md index 68639541ea..df3e2ac134 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -1,6 +1,6 @@ # Architecture -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-02 · **Change:** minor (Python mode in the formula bar; earlier: Python cells as data; earlier: equations: the `math` crate and the layout cache; earlier: recently used functions kept in the preferences; Function Library module; accent icons; earlier: the hidden names that hold macros) · **Target:** Microsoft Excel (Microsoft 365) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-11 · **Change:** minor (paper names and sizes in one table, `model::paper`; earlier: Python mode in the formula bar; earlier: Python cells as data; earlier: equations: the `math` crate and the layout cache; earlier: recently used functions kept in the preferences; Function Library module; accent icons; earlier: the hidden names that hold macros) · **Target:** Microsoft Excel (Microsoft 365) How GridCraft is built today. Rules for contributors are in [`AGENTS.md`](../AGENTS.md). @@ -17,7 +17,7 @@ including tests, 2026-10-10. | L1 | `formula` | ~1.7k | Tokenizer, parser, AST, printer (A1 and R1C1), reference adjustment for copy, fill and structural edits | | L1 | `functions` | ~13.4k | The function library: `FnSpec` registry (name, arity, category, scalar args, signature, description) and pure implementations; automatic array lifting | | L1 | `math` | ~1.1k | Equations: LaTeX laid out by RaTeX (MIT, pinned) into plain glyph, rule and path data, and LaTeX to Office Math; every entry point capped and panic-guarded | -| L2 | `model` | ~2.2k | Workbook, sheets, copy-on-write cell store (64-row bands behind `Arc`), interned styles, names, tables, CF, validation, comments, charts, shapes, images, sparklines, print settings, protection | +| L2 | `model` | ~2.2k | Workbook, sheets, copy-on-write cell store (64-row bands behind `Arc`), interned styles, names, tables, CF, validation, comments, charts, shapes, images, sparklines, print settings (paper names and sizes in `paper`, the one table file formats and print layout read), protection | | L2 | `calc` | ~2.9k | Evaluator (references, names, tables, LET/LAMBDA, special forms like OFFSET/INDIRECT/SUBTOTAL) and dependency-graph recalculation with dynamic arrays, spills and cycle detection; single-threaded | | L2 | `xlsx` | ~10.7k | XLSX read/write (transitional and strict read), CSV/TSV, XLSB and ODS data import, PivotTable caches, DrawingML charts and drawings; byte slices only (WASM-safe); lenient reader that reports warnings | | L2 | `pdf` | ~1k | Small PDF 1.7 writer (14 standard fonts, vectors, images) for print and export | @@ -236,6 +236,7 @@ rpm, tarball), FreeBSD, and web (WASM; WebGPU or WebGL2). Release workflows in | Date | Change | Summary | |---|---|---| +| 2026-11-11 | minor | Paper sizes: `model::paper` (`canonical`, `size_pt`, `for_size`) replaces the engine's `known_paper` and the XLSX alias list; an empty `PrintSettings::paper` means the file stated none | | 2026-11-02 | minor | Python mode in the formula bar: Python mode on the shared editor, `code_field` and its stop keys; drafts follow their sheet by `model::SheetUid` | | 2026-11-02 | minor | Python cells as data: `model::PyCode`, the file forms, calc laying out kept results, the limits on open, and what copying, filling and sorting do to `xl()` references; edits that would push code past the limit are refused | | 2026-11-01 | trivial | Equations: the layout cache answers for a source over the cap by its length alone, without hashing it | diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index d2660dde02..981ddd3fa5 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -1,6 +1,6 @@ # File-format parity -> **Last reviewed:** 2026-11-01 · **Last updated:** 2026-11-03 · **Change:** minor (a web page's first table opens as a sheet, also when the page is named `.xls`; earlier: `workbookPr filterPrivacy` kept, and honoured on save; earlier: a workbook's R1C1 reference style, `calcPr refMode`, is kept through open and save; earlier: XLSX page margins are written as their decimals, `0.3` rather than `0.30000001192092896`; earlier: Python cells in `.xlsx` as [MS-XLSX] specifies, `_xlfn._xlws.PY(…)` naming code in the Python part, with cached values, and in GridCraft JSON, with limits on open; earlier: equations in xlsx as Office Math with a marker in `descr` so an edit made in Excel reads back, read back only up to the equation source cap, and a brace with a label and a script on its other side keeps both; Symbol font in PDF; earlier: XLSX reads and writes Page Setup's page order, `pageSetup pageOrder`, and PDF export follows it; earlier: chart data tables: native c:dTable import/export; earlier: XLSX workbook-view selection, normalized tab ratios and sheet-edit regressions; fidelity estimates unchanged; earlier: formulas from Google Sheets' XLSX export open as the original formula instead of `IFERROR(__xludf.DUMMYFUNCTION(…),…)` when GridCraft calculates every function in it, and save as it; `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; earlier: `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; CSV and text open detects each column's date order from values that read only one way, warns when every date is ambiguous, and keeps a column with both kinds as text (#2765)) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 +> **Last reviewed:** 2026-11-01 · **Last updated:** 2026-11-11 · **Change:** minor (one paper table, `model::paper`, for XLSX paper ids and print layout: `11x17`, `US Legal` and the other spellings keep their `paperSize`, XLSX id 34 (ECMA-376's 176×250 mm B5 envelope) reads as `B5 (ISO)`, and an empty paper name, a file that stated none, writes no `paperSize`; earlier: a web page's first table opens as a sheet, also when the page is named `.xls`; earlier: `workbookPr filterPrivacy` kept, and honoured on save; earlier: a workbook's R1C1 reference style, `calcPr refMode`, is kept through open and save; earlier: XLSX page margins are written as their decimals, `0.3` rather than `0.30000001192092896`; earlier: Python cells in `.xlsx` as [MS-XLSX] specifies, `_xlfn._xlws.PY(…)` naming code in the Python part, with cached values, and in GridCraft JSON, with limits on open; earlier: equations in xlsx as Office Math with a marker in `descr` so an edit made in Excel reads back, read back only up to the equation source cap, and a brace with a label and a script on its other side keeps both; Symbol font in PDF; earlier: XLSX reads and writes Page Setup's page order, `pageSetup pageOrder`, and PDF export follows it; earlier: chart data tables: native c:dTable import/export; earlier: XLSX workbook-view selection, normalized tab ratios and sheet-edit regressions; fidelity estimates unchanged; earlier: formulas from Google Sheets' XLSX export open as the original formula instead of `IFERROR(__xludf.DUMMYFUNCTION(…),…)` when GridCraft calculates every function in it, and save as it; `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; earlier: `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; CSV and text open detects each column's date order from values that read only one way, warns when every date is ambiguous, and keeps a column with both kinds as text (#2765)) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 Every format Excel opens or saves, with GridCraft's read and write support, fidelity and tests. Part of [target-app-parity.md](target-app-parity.md). **File formats: ~50% ready, 80–120 h** @@ -158,6 +158,7 @@ refresh. Counted under features (Get & Transform, ~10% ready), not here. | Date | Change | Summary | |---|---|---| +| 2026-11-11 | minor | One paper table (`model::paper`) behind XLSX `paperSize` and print layout; id 34 reads as `B5 (ISO)`, the ISO B5 size; `B5 (ISO)` and every alias save with their id; an empty paper writes no `paperSize` | | 2026-11-03 | minor | SYLK (`.slk`) import: values, R1C1 formulas as A1 (shared formulas too) with cached results, number formats and column widths; import only (#1481) | | 2026-11-03 | minor | Opening a web page (HTML) reads its first table as a sheet, whatever the file is called: a web app's "Export to Excel" saved as `.xls` no longer opens as lines of markup. Values read as in a CSV (or as text with `csvAsText`), `` cells are bold and centred, `` names the sheet, and a page not named `.htm`/`.html` opens with a warning (#3166) | | 2026-11-03 | minor | XLSX `` (Remove personal information from file properties on save) is read and written back, and while it is on GridCraft saves no author (`dc:creator`) and no company, as Excel leaves them empty (#3089, file part) | From f21dc313dbe38bbf5b6530563501f98362c5de67 Mon Sep 17 00:00:00 2001 From: alehel Date: Wed, 11 Nov 2026 10:28:45 +0000 Subject: [PATCH 4/7] model::paper: nearest-size match, new papers documented and tested - for_size picks the nearest paper within 2 mm (as it stands, else turned) instead of the first in table order: Letter and Japanese Envelope Kaku #3 are less than 4 mm apart. - Page Setup and Size list Statement, Envelope #10 and Envelope DL in their params docs; a test checks both commands store and print them. - Paper docs are format-neutral. --- crates/engine/src/cmd/print.rs | 2 +- crates/engine/src/cmd/print/tests.rs | 20 +++++++++++++--- crates/engine/src/cmd/view.rs | 2 +- crates/model/src/features/print.rs | 5 ++-- crates/model/src/paper.rs | 35 ++++++++++++++++++++++++---- docs/architecture.md | 2 +- docs/file-format-parity.md | 4 ++-- 7 files changed, 54 insertions(+), 16 deletions(-) diff --git a/crates/engine/src/cmd/print.rs b/crates/engine/src/cmd/print.rs index a76f45c5e8..6e3d888e45 100644 --- a/crates/engine/src/cmd/print.rs +++ b/crates/engine/src/cmd/print.rs @@ -78,7 +78,7 @@ pub fn specs() -> Vec { "Page Setup…", ["Page Layout", "Page Setup"], None, - "{sheet?, orientation?: portrait|landscape, paper?: Letter|Legal|A4|A3|A5|A6|Tabloid|Executive|Ledger|B4|B5|B6|B4 (ISO)|B5 (ISO)|B6 (ISO)|Japanese Postcard|Japanese Double Postcard|Japanese Envelope #3|Japanese Envelope #4|Japanese Envelope Kaku #2|Japanese Envelope Kaku #3 (B4/B5/B6 are the JIS sizes), margins?: {left,right,top,bottom,header,footer} (inches; also accepted as top-level keys), scale?: 10..400, fitWidth?, fitHeight? (pages; 0 = automatic), fitToPage?: bool, centerH?, centerV?, gridlines?, headings?, header?: \"&L&A&RPage &P of &N\", footer?, printArea?: \"A1:F50\" (\"\" clears), titleRows?: \"1:2\", titleCols?: \"A:A\", rowBreaks?: [46, 91], colBreaks?: [\"K\"], pageOrder?: downThenOver|overThenDown} → the sheet's print settings", + "{sheet?, orientation?: portrait|landscape, paper?: Letter|Legal|A4|A3|A5|A6|Tabloid|Executive|Ledger|B4|B5|B6|B4 (ISO)|B5 (ISO)|B6 (ISO)|Japanese Postcard|Japanese Double Postcard|Japanese Envelope #3|Japanese Envelope #4|Japanese Envelope Kaku #2|Japanese Envelope Kaku #3|Statement|Envelope #10|Envelope DL (B4/B5/B6 are the JIS sizes), margins?: {left,right,top,bottom,header,footer} (inches; also accepted as top-level keys), scale?: 10..400, fitWidth?, fitHeight? (pages; 0 = automatic), fitToPage?: bool, centerH?, centerV?, gridlines?, headings?, header?: \"&L&A&RPage &P of &N\", footer?, printArea?: \"A1:F50\" (\"\" clears), titleRows?: \"1:2\", titleCols?: \"A:A\", rowBreaks?: [46, 91], colBreaks?: [\"K\"], pageOrder?: downThenOver|overThenDown} → the sheet's print settings", has_doc, page_setup ), diff --git a/crates/engine/src/cmd/print/tests.rs b/crates/engine/src/cmd/print/tests.rs index ee22e14e20..6457002d1b 100644 --- a/crates/engine/src/cmd/print/tests.rs +++ b/crates/engine/src/cmd/print/tests.rs @@ -652,9 +652,23 @@ fn paper_size_commands_store_the_table_name() { assert_eq!(s.doc().unwrap().wb.sheets[0].print.paper, "B5"); s.execute("pageLayout.pageSetup", json!({"paper": "11x17"})).unwrap(); assert_eq!(s.doc().unwrap().wb.sheets[0].print.paper, "Tabloid"); - // Statement and the envelopes Excel names now print on their own size. - s.execute("pageLayout.pageSetup", json!({"paper": "Envelope DL"})).unwrap(); - assert_eq!(paper_size("Statement"), (396.0, 612.0)); + // Statement and the envelopes XLSX names are accepted by both commands (Page Setup refused + // them before), stored under their table name and printed on their own size. + s.execute("range.setValues", json!({"range": "A1", "values": [["x"]]})).unwrap(); + let close = |v: &Json, want: f64| (v.as_f64().unwrap() - want).abs() < 0.01; + for (cmd, given, stored, w, h) in [ + ("pageLayout.pageSetup", "statement", "Statement", 396.0, 612.0), + ("pageLayout.pageSetup", "envelope #10", "Envelope #10", 297.0, 684.0), + ("pageLayout.pageSetup", "Envelope-DL", "Envelope DL", 311.81, 623.62), + ("pageLayout.size", "Statement", "Statement", 396.0, 612.0), + ("pageLayout.size", "envelope dl", "Envelope DL", 311.81, 623.62), + ] { + s.execute(cmd, json!({"paper": given})).unwrap(); + assert_eq!(s.doc().unwrap().wb.sheets[0].print.paper, stored, "{cmd} {given}"); + let pv = s.execute("file.printPreview", json!({})).unwrap(); + let page = &pv["pageList"][0]; + assert!(close(&page["width"], w) && close(&page["height"], h), "{cmd} {given}: {page}"); + } // A new workbook still prints on Letter. assert_eq!(gridcraft_model::Workbook::new().sheets[0].print.paper, "Letter"); } diff --git a/crates/engine/src/cmd/view.rs b/crates/engine/src/cmd/view.rs index d6d56b0509..b01c8b71a8 100644 --- a/crates/engine/src/cmd/view.rs +++ b/crates/engine/src/cmd/view.rs @@ -84,7 +84,7 @@ pub fn specs() -> Vec { "Size", ["Page Layout", "Page Setup"], None, - "{paper: Letter|Legal|A4|A3|A5|A6|Tabloid|Executive|Ledger|B4|B5|B6|B4 (ISO)|B5 (ISO)|B6 (ISO)|Japanese Postcard|Japanese Double Postcard|Japanese Envelope #3|Japanese Envelope #4|Japanese Envelope Kaku #2|Japanese Envelope Kaku #3 (B4/B5/B6 are the JIS sizes)}", + "{paper: Letter|Legal|A4|A3|A5|A6|Tabloid|Executive|Ledger|B4|B5|B6|B4 (ISO)|B5 (ISO)|B6 (ISO)|Japanese Postcard|Japanese Double Postcard|Japanese Envelope #3|Japanese Envelope #4|Japanese Envelope Kaku #2|Japanese Envelope Kaku #3|Statement|Envelope #10|Envelope DL (B4/B5/B6 are the JIS sizes)}", has_doc, paper ), diff --git a/crates/model/src/features/print.rs b/crates/model/src/features/print.rs index 049ac454d0..833588c734 100644 --- a/crates/model/src/features/print.rs +++ b/crates/model/src/features/print.rs @@ -12,9 +12,8 @@ pub enum Orientation { pub struct PrintSettings { pub orientation: Orientation, /// Paper size name (`Letter`, `A4`, `Legal`…; see [`crate::paper`]), or empty when the file - /// stated none: the printer's or locale's paper then, which an ODF file leaves to the - /// application. Print layout falls back to Letter and XLSX writes no `paperSize`. New sheets - /// default to Letter. + /// stated none: the printer's or locale's paper then. Print layout falls back to Letter and + /// XLSX writes no `paperSize`. New sheets default to Letter. pub paper: String, /// Margins in inches: left, right, top, bottom, header, footer. pub margins: [f32; 6], diff --git a/crates/model/src/paper.rs b/crates/model/src/paper.rs index b3068e6aab..546c1d2577 100644 --- a/crates/model/src/paper.rs +++ b/crates/model/src/paper.rs @@ -1,5 +1,5 @@ //! Paper sizes by name: the names `PrintSettings::paper` holds, with their sizes. File formats -//! (XLSX paper ids, ODF page sizes) and print layout all read this one table. +//! (paper ids or page sizes) and print layout all read this one table. /// Paper names and sizes in points, width then height, as the paper is named: Ledger is /// Tabloid turned on its side. Each size has one name, so a size reads back as the name it was @@ -74,11 +74,22 @@ pub fn size_pt(name: &str) -> Option<(f32, f32)> { PAPERS.iter().find(|(p, _, _)| *p == n).map(|(_, w, h)| (*w, *h)) } -/// The paper of a page `width` × `height` points, within 2 mm: as it stands, else turned. +/// The paper of a page `width` × `height` points, within 2 mm on each side: the nearest one as it +/// stands, else the nearest one turned. Some papers are less than 4 mm apart (Letter and Japanese +/// Envelope Kaku #3), so the nearest wins, not the first in the table. pub fn for_size(width: f32, height: f32) -> Option<&'static str> { - let near = |a: f32, b: f32| (a - b).abs() < 5.67; - let find = |w: f32, h: f32| PAPERS.iter().find(|(_, pw, ph)| near(*pw, w) && near(*ph, h)).map(|(n, _, _)| *n); - find(width, height).or_else(|| find(height, width)) + const TOLERANCE: f32 = 5.67; // 2 mm + let nearest = |w: f32, h: f32| { + PAPERS + .iter() + .filter_map(|(n, pw, ph)| { + let (dw, dh) = ((pw - w).abs(), (ph - h).abs()); + (dw < TOLERANCE && dh < TOLERANCE).then_some((dw + dh, *n)) + }) + .min_by(|a, b| a.0.total_cmp(&b.0)) + .map(|(_, n)| n) + }; + nearest(width, height).or_else(|| nearest(height, width)) } #[cfg(test)] @@ -105,4 +116,18 @@ mod tests { } assert_eq!(canonical("Envelope B5"), Some("B5 (ISO)")); } + + /// Letter (612×792) and Japanese Envelope Kaku #3 (612.28×785.2) are within 2 mm of some + /// of the same sizes: the nearer paper wins, whichever comes first in the table. + #[test] + fn for_size_picks_the_nearest_paper() { + assert_eq!(for_size(612.2, 788.0), Some("Japanese Envelope Kaku #3")); + assert_eq!(for_size(612.0, 790.0), Some("Letter")); + assert_eq!(for_size(788.0, 612.2), Some("Japanese Envelope Kaku #3")); + // A wide page that is a paper as it stands is not read as another paper turned. + assert_eq!(for_size(1224.0, 792.0), Some("Ledger")); + assert_eq!(for_size(1000.0, 10.0), None); + assert_eq!(for_size(f32::NAN, 792.0), None); + assert_eq!(for_size(f32::INFINITY, f32::INFINITY), None); + } } diff --git a/docs/architecture.md b/docs/architecture.md index df3e2ac134..236b72238d 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -236,7 +236,7 @@ rpm, tarball), FreeBSD, and web (WASM; WebGPU or WebGL2). Release workflows in | Date | Change | Summary | |---|---|---| -| 2026-11-11 | minor | Paper sizes: `model::paper` (`canonical`, `size_pt`, `for_size`) replaces the engine's `known_paper` and the XLSX alias list; an empty `PrintSettings::paper` means the file stated none | +| 2026-11-11 | minor | Paper sizes: `model::paper` (`canonical`, `size_pt`, `for_size`) replaces the engine's `known_paper` and the XLSX alias list; an empty `PrintSettings::paper` means the file stated none; `for_size` picks the nearest paper; Statement, Envelope #10 and Envelope DL are accepted by Page Setup and Size | | 2026-11-02 | minor | Python mode in the formula bar: Python mode on the shared editor, `code_field` and its stop keys; drafts follow their sheet by `model::SheetUid` | | 2026-11-02 | minor | Python cells as data: `model::PyCode`, the file forms, calc laying out kept results, the limits on open, and what copying, filling and sorting do to `xl()` references; edits that would push code past the limit are refused | | 2026-11-01 | trivial | Equations: the layout cache answers for a source over the cap by its length alone, without hashing it | diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index 981ddd3fa5..c3d87732fc 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -1,6 +1,6 @@ # File-format parity -> **Last reviewed:** 2026-11-01 · **Last updated:** 2026-11-11 · **Change:** minor (one paper table, `model::paper`, for XLSX paper ids and print layout: `11x17`, `US Legal` and the other spellings keep their `paperSize`, XLSX id 34 (ECMA-376's 176×250 mm B5 envelope) reads as `B5 (ISO)`, and an empty paper name, a file that stated none, writes no `paperSize`; earlier: a web page's first table opens as a sheet, also when the page is named `.xls`; earlier: `workbookPr filterPrivacy` kept, and honoured on save; earlier: a workbook's R1C1 reference style, `calcPr refMode`, is kept through open and save; earlier: XLSX page margins are written as their decimals, `0.3` rather than `0.30000001192092896`; earlier: Python cells in `.xlsx` as [MS-XLSX] specifies, `_xlfn._xlws.PY(…)` naming code in the Python part, with cached values, and in GridCraft JSON, with limits on open; earlier: equations in xlsx as Office Math with a marker in `descr` so an edit made in Excel reads back, read back only up to the equation source cap, and a brace with a label and a script on its other side keeps both; Symbol font in PDF; earlier: XLSX reads and writes Page Setup's page order, `pageSetup pageOrder`, and PDF export follows it; earlier: chart data tables: native c:dTable import/export; earlier: XLSX workbook-view selection, normalized tab ratios and sheet-edit regressions; fidelity estimates unchanged; earlier: formulas from Google Sheets' XLSX export open as the original formula instead of `IFERROR(__xludf.DUMMYFUNCTION(…),…)` when GridCraft calculates every function in it, and save as it; `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; earlier: `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; CSV and text open detects each column's date order from values that read only one way, warns when every date is ambiguous, and keeps a column with both kinds as text (#2765)) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 +> **Last reviewed:** 2026-11-01 · **Last updated:** 2026-11-11 · **Change:** minor (one paper table, `model::paper`, for XLSX paper ids and print layout: `11x17`, `US Legal` and the other spellings keep their `paperSize`, XLSX id 34 (ECMA-376's 176×250 mm B5 envelope) reads as `B5 (ISO)`, and an empty paper name, a file that stated none, writes no `paperSize`; Page Setup and Size take Statement, Envelope #10 and Envelope DL; earlier: a web page's first table opens as a sheet, also when the page is named `.xls`; earlier: `workbookPr filterPrivacy` kept, and honoured on save; earlier: a workbook's R1C1 reference style, `calcPr refMode`, is kept through open and save; earlier: XLSX page margins are written as their decimals, `0.3` rather than `0.30000001192092896`; earlier: Python cells in `.xlsx` as [MS-XLSX] specifies, `_xlfn._xlws.PY(…)` naming code in the Python part, with cached values, and in GridCraft JSON, with limits on open; earlier: equations in xlsx as Office Math with a marker in `descr` so an edit made in Excel reads back, read back only up to the equation source cap, and a brace with a label and a script on its other side keeps both; Symbol font in PDF; earlier: XLSX reads and writes Page Setup's page order, `pageSetup pageOrder`, and PDF export follows it; earlier: chart data tables: native c:dTable import/export; earlier: XLSX workbook-view selection, normalized tab ratios and sheet-edit regressions; fidelity estimates unchanged; earlier: formulas from Google Sheets' XLSX export open as the original formula instead of `IFERROR(__xludf.DUMMYFUNCTION(…),…)` when GridCraft calculates every function in it, and save as it; `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; earlier: `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; CSV and text open detects each column's date order from values that read only one way, warns when every date is ambiguous, and keeps a column with both kinds as text (#2765)) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 Every format Excel opens or saves, with GridCraft's read and write support, fidelity and tests. Part of [target-app-parity.md](target-app-parity.md). **File formats: ~50% ready, 80–120 h** @@ -158,7 +158,7 @@ refresh. Counted under features (Get & Transform, ~10% ready), not here. | Date | Change | Summary | |---|---|---| -| 2026-11-11 | minor | One paper table (`model::paper`) behind XLSX `paperSize` and print layout; id 34 reads as `B5 (ISO)`, the ISO B5 size; `B5 (ISO)` and every alias save with their id; an empty paper writes no `paperSize` | +| 2026-11-11 | minor | One paper table (`model::paper`) behind XLSX `paperSize` and print layout; id 34 reads as `B5 (ISO)`, the ISO B5 size; `B5 (ISO)` and every alias save with their id; an empty paper writes no `paperSize`; Page Setup and Size now take Statement, Envelope #10 and Envelope DL (Page Setup refused them before) and print them on their own size | | 2026-11-03 | minor | SYLK (`.slk`) import: values, R1C1 formulas as A1 (shared formulas too) with cached results, number formats and column widths; import only (#1481) | | 2026-11-03 | minor | Opening a web page (HTML) reads its first table as a sheet, whatever the file is called: a web app's "Export to Excel" saved as `.xls` no longer opens as lines of markup. Values read as in a CSV (or as text with `csvAsText`), `` cells are bold and centred, `` names the sheet, and a page not named `.htm`/`.html` opens with a warning (#3166) | | 2026-11-03 | minor | XLSX `` (Remove personal information from file properties on save) is read and written back, and while it is on GridCraft saves no author (`dc:creator`) and no company, as Excel leaves them empty (#3089, file part) | From 8cb34cd3120c2e98e47f7ebdea9fe0acfe0507c1 Mon Sep 17 00:00:00 2001 From: alehel Date: Sat, 14 Nov 2026 08:52:38 +0100 Subject: [PATCH 5/7] model::paper: say what an empty paper means today; every table paper keeps an XLSX id Review round 1. - PrintSettings::paper and the docs said an empty paper is "a file that stated none", but no reader produces it yet. They now say empty means no paper is stated, which a reader may set. - for_size documents that it names the page as it stands (17x11 in is Ledger), so a caller that also records landscape passes the size upright. - xlsx: a test that every paper in model::paper::PAPERS saves with an id and reads back as itself, so the two tables cannot drift. B6 (ISO) is the one exception (ECMA-376 has no upright ISO B6 id). --- crates/engine/src/cmd/print/tests.rs | 2 +- crates/model/src/features/print.rs | 7 ++++--- crates/model/src/paper.rs | 4 ++++ crates/xlsx/src/tables.rs | 14 ++++++++++++++ crates/xlsx/src/tests/roundtrip.rs | 2 +- docs/architecture.md | 2 +- docs/file-format-parity.md | 2 +- 7 files changed, 26 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/cmd/print/tests.rs b/crates/engine/src/cmd/print/tests.rs index c056a23f9e..2e198bd25f 100644 --- a/crates/engine/src/cmd/print/tests.rs +++ b/crates/engine/src/cmd/print/tests.rs @@ -631,7 +631,7 @@ fn page_setup_paper_sizes_reach_the_pdf_page() { assert!(s.execute("pageLayout.pageSetup", json!({"paper": "Napkin"})).is_err()); } -/// An empty paper name means the file stated none; it prints on Letter. +/// An empty paper name means no paper is stated; it prints on Letter. #[test] fn an_unstated_paper_prints_on_letter() { let mut wb = gridcraft_model::Workbook::new(); diff --git a/crates/model/src/features/print.rs b/crates/model/src/features/print.rs index 833588c734..241b4b40e4 100644 --- a/crates/model/src/features/print.rs +++ b/crates/model/src/features/print.rs @@ -11,9 +11,10 @@ pub enum Orientation { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct PrintSettings { pub orientation: Orientation, - /// Paper size name (`Letter`, `A4`, `Legal`…; see [`crate::paper`]), or empty when the file - /// stated none: the printer's or locale's paper then. Print layout falls back to Letter and - /// XLSX writes no `paperSize`. New sheets default to Letter. + /// Paper size name (`Letter`, `A4`, `Legal`…; see [`crate::paper`]). Empty means no paper is + /// stated, so the printer's or locale's paper applies: a reader may leave it so for a file + /// that states none (none does yet). Print layout falls back to Letter and XLSX writes no + /// `paperSize`. New sheets default to Letter. pub paper: String, /// Margins in inches: left, right, top, bottom, header, footer. pub margins: [f32; 6], diff --git a/crates/model/src/paper.rs b/crates/model/src/paper.rs index 546c1d2577..2db5c28e84 100644 --- a/crates/model/src/paper.rs +++ b/crates/model/src/paper.rs @@ -77,6 +77,10 @@ pub fn size_pt(name: &str) -> Option<(f32, f32)> { /// The paper of a page `width` × `height` points, within 2 mm on each side: the nearest one as it /// stands, else the nearest one turned. Some papers are less than 4 mm apart (Letter and Japanese /// Envelope Kaku #3), so the nearest wins, not the first in the table. +/// +/// The name is the paper as the page stands: a 17×11 in page is `Ledger`. A caller that also +/// records a landscape orientation should pass the size upright (narrow side first), since +/// print layout turns the named paper once more for landscape. pub fn for_size(width: f32, height: f32) -> Option<&'static str> { const TOLERANCE: f32 = 5.67; // 2 mm let nearest = |w: f32, h: f32| { diff --git a/crates/xlsx/src/tables.rs b/crates/xlsx/src/tables.rs index 363ab9cedf..5427f31e01 100644 --- a/crates/xlsx/src/tables.rs +++ b/crates/xlsx/src/tables.rs @@ -323,6 +323,20 @@ pub const EMU_PER_PX: f64 = 9525.0; mod tests { use super::*; + /// Every paper in the shared table saves with an XLSX id, so it reopens as itself. ECMA-376 + /// has no upright ISO B6 id (35 is the B6 envelope stated wide), so `B6 (ISO)` alone has none. + #[test] + fn every_shared_paper_has_an_xlsx_id() { + for (name, _, _) in gridcraft_model::paper::PAPERS { + let id = paper_id(name); + if name == "B6 (ISO)" { + assert_eq!(id, None); + } else { + assert_eq!(id.and_then(paper_name), Some(name), "{name}"); + } + } + } + #[test] fn widths() { assert_eq!(col_width_to_px(9.140625), 64.0); diff --git a/crates/xlsx/src/tests/roundtrip.rs b/crates/xlsx/src/tests/roundtrip.rs index 928ba0a597..668d154479 100644 --- a/crates/xlsx/src/tests/roundtrip.rs +++ b/crates/xlsx/src/tests/roundtrip.rs @@ -1681,7 +1681,7 @@ fn japanese_paper_sizes_round_trip() { /// The paper names every spelling folds onto keep their file id: `11x17` is Tabloid (3), and /// ISO B5 is id 34 (ECMA-376's 176×250 mm "B5 envelope"), read back as `B5 (ISO)`. An empty -/// paper (the file stated none) writes no `paperSize`, so the reader's own paper applies. +/// paper (none stated) writes no `paperSize`, so the reader's own paper applies. #[test] fn paper_names_keep_their_xlsx_id_and_an_unstated_paper_writes_none() { for (paper, id, back_as) in [("11x17", 3, "Tabloid"), ("US Legal", 5, "Legal"), ("B5 (ISO)", 34, "B5 (ISO)"), ("Envelope B5", 34, "B5 (ISO)")] { diff --git a/docs/architecture.md b/docs/architecture.md index 341333718c..bbc7a05cae 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -242,7 +242,7 @@ rpm, tarball), FreeBSD, and web (WASM; WebGPU or WebGL2). Release workflows in | Date | Change | Summary | |---|---|---| -| 2026-11-13 | minor | Paper sizes: `model::paper` (`canonical`, `size_pt`, `for_size`) replaces the engine's `known_paper` and the XLSX alias list; an empty `PrintSettings::paper` means the file stated none; `for_size` picks the nearest paper; Statement, Envelope #10 and Envelope DL are accepted by Page Setup and Size | +| 2026-11-13 | minor | Paper sizes: `model::paper` (`canonical`, `size_pt`, `for_size`) replaces the engine's `known_paper` and the XLSX alias list; an empty `PrintSettings::paper` means no paper is stated (no reader sets it yet); `for_size` picks the nearest paper; Statement, Envelope #10 and Envelope DL are accepted by Page Setup and Size | | 2026-11-02 | minor | Python mode in the formula bar: Python mode on the shared editor, `code_field` and its stop keys; drafts follow their sheet by `model::SheetUid` | | 2026-11-02 | minor | Python cells as data: `model::PyCode`, the file forms, calc laying out kept results, the limits on open, and what copying, filling and sorting do to `xl()` references; edits that would push code past the limit are refused | | 2026-11-01 | trivial | Equations: the layout cache answers for a source over the cap by its length alone, without hashing it | diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index 34b114bff7..15e10fb98b 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -1,6 +1,6 @@ # File-format parity -> **Last reviewed:** 2026-11-01 · **Last updated:** 2026-11-13 · **Change:** minor (one paper table, `model::paper`, for XLSX paper ids and print layout: `11x17`, `US Legal` and the other spellings keep their `paperSize`, XLSX id 34 (ECMA-376's 176×250 mm B5 envelope) reads as `B5 (ISO)`, and an empty paper name, a file that stated none, writes no `paperSize`; Page Setup and Size take Statement, Envelope #10 and Envelope DL; earlier: .xls data validation is read; earlier: .xls is read by the shared craft-xls crate: the workbook opens on the sheet it was saved on, and rich-text (RString) cells are read; earlier: form controls: buttons, scroll bars and spin buttons read and written; earlier: a web page's first table opens as a sheet, also when the page is named `.xls`; earlier: `workbookPr filterPrivacy` kept, and honoured on save; earlier: a workbook's R1C1 reference style, `calcPr refMode`, is kept through open and save; earlier: XLSX page margins are written as their decimals, `0.3` rather than `0.30000001192092896`; earlier: Python cells in `.xlsx` as [MS-XLSX] specifies, `_xlfn._xlws.PY(…)` naming code in the Python part, with cached values, and in GridCraft JSON, with limits on open; earlier: equations in xlsx as Office Math with a marker in `descr` so an edit made in Excel reads back, read back only up to the equation source cap, and a brace with a label and a script on its other side keeps both; Symbol font in PDF; earlier: XLSX reads and writes Page Setup's page order, `pageSetup pageOrder`, and PDF export follows it; earlier: chart data tables: native c:dTable import/export; earlier: XLSX workbook-view selection, normalized tab ratios and sheet-edit regressions; fidelity estimates unchanged; earlier: formulas from Google Sheets' XLSX export open as the original formula instead of `IFERROR(__xludf.DUMMYFUNCTION(…),…)` when GridCraft calculates every function in it, and save as it; `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; earlier: `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; CSV and text open detects each column's date order from values that read only one way, warns when every date is ambiguous, and keeps a column with both kinds as text (#2765)) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 +> **Last reviewed:** 2026-11-01 · **Last updated:** 2026-11-13 · **Change:** minor (one paper table, `model::paper`, for XLSX paper ids and print layout: `11x17`, `US Legal` and the other spellings keep their `paperSize`, XLSX id 34 (ECMA-376's 176×250 mm B5 envelope) reads as `B5 (ISO)`, and an empty paper name (no paper stated) writes no `paperSize`; Page Setup and Size take Statement, Envelope #10 and Envelope DL; earlier: .xls data validation is read; earlier: .xls is read by the shared craft-xls crate: the workbook opens on the sheet it was saved on, and rich-text (RString) cells are read; earlier: form controls: buttons, scroll bars and spin buttons read and written; earlier: a web page's first table opens as a sheet, also when the page is named `.xls`; earlier: `workbookPr filterPrivacy` kept, and honoured on save; earlier: a workbook's R1C1 reference style, `calcPr refMode`, is kept through open and save; earlier: XLSX page margins are written as their decimals, `0.3` rather than `0.30000001192092896`; earlier: Python cells in `.xlsx` as [MS-XLSX] specifies, `_xlfn._xlws.PY(…)` naming code in the Python part, with cached values, and in GridCraft JSON, with limits on open; earlier: equations in xlsx as Office Math with a marker in `descr` so an edit made in Excel reads back, read back only up to the equation source cap, and a brace with a label and a script on its other side keeps both; Symbol font in PDF; earlier: XLSX reads and writes Page Setup's page order, `pageSetup pageOrder`, and PDF export follows it; earlier: chart data tables: native c:dTable import/export; earlier: XLSX workbook-view selection, normalized tab ratios and sheet-edit regressions; fidelity estimates unchanged; earlier: formulas from Google Sheets' XLSX export open as the original formula instead of `IFERROR(__xludf.DUMMYFUNCTION(…),…)` when GridCraft calculates every function in it, and save as it; `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; earlier: `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; CSV and text open detects each column's date order from values that read only one way, warns when every date is ambiguous, and keeps a column with both kinds as text (#2765)) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 Every format Excel opens or saves, with GridCraft's read and write support, fidelity and tests. Part of [target-app-parity.md](target-app-parity.md). **File formats: ~50% ready, 80–120 h** From a1b96711b6ba6328d037bc71b2d5b2739725ce50 Mon Sep 17 00:00:00 2001 From: alehel Date: Mon, 23 Nov 2026 10:36:04 +0100 Subject: [PATCH 6/7] PR4139: verify imported ISO B5 print dimensions --- crates/engine/src/cmd/print/tests.rs | 35 ++++++++++++++++++++++++++++ docs/file-format-parity.md | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/print/tests.rs b/crates/engine/src/cmd/print/tests.rs index 6ef29e6c05..af06027c62 100644 --- a/crates/engine/src/cmd/print/tests.rs +++ b/crates/engine/src/cmd/print/tests.rs @@ -1264,3 +1264,38 @@ fn chart_budget_counts_path_points_and_drops_charts_that_do_not_fit() { assert!(pics.chart((0, 1), || vec![line(1000)]).is_none()); assert!(pics.charts.is_empty() && pics.rejected_charts.contains(&(0, 1))); } + +/// XLSX id 34 is ISO B5 (176 × 250 mm), not the Letter fallback of the old name. +#[test] +fn imported_xlsx_b5_envelope_uses_iso_b5_print_dimensions() { + use std::io::{Cursor, Read, Write}; + let mut wb = gridcraft_model::Workbook::new(); + wb.sheet_mut(0).unwrap().set_value(CellRef::new(0, 0), gridcraft_core::Value::Text("x".into())); + wb.sheet_mut(0).unwrap().print.paper = "Legal".into(); + let bytes = gridcraft_xlsx::write_xlsx(&wb).unwrap(); + let mut input = zip::ZipArchive::new(Cursor::new(&bytes)).unwrap(); + let mut output = zip::ZipWriter::new(Cursor::new(Vec::new())); + for i in 0..input.len() { + let mut part = input.by_index(i).unwrap(); + let mut data = Vec::new(); + part.read_to_end(&mut data).unwrap(); + if part.name() == "xl/worksheets/sheet1.xml" { + let xml = String::from_utf8(data).unwrap(); + assert!(xml.contains(r#"paperSize="5""#)); + // Set the input id independently of the shared paper-name mapping under test. + data = xml.replace(r#"paperSize="5""#, r#"paperSize="34""#).into_bytes(); + } + output.start_file(part.name(), zip::write::SimpleFileOptions::default()).unwrap(); + output.write_all(&data).unwrap(); + } + let bytes = output.finish().unwrap().into_inner(); + let mut s = Session::new(); + s.execute("file.open", json!({"name": "iso-b5.xlsx", "base64": crate::io::base64_encode(&bytes)})).unwrap(); + let preview = s.execute("file.printPreview", json!({})).unwrap(); + let page = &preview["pageList"][0]; + assert!((page["width"].as_f64().unwrap() - 498.90).abs() < 0.01, "{page}"); + assert!((page["height"].as_f64().unwrap() - 708.66).abs() < 0.01, "{page}"); + let (pdf, pages) = pdf_of(&mut s, json!({})); + assert_eq!(pages, 1); + assert!(contains(&pdf, "/MediaBox [0 0 498.9 708.66]")); +} diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index 719b55abca..df5ad00e0f 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -1,6 +1,6 @@ # File-format parity -> **Last reviewed:** 2026-11-01 · **Last updated:** 2026-11-13 · **Change:** minor (one paper table, `model::paper`, for XLSX paper ids and print layout: `11x17`, `US Legal` and the other spellings keep their `paperSize`, XLSX id 34 (ECMA-376's 176×250 mm B5 envelope) reads as `B5 (ISO)`, and an empty paper name (no paper stated) writes no `paperSize`; Page Setup and Size take Statement, Envelope #10 and Envelope DL; earlier: PDF honours cell reading direction and mirrors right-to-left sheets; earlier: Arabic PDF export no longer fails when a character or the Arabic font is missing; earlier: Arabic PDF text is shaped with embedded Noto Arabic glyphs beside the non-embedded standard, Symbol and CID fonts; earlier: .xls data validation is read; earlier: .xls is read by the shared craft-xls crate: the workbook opens on the sheet it was saved on, and rich-text (RString) cells are read; earlier: form controls: buttons, scroll bars and spin buttons read and written; earlier: a web page's first table opens as a sheet, also when the page is named `.xls`; earlier: `workbookPr filterPrivacy` kept, and honoured on save; earlier: a workbook's R1C1 reference style, `calcPr refMode`, is kept through open and save; earlier: XLSX page margins are written as their decimals, `0.3` rather than `0.30000001192092896`; earlier: Python cells in `.xlsx` as [MS-XLSX] specifies, `_xlfn._xlws.PY(…)` naming code in the Python part, with cached values, and in GridCraft JSON, with limits on open; earlier: equations in xlsx as Office Math with a marker in `descr` so an edit made in Excel reads back, read back only up to the equation source cap, and a brace with a label and a script on its other side keeps both; Symbol font in PDF; earlier: XLSX reads and writes Page Setup's page order, `pageSetup pageOrder`, and PDF export follows it; earlier: chart data tables: native c:dTable import/export; earlier: XLSX workbook-view selection, normalized tab ratios and sheet-edit regressions; fidelity estimates unchanged; earlier: formulas from Google Sheets' XLSX export open as the original formula instead of `IFERROR(__xludf.DUMMYFUNCTION(…),…)` when GridCraft calculates every function in it, and save as it; `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; earlier: `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; CSV and text open detects each column's date order from values that read only one way, warns when every date is ambiguous, and keeps a column with both kinds as text (#2765)) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 +> **Last reviewed:** 2026-11-01 · **Last updated:** 2026-11-23 · **Change:** minor (one paper table, `model::paper`, for XLSX paper ids and print layout: `11x17`, `US Legal` and the other spellings keep their `paperSize`, XLSX id 34 (ECMA-376's 176×250 mm B5 envelope) reads as `B5 (ISO)` and prints at 176×250 mm instead of the old Letter fallback, and an empty paper name (no paper stated) writes no `paperSize`; Page Setup and Size take Statement, Envelope #10 and Envelope DL; earlier: PDF honours cell reading direction and mirrors right-to-left sheets; earlier: Arabic PDF export no longer fails when a character or the Arabic font is missing; earlier: Arabic PDF text is shaped with embedded Noto Arabic glyphs beside the non-embedded standard, Symbol and CID fonts; earlier: .xls data validation is read; earlier: .xls is read by the shared craft-xls crate: the workbook opens on the sheet it was saved on, and rich-text (RString) cells are read; earlier: form controls: buttons, scroll bars and spin buttons read and written; earlier: a web page's first table opens as a sheet, also when the page is named `.xls`; earlier: `workbookPr filterPrivacy` kept, and honoured on save; earlier: a workbook's R1C1 reference style, `calcPr refMode`, is kept through open and save; earlier: XLSX page margins are written as their decimals, `0.3` rather than `0.30000001192092896`; earlier: Python cells in `.xlsx` as [MS-XLSX] specifies, `_xlfn._xlws.PY(…)` naming code in the Python part, with cached values, and in GridCraft JSON, with limits on open; earlier: equations in xlsx as Office Math with a marker in `descr` so an edit made in Excel reads back, read back only up to the equation source cap, and a brace with a label and a script on its other side keeps both; Symbol font in PDF; earlier: XLSX reads and writes Page Setup's page order, `pageSetup pageOrder`, and PDF export follows it; earlier: chart data tables: native c:dTable import/export; earlier: XLSX workbook-view selection, normalized tab ratios and sheet-edit regressions; fidelity estimates unchanged; earlier: formulas from Google Sheets' XLSX export open as the original formula instead of `IFERROR(__xludf.DUMMYFUNCTION(…),…)` when GridCraft calculates every function in it, and save as it; `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; earlier: `file.exportCsv {values: true}` writes raw values for automation; .xls dialog sheets are skipped instead of read as worksheets; `.xls` import reads each sheet's display options from WINDOW2: right-to-left, gridlines, headings, zeros, formulas; XLSX text boxes and shapes keep their paragraphs' right-to-left direction on save; CSV/TSV/TXT can open with every field kept as text via `file.open {csvAsText}`; formulas over Excel's 8,192 characters, and `%` or call chains past the nesting limit, are parse errors instead of stack overflows when a file is opened; XLSX PivotTables read and write `rowGrandTotals`/`colGrandTotals` the way Excel does, so a table saved with only one grand total opens with the right one; HTML export keeps right-to-left; CSV and text import detects likely Windows-1256 Arabic when invalid UTF-8 has Arabic byte runs; other invalid UTF-8 remains Windows-1252; HTML export places pictures and charts, as inline SVG, at their anchors; CSV and text open detects each column's date order from values that read only one way, warns when every date is ambiguous, and keeps a column with both kinds as text (#2765)) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 Every format Excel opens or saves, with GridCraft's read and write support, fidelity and tests. Part of [target-app-parity.md](target-app-parity.md). **File formats: ~50% ready, 80–120 h** @@ -163,6 +163,7 @@ refresh. Counted under features (Get & Transform, ~10% ready), not here. | Date | Change | Summary | |---|---|---| +| 2026-11-23 | minor | Clarify that imported XLSX paper id 34 changes printed output from the old Letter fallback to ISO B5 (176×250 mm); add import-to-preview/PDF regression coverage | | 2026-11-13 | minor | One paper table (`model::paper`) behind XLSX `paperSize` and print layout; id 34 reads as `B5 (ISO)`, the ISO B5 size; `B5 (ISO)` and every alias save with their id; an empty paper writes no `paperSize`; Page Setup and Size now take Statement, Envelope #10 and Envelope DL (Page Setup refused them before) and print them on their own size | | 2026-11-13 | minor | PDF of a right-to-left sheet keeps explicit Left and Right alignment on the side the grid shows them | | 2026-11-12 | minor | `.xls` files open with their data validation (drop-down lists, input messages, error alerts and the rules), read by craft-xls and mapped as the `.xlsx` reader maps the same rules. A rule Excel would refuse, or one past 65,536 in a workbook, is skipped with a warning (#3634, from #3636) | From 0f36a7aee31703dc70f32ea129055cc3ee13dfdb Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Thu, 26 Nov 2026 21:34:27 +0700 Subject: [PATCH 7/7] print tests: read the zip entry name through main's fallible ZipFile::name() --- crates/engine/src/cmd/print/tests.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/print/tests.rs b/crates/engine/src/cmd/print/tests.rs index 71f0a29fc9..918a94c2c5 100644 --- a/crates/engine/src/cmd/print/tests.rs +++ b/crates/engine/src/cmd/print/tests.rs @@ -1307,13 +1307,14 @@ fn imported_xlsx_b5_envelope_uses_iso_b5_print_dimensions() { let mut part = input.by_index(i).unwrap(); let mut data = Vec::new(); part.read_to_end(&mut data).unwrap(); - if part.name() == "xl/worksheets/sheet1.xml" { + let name = part.name().unwrap().to_string(); + if name == "xl/worksheets/sheet1.xml" { let xml = String::from_utf8(data).unwrap(); assert!(xml.contains(r#"paperSize="5""#)); // Set the input id independently of the shared paper-name mapping under test. data = xml.replace(r#"paperSize="5""#, r#"paperSize="34""#).into_bytes(); } - output.start_file(part.name(), zip::write::SimpleFileOptions::default()).unwrap(); + output.start_file(name, zip::write::SimpleFileOptions::default()).unwrap(); output.write_all(&data).unwrap(); } let bytes = output.finish().unwrap().into_inner();