From fd664055dfd97d4b05b1e242515892fa4b7d7429 Mon Sep 17 00:00:00 2001 From: alehel Date: Wed, 11 Nov 2026 09:19:20 +0000 Subject: [PATCH] Fonts: outlined letters kept through XLSX open and save An XLSX font's was never read, so outlined (hollow) letters came back solid after a save. The model's Font gains `outline` (serde default false, left out of JSON when off, part of the hand-written Hash), read in read_font and written by font_xml after as Excel orders it, for cell fonts and differential formats. home.formatCells sets it through the style JSON. GridCraft does not draw outlined text yet. Split out of the ODS branch, which also maps style:text-outline onto it. --- crates/engine/src/cmd/format.rs | 12 ++++++++++++ crates/model/src/style.rs | 24 +++++++++++++++++++++++- crates/xlsx/src/styles.rs | 6 ++++++ crates/xlsx/src/tests/fixtures.rs | 25 +++++++++++++++++++++++++ crates/xlsx/src/tests/roundtrip.rs | 27 +++++++++++++++++++++++++++ docs/file-format-parity.md | 3 ++- 6 files changed, 95 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/format.rs b/crates/engine/src/cmd/format.rs index 1066f48e2..73861ebc6 100644 --- a/crates/engine/src/cmd/format.rs +++ b/crates/engine/src/cmd/format.rs @@ -870,6 +870,18 @@ 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!(s.execute("cell.get", json!({"cell": "A1"})).unwrap()["style"]["font"].get("outline").is_none()); + } + #[test] fn width_units() { assert_eq!(chars_to_points(8.43), 64.0); diff --git a/crates/model/src/style.rs b/crates/model/src/style.rs index d2f10780e..9ade75ca2 100644 --- a/crates/model/src/style.rs +++ b/crates/model/src/style.rs @@ -197,6 +197,10 @@ 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). + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub outline: bool, } fn default_minor() -> bool { @@ -208,7 +212,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 +230,7 @@ impl Default for Font { charset: None, family: None, minor: true, + outline: false, } } } @@ -499,6 +504,23 @@ mod tests { assert!(!t.get(StyleId(999)).font.bold); } + /// Two fonts differing only in outlined letters are different styles; JSON leaves the + /// flag out 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 json = serde_json::to_value(Font::default())?; + assert!(json.get("outline").is_none()); + 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))); + 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 c1f93aca9..d9229d1a8 100644 --- a/crates/xlsx/src/styles.rs +++ b/crates/xlsx/src/styles.rs @@ -71,6 +71,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 = bool_prop(e, "outline"); if let Some(u) = e.child("u") { f.underline = match u.attr("val").unwrap_or("single") { "double" => Underline::Double, @@ -436,6 +437,10 @@ 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). + if f.outline { + s.push_str(""); + } match f.underline { Underline::None if stated.underline => s.push_str(""), Underline::None => {} @@ -709,6 +714,7 @@ pub fn write_styles(wb: &Workbook, dxfs: &[Style], extra_fmts: &[String]) -> (St 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 diff --git a/crates/xlsx/src/tests/fixtures.rs b/crates/xlsx/src/tests/fixtures.rs index 4de0be3c3..f0c57f851 100644 --- a/crates/xlsx/src/tests/fixtures.rs +++ b/crates/xlsx/src/tests/fixtures.rs @@ -236,6 +236,31 @@ fn dxf_font_and_parts_stated_at_their_defaults_survive_save() { assert_eq!(written, Some(format!(r#" count="4">{dxfs}"#).as_str())); } +/// A differential format whose only font part is outlined letters keeps it on save. +#[test] +fn dxf_outline_font_survives_save() { + let dxfs = r#""#; + let styles = format!( + r#" + + + + + {dxfs} + "# + ); + let rels = r#""#; + let body = r#"1 + 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="1">{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 4eb6c3cfe..af9cb34bd 100644 --- a/crates/xlsx/src/tests/roundtrip.rs +++ b/crates/xlsx/src/tests/roundtrip.rs @@ -790,6 +790,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 d2660dde0..5090e9b4b 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 (XLSX fonts keep outlined letters, ``, through open and save; GridCraft draws them solid; 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 | XLSX fonts' outlined (hollow) letters, ``, are read and written back after `` as Excel writes them, in cell fonts and differential formats; 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-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) |