mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-02 02:37:26 -06:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a8e4ac2d3 | ||
|
|
f722a2f80b | ||
|
|
cac0dd2ee0 | ||
|
|
0ef496019a | ||
|
|
0b1117c87f | ||
|
|
110852a379 | ||
|
|
17b26e39cc | ||
|
|
0345dd28f3 | ||
|
|
959bc54505 | ||
|
|
791e144fd7 | ||
|
|
6ce224d4b3 | ||
|
|
20b8ce57a8 | ||
|
|
9f34d3790e |
@@ -443,7 +443,11 @@ fn diff_blocks(doc: &mut Document, old: &[Arc<Block>], new: &[Arc<Block>], ctx:
|
||||
(Some(Block::Para(pa)), Some(Block::Para(pb))) => out.push(para_block(word_diff(doc, pa, pb, ctx))),
|
||||
_ => {
|
||||
if let Some(x) = a {
|
||||
out.push(Arc::new(mark_block(x, &|c| c.del = Some(ctx.del))));
|
||||
out.push(Arc::new(mark_block(x, &|c| {
|
||||
// An existing deletion is another author's: keep their revision
|
||||
// stamp instead of re-attributing the paragraph to this compare.
|
||||
c.del.get_or_insert(ctx.del);
|
||||
})));
|
||||
}
|
||||
if let Some(x) = b {
|
||||
out.push(Arc::new(mark_block(x, &|c| c.ins = Some(ctx.ins))));
|
||||
@@ -1613,8 +1617,17 @@ fn block_text(b: &Block, depth: usize) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a copy of `b` with all text runs and paragraph marks across all nested table cells
|
||||
/// updated by `f` iteratively, without recursion or depth truncation.
|
||||
/// A copy of the block with every run (in tables, every cell's) changed by `f`, and a paragraph's
|
||||
/// mark along with them, so a whole inserted or deleted paragraph carries the revision even when
|
||||
/// the paragraph is empty (`format` returns early for a length-0 range). Walks nested tables
|
||||
/// iteratively, without recursion or depth truncation.
|
||||
///
|
||||
/// Known limitation: resolving a revision needs a following paragraph, so a paragraph inserted at
|
||||
/// the very end (rejected) or deleted from the very end (accepted) still leaves one empty
|
||||
/// paragraph. That is a separate follow-up, not handled here. A section-carrying inserted
|
||||
/// paragraph is not such a case: `resolve_para` removes the section break first (#5734, issue
|
||||
/// #5667), so rejecting it takes the paragraph out whole and the following paragraph keeps its
|
||||
/// own properties.
|
||||
fn mark_block(b: &Block, f: &dyn Fn(&mut CharProps)) -> Block {
|
||||
let mut out = b.clone();
|
||||
let mut todo = vec![&mut out];
|
||||
|
||||
@@ -11,6 +11,196 @@ fn compare_marks_changes() {
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "The dog sat.\nKeep this.\nNew line here.");
|
||||
}
|
||||
|
||||
/// Top-level body blocks that are empty paragraphs.
|
||||
fn empty_paras(s: &Session) -> usize {
|
||||
s.doc.body.iter().filter(|b| matches!(b.as_para(), Some(p) if p.is_empty())).count()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compare_marks_a_whole_paragraph_and_its_mark() {
|
||||
// A whole inserted paragraph carries the insertion on its mark, not just on its runs.
|
||||
let mut s = Session::new(Document::from_text("A\nB"));
|
||||
s.run("review.compare", &json!({"text": "A\nNEW\nB"})).unwrap();
|
||||
assert_eq!(s.doc.body.len(), 3);
|
||||
let mid = s.doc.body[1].as_para().unwrap();
|
||||
assert_eq!(mid.plain_text(), "NEW");
|
||||
assert!(mid.mark.ins.is_some(), "the inserted paragraph's mark is not marked inserted");
|
||||
s.run("review.rejectAll", &json!({})).unwrap();
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nB");
|
||||
assert_eq!(s.doc.body.len(), 2);
|
||||
assert_eq!(empty_paras(&s), 0, "rejecting an inserted paragraph left an empty paragraph behind");
|
||||
let mut s = Session::new(Document::from_text("A\nB"));
|
||||
s.run("review.compare", &json!({"text": "A\nNEW\nB"})).unwrap();
|
||||
s.run("review.acceptAll", &json!({})).unwrap();
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nNEW\nB");
|
||||
assert_eq!(s.doc.body.len(), 3);
|
||||
assert_eq!(empty_paras(&s), 0, "accepting an inserted paragraph left an empty paragraph behind");
|
||||
|
||||
// A whole deleted paragraph carries the deletion on its mark.
|
||||
let mut s = Session::new(Document::from_text("A\nOLD\nB"));
|
||||
s.run("review.compare", &json!({"text": "A\nB"})).unwrap();
|
||||
assert_eq!(s.doc.body.len(), 3);
|
||||
let mid = s.doc.body[1].as_para().unwrap();
|
||||
assert_eq!(mid.plain_text(), "OLD");
|
||||
assert!(mid.mark.del.is_some(), "the deleted paragraph's mark is not marked deleted");
|
||||
s.run("review.acceptAll", &json!({})).unwrap();
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nB");
|
||||
assert_eq!(s.doc.body.len(), 2);
|
||||
assert_eq!(empty_paras(&s), 0, "accepting a deleted paragraph left an empty paragraph behind");
|
||||
let mut s = Session::new(Document::from_text("A\nOLD\nB"));
|
||||
s.run("review.compare", &json!({"text": "A\nB"})).unwrap();
|
||||
s.run("review.rejectAll", &json!({})).unwrap();
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nOLD\nB");
|
||||
assert_eq!(s.doc.body.len(), 3);
|
||||
assert_eq!(empty_paras(&s), 0, "rejecting a deleted paragraph left an empty paragraph behind");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compare_marks_an_empty_paragraphs_mark() {
|
||||
// An empty inserted paragraph is stamped on its mark, though `format` skips its empty range.
|
||||
let mut s = Session::new(Document::from_text("A\nB"));
|
||||
s.run("review.compare", &json!({"text": "A\n\nB"})).unwrap();
|
||||
assert_eq!(s.doc.body.len(), 3);
|
||||
let empty = s.doc.body[1].as_para().unwrap();
|
||||
assert!(empty.is_empty());
|
||||
assert!(empty.mark.ins.is_some(), "the empty inserted paragraph's mark is not marked inserted");
|
||||
s.run("review.rejectAll", &json!({})).unwrap();
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nB");
|
||||
assert_eq!(s.doc.body.len(), 2);
|
||||
assert_eq!(empty_paras(&s), 0, "rejecting an empty inserted paragraph left it behind");
|
||||
|
||||
// An empty deleted paragraph is stamped on its mark too.
|
||||
let mut s = Session::new(Document::from_text("A\n\nB"));
|
||||
s.run("review.compare", &json!({"text": "A\nB"})).unwrap();
|
||||
assert_eq!(s.doc.body.len(), 3);
|
||||
let empty = s.doc.body[1].as_para().unwrap();
|
||||
assert!(empty.is_empty());
|
||||
assert!(empty.mark.del.is_some(), "the empty deleted paragraph's mark is not marked deleted");
|
||||
s.run("review.acceptAll", &json!({})).unwrap();
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nB");
|
||||
assert_eq!(s.doc.body.len(), 2);
|
||||
assert_eq!(empty_paras(&s), 0, "accepting an empty deleted paragraph left it behind");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compare_keeps_another_authors_deletion_stamp() {
|
||||
// A paragraph the original already carries as a tracked deletion by another author: Compare
|
||||
// must keep that author's revision on its runs and on its paragraph mark, not re-attribute
|
||||
// the block to its own deletion revision.
|
||||
let mut doc = Document::from_text("A\nOLD\nB");
|
||||
doc.revisions.push(wordcraft_doc::Revision::new(RevisionKind::Delete, "Alice", ""));
|
||||
let p = doc.para_mut(StoryRef::Body, &wordcraft_doc::Path::top(1)).unwrap();
|
||||
for r in &mut p.runs {
|
||||
r.props.del = Some(0);
|
||||
}
|
||||
p.mark.del = Some(0);
|
||||
let mut s = Session::new(doc);
|
||||
s.run("review.compare", &json!({"text": "A\nB", "author": "Bob"})).unwrap();
|
||||
assert_eq!(s.doc.body.len(), 3);
|
||||
let mid = s.doc.body[1].as_para().unwrap();
|
||||
assert_eq!(mid.plain_text(), "OLD");
|
||||
assert!(mid.runs.iter().all(|r| r.props.del == Some(0)), "the runs' deletion was re-stamped: {:?}", mid.runs);
|
||||
assert_eq!(mid.mark.del, Some(0), "the paragraph mark's deletion was re-stamped");
|
||||
assert_eq!(s.doc.revisions.first().map(|r| (r.kind, r.author.as_str())), Some((RevisionKind::Delete, "Alice")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compare_pins_the_terminal_inserted_paragraph_limitation() {
|
||||
// Characterizes the limitation documented on `mark_block` (compare.rs): resolving a revision
|
||||
// needs a following paragraph, so a paragraph inserted at the very end is rejected but leaves
|
||||
// one empty paragraph behind. Flip this test when the follow-up fix lands.
|
||||
let mut s = Session::new(Document::from_text("A\nB"));
|
||||
s.run("review.compare", &json!({"text": "A\nB\nC"})).unwrap();
|
||||
assert_eq!(s.doc.body.len(), 3);
|
||||
s.run("review.rejectAll", &json!({})).unwrap();
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nB\n", "the rejected terminal paragraph still leaves a line");
|
||||
assert_eq!(s.doc.body.len(), 3);
|
||||
assert_eq!(empty_paras(&s), 1, "the rejected terminal paragraph is left as one empty paragraph");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compare_pins_the_terminal_deleted_paragraph_limitation() {
|
||||
// The mirror of `compare_pins_the_terminal_inserted_paragraph_limitation`: a paragraph deleted
|
||||
// from the very end is accepted but still leaves one empty paragraph. Characterizes the
|
||||
// limitation documented on `mark_block` (compare.rs); flip when the follow-up fix lands.
|
||||
let mut s = Session::new(Document::from_text("A\nB\nC"));
|
||||
s.run("review.compare", &json!({"text": "A\nB"})).unwrap();
|
||||
assert_eq!(s.doc.body.len(), 3);
|
||||
s.run("review.acceptAll", &json!({})).unwrap();
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nB\n", "the accepted terminal deletion still leaves a line");
|
||||
assert_eq!(s.doc.body.len(), 3);
|
||||
assert_eq!(empty_paras(&s), 1, "the accepted terminal deletion is left as one empty paragraph");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compare_pins_rejecting_an_inserted_section_keeps_the_next_paragraphs_style() {
|
||||
// Pins the fixed behaviour for rejecting an inserted paragraph that carries a section
|
||||
// break. This was a known limitation recorded on `mark_block` (compare.rs): `resolve`'s
|
||||
// `remove_empty_para` refused paragraphs carrying a section, so once the inserted
|
||||
// paragraph's text was rejected the empty paragraph was joined into the next one, which
|
||||
// took its properties ("Body" came back Normal instead of its original Heading 1). Fixed
|
||||
// on main by #5734 (issue #5667): `resolve_para` now removes the section break first, so
|
||||
// the empty paragraph goes whole and the following paragraph keeps its own properties.
|
||||
// After Reject All the original is restored exactly.
|
||||
let mut original = Document::from_text("Intro\nBody");
|
||||
original.para_mut(StoryRef::Body, &wordcraft_doc::Path::top(1)).unwrap().props.style = Some("Heading1".into());
|
||||
let mut s = Session::new(original);
|
||||
|
||||
let mut rev = Document::from_text("Intro\nAppendix\nBody");
|
||||
{
|
||||
let p = rev.para_mut(StoryRef::Body, &wordcraft_doc::Path::top(1)).unwrap();
|
||||
p.props.style = Some("Normal".into());
|
||||
p.section = Some(Box::new(wordcraft_doc::section::SectionProps::default()));
|
||||
}
|
||||
rev.para_mut(StoryRef::Body, &wordcraft_doc::Path::top(2)).unwrap().props.style = Some("Heading1".into());
|
||||
let path = std::env::temp_dir().join(format!("wc-compare-section-{}.docx", std::process::id()));
|
||||
crate::io::save_path(&path, &rev).unwrap();
|
||||
s.run("review.compare", &json!({"path": path.to_string_lossy()})).unwrap();
|
||||
let _ = std::fs::remove_file(&path);
|
||||
s.run("review.rejectAll", &json!({})).unwrap();
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "Intro\nBody");
|
||||
assert_eq!(s.doc.body.len(), 2);
|
||||
let body = s.doc.body[1].as_para().unwrap();
|
||||
assert_eq!(body.plain_text(), "Body");
|
||||
assert_eq!(body.props.style.as_deref(), Some("Heading1"), "the following paragraph keeps its own properties (fixed on main by #5734)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compare_pins_accepting_a_deleted_section_keeps_the_next_paragraphs_style() {
|
||||
// The Accept-side mirror of `compare_pins_rejecting_an_inserted_section_keeps_the_next_paragraphs_style`:
|
||||
// compare deletes a paragraph that carries a section break whole (original `A`, `OLD`
|
||||
// with a section break, `B`; revised `A`, `B`). Accept All goes through the same #5734
|
||||
// branch in `resolve_para` as the reject case: the section break is removed first, so
|
||||
// the emptied paragraph goes whole instead of being joined into the next one. After
|
||||
// Accept All the revised text stands exactly and `B` keeps its own properties.
|
||||
let mut original = Document::from_text("A\nOLD\nB");
|
||||
{
|
||||
let p = original.para_mut(StoryRef::Body, &wordcraft_doc::Path::top(1)).unwrap();
|
||||
p.props.style = Some("Normal".into());
|
||||
p.section = Some(Box::new(wordcraft_doc::section::SectionProps::default()));
|
||||
}
|
||||
original.para_mut(StoryRef::Body, &wordcraft_doc::Path::top(2)).unwrap().props.style = Some("Heading1".into());
|
||||
let mut s = Session::new(original);
|
||||
|
||||
let mut rev = Document::from_text("A\nB");
|
||||
rev.para_mut(StoryRef::Body, &wordcraft_doc::Path::top(1)).unwrap().props.style = Some("Heading1".into());
|
||||
let path = std::env::temp_dir().join(format!("wc-compare-section-accept-{}.docx", std::process::id()));
|
||||
crate::io::save_path(&path, &rev).unwrap();
|
||||
s.run("review.compare", &json!({"path": path.to_string_lossy()})).unwrap();
|
||||
let _ = std::fs::remove_file(&path);
|
||||
assert_eq!(s.doc.body.len(), 3);
|
||||
let mid = s.doc.body[1].as_para().unwrap();
|
||||
assert_eq!(mid.plain_text(), "OLD");
|
||||
assert!(mid.mark.del.is_some(), "the deleted sectioned paragraph's mark is not marked deleted");
|
||||
s.run("review.acceptAll", &json!({})).unwrap();
|
||||
assert_eq!(s.doc.plain_text(StoryRef::Body), "A\nB");
|
||||
assert_eq!(s.doc.body.len(), 2);
|
||||
assert_eq!(empty_paras(&s), 0, "accepting the deleted sectioned paragraph left it behind");
|
||||
let body = s.doc.body[1].as_para().unwrap();
|
||||
assert_eq!(body.plain_text(), "B");
|
||||
assert_eq!(body.props.style.as_deref(), Some("Heading1"), "the following paragraph keeps its own properties (fixed on main by #5734)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compare_options_ignore_case_and_white_space() {
|
||||
let original = "The Cat sat.\nTwo spaces here.";
|
||||
|
||||
@@ -1,33 +1,83 @@
|
||||
//! OpenDocument Text (`.odt`, `.ott`, `.fodt`) import and export via `craft-odf`.
|
||||
|
||||
use wordcraft_doc::{Document, SectionProps};
|
||||
use std::sync::Arc;
|
||||
|
||||
use wordcraft_doc::{Block, Document, SectionProps};
|
||||
|
||||
pub use craft_odf::text::{CryptError, TEMPLATE_MIME, TEXT_MIME, decrypt, encrypt, is_encrypted};
|
||||
|
||||
/// Text room, points, that header and footer bands leave on a page (as Page Setup's margins must).
|
||||
const MIN_TEXT_ROOM: f32 = 36.0;
|
||||
|
||||
fn shared_section(page: &SectionProps) -> craft_wordmodel::SectionProps {
|
||||
let mut d = Document::new();
|
||||
d.last_section = page.clone();
|
||||
wordcraft_docx::to_shared_model(&d).map(|s| s.last_section).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// A shared document opened as a WordCraft one, its pages keeping the text room the header and
|
||||
/// footer bands leave ([`keep_text_room`]).
|
||||
fn from_shared(shared: craft_wordmodel::Document) -> Result<Document, String> {
|
||||
let mut doc = wordcraft_docx::from_shared_model(shared).map_err(|e| e.to_string())?;
|
||||
keep_text_room(&mut doc);
|
||||
Ok(doc)
|
||||
}
|
||||
|
||||
/// A page's header and footer bands grow its margins, and a band as tall as the page (to fit a
|
||||
/// full-page picture, #5806) takes all the text's room: every page then draws one line below the
|
||||
/// paper and the rest of the body is missing from the render and PDF. The bands grow the margins
|
||||
/// only while the text keeps half an inch (Page Setup's rule for margins): the larger margin, the
|
||||
/// larger band with it, gives up the excess first, so the smaller band is kept whole. The band's
|
||||
/// own height is untouched: the header still draws as tall as its content.
|
||||
///
|
||||
/// `craft-odf` caps a band at the page's longer side rather than at the room left for text; this
|
||||
/// is the guard that keeps the text on the page until the shared reader makes the same one.
|
||||
fn keep_text_room(doc: &mut Document) {
|
||||
for b in &mut doc.body {
|
||||
if let Block::Para(p) = &mut *Arc::make_mut(b)
|
||||
&& let Some(sec) = p.section.as_mut()
|
||||
{
|
||||
keep_section_room(sec);
|
||||
}
|
||||
}
|
||||
keep_section_room(&mut doc.last_section);
|
||||
}
|
||||
|
||||
fn keep_section_room(sec: &mut SectionProps) {
|
||||
if !(sec.page_h.is_finite() && sec.margin_top.is_finite() && sec.margin_bottom.is_finite()) {
|
||||
return;
|
||||
}
|
||||
let mut excess = sec.margin_top + sec.margin_bottom - (sec.page_h - MIN_TEXT_ROOM);
|
||||
if excess <= 0.0 {
|
||||
return;
|
||||
}
|
||||
let (first, second) = if sec.margin_top >= sec.margin_bottom {
|
||||
(&mut sec.margin_top, &mut sec.margin_bottom)
|
||||
} else {
|
||||
(&mut sec.margin_bottom, &mut sec.margin_top)
|
||||
};
|
||||
let cut = excess.min(first.max(0.0));
|
||||
*first -= cut;
|
||||
excess -= cut;
|
||||
if excess > 0.0 {
|
||||
*second = (*second - excess).max(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn import(bytes: &[u8]) -> Result<Document, String> {
|
||||
let shared = craft_odf::text::import(bytes)?;
|
||||
wordcraft_docx::from_shared_model(shared).map_err(|e| e.to_string())
|
||||
from_shared(craft_odf::text::import(bytes)?)
|
||||
}
|
||||
|
||||
pub fn import_on(bytes: &[u8], page: &SectionProps) -> Result<Document, String> {
|
||||
let shared = craft_odf::text::import_on(bytes, &shared_section(page))?;
|
||||
wordcraft_docx::from_shared_model(shared).map_err(|e| e.to_string())
|
||||
from_shared(craft_odf::text::import_on(bytes, &shared_section(page))?)
|
||||
}
|
||||
|
||||
pub fn import_flat(bytes: &[u8]) -> Result<Document, String> {
|
||||
let shared = craft_odf::text::import_flat(bytes)?;
|
||||
wordcraft_docx::from_shared_model(shared).map_err(|e| e.to_string())
|
||||
from_shared(craft_odf::text::import_flat(bytes)?)
|
||||
}
|
||||
|
||||
pub fn import_flat_on(bytes: &[u8], page: &SectionProps) -> Result<Document, String> {
|
||||
let shared = craft_odf::text::import_flat_on(bytes, &shared_section(page))?;
|
||||
wordcraft_docx::from_shared_model(shared).map_err(|e| e.to_string())
|
||||
from_shared(craft_odf::text::import_flat_on(bytes, &shared_section(page))?)
|
||||
}
|
||||
|
||||
/// The shared model an OpenDocument file is written from. ODF's `dc:date` is an instant (a `Z`
|
||||
|
||||
@@ -342,6 +342,47 @@ fn odt_round_trip() {
|
||||
assert_eq!(back.core.creator, "Ada Writer");
|
||||
}
|
||||
|
||||
/// A flat ODT on A4 with a header and a footer, their bands' minimum heights (`fo:min-height`)
|
||||
/// stated, and two body paragraphs.
|
||||
fn flat_odt_with_bands(header: &str, footer: &str) -> Vec<u8> {
|
||||
format!(
|
||||
r#"<?xml version="1.0" encoding="UTF-8"?>
|
||||
<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
|
||||
<office:automatic-styles><style:page-layout style:name="pm1"><style:page-layout-properties fo:page-width="21cm" fo:page-height="29.7cm" fo:margin-top="2cm" fo:margin-bottom="1.5cm" fo:margin-left="2cm" fo:margin-right="2cm"/><style:header-style><style:header-footer-properties fo:min-height="{header}" fo:margin-bottom="0.25cm"/></style:header-style><style:footer-style><style:header-footer-properties fo:min-height="{footer}" fo:margin-top="0.5cm"/></style:footer-style></style:page-layout></office:automatic-styles>
|
||||
<office:master-styles><style:master-page style:name="Standard" style:page-layout-name="pm1"><style:header><text:p>H</text:p></style:header><style:footer><text:p>F</text:p></style:footer></style:master-page></office:master-styles>
|
||||
<office:body><office:text><text:p>a</text:p><text:p>b</text:p></office:text></office:body>
|
||||
</office:document>"#
|
||||
)
|
||||
.into_bytes()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_header_band_as_tall_as_the_page_leaves_the_text_room() {
|
||||
// #5806: a header's min-height raised to the page height (to fit a full-page picture) made the
|
||||
// text's top margin the page's bottom edge, so each page drew one line off the paper and the
|
||||
// rest of the text was lost. The bands grow the margins only while the text keeps half an
|
||||
// inch, as Page Setup's margins must.
|
||||
let cm = |v: f32| v * 72.0 / 2.54;
|
||||
let near = |a: f32, b: f32| (a - b).abs() < 0.05;
|
||||
let room = |header: &str, footer: &str| {
|
||||
let doc = import("fodt", &flat_odt_with_bands(header, footer)).unwrap().unwrap();
|
||||
let s = doc.last_section.clone();
|
||||
(s.page_h - s.margin_top - s.margin_bottom, s)
|
||||
};
|
||||
let (left, s) = room("29.7cm", "1cm");
|
||||
assert!(left >= 36.0 - 0.05, "text room {left}: {s:?}");
|
||||
// The header still starts at the page margin; the text right after as much band as fits.
|
||||
assert!(near(s.header, cm(2.0)) && near(s.margin_top, s.page_h - cm(3.0) - 36.0), "{s:?}");
|
||||
// A footer as tall as the page leaves it too, and so do both at once.
|
||||
let (left, s) = room("0.5cm", "29.7cm");
|
||||
assert!(left >= 36.0 - 0.05 && near(s.margin_top, cm(2.75)), "text room {left}: {s:?}");
|
||||
let (left, s) = room("29.7cm", "29.7cm");
|
||||
assert!(left >= 36.0 - 0.05, "text room {left}: {s:?}");
|
||||
// Bands that fit are as stated.
|
||||
let (_, s) = room("0.5cm", "1cm");
|
||||
assert!(near(s.margin_top, cm(2.75)) && near(s.margin_bottom, cm(3.0)), "{s:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn latex_round_trip() {
|
||||
check_round_trip("tex", true);
|
||||
|
||||
@@ -236,6 +236,7 @@ Page Setup's margin, paper-size and document-grid number boxes scroll long text
|
||||
| 2026-10-26 | trivial | Dialog sections improve readability across 13 dialogs; conditional scrolling keeps tall dialogs usable. Ranked gaps and estimates unchanged (#4035, #4038) |
|
||||
| 2026-11-12 | trivial | PDF exports and print jobs mark tracked changes in the Track Changes Options colours and marks, and deletions marked Hidden take no space; print jobs without Print Markup lay out the final text. The print preview pages as the job prints, and the preview and downloaded PNGs draw headers at full strength (#5232, #6267). MCP/control-screenshot rendering (#6266), STYLEREF of hidden deletions (#6263) and the preview cache's numeral key (#6265) remain; no ranked gap changed. |
|
||||
| 2026-11-12 | trivial | Clipboard: a copied picture is published to the system clipboard as PNG, with HTML where the host writes it, and WordCraft's own paste keeps the original fragment; a copy of only shapes stays in WordCraft (#6205). Native external-app paste remains untested. |
|
||||
| 2026-11-16 | trivial | Compare: a whole-paragraph change at the very end of the body leaves one empty paragraph when resolved — rejecting a terminal inserted paragraph, or accepting a terminal deleted one — because revision resolution needs a following paragraph (#3750; pinned by tests in #5505). No ranked gap changed. |
|
||||
| 2026-11-08 | trivial | #10 narrowed: a turned inline picture with no recorded effect extent keeps its line to its frame (exchanged near a quarter turn in Word 2013+ layout), cut at the line; gap stays open |
|
||||
| 2026-11-08 | trivial | #4 narrowed: a cell's last Normal paragraph drops its contextual space after, the end-of-cell mark counting as a Normal paragraph (#5450) |
|
||||
| 2026-11-07 | trivial | Page Setup also bounds the unfocused margin display after a long numeric paste; the accepted value is retained (#5650). |
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# How WordCraft interprets OpenDocument files
|
||||
|
||||
> **Last reviewed:** 2026-11-02 · **Last updated:** 2026-11-05 · **Change:** trivial (a document's language: kept on any save, and stated when written from the model); previously major (no more settings: one choice for each case the standard leaves open); previously trivial (what is written as read: unchanged paragraphs with drawings, comments, changes or marks too); previously minor (the two presets are Microsoft Word style and LibreOffice style; CLI values listed one by one); previously minor (deviations from the standard listed; ODF 1.2 → 1.3 checked); previously major (new: the ODF interpretation profile and the list of every case)
|
||||
> **Last reviewed:** 2026-11-02 · **Last updated:** 2026-11-18 · **Change:** trivial (where the text room an oversized header or footer band leaves is kept: WordCraft's import, as the shared reader still caps a band at the page's longer side); previously trivial (header and footer bands leave the text room on the page, #5806); previously trivial (a document's language: kept on any save, and stated when written from the model); previously major (no more settings: one choice for each case the standard leaves open); previously trivial (what is written as read: unchanged paragraphs with drawings, comments, changes or marks too); previously minor (the two presets are Microsoft Word style and LibreOffice style; CLI values listed one by one); previously minor (deviations from the standard listed; ODF 1.2 → 1.3 checked); previously major (new: the ODF interpretation profile and the list of every case)
|
||||
|
||||
OpenDocument (ODF 1.3, OASIS) leaves some of a document's look to the application. Part 3 §16.2
|
||||
says that when no style sets a property and the standard gives no default, "an
|
||||
@@ -37,6 +37,7 @@ knows of, so none gets lost.
|
||||
| Page margins a page layout doesn't state | §20.206–20.209 refer to XSL §7.10 (initial value 0); whether that default comes with the reference is not said | 0 (XSL's initial value) | 2 cm (its own files always state theirs; some of its templates don't) |
|
||||
| Height of a header or footer whose style states none | §20.212.2 `fo:min-height`: no default | 0 (as tall as its text) | 0.5 cm |
|
||||
| *(meaning)* Whether a header's stated minimum height includes its stated spacing from the body | §20.212.2, §20.207: not said | no: spacing comes after the height | yes |
|
||||
| *(meaning)* Header and footer heights that, with the page margins, leave no room for text (a header as tall as the page, to fit a full-page picture) | §20.212.2: not said | the bands take what leaves the text half an inch (Page Setup's rule for margins), the smaller band kept whole; the header is still drawn as tall as its content. WordCraft trims the margins when it opens the file; the shared `craft-odf` reader still caps a band at the page's longer side | not measured |
|
||||
| A header taller than its height with `style:dynamic-spacing` unstated | §20.264: no default | off: the spacing is kept (on, with no height stated, would always drop the spacing the file states) | off |
|
||||
| Where paragraph tab stops, default ones too, are measured from when `settings.xml` doesn't say | §19.512.3 `style:position` doesn't say; §19.861 covers only indexes | the margin (as Word; ONLYOFFICE's files mean this too) | the paragraph's left indent (its `TabsRelativeToIndent` default): explicit stops, the default stops every interval and the hanging indent's stop all move with the indent (measured) |
|
||||
| Gap between columns when `style:columns` states none | §19.233 `fo:column-gap`: no default (and explicitly not XSL's) | 0.5 in (Word's) | 0 |
|
||||
@@ -164,6 +165,8 @@ from public bug reports and ONLYOFFICE's converter test snapshots):
|
||||
|
||||
| Date | Change |
|
||||
|---|---|
|
||||
| 2026-11-18 | Where the rule above is kept: WordCraft trims the margins as it opens the file, the header and footer parts keeping their place, because the shared `craft-odf` reader still caps a band at the page's longer side. The behaviour and the pages are the same; the trim moves with the reader when it makes the same choice. |
|
||||
| 2026-11-12 | Header and footer heights too tall for the page (#5806): the bands leave the text half an inch, the smaller band kept whole. A header as tall as the page put the text below the paper, and the body was lost from the render and PDF. |
|
||||
| 2026-11-05 | A document's language is read from its default style or Standard and written back from the model. It was lost when a style or list definition changed (numbering, a new style), and readers then showed the document in their own default language. Styles written from the model no longer say English for a document that isn't. A language's script (`fo:script`) is kept with it, and a style with no parent takes the default style's language when Standard's differs. |
|
||||
| 2026-11-04 | The settings removed: File › Options › Advanced › OpenDocument files, `file.options` `odf`, `WORDCRAFT_ODF`, the LibreOffice style and custom values. WordCraft makes one choice for each case the standard leaves open, the one the default made, so nothing changes for a document opened with the default. What a file states is still followed, its `TabsRelativeToIndent` and `AddParaTableSpacing` among it. LibreOffice's choices stay listed beside WordCraft's. |
|
||||
| 2026-11-04 | How WordCraft writes ODF: unchanged paragraphs and tables with drawings, comments, tracked changes, notes or marks are written as read too (the text said from the model); what is edited, and the cases left in the element audit, from the model. |
|
||||
|
||||
Reference in New Issue
Block a user