mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-15 23:12:31 +00:00
ODT: fixed fields as locked fields with their values; sender fields
A fixed date or time (text:fixed) opens as a locked field and is written back fixed, with the value its text shows under its picture (text:date-value / text:time-value), which LibreOffice needs to keep it. One whose text can't be read back is written as text. Sender fields open as SENDER fields and are written back as text:sender-*. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GBVQLyDnrG8Tn1yDQcUabC
This commit is contained in:
12 files changed
+242
-32
No files matched your search
@@ -289,8 +289,8 @@ fn rich_inlines(doc: &Document, o: &InlineObject, f: &Fmt, opts: FlowOpts) -> Op
|
||||
InlineObject::FieldEnd if opts.fields => vec![Inline::FieldEnd],
|
||||
// Where a bookmark ends, so it covers its text (Word's `_GoBack` is the last edit's spot).
|
||||
InlineObject::BookmarkEnd { name } if opts.fields && name != "_GoBack" => vec![Inline::AnchorEnd(name.clone())],
|
||||
InlineObject::Field { instr, result, .. } if opts.fields => {
|
||||
vec![Inline::Field { instr: instr.clone(), result: result.clone(), fmt: f.clone() }]
|
||||
InlineObject::Field { instr, result, locked, .. } if opts.fields => {
|
||||
vec![Inline::Field { instr: instr.clone(), result: result.clone(), fmt: f.clone(), locked: *locked }]
|
||||
}
|
||||
_ => return None,
|
||||
})
|
||||
|
||||
@@ -569,13 +569,13 @@ impl<'a> Builder<'a> {
|
||||
append(&mut out, "", &CharProps { style: Some(style.into()), ..Default::default() }, Some(obj));
|
||||
}
|
||||
}
|
||||
Inline::Field { instr, result, fmt } => {
|
||||
Inline::Field { instr, result, fmt, locked } => {
|
||||
let cp = self.budget(char_props(fmt));
|
||||
let (instr, result) = (clean_text(instr), clean_text(result));
|
||||
if instr.trim().is_empty() {
|
||||
append(&mut out, &result, &cp, None);
|
||||
} else {
|
||||
let obj = InlineObject::Field { instr, result, locked: false, dirty: false, code: false, form: String::new() };
|
||||
let obj = InlineObject::Field { instr, result, locked: *locked, dirty: false, code: false, form: String::new() };
|
||||
append(&mut out, "", &cp, Some(obj));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,6 +232,8 @@ pub enum Inline {
|
||||
instr: String,
|
||||
result: String,
|
||||
fmt: Fmt,
|
||||
/// Its result is kept, not worked out again (Word's locked field, ODF's `text:fixed`).
|
||||
locked: bool,
|
||||
},
|
||||
/// A footnote or endnote: its custom mark (empty: numbered) and its content, without the
|
||||
/// note's own mark. Only flows asked for notes ([`FlowOpts::notes`]) hold them; formats
|
||||
|
||||
@@ -1102,7 +1102,7 @@ impl Body<'_> {
|
||||
&& let Some(set) = super::fields::set_instr(a)
|
||||
{
|
||||
let fmt = self.cur_fmt();
|
||||
self.push_inline(Inline::Field { instr: set, result: String::new(), fmt });
|
||||
self.push_inline(Inline::Field { instr: set, result: String::new(), fmt, locked: false });
|
||||
if get(a, "text:display").map(str::trim) == Some("none") {
|
||||
self.skip = 1;
|
||||
return true;
|
||||
@@ -1176,7 +1176,7 @@ impl Body<'_> {
|
||||
})
|
||||
.collect();
|
||||
if let Some(instr) = super::fields::xe_instr(k1.as_deref(), k2.as_deref(), &text) {
|
||||
let field = Inline::Field { instr, result: String::new(), fmt: Fmt::default() };
|
||||
let field = Inline::Field { instr, result: String::new(), fmt: Fmt::default(), locked: false };
|
||||
// Inside a run: split it there.
|
||||
let split = match p.inlines.get_mut(from) {
|
||||
Some(Inline::Text(t, f)) if off > 0 && t.is_char_boundary(off) && off < t.len() => {
|
||||
|
||||
@@ -103,7 +103,7 @@ impl Body<'_> {
|
||||
_ => None,
|
||||
};
|
||||
if let Some(FBlock::Para(p)) = titled {
|
||||
p.inlines.push(Inline::Field { instr, result: String::new(), fmt: Fmt::default() });
|
||||
p.inlines.push(Inline::Field { instr, result: String::new(), fmt: Fmt::default(), locked: false });
|
||||
return;
|
||||
}
|
||||
let Some(entries) = blocks.get_mut(start..) else { return };
|
||||
|
||||
@@ -334,11 +334,8 @@ impl Body<'_> {
|
||||
let at = if before.trim() == label { 0 } else { p.inlines.len() };
|
||||
p.inlines.insert(at, Inline::Anchor(name.clone()));
|
||||
}
|
||||
if fixed && !result.trim().is_empty() {
|
||||
p.push_text(&result, &fmt);
|
||||
} else {
|
||||
p.inlines.push(Inline::Field { instr, result: result.trim().to_string(), fmt });
|
||||
}
|
||||
// A fixed field keeps what it shows (§19.807 `text:fixed`): a locked field.
|
||||
p.inlines.push(Inline::Field { instr, result: result.trim().to_string(), fmt, locked: fixed && !result.trim().is_empty() });
|
||||
if let Some(name) = anchor {
|
||||
p.inlines.push(Inline::AnchorEnd(name));
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ pub(super) fn into_field(blocks: &mut [FBlock], instr: String) {
|
||||
}
|
||||
let fmt = p.inlines.iter().find_map(|i| if let Inline::Text(_, f) = i { Some(f.clone()) } else { None }).unwrap_or_default();
|
||||
let result: String = p.inlines.iter().filter_map(|i| if let Inline::Text(t, _) = i { Some(t.as_str()) } else { None }).collect();
|
||||
p.inlines = vec![Inline::Field { instr, result: result.trim().to_owned(), fmt }];
|
||||
p.inlines = vec![Inline::Field { instr, result: result.trim().to_owned(), fmt, locked: false }];
|
||||
}
|
||||
|
||||
/// The formula field a cell is, when it is one: its field code and the result it shows (a cell
|
||||
|
||||
@@ -222,3 +222,119 @@ pub(super) fn auto_ordered(parts: &[Part]) -> Vec<Part> {
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// English month names, in order; a month shown is its name or the start of it (three letters
|
||||
/// or more).
|
||||
const MONTHS: [&str; 12] = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"];
|
||||
|
||||
/// The value a date or time shown as `shown` under Word picture `pic` stands for, as a fixed
|
||||
/// field's `text:date-value` / `text:time-value` (§19.871, §19.880) state it: `YYYY-MM-DD`, with
|
||||
/// `Thh:mm:ss` when it shows a time (on 1899-12-30, ODF's day 0, when it shows no date). `None`
|
||||
/// when the text doesn't read under the picture (month names in another language, say).
|
||||
pub(super) fn value_shown(pic: &str, shown: &str) -> Option<String> {
|
||||
let parts = parts_of(pic);
|
||||
let s: Vec<char> = shown.trim().chars().take(MAX_PICTURE).collect();
|
||||
let mut i = 0usize;
|
||||
let (mut day, mut month, mut year) = (None, None, None);
|
||||
let (mut hour, mut minute, mut second, mut pm) = (None, None, 0u32, None);
|
||||
// A run of digits (at most `max`) or of letters at `i`.
|
||||
let digits = |i: &mut usize, max: usize| -> Option<u32> {
|
||||
let start = *i;
|
||||
while *i - start < max && s.get(*i).is_some_and(char::is_ascii_digit) {
|
||||
*i += 1;
|
||||
}
|
||||
s.get(start..*i).filter(|d| !d.is_empty())?.iter().collect::<String>().parse().ok()
|
||||
};
|
||||
let word = |i: &mut usize| -> String {
|
||||
let start = *i;
|
||||
while s.get(*i).is_some_and(|c| c.is_alphabetic()) {
|
||||
*i += 1;
|
||||
}
|
||||
s.get(start..*i).map(|w| w.iter().collect::<String>().to_lowercase()).unwrap_or_default()
|
||||
};
|
||||
for p in &parts {
|
||||
match p {
|
||||
Part::Text(t) => {
|
||||
for c in t.chars() {
|
||||
match s.get(i) {
|
||||
Some(&got) if got.eq_ignore_ascii_case(&c) => i += 1,
|
||||
// Spaces are loose: one shown where the picture has none, or none where it has one.
|
||||
Some(&got) if got.is_whitespace() => i += 1,
|
||||
_ if c.is_whitespace() => {}
|
||||
_ => return None,
|
||||
}
|
||||
}
|
||||
}
|
||||
Part::Day(_) => day = Some(digits(&mut i, 2)?),
|
||||
Part::Month(_, false) => month = Some(digits(&mut i, 2)?),
|
||||
Part::Month(_, true) => {
|
||||
let w = word(&mut i);
|
||||
let n = MONTHS.iter().position(|m| w.len() >= 3 && m.starts_with(w.as_str()))?;
|
||||
month = Some(u32::try_from(n).ok()? + 1);
|
||||
}
|
||||
Part::Year(_) => {
|
||||
let start = i;
|
||||
let y = digits(&mut i, 4)?;
|
||||
// Two digits: Word's window, 1930–2029.
|
||||
year = Some(if i - start <= 2 { if y < 30 { 2000 + y } else { 1900 + y } } else { y });
|
||||
}
|
||||
Part::Weekday(_) => {
|
||||
if word(&mut i).is_empty() {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Part::Hours(_) => hour = Some(digits(&mut i, 2)?),
|
||||
Part::Minutes(_) => minute = Some(digits(&mut i, 2)?),
|
||||
Part::Seconds(_) => second = digits(&mut i, 2)?,
|
||||
Part::AmPm => {
|
||||
let w = word(&mut i);
|
||||
pm = Some(match w.as_str() {
|
||||
"am" | "a" => false,
|
||||
"pm" | "p" => true,
|
||||
_ => return None,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if i < s.len() {
|
||||
return None;
|
||||
}
|
||||
let time = match (hour, minute) {
|
||||
(Some(h), m) => {
|
||||
let h = match pm {
|
||||
Some(true) if h < 12 => h + 12,
|
||||
Some(false) if h == 12 => 0,
|
||||
_ => h,
|
||||
};
|
||||
let m = m.unwrap_or(0);
|
||||
(h < 24 && m < 60 && second < 60).then(|| format!("T{h:02}:{m:02}:{second:02}"))?
|
||||
}
|
||||
(None, Some(_)) => return None,
|
||||
(None, None) => String::new(),
|
||||
};
|
||||
let date = match (year, month, day) {
|
||||
(Some(y), Some(m), Some(d)) if (1..=12).contains(&m) && (1..=31).contains(&d) && y <= 9999 => format!("{y:04}-{m:02}-{d:02}"),
|
||||
(None, None, None) if !time.is_empty() => "1899-12-30".to_string(),
|
||||
_ => return None,
|
||||
};
|
||||
Some(format!("{date}{time}"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod value_tests {
|
||||
use super::value_shown;
|
||||
|
||||
#[test]
|
||||
fn a_shown_date_or_time_reads_back_under_its_picture() {
|
||||
assert_eq!(value_shown("dddd, MMMM dd, yyyy", "Sunday, November 01, 2026").as_deref(), Some("2026-11-01"));
|
||||
assert_eq!(value_shown("dd/MM/yy", "03/11/26").as_deref(), Some("2026-11-03"));
|
||||
assert_eq!(value_shown("hh:mm AM/PM", "04:04 PM").as_deref(), Some("1899-12-30T16:04:00"));
|
||||
assert_eq!(value_shown("d MMM yyyy H:mm:ss", "5 Mar 1999 7:08:09").as_deref(), Some("1999-03-05T07:08:09"));
|
||||
// Not readable: another language's month, extra text, an impossible day, junk.
|
||||
assert_eq!(value_shown("d MMMM yyyy", "5 mars 2026"), None);
|
||||
assert_eq!(value_shown("d MMMM yyyy", "5 March 2026 and more"), None);
|
||||
assert_eq!(value_shown("dd/MM/yyyy", "45/11/2026"), None);
|
||||
assert_eq!(value_shown("dd/MM/yyyy", ""), None);
|
||||
assert_eq!(value_shown("", "anything"), None);
|
||||
}
|
||||
}
|
||||
@@ -35,13 +35,63 @@ const SIMPLE: &[(&str, &str)] = &[
|
||||
("print-date", "PRINTDATE"),
|
||||
];
|
||||
|
||||
/// The sender fields (§7.3.6 `text:sender-firstname` … §7.3.7 `text:sender-state-or-province`).
|
||||
const SENDER_PARTS: [&str; 18] = [
|
||||
"firstname",
|
||||
"lastname",
|
||||
"initials",
|
||||
"title",
|
||||
"position",
|
||||
"email",
|
||||
"phone-private",
|
||||
"fax",
|
||||
"company",
|
||||
"phone-work",
|
||||
"street",
|
||||
"city",
|
||||
"postal-code",
|
||||
"country",
|
||||
"state-or-province",
|
||||
"country-code",
|
||||
"street-number",
|
||||
"address",
|
||||
];
|
||||
|
||||
/// `el`, a field element, fixed at what it shows (§19.807 `text:fixed`), for the fields that can
|
||||
/// be.
|
||||
/// Field element `el` for locked field `instr` showing `result`, fixed (see [`fixed`]). A date
|
||||
/// or time is fixed at the value its text shows under its picture (§19.871, §19.880); `None`
|
||||
/// when that can't be read, as a reader shows a fixed date without a value as today's (then it
|
||||
/// is written as its text).
|
||||
pub(super) fn locked(el: &str, instr: &str, result: &str) -> Option<String> {
|
||||
let code = instr.split_whitespace().next().unwrap_or("").to_ascii_uppercase();
|
||||
let attr = match code.as_str() {
|
||||
"DATE" => "text:date-value",
|
||||
"TIME" => "text:time-value",
|
||||
_ => return Some(fixed(el)),
|
||||
};
|
||||
let value = super::datastyle::picture_of(instr).and_then(|pic| super::datastyle::value_shown(&pic, result))?;
|
||||
let el = fixed(el);
|
||||
let (tag, rest) = el.find(['>', ' ']).and_then(|at| Some((el.get(..at)?, el.get(at..)?)))?;
|
||||
Some(format!("{tag} {attr}=\"{value}\"{rest}"))
|
||||
}
|
||||
|
||||
pub(super) fn fixed(el: &str) -> String {
|
||||
const FIXABLE: [&str; 6] = ["<text:date", "<text:time", "<text:author-name", "<text:author-initials", "<text:sender-", "<text:file-name"];
|
||||
if !FIXABLE.iter().any(|f| el.starts_with(f)) {
|
||||
return el.to_string();
|
||||
}
|
||||
match el.find(['>', ' ']).and_then(|at| Some((el.get(..at)?, el.get(at..)?))) {
|
||||
Some((tag, rest)) => format!("{tag} text:fixed=\"true\"{rest}"),
|
||||
None => el.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The Word field code for the `text:` field element `local` with attributes `a`, or `None`
|
||||
/// when it is no field WordCraft keeps (then its text is read as text).
|
||||
pub(super) fn instr_of(local: &str, a: &Attrs, picture: impl Fn(&str) -> Option<String>) -> Option<String> {
|
||||
// Fixed, unless it holds no value to be fixed at (LibreOffice's templates: a date that shows
|
||||
// the day the document is made from them).
|
||||
let fixed =
|
||||
get(a, "text:fixed").is_some_and(|v| v.trim() == "true") && (get(a, "text:date-value").is_some() || get(a, "text:time-value").is_some());
|
||||
// A name a field code can hold as one word.
|
||||
let name = |k: &str| {
|
||||
get(a, k)
|
||||
@@ -112,7 +162,9 @@ pub(super) fn instr_of(local: &str, a: &Attrs, picture: impl Fn(&str) -> Option<
|
||||
_ => format!("REF {name} \\h"),
|
||||
})
|
||||
}
|
||||
_ if fixed => None,
|
||||
// The sender's details (§7.3.6–7.3.7), from the application's user data: WordCraft's
|
||||
// own `SENDER` field code, shown as its last result.
|
||||
_ if local.strip_prefix("sender-").is_some_and(|p| SENDER_PARTS.contains(&p)) => local.strip_prefix("sender-").map(|p| format!("SENDER {p}")),
|
||||
_ => {
|
||||
let code = SIMPLE.iter().find(|(e, _)| *e == local).map(|(_, code)| code.to_string())?;
|
||||
// A date or time in its date style (§19.473 `style:data-style-name`).
|
||||
@@ -131,6 +183,10 @@ pub(super) fn element(instr: &str, result: &str, data_style: Option<&str>) -> Op
|
||||
let mut words = instr.split_whitespace();
|
||||
let code = words.next()?.to_ascii_uppercase();
|
||||
match code.as_str() {
|
||||
"SENDER" => {
|
||||
let part = words.next().filter(|p| SENDER_PARTS.contains(p))?;
|
||||
Some(format!("<text:sender-{part}>{result}</text:sender-{part}>"))
|
||||
}
|
||||
"SEQ" => {
|
||||
let seq = words.next().filter(|n| !n.starts_with('\\') && n.len() <= MAX_REF_NAME)?;
|
||||
let fmt = match switch_arg(instr, '*').as_deref() {
|
||||
|
||||
@@ -57,10 +57,29 @@ fn fields_open_as_fields_with_their_shown_text() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_fixed_date_and_unknown_fields_are_plain_text() {
|
||||
fn a_fixed_date_is_a_locked_field_and_unknown_fields_are_plain_text() {
|
||||
// A fixed date (§19.807 `text:fixed`) keeps what it shows: a locked field, written back fixed.
|
||||
let d = import(&body(r#"<text:p><text:date text:fixed="true">1 May</text:date>, <text:conditional-text text:condition="ooow:1" text:string-value-if-true="4" text:string-value-if-false="5">4</text:conditional-text>, <text:page-number text:select-page="next">5</text:page-number></text:p>"#)).unwrap();
|
||||
assert!(fields(&d).is_empty());
|
||||
assert_eq!(d.body[0].as_para().unwrap().text, "1 May, 4, 5");
|
||||
assert_eq!(fields(&d), [("DATE".to_string(), "1 May".to_string())]);
|
||||
let locked = d.body[0].as_para().unwrap().objects.iter().any(|o| matches!(o, InlineObject::Field { locked: true, .. }));
|
||||
assert!(locked);
|
||||
// Written back: with no picture to read its value under, as its text (a reader would show a
|
||||
// fixed date without a value as today's).
|
||||
let c = crate::odt::tests::content_of(&export(&d).unwrap());
|
||||
assert!(!c.contains("<text:date") && c.contains("1 May"), "{c}");
|
||||
// With a picture, fixed at the value it shows (§19.871).
|
||||
let n = r#"xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0""#;
|
||||
let d = import(&package(
|
||||
&format!(
|
||||
r#"<office:document-content {NS_T} {n}><office:automatic-styles><number:date-style style:name="N1"><number:day/><number:text> </number:text><number:month number:style="long" number:textual="true"/><number:text> </number:text><number:year number:style="long"/></number:date-style><number:time-style style:name="N2"><number:hours number:style="long"/><number:text>:</number:text><number:minutes number:style="long"/></number:time-style></office:automatic-styles><office:body><office:text><text:p><text:date text:fixed="true" style:data-style-name="N1" text:date-value="2026-05-01">1 May 2026</text:date> <text:time text:fixed="true" style:data-style-name="N2" text:time-value="2026-05-01T14:30:00">14:30</text:time></text:p></office:text></office:body></office:document-content>"#
|
||||
),
|
||||
None,
|
||||
))
|
||||
.unwrap();
|
||||
let c = crate::odt::tests::content_of(&export(&d).unwrap());
|
||||
assert!(c.contains(r#"text:date-value="2026-05-01""#) && c.contains(">1 May 2026</text:date>"), "{c}");
|
||||
assert!(c.contains(r#"text:time-value="1899-12-30T14:30:00""#) && c.contains(">14:30</text:time>"), "{c}");
|
||||
assert_eq!(c.matches(r#"text:fixed="true""#).count(), 2, "{c}");
|
||||
// A fixed date with neither a value nor text (LibreOffice's templates) shows the day: a
|
||||
// date field.
|
||||
let d = import(&body(r#"<text:p><text:date text:fixed="true"/>.</text:p>"#)).unwrap();
|
||||
@@ -320,3 +339,19 @@ fn user_fields_stay_user_fields() {
|
||||
let back = import(&saved).unwrap();
|
||||
assert_eq!(back.custom_props, d.custom_props);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sender_fields_stay_fields() {
|
||||
// LibreOffice's letter and fax templates: the sender's details (§7.3.6), shown as last filled
|
||||
// in (WordCraft's `SENDER` field code), written back as the same fields.
|
||||
let d = import(&body(r#"<text:p><text:sender-firstname>Ada</text:sender-firstname> <text:sender-lastname>Lovelace</text:sender-lastname>, <text:sender-email>ada@example.org</text:sender-email></text:p>"#)).unwrap();
|
||||
assert_eq!(
|
||||
fields(&d),
|
||||
[("SENDER firstname".into(), "Ada".into()), ("SENDER lastname".into(), "Lovelace".into()), ("SENDER email".into(), "ada@example.org".into())]
|
||||
);
|
||||
let c = crate::odt::tests::content_of(&export(&d).unwrap());
|
||||
assert!(
|
||||
c.contains("<text:sender-firstname>Ada</text:sender-firstname>") && c.contains("<text:sender-email>ada@example.org</text:sender-email>"),
|
||||
"{c}"
|
||||
);
|
||||
}
|
||||
@@ -449,20 +449,23 @@ impl Writer {
|
||||
// A field around content: an index's is its element (see `index_at`).
|
||||
Inline::FieldStart(_) | Inline::FieldEnd => {}
|
||||
Inline::CommentEnd(id) => out.push_str(&format!("<office:annotation-end office:name=\"{}\"/>", annotation_name(self.prefix, *id))),
|
||||
Inline::Field { instr, result, fmt } => match self.field_element(instr, result) {
|
||||
Some(el) => {
|
||||
match self.text_style(&Fmt { link: None, ..fmt.clone() }) {
|
||||
Some(n) => out.push_str(&format!("<text:span text:style-name=\"{n}\">{el}</text:span>")),
|
||||
None => out.push_str(&el),
|
||||
Inline::Field { instr, result, fmt, locked } => {
|
||||
match self.field_element(instr, result).and_then(|el| if *locked { super::fields::locked(&el, instr, result) } else { Some(el) })
|
||||
{
|
||||
Some(el) => {
|
||||
match self.text_style(&Fmt { link: None, ..fmt.clone() }) {
|
||||
Some(n) => out.push_str(&format!("<text:span text:style-name=\"{n}\">{el}</text:span>")),
|
||||
None => out.push_str(&el),
|
||||
}
|
||||
prev_space = false;
|
||||
}
|
||||
// No ODF field for it: what it shows, as text.
|
||||
None => {
|
||||
self.plain_inlines(&[Inline::Text(result.clone(), fmt.clone())], out);
|
||||
prev_space = result.ends_with(' ');
|
||||
}
|
||||
prev_space = false;
|
||||
}
|
||||
// No ODF field for it: what it shows, as text.
|
||||
None => {
|
||||
self.plain_inlines(&[Inline::Text(result.clone(), fmt.clone())], out);
|
||||
prev_space = result.ends_with(' ');
|
||||
}
|
||||
},
|
||||
}
|
||||
// Inside a tracked change: its base text, which the text path marks as changed.
|
||||
Inline::Ruby { base, fmt, .. } if fmt.ins.is_some() || fmt.del.is_some() => {
|
||||
self.plain_inlines(&[Inline::Text(base.clone(), fmt.clone())], out);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# File-format parity with Microsoft Word
|
||||
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-03 · **Change:** trivial (ODT: table styles saved into their cells; ODT tables carry no Word table style; section column balance); previously trivial (ODT interpretation profile: the standard is law, what it leaves open (including unstated page margins) follows WordCraft, LibreOffice or custom settings); previously trivial (ODT form controls keep their place on the line and text areas their lines; custom shapes keep their geometry); previously trivial (ODT in-line frames placed against the text; in-line pictures saved standing on the baseline); previously trivial (ODT charts written back as they were while unchanged; frames' drawn outline; default header height); previously trivial (ODT header rows only where they repeat); previously trivial (ODT padding without a border; unequal columns; column breaks); previously trivial (ODT lines of only pictures laid out as LibreOffice does; default page without a layout); previously trivial (ODT pictures alone in a paragraph keep its size; in-line frames raised under an inherited paragraph relation); previously trivial (ODT tables fit the margins and keep their space above and below; header spacing kept); previously trivial (ODT frames anchored and placed by their style); previously trivial (ODT default font size saved; page-anchored frames placed from the page; text box paragraph styles kept; empty paragraphs keep their size); previously trivial (ODT default font size; locale-ordered dates); previously trivial (ODT page background pictures); previously trivial (ODT tables fixed layout; tables starting a page); previously trivial (emphasis marks: model, layout, DOCX `w:em`, ODT `style:text-emphasize`, `format.emphasisMark`); previously trivial (ODT variables as SET/REF fields; character styles keep what they turn off); previously trivial (ODT styles keep what they turn off; WMF/EMF pictures kept; pictures in text boxes shown by LibreOffice); previously trivial (ODT unstated page margins are LibreOffice's 2 cm; drawings outside a paragraph join the next one); previously trivial (ODT placeholders as content controls, template dates, user name fields, unsized pages, style-only templates, found with LibreOffice's own templates); previously trivial (ODT hidden form controls kept; `.ott` templates opened and saved); previously trivial (ODT fidelity re-estimated at ~90%; a kept form control made another kind is saved as that kind); previously 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); previousLine truncated
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-03 · **Change:** trivial (ODT fixed and sender fields); previously trivial (ODT: table styles saved into their cells; ODT tables carry no Word table style; section column balance); previously trivial (ODT interpretation profile: the standard is law, what it leaves open (including unstated page margins) follows WordCraft, LibreOffice or custom settings); previously trivial (ODT form controls keep their place on the line and text areas their lines; custom shapes keep their geometry); previously trivial (ODT in-line frames placed against the text; in-line pictures saved standing on the baseline); previously trivial (ODT charts written back as they were while unchanged; frames' drawn outline; default header height); previously trivial (ODT header rows only where they repeat); previously trivial (ODT padding without a border; unequal columns; column breaks); previously trivial (ODT lines of only pictures laid out as LibreOffice does; default page without a layout); previously trivial (ODT pictures alone in a paragraph keep its size; in-line frames raised under an inherited paragraph relation); previously trivial (ODT tables fit the margins and keep their space above and below; header spacing kept); previously trivial (ODT frames anchored and placed by their style); previously trivial (ODT default font size saved; page-anchored frames placed from the page; text box paragraph styles kept; empty paragraphs keep their size); previously trivial (ODT default font size; locale-ordered dates); previously trivial (ODT page background pictures); previously trivial (ODT tables fixed layout; tables starting a page); previously trivial (emphasis marks: model, layout, DOCX `w:em`, ODT `style:text-emphasize`, `format.emphasisMark`); previously trivial (ODT variables as SET/REF fields; character styles keep what they turn off); previously trivial (ODT styles keep what they turn off; WMF/EMF pictures kept; pictures in text boxes shown by LibreOffice); previously trivial (ODT unstated page margins are LibreOffice's 2 cm; drawings outside a paragraph join the next one); previously trivial (ODT placeholders as content controls, template dates, user name fields, unsized pages, style-only templates, found with LibreOffice's own templates); previously trivial (ODT hidden form controls kept; `.ott` templates opened and saved); previously trivial (ODT fidelity re-estimated at ~90%; a kept form control made another kind is saved as that kind); previously 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 triLine 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;
|
||||
@@ -285,6 +285,7 @@ Custom document properties retain their bookmark link targets through DOCX saves
|
||||
| 2026-11-02 | trivial | ODT: a chart lost the look WordCraft doesn't model (its fonts and sizes, axis and grid lines) on save, written anew from WordCraft's chart. The chart object as read is kept (through drawing it again when it opens or is resized), and written back whole while the chart reads the same; an edited chart is written from WordCraft's chart as before. The chart documents round-trip pixel-identical (`charts::an_unchanged_chart_is_written_back_as_it_was_and_an_edited_one_anew`, `engine::tests::redrawing_a_chart_keeps_the_chart_as_read`). Found with LibreOffice's serif business letter: a text frame outlined by its drawn stroke (`draw:stroke`, no `fo:border`) lost its outline; it's the frame's line. A header or footer whose style states no height (or that has none) was 0 tall; it's LibreOffice's 0.5 cm (measured), so the text no longer moves up. The letter round-trips to 116 differing pixels (from 4,223) (`text_boxes::a_frames_drawn_stroke_is_its_line_when_it_has_no_border`, `headers::a_header_without_a_stated_height_is_half_a_centimetre`) |
|
||||
| 2026-11-02 | trivial | ODT, found with LibreOffice's agendas: saving wrote every table's first row as a header row (`table:table-header-rows`), repeated at the top of each page, because a table style's header row (on by default in Word's table look) was taken for Repeat as header row; a table crossing a page showed its first row twice. Only rows set to repeat are written so. The agendas round-trip to about 145 differing pixels (from 5,269 and 5,086), their text the same (`tables::only_rows_set_to_repeat_are_written_as_header_rows`) |
|
||||
| 2026-11-02 | trivial | ODT, found with LibreOffice's report templates and one-page résumé. A paragraph's padding on a side without a border (measured: LibreOffice gives it room) was dropped; it's kept, laid out (see layout-parity) and written back. Unequal columns (`style:column` `style:rel-width` and indents, on pages and sections) were made equal; they keep their widths, written back as shares, without the gap LibreOffice ignores them beside. Columns with no stated gap have none (it had been Word's 0.5 in). A paragraph starting a column (`fo:break-before="column"`) didn't; it starts with Word's column break, written back on the paragraph. The report templates round-trip to 0–11 differing pixels (from 9,600), the résumé to 24 (from 6,286) (`para_borders::padding_without_a_border_keeps_its_room`, `odt::tests::unequal_columns_keep_their_widths_and_columns_without_a_gap_have_none`, `odt::tests::a_paragraph_starting_a_column_starts_with_a_column_break`) |
|
||||
| 2026-11-03 | trivial | ODT fixed fields (§19.807 `text:fixed`) open as locked fields and are written back fixed, a date or time with the value its text shows under its picture (`text:date-value`, `text:time-value`, which LibreOffice needs to keep it); one whose text can't be read back is written as its text. Sender fields (§7.3.6 `text:sender-*`) open as `SENDER` fields and are written back as themselves. |
|
||||
| 2026-11-03 | trivial | ODT user fields (§7.4.7 `text:user-field-decl`, §7.4.9 `text:user-field-get`; LibreOffice's report templates) are written back as user fields, with their declared values in the content, instead of as document properties (`CustomProp::odf_user_field`). |
|
||||
| 2026-11-03 | trivial | ODT, found by a loss check that compares what a file uses with what WordCraft writes back: each font is now declared (`office:font-face-decls`, §16.21: family, generic family, pitch) and named where used (`style:font-name`), so a reader without it picks a like one; who changed the document last, when, and how often it was saved (`dc:creator`, `dc:date`, `meta:editing-cycles`) are read into and written from the document's properties. |
|
||||
| 2026-11-03 | trivial | ODT, found with Google Docs' and ONLYOFFICE's files (now in the corpus): a heading's look comes from its style and its outline level from its element, so a `text:h` without `text:outline-level` (level 1, §19.850.4) in a style based on Heading 2 looks as Heading 2, as LibreOffice draws it, and stays level 1 (it became Heading 1). Widow and orphan control is stated in the default paragraph style (`fo:widows`/`fo:orphans` 2) when Normal has it, since LibreOffice reads none unsaid as off. Google's 2011 Fundamentals export now round-trips with its 88 pages and text (1.27M → 139k differing pixels). |
|
||||
|
||||
Reference in new issue
Block a user