pub struct Theme {
pub name: String,
pub colors: ColorScheme,
pub fonts: FontScheme,
}Expand description
A document’s theme (word/theme/theme1.xml, CT_OfficeStyleSheet, root element <a:theme>) —
the combination of color scheme and font scheme behind Word’s own “Theme Colors”/“Theme Fonts”
palettes, and behind what Word’s built-in heading styles (Heading 1-9, Title..) resolve to,
since those are defined in terms of theme slots inside Word’s own built-in style definitions
rather than anything in Document.styles. This crate’s own Style/Run formatting never
references a theme slot — color/highlight/underline_color are always literal values, never
w:themeColor — so a Theme mainly matters for controlling those built-in styles’ appearance
and for round-tripping a document’s existing theme unchanged.
A theme part also requires fmtScheme (a fill/line/effect “style matrix”, CT_StyleMatrix —
CT_BaseStyles’s three children, clrScheme/fontScheme/fmtScheme, are all
minOccurs="1"), which is relevant almost entirely to DrawingML shapes/charts, out of scope for
word-ooxml entirely (see Image’s doc comment on what DrawingML content this crate does
support). It is always written as a fixed copy of Office’s own built-in default rather than also
modeled here: each of fmtScheme’s four lists (fillStyleLst/lnStyleLst/effectStyleLst/
bgFillStyleLst) is a minOccurs="3" maxOccurs="3" sequence of DrawingML fill/line/effect
definitions, non-trivial to also expose as configurable, and no real need for that has come up —
the same deliberate scope limit as the fixed default w:sectPr written since.
objectDefaults/extraClrSchemeLst (both minOccurs="0" on CT_OfficeStyleSheet itself) are
omitted entirely rather than also given a fixed default, since omitting them outright is simpler
and just as schema-valid.
Fields§
§name: StringThe theme’s name (<a:theme name="..">), shown in Word’s Design > Themes gallery. Also
reused, unchanged, as the name attribute of the nested <a:clrScheme>/<a:fontScheme>
elements when writing — real Word-authored themes usually give all three the same name (e.g.
"Office"), and this crate doesn’t model them separately.
colors: ColorSchemeThe theme’s 12-color palette.
fonts: FontSchemeThe theme’s heading/body typefaces.
Implementations§
Source§impl Theme
impl Theme
Sourcepub fn new(
name: impl Into<String>,
colors: ColorScheme,
fonts: FontScheme,
) -> Theme
pub fn new( name: impl Into<String>, colors: ColorScheme, fonts: FontScheme, ) -> Theme
Creates a theme with the given name, colors and fonts.
Examples found in repository?
14fn main() -> office_toolkit::Result<()> {
15 let default_theme_document = Document::new()
16 .with_theme(Theme::office_default())
17 .with_paragraph(Paragraph::with_text("Office's built-in default theme."))
18 .with_paragraph(Paragraph::with_text(
19 "Cambria for headings, Calibri for body text, the classic Office palette.",
20 ));
21 let default_path = output_path("docx_theme_default.docx");
22 default_theme_document.save_to_file(&default_path)?;
23 println!("Wrote {}", default_path.display());
24
25 // A custom, branded theme: a dark navy/orange palette and a different
26 // heading/body font pairing.
27 let custom_colors = ColorScheme::new(
28 "1B1B1B", "FFFFFF", "0A2540", "F5F5F5", "0A2540", "E8622C", "2E86AB", "6FB98F", "F4A259",
29 "8E4585", "1155CC", "6B3FA0",
30 );
31 let custom_fonts = FontScheme::new("Georgia", "Verdana");
32 let custom_theme_document = Document::new()
33 .with_theme(Theme::new("Custom Brand", custom_colors, custom_fonts))
34 .with_paragraph(Paragraph::with_text("A custom, branded theme."))
35 .with_paragraph(Paragraph::with_text(
36 "Georgia for headings, Verdana for body text, a navy/orange palette.",
37 ));
38 let custom_path = output_path("docx_theme_custom.docx");
39 custom_theme_document.save_to_file(&custom_path)?;
40 println!("Wrote {}", custom_path.display());
41
42 Ok(())
43}Sourcepub fn office_default() -> Theme
pub fn office_default() -> Theme
Office’s own built-in default theme: its classic “Office” color palette and Cambria/Calibri heading/body fonts — the same theme a brand-new blank document uses.
Examples found in repository?
14fn main() -> office_toolkit::Result<()> {
15 let default_theme_document = Document::new()
16 .with_theme(Theme::office_default())
17 .with_paragraph(Paragraph::with_text("Office's built-in default theme."))
18 .with_paragraph(Paragraph::with_text(
19 "Cambria for headings, Calibri for body text, the classic Office palette.",
20 ));
21 let default_path = output_path("docx_theme_default.docx");
22 default_theme_document.save_to_file(&default_path)?;
23 println!("Wrote {}", default_path.display());
24
25 // A custom, branded theme: a dark navy/orange palette and a different
26 // heading/body font pairing.
27 let custom_colors = ColorScheme::new(
28 "1B1B1B", "FFFFFF", "0A2540", "F5F5F5", "0A2540", "E8622C", "2E86AB", "6FB98F", "F4A259",
29 "8E4585", "1155CC", "6B3FA0",
30 );
31 let custom_fonts = FontScheme::new("Georgia", "Verdana");
32 let custom_theme_document = Document::new()
33 .with_theme(Theme::new("Custom Brand", custom_colors, custom_fonts))
34 .with_paragraph(Paragraph::with_text("A custom, branded theme."))
35 .with_paragraph(Paragraph::with_text(
36 "Georgia for headings, Verdana for body text, a navy/orange palette.",
37 ));
38 let custom_path = output_path("docx_theme_custom.docx");
39 custom_theme_document.save_to_file(&custom_path)?;
40 println!("Wrote {}", custom_path.display());
41
42 Ok(())
43}Trait Implementations§
impl Eq for Theme
impl StructuralPartialEq for Theme
Auto Trait Implementations§
impl Freeze for Theme
impl RefUnwindSafe for Theme
impl Send for Theme
impl Sync for Theme
impl Unpin for Theme
impl UnsafeUnpin for Theme
impl UnwindSafe for Theme
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.