mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-15 23:12:31 +00:00
Gap 19: ODT form control sizes and buttons kept
On save, form controls were sized to their text. Buttons and other controls WordCraft has no kind for were dropped. - Sizes: each control keeps the size of its `draw:control` (`svg:width`, `svg:height`), stored on the content control. - Buttons, image buttons, labels, file and value-range controls, frames and generic controls now show their label, locked, as a content control. Their form XML is kept verbatim and written back as it was, so LibreOffice's button round-trips as a button. - A kept control that names a namespace WordCraft doesn't declare is left out. So is one longer than 64 KiB. - The `ooo`, `oooc`, `script` and `dom` prefixes that LibreOffice's controls use are declared, so the content validates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GBVQLyDnrG8Tn1yDQcUabC
This commit is contained in:
6 files changed
+166
-5
No files matched your search
@@ -254,6 +254,14 @@ pub struct ContentControl {
|
||||
/// `w:sdtEndPr`, kept verbatim (XML).
|
||||
#[serde(skip_serializing_if = "String::is_empty")]
|
||||
pub end_pr_xml: String,
|
||||
/// The size of the form control it came from (an ODF `draw:control`'s `svg:width` and
|
||||
/// `svg:height`), points: kept for saving back as one.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub form_size: Option<[f32; 2]>,
|
||||
/// A form control WordCraft has no kind for (an ODF button, image button, label…): its form
|
||||
/// XML, kept verbatim and saved back as it was. It shows its label, locked.
|
||||
#[serde(skip_serializing_if = "String::is_empty")]
|
||||
pub form_xml: String,
|
||||
}
|
||||
|
||||
impl ContentControl {
|
||||
|
||||
@@ -862,7 +862,12 @@ impl Body<'_> {
|
||||
if self.field.is_some() {
|
||||
return;
|
||||
}
|
||||
if let Some((control, text)) = get(a, "draw:control").and_then(|id| self.forms.controls.get(id)).cloned() {
|
||||
if let Some((mut control, text)) = get(a, "draw:control").and_then(|id| self.forms.controls.get(id)).cloned() {
|
||||
// Its size (§19.539, §19.571).
|
||||
let len = |k: &str| get(a, k).and_then(length).filter(|v| v.is_finite() && *v > 0.0).map(|v| v.min(1584.0));
|
||||
if let (Some(w), Some(h)) = (len("svg:width"), len("svg:height")) {
|
||||
control.form_size = Some([w, h]);
|
||||
}
|
||||
let fmt = self.cur_fmt();
|
||||
self.push_inline(Inline::Control { control: Box::new(control), text, fmt });
|
||||
}
|
||||
|
||||
@@ -21,6 +21,17 @@ const MAX_VALUE: usize = 10_000;
|
||||
pub(in crate::odt) const RADIO_ON: char = '\u{25C9}';
|
||||
pub(in crate::odt) const RADIO_OFF: char = '\u{25CB}';
|
||||
|
||||
/// Form controls WordCraft has no kind for, kept verbatim (see [`ContentControl::form_xml`]).
|
||||
const KEPT: [&str; 8] =
|
||||
["form:button", "form:image", "form:fixed-text", "form:file", "form:value-range", "form:frame", "form:image-frame", "form:generic-control"];
|
||||
/// Most bytes of a kept control's XML.
|
||||
const MAX_KEPT: usize = 64 * 1024;
|
||||
/// The namespace prefixes a kept control may use: those the content WordCraft writes declares.
|
||||
const PREFIXES: [&str; 19] = [
|
||||
"office", "style", "text", "table", "draw", "fo", "xlink", "dc", "meta", "svg", "number", "form", "ooo", "ooow", "oooc", "script", "dom",
|
||||
"loext", "xml",
|
||||
];
|
||||
|
||||
/// A control read: its content control and the text it holds.
|
||||
pub(in crate::odt) type Read = (ContentControl, String);
|
||||
|
||||
@@ -37,6 +48,39 @@ pub(in crate::odt) struct FormsReader {
|
||||
open: Option<(String, ContentControl, Vec<String>)>,
|
||||
/// The controls read, by `form:id` (or `xml:id`).
|
||||
pub(in crate::odt) controls: HashMap<String, Read>,
|
||||
/// A control WordCraft has no kind for being kept: its id, name, label, its XML so far (its
|
||||
/// id left out) and how many of its elements are open.
|
||||
kept: Option<Kept>,
|
||||
}
|
||||
|
||||
struct Kept {
|
||||
id: String,
|
||||
name: String,
|
||||
label: String,
|
||||
xml: String,
|
||||
open: usize,
|
||||
/// It uses a prefix the content WordCraft writes doesn't declare: not kept.
|
||||
foreign: bool,
|
||||
}
|
||||
|
||||
/// Whether name `q` has a prefix the content WordCraft writes declares.
|
||||
fn known(q: &str) -> bool {
|
||||
q.split_once(':').is_some_and(|(p, _)| PREFIXES.contains(&p))
|
||||
}
|
||||
|
||||
/// Whether element `q` with attributes `a` uses only declared prefixes.
|
||||
fn declared(q: &str, a: &Attrs) -> bool {
|
||||
known(q) && a.iter().all(|(k, _)| known(k))
|
||||
}
|
||||
|
||||
/// Element `q` with attributes `a` as XML, its ids (`form:id`, `xml:id`) left out.
|
||||
fn element_xml(q: &str, a: &Attrs) -> String {
|
||||
let mut s = format!("<{q}");
|
||||
for (k, v) in a.iter().filter(|(k, _)| k != "form:id" && k != "xml:id") {
|
||||
s.push_str(&format!(" {k}=\"{}\"", x(v)));
|
||||
}
|
||||
s.push('>');
|
||||
s
|
||||
}
|
||||
|
||||
impl FormsReader {
|
||||
@@ -50,7 +94,21 @@ impl FormsReader {
|
||||
return true;
|
||||
}
|
||||
self.depth += 1;
|
||||
if let Some(k) = &mut self.kept {
|
||||
if k.xml.len() < MAX_KEPT {
|
||||
k.xml.push_str(&element_xml(q, a));
|
||||
}
|
||||
k.foreign |= !declared(q, a);
|
||||
k.open += 1;
|
||||
return true;
|
||||
}
|
||||
let id = get(a, "form:id").or_else(|| get(a, "xml:id")).unwrap_or_default().to_string();
|
||||
if KEPT.contains(&q) && !id.is_empty() && self.controls.len() < MAX_CONTROLS {
|
||||
let name = get(a, "form:name").map(capped).unwrap_or_default();
|
||||
let label = get(a, "form:label").map(capped).filter(|l| !l.is_empty()).unwrap_or_else(|| name.clone());
|
||||
self.kept = Some(Kept { id, name, label, xml: element_xml(q, a), open: 1, foreign: !declared(q, a) });
|
||||
return true;
|
||||
}
|
||||
let name = get(a, "form:name").map(capped).unwrap_or_default();
|
||||
let value = || get(a, "form:current-value").or_else(|| get(a, "form:value")).map(capped).unwrap_or_default();
|
||||
let kind = match q {
|
||||
@@ -122,6 +180,23 @@ impl FormsReader {
|
||||
return false;
|
||||
}
|
||||
self.depth -= 1;
|
||||
if let Some(k) = &mut self.kept {
|
||||
k.xml.push_str(&format!("</{q}>"));
|
||||
k.open = k.open.saturating_sub(1);
|
||||
if k.open == 0
|
||||
&& let Some(k) = self.kept.take()
|
||||
{
|
||||
// Too long to keep whole, or naming what WordCraft can't write: not kept.
|
||||
if k.xml.len() <= MAX_KEPT && !k.foreign {
|
||||
let mut c = ContentControl::new(ControlKind::Text { multi_line: false });
|
||||
c.tag = k.name;
|
||||
c.lock = wordcraft_doc::control::ControlLock::ContentLocked;
|
||||
c.form_xml = k.xml;
|
||||
self.controls.insert(k.id, (c, k.label));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if matches!(
|
||||
q,
|
||||
"form:text" | "form:formatted-text" | "form:textarea" | "form:checkbox" | "form:radio" | "form:listbox" | "form:combobox" | "form:date"
|
||||
@@ -160,6 +235,19 @@ fn value(c: &ContentControl, text: &str) -> String {
|
||||
/// A content control as a form control in `office:forms`, with id `id`: the element, and the
|
||||
/// size of its `draw:control` (points). `None` for kinds a form has no control for.
|
||||
pub(in crate::odt) fn form_xml(c: &ContentControl, text: &str, id: &str, n: usize) -> Option<(String, f32, f32)> {
|
||||
let size = |(xml, w, h): (String, f32, f32)| {
|
||||
let fit = |v: f32| if v.is_finite() { v.clamp(1.0, 1584.0) } else { 16.0 };
|
||||
match c.form_size {
|
||||
Some([fw, fh]) => (xml, fit(fw), fit(fh)),
|
||||
None => (xml, w, h),
|
||||
}
|
||||
};
|
||||
// A control kept verbatim, with its new id.
|
||||
if !c.form_xml.is_empty() {
|
||||
let end = c.form_xml.find(|ch: char| ch.is_whitespace() || ch == '>')?;
|
||||
let (head, rest) = (c.form_xml.get(..end)?, c.form_xml.get(end..)?);
|
||||
return Some(size((format!("{head} xml:id=\"{id}\" form:id=\"{id}\"{rest}"), 72.0, 20.0)));
|
||||
}
|
||||
let name = if c.tag.is_empty() { format!("Control {n}") } else { c.tag.clone() };
|
||||
let common = format!(" form:name=\"{}\" xml:id=\"{id}\" form:id=\"{id}\"", x(&name));
|
||||
let label = if c.title.is_empty() { String::new() } else { format!(" form:label=\"{}\"", x(&c.title)) };
|
||||
@@ -228,7 +316,7 @@ pub(in crate::odt) fn form_xml(c: &ContentControl, text: &str, id: &str, n: usiz
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
Some(out)
|
||||
Some(size(out))
|
||||
}
|
||||
|
||||
/// The `office:forms` holding the controls `xml` (empty when there are none).
|
||||
|
||||
@@ -39,7 +39,9 @@ fn controls(flow: &crate::model::Flow) -> Vec<(ControlKind, String, String, Stri
|
||||
fn form_controls_open_as_content_controls() {
|
||||
let flow = parse(&package(&doc_xml(), None)).unwrap();
|
||||
let got = controls(&flow);
|
||||
assert_eq!(got.len(), 8, "the button and a missing control are left out: {got:?}");
|
||||
assert_eq!(got.len(), 9, "a missing control is left out: {got:?}");
|
||||
// A button, which WordCraft has no kind for, shows its label (see `buttons_are_kept`).
|
||||
assert_eq!((got[8].1.as_str(), got[8].3.as_str()), ("Submit", "Send"));
|
||||
assert_eq!(got[0], (ControlKind::Text { multi_line: false }, "FullName".into(), String::new(), "Ada Lovelace".into(), false));
|
||||
assert!(matches!(got[1].0, ControlKind::CheckBox { checked: true, checked_char: '\u{2612}', unchecked_char: '\u{2610}', .. }));
|
||||
assert_eq!((got[1].1.as_str(), got[1].2.as_str(), got[1].3.as_str()), ("Subscribe", "Yes please", "\u{2612}"));
|
||||
@@ -102,3 +104,56 @@ fn hostile_forms_are_bounded() {
|
||||
assert!(got.iter().all(|(k, ..)| k.items().is_none_or(|i| i.len() <= 1000)));
|
||||
assert!(got.len() <= 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn controls_keep_their_size() {
|
||||
let saved = export(&import(&package(&doc_xml(), None)).unwrap()).unwrap();
|
||||
let content = entry(&saved, "content.xml");
|
||||
// Each control 1in × 0.2in, as it was, not sized to its text.
|
||||
assert_eq!(content.matches(r#"svg:width="72pt" svg:height="14.4pt""#).count(), 9, "{content}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buttons_are_kept() {
|
||||
let button = r#"<form:button form:name="Go" form:control-implementation="ooo:com.sun.star.form.component.CommandButton" xml:id="b1" form:id="b1" form:label="Send & close" form:image-position="center"><form:properties><form:property form:property-name="DefaultControl" office:value-type="string" office:string-value="com.sun.star.form.control.CommandButton"/></form:properties></form:button>"#;
|
||||
let content = format!(
|
||||
r#"<office:document-content {NS_T} {NS_F}><office:body><office:text><office:forms><form:form form:name="Form">{button}</form:form></office:forms><text:p>Press <draw:control text:anchor-type="as-char" svg:width="1in" svg:height="0.3in" draw:control="b1"/></text:p></office:text></office:body></office:document-content>"#
|
||||
);
|
||||
let doc = import(&package(&content, None)).unwrap();
|
||||
// It shows its label, which can't be edited.
|
||||
let p = doc.body[0].as_para().unwrap();
|
||||
assert!(p.text.contains("Send & close"), "{:?}", p.text);
|
||||
let saved = export(&doc).unwrap();
|
||||
let c = entry(&saved, "content.xml");
|
||||
assert!(
|
||||
c.contains(r#"<form:button xml:id="control1" form:id="control1" form:name="Go" form:control-implementation="ooo:com.sun.star.form.component.CommandButton" form:label="Send & close" form:image-position="center"><form:properties><form:property form:property-name="DefaultControl""#),
|
||||
"{c}"
|
||||
);
|
||||
assert!(c.contains(r#"svg:width="72pt" svg:height="21.6pt" draw:control="control1""#), "{c}");
|
||||
// And again: still a button.
|
||||
let again = entry(&export(&import(&saved).unwrap()).unwrap(), "content.xml");
|
||||
assert_eq!(again.matches("<form:button ").count(), 1, "{again}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hostile_kept_controls_are_bounded() {
|
||||
let deep = format!("{}{}", "<form:properties>".repeat(5000), "</form:properties>".repeat(5000));
|
||||
let wide =
|
||||
r#"<form:property form:property-name="p" office:string-value="vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"/>"#
|
||||
.repeat(5000);
|
||||
let content = format!(
|
||||
r#"<office:document-content {NS_T} {NS_F}><office:body><office:text><office:forms><form:form><form:button form:id="a">{deep}</form:button><form:button form:id="b">{wide}</form:button><form:button form:label="no id"/><form:image form:id="c"><form:button form:id="d"/></form:image></form:form></office:forms><text:p><draw:control draw:control="a" svg:width="-1in" svg:height="1e40in"/><draw:control draw:control="b"/><draw:control draw:control="c"/><draw:control draw:control="d"/></text:p></office:text></office:body></office:document-content>"#
|
||||
);
|
||||
let doc = import(&package(&content, None)).unwrap();
|
||||
let c = entry(&export(&doc).unwrap(), "content.xml");
|
||||
// Too long to keep whole: left out; a control inside a kept one is part of it.
|
||||
assert_eq!(c.matches("<form:image ").count(), 1, "{c}");
|
||||
assert!(!c.contains(r#"office:string-value="vvvv"#), "the over-long button isn't kept");
|
||||
// One naming a namespace prefix the saved content doesn't declare isn't kept.
|
||||
let content = format!(
|
||||
r#"<office:document-content {NS_T} {NS_F}><office:body><office:text><office:forms><form:form><form:button form:id="a" xmlns:odd="urn:x"><odd:thing/></form:button><form:button form:id="b" odd:attr="1"/><form:button form:id="c"><office:event-listeners><script:event-listener script:language="ooo:script" script:event-name="dom:click" xlink:href="vnd.sun.star.script:x"/></office:event-listeners></form:button></form:form></office:forms><text:p><draw:control draw:control="a"/><draw:control draw:control="b"/><draw:control draw:control="c"/></text:p></office:text></office:body></office:document-content>"#
|
||||
);
|
||||
let c = entry(&export(&import(&package(&content, None)).unwrap()).unwrap(), "content.xml");
|
||||
assert_eq!(c.matches("<form:button ").count(), 1, "{c}");
|
||||
assert!(c.contains("<script:event-listener "), "{c}");
|
||||
}
|
||||
@@ -74,7 +74,11 @@ pub(super) const NS: &str = concat!(
|
||||
"xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" ",
|
||||
"xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\" ",
|
||||
"xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\" ",
|
||||
"xmlns:ooo=\"http://openoffice.org/2004/office\" ",
|
||||
"xmlns:ooow=\"http://openoffice.org/2004/writer\" ",
|
||||
"xmlns:oooc=\"http://openoffice.org/2004/calc\" ",
|
||||
"xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\" ",
|
||||
"xmlns:dom=\"http://www.w3.org/2001/xml-events\" ",
|
||||
"xmlns:loext=\"urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0\" ",
|
||||
"office:version=\"1.3\""
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# File-format parity with Microsoft Word
|
||||
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-01 · **Change:** trivial (ODT turned text in cells and text boxes); previously trivial (ODT macros and unknown package parts kept); previously trivial (ODT table cell formulas as formula fields); previously trivial (ODT custom shapes drawn from their own geometry); previously trivial (ODT bibliography marks as citations of sources); previously trivial (ODT linked text boxes); previously trivial (ODT picture crops and contour wrapping); previously trivial (ODT fidelity re-estimated at ~85%); previously trivial (ODT custom document properties and user fields as DOCPROPERTY); previously trivial (ODT connectors read and written glued); previously trivial (ODT borders around text read and written); previously trivial (ODT index marks read and written as XE fields; an index held around its entries updates); previously trivial (ODT ruby read and written); previously trivial (ODT page breaks after a paragraph, kept lines, widow control, hyphenation, table alignment and width and row heights); previously trivial (in-line drawings raised or lowered by their run's position; ODT in-line frames keep their place on the baseline; leading's space after the last line; text box borders shown by LibreOffice); previously trivial (ODT form controls opened and saved as content controls); previously trivial (password-protected ODT opened and saved); previously trivial (ODT headers and footers keep their shapes, text boxes, charts and embedded objects on save); previously trivial (ODT embedded spreadsheets and OLE objects kept whole instead of lost; flat ODT sub-documents valid `office:document`s); previously trivial (ODT charts in drawing groups drawn on open); previously trivial (ODT charts opened and saved as editable charts; flat ODT sub-documents no longer end the body); previously trivial (ODT leading read as an at-least spacing); previously trivial (ODT tracked formatting changes; changed regions named by `xml:id`); previously trivial (ODT drop caps; tab stops no longer drop a paragraph's background); previously 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 (Line truncated
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-01 · **Change:** trivial (ODT form control sizes and buttons kept); previously trivial (ODT turned text in cells and text boxes); previously trivial (ODT macros and unknown package parts kept); previously trivial (ODT table cell formulas as formula fields); previously trivial (ODT custom shapes drawn from their own geometry); previously trivial (ODT bibliography marks as citations of sources); previously trivial (ODT linked text boxes); previously trivial (ODT picture crops and contour wrapping); previously trivial (ODT fidelity re-estimated at ~85%); previously trivial (ODT custom document properties and user fields as DOCPROPERTY); previously trivial (ODT connectors read and written glued); previously trivial (ODT borders around text read and written); previously trivial (ODT index marks read and written as XE fields; an index held around its entries updates); previously trivial (ODT ruby read and written); previously trivial (ODT page breaks after a paragraph, kept lines, widow control, hyphenation, table alignment and width and row heights); previously trivial (in-line drawings raised or lowered by their run's position; ODT in-line frames keep their place on the baseline; leading's space after the last line; text box borders shown by LibreOffice); previously trivial (ODT form controls opened and saved as content controls); previously trivial (password-protected ODT opened and saved); previously trivial (ODT headers and footers keep their shapes, text boxes, charts and embedded objects on save); previously trivial (ODT embedded spreadsheets and OLE objects kept whole instead of lost; flat ODT sub-documents valid `office:document`s); previously trivial (ODT charts in drawing groups drawn on open); previously trivial (ODT charts opened and saved as editable charts; flat ODT sub-documents no longer end the body); previously trivial (ODT leading read as an at-least spacing); previously trivial (ODT tracked formatting changes; changed regions named by `xml:id`); previously trivial (ODT drop caps; tab stops no longer drop a paragraph's background); previously 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 wiLine truncated
|
||||
|
||||
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 (and flat `.fodt`) | 2% | R/W | 🟡 | 🟡 | ~85% | 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`, `odt_charts.rs`, `odt_objects.rs`, `odt_password.rs`, `odt_forms.rs`; checked against LibreOffice's own documents (round trips compared page by page) and the ODF 1.3 schema | Ruby (`text:ruby`, §6.4: a base text with ruby text over it) is read as WordCraft's Phonetic Guide and written back as ODF ruby above its base, centred (one inside a tracked change is written as its base text, which the change marks); its own position and alignment aren't kept. A border around text (LibreOffice's `loext:border` or its sides, with `loext:padding`: ODF 1.3 has no attribute for it) is Word's text border, one line all round, and is written back so (a document with one is then extended ODF, not strict). Emphasis marks (`style:text-emphasize`) and rotated text (`style:text-rotation-angle`) aren't read. How text flows: a page break after a paragraph (`fo:break-after`, a page break before the next paragraph as Word has it), lines kept together (`fo:keep-together`), widow and orphan control (`fo:widows`/`fo:orphans`: on with any line count, off with none; the counts themselves aren't kept) and hyphenation (`fo:hyphenate`, a paragraph's in ODF and the document's in WordCraft: a document with a hyphenated paragraph hyphenates, its other paragraphs opting out) are read and written; a table's alignment and width (`table:align`, `style:rel-width`, or `style:width` for an aligned table) and its rows' heights (`style:row-height` exact, `style:min-row-height` at least) are read and written. Form controls (`office:forms` controls placed by `draw:control`, ODF 1.3 §13) open as content controls — text fields and text areas as plain text controls, check boxes as check boxes, radio buttons as check boxes with round symbols, list boxes as drop-down lists, combo boxes as combo boxes, date fields as date controls, each with its value, entries and selection, its name as the control's tag and a label as its title — and content controls of those kinds in the body are written back as form controls LibreOffice shows with their values (in headers and footers, as their text); buttons, images, hidden and other controls aren't read, and a control's size and look aren't kept. Turned text (`style:writing-mode`, §20.404; LibreOffice's own `loext:writing-mode="bt-lr"` for text running upwards) in table cells and text boxes opens as WordCraft's cell and text box text direction, down or up, and is written back the same way; turned characters (`style:text-rotation-angle`) open upright, as WordCraft has no turned characters. Package parts WordCraft doesn't read — LibreOffice Basic macros and dialogs (`Basic/`, `Dialogs/`), `manifest.rdf`, other applications' files — are kept as they are and written back with their manifest entries, so LibreOffice still finds a document's macros (WordCraft never runs them); the old thumbnail and digital signatures (`META-INF/*signatures*.xml`, which sign the package as it was) are dropped on save, and paths that climb out of the package aren't written. Password-protected ODT (ODF 1.3 Part 2 §3.4) opens with its password — AES-256-CBC with a SHA-256 or SHA-1 start key and PBKDF2, as LibreOffice writes it; the old Blowfish encryption is refused with a message saying so — and a document opened with a password, or saved with one (Save with password), is written encrypted the way LibreOffice encrypts (every file but the `mimetype` and manifest; each with its own salt and initialisation vector; SHA-256 checksums), which LibreOffice opens with the password. 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 are Word's `XE` fields — a mark at a point (`text:alphabetical-index-mark`, its `text:key1`/`text:key2` the levels above its entry) and one over textLine truncated
|
||||
| `.odt` OpenDocument Text (and flat `.fodt`) | 2% | R/W | 🟡 | 🟡 | ~85% | 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`, `odt_charts.rs`, `odt_objects.rs`, `odt_password.rs`, `odt_forms.rs`; checked against LibreOffice's own documents (round trips compared page by page) and the ODF 1.3 schema | Ruby (`text:ruby`, §6.4: a base text with ruby text over it) is read as WordCraft's Phonetic Guide and written back as ODF ruby above its base, centred (one inside a tracked change is written as its base text, which the change marks); its own position and alignment aren't kept. A border around text (LibreOffice's `loext:border` or its sides, with `loext:padding`: ODF 1.3 has no attribute for it) is Word's text border, one line all round, and is written back so (a document with one is then extended ODF, not strict). Emphasis marks (`style:text-emphasize`) and rotated text (`style:text-rotation-angle`) aren't read. How text flows: a page break after a paragraph (`fo:break-after`, a page break before the next paragraph as Word has it), lines kept together (`fo:keep-together`), widow and orphan control (`fo:widows`/`fo:orphans`: on with any line count, off with none; the counts themselves aren't kept) and hyphenation (`fo:hyphenate`, a paragraph's in ODF and the document's in WordCraft: a document with a hyphenated paragraph hyphenates, its other paragraphs opting out) are read and written; a table's alignment and width (`table:align`, `style:rel-width`, or `style:width` for an aligned table) and its rows' heights (`style:row-height` exact, `style:min-row-height` at least) are read and written. Form controls (`office:forms` controls placed by `draw:control`, ODF 1.3 §13) open as content controls — text fields and text areas as plain text controls, check boxes as check boxes, radio buttons as check boxes with round symbols, list boxes as drop-down lists, combo boxes as combo boxes, date fields as date controls, each with its value, entries and selection, its name as the control's tag and a label as its title — and content controls of those kinds in the body are written back as form controls LibreOffice shows with their values (in headers and footers, as their text); a control keeps its size (`draw:control` `svg:width`/`svg:height`); buttons, image buttons, labels and the other controls WordCraft has no kind for show their label, locked, and are kept verbatim and written back as they were (one naming a namespace WordCraft doesn't declare is left out); hidden controls aren't read, and a control's look (colours, font) isn't kept. Turned text (`style:writing-mode`, §20.404; LibreOffice's own `loext:writing-mode="bt-lr"` for text running upwards) in table cells and text boxes opens as WordCraft's cell and text box text direction, down or up, and is written back the same way; turned characters (`style:text-rotation-angle`) open upright, as WordCraft has no turned characters. Package parts WordCraft doesn't read — LibreOffice Basic macros and dialogs (`Basic/`, `Dialogs/`), `manifest.rdf`, other applications' files — are kept as they are and written back with their manifest entries, so LibreOffice still finds a document's macros (WordCraft never runs them); the old thumbnail and digital signatures (`META-INF/*signatures*.xml`, which sign the package as it was) are dropped on save, and paths that climb out of the package aren't written. Password-protected ODT (ODF 1.3 Part 2 §3.4) opens with its password — AES-256-CBC with a SHA-256 or SHA-1 start key and PBKDF2, as LibreOffice writes it; the old Blowfish encryption is refused with a message saying so — and a document opened with a password, or saved with one (Save with password), is written encrypted the way LibreOffice encrypts (every file but the `mimetype` and manifest; each with its own salt and initialisation vector; SHA-256 checksums), which LibreOffice opens with the password. 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 updLine truncated
|
||||
| `.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 (`<html>`, `<!DOCTYPE html>`) 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 `</head>` tolerated (#154); the empty comments `<!-->` and `<!--->` end at once instead of swallowing the rest of the page (#5040). Header cells (`<th>`) 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 `<blockquote>` (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 `<ruby>base<rt>reading</rt></ruby>` in the base text's formatting and read back from `<ruby>`/`<rb>`/`<rt>` (`<rp>` 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 | ODT: form controls were sized to their text on save, and buttons and other controls WordCraft has no kind for were dropped; controls keep their size, and those controls show their label and are kept verbatim, so LibreOffice's button round-trips as a button (`odt::tests_more::forms::controls_keep_their_size`, `buttons_are_kept`, `hostile_kept_controls_are_bounded`) |
|
||||
| 2026-11-01 | trivial | ODT: text turned down or up in table cells and text boxes (`style:writing-mode`, `loext:writing-mode`) opened across; it opens and saves turned, and LibreOffice's turned cells render as LibreOffice draws them (`odt::tests_more::text_direction`) |
|
||||
| 2026-11-01 | trivial | ODT: package parts WordCraft doesn't read (LibreOffice Basic macros, `manifest.rdf`, other applications' files) were dropped on save; they are kept and written back with their manifest entries, and LibreOffice finds a round-tripped document's macro intact; thumbnails and signatures are dropped (`odt::tests_more::parts`) |
|
||||
| 2026-11-01 | trivial | ODT: table cell formulas (`table:formula`) were lost, leaving their value as text; LibreOffice's formulas open as Word formula fields that Update Field recalculates, and formula fields in cells are written back as cell formulas LibreOffice calculates (numbers in cells written as numbers, `ooow` declared); a LibreOffice table of sums round-trips with its text the same (`odt::tests_more::cell_formulas`, `odt_fields.rs::a_table_formula_updates_as_a_word_formula`) |
|
||||
|
||||
Reference in new issue
Block a user