pub struct NumberingDefinition {
pub id: u32,
pub levels: Vec<ListLevel>,
}Expand description
A numbering (list) definition declared in word/numbering.xml, referenced from paragraphs
(Paragraph.numbering_id) by id.
WordprocessingML actually splits a list definition into two linked elements: w:abstractNum
(the real level formatting, CT_AbstractNum) and w:num (CT_Num, a thin indirection
paragraphs reference by numId, pointing at an abstractNumId) — this indirection exists so
several w:num entries can share one w:abstractNum, which real Word documents do use, but
which this crate doesn’t need for the common case of one standalone list. So this type collapses
both into one value: id corresponds to w:num’s numId (what a paragraph actually
references), and a dedicated w:abstractNum is always written alongside it internally — see
writer.rs. Reading back a real, externally-authored document that DOES share one
w:abstractNum across several w:num entries still works (each w:num becomes its own
NumberingDefinition, with its levels resolved through whichever w:abstractNum it points
to), just without preserving that sharing structure on a round trip.
Fields§
§id: u32This definition’s id (w:num’s w:numId), referenced by Paragraph.numbering_id.
levels: Vec<ListLevel>The formatting for each indent level this list defines, in order (index 0 is the outermost
level, w:lvl’s ilvl="0"). WordprocessingML allows up to 9 (ilvl 0-8); most real lists
only need 1-3.
Implementations§
Source§impl NumberingDefinition
impl NumberingDefinition
Sourcepub fn new(id: u32, levels: Vec<ListLevel>) -> NumberingDefinition
pub fn new(id: u32, levels: Vec<ListLevel>) -> NumberingDefinition
Creates a numbering definition with the given id and levels (fully custom — see
NumberingDefinition::bullet/ NumberingDefinition::decimal for ready-made common
cases).
Examples found in repository?
13fn main() -> office_toolkit::Result<()> {
14 let path = output_path("docx_styles_and_lists.docx");
15
16 let heading_style = Style::new("Heading1", "Heading 1", StyleKind::Paragraph)
17 .with_bold(true)
18 .with_font_size(32);
19 let emphasis_style = Style::new("StrongEmphasis", "Strong Emphasis", StyleKind::Character)
20 .with_bold(true)
21 .with_color("C00000");
22
23 let bulleted = NumberingDefinition::bullet(1);
24 let numbered = NumberingDefinition::decimal(2);
25 let custom = NumberingDefinition::new(
26 3,
27 vec![
28 ListLevel::new(NumberFormat::UpperRoman, "%1.", 720, 360),
29 ListLevel::new(NumberFormat::LowerLetter, "%2)", 1440, 360),
30 ],
31 );
32
33 let document = Document::new()
34 .with_style(heading_style)
35 .with_style(emphasis_style)
36 .with_numbering_definition(bulleted)
37 .with_numbering_definition(numbered)
38 .with_numbering_definition(custom)
39 .with_paragraph(heading("Named paragraph and character styles", false))
40 .with_paragraph(
41 Paragraph::with_text("This paragraph uses the Heading 1 style.")
42 .with_style_id("Heading1"),
43 )
44 .with_paragraph(
45 Paragraph::new()
46 .with_run(Run::new("Plain text, then "))
47 .with_run(Run::new("some strongly emphasized text").with_style_id("StrongEmphasis"))
48 .with_run(Run::new(", then plain text again.")),
49 )
50 .with_paragraph(heading("Bulleted list", true))
51 .with_paragraph(Paragraph::with_text("First item").with_numbering(1, 0))
52 .with_paragraph(Paragraph::with_text("Second item").with_numbering(1, 0))
53 .with_paragraph(Paragraph::with_text("A sub-item, one level deeper").with_numbering(1, 1))
54 .with_paragraph(heading("Numbered list", true))
55 .with_paragraph(Paragraph::with_text("First step").with_numbering(2, 0))
56 .with_paragraph(Paragraph::with_text("Second step").with_numbering(2, 0))
57 .with_paragraph(
58 Paragraph::with_text("A sub-step, cumulatively numbered").with_numbering(2, 1),
59 )
60 .with_paragraph(heading(
61 "Custom multi-level list (roman numerals, then letters)",
62 true,
63 ))
64 .with_paragraph(Paragraph::with_text("First top-level item").with_numbering(3, 0))
65 .with_paragraph(Paragraph::with_text("A lettered sub-item").with_numbering(3, 1))
66 .with_paragraph(Paragraph::with_text("Second top-level item").with_numbering(3, 0));
67
68 document.save_to_file(&path)?;
69 println!("Wrote {}", path.display());
70 Ok(())
71}Sourcepub fn bullet(id: u32) -> NumberingDefinition
pub fn bullet(id: u32) -> NumberingDefinition
A ready-made 3-level bulleted (unordered) list, using the same bullet characters, format and indentation Word’s own default “Bullets” gallery entry uses when it doesn’t need to fall back to a Wingdings/Symbol-font glyph — this crate doesn’t model fonts, so plain Unicode bullet characters are used instead of Word’s own Wingdings/Symbol ones (which would render as the wrong glyph without the matching font declared on the run).
Examples found in repository?
13fn main() -> office_toolkit::Result<()> {
14 let path = output_path("docx_styles_and_lists.docx");
15
16 let heading_style = Style::new("Heading1", "Heading 1", StyleKind::Paragraph)
17 .with_bold(true)
18 .with_font_size(32);
19 let emphasis_style = Style::new("StrongEmphasis", "Strong Emphasis", StyleKind::Character)
20 .with_bold(true)
21 .with_color("C00000");
22
23 let bulleted = NumberingDefinition::bullet(1);
24 let numbered = NumberingDefinition::decimal(2);
25 let custom = NumberingDefinition::new(
26 3,
27 vec![
28 ListLevel::new(NumberFormat::UpperRoman, "%1.", 720, 360),
29 ListLevel::new(NumberFormat::LowerLetter, "%2)", 1440, 360),
30 ],
31 );
32
33 let document = Document::new()
34 .with_style(heading_style)
35 .with_style(emphasis_style)
36 .with_numbering_definition(bulleted)
37 .with_numbering_definition(numbered)
38 .with_numbering_definition(custom)
39 .with_paragraph(heading("Named paragraph and character styles", false))
40 .with_paragraph(
41 Paragraph::with_text("This paragraph uses the Heading 1 style.")
42 .with_style_id("Heading1"),
43 )
44 .with_paragraph(
45 Paragraph::new()
46 .with_run(Run::new("Plain text, then "))
47 .with_run(Run::new("some strongly emphasized text").with_style_id("StrongEmphasis"))
48 .with_run(Run::new(", then plain text again.")),
49 )
50 .with_paragraph(heading("Bulleted list", true))
51 .with_paragraph(Paragraph::with_text("First item").with_numbering(1, 0))
52 .with_paragraph(Paragraph::with_text("Second item").with_numbering(1, 0))
53 .with_paragraph(Paragraph::with_text("A sub-item, one level deeper").with_numbering(1, 1))
54 .with_paragraph(heading("Numbered list", true))
55 .with_paragraph(Paragraph::with_text("First step").with_numbering(2, 0))
56 .with_paragraph(Paragraph::with_text("Second step").with_numbering(2, 0))
57 .with_paragraph(
58 Paragraph::with_text("A sub-step, cumulatively numbered").with_numbering(2, 1),
59 )
60 .with_paragraph(heading(
61 "Custom multi-level list (roman numerals, then letters)",
62 true,
63 ))
64 .with_paragraph(Paragraph::with_text("First top-level item").with_numbering(3, 0))
65 .with_paragraph(Paragraph::with_text("A lettered sub-item").with_numbering(3, 1))
66 .with_paragraph(Paragraph::with_text("Second top-level item").with_numbering(3, 0));
67
68 document.save_to_file(&path)?;
69 println!("Wrote {}", path.display());
70 Ok(())
71}Sourcepub fn decimal(id: u32) -> NumberingDefinition
pub fn decimal(id: u32) -> NumberingDefinition
A ready-made 3-level numbered (ordered) list, using the same cumulative numbering (each level repeats its ancestors’ counters, e.g. “1.1.1.”) and indentation Word’s own default “Numbering” gallery entry uses.
Examples found in repository?
13fn main() -> office_toolkit::Result<()> {
14 let path = output_path("docx_styles_and_lists.docx");
15
16 let heading_style = Style::new("Heading1", "Heading 1", StyleKind::Paragraph)
17 .with_bold(true)
18 .with_font_size(32);
19 let emphasis_style = Style::new("StrongEmphasis", "Strong Emphasis", StyleKind::Character)
20 .with_bold(true)
21 .with_color("C00000");
22
23 let bulleted = NumberingDefinition::bullet(1);
24 let numbered = NumberingDefinition::decimal(2);
25 let custom = NumberingDefinition::new(
26 3,
27 vec![
28 ListLevel::new(NumberFormat::UpperRoman, "%1.", 720, 360),
29 ListLevel::new(NumberFormat::LowerLetter, "%2)", 1440, 360),
30 ],
31 );
32
33 let document = Document::new()
34 .with_style(heading_style)
35 .with_style(emphasis_style)
36 .with_numbering_definition(bulleted)
37 .with_numbering_definition(numbered)
38 .with_numbering_definition(custom)
39 .with_paragraph(heading("Named paragraph and character styles", false))
40 .with_paragraph(
41 Paragraph::with_text("This paragraph uses the Heading 1 style.")
42 .with_style_id("Heading1"),
43 )
44 .with_paragraph(
45 Paragraph::new()
46 .with_run(Run::new("Plain text, then "))
47 .with_run(Run::new("some strongly emphasized text").with_style_id("StrongEmphasis"))
48 .with_run(Run::new(", then plain text again.")),
49 )
50 .with_paragraph(heading("Bulleted list", true))
51 .with_paragraph(Paragraph::with_text("First item").with_numbering(1, 0))
52 .with_paragraph(Paragraph::with_text("Second item").with_numbering(1, 0))
53 .with_paragraph(Paragraph::with_text("A sub-item, one level deeper").with_numbering(1, 1))
54 .with_paragraph(heading("Numbered list", true))
55 .with_paragraph(Paragraph::with_text("First step").with_numbering(2, 0))
56 .with_paragraph(Paragraph::with_text("Second step").with_numbering(2, 0))
57 .with_paragraph(
58 Paragraph::with_text("A sub-step, cumulatively numbered").with_numbering(2, 1),
59 )
60 .with_paragraph(heading(
61 "Custom multi-level list (roman numerals, then letters)",
62 true,
63 ))
64 .with_paragraph(Paragraph::with_text("First top-level item").with_numbering(3, 0))
65 .with_paragraph(Paragraph::with_text("A lettered sub-item").with_numbering(3, 1))
66 .with_paragraph(Paragraph::with_text("Second top-level item").with_numbering(3, 0));
67
68 document.save_to_file(&path)?;
69 println!("Wrote {}", path.display());
70 Ok(())
71}Trait Implementations§
Source§impl Clone for NumberingDefinition
impl Clone for NumberingDefinition
Source§fn clone(&self) -> NumberingDefinition
fn clone(&self) -> NumberingDefinition
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NumberingDefinition
impl Debug for NumberingDefinition
impl Eq for NumberingDefinition
Source§impl PartialEq for NumberingDefinition
impl PartialEq for NumberingDefinition
impl StructuralPartialEq for NumberingDefinition
Auto Trait Implementations§
impl Freeze for NumberingDefinition
impl RefUnwindSafe for NumberingDefinition
impl Send for NumberingDefinition
impl Sync for NumberingDefinition
impl Unpin for NumberingDefinition
impl UnsafeUnpin for NumberingDefinition
impl UnwindSafe for NumberingDefinition
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.