diff --git a/Cargo.lock b/Cargo.lock index 0500086433..35b2360afa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6802,6 +6802,7 @@ dependencies = [ name = "wordcraft-formats" version = "0.13.2" dependencies = [ + "base64 0.23.1", "cfb", "chardetng", "chrono", diff --git a/apps/wordcraft-web/src/web.rs b/apps/wordcraft-web/src/web.rs index 7fa947f02b..fd6c770671 100644 --- a/apps/wordcraft-web/src/web.rs +++ b/apps/wordcraft-web/src/web.rs @@ -9,7 +9,7 @@ use wordcraft_engine::Session; use wordcraft_ui_egui::async_saves::{AsyncSaves, SaveOutcome}; use wordcraft_ui_egui::{Inbox, Services, WordApp}; -const DOC_EXTS: &[&str] = &["docx", "docm", "dotx", "dotm", "doc", "dot", "odt", "rtf", "txt", "md", "html", "htm", "tex", "json", "xml"]; +const DOC_EXTS: &[&str] = &["docx", "docm", "dotx", "dotm", "doc", "dot", "odt", "fodt", "rtf", "txt", "md", "html", "htm", "tex", "json", "xml"]; const IMAGE_EXTS: &[&str] = &["png", "jpg", "jpeg", "gif", "webp", "bmp", "wmf", "emf"]; const RECIPIENT_EXTS: &[&str] = wordcraft_engine::cmd::mailings::RECIPIENT_EXTENSIONS; mod font_store; @@ -654,6 +654,7 @@ fn mime_for(name: &str) -> &'static str { Some("pdf") => "application/pdf", Some("docx") => "application/vnd.openxmlformats-officedocument.wordprocessingml.document", Some("odt") => "application/vnd.oasis.opendocument.text", + Some("fodt") => "application/vnd.oasis.opendocument.text-flat-xml", Some("rtf") => "application/rtf", Some("html") => "text/html", Some("md" | "txt") => "text/plain", diff --git a/apps/wordcraft/src/file_dialogs.rs b/apps/wordcraft/src/file_dialogs.rs index 667298a72b..dbdb18ad38 100644 --- a/apps/wordcraft/src/file_dialogs.rs +++ b/apps/wordcraft/src/file_dialogs.rs @@ -239,6 +239,7 @@ fn format_name(ext: &str) -> String { "html" => "Web Page".into(), "rtf" => "Rich Text Format".into(), "odt" => "OpenDocument Text".into(), + "fodt" => "Flat OpenDocument Text".into(), "tex" => "LaTeX".into(), "png" => "PNG Image".into(), "json" => "JSON".into(), diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index 1dbdd1ba42..ddadaabf5a 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -380,7 +380,7 @@ fn save(s: &mut Session, v: &Value) -> CmdResult { // A save in a format that doesn't keep everything (plain text, Markdown, a page image) is a // copy, except over the document's own file: a note.txt opened and saved is saved (#2376). let own_file = s.path.as_deref() == Some(path.as_path()); - if own_file || ["docx", "docm", "dotx", "dotm", "odt", "rtf", "json", "xml"].contains(&ext.as_str()) { + if own_file || ["docx", "docm", "dotx", "dotm", "odt", "fodt", "rtf", "json", "xml"].contains(&ext.as_str()) { s.path = Some(path.clone()); s.dirty = false; s.relayout(); diff --git a/crates/engine/src/io.rs b/crates/engine/src/io.rs index 960255030b..464648efb1 100644 --- a/crates/engine/src/io.rs +++ b/crates/engine/src/io.rs @@ -20,6 +20,7 @@ pub const OPEN_EXTS: &[&str] = &[ "htm", "rtf", "odt", + "fodt", "tex", "latex", "ltx", @@ -28,7 +29,7 @@ pub const OPEN_EXTS: &[&str] = &[ "json", ]; /// Formats WordCraft saves (Save As). -pub const SAVE_EXTS: &[&str] = &["docx", "docm", "dotx", "dotm", "pdf", "txt", "md", "html", "rtf", "odt", "tex", "png", "json", "xml"]; +pub const SAVE_EXTS: &[&str] = &["docx", "docm", "dotx", "dotm", "pdf", "txt", "md", "html", "rtf", "odt", "fodt", "tex", "png", "json", "xml"]; /// Magic number for ZIP package signatures (used by .docx/.docm/.dotx/.dotm). const ZIP_SIG: &[u8] = b"PK\x03\x04"; diff --git a/crates/engine/tests/it/odt_fields.rs b/crates/engine/tests/it/odt_fields.rs index 4c1db11b10..86eb1322da 100644 --- a/crates/engine/tests/it/odt_fields.rs +++ b/crates/engine/tests/it/odt_fields.rs @@ -71,3 +71,14 @@ fn captions_chapters_and_dates_update_as_words() { s.run("references.updateFields", &json!({"all": true})).unwrap(); assert_eq!(results(&s), ["1", "2", "Figure 2", "Methods"], "{:?}", text(&s)); } + +#[test] +fn a_flat_document_opens_and_saves_by_its_extension() { + let fodt = r#"Flat words."#; + let doc = io::open_bytes("plain.fodt", fodt.as_bytes()).unwrap(); + let s = Session::new(doc); + assert_eq!(text(&s), ["Flat words."]); + let saved = io::save_bytes("plain.fodt", &s.doc).unwrap(); + assert!(saved.starts_with(b" Option> { @@ -34,6 +34,7 @@ pub fn import(ext: &str, bytes: &[u8]) -> Option> { "html" | "htm" | "xhtml" => Ok(html::import(&html::decode(bytes))), "rtf" => rtf::import(bytes), "odt" => odt::import(bytes), + "fodt" => odt::import_flat(bytes), "tex" | "latex" | "ltx" => Ok(latex::import(bytes)), _ => return None, }; @@ -67,6 +68,7 @@ pub fn export(ext: &str, doc: &Document) -> Option, String>> { "html" | "htm" | "xhtml" => Ok(html::export(doc).into_bytes()), "rtf" => Ok(rtf::export(doc).into_bytes()), "odt" => odt::export(doc), + "fodt" => odt::export_flat(doc), "tex" | "latex" | "ltx" => Ok(latex::export(doc).into_bytes()), _ => return None, }) diff --git a/crates/formats/src/odt.rs b/crates/formats/src/odt.rs index a10d189ef6..87b2b1bf3a 100644 --- a/crates/formats/src/odt.rs +++ b/crates/formats/src/odt.rs @@ -40,6 +40,7 @@ use crate::model::{self, Cell, FBlock, FComment, FTable, Flow, Fmt, Inline, Kind mod body; mod datastyle; mod fields; +mod flat; mod formula_size; mod frames; mod import; @@ -53,6 +54,7 @@ mod writer; mod xml; use body::Body; +pub use flat::{export_flat, import_flat}; use import::Pages; #[cfg(test)] use import::{Pictures, apply_page_layout, read_entry, read_meta}; diff --git a/crates/formats/src/odt/flat.rs b/crates/formats/src/odt/flat.rs new file mode 100644 index 0000000000..511116ca9e --- /dev/null +++ b/crates/formats/src/odt/flat.rs @@ -0,0 +1,279 @@ +//! Flat OpenDocument text (`.fodt`, ODF 1.3 Part 3 §2.1.2): the whole document in one +//! `office:document` element, its pictures inline (`office:binary-data`, base64) and its +//! formulas inline (`math:math` inside `draw:object`). Read by taking it apart into a package's +//! files and opening that; written by putting a package's files together. + +use super::limits::MAX_ENTRY; +use base64::Engine as _; +use base64::engine::general_purpose::STANDARD; +use std::io::{Cursor, Read, Write}; +use wordcraft_doc::Document; + +/// The top-level parts of a flat document, in the order a package's files take them. +const META: &str = "office:meta"; +const SETTINGS: &str = "office:settings"; +const FONTS: &str = "office:font-face-decls"; +const STYLES: &str = "office:styles"; +const AUTOMATIC: &str = "office:automatic-styles"; +const MASTERS: &str = "office:master-styles"; +const BODY: &str = "office:body"; + +/// Most pictures and formulas taken out of a flat document (hostile files). +const MAX_INLINE: usize = 10_000; + +/// Element `name` in `xml` (its first one, start to end, or self-closed); "" when there is none. +fn element<'a>(xml: &'a str, name: &str) -> &'a str { + let open = format!("<{name}"); + let Some(start) = xml + .match_indices(&open) + .map(|(i, _)| i) + .find(|&i| xml.get(i + open.len()..).and_then(|r| r.chars().next()).is_some_and(|c| c == '>' || c == '/' || c.is_whitespace())) + else { + return ""; + }; + let Some(tag_end) = xml.get(start..).and_then(|r| r.find('>')).map(|e| start + e) else { return "" }; + if xml.get(..tag_end).is_some_and(|t| t.ends_with('/')) { + return xml.get(start..=tag_end).unwrap_or(""); + } + let close = format!(""); + match xml.get(tag_end..).and_then(|r| r.find(&close)) { + Some(e) => xml.get(start..tag_end + e + close.len()).unwrap_or(""), + // Unclosed (malformed): to the end. + None => xml.get(start..).unwrap_or(""), + } +} + +/// What is inside element `el` (an element string as [`element`] gives). +fn inner(el: &str) -> &str { + let Some(tag_end) = el.find('>') else { return "" }; + if el.get(..tag_end).is_some_and(|t| t.ends_with('/')) { + return ""; + } + let end = el.rfind(" &'static str { + if data.starts_with(b"\x89PNG") { + "png" + } else if data.starts_with(b"\xff\xd8") { + "jpg" + } else if data.starts_with(b"GIF8") { + "gif" + } else if data.starts_with(b" Option { + let mut from = 0; + while let Some(i) = xml.get(from..).and_then(|r| r.find("').and_then(|e| r.get(..e))).unwrap_or(""); + let next = tag.get(")>) -> String { + let mut out = String::with_capacity(xml.len()); + let mut rest = xml; + loop { + let pic = rest.find(""); + let obj = inline_object(rest); + let (at, picture) = match (pic, obj) { + (Some(p), Some(o)) if o < p => (o, false), + (Some(p), _) => (p, true), + (None, Some(o)) => (o, false), + (None, None) => break, + }; + let (before, from) = rest.split_at(at); + let close = if picture { "" } else { "" }; + let Some(end) = from.find(close) else { + out.push_str(before); + rest = from; + break; + }; + let open_len = if picture { "".len() } else { from.find('>').map_or(0, |e| e + 1) }; + let body = from.get(open_len..end).unwrap_or(""); + let after = from.get(end + close.len()..).unwrap_or(""); + let n = files.len() + 1; + if files.len() >= MAX_INLINE { + out.push_str(before); + rest = after; + continue; + } + if picture { + // The picture's `draw:image` start tag (just before) gets the package's reference. + let b64: String = body.chars().filter(|c| !c.is_whitespace()).collect(); + let data = STANDARD.decode(b64.as_bytes()).ok().filter(|d| d.len() <= MAX_ENTRY as usize).unwrap_or_default(); + let name = format!("Pictures/flat{n}.{}", picture_ext(&data)); + match before.rfind(" { + let (head, tag) = before.split_at(img); + out.push_str(head); + out.push_str(&format!(" out.push_str(before), + } + } else { + let dir = format!("Object flat{n}"); + out.push_str(before); + out.push_str(&format!("")); + files.push((format!("{dir}/content.xml"), body.as_bytes().to_vec())); + } + rest = after; + } + out.push_str(rest); + out +} + +/// Open a flat OpenDocument text document. +pub fn import_flat(bytes: &[u8]) -> Result { + let xml = std::str::from_utf8(bytes).map_err(|_| "FODT: not UTF-8 text".to_string())?; + let root = element(xml, "office:document"); + let attrs = + root.find('>').and_then(|e| root.get(" String { + let body: String = parts.iter().map(|p| element(root, p)).collect(); + format!("\n{body}") + }; + let mut files: Vec<(String, Vec)> = Vec::new(); + let content = take_out(&doc("document-content", &[FONTS, AUTOMATIC, BODY]), &mut files); + let styles = take_out(&doc("document-styles", &[FONTS, STYLES, AUTOMATIC, MASTERS]), &mut files); + let entries: Vec<(String, Vec)> = [ + ("mimetype".to_string(), b"application/vnd.oasis.opendocument.text".to_vec()), + ("content.xml".to_string(), content.into_bytes()), + ("styles.xml".to_string(), styles.into_bytes()), + ("meta.xml".to_string(), doc("document-meta", &[META]).into_bytes()), + ("settings.xml".to_string(), doc("document-settings", &[SETTINGS]).into_bytes()), + ] + .into_iter() + .chain(files) + .collect(); + let mut z = zip::ZipWriter::new(Cursor::new(Vec::new())); + let stored = zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored); + for (name, data) in &entries { + z.start_file(name.as_str(), stored).map_err(|e| format!("FODT: {e}"))?; + z.write_all(data).map_err(|e| format!("FODT: {e}"))?; + } + let package = z.finish().map_err(|e| format!("FODT: {e}"))?.into_inner(); + super::import(&package) +} + +/// Save `doc` as flat OpenDocument text: its package's files in one `office:document`, the +/// automatic styles of its content and its styles together, pictures and formulas inline. +pub fn export_flat(doc: &Document) -> Result, String> { + let package = super::export(doc)?; + let mut z = zip::ZipArchive::new(Cursor::new(package)).map_err(|e| format!("FODT: {e}"))?; + let mut read = |name: &str| -> String { + let mut s = String::new(); + if let Ok(mut f) = z.by_name(name) { + let _ = f.read_to_string(&mut s); + } + s + }; + let (content, styles, meta, settings) = (read("content.xml"), read("styles.xml"), read("meta.xml"), read("settings.xml")); + let mut bytes_of = |name: &str| -> Vec { + let mut v = Vec::new(); + if let Ok(mut f) = z.by_name(name) { + let _ = f.read_to_end(&mut v); + } + v + }; + let automatic = format!("<{AUTOMATIC}>{}{}", inner(element(&content, AUTOMATIC)), inner(element(&styles, AUTOMATIC))); + let mut body = String::new(); + for part in [ + element(&meta, META), + element(&settings, SETTINGS), + element(&styles, FONTS), + element(&content, FONTS), + element(&styles, STYLES), + &automatic, + element(&styles, MASTERS), + element(&content, BODY), + ] { + body.push_str(part); + } + // Pictures and formulas in the document, not beside it. + let mut flat = String::with_capacity(body.len()); + let mut rest = body.as_str(); + while let Some(at) = rest.find("xlink:href=\"") { + let (before, from) = rest.split_at(at); + let target_start = "xlink:href=\"".len(); + let Some(len) = from.get(target_start..).and_then(|r| r.find('"')) else { break }; + let target = from.get(target_start..target_start + len).unwrap_or(""); + let after = from.get(target_start + len + 1..).unwrap_or(""); + let tag = before.rfind('<').and_then(|i| before.get(i..)).unwrap_or(""); + if tag.starts_with("` → `…`. + let data = bytes_of(target); + let rest_tag_end = after.find("/>").unwrap_or(0); + // The link's other attributes go with it. + let attrs: String = + after.get(..rest_tag_end).unwrap_or("").split_whitespace().filter(|a| !a.starts_with("xlink:")).map(|a| format!(" {a}")).collect(); + flat.push_str(before.trim_end()); + flat.push_str(&attrs); + flat.push_str(&format!(">{}", STANDARD.encode(&data))); + rest = after.get(rest_tag_end + 2..).unwrap_or(""); + } else if tag.starts_with("").map_or(math.as_ref(), |(_, m)| m).trim(); + // A plain `draw:object` around it: the reference's other attributes go with it. + let rest_tag_end = after.find("/>").unwrap_or(0); + flat.push_str(before.rfind("{math}")); + rest = after.get(rest_tag_end + 2..).unwrap_or(""); + } else { + flat.push_str(before); + flat.push_str(from.get(..target_start + len + 1).unwrap_or("")); + rest = after; + } + } + flat.push_str(rest); + // Every namespace the parts declare (the settings' `config`, say), each prefix once. + let mut ns: Vec = Vec::new(); + for part in [&content, &styles, &meta, &settings] { + for decl in namespaces(part) { + let prefix = decl.split('=').next().unwrap_or(""); + if !ns.iter().any(|d| d.split('=').next() == Some(prefix)) { + ns.push(decl.to_string()); + } + } + } + Ok(format!( + "\n{flat}\n", + ns.join(" ") + ) + .into_bytes()) +} + +/// The namespace declarations (`xmlns:p="…"`) on the root element of `xml`. +fn namespaces(xml: &str) -> Vec<&str> { + let start = xml.find("').and_then(|e| r.get(..e))).unwrap_or(""); + let mut out = Vec::new(); + let mut rest = tag; + while let Some(i) = rest.find("xmlns:") { + let from = rest.get(i..).unwrap_or(""); + // `xmlns:p="…"`: up to the closing quote. + let Some(q1) = from.find('"') else { break }; + let Some(q2) = from.get(q1 + 1..).and_then(|r| r.find('"')) else { break }; + out.push(from.get(..q1 + 1 + q2 + 1).unwrap_or("")); + rest = from.get(q1 + 1 + q2 + 1..).unwrap_or(""); + } + out +} diff --git a/crates/formats/src/odt/tests_more.rs b/crates/formats/src/odt/tests_more.rs index 52796c2697..77f96dec13 100644 --- a/crates/formats/src/odt/tests_more.rs +++ b/crates/formats/src/odt/tests_more.rs @@ -6,6 +6,7 @@ mod chars; mod comments; mod equations; mod fields; +mod flat; mod floats; mod fonts; mod groups; diff --git a/crates/formats/src/odt/tests_more/flat.rs b/crates/formats/src/odt/tests_more/flat.rs new file mode 100644 index 0000000000..220a709a28 --- /dev/null +++ b/crates/formats/src/odt/tests_more/flat.rs @@ -0,0 +1,111 @@ +//! Flat OpenDocument text (`.fodt`, ODF 1.3 Part 3 §2.1.2: the whole document in one +//! `office:document` element, pictures inline as `office:binary-data`, formulas as +//! `math:math` inside their object): opened and saved like a package. + +use crate::odt::{export_flat, import_flat}; +use wordcraft_doc::Document; +use wordcraft_doc::para::InlineObject; + +/// A 1×1 PNG, base64. +const PNG_B64: &str = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="; + +fn flat() -> String { + format!( + r#" + + Flat title + + + + + + The footer + + Some bold words. + +{PNG_B64} + + xx + +"# + ) +} + +/// What a flat document holds: (its title, page width, body text, bold text, the paragraph +/// style, its footer's text, its pictures' sizes in bytes, its equations). +#[allow(clippy::type_complexity)] +fn summary(d: &Document) -> (String, f32, Vec, Vec, Option, String, Vec, Vec) { + let paras: Vec<_> = d.body.iter().filter_map(|b| b.as_para()).collect(); + let text = paras.iter().map(|p| p.text.replace(wordcraft_doc::para::OBJ, "#")).collect(); + let bold = paras + .iter() + .flat_map(|p| p.run_ranges().filter(|(_, c)| c.bold == Some(true)).map(|(r, _)| p.text.get(r).unwrap_or("").to_string()).collect::>()) + .collect(); + let style = paras.first().and_then(|p| p.props.style.clone()); + let footer = d + .last_section + .footers + .default + .and_then(|id| d.parts.get(&id)) + .map(|p| p.blocks.iter().filter_map(|b| b.as_para()).map(|p| p.text.clone()).collect()) + .unwrap_or_default(); + let mut pictures = Vec::new(); + let mut equations = Vec::new(); + for p in ¶s { + for o in &p.objects { + match o { + InlineObject::Image { media, .. } => pictures.push(d.media.get(media).map_or(0, |m| m.len())), + InlineObject::Equation { linear, .. } => equations.push(linear.clone()), + _ => {} + } + } + } + (d.core.title.clone(), d.last_section.page_w, text, bold, style, footer, pictures, equations) +} + +#[test] +fn a_flat_document_opens() { + let d = import_flat(flat().as_bytes()).unwrap(); + let s = summary(&d); + assert_eq!(s.0, "Flat title"); + assert_eq!(s.1, 360.0); + assert_eq!(s.2, ["Some bold words.", "#", "#"]); + assert_eq!(s.3, ["bold"]); + assert_eq!(s.4.as_deref(), Some("Quiet")); + assert_eq!(s.5, "The footer"); + // The picture's own bytes, decoded. + assert_eq!(s.6, [70]); + assert_eq!(s.7, ["x"]); +} + +#[test] +fn a_flat_document_round_trips() { + let d = import_flat(flat().as_bytes()).unwrap(); + let bytes = export_flat(&d).unwrap(); + let xml = String::from_utf8(bytes.clone()).unwrap(); + assert!(xml.contains("") && !xml.contains("Pictures/"), "pictures inline: {xml}"); + assert_eq!(xml.matches("").count(), 1, "one set of automatic styles"); + assert_eq!(summary(&import_flat(&bytes).unwrap()), summary(&d)); + // And by its extension. + assert_eq!(summary(&crate::import("fodt", &bytes).unwrap().unwrap()), summary(&d)); +} + +#[test] +fn hostile_flat_documents_do_not_panic() { + let f = flat(); + for bad in [ + String::new(), + "".to_string(), + f.replace("", ""), + f.replace(PNG_B64, "!!!not base64!!!"), + f.replace("", ""), + f.replace("", ""), + format!("{}", "".repeat(10_000)), + "\u{feff}".to_string(), + ] { + if let Ok(d) = import_flat(bad.as_bytes()) { + let _ = export_flat(&d).unwrap(); + } + } +} diff --git a/crates/ui-egui/src/file_dialogs.rs b/crates/ui-egui/src/file_dialogs.rs index 6bec025c88..8b055b3ad2 100644 --- a/crates/ui-egui/src/file_dialogs.rs +++ b/crates/ui-egui/src/file_dialogs.rs @@ -39,7 +39,7 @@ pub type FileDialogAnswer = Result, String>; const MAX_FONTS_PER_PICK: usize = 2000; const PICTURES: &[&str] = &["png", "jpg", "jpeg", "gif", "webp", "bmp", "wmf", "emf"]; -const DOCUMENTS: &[&str] = &["docx", "docm", "dotx", "dotm", "doc", "dot", "odt", "rtf", "txt", "md", "html", "htm", "tex", "json", "xml"]; +const DOCUMENTS: &[&str] = &["docx", "docm", "dotx", "dotm", "doc", "dot", "odt", "fodt", "rtf", "txt", "md", "html", "htm", "tex", "json", "xml"]; /// The file types Open offers, as (label, extensions; `*` is any file): pictures for Insert/Change /// Picture, recipient lists for Select Recipients › Use an Existing List…, documents otherwise. diff --git a/crates/ui-egui/src/print_page.rs b/crates/ui-egui/src/print_page.rs index e496268bb3..67296bbe94 100644 --- a/crates/ui-egui/src/print_page.rs +++ b/crates/ui-egui/src/print_page.rs @@ -358,6 +358,7 @@ pub fn export_formats(app: &mut WordApp, ui: &mut Ui) { ("Word XML Document (*.xml)", "xml"), ("Word 2003 XML Document (*.xml)", EXPORT_WORD_2003), ("OpenDocument Text (*.odt)", "odt"), + ("Flat OpenDocument Text (*.fodt)", "fodt"), ("Rich Text Format (*.rtf)", "rtf"), ("Web page (*.html)", "html"), ("Markdown (*.md)", "md"), diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 884fbb3b42..b18b384197 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -82,5 +82,5 @@ impl AutoSaveBlock { /// AutoSave writes only these formats. pub fn keeps_everything(name: &str) -> bool { let ext = std::path::Path::new(name).extension().map(|e| e.to_string_lossy().to_ascii_lowercase()).unwrap_or_default(); - matches!(ext.as_str(), "docx" | "docm" | "dotx" | "dotm" | "odt" | "rtf" | "json" | "xml") + matches!(ext.as_str(), "docx" | "docm" | "dotx" | "dotm" | "odt" | "fodt" | "rtf" | "json" | "xml") } diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index 7428ed96ae..cfb01677d1 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -1,6 +1,6 @@ # File-format parity with Microsoft Word -> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-31 · **Change:** trivial (ODT Asian and complex-script fonts); previously trivial (ODT right-to-left paragraphs); previously trivial (ODT text boxes kept); previously trivial (ODT unnumbered headings detached from the outline); previously trivial (ODT contextual spacing and layout settings); previously trivial (ODT custom character styles kept); previously trivial (ODT list level positions); previously trivial (ODT custom paragraph styles kept); previously trivial (ODT equations written as formula objects); previously trivial (ODT numbered headings written as headings); previously trivial (ODT floating pictures); previously trivial (ODT paragraph borders and background); previously trivial (ODT heading numbering); previously trivial (ODT font-face names); previously trivial (ODT table cell borders and padding); previously trivial (ODT heading, title, quote and preformatted styles keep their look); previously trivial (ODT tab stops read and written); previously trivial (ODT character formatting read and written); previously trivial (ODT lists keep their number formats, bullets and identity); previously trivial (ODT comments read and written); previously trivial (ODT footnotes and endnotes read and written); previously trivial (ODT headers, footers and text fields written; fields read); previously trivial (ODT paragraph spacing, indents and line spacing read and written); previously trivial (a paragraph naming an undefined style is formatted as Normal, as in Word, #5077); previously trivial (a hyperlinked TOC writes its page numbers as `PAGEREF _Toc… \h` fields, as Word does, #5097); previously trivial (HTML import ends the empty comments and at once, #5040); previously trivial (chart and SmartArt text the font lacks is drawn in a fallback face, so Chinese labels no longer show boxes, #4720); previously trivial (bibliography sources keep a corporate author (`b:Corporate`): read, written, cited and listed whole, #4848); previously trivial (custom-property bookmark-link preservation, #4767); previously trivial (note conversion preserves content with an ordered reference/run walk, #4750); previously trivial (DOCX comment-ID save lookups); previously trivial (built-in heading styles have their outline level without `w:outlineLvl`, #4696); previously trivial (DOCX comment ranges inside footnotes and endnotes are kept on read, #4548); previously trivial (RTF import and export keep Windows and Enhanced Metafile pictures (`\wmetafile`, `\emfblip`), #4259); previously trivial (#4658 bounds nested Markdown reference-label work); previously trivial (HTML import keeps preformatted lines with CR or CRLF input newlines, #4810); previously trivial (DOCX parts stored under another casing keep their embedded fonts through a save, and a private save of a kept glossary escapes the attribute values it rewrites; previously trivial: the `.doc` reader logs what its copy budget leaves out, once a kind per document; importers bound hostile expansion: font names, links, ODS repeats, LaTeX wrappers, Markdown delimiters, #3692/#3713; previously trivial: repeated DOCX style IDs: save/reopen regression; previously trivial: Markdown code spans keep line-broken text literal, #3738; previously trivial: Arabic list labels: `arabicAlpha` and `arabicAbjad` draw the 28 Arabic letters (alphabetical and abjad order), doubling past the last letter; Hebrew, Hindi, Thai and Vietnamese still show decimal (`doc::section::tests::arabic_letters_count_in_both_orders`); previously trivial: localized TOC style ids read as the TOC styles, and a TOC in columns keeps its layout through Update Table, #3889; previously trivial: cu20we: outline caps; previously trivial: a relationship the markup names without the prefix is read as it wrote: an unqualified `id` on an element that carries a relationship names that relationship, and the writer keeps the attribute with the id the new package holds the part under; an ordinary `id` — a VML shape's, a drawing's — names no part; previously trivial: the reader takes the relationship ids the markup refers to from the relationship attributes of the main document it has already parsed, so a document with many relationships opens in the time its part takes, #3411; previously trivial: a table cell span from a `.json` file stays within 63 columns through Insert Column and Merge Cells, #3637; previously trivial: the file commands that change the document are checked on a protected document, the protection of a protected document needs an explicit stop, the session author can't change through `file.setAuthor` under protection (the CLI's `--author` uses the same protection check), and the post-check compares the settings and the metadata; previously trivial: a document with many content controls saves in the time the controls take, #13; previously trivial: `majorBidi`/`minorBidi` theme fonts follow the settings' theme font language, as measured in Word; previously trivial: Word signature lines are kept on save, still signable; previously trivial: Times New Roman keeps Liberation Serif under the roman-font rule; previously trivial: shape gradients and transparency, #1500; previously trivial: a folder that keeps no Unix modes, such as a NAS share mounted by GVFS, still takes a save, #3003; previously trivial: a text frame in the paragraph defaults frames nothing, #2360; previously trivial: table style band sizes written, a style without them unbanded as in Word, #3415; previously trivial: HTML export writes ruby (furigana, phonetic guides) and HTML import reads it back, #1681; previously trivial: RTF import decodes the East Asian multibyte code pages, #1653; previously trivial: PDF export: lam-alef drawn as two glyphs at one x extracts in reading order, #2310; previously trivial: native .json stores pictures and kept parts as base64, #586 follow-up; previously trivial: ODT headers and footers read from each master page, #863; previously trivial: RTF import compares heading and code formatting with the file's stylesheet; previously trivial: text typed into a content control takes the control's formatting; localized placeholder styles recognised; previously trivial: forms protection keeps its content controls: no inserting, Properties or Remove Content Control; previously trivial: Word XML and web pages saved as `.doc` open by what they hold, #2853; previously trivial: a VML shape in a header cell is always placed on the page, user-checked in Word for Mac, #1775; previously trivial: `w:sym` characters keep their symbol font when the text's font changes and are written back as `w:sym`, #2036; previously trivial: RTF export writes sections (gap 19); previously trivial: ODT export writes sections (gap 19); previously trivial: two lines in one and horizontal in vertical (`w:eastAsianLayout`) kept on save; previously trivial: PDF outline targets follow leading page breaks; previously trivial: positional tabs `w:ptab` read and kept on save, #2367; previously trivial: DOCX: mixed right-to-left runs split and marked `w:rtl` with their language, #1543; previously trivial: `w:doNotTrackMoves` round-trips and turns move tracking off; previously trivial: legacy outline, shadow, emboss and imprint text effects drawn, #2534; previously trivial: DOCX glossary documents (building blocks) read, kept and written; previously trivial: cached field results keep their visible run formatting; previously trivial: cached REF results retain hyperlink destinations; previously trivial: CLI conversions can explicitly refresh fields; previously trivial: a copied equation also goes in the clipboard's MathML formats, #1297; previously trivial: a pasted HTML `
` is an indented paragraph, not the Quote style, #1270); previously trivial: every table style part round-trips, #714; previously trivial: VML freeforms read and kept on save; previously trivial: multi-paragraph field instructions no longer add blank lines; previously trivial: `flowChartOr` draws its circle and cross spokes, as in Word; previously trivial: RTF: Mac OS Roman and DOS text, #1653; previously trivial: VML text boxes keep their internal margins, fit to their text and vertical alignment; hidden drawings not shown; previously trivial: PDF export draws horizontal and vertical lines inside groups, #1474; previously trivial: symbol-font text exported as Unicode, #776; previously trivial: text-box margins, Resize shape to fit text and freeforms in groups, #743; previously trivial: formatted paste from the system clipboard's HTML and RTF, #687; previously trivial: independent complex-script formatting inheritance and round-trip regression tests; previously trivial: import/export fixes for TXT, RTF, ODT, HTML and LaTeX, #433–#440; previously major: first version; every format Word reads or writes, measured from the readers and writers on origin/main) · **Target:** Microsoft Word (Microsoft 365) for Mac 16.113.4, plus Word for Windows' extra formats +> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-01 · **Change:** trivial (flat ODT `.fodt` opened and saved; ODT fidelity re-estimated at ~80%); previously trivial (ODT page settings; a footnote no longer takes a footer's text); previously trivial (ODT dates in their formats, sequences, chapters and references); previously trivial (ODT bookmarks over text); previously trivial (ODT tables of contents and indexes; ODT fidelity re-estimated); previously trivial (ODT polygons, polylines and paths); previously trivial (ODT arrowheads, dashes and gradients); previously trivial (ODT groups of shapes and pictures); previously trivial (ODT rotated and mirrored shapes and pictures); previously trivial (ODT drawing shapes read and written); previously trivial (ODT text box frames keep their line, fill, padding and fit); previously trivial (ODT Asian and complex-script fonts); previously trivial (ODT right-to-left paragraphs); previously trivial (ODT text boxes kept); previously trivial (ODT unnumbered headings detached from the outline); previously trivial (ODT contextual spacing and layout settings); previously trivial (ODT custom character styles kept); previously trivial (ODT list level positions); previously trivial (ODT custom paragraph styles kept); previously trivial (ODT equations written as formula objects); previously trivial (ODT numbered headings written as headings); previously trivial (ODT floating pictures); previously trivial (ODT paragraph borders and background); previously trivial (ODT heading numbering); previously trivial (ODT font-face names); previously trivial (ODT table cell borders and padding); previously trivial (ODT heading, title, quote and preformatted styles keep their look); previously trivial (ODT tab stops read and written); previously trivial (ODT character formatting read and written); previously trivial (ODT lists keep their number formats, bullets and identity); previously trivial (ODT comments read and written); previously trivial (ODT footnotes and endnotes read and written); previously trivial (ODT headers, footers and text fields written; fields read); previously trivial (ODT paragraph spacing, indents and line spacing read and written); previously trivial (a paragraph naming an undefined style is formatted as Normal, as in Word, #5077); previously trivial (a hyperlinked TOC writes its page numbers as `PAGEREF _Toc… \h` fields, as Word does, #5097); previously trivial (HTML import ends the empty comments and at once, #5040); previously trivial (chart and SmartArt text the font lacks is drawn in a fallback face, so Chinese labels no longer show boxes, #4720); previously trivial (bibliography sources keep a corporate author (`b:Corporate`): read, written, cited and listed whole, #4848); previously trivial (custom-property bookmark-link preservation, #4767); previously trivial (note conversion preserves content with an ordered reference/run walk, #4750); previously trivial (DOCX comment-ID save lookups); previously trivial (built-in heading styles have their outline level without `w:outlineLvl`, #4696); previously trivial (DOCX comment ranges inside footnotes and endnotes are kept on read, #4548); previously trivial (RTF import and export keep Windows and Enhanced Metafile pictures (`\wmetafile`, `\emfblip`), #4259); previously trivial (#4658 bounds nested Markdown reference-label work); previously trivial (HTML import keeps preformatted lines with CR or CRLF input newlines, #4810); previously trivial (DOCX parts stored under another casing keep their embedded fonts through a save, and a private save of a kept glossary escapes the attribute values it rewrites; previously trivial: the `.doc` reader logs what its copy budget leaves out, once a kind per document; importers bound hostile expansion: font names, links, ODS repeats, LaTeX wrappers, Markdown delimiters, #3692/#3713; previously trivial: repeated DOCX style IDs: save/reopen regression; previously trivial: Markdown code spans keep line-broken text literal, #3738; previously trivial: Arabic list labels: `arabicAlpha` and `arabicAbjad` draw the 28 Arabic letters (alphabetical and abjad order), doubling past the last letter; Hebrew, Hindi, Thai and Vietnamese still show decimal (`doc::section::tests::arabic_letters_count_in_both_orders`); previously trivial: localized TOC style ids read as the TOC styles, and a TOC in columns keeps its layout through Update Table, #3889; previously trivial: cu20we: outline caps; previously trivial: a relationship the markup names without the prefix is read as it wrote: an unqualified `id` on an element that carries a relationship names that relationship, and the writer keeps the attribute with the id the new package holds the part under; an ordinary `id` — a VML shape's, a drawing's — names no part; previously trivial: the reader takes the relationship ids the markup refers to from the relationship attributes of the main document it has already parsed, so a document with many relationships opens in the time its part takes, #3411; previously trivial: a table cell span from a `.json` file stays within 63 columns through Insert Column and Merge Cells, #3637; previously trivial: the file commands that change the document are checked on a protected document, the protection of a protected document needs an explicit stop, the session author can't change through `file.setAuthor` under protection (the CLI's `--author` uses the same protection check), and the post-check compares the settings and the metadata; previously trivial: a document with many content controls saves in the time the controls take, #13; previously trivial: `majorBidi`/`minorBidi` theme fonts follow the settings' theme font language, as measured in Word; previously trivial: Word signature lines are kept on save, still signable; previously trivial: Times New Roman keeps Liberation Serif under the roman-font rule; previously trivial: shape gradients and transparency, #1500; previously trivial: a folder that keeps no Unix modes, such as a NAS share mounted by GVFS, still takes a save, #3003; previously trivial: a text frame in the paragraph defaults frames nothing, #2360; previously trivial: table style band sizes written, a style without them unbanded as in Word, #3415; previously trivial: HTML export writes ruby (furigana, phonetic guides) and HTML import reads it back, #1681; previously trivial: RTF import decodes the East Asian multibyte code pages, #1653; previously trivial: PDF export: lam-alef drawn as two glyphs at one x extracts in reading order, #2310; previously trivial: native .json stores pictures and kept parts as base64, #586 follow-up; previously trivial: ODT headers and footers read from each master page, #863; previously trivial: RTF import compares heading and code formatting with the file's stylesheet; previously trivial: text typed into a content control takes the control's formatting; localized placeholder styles recognised; previously trivial: forms protection keeps its content controls: no inserting, Properties or Remove Content Control; previously trivial: Word XML and web pages saved as `.doc` open by what they hold, #2853; previously trivial: a VML shape in a header cell is always placed on the page, user-checked in Word for Mac, #1775; previously trivial: `w:sym` characters keep their symbol font when the text's font changes and are written back as `w:sym`, #2036; previously trivial: RTF export writes sections (gap 19); previously trivial: ODT export writes sections (gap 19); previously trivial: two lines in one and horizontal in vertical (`w:eastAsianLayout`) kept on save; previously trivial: PDF outline targets follow leading page breaks; previously trivial: positional tabs `w:ptab` read and kept on save, #2367; previously trivial: DOCX: mixed right-to-left runs split and marked `w:rtl` with their language, #1543; previously trivial: `w:doNotTrackMoves` round-trips and turns move tracking off; previously trivial: legacy outline, shadow, emboss and imprint text effects drawn, #2534; previously trivial: DOCX glossary documents (building blocks) read, kept and written; previously trivial: cached field results keep their visible run formatting; previously trivial: cached REF results retain hyperlink destinations; previously trivial: CLI conversions can explicitly refresh fields; previously trivial: a copied equation also goes in the clipboard's MathML formats, #1297; previously trivial: a pasted HTML `
` is an indented paragraph, not the Quote style, #1270); previously trivial: every table style part round-trips, #714; previously trivial: VML freeforms read and kept on save; previously trivial: multi-paragraph field instructions no longer add blank lines; previously trivial: `flowChartOr` draws its circle and cross spokes, as in Word; previously trivial: RTF: Mac OS Roman and DOS text, #1653; previously trivial: VML text boxes keep their internal margins, fit to their text and vertical alignment; hidden drawings not shown; previously trivial: PDF export draws horizontal and vertical lines inside groups, #1474; previously trivial: symbol-font text exported as Unicode, #776; previously trivial: text-box margins, Resize shape to fit text and freeforms in groups, #743; previously trivial: formatted paste from the system clipboard's HTML and RTF, #687; previously trivial: independent complex-script formatting inheritance and round-trip regression tests; previously trivial: import/export fixes for TXT, RTF, ODT, HTML and LaTeX, #433–#440; previously major: first version; every format Word reads or writes, measured from the readers and writers on origin/main) · **Target:** Microsoft Word (Microsoft 365) for Mac 16.113.4, plus Word for Windows' extra formats Every format Word opens or saves, what WordCraft does with it, and how it's tested. Fidelity is the share of a typical real-world file's content and formatting that survives (read: shows correctly; @@ -57,7 +57,7 @@ Weights are the share of a Word user's file traffic (estimate). Read/write: ✅ | PDF export | 8% | W | — | ✅ | ~80% | 6–10 | `crates/pdf/src/tests.rs` | krilla: embedded subsets, selectable text incl. field results (#133); Hebrew and Arabic copy and search as whole words (right-to-left glyphs written in visual order, #1383, also with fonts that draw lam-alef as two glyphs at one x, #2310); All Caps and Small Caps text extracts as the capitals shown, as from Word's PDFs, and never changes the case of other text (#1473), links, outline, tagging. Outline destinations follow leading page breaks to the heading text. Fonts it can't subset become outlines (#132). Print Markup (#589): comments in balloons beside each page (scaled to its paper) and tracked changes; HTML/Markdown/text copies end with a comment list. Horizontal and vertical lines inside groups are drawn (#1474). No PDF/A option, no "best for printing/online" choice | | PDF open (PDF Reflow, Word for Windows) | 1% | R | ❌ | — | 0% | 30–50 | — | Converting a PDF into an editable document. A sibling app (PdfCraft) may supply the parser | | `.rtf` Rich Text Format | 3% | R/W | 🟡 | 🟡 | ~50% | 10–15 | `crates/formats/src/tests.rs` | ~1,500 lines: text, character/paragraph formatting, styles, lists, tables, pictures (`\shppict`, #154; Windows and Enhanced Metafiles, `\wmetafile` and `\emfblip`, read and written, #4259), fields, bookmarks. 8-bit text in the document's code page (`\ansicpg`) or the current font's (`\fcharset`, `\cpg`): Cyrillic, Central European, Greek, Turkish, Hebrew, Arabic, Baltic, Vietnamese, Thai (was Windows-1252 only), Mac OS Roman (`\mac`, `\fcharset77`) and DOS code pages (`\pc` 437, `\pca` 850, `\cpg` 437/737/850/852/857/866, `\fcharset254`) (#1653). East Asian multibyte code pages decoded as runs: 932 Shift-JIS (`\fcharset128`, Japanese), 936 GBK (134, Simplified Chinese), 949 UHC/windows-949 (129, Korean) and 950 Big5 (136, Traditional Chinese) through `\ansicpg`, `\cpg` or the font's charset, escaped or raw, a lead byte and its trail byte together; invalid sequences read as U+FFFD, and a run that starts `EF BB BF` is text, not a BOM (#1653). Pasted from the system clipboard where the platform offers it (Windows, Wayland) when there is no HTML (#687). Tracked insertions and deletions read and written (`\revtbl`, `\revised`/`\deleted`, authors, `\revdttm` dates), so Accept/Reject All work after opening or a round trip; tracked paragraph marks (`\par` inside `\revised`/`\deleted` groups, including a `\sect` inside a deletion) and character and paragraph formatting revisions (`\crauth`/`\crdate` with `\oldcprops`, `\prauth`/`\prdate` with `\oldpprops`) read and written; section and table formatting revisions (`\oldsprops`, `\oldtprops`) not yet. Sections on import (#1378): each `\sect` ends a section with its own page size and orientation, margins, header/footer distance, columns, break type, page-number restart, start and format, title page and headers/footers (those it leaves out link to the previous); export writes every section too (break type, page size and orientation, margins, header/footer distance, columns, page numbering, title page; not headers/footers). Thin: comments, notes, RTL | -| `.odt` OpenDocument Text | 2% | R/W | 🟡 | 🟡 | ~72% | 30–50 | `crates/formats/src/tests.rs`, `crates/formats/src/odt/tests.rs` and one file per feature in `crates/formats/src/odt/tests_more/`, `crates/engine/tests/it/odt_sections.rs`, `odt_toc.rs`, `odt_fields.rs`; checked against LibreOffice's own documents (round trips compared page by page) and the ODF 1.3 schema | Tables of contents and other indexes (`text:table-of-content`, `text:illustration-index`/`text:table-index`, `text:alphabetical-index`, `text:bibliography`) open as Word's `TOC` (levels from the source's `text:outline-level`; `\c` with the caption name for a table of figures), `INDEX` and `BIBLIOGRAPHY` fields — in the title paragraph when the index has one, as WordCraft inserts a table, else around the entries — so References › Update Table regenerates them; LibreOffice's Contents 1–10, Contents Heading and Figure Index 1 styles are WordCraft's TOC 1–9, TOC Heading and Table of Figures; WordCraft's tables are written back as ODF indexes with their source and entry templates (LibreOffice updates them), entries' links in the Index Link style; user and object indexes are read as their paragraphs; index marks (`text:alphabetical-index-mark`, Word's `XE`) are not read. Custom character styles (a common text style other than LibreOffice's link, note-mark and list-label styles kept as a character style with its name, parent and own formatting, its text in it; written back as common text styles), custom paragraph styles (a common style other than Standard, the kinds' and the note texts' kept as a document style with its name, parent and own formatting, its paragraphs in it rather than given its formatting directly; written back as common styles, named so LibreOffice keeps them), paragraph borders (each side's line and padding) and background, heading numbering (`text:outline-style`: each level's format, prefix, suffix, levels shown and start number the headings through their styles, as Word's numbered headings, and are written back), styles (the file's own Heading 1–6, Title, Quotations and Preformatted Text definitions give those styles' look on open — font, size, percent sizes included, bold, colour, spacing, alignment, keep with next — and saving writes the document's own style definitions rather than fixed ones), tab stops (left, centre, right, decimal; dot, hyphen, underline and middle-dot leaders; LibreOffice's indent-relative positions converted, and a `settings.xml` written saying positions run from the margin) and the default tab interval, character formatting (underline styles and colour, double strike, caps, small caps, hidden text kept hidden, letter spacing, scale, raised and lowered text, outline, shadow, emboss, engrave, language, Asian and complex-script fonts, complex-script size, weight and posture and both script languages (per run and as document defaults), a monospaced font by its own name, a `style:font-name` read as the family its `style:font-face` declares, and the default style's pair kerning) both ways, lists (#87; each `text:list` a list of its own unless it continues one by `text:continue-numbering` or `text:continue-list`, an item's `text:start-value` restarting from it; each level's number format — 1, i, I, a, A, none —, prefix, suffix, levels shown, start value, bullet character, indent, hanging and number alignment read from its list style and written back), floating pictures (a frame anchored to a paragraph, character or page: wrap — square on both sides, left, right or the larger side, top and bottom, behind or in front of text —, horizontal and vertical alignment or offset and what it is relative to, distances from the text, read into the picture's placement and written back in a graphic style), tables (cell borders — width, style, colour, an edge LibreOffice gives one cell shared by both — and cell padding read and written, each shared edge written once so lines don't double, a table without lines written without), pictures, page breaks (#86), paragraph spacing, indents and line spacing (proportional, fixed, at least; leading read as a proportional approximation) both ways, with the default and Standard styles' spacing as the document defaults (ODT's are none, not Word's 8 pt after and 1.15 lines), headers and footers of each master page (every, left and first page) read on open and written on save, with the header and footer distances converted between Word's page-edge measures and ODF's header bands (#863), text fields (page number and count, date, time, title, subject, author, file name, word and character counts, bookmark references as `REF`/`PAGEREF`, to bookmarks kept over the text they mark — `text:bookmark-start`…`-end`, in a paragraph or across several — so a reference updates to that text) read as fields and written back as ODF fields; dates and times in their date style (`number:date-style`/`time-style` ↔ Word's `\@` picture, both ways), sequences numbering figures and tables (`text:sequence` ↔ `SEQ` with its number format, declared on save; a bookmark over the caption's label and number, which references to it show), chapter fields (`text:chapter` ↔ `STYLEREF "Heading n"`, by name or number), reference marks (as bookmarks) and references to them and to sequences (`text:reference-ref`, `text:sequence-ref` ↔ `REF`/`PAGEREF`); fixed dates and fields without a Word equivalent (variables, references to a caption's text) read as their text, and Word fields ODF lacks written as their result, keep with next (#2813), an embedded formula object (`draw:object`) is read from its own `content.xml`'s MathML, same as HTML (#3099); export writes each equation as a formula object of its own (MathML, with its linear text as an annotation), its frame sized from the equation's structure and centred on the line, so LibreOffice shows and edits it, page size, orientation and margins (#810), page number format (the page style's, and a page number field's own as `PAGE \* Arabic`/`roman`/…), page colour, page borders (ODF's at the margin with the text inside their padding ↔ WordCraft's measured from the page edge), footnote and endnote numbering (`text:notes-configuration`: format, first number, restart, page foot or document end) and line numbering (`text:linenumbering-configuration`, on unless it says otherwise: every how many lines, distance, restart on each page), sections: one per master-page change on a paragraph or table (next page, with its own page size, orientation, margins, columns and page-numbering restart) and per columned `text:section` (continuous, with its columns and separator line) (#1379); export writes them back: a master page and page layout per new-page section (size, orientation, margins, columns, page-numbering restart on the first paragraph or table), a `text:section` with its columns per continuous section whose columns differ from the page's (one column included), a list cut by a section break goes on numbering. Limits: a continuous section's page-numbering restart isn't written (ODF applies it only with a master page); a continuous section with the page's columns merges into the section before it on reopening; even and odd page starts are written as plain new pages; a tracked deletion of a section break is lost; an empty last section is dropped; tracked insertions and deletions with author and date, inserted and deleted paragraph marks and text inserted then deleted included (ODF change tracking; format changes read as none; pictures and tables inside a tracked deletion are dropped). footnotes and endnotes (`text:note`) read into note stories as Word's (Footnote Text style, the note's own mark first, a custom mark kept) and written back with their citations; notes inside notes and in deleted text left out; comments (`office:annotation` with `office:annotation-end` ranges, author, date, initials, LibreOffice's resolved state and reply threads, `loext:resolved`/`loext:parent-name`) read and written, a comment whose end never comes covering nothing; comments in notes and in deleted text left out; text boxes (`draw:text-box` in a frame) open as WordCraft text boxes with their text, in line or floating, and are written back, keeping the frame's line (colour and width), fill, padding (through the frame's graphic style and its parents, LibreOffice's Frame style included) and a frame without a height growing to its text (`fo:min-height`), which WordCraft lays out floating as well as in line. Right-to-left paragraphs (`style:writing-mode` `rl-tb`) read and written. Drawing shapes (`draw:rect`, `draw:ellipse`, `draw:line`, and `draw:custom-shape` of a predefined geometry by its `draw:type`: rounded rectangle, triangles, diamond, the four block arrows, star, heart, flowchart or; LibreOffice's names and the `ooxml-` preset names) open as WordCraft shapes with their size, placement (in line or floating, as frames are), fill, line (colour and width; LibreOffice's default blue line and fill where the styles say nothing), text and a line's direction, and are written back, a custom shape by its type alone, which LibreOffice rebuilds the geometry from; a geometry WordCraft has no shape for opens as a rectangle; shapes and pictures turned by `draw:transform` (rotate, translate and scale; anticlockwise about the corner in the file, clockwise about the centre in WordCraft) and custom shapes mirrored (`draw:mirror-horizontal`/`-vertical`) keep their turn and mirroring both ways, in line or floating, a turned line by its turned ends; groups (`draw:g`) of shapes, text boxes and pictures open as one WordCraft group anchored and wrapped as the group is, its members placed (and turned) as they are in it, groups in it flattened into it, and are written back as a group; a frame, shape or group whose styles state no wrap has text on both sides, as LibreOffice wraps it (§20.400 states no default), and `biggest` wraps on the larger side; arrowheads (`draw:marker-start`/`-end`, written with WordCraft's own triangle marker), dashes (`draw:stroke-dash`: up to two kinds of dash and a space, in line widths or lengths, matched to WordCraft's named dashes; a pattern with more kinds is written as its first two) and gradient fills (`draw:gradient`: linear and axial along their angle, radial, ellipsoid, square and rectangular out from their centre, border and intensity; more than two colours written as the first and last) are read and written, a line's direction (and so its arrowheads' ends) kept from its two ends; polygons, polylines, paths (SVG path data: moves, lines, cubic and quadratic curves, smooth ones and elliptical arcs, absolute and relative, curves followed in short straight steps) and regular polygons (stars too) open as WordCraft freeforms in their view box, circles as ellipses, and freeforms (ink too) are written as `draw:path`; connectors, captions and measures are left out, a custom shape whose type WordCraft has no shape for opens as a rectangle; an in-line shape is written sitting on the baseline, as Word places it | +| `.odt` OpenDocument Text (and flat `.fodt`) | 2% | R/W | 🟡 | 🟡 | ~80% | 30–50 | `crates/formats/src/tests.rs`, `crates/formats/src/odt/tests.rs` and one file per feature in `crates/formats/src/odt/tests_more/`, `crates/engine/tests/it/odt_sections.rs`, `odt_toc.rs`, `odt_fields.rs`; checked against LibreOffice's own documents (round trips compared page by page) and the ODF 1.3 schema | Flat OpenDocument text (`.fodt`: the whole document in one `office:document`, pictures inline as base64 `office:binary-data`, formulas inline) is opened and saved as a package is, both validating against the schema. Tables of contents and other indexes (`text:table-of-content`, `text:illustration-index`/`text:table-index`, `text:alphabetical-index`, `text:bibliography`) open as Word's `TOC` (levels from the source's `text:outline-level`; `\c` with the caption name for a table of figures), `INDEX` and `BIBLIOGRAPHY` fields — in the title paragraph when the index has one, as WordCraft inserts a table, else around the entries — so References › Update Table regenerates them; LibreOffice's Contents 1–10, Contents Heading and Figure Index 1 styles are WordCraft's TOC 1–9, TOC Heading and Table of Figures; WordCraft's tables are written back as ODF indexes with their source and entry templates (LibreOffice updates them), entries' links in the Index Link style; user and object indexes are read as their paragraphs; index marks (`text:alphabetical-index-mark`, Word's `XE`) are not read. Custom character styles (a common text style other than LibreOffice's link, note-mark and list-label styles kept as a character style with its name, parent and own formatting, its text in it; written back as common text styles), custom paragraph styles (a common style other than Standard, the kinds' and the note texts' kept as a document style with its name, parent and own formatting, its paragraphs in it rather than given its formatting directly; written back as common styles, named so LibreOffice keeps them), paragraph borders (each side's line and padding) and background, heading numbering (`text:outline-style`: each level's format, prefix, suffix, levels shown and start number the headings through their styles, as Word's numbered headings, and are written back), styles (the file's own Heading 1–6, Title, Quotations and Preformatted Text definitions give those styles' look on open — font, size, percent sizes included, bold, colour, spacing, alignment, keep with next — and saving writes the document's own style definitions rather than fixed ones), tab stops (left, centre, right, decimal; dot, hyphen, underline and middle-dot leaders; LibreOffice's indent-relative positions converted, and a `settings.xml` written saying positions run from the margin) and the default tab interval, character formatting (underline styles and colour, double strike, caps, small caps, hidden text kept hidden, letter spacing, scale, raised and lowered text, outline, shadow, emboss, engrave, language, Asian and complex-script fonts, complex-script size, weight and posture and both script languages (per run and as document defaults), a monospaced font by its own name, a `style:font-name` read as the family its `style:font-face` declares, and the default style's pair kerning) both ways, lists (#87; each `text:list` a list of its own unless it continues one by `text:continue-numbering` or `text:continue-list`, an item's `text:start-value` restarting from it; each level's number format — 1, i, I, a, A, none —, prefix, suffix, levels shown, start value, bullet character, indent, hanging and number alignment read from its list style and written back), floating pictures (a frame anchored to a paragraph, character or page: wrap — square on both sides, left, right or the larger side, top and bottom, behind or in front of text —, horizontal and vertical alignment or offset and what it is relative to, distances from the text, read into the picture's placement and written back in a graphic style), tables (cell borders — width, style, colour, an edge LibreOffice gives one cell shared by both — and cell padding read and written, each shared edge written once so lines don't double, a table without lines written without), pictures, page breaks (#86), paragraph spacing, indents and line spacing (proportional, fixed, at least; leading read as a proportional approximation) both ways, with the default and Standard styles' spacing as the document defaults (ODT's are none, not Word's 8 pt after and 1.15 lines), headers and footers of each master page (every, left and first page) read on open and written on save, with the header and footer distances converted between Word's page-edge measures and ODF's header bands (#863), text fields (page number and count, date, time, title, subject, author, file name, word and character counts, bookmark references as `REF`/`PAGEREF`, to bookmarks kept over the text they mark — `text:bookmark-start`…`-end`, in a paragraph or across several — so a reference updates to that text) read as fields and written back as ODF fields; dates and times in their date style (`number:date-style`/`time-style` ↔ Word's `\@` picture, both ways), sequences numbering figures and tables (`text:sequence` ↔ `SEQ` with its number format, declared on save; a bookmark over the caption's label and number, which references to it show), chapter fields (`text:chapter` ↔ `STYLEREF "Heading n"`, by name or number), reference marks (as bookmarks) and references to them and to sequences (`text:reference-ref`, `text:sequence-ref` ↔ `REF`/`PAGEREF`); fixed dates and fields without a Word equivalent (variables, references to a caption's text) read as their text, and Word fields ODF lacks written as their result, keep with next (#2813), an embedded formula object (`draw:object`) is read from its own `content.xml`'s MathML, same as HTML (#3099); export writes each equation as a formula object of its own (MathML, with its linear text as an annotation), its frame sized from the equation's structure and centred on the line, so LibreOffice shows and edits it, page size, orientation and margins (#810), page number format (the page style's, and a page number field's own as `PAGE \* Arabic`/`roman`/…), page colour, page borders (ODF's at the margin with the text inside their padding ↔ WordCraft's measured from the page edge), footnote and endnote numbering (`text:notes-configuration`: format, first number, restart, page foot or document end) and line numbering (`text:linenumbering-configuration`, on unless it says otherwise: every how many lines, distance, restart on each page), sections: one per master-page change on a paragraph or table (next page, with its own page size, orientation, margins, columns and page-numbering restart) and per columned `text:section` (continuous, with its columns and separator line) (#1379); export writes them back: a master page and page layout per new-page section (size, orientation, margins, columns, page-numbering restart on the first paragraph or table), a `text:section` with its columns per continuous section whose columns differ from the page's (one column included), a list cut by a section break goes on numbering. Limits: a continuous section's page-numbering restart isn't written (ODF applies it only with a master page); a continuous section with the page's columns merges into the section before it on reopening; even and odd page starts are written as plain new pages; a tracked deletion of a section break is lost; an empty last section is dropped; tracked insertions and deletions with author and date, inserted and deleted paragraph marks and text inserted then deleted included (ODF change tracking; format changes read as none; pictures and tables inside a tracked deletion are dropped). footnotes and endnotes (`text:note`) read into note stories as Word's (Footnote Text style, the note's own mark first, a custom mark kept) and written back with their citations; notes inside notes and in deleted text left out; comments (`office:annotation` with `office:annotation-end` ranges, author, date, initials, LibreOffice's resolved state and reply threads, `loext:resolved`/`loext:parent-name`) read and written, a comment whose end never comes covering nothing; comments in notes and in deleted text left out; text boxes (`draw:text-box` in a frame) open as WordCraft text boxes with their text, in line or floating, and are written back, keeping the frame's line (colour and width), fill, padding (through the frame's graphic style and its parents, LibreOffice's Frame style included) and a frame without a height growing to its text (`fo:min-height`), which WordCraft lays out floating as well as in line. Right-to-left paragraphs (`style:writing-mode` `rl-tb`) read and written. Drawing shapes (`draw:rect`, `draw:ellipse`, `draw:line`, and `draw:custom-shape` of a predefined geometry by its `draw:type`: rounded rectangle, triangles, diamond, the four block arrows, star, heart, flowchart or; LibreOffice's names and the `ooxml-` preset names) open as WordCraft shapes with their size, placement (in line or floating, as frames are), fill, line (colour and width; LibreOffice's default blue line and fill where the styles say nothing), text and a line's direction, and are written back, a custom shape by its type alone, which LibreOffice rebuilds the geometry from; a geometry WordCraft has no shape for opens as a rectangle; shapes and pictures turned by `draw:transform` (rotate, translate and scale; anticlockwise about the corner in the file, clockwise about the centre in WordCraft) and custom shapes mirrored (`draw:mirror-horizontal`/`-vertical`) keep their turn and mirroring both ways, in line or floating, a turned line by its turned ends; groups (`draw:g`) of shapes, text boxes and pictures open as one WordCraft group anchored and wrapped as the group is, its members placed (and turned) as they are in it, groups in it flattened into it, and are written back as a group; a frame, shape or group whose styles state no wrap has text on both sides, as LibreOffice wraps it (§20.400 states no default), and `biggest` wraps on the larger side; arrowheads (`draw:marker-start`/`-end`, written with WordCraft's own triangle marker), dashes (`draw:stroke-dash`: up to two kinds of dash and a space, in line widths or lengths, matched to WordCraft's named dashes; a pattern with more kinds is written as its first two) and gradient fills (`draw:gradient`: linear and axial along their angle, radial, ellipsoid, square and rectangular out from their centre, border and intensity; more than two colours written as the first and last) are read and written, a line's direction (and so its arrowheads' ends) kept from its two ends; polygons, polylines, paths (SVG path data: moves, lines, cubic and quadratic curves, smooth ones and elliptical arcs, absolute and relative, curves followed in short straight steps) and regular polygons (stars too) open as WordCraft freeforms in their view box, circles as ellipses, and freeforms (ink too) are written as `draw:path`; connectors, captions and measures are left out, a custom shape whose type WordCraft has no shape for opens as a rectangle; an in-line shape is written sitting on the baseline, as Word places it | | `.txt` Plain text | 2% | R/W | ✅ | ✅ | ~95% | 1–2 | unit tests | Encoding detection. Files with other extensions (`.m3u`/`.m3u8` playlists, logs, config files, no extension) open as text when they are text, Word and RTF files by their signature; binary files are refused (#569). A Word or RTF extension that contradicts the content also opens by signature, as in Word: RTF saved as `.doc` (hh.ru résumés, accounting exports), a `.docx` renamed `.doc`, a Word 97-2003 file renamed `.docx`; a Word XML Document (Word 2003 XML or Flat OPC) or a web page (``, ``) under a `.doc`, `.docx` or `.rtf` name opens as what it is (#2853, `tests::word_xml_and_web_pages_saved_as_doc_open_by_content`). Word's encoding choice dialog and line-ending options missing; such files save only through Save As | | `.htm/.html` Web Page and Web Page, Filtered | 1% | R/W | 🟡 | 🟡 | ~60% | 6–10 | `crates/formats/src/tests.rs` | Tables (#102), relative pictures embedded (#113), missing `` tolerated (#154); the empty comments `` and `` end at once instead of swallowing the rest of the page (#5040). Header cells (``) bold unless their CSS says otherwise; `text-align` on a cell, or inherited from its row, row group or table, aligns the cell's paragraphs (#1381). HTML gives no page size, so it opens on the region's paper (A4 or Letter), as Markdown and plain text do; `@page` isn't read (#1381). No Word "Web Page" (with `_files` folder) round-trip. The same reader takes HTML from the system clipboard: Paste keeps another program's formatting (a Word document, a web page; Windows' "HTML Format" header understood), Merge Formatting keeps its emphasis (#687). A pasted `
` (LibreOffice's paragraph indented on both sides) becomes a Normal paragraph indented by the page's `blockquote` margins, else 0.5 in each side; opening an .html file keeps it as the Quote style (#1270). Equations are written as MathML (with the linear format as a UnicodeMath annotation) and read back from MathML: our annotation, else the presentation elements, else a TeX annotation (#816). A copy of one equation alone also goes in the clipboard's MathML formats (Windows "MathML" and "MathML Presentation", macOS `public.mathml.presentation` and `public.mathml`; W3C MathML 3 §6.2.4), which Microsoft documents Word reading first when it pastes math (#1297; the paste into Word is not yet verified); Ruby (furigana, phonetic guides) is written as `basereading` in the base text's formatting and read back from ``/``/`` (`` fallback parentheses dropped; malformed markup keeps its text), so docx/doc → HTML → doc keeps the annotation; HTML states no alignment, size or raise, so the Phonetic Guide's defaults apply (#1681) CRLF and lone CR input newlines normalize before tokenization, preserving preformatted lines and leaving decoded character references separate (#4810). | | `.mht/.mhtml` Single File Web Page | <1% | R/W | ❌ | ❌ | 0% | 3–5 | — | | @@ -279,6 +279,7 @@ Custom document properties retain their bookmark link targets through DOCX saves | Date | Change | Summary | |---|---|---| +| 2026-11-01 | trivial | Flat OpenDocument text (`.fodt`) opened and saved (Open, Save As, the CLI, the web app): taken apart into a package's files and put together again, its pictures inline as base64 and its formulas inline in their objects; LibreOffice's own flat documents round-trip as their packages do. ODT fidelity re-estimated at ~80% (tables of contents and indexes, field formats and references, bookmarks over text, page settings and flat files since ~72%; still missing: embedded charts and other objects, form controls, password-protected files, tracked formatting changes, variables, drop caps) | | 2026-11-01 | trivial | ODT: page settings read and written — page number format (the page style's, and a page number field's own as `PAGE \* Arabic` and the like), page colour, page borders (at ODF's margin, the text inside their padding; WordCraft measures them from the edge), footnote and endnote numbering and line numbering. Fixed: in a document with footnotes (or comments, or text boxes) and a header or footer, the header or footer took the story id of a note, so the note showed the footer's text (`a_footnote_keeps_its_text_beside_a_footer`). A LibreOffice document with all of these round-trips pixel for pixel, and WordCraft draws it 7,213 px from LibreOffice (24,025 before the border was placed right) | | 2026-11-01 | trivial | ODT: dates and times keep their format (date and time styles ↔ Word's `\@` pictures, both ways), sequences numbering figures and tables open as `SEQ` fields with a bookmark over the caption's label and number, chapter fields as `STYLEREF`, reference marks as bookmarks, and references to marks and sequences as `REF`/`PAGEREF`, instead of as plain text, so Update Field renumbers captions and refreshes references (`odt_fields.rs`); a LibreOffice document with all of them round-trips 13 px apart. Fields: a date-time picture's text in single quotes is shown as it is (`date_pictures_keep_quoted_text`) | | 2026-11-01 | trivial | ODT: a bookmark over text (`text:bookmark-start`…`-end`, in one paragraph or across several) keeps the text it covers, both ways (it was read as a point at its start, and a Word bookmark over text was written as a point), so a reference to it — LibreOffice's references to headings included — updates to that text instead of to nothing (`odt_fields.rs`) |