mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-11 00:31:10 +00:00
ODT: custom styles with an outline level keep their name when edited (gap 19) (#5770)
* ODT gap 19: custom styles with an outline level keep their name when edited A paragraph in a custom style with style:default-outline-level was read as WordCraft's Heading 1 or whichever level it named. Unedited, it was written as read. Edited, it was saved as Heading_20_1, so LibreOffice showed WordCraft's blue heading instead of the file's look, and WordCraft drew it that way too. Read such a style as a custom style that carries the outline level. The paragraph stays a heading at that level in WordCraft, is numbered with the file's outline as LibreOffice numbers it, and is saved as <text:h text:style-name="Head" text:outline-level="1">. The level comes from the style, not the paragraph kind, because kinds stop at Heading 6. The writer dropped a custom style's name on any heading, title, quotation or code paragraph, so custom styles based on those lost their look when edited too. It now keeps the name for every kind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ODT: a heading's own outline level gives its number (gap 19) LibreOffice numbers a heading by its text:outline-level. WordCraft took the number from the style's level, so a heading stating another showed the wrong number, or one on a level the outline doesn't number. A heading in a list stays the list's. Found by CodeRabbit on this PR, as was the Title-based style test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ODT: a heading in a list of its own keeps it, and an unnumbered level takes no number (gap 19) Any list whose first level was linked to a style counted as the outline's, so a heading deeper in one lost its list on save. Now only the number the outline itself gives counts. A style based on a numbered heading, at a level the outline doesn't number, took its parent's number. Found by CodeRabbit on this PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ODT: a heading past level 6 keeps its list (gap 19) The written outline has no number past Heading 6, so counting such a heading's list as the outline's lost its number. Found by CodeRabbit on this PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ODT: a style with a heading numbered by its own level stays on the outline (gap 19) Writing it with no list style took the number from that heading in LibreOffice. Written so, the numbers match the file's. Found by CodeRabbit on this PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ODT: a heading past level six numbered through its style keeps its list (gap 19) The written outline numbers only six levels, and the list was dropped for a heading numbered only through its style, so at levels 7 to 9 it lost its number once its style was rewritten. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Gap 19: docs status lines are main's, with this change in front Merging main had kept this branch's older status lines in ROADMAP.md and docs/file-format-parity.md, which set main's 2026-11-08 date back and dropped main's newer entries and the parity doc's CLI path note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: FredApps <FredApps@users.noreply.github.com>
This commit is contained in:
8 files changed
+460
-29
No files matched your search
+3
-1
@@ -8,7 +8,7 @@
|
||||
|
||||
**Stage: alpha** · next: beta, ~15 points (60% → 75% ready for real work) and ~150–230 h away
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-08 · **Change:** trivial (progress log: ODT pictures keep the size their file gives); previously trivial (progress log: ODT frames keep the page they are anchored to); previously trivial (pointer zoom stretches page rasters until it stops); previously trivial (dark-theme interface text on Linux no longer looks semi-bold); previously trivial (Control/MCP #2596 review: partial-write outcomes, path-bearing image exports, accept-thread startup cleanup and malformed UTF-8 handling); previously trivial (progress log: a turned inline picture whose file keeps no room for the turn keeps its line to its frame); previously trivial (progress log: the Arabic interface's Styles gallery reads from the right (#5566)); previously trivial (progress log: ODT pictures offered in several formats); previously trivial (progress log: ODT heading text of another size); previously trivial (Protected typing boundary lookup counts preceding objects once and indexes editable permission IDs (#3614); caret movement and enforcement policy are unchanged; previously trivial: progress log: Custom document properties dialog, #2982; previously trivial: progress log: View › New Window; previously trivial: progress log: interface translations come from storytold/craft-i18n through the `craft-i18n` crate; previously trivial: progress log: disabled-control reasons translated in every interface language, #2678; previously trivial: progress log: mail merge record navigation and record ranges for printing, #3028; previously trivial: selection bar for right-to-left paragraphs and table rows; previously trivial: group connector rerouting preserves rotated and flipped free or unresolved endpoints under nonuniform group scaling; readiness estimates unchanged; previously trivial: progress log: a word with no break opportunity in it no longer makes the layout quadratic, #3412; previously trivial: progress log: a relationship the markup names without the prefix is read as it wrote, and an ordinary `id` names no part; previously trivial: progress log: a document with many relationships opens in the time its part takes, and an id the text only mentions is not a reference, #3411; previously trivial: progress log: read only and comments-only protection grey out edits; previously trivial: progress log: an empty paragraph with a hidden mark shows nothing, not even its list number, #3982; previously trivial: progress log: "NaN" in the Font dialog's Size box no longer closes the app, #3663; previously trivial: progress log: a table cell span from a `.json` file no longer overflows, #3637; previously trivial: progress log: a click in the footer while editing the header moves there; previously trivial: explicit documents keep the editor when recovery discovery finishes; readable recovery controls; previously trivial: Slovenian interface catalog, 2,614 entries; previously trivial: Insert Table of Figures dialog for any caption label, #3013; previously trivial: progress log: Home › Underline drop-down, #2738; previously trivial: personal templates in File › New and Save as Word Template, #2852; previously trivial: progress log: the scrollbar page tip stays on one line, #3341; previously trivial: progress log: forms protection greys out the control buttons; previously trivial: progress log: a document with many content controls saves in the time the controls take, #13; previously trivial: progress log: Word signature lines kept on save; previously trivial: a Thai run with Latin finds one installed font covering it all on Linux too, #1549; previously trivial: progress log: closing the header returns to the body selection, #3331; previously trivial: progress log: saving to a NAS share mounted by GVFS, #3003; previously trivial: progress log: a picture dragged near the bottom of a page lands there, #3169; previously trivial: centred list labels after leading page breaks, #2964; previously trivial: progress log: inline pictures drag to an insertion cursor and stay inline, #2233, #2234; previously trivial: progress log: a text file saved over itself closes without asking, #2376; previously trivial: progress log: a text frame in the paragraph defaults frames nothing, #2360; previously trivial: fixed font inputs in four layout controls; previously trivial: typing no longer starts render threads on every repaint, #3027; previously trivial: a right, centre or decimal tab whose text doesn't fit, or a left tab past the right indent, goes to the next line with its text, #1840; previously trivial: progress log: banded rows shade as in Word, #3415; previously trivial: progress log: the table handles show while the caret is in the table, #2428; previously trivial: progress log: a click below a floating table reaches the text after it, #2038; previously trivial: progress log: Delete on selected table cells leaves one empty paragraph in each, #2802; previously trivial: progress log: lam-alef in exported PDFs extracts wLine truncated
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-08 · **Change:** trivial (progress log: edited ODT paragraphs keep custom styles with an outline level); previously trivial (progress log: ODT pictures keep the size their file gives); previously trivial (progress log: ODT frames keep the page they are anchored to); previously trivial (pointer zoom stretches page rasters until it stops); previously trivial (dark-theme interface text on Linux no longer looks semi-bold); previously trivial (Control/MCP #2596 review: partial-write outcomes, path-bearing image exports, accept-thread startup cleanup and malformed UTF-8 handling); previously trivial (progress log: a turned inline picture whose file keeps no room for the turn keeps its line to its frame); previously trivial (progress log: the Arabic interface's Styles gallery reads from the right (#5566)); previously trivial (progress log: ODT pictures offered in several formats); previously trivial (progress log: ODT heading text of another size); previously trivial (Protected typing boundary lookup counts preceding objects once and indexes editable permission IDs (#3614); caret movement and enforcement policy are unchanged; previously trivial: progress log: Custom document properties dialog, #2982; previously trivial: progress log: View › New Window; previously trivial: progress log: interface translations come from storytold/craft-i18n through the `craft-i18n` crate; previously trivial: progress log: disabled-control reasons translated in every interface language, #2678; previously trivial: progress log: mail merge record navigation and record ranges for printing, #3028; previously trivial: selection bar for right-to-left paragraphs and table rows; previously trivial: group connector rerouting preserves rotated and flipped free or unresolved endpoints under nonuniform group scaling; readiness estimates unchanged; previously trivial: progress log: a word with no break opportunity in it no longer makes the layout quadratic, #3412; previously trivial: progress log: a relationship the markup names without the prefix is read as it wrote, and an ordinary `id` names no part; previously trivial: progress log: a document with many relationships opens in the time its part takes, and an id the text only mentions is not a reference, #3411; previously trivial: progress log: read only and comments-only protection grey out edits; previously trivial: progress log: an empty paragraph with a hidden mark shows nothing, not even its list number, #3982; previously trivial: progress log: "NaN" in the Font dialog's Size box no longer closes the app, #3663; previously trivial: progress log: a table cell span from a `.json` file no longer overflows, #3637; previously trivial: progress log: a click in the footer while editing the header moves there; previously trivial: explicit documents keep the editor when recovery discovery finishes; readable recovery controls; previously trivial: Slovenian interface catalog, 2,614 entries; previously trivial: Insert Table of Figures dialog for any caption label, #3013; previously trivial: progress log: Home › Underline drop-down, #2738; previously trivial: personal templates in File › New and Save as Word Template, #2852; previously trivial: progress log: the scrollbar page tip stays on one line, #3341; previously trivial: progress log: forms protection greys out the control buttons; previously trivial: progress log: a document with many content controls saves in the time the controls take, #13; previously trivial: progress log: Word signature lines kept on save; previously trivial: a Thai run with Latin finds one installed font covering it all on Linux too, #1549; previously trivial: progress log: closing the header returns to the body selection, #3331; previously trivial: progress log: saving to a NAS share mounted by GVFS, #3003; previously trivial: progress log: a picture dragged near the bottom of a page lands there, #3169; previously trivial: centred list labels after leading page breaks, #2964; previously trivial: progress log: inline pictures drag to an insertion cursor and stay inline, #2233, #2234; previously trivial: progress log: a text file saved over itself closes without asking, #2376; previously trivial: progress log: a text frame in the paragraph defaults frames nothing, #2360; previously trivial: fixed font inputs in four layout controls; previously trivial: typing no longer starts render threads on every repaint, #3027; previously trivial: a right, centre or decimal tab whose text doesn't fit, or a left tab past the right indent, goes to the next line with its text, #1840; previously trivial: progress log: banded rows shade as in Word, #3415; previously trivial: progress log: the table handles show while the caret is in the table, #2428; previously trivial: progress log: a click below a floating table reaches the text after it, #2038; previously trivial: progress log: Delete on selected table cells leaves one empLine truncated
|
||||
>
|
||||
> **Recipient CSV update:** 2026-10-27 · Complete quoted header records choose the delimiter (#4249); detection and regressions follow the current mailings module split. Recipient limits and readiness estimates are unchanged.
|
||||
>
|
||||
@@ -150,6 +150,7 @@ Ranked, to beta (detail and remaining milestones in [docs/roadmap.md](docs/roadm
|
||||
|
||||
## Progress log
|
||||
|
||||
- 2026-11-06: An edited ODT paragraph keeps its custom paragraph style when that style has an outline level, or is based on a heading, Title, Quotations or Preformatted Text (gap 19). It was saved under the built-in style instead, such as WordCraft's blue Heading 1, and looked wrong in LibreOffice; a style with an outline level also drew that way in WordCraft. The style's outline level and numbering still work in WordCraft.
|
||||
- 2026-11-05: ODT pictures keep the size their file gives (gap 19): opening a file shrank ones wider than the text, so a save with no edit to them changed how LibreOffice laid them out.
|
||||
- 2026-11-05: ODT frames keep the page they are anchored to (gap 19): written without its number, a frame on page 3 came back on page 1 in LibreOffice after a save.
|
||||
- 2026-11-05: ODT documents keep their language (gap 19). It was lost on save after numbering or a new style, and LibreOffice then showed the document in its own default language; a document in another language was also proofed as English.
|
||||
@@ -899,6 +900,7 @@ MATH glyphs that reference the same construction now share its immutable variant
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-06 | trivial | Progress log: edited ODT paragraphs keep custom styles with an outline level (gap 19) |
|
||||
| 2026-10-31 | trivial | Control/MCP #2596 review fixes; readiness estimates unchanged |
|
||||
| 2026-11-08 | trivial | Progress log: XML line ends in text normalised (#5897) |
|
||||
| 2026-11-08 | trivial | Progress log: contextual spacing drops the space after a cell's last Normal paragraph (#5450) |
|
||||
|
||||
@@ -182,6 +182,9 @@ fn para_extra(doc: &Document, p: &wordcraft_doc::props::ParaProps) -> Option<Box
|
||||
tabs
|
||||
});
|
||||
let style = p.style.clone().filter(|id| is_custom_style(doc, id));
|
||||
// Its own, else its custom style's: the kind doesn't say (it stops at Heading 6, and is the
|
||||
// heading style's where the style is based on one).
|
||||
let outline_level = p.outline_level.or_else(|| style.as_ref().and_then(|_| doc.styles.resolve_para(p).outline_level));
|
||||
let x = wordcraft_doc::props::ParaProps {
|
||||
tabs,
|
||||
shading: p.shading,
|
||||
@@ -191,7 +194,7 @@ fn para_extra(doc: &Document, p: &wordcraft_doc::props::ParaProps) -> Option<Box
|
||||
drop_cap: p.drop_cap.filter(|l| *l > 1),
|
||||
drop_cap_distance: p.drop_cap_distance.filter(|_| p.drop_cap.is_some_and(|l| l > 1)),
|
||||
keep_lines: p.keep_lines.filter(|k| *k),
|
||||
outline_level: p.outline_level,
|
||||
outline_level,
|
||||
widow_control: p.widow_control.filter(|w| !*w),
|
||||
// Hyphenated (the document hyphenates and the paragraph doesn't opt out): `Some(false)`.
|
||||
suppress_hyphens: (doc.settings.auto_hyphenation && p.suppress_hyphens != Some(true)).then_some(false),
|
||||
@@ -413,14 +416,25 @@ fn flow_comment(doc: &Document, c: &wordcraft_doc::Comment, parent: Option<u32>,
|
||||
FComment { author: c.author.clone(), initials: c.initials.clone(), date: c.date.clone(), resolved: c.resolved, parent, blocks }
|
||||
}
|
||||
|
||||
/// Whether `li`, the list of heading `p`, is the number its outline level has from its heading
|
||||
/// style's list, not a list of its own: it states that level, and the heading style of that level
|
||||
/// numbers with that list there. Past Heading 6 no such style gives the written outline a number.
|
||||
fn numbered_by_outline(doc: &Document, p: &Paragraph, li: &ListInfo) -> bool {
|
||||
use wordcraft_doc::props::NumRef;
|
||||
p.props.outline_level == Some(li.level)
|
||||
&& li.level < 6
|
||||
&& doc.styles.para_style_props(&format!("Heading{}", li.level + 1)).0.numbering == Some(NumRef { num: li.list, level: li.level })
|
||||
}
|
||||
|
||||
/// A paragraph's list membership as the flow keeps it: without the list's identity and label
|
||||
/// unless `opts` asks for them, and none for a heading numbered only through its style, which a
|
||||
/// format with heading numbering of its own (ODT's outline style) numbers instead.
|
||||
fn flow_list(kind: Kind, list: Option<ListInfo>, p: &Paragraph, opts: FlowOpts) -> Option<ListInfo> {
|
||||
/// unless `opts` asks for them, and none for a heading numbered only through its style or
|
||||
/// [`numbered_by_outline`], which a format with heading numbering of its own (ODT's outline style)
|
||||
/// numbers instead, in its first six levels.
|
||||
fn flow_list(doc: &Document, kind: Kind, list: Option<ListInfo>, p: &Paragraph, opts: FlowOpts) -> Option<ListInfo> {
|
||||
let mut li = list?;
|
||||
if !opts.lists {
|
||||
(li.list, li.label) = (0, None);
|
||||
} else if matches!(kind, Kind::Heading(_)) && p.props.numbering.is_none() {
|
||||
} else if matches!(kind, Kind::Heading(_)) && li.level < 6 && (p.props.numbering.is_none() || numbered_by_outline(doc, p, &li)) {
|
||||
return None;
|
||||
}
|
||||
Some(li)
|
||||
@@ -458,7 +472,7 @@ pub fn flow_paras(doc: &Document, p: &Paragraph) -> Vec<Para> {
|
||||
fn flow_paras_in(doc: &Document, p: &Paragraph, opts: FlowOpts) -> Vec<Para> {
|
||||
let tracked = opts.tracked;
|
||||
let (kind, list) = para_kind(doc, p);
|
||||
let list = flow_list(kind, list, p, opts);
|
||||
let list = flow_list(doc, kind, list, p, opts);
|
||||
let mut done: Vec<Para> = Vec::new();
|
||||
let borders = if kind == Kind::Rule { None } else { p.props.borders.filter(|b| b.takes_room()) };
|
||||
let mut out = Para {
|
||||
|
||||
@@ -296,6 +296,8 @@ fn add_custom_styles(doc: &mut Document, named: &[super::styles::NamedStyle], od
|
||||
}),
|
||||
contextual_spacing: look.contextual,
|
||||
bidi: look.rtl.filter(|r| *r),
|
||||
// The document's nine levels; ODF's tenth is the last of them.
|
||||
outline_level: def.outline.map(|o| o.clamp(1, 9) - 1),
|
||||
..Default::default()
|
||||
};
|
||||
let name = super::writer::generating_style(name).map_or_else(|| def.name.clone(), |(_, n)| n);
|
||||
@@ -362,7 +364,7 @@ fn apply_look(doc: &mut Document, kind: model::Kind, look: &super::styles::ParaL
|
||||
fn number_headings(doc: &mut Document, levels: &[super::styles::ListLevel]) {
|
||||
use wordcraft_doc::numbering::{AbstractNum, ListKind, Num, levels_for};
|
||||
use wordcraft_doc::props::NumRef;
|
||||
let numbered: Vec<bool> = (0..6).map(|i| levels.get(i).is_some_and(|l| l.ordered)).collect();
|
||||
let numbered: Vec<bool> = (0..9).map(|i| levels.get(i).is_some_and(|l| l.ordered)).collect();
|
||||
if !numbered.contains(&true) {
|
||||
return;
|
||||
}
|
||||
@@ -395,11 +397,62 @@ fn number_headings(doc: &mut Document, levels: &[super::styles::ListLevel]) {
|
||||
numbering.abstracts.push(AbstractNum { id: aid, name: None, levels: out, ..Default::default() });
|
||||
let nid = numbering.nums.iter().map(|n| n.id + 1).max().unwrap_or(1).max(1);
|
||||
numbering.nums.push(Num { id: nid, abstract_id: aid, ..Default::default() });
|
||||
let styles = Arc::make_mut(&mut doc.styles);
|
||||
for (i, on) in numbered.iter().enumerate() {
|
||||
if *on && let Some(st) = Arc::make_mut(&mut doc.styles).get_mut(&format!("Heading{}", i + 1)) {
|
||||
if *on && let Some(st) = styles.get_mut(&format!("Heading{}", i + 1)) {
|
||||
st.para.numbering = Some(NumRef { num: nid, level: i as u8 });
|
||||
}
|
||||
}
|
||||
// LibreOffice numbers a custom style at an outline level along with that level's headings.
|
||||
for st in &mut styles.styles {
|
||||
if let Some(l) = st.para.outline_level.filter(|l| numbered.get(usize::from(*l)) == Some(&true)) {
|
||||
st.para.numbering = Some(NumRef { num: nid, level: l });
|
||||
}
|
||||
}
|
||||
// A style at a level the outline doesn't number doesn't take its parent's number from it.
|
||||
let of_outline = |st: &wordcraft_doc::styles::Style| {
|
||||
let at = wordcraft_doc::props::ParaProps { style: Some(st.id.clone()), ..Default::default() };
|
||||
st.para.numbering.is_none()
|
||||
&& st.para.outline_level.is_some_and(|l| numbered.get(usize::from(l)) != Some(&true))
|
||||
&& styles.resolve_para(&at).numbering.is_some_and(|n| n.num == nid)
|
||||
};
|
||||
let unnumbered: Vec<String> = styles.styles.iter().filter(|st| of_outline(st)).map(|st| st.id.clone()).collect();
|
||||
for id in unnumbered {
|
||||
if let Some(st) = styles.get_mut(&id) {
|
||||
// (`num: 0` switches the number off.)
|
||||
st.para.numbering = Some(NumRef { num: 0, level: 0 });
|
||||
}
|
||||
}
|
||||
// A heading's own outline level goes before its style's: LibreOffice numbers it by that level.
|
||||
// A heading in a list is that list's.
|
||||
let styles = doc.styles.clone();
|
||||
each_body_para(&mut doc.body, 0, &mut |p| {
|
||||
let Some(l) = p.props.outline_level.filter(|_| p.props.numbering.is_none()) else { return };
|
||||
let style = styles.resolve_para(&wordcraft_doc::props::ParaProps { style: p.props.style.clone(), ..Default::default() });
|
||||
if style.outline_level.is_none() {
|
||||
return;
|
||||
}
|
||||
let own = (numbered.get(usize::from(l)) == Some(&true)).then_some(NumRef { num: nid, level: l });
|
||||
if own != style.numbering {
|
||||
// (`num: 0` switches the style's number off.)
|
||||
p.props.numbering = Some(own.unwrap_or(NumRef { num: 0, level: 0 }));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Each paragraph of `blocks`, those in tables too (to 16 levels deep).
|
||||
fn each_body_para(blocks: &mut [Arc<wordcraft_doc::Block>], depth: usize, f: &mut dyn FnMut(&mut wordcraft_doc::Paragraph)) {
|
||||
for b in blocks {
|
||||
match Arc::make_mut(b) {
|
||||
wordcraft_doc::Block::Para(p) => f(p),
|
||||
wordcraft_doc::Block::Table(t) if depth < 16 => {
|
||||
for cell in t.rows.iter_mut().flat_map(|r| r.cells.iter_mut()) {
|
||||
each_body_para(&mut cell.blocks, depth + 1, f);
|
||||
}
|
||||
}
|
||||
wordcraft_doc::Block::Table(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The boolean configuration item `name` of `settings.xml` (ODF 1.3 §3.10), when it has one.
|
||||
|
||||
@@ -29,7 +29,7 @@ fn columns_xml(c: &Columns) -> String {
|
||||
/// Preformatted Text), each with the look of the document's own style: font, size, bold,
|
||||
/// italic, colour and the rest of its text formatting, spacing, indents, alignment and keep with
|
||||
/// next, written out in full so other programs show them as WordCraft does.
|
||||
fn kind_styles(doc: &Document) -> String {
|
||||
fn kind_styles(doc: &Document, on_outline: &std::collections::BTreeSet<String>) -> String {
|
||||
let mut s = String::new();
|
||||
let mut kinds: Vec<(String, String, String, Option<u8>, &str)> =
|
||||
(1..=6).map(|n| (format!("Heading_20_{n}"), format!("Heading {n}"), format!("Heading{n}"), Some(n), "text")).collect();
|
||||
@@ -63,14 +63,7 @@ fn kind_styles(doc: &Document) -> String {
|
||||
if let Some(c) = pp.contextual_spacing {
|
||||
para.push_str(&format!(" style:contextual-spacing=\"{c}\""));
|
||||
}
|
||||
// A heading level the outline doesn't number names no list style: LibreOffice would
|
||||
// otherwise give it the outline's (unnumbered) level, and its indent.
|
||||
let numbered = pp
|
||||
.numbering
|
||||
.and_then(|r| doc.numbering.level(r.num, r.level))
|
||||
.is_some_and(|l| !matches!(l.format, wordcraft_doc::section::NumFormat::None | wordcraft_doc::section::NumFormat::Bullet));
|
||||
let detach = if outline.is_some() && !numbered { " style:list-style-name=\"\"" } else { "" };
|
||||
let outline = outline.map(|n| format!(" style:default-outline-level=\"{n}\"{detach}")).unwrap_or_default();
|
||||
let outline = outline.map(|n| outline_attrs(doc, n, &pp, on_outline.contains(&id))).unwrap_or_default();
|
||||
s.push_str(&format!(
|
||||
"<style:style style:name=\"{name}\" style:display-name=\"{display}\" style:family=\"paragraph\" style:parent-style-name=\"Standard\" style:next-style-name=\"Standard\"{outline} style:class=\"{class}\"><style:paragraph-properties{para}/><style:text-properties{}/></style:style>",
|
||||
props_text(&cp)
|
||||
@@ -79,6 +72,42 @@ fn kind_styles(doc: &Document) -> String {
|
||||
s
|
||||
}
|
||||
|
||||
/// The styles of the headings in `blocks` (and their tables, to 16 levels deep) with a number by
|
||||
/// their own outline level.
|
||||
fn styles_numbered_by_own_level(blocks: &[std::sync::Arc<wordcraft_doc::Block>], depth: usize, out: &mut std::collections::BTreeSet<String>) {
|
||||
for b in blocks {
|
||||
match &**b {
|
||||
wordcraft_doc::Block::Para(p) => {
|
||||
if p.props.outline_level.is_some()
|
||||
&& p.props.numbering.is_some_and(|n| n.num != 0)
|
||||
&& let Some(s) = &p.props.style
|
||||
{
|
||||
out.insert(s.clone());
|
||||
}
|
||||
}
|
||||
wordcraft_doc::Block::Table(t) if depth < 16 => {
|
||||
for cell in t.rows.iter().flat_map(|r| r.cells.iter()) {
|
||||
styles_numbered_by_own_level(&cell.blocks, depth + 1, out);
|
||||
}
|
||||
}
|
||||
wordcraft_doc::Block::Table(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A paragraph style's outline level `n` (`style:default-outline-level`), its properties being `pp`.
|
||||
fn outline_attrs(doc: &Document, n: u8, pp: &wordcraft_doc::props::ParaProps, on_outline: bool) -> String {
|
||||
// A level the outline doesn't number names no list style: LibreOffice would otherwise give
|
||||
// it the outline's (unnumbered) level, and its indent. Unless a heading in the style has a
|
||||
// number by its own level (`on_outline`), which that would take from it.
|
||||
let numbered = pp
|
||||
.numbering
|
||||
.and_then(|r| doc.numbering.level(r.num, r.level))
|
||||
.is_some_and(|l| !matches!(l.format, wordcraft_doc::section::NumFormat::None | wordcraft_doc::section::NumFormat::Bullet));
|
||||
let detach = if numbered || on_outline { "" } else { " style:list-style-name=\"\"" };
|
||||
format!(" style:default-outline-level=\"{n}\"{detach}")
|
||||
}
|
||||
|
||||
/// The ODF parent of document style `id`: Standard for Normal, the kinds' styles for theirs, a
|
||||
/// custom style by its id.
|
||||
fn odf_parent(doc: &Document, id: Option<&str>) -> String {
|
||||
@@ -98,7 +127,7 @@ fn odf_parent(doc: &Document, id: Option<&str>) -> String {
|
||||
/// The custom paragraph styles in `named` and the custom styles they are based on, as common
|
||||
/// styles (ODF 1.3 §16.2): named by their document id, shown by their name, each with its own
|
||||
/// paragraph and text formatting over its parent's.
|
||||
fn custom_styles(doc: &Document, named: &std::collections::BTreeSet<String>) -> String {
|
||||
fn custom_styles(doc: &Document, named: &std::collections::BTreeSet<String>, on_outline: &std::collections::BTreeSet<String>) -> String {
|
||||
let mut todo: Vec<String> = named.iter().cloned().collect();
|
||||
let mut done = std::collections::BTreeSet::new();
|
||||
let mut s = String::new();
|
||||
@@ -146,8 +175,9 @@ fn custom_styles(doc: &Document, named: &std::collections::BTreeSet<String>) ->
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let parent = odf_parent(doc, st.based_on.as_deref());
|
||||
let outline = pp.outline_level.filter(|l| *l < 9).map(|l| outline_attrs(doc, l + 1, pp, on_outline.contains(&id))).unwrap_or_default();
|
||||
s.push_str(&format!(
|
||||
"<style:style style:name=\"{}\" style:display-name=\"{}\" style:family=\"paragraph\" style:parent-style-name=\"{parent}\"><style:paragraph-properties{attrs}>{tabs}</style:paragraph-properties><style:text-properties{}/></style:style>",
|
||||
"<style:style style:name=\"{}\" style:display-name=\"{}\" style:family=\"paragraph\" style:parent-style-name=\"{parent}\"{outline}><style:paragraph-properties{attrs}>{tabs}</style:paragraph-properties><style:text-properties{}/></style:style>",
|
||||
super::writer::odf_name(&id),
|
||||
x(&super::writer::generated_style(&id).map_or_else(|| st.name.clone(), |(_, d)| d)),
|
||||
props_text(&st.chr)
|
||||
@@ -365,9 +395,11 @@ fn styles_xml(
|
||||
scripts = super::writer::script_attrs(&doc.styles.default_chr)
|
||||
));
|
||||
s.push_str("<style:style style:name=\"Standard\" style:family=\"paragraph\" style:class=\"text\"/>");
|
||||
s.push_str(&kind_styles(doc));
|
||||
let mut on_outline = std::collections::BTreeSet::new();
|
||||
styles_numbered_by_own_level(&doc.body, 0, &mut on_outline);
|
||||
s.push_str(&kind_styles(doc, &on_outline));
|
||||
s.push_str(&outline_style(doc));
|
||||
s.push_str(&custom_styles(doc, named));
|
||||
s.push_str(&custom_styles(doc, named, &on_outline));
|
||||
// The note text styles, as WordCraft's Footnote Text and Endnote Text: 10 pt, no spacing.
|
||||
for (name, class) in [("Footnote", "extra"), ("Endnote", "extra")] {
|
||||
s.push_str(&format!(
|
||||
|
||||
@@ -465,6 +465,8 @@ pub(super) struct NamedStyle {
|
||||
/// What it turns off, which a style it is based on may turn on: bold, italic, underline,
|
||||
/// strike-through (`fo:font-weight="normal"`…).
|
||||
pub(super) off: [bool; 4],
|
||||
/// Its outline level, 1–10 (`style:default-outline-level`).
|
||||
pub(super) outline: Option<u8>,
|
||||
}
|
||||
|
||||
/// Reads date and time styles (`number:date-style`, `number:time-style`) as Word pictures.
|
||||
@@ -1560,13 +1562,16 @@ impl Styles {
|
||||
};
|
||||
let name = s.display.clone().unwrap_or_else(|| odt.replace("_20_", " "));
|
||||
let off = [s.fmt.bold, s.fmt.italic, s.fmt.underline, s.fmt.strike].map(|v| v == Some(false));
|
||||
Some(NamedStyle { name: name.chars().take(super::super::model::MAX_FONT_NAME).collect(), parent, look, off })
|
||||
let outline = s.outline.filter(|o| (1..=10).contains(o));
|
||||
Some(NamedStyle { name: name.chars().take(super::super::model::MAX_FONT_NAME).collect(), parent, look, off, outline })
|
||||
}
|
||||
|
||||
pub(super) fn para(&self, name: &str) -> ParaLook {
|
||||
let chain = self.chain(name);
|
||||
let mut kind = Kind::Normal;
|
||||
let mut kind_at = chain.len();
|
||||
// The nearest outline level; a style with one is no kind's style: its look is its own.
|
||||
let mut outline = None;
|
||||
for (i, (n, s)) in chain.iter().enumerate() {
|
||||
kind_at = i;
|
||||
let dn = s.display.as_deref().unwrap_or(n).to_ascii_lowercase().replace("_20_", " ");
|
||||
@@ -1585,12 +1590,12 @@ impl Styles {
|
||||
if kind != Kind::Normal {
|
||||
break;
|
||||
}
|
||||
if let Some(o) = s.outline.filter(|o| (1..=10).contains(o)) {
|
||||
kind = Kind::Heading(o.min(6));
|
||||
break;
|
||||
}
|
||||
outline = outline.or(s.outline.filter(|o| (1..=10).contains(o)));
|
||||
kind_at = chain.len();
|
||||
}
|
||||
if let Some(o) = outline {
|
||||
kind = Kind::Heading(o.min(6));
|
||||
}
|
||||
// The nearest custom style: its formatting stays in it; the automatic styles over it give
|
||||
// the paragraph's own.
|
||||
let named_at = chain.iter().take(kind_at).position(|(n, _)| self.is_named(n));
|
||||
|
||||
@@ -112,3 +112,327 @@ fn a_heading_looks_as_its_style_and_has_the_level_its_element_gives() {
|
||||
let back = import(&saved).unwrap();
|
||||
assert_eq!((props(&back, 0).style.as_deref(), props(&back, 0).outline_level), (Some("Heading2"), Some(0)));
|
||||
}
|
||||
|
||||
/// A document with these common `styles` and this `body`.
|
||||
fn in_custom_style(styles: &str, body: &str) -> Document {
|
||||
let styles = format!(
|
||||
r#"<office:document-styles {NS_T}><office:styles><style:style style:name="Standard" style:family="paragraph"/>{styles}</office:styles></office:document-styles>"#
|
||||
);
|
||||
let content =
|
||||
format!(r#"<office:document-content {NS_T}><office:body><office:text>{body}</office:text></office:body></office:document-content>"#);
|
||||
import(&package(&content, Some(&styles))).unwrap()
|
||||
}
|
||||
|
||||
const HEAD: &str = r#"<style:style style:name="Head" style:family="paragraph" style:parent-style-name="Standard" style:default-outline-level="1" style:class="text"><style:text-properties fo:font-size="26pt" fo:font-weight="bold"/></style:style>"#;
|
||||
|
||||
fn saved_after_an_edit(d: &mut Document) -> Vec<u8> {
|
||||
d.insert_text(&wordcraft_doc::Pos::body(0, 0), "Yearly ", &Default::default()).unwrap();
|
||||
export(d).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_custom_style_with_an_outline_level_stays_the_paragraphs_style() {
|
||||
// The outline level is the style's; the look stays the file's own, not Heading 1's.
|
||||
let mut d = in_custom_style(HEAD, r#"<text:p text:style-name="Head">Annual report edition</text:p>"#);
|
||||
let p = d.body[0].as_para().unwrap().props.clone();
|
||||
assert_eq!(p.style.as_deref(), Some("Head"));
|
||||
assert_eq!(d.styles.resolve_para(&p).outline_level, Some(0), "still a heading in WordCraft");
|
||||
let look = d.styles.resolve_char(p.style.as_deref(), &Default::default());
|
||||
assert_eq!((look.size, look.bold), (26.0, true));
|
||||
let r = d.body[0].as_para().unwrap().runs.first().unwrap().props.clone();
|
||||
assert!(r.size.is_none() && r.bold.is_none(), "the look stays in the style: {r:?}");
|
||||
|
||||
// Edited, it is written from the model, under its own name, at its level.
|
||||
let saved = saved_after_an_edit(&mut d);
|
||||
let c = crate::odt::tests::content_of(&saved);
|
||||
assert!(c.contains(r#"<text:h text:style-name="Head" text:outline-level="1">Yearly Annual"#), "{c}");
|
||||
let s = crate::odt::tests::styles_of(&saved);
|
||||
let head = s.split("<style:style ").find(|x| x.starts_with(r#"style:name="Head""#)).unwrap_or("");
|
||||
assert!(head.contains(r#"style:default-outline-level="1""#) && head.contains(r#"fo:font-size="26pt""#), "{head}");
|
||||
|
||||
// And read back, it is the same heading.
|
||||
let back = import(&saved).unwrap();
|
||||
let p = back.body[0].as_para().unwrap().props.clone();
|
||||
assert_eq!((p.style.as_deref(), back.styles.resolve_para(&p).outline_level), (Some("Head"), Some(0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unedited_paragraph_in_such_a_style_is_written_as_read() {
|
||||
let body = r#"<text:p text:style-name="Head">Annual report edition</text:p>"#;
|
||||
let saved = export(&in_custom_style(HEAD, body)).unwrap();
|
||||
assert!(crate::odt::tests::content_of(&saved).contains(body));
|
||||
let s = crate::odt::tests::styles_of(&saved);
|
||||
assert_eq!(s.matches(r#"style:name="Head""#).count(), 1, "{s}");
|
||||
assert!(s.contains(r#"style:default-outline-level="1""#), "{s}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_level_of_such_a_style_is_written_as_it_is() {
|
||||
// The paragraph kinds stop at Heading 6; the outline levels go on, and a style based on another
|
||||
// heading has its own.
|
||||
let styles = r#"<style:style style:name="Heading_20_2" style:display-name="Heading 2" style:family="paragraph"/><style:style style:name="Deep" style:family="paragraph" style:default-outline-level="8"/><style:style style:name="Under" style:family="paragraph" style:parent-style-name="Heading_20_2" style:default-outline-level="3"/><style:style style:name="Child" style:family="paragraph" style:parent-style-name="Deep"/>"#;
|
||||
let body =
|
||||
r#"<text:p text:style-name="Deep">deep</text:p><text:p text:style-name="Under">under</text:p><text:p text:style-name="Child">child</text:p>"#;
|
||||
let d = in_custom_style(styles, body);
|
||||
let level = |d: &Document, i: usize| d.styles.resolve_para(&d.body[i].as_para().unwrap().props).outline_level;
|
||||
assert_eq!([level(&d, 0), level(&d, 1), level(&d, 2)], [Some(7), Some(2), Some(7)]);
|
||||
let saved = crate::odt::tests::export_model(&d).unwrap();
|
||||
let c = crate::odt::tests::content_of(&saved);
|
||||
assert!(c.contains(r#"<text:h text:style-name="Deep" text:outline-level="8">deep"#), "{c}");
|
||||
assert!(c.contains(r#"<text:h text:style-name="Under" text:outline-level="3">under"#), "{c}");
|
||||
assert!(c.contains(r#"<text:h text:style-name="Child" text:outline-level="8">child"#), "{c}");
|
||||
let back = import(&saved).unwrap();
|
||||
assert_eq!([level(&back, 0), level(&back, 1), level(&back, 2)], [Some(7), Some(2), Some(7)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_paragraphs_own_level_and_formatting_stay_over_such_a_style() {
|
||||
let styles = format!(r#"<office:document-styles {NS_T}><office:styles>{HEAD}</office:styles></office:document-styles>"#);
|
||||
let content = format!(
|
||||
r#"<office:document-content {NS_T}><office:automatic-styles><style:style style:name="P1" style:family="paragraph" style:parent-style-name="Head"><style:paragraph-properties fo:text-align="center"/></style:style></office:automatic-styles><office:body><office:text><text:h text:style-name="P1" text:outline-level="2">Moved</text:h></office:text></office:body></office:document-content>"#
|
||||
);
|
||||
let d = import(&package(&content, Some(&styles))).unwrap();
|
||||
let p = d.body[0].as_para().unwrap().props.clone();
|
||||
assert_eq!((p.style.as_deref(), p.outline_level, p.align), (Some("Head"), Some(1), Some(wordcraft_doc::Align::Center)));
|
||||
let c = crate::odt::tests::content_of(&crate::odt::tests::export_model(&d).unwrap());
|
||||
assert!(c.contains(r#"text:outline-level="2">Moved"#), "{c}");
|
||||
assert!(c.contains(r#"style:parent-style-name="Head""#) && c.contains(r#"fo:text-align="center""#), "{c}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_hostile_outline_level_on_a_custom_style_is_no_heading() {
|
||||
for bad in ["0", "11", "255", "999", "-1", "x", ""] {
|
||||
let styles = format!(r#"<style:style style:name="Head" style:family="paragraph" style:default-outline-level="{bad}"/>"#);
|
||||
let d = in_custom_style(&styles, r#"<text:p text:style-name="Head">Plain</text:p>"#);
|
||||
let p = d.body[0].as_para().unwrap().props.clone();
|
||||
assert_eq!((p.style.as_deref(), d.styles.resolve_para(&p).outline_level), (Some("Head"), None), "{bad}");
|
||||
let c = crate::odt::tests::content_of(&crate::odt::tests::export_model(&d).unwrap());
|
||||
assert!(c.contains(r#"<text:p text:style-name="Head">Plain"#), "{bad}: {c}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn such_a_style_is_numbered_with_its_level() {
|
||||
// LibreOffice numbers it through the outline style, one list with the level's headings.
|
||||
let d = in_custom_style(
|
||||
&format!(
|
||||
r#"{HEAD}<style:style style:name="Heading_20_1" style:display-name="Heading 1" style:family="paragraph" style:default-outline-level="1"/>{NUMBERED}"#
|
||||
),
|
||||
r#"<text:p text:style-name="Head">First</text:p><text:h text:style-name="Heading_20_1" text:outline-level="1">Second</text:h>"#,
|
||||
);
|
||||
let num = |d: &Document, i: usize| d.styles.resolve_para(&d.body[i].as_para().unwrap().props).numbering;
|
||||
assert!(num(&d, 0).is_some());
|
||||
assert_eq!(num(&d, 0), num(&d, 1));
|
||||
let saved = crate::odt::tests::export_model(&d).unwrap();
|
||||
let c = crate::odt::tests::content_of(&saved);
|
||||
assert!(!c.contains("<text:list"), "the outline numbers it: {c}");
|
||||
assert!(c.contains(r#"<text:h text:style-name="Head" text:outline-level="1">First"#), "{c}");
|
||||
// A numbered level stays attached to the outline; an unnumbered one doesn't take its indent.
|
||||
let head = |xml: String| xml.split("<style:style ").find(|x| x.starts_with(r#"style:name="Head""#)).map(String::from).unwrap_or_default();
|
||||
assert!(!head(crate::odt::tests::styles_of(&saved)).contains("style:list-style-name"));
|
||||
let back = import(&saved).unwrap();
|
||||
assert!(num(&back, 0).is_some());
|
||||
assert_eq!(num(&back, 0), num(&back, 1));
|
||||
let plain = in_custom_style(HEAD, r#"<text:p text:style-name="Head">First</text:p>"#);
|
||||
let s = crate::odt::tests::styles_of(&crate::odt::tests::export_model(&plain).unwrap());
|
||||
assert!(head(s).contains(r#"style:list-style-name="""#));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_styles_based_on_any_kinds_style_keep_their_name_when_edited() {
|
||||
// The kind's style took their place, without their own look.
|
||||
let styles = r##"<style:style style:name="Title" style:family="paragraph"/><style:style style:name="Quotations" style:family="paragraph"/><style:style style:name="Preformatted_20_Text" style:display-name="Preformatted Text" style:family="paragraph"/><style:style style:name="Heading_20_2" style:display-name="Heading 2" style:family="paragraph"/><style:style style:name="Banner" style:family="paragraph" style:parent-style-name="Title"><style:text-properties fo:color="#cc6600"/></style:style><style:style style:name="Aside" style:family="paragraph" style:parent-style-name="Quotations"/><style:style style:name="Listing" style:family="paragraph" style:parent-style-name="Preformatted_20_Text"/><style:style style:name="Plaque" style:family="paragraph" style:parent-style-name="Heading_20_2"/>"##;
|
||||
let body = r#"<text:p text:style-name="Banner">b</text:p><text:p text:style-name="Aside">a</text:p><text:p text:style-name="Listing">l</text:p><text:p text:style-name="Plaque">p</text:p>"#;
|
||||
let saved = crate::odt::tests::export_model(&in_custom_style(styles, body)).unwrap();
|
||||
let c = crate::odt::tests::content_of(&saved);
|
||||
for want in [
|
||||
r#"<text:p text:style-name="Banner">b"#,
|
||||
r#"<text:p text:style-name="Aside">a"#,
|
||||
r#"<text:p text:style-name="Listing">l"#,
|
||||
r#"<text:h text:style-name="Plaque" text:outline-level="2">p"#,
|
||||
] {
|
||||
assert!(c.contains(want), "{want} in {c}");
|
||||
}
|
||||
let s = crate::odt::tests::styles_of(&saved);
|
||||
assert!(s.contains(r#"style:name="Banner" style:display-name="Banner" style:family="paragraph" style:parent-style-name="Title""#), "{s}");
|
||||
}
|
||||
|
||||
/// A heading's number is its own outline level's, as in LibreOffice, not its style's: `(level)` of
|
||||
/// each paragraph's number, as layout takes it.
|
||||
fn number_levels(d: &Document) -> Vec<Option<u8>> {
|
||||
d.body
|
||||
.iter()
|
||||
.filter_map(|b| b.as_para())
|
||||
.map(|p| p.props.numbering.or(d.styles.resolve_para(&p.props).numbering).filter(|n| n.num != 0).map(|n| n.level))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_headings_own_outline_level_gives_its_number() {
|
||||
let outline = r#"<text:outline-style style:name="Outline"><text:outline-level-style text:level="1" style:num-format="1" style:num-suffix="."/><text:outline-level-style text:level="2" style:num-format="1" text:display-levels="2" style:num-suffix="."/><text:outline-level-style text:level="3" style:num-format=""/></text:outline-style>"#;
|
||||
let styles = format!(
|
||||
r#"{HEAD}<style:style style:name="Low" style:family="paragraph" style:parent-style-name="Standard" style:default-outline-level="3"/><style:style style:name="Heading_20_1" style:display-name="Heading 1" style:family="paragraph" style:default-outline-level="1"/>{outline}"#
|
||||
);
|
||||
let h = |style: &str, level: u8| format!(r#"<text:h text:style-name="{style}" text:outline-level="{level}">{style} {level}</text:h>"#);
|
||||
let body = [h("Head", 1), h("Head", 2), h("Head", 3), h("Low", 3), h("Low", 1), h("Low", 2), h("Heading_20_1", 2), h("Heading_20_1", 3)].concat();
|
||||
let d = in_custom_style(&styles, &body);
|
||||
let want = vec![Some(0), Some(1), None, None, Some(0), Some(1), Some(1), None];
|
||||
assert_eq!(number_levels(&d), want);
|
||||
let nums: std::collections::BTreeSet<u32> = d
|
||||
.body
|
||||
.iter()
|
||||
.filter_map(|b| b.as_para())
|
||||
.filter_map(|p| p.props.numbering.or(d.styles.resolve_para(&p.props).numbering))
|
||||
.map(|n| n.num)
|
||||
.filter(|n| *n != 0)
|
||||
.collect();
|
||||
assert_eq!(nums.len(), 1, "one list with the headings': {nums:?}");
|
||||
// Written from the model the outline still numbers them, by the levels stated, and read back
|
||||
// they are as they were.
|
||||
let saved = crate::odt::tests::export_model(&d).unwrap();
|
||||
let c = crate::odt::tests::content_of(&saved);
|
||||
assert!(!c.contains("<text:list"), "{c}");
|
||||
for (style, level) in [("Head", 2), ("Low", 1), ("Heading_20_1", 3)] {
|
||||
assert!(c.contains(&format!(r#"<text:h text:style-name="{style}" text:outline-level="{level}">{style} {level}"#)), "{c}");
|
||||
}
|
||||
assert_eq!(number_levels(&import(&saved).unwrap()), want);
|
||||
}
|
||||
|
||||
/// A heading in a list is that list's, whatever its outline level would number.
|
||||
#[test]
|
||||
fn a_heading_in_a_list_keeps_the_lists_number() {
|
||||
let styles = format!(
|
||||
r#"{HEAD}{NUMBERED}<text:list-style style:name="L"><text:list-level-style-number text:level="1" style:num-format="a"/></text:list-style>"#
|
||||
);
|
||||
let d = in_custom_style(
|
||||
&styles,
|
||||
r#"<text:list text:style-name="L"><text:list-item><text:h text:style-name="Head" text:outline-level="2">x</text:h></text:list-item></text:list>"#,
|
||||
);
|
||||
let p = d.body[0].as_para().unwrap();
|
||||
let n = p.props.numbering.expect("its list");
|
||||
assert_eq!(d.numbering.level(n.num, n.level).map(|l| l.format), Some(NumFormat::LowerLetter));
|
||||
}
|
||||
|
||||
/// A style based on Title with an outline level is a heading at that level, in its own name.
|
||||
#[test]
|
||||
fn a_title_based_style_with_an_outline_level_stays_a_heading() {
|
||||
let styles = r#"<style:style style:name="Title" style:family="paragraph"/><style:style style:name="Banner" style:family="paragraph" style:parent-style-name="Title" style:default-outline-level="1"/>"#;
|
||||
let mut d = in_custom_style(styles, r#"<text:p text:style-name="Banner">report</text:p>"#);
|
||||
let p = d.body[0].as_para().unwrap().props.clone();
|
||||
assert_eq!((p.style.as_deref(), d.styles.resolve_para(&p).outline_level), (Some("Banner"), Some(0)));
|
||||
let saved = saved_after_an_edit(&mut d);
|
||||
let c = crate::odt::tests::content_of(&saved);
|
||||
assert!(c.contains(r#"<text:h text:style-name="Banner" text:outline-level="1">Yearly report"#), "{c}");
|
||||
}
|
||||
|
||||
/// A style based on a numbered heading, at a level the outline doesn't number, has no number: as
|
||||
/// in LibreOffice, not its parent's.
|
||||
#[test]
|
||||
fn a_style_at_an_unnumbered_level_has_no_number_from_its_parent() {
|
||||
let outline = r#"<text:outline-style style:name="Outline"><text:outline-level-style text:level="1" style:num-format="1" style:num-suffix="."/><text:outline-level-style text:level="2" style:num-format=""/><text:outline-level-style text:level="3" style:num-format="1" style:num-suffix="."/></text:outline-style>"#;
|
||||
let styles = format!(
|
||||
r#"<style:style style:name="Heading_20_1" style:display-name="Heading 1" style:family="paragraph" style:parent-style-name="Standard" style:default-outline-level="1"/><style:style style:name="Child" style:family="paragraph" style:parent-style-name="Heading_20_1" style:default-outline-level="2"/><style:style style:name="Grand" style:family="paragraph" style:parent-style-name="Heading_20_1" style:default-outline-level="3"/>{outline}"#
|
||||
);
|
||||
let body = r#"<text:h text:style-name="Heading_20_1" text:outline-level="1">One</text:h><text:p text:style-name="Child">As p</text:p><text:h text:style-name="Child" text:outline-level="2">As h</text:h><text:p text:style-name="Grand">Third</text:p><text:h text:style-name="Heading_20_1" text:outline-level="1">Two</text:h>"#;
|
||||
let d = in_custom_style(&styles, body);
|
||||
let want = vec![Some(0), None, None, Some(2), Some(0)];
|
||||
assert_eq!(number_levels(&d), want);
|
||||
let saved = crate::odt::tests::export_model(&d).unwrap();
|
||||
let written = crate::odt::tests::styles_of(&saved);
|
||||
let child = written.split("<style:style ").find(|x| x.starts_with(r#"style:name="Child""#)).unwrap_or_default();
|
||||
assert!(child.contains(r#"style:list-style-name="""#), "LibreOffice gives it no number: {child}");
|
||||
assert_eq!(number_levels(&import(&saved).unwrap()), want);
|
||||
}
|
||||
|
||||
/// A heading in a list of its own stays in it, whatever the list's levels are linked to: only the
|
||||
/// number the outline itself gives a heading goes with the outline.
|
||||
#[test]
|
||||
fn a_heading_in_a_list_linked_to_a_style_stays_in_it() {
|
||||
use std::sync::Arc;
|
||||
use wordcraft_doc::props::NumRef;
|
||||
let mut d = Document::new();
|
||||
let numbering = Arc::make_mut(&mut d.numbering);
|
||||
let num = numbering.add_list(wordcraft_doc::numbering::ListKind::Numbered);
|
||||
let first = numbering.abstracts.last_mut().and_then(|a| a.levels.first_mut()).unwrap();
|
||||
first.style = Some("Heading1".into());
|
||||
let mut p = wordcraft_doc::Paragraph::with_text("x", Default::default());
|
||||
p.props.style = Some("Heading2".into());
|
||||
p.props.numbering = Some(NumRef { num, level: 1 });
|
||||
let has_list = |d: &Document| crate::odt::tests::content_of(&crate::odt::tests::export_model(d).unwrap()).contains("<text:list");
|
||||
// At a deeper level than the link, no level of its own stated.
|
||||
d.body = vec![wordcraft_doc::para_block(p.clone())];
|
||||
assert!(has_list(&d), "a list of its own");
|
||||
// At its own level too, but its heading style isn't numbered: the outline wouldn't number it.
|
||||
p.props.outline_level = Some(1);
|
||||
d.body = vec![wordcraft_doc::para_block(p)];
|
||||
assert!(has_list(&d), "the outline has no number for it");
|
||||
// Its heading style numbered there by this list: the outline's number.
|
||||
Arc::make_mut(&mut d.styles).get_mut("Heading2").unwrap().para.numbering = Some(NumRef { num, level: 1 });
|
||||
assert!(!has_list(&d), "the outline's");
|
||||
}
|
||||
|
||||
/// Past Heading 6 the outline written has no number to give, so a heading there keeps its list.
|
||||
#[test]
|
||||
fn a_heading_past_level_six_keeps_its_list() {
|
||||
use std::sync::Arc;
|
||||
use wordcraft_doc::props::NumRef;
|
||||
let mut d = Document::new();
|
||||
let num = Arc::make_mut(&mut d.numbering).add_list(wordcraft_doc::numbering::ListKind::Numbered);
|
||||
Arc::make_mut(&mut d.styles).get_mut("Heading1").unwrap().para.numbering = Some(NumRef { num, level: 0 });
|
||||
for level in 6..=8 {
|
||||
let mut p = wordcraft_doc::Paragraph::with_text("x", Default::default());
|
||||
p.props.style = Some("Heading6".into());
|
||||
p.props.outline_level = Some(level);
|
||||
p.props.numbering = Some(NumRef { num, level });
|
||||
d.body = vec![wordcraft_doc::para_block(p)];
|
||||
let c = crate::odt::tests::content_of(&crate::odt::tests::export_model(&d).unwrap());
|
||||
assert!(c.contains("<text:list"), "level {level}: {c}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A heading past level six numbered through its style keeps its list too, as the outline written
|
||||
/// numbers only six: read, written from the model and with its style edited.
|
||||
#[test]
|
||||
fn a_heading_past_level_six_numbered_by_its_style_keeps_its_list() {
|
||||
use std::sync::Arc;
|
||||
for level in 7..=9u8 {
|
||||
let styles = format!(
|
||||
r#"<style:style style:name="Deep" style:family="paragraph" style:parent-style-name="Standard" style:default-outline-level="{level}"/><text:outline-style style:name="Outline"><text:outline-level-style text:level="{level}" style:num-format="1" style:num-suffix="."/></text:outline-style>"#
|
||||
);
|
||||
let body = format!(r#"<text:h text:style-name="Deep" text:outline-level="{level}">x</text:h>"#);
|
||||
let mut d = in_custom_style(&styles, &body);
|
||||
let check = |saved: &[u8], what: &str| {
|
||||
let c = crate::odt::tests::content_of(saved);
|
||||
assert!(c.contains("<text:list"), "level {level}, {what}: {c}");
|
||||
};
|
||||
check(&crate::odt::tests::export_model(&d).unwrap(), "from the model");
|
||||
let id = d.body[0].as_para().unwrap().props.style.clone().unwrap();
|
||||
Arc::make_mut(&mut d.styles).get_mut(&id).unwrap().chr.italic = Some(true);
|
||||
let saved = export(&d).unwrap();
|
||||
check(&saved, "style edited");
|
||||
let back = import(&saved).unwrap();
|
||||
let p = back.body[0].as_para().unwrap();
|
||||
let n = p.props.numbering.or_else(|| back.styles.para_style_props(p.props.style.as_deref().unwrap_or("Normal")).0.numbering);
|
||||
assert_eq!(n.map(|n| n.level), Some(level - 1), "level {level}, reopened");
|
||||
}
|
||||
}
|
||||
|
||||
/// A style at an unnumbered level with a heading numbered by its own level stays on the outline,
|
||||
/// or LibreOffice shows that heading no number; with none, it comes off, for the level's indent.
|
||||
#[test]
|
||||
fn a_style_with_a_heading_numbered_by_its_own_level_stays_on_the_outline() {
|
||||
let styles = format!(
|
||||
r#"<style:style style:name="Low" style:family="paragraph" style:parent-style-name="Standard" style:default-outline-level="3"/><style:style style:name="Heading_20_3" style:display-name="Heading 3" style:family="paragraph" style:default-outline-level="3"/>{NUMBERED}"#
|
||||
);
|
||||
let saved = |body: &str| crate::odt::tests::styles_of(&crate::odt::tests::export_model(&in_custom_style(&styles, body)).unwrap());
|
||||
let style_of = |xml: &str, name: &str| {
|
||||
xml.split("<style:style ").find(|x| x.starts_with(&format!(r#"style:name="{name}""#))).map(String::from).unwrap_or_default()
|
||||
};
|
||||
let xml = saved(
|
||||
r#"<text:h text:style-name="Low" text:outline-level="1">a</text:h><text:h text:style-name="Heading_20_3" text:outline-level="2">b</text:h>"#,
|
||||
);
|
||||
assert!(!style_of(&xml, "Low").contains("style:list-style-name"), "{xml}");
|
||||
assert!(!style_of(&xml, "Heading_20_3").contains("style:list-style-name"), "{xml}");
|
||||
let xml = saved(r#"<text:h text:style-name="Low" text:outline-level="3">a</text:h>"#);
|
||||
assert!(style_of(&xml, "Low").contains(r#"style:list-style-name="""#), "{xml}");
|
||||
}
|
||||
@@ -322,7 +322,7 @@ impl Writer {
|
||||
/// The paragraph style of `p`; `start` makes it begin a page of that master page (ODF 1.3
|
||||
/// §19.471 `style:master-page-name`), restarting page numbering where asked (§20.322).
|
||||
fn para_style_at(&mut self, p: &Para, start: Option<&SecStart>) -> String {
|
||||
let named = p.extra.as_ref().and_then(|x| x.style.as_deref()).filter(|_| matches!(p.kind, Kind::Normal | Kind::Rule));
|
||||
let named = p.extra.as_ref().and_then(|x| x.style.as_deref());
|
||||
let parent = match (p.kind, self.note_parent, named) {
|
||||
// A custom style: written as a common style of the same name (see `custom_styles`).
|
||||
(_, _, Some(id)) => {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
> **2026-11-05:** DOCX paragraph `w:adjustRightInd` keeps its default and explicit values through style resolution and schema-ordered repeated saves.
|
||||
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-08 · **Change:** trivial (ODT pictures keep the size their file gives); previously trivial (ODT frames keep the page they are anchored to); previously trivial (ODT: a document's language kept when its styles are written from the model); previously trivial (ODT table and row backgrounds); previously trivial (ODT row: how tab stops are saved, corrected); previously trivial (RTF footnotes, endnotes and comments, #1053); previously trivial (XML line ends in text normalised, #5897); previously trivial (ODT pictures offered in several formats); previously trivial (ODT heading text of another size); previously trivial (built-in citation source lookups, #4888; current-main progress records retained); previously trivial (ODT: no settings for what the standard leaves open); previously trivial (picture brightness, contrast and transparency); previously trivial (ODT paragraph groups kept as read); previously trivial (ODT paragraphs with charts kept as read); previously trivial (ODT sections in cells and at empty paragraphs); previously trivial (ODT element audit); previously trivial (ODT reference marks written as such); previously trivial (ODT hidden sections stay hidden; lists kept as read); previously trivial (ODT manifest lists every file); previously trivial (ODT paragraphs with bookmarks, notes, objects and page-anchored frames written as read); previously trivial (ODT paragraphs with text boxes written as read); previously trivial (ODT paragraphs with comments and tracked changes written as read); previously trivial (ODT paragraphs with pictures and shapes written as read); previously trivial (ODT sections inside text boxes); previously trivial (ODT definitions sharing a name, sections around tables, chart replacement pictures, note citations, stacking order); previously trivial (ODT form definitions and indexes written as read); previously trivial (ODT gradient angles by the file's version; deviation documented); previously minor (ODT: unedited tables, pages, sections, properties and declarations written as read; no-edit loss gate); previously minor (ODT: unedited paragraphs and style definitions written as read); previously trivial (ODT author fields said not fixed); previously trivial (ODT default text colour; covered cells' content); previously trivial (ODT widow control profile case; tabs from the indent kept); previously trivial (ODT span kerning; note reference formatting; notes starting with a tab); previously 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 sizLine truncated
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-08 · **Change:** trivial (ODT custom styles with an outline level); previously trivial (ODT pictures keep the size their file gives); previously trivial (ODT frames keep the page they are anchored to); previously trivial (ODT: a document's language kept when its styles are written from the model); previously trivial (ODT table and row backgrounds); previously trivial (ODT row: how tab stops are saved, corrected); previously trivial (RTF footnotes, endnotes and comments, #1053); previously trivial (XML line ends in text normalised, #5897); previously trivial (ODT pictures offered in several formats); previously trivial (ODT heading text of another size); previously trivial (built-in citation source lookups, #4888; current-main progress records retained); previously trivial (ODT: no settings for what the standard leaves open); previously trivial (picture brightness, contrast and transparency); previously trivial (ODT paragraph groups kept as read); previously trivial (ODT paragraphs with charts kept as read); previously trivial (ODT sections in cells and at empty paragraphs); previously trivial (ODT element audit); previously trivial (ODT reference marks written as such); previously trivial (ODT hidden sections stay hidden; lists kept as read); previously trivial (ODT manifest lists every file); previously trivial (ODT paragraphs with bookmarks, notes, objects and page-anchored frames written as read); previously trivial (ODT paragraphs with text boxes written as read); previously trivial (ODT paragraphs with comments and tracked changes written as read); previously trivial (ODT paragraphs with pictures and shapes written as read); previously trivial (ODT sections inside text boxes); previously trivial (ODT definitions sharing a name, sections around tables, chart replacement pictures, note citations, stacking order); previously trivial (ODT form definitions and indexes written as read); previously trivial (ODT gradient angles by the file's version; deviation documented); previously minor (ODT: unedited tables, pages, sections, properties and declarations written as read; no-edit loss gate); previously minor (ODT: unedited paragraphs and style definitions written as read); previously trivial (ODT author fields said not fixed); previously trivial (ODT default text colour; covered cells' content); previously trivial (ODT widow control profile case; tabs from the indent kept); previously trivial (ODT span kerning; note reference formatting; notes starting with a tab); previously 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 isLine truncated
|
||||
> **CLI path update:** 2026-11-04 · Options before a non-Unicode input filename no longer make the CLI reject that filename; text option values still require Unicode; `run --file` and `run --script` retain native paths. No ranked gap or readiness estimate changes.
|
||||
|
||||
> **Legacy form update:** 2026-10-22 · trivial: field names and selected drop-down labels decode numeric XML character references once.
|
||||
@@ -335,6 +335,7 @@ For field results, the engine parser treats a backslash in quoted arguments as e
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-08 | trivial | ODT row corrected: a file whose tab stops are measured from the indent is saved measuring from it, not always from the margin (the 2026-11-03 change); the default stops are counted from the indent |
|
||||
| 2026-11-06 | trivial | ODT: a custom paragraph style with an outline level (`style:default-outline-level`) stays the paragraph's style. It draws with the file's look, is a heading at that level and is numbered with the outline, and an edited paragraph is saved under its own name (`<text:h text:style-name="Head" text:outline-level="1">`). It became WordCraft's Heading 1, on screen and in LibreOffice after an edit. Custom styles based on a heading, Title, Quotations or Preformatted Text also keep their name when edited A heading's own `text:outline-level` gives its number, as in LibreOffice. A style at a level the outline doesn't number takes no number from its parent. A heading past level six numbered through its style keeps its list too. |
|
||||
| 2026-11-05 | trivial | ODT: a picture keeps the size its frame states. Opening a file fitted one wider than the text to it, and any wider than 6.5 in to that, which took its paragraph off being written as read and moved things in LibreOffice after a save Stated on one side, the other follows its proportions. In line with no size stated, it is fitted to the text when read, an object's picture too. A frame stating a width of nothing states no size. A picture in line that is raised, turned or mirrored is fitted too. |
|
||||
| 2026-11-05 | trivial | ODT: a frame or shape anchored to a page keeps its page number (`text:anchor-page-number`). It was written without one, so a frame on page 3 came back on page 1 in LibreOffice after a save. WordCraft's own layout still places it on its anchor paragraph's page. Groups keep theirs too, and a number on another anchor is ignored, as LibreOffice does. Moved in WordCraft onto a spot where a paragraph starts, a frame is placed by that paragraph and its page number is removed, not only hidden. Dropped where no paragraph starts, it stays anchored to the page and its number becomes the new page's. |
|
||||
| 2026-11-05 | trivial | ODT: a document's language, stated in its default style or Standard, is read and written back from the model. After numbering or a new style it was dropped on save, so LibreOffice showed the document in its own default language; WordCraft also proofed such a document as English. A document stating no language has none 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. The language written is Normal's, as WordCraft has it, not the defaults' under it. |
|
||||
|
||||
Reference in new issue
Block a user