diff --git a/crates/engine/src/cmd/format.rs b/crates/engine/src/cmd/format.rs index 90213a5e1..a5c79bbf9 100644 --- a/crates/engine/src/cmd/format.rs +++ b/crates/engine/src/cmd/format.rs @@ -870,6 +870,33 @@ mod tests { assert_eq!(s.execute("cell.get", json!({"cell": "A1"})).unwrap()["style"]["num_fmt"], "0.00"); } + /// Outlined letters have no Font-group command; Format Cells' style JSON sets and clears them. + #[test] + fn format_cells_sets_outlined_letters() { + let mut s = crate::Session::new(); + s.new_workbook(); + s.execute("cell.set", json!({"cell": "A1", "input": "x"})).unwrap(); + s.execute("home.formatCells", json!({"range": "A1", "style": {"font": {"outline": true}}})).unwrap(); + assert_eq!(s.execute("cell.get", json!({"cell": "A1"})).unwrap()["style"]["font"]["outline"], true); + s.execute("home.formatCells", json!({"range": "A1", "style": {"font": {"outline": false}}})).unwrap(); + assert_eq!(s.execute("cell.get", json!({"cell": "A1"})).unwrap()["style"]["font"]["outline"], false); + } + + /// The Format Cells dialog sends the active cell's whole style to every selected cell, so a + /// non-outlined active cell must clear outline on the others, as it does bold. + #[test] + fn format_cells_whole_style_clears_outline_on_the_selection() { + let mut s = crate::Session::new(); + s.new_workbook(); + s.execute("cell.set", json!({"cell": "A1", "input": "plain"})).unwrap(); + s.execute("cell.set", json!({"cell": "B1", "input": "hollow"})).unwrap(); + s.execute("home.formatCells", json!({"range": "B1", "style": {"font": {"outline": true, "bold": true}}})).unwrap(); + let style = s.execute("cell.get", json!({"cell": "A1"})).unwrap()["style"].clone(); + s.execute("home.formatCells", json!({"range": "A1:B1", "style": style})).unwrap(); + let font = s.execute("cell.get", json!({"cell": "B1"})).unwrap()["style"]["font"].clone(); + assert_eq!((font["bold"].clone(), font["outline"].clone()), (json!(false), json!(false))); + } + #[test] fn arabic_vowel_and_direction_marks_add_no_width() { let plain = approx_text_width("محمد يدرس في المدرسة", 11.0, false); diff --git a/crates/engine/tests/golden/book.json b/crates/engine/tests/golden/book.json index 403189aa7..bb96cd821 100644 --- a/crates/engine/tests/golden/book.json +++ b/crates/engine/tests/golden/book.json @@ -168,7 +168,8 @@ "vert": "Baseline", "charset": null, "family": null, - "minor": true + "minor": true, + "outline": false }, "fill": { "pattern": "None", @@ -219,6 +220,7 @@ "bold": false, "italic": false, "strike": false, + "outline": false, "underline": false, "size": false, "name": false, @@ -238,7 +240,8 @@ "vert": "Baseline", "charset": null, "family": null, - "minor": true + "minor": true, + "outline": false }, "fill": { "pattern": "None", @@ -289,6 +292,7 @@ "bold": false, "italic": false, "strike": false, + "outline": false, "underline": false, "size": false, "name": false, @@ -308,7 +312,8 @@ "vert": "Baseline", "charset": null, "family": null, - "minor": true + "minor": true, + "outline": false }, "fill": { "pattern": "None", @@ -359,6 +364,7 @@ "bold": false, "italic": false, "strike": false, + "outline": false, "underline": false, "size": false, "name": false, diff --git a/crates/engine/tests/golden/kept.json b/crates/engine/tests/golden/kept.json index 0cbc313cf..c1ecfe6f3 100644 --- a/crates/engine/tests/golden/kept.json +++ b/crates/engine/tests/golden/kept.json @@ -247,6 +247,7 @@ "bold": false, "italic": false, "name": false, + "outline": false, "protection": false, "scheme": null, "size": false, @@ -266,6 +267,7 @@ "italic": false, "minor": true, "name": "Calibri", + "outline": false, "size": 11.0, "strike": false, "underline": "None", @@ -317,6 +319,7 @@ "bold": false, "italic": false, "name": false, + "outline": false, "protection": false, "scheme": null, "size": false, @@ -336,6 +339,7 @@ "italic": false, "minor": true, "name": "Calibri", + "outline": false, "size": 11.0, "strike": false, "underline": "None", @@ -387,6 +391,7 @@ "bold": false, "italic": false, "name": false, + "outline": false, "protection": false, "scheme": null, "size": false, @@ -406,6 +411,7 @@ "italic": false, "minor": true, "name": "Calibri", + "outline": false, "size": 11.0, "strike": false, "underline": "None", diff --git a/crates/model/src/style.rs b/crates/model/src/style.rs index 9ad61abec..29434b2d3 100644 --- a/crates/model/src/style.rs +++ b/crates/model/src/style.rs @@ -197,6 +197,11 @@ pub struct Font { /// theme's minor font. Fonts derived from it (bold, a colour, a size) keep the link. #[serde(default = "default_minor")] pub minor: bool, + /// Outlined (hollow) letters: an XLSX ``. Kept and saved; GridCraft does not + /// draw it yet (the letters render solid). Always serialized, like the other flags, so a + /// whole style sent back through `home.formatCells` (the Format Cells dialog) clears it. + #[serde(default)] + pub outline: bool, } fn default_minor() -> bool { @@ -208,7 +213,7 @@ impl Hash for Font { fn hash(&self, h: &mut H) { self.name.hash(h); self.size.to_bits().hash(h); - (self.bold, self.italic, self.underline, self.strike, self.color, self.vert, self.charset, self.family, self.minor).hash(h); + (self.bold, self.italic, self.underline, self.strike, self.color, self.vert, self.charset, self.family, self.minor, self.outline).hash(h); } } @@ -226,6 +231,7 @@ impl Default for Font { charset: None, family: None, minor: true, + outline: false, } } } @@ -408,6 +414,9 @@ pub struct DxfStated { pub bold: bool, pub italic: bool, pub strike: bool, + /// Outlined letters turned off (``). Defaulted so JSON saved before it opens. + #[serde(default)] + pub outline: bool, pub underline: bool, pub size: bool, pub name: bool, @@ -529,6 +538,27 @@ mod tests { assert!(!t.get(StyleId(999)).font.bold); } + /// Two fonts differing only in outlined letters are different styles; JSON states the flag + /// even when off, and JSON saved before it existed reads as not outlined. + #[test] + fn outline_makes_a_distinct_style() -> Result<(), Box> { + let mut t = StyleTable::default(); + let outlined = t.derive(StyleId::DEFAULT, |s| s.font.outline = true); + assert_ne!(outlined, StyleId::DEFAULT); + assert_ne!(Font { outline: true, ..Font::default() }, Font::default()); + assert_eq!(t.derive(outlined, |s| s.font.outline = false), StyleId::DEFAULT); + let mut json = serde_json::to_value(Font::default())?; + assert_eq!(json.get("outline"), Some(&serde_json::Value::Bool(false))); + assert!(json.as_object_mut().ok_or("none")?.remove("outline").is_some()); + assert_eq!(serde_json::from_value::(json)?, Font::default()); + let on = serde_json::to_value(Font { outline: true, ..Font::default() })?; + assert_eq!(on.get("outline"), Some(&serde_json::Value::Bool(true))); + let mut stated = serde_json::to_value(DxfStated::default())?; + assert!(stated.as_object_mut().ok_or("none")?.remove("outline").is_some()); + assert_eq!(serde_json::from_value::(stated)?, DxfStated::default()); + Ok(()) + } + #[test] fn a_theme_saved_before_per_script_fonts_still_opens() -> Result<(), Box> { let mut json = serde_json::to_value(Theme::default())?; diff --git a/crates/xlsx/src/styles.rs b/crates/xlsx/src/styles.rs index dd7014497..2da082c61 100644 --- a/crates/xlsx/src/styles.rs +++ b/crates/xlsx/src/styles.rs @@ -61,6 +61,22 @@ fn bool_prop(e: &El, name: &str) -> bool { e.child(name).is_some_and(|c| c.flag("val", true)) } +/// A font's `outline` as the shared SpreadsheetML font (`craft-xlsx`) reads it: `None` when the +/// element is absent, `Some(false)` when it says `val="0"` (stated off, which a differential +/// format keeps), `Some(true)` when on. +fn shared_outline(e: &El) -> Option { + craft_xlsx::Font::read(&crate::chart::to_craft_el(e)).outline +} + +/// The shared SpreadsheetML font's `outline` element for `outline`, written as it writes it: +/// ``, ``, or nothing. +fn push_shared_outline(s: &mut String, outline: Option) { + let font = craft_xlsx::Font { outline, ..Default::default() }.to_el("font", false); + for child in font.elements() { + child.write_xml(s); + } +} + const DEFAULT_FONT_FAMILY: u8 = 2; const MAX_FONT_FAMILY: u8 = 14; @@ -79,6 +95,7 @@ pub fn read_font(e: &El, palette: &[u32]) -> Font { f.bold = bool_prop(e, "b"); f.italic = bool_prop(e, "i"); f.strike = bool_prop(e, "strike"); + f.outline = shared_outline(e) == Some(true); if let Some(u) = e.child("u") { f.underline = match u.attr("val").unwrap_or("single") { "double" => Underline::Double, @@ -414,6 +431,7 @@ fn read_dxf<'a>(x: &'a El, palette: &[u32], fmts: &HashMap, inline_ st.bold = e.child("b").is_some() && !f.bold; st.italic = e.child("i").is_some() && !f.italic; st.strike = e.child("strike").is_some() && !f.strike; + st.outline = shared_outline(e) == Some(false); st.underline = e.child("u").is_some() && f.underline == Underline::None; st.size = has_size && size == def.size; st.name = has_name && name == def.name; @@ -480,6 +498,9 @@ fn font_xml(f: &Font, dxf: Option<&DxfStated>, minor: bool) -> String { let _ = write!(s, "<{tag} val=\"0\"/>"); } } + // Excel's order puts outline after strike (condense and extend aren't modelled). + let outline = if f.outline { Some(true) } else { stated.outline.then_some(false) }; + push_shared_outline(&mut s, outline); match f.underline { Underline::None if stated.underline => s.push_str(""), Underline::None => {} @@ -800,6 +821,7 @@ pub fn dxf_xml(tag: &str, d: &Style, nf: &mut NumFmts) -> String { if d.font.bold || d.font.italic || d.font.strike + || d.font.outline || d.font.underline != Underline::None || d.font.color != Color::Auto || d.font.vert != VertAlign::Baseline @@ -808,6 +830,7 @@ pub fn dxf_xml(tag: &str, d: &Style, nf: &mut NumFmts) -> String { || d.dxf_stated.bold || d.dxf_stated.italic || d.dxf_stated.strike + || d.dxf_stated.outline || d.dxf_stated.underline || d.dxf_stated.size || d.dxf_stated.name diff --git a/crates/xlsx/src/tests/fixtures.rs b/crates/xlsx/src/tests/fixtures.rs index b40be2b15..8301ba70d 100644 --- a/crates/xlsx/src/tests/fixtures.rs +++ b/crates/xlsx/src/tests/fixtures.rs @@ -236,6 +236,38 @@ fn dxf_font_and_parts_stated_at_their_defaults_survive_save() { assert_eq!(written, Some(format!(r#" count="4">{dxfs}"#).as_str())); } +/// Differential fonts that turn outlined letters on, or state them off (alone, or after strike), +/// keep it on save, like strike. +#[test] +fn dxf_outline_font_survives_save() { + let dxfs = concat!( + r#""#, + r#""#, + r#""#, + ); + let styles = format!( + r#" + + + + + {dxfs} + "# + ); + let rels = r#""#; + let body = r#"1 + 0 + 0 + 0"#; + let bytes = minimal(body, &[("xl/styles.xml", &styles)], rels, ""); + let (wb, _) = read_xlsx(&bytes).unwrap(); + let out = crate::write_xlsx(&wb).unwrap(); + let st = crate::package::Package::open(&out).unwrap().read("xl/styles.xml").unwrap().unwrap(); + let st = String::from_utf8(st).unwrap(); + let written = st.split_once("")).map(|(d, _)| d); + assert_eq!(written, Some(format!(r#" count="3">{dxfs}"#).as_str())); +} + /// A dxf writes its parts in schema order: the border comes before the protection. #[test] fn dxf_border_is_written_before_protection() { diff --git a/crates/xlsx/src/tests/roundtrip.rs b/crates/xlsx/src/tests/roundtrip.rs index a49700768..34be07825 100644 --- a/crates/xlsx/src/tests/roundtrip.rs +++ b/crates/xlsx/src/tests/roundtrip.rs @@ -809,6 +809,33 @@ fn empty_workbook_roundtrip() { assert!(crate::sniff(&bytes) == crate::Format::Xlsx); } +/// Outlined (hollow) letters are kept on save and reopen, written after `` as Excel does; +/// `` reads as not outlined. +#[test] +fn outlined_font_survives_xlsx_roundtrip() { + let mut wb = Workbook::new(); + let outlined = wb.styles.derive(StyleId::DEFAULT, |s| { + s.font.outline = true; + s.font.strike = true; + }); + let sheet = wb.sheet_mut(0).unwrap(); + sheet.cells.set(at("A1"), Cell { value: Value::text("hollow"), formula: None, style: outlined, py: None }); + sheet.set_value(at("A2"), Value::text("solid")); + + let bytes = write_xlsx(&wb).unwrap(); + let styles = Package::open(&bytes).unwrap().read("xl/styles.xml").unwrap().unwrap(); + let styles = String::from_utf8(styles).unwrap(); + assert!(styles.contains(""), "{styles}"); + assert_eq!(styles.matches(""#).unwrap(), &[]).outline); +} + #[test] fn cell_text_carriage_returns_survive_xlsx_roundtrip() { let mut wb = Workbook::new(); diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index 0aa14e6f4..2f3de7d32 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 (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-14 · **Change:** minor (XLSX fonts keep outlined letters, ``, through open and save; GridCraft draws them solid; 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** @@ -161,6 +161,7 @@ refresh. Counted under features (Get & Transform, ~10% ready), not here. | Date | Change | Summary | |---|---|---| +| 2026-11-14 | minor | XLSX fonts' outlined (hollow) letters, ``, are read and written back after `` as Excel writes them, in cell fonts and differential formats (a differential format that turns it off, ``, keeps that too); they were dropped before. Two fonts differing only in it are different styles. Set by `home.formatCells {style: {font: {outline: true}}}`; GridCraft does not draw outlined text yet (it shows solid) | | 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) | | 2026-11-12 | minor | .xls import reads the file with craft-xls (storytold/craft-libs), the reader that moved there from this repository; GridCraft keeps the mapping onto its model. The workbook now opens on the sheet it was saved on (WINDOW1 `itabCur`), falling back to the first visible sheet as before (from #3551), and cells saved as RString records (text with formatting runs) are read as text instead of skipped |