From 0d868b83df1dbcb58a007d79f0b17abe5bfc9b37 Mon Sep 17 00:00:00 2001 From: alehel Date: Sat, 14 Nov 2026 08:29:24 +0100 Subject: [PATCH] Text defaults: keep ODF's script code and BCP 47 language tag ODF 1.2 states a default language with fo:script and style:rfc-language-tag (and their -asian/-complex forms) as well as fo:language/fo:country. Without them, locales such as sr-Latn-RS or ca-ES-valencia would lose their script or variant on an ODS round trip, and adding them later would be a breaking model change. ScriptDefault gains `script` and `rfc_language_tag`, both skipped in JSON when unset and counted by is_empty. The `font` doc now says it holds the family name (not a style:font-face name) and that western.font is unused; the "no language" note says zxx is the language and none the country. The test round-trips sr-Latn-RS and fails if is_empty ignores either new field. --- crates/model/src/workbook.rs | 43 ++++++++++++++++++++++++++++++------ docs/file-format-parity.md | 2 +- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/crates/model/src/workbook.rs b/crates/model/src/workbook.rs index 1066acb57a..26e540bfcf 100644 --- a/crates/model/src/workbook.rs +++ b/crates/model/src/workbook.rs @@ -144,22 +144,34 @@ pub struct DefinedName { pub hidden: bool, } -/// The language, country and font a document gives one script's text by default, each `None` -/// when unstated. Codes are as files spell them (`de`/`DE`; ODF's `zxx`/`none` for no language). +/// The language, script, country and font a document gives one script's text by default, each +/// `None` when unstated. Codes are as files spell them (`de`/`DE`; ODF states "no language" as +/// language `zxx` with country `none`). ODF 1.2 and later can also state a script code (`Latn` in `sr-Latn-RS`) and a full +/// BCP 47 tag for locales the separate codes cannot express (`ca-ES-valencia`); both are kept so +/// such a locale survives open and save. #[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct ScriptDefault { #[serde(default, skip_serializing_if = "Option::is_none")] pub language: Option, + /// ISO 15924 script code (ODF `fo:script`, `style:script-asian`, `style:script-complex`). + #[serde(default, skip_serializing_if = "Option::is_none")] + pub script: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub country: Option, - /// Asian and complex text only: Western text takes the default style's font. + /// BCP 47 language tag (ODF `style:rfc-language-tag`, `-asian`, `-complex`). + #[serde(default, skip_serializing_if = "Option::is_none")] + pub rfc_language_tag: Option, + /// The font family name (not an ODF `style:font-face` declaration name: a reader resolves + /// `style:font-name-asian`/`-complex` to its family, a writer declares a face for it). Read + /// for Asian and complex text only; Western text takes the default style's font, so + /// `western.font` is unused. #[serde(default, skip_serializing_if = "Option::is_none")] pub font: Option, } impl ScriptDefault { pub fn is_empty(&self) -> bool { - self.language.is_none() && self.country.is_none() && self.font.is_none() + self.language.is_none() && self.script.is_none() && self.country.is_none() && self.rfc_language_tag.is_none() && self.font.is_none() } } @@ -649,9 +661,20 @@ mod tests { assert!(serde_json::from_str::(&json)?.text_defaults.is_empty()); wb.text_defaults = TextDefaults { - western: ScriptDefault { language: Some("de".into()), country: Some("DE".into()), font: None }, - asian: ScriptDefault { language: Some("ja".into()), country: Some("JP".into()), font: Some("Noto Sans CJK JP".into()) }, - complex: ScriptDefault { language: None, country: None, font: Some("Noto Naskh Arabic".into()) }, + western: ScriptDefault { + language: Some("sr".into()), + script: Some("Latn".into()), + country: Some("RS".into()), + rfc_language_tag: Some("sr-Latn-RS".into()), + font: None, + }, + asian: ScriptDefault { + language: Some("ja".into()), + country: Some("JP".into()), + font: Some("Noto Sans CJK JP".into()), + ..Default::default() + }, + complex: ScriptDefault { font: Some("Noto Naskh Arabic".into()), ..Default::default() }, }; assert!(!wb.text_defaults.is_empty()); let json = serde_json::to_string(&wb)?; @@ -661,6 +684,12 @@ mod tests { let td = value.get("text_defaults").ok_or("text_defaults written")?; assert!(td["western"].get("font").is_none()); assert!(td["complex"].get("language").is_none()); + assert!(td["asian"].get("script").is_none() && td["asian"].get("rfc_language_tag").is_none()); + assert_eq!(td["western"]["script"], "Latn"); + assert_eq!(td["western"]["rfc_language_tag"], "sr-Latn-RS"); + // A script that states only a script code or only a language tag is not empty. + assert!(!ScriptDefault { script: Some("Latn".into()), ..Default::default() }.is_empty()); + assert!(!ScriptDefault { rfc_language_tag: Some("ca-ES-valencia".into()), ..Default::default() }.is_empty()); // Only one script stated: the others are skipped and load back empty. wb.text_defaults = diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index 0ae6326f4c..612237fd43 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -158,7 +158,7 @@ refresh. Counted under features (Get & Transform, ~10% ready), not here. | Date | Change | Summary | |---|---|---| -| 2026-11-11 | trivial | The workbook model holds the document's default language and country of Western, Asian and complex text, and the default Asian and complex fonts (`Workbook::text_defaults`), which an OpenDocument file states on its default cell style. GridCraft JSON keeps them and leaves the field out when nothing is stated, so other workbooks' JSON is unchanged; XLSX has no equivalent and ignores them. The ODS reader and writer that fill and write them come separately | +| 2026-11-11 | trivial | The workbook model holds the document's default language, script, country and BCP 47 language tag of Western, Asian and complex text, and the default Asian and complex fonts (`Workbook::text_defaults`), which an OpenDocument file states on its default cell style. GridCraft JSON keeps them and leaves the field out when nothing is stated, so other workbooks' JSON is unchanged; XLSX has no equivalent and ignores them. The ODS reader and writer that fill and write them come separately | | 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) |