Fonts: outlined letters kept through XLSX open and save

An XLSX font's <outline/> 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 <strike/> 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.
This commit is contained in:
alehel
2026-11-11 09:19:20 +00:00
parent 632e4a1bc5
commit fd664055df
6 changed files with 95 additions and 2 deletions
+12
View File
@@ -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);
+23 -1
View File
@@ -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 `<outline/>`. 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<H: Hasher>(&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<dyn std::error::Error>> {
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::<Font>(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<dyn std::error::Error>> {
let mut json = serde_json::to_value(Theme::default())?;
+6
View File
@@ -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("<outline/>");
}
match f.underline {
Underline::None if stated.underline => s.push_str("<u val=\"none\"/>"),
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
+25
View File
@@ -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#"<dxf><font><outline/></font></dxf>"#;
let styles = format!(
r#"<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<fonts count="1"><font><sz val="11"/><name val="Calibri"/></font></fonts>
<fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills>
<borders count="1"><border/></borders>
<cellXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellXfs>
<dxfs count="1">{dxfs}</dxfs>
</styleSheet>"#
);
let rels = r#"<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>"#;
let body = r#"<sheetData><row r="1"><c r="A1"><v>1</v></c></row></sheetData>
<conditionalFormatting sqref="A1"><cfRule type="cellIs" dxfId="0" priority="1" operator="greaterThan"><formula>0</formula></cfRule></conditionalFormatting>"#;
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("<dxfs").and_then(|(_, r)| r.split_once("</dxfs>")).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() {
+27
View File
@@ -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 `<strike/>` as Excel does;
/// `<outline val="0"/>` 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("<strike/><outline/>"), "{styles}");
assert_eq!(styles.matches("<outline").count(), 1, "only the outlined font says so: {styles}");
let (back, _) = read_xlsx(&bytes).unwrap();
let sheet = &back.sheets[0];
let style_of = |a: &str| back.styles.get(sheet.cells.get(at(a)).map_or(StyleId::DEFAULT, |c| c.style));
assert!(style_of("A1").font.outline && style_of("A1").font.strike);
assert!(!style_of("A2").font.outline);
assert!(!crate::styles::read_font(&crate::xml::parse(br#"<font><outline val="0"/></font>"#).unwrap(), &[]).outline);
}
#[test]
fn cell_text_carriage_returns_survive_xlsx_roundtrip() {
let mut wb = Workbook::new();
+2 -1
View File
@@ -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, `<outline/>`, 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, `<outline/>`, are read and written back after `<strike/>` 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`), `<th>` cells are bold and centred, `<x:Name>` names the sheet, and a page not named `.htm`/`.html` opens with a warning (#3166) |
| 2026-11-03 | minor | XLSX `<workbookPr filterPrivacy="1"/>` (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) |