pub struct ColorScheme {
pub dark1: String,
pub light1: String,
pub dark2: String,
pub light2: String,
pub accent1: String,
pub accent2: String,
pub accent3: String,
pub accent4: String,
pub accent5: String,
pub accent6: String,
pub hyperlink: String,
pub followed_hyperlink: String,
}Expand description
A theme’s 12-color palette (<a:clrScheme>, CT_ColorScheme): two dark/ light pairs, six
accents, and two hyperlink colors — the palette behind Word’s “Theme Colors” swatches and
w:themeColor-based direct formatting (CT_Color’s theme-color choice, not modeled on Run/
Style itself, which only ever carry literal RGB colors).
Every slot is stored as a plain 6-digit RGB hex string (no leading #, e.g. "4F81BD"),
written as <a:srgbClr val="..">. CT_Color’s other choice, <a:sysClr> (binding a slot to a
live Windows system color, with a fallback RGB for non-Windows renderers) — what Word’s own
default theme actually uses for dk1/lt1 (bound to windowText/window) — is not modeled
for writing; a plain srgbClr is schema-valid in its place and renders identically outside of
that live system-color binding, which this crate has no way to honor anyway (a document it
writes isn’t tied to any running Windows session). Reading back a real, externally-authored
theme that does use <a:sysClr> for a slot still works: its fallback RGB (lastClr) is
captured instead of the live binding, which is lost on a round trip — see reader.rs.
Fields§
§dark1: String§light1: String§dark2: String§light2: String§accent1: String§accent2: String§accent3: String§accent4: String§accent5: String§accent6: String§hyperlink: String§followed_hyperlink: StringImplementations§
Source§impl ColorScheme
impl ColorScheme
Sourcepub fn new(
dark1: impl Into<String>,
light1: impl Into<String>,
dark2: impl Into<String>,
light2: impl Into<String>,
accent1: impl Into<String>,
accent2: impl Into<String>,
accent3: impl Into<String>,
accent4: impl Into<String>,
accent5: impl Into<String>,
accent6: impl Into<String>,
hyperlink: impl Into<String>,
followed_hyperlink: impl Into<String>,
) -> ColorScheme
pub fn new( dark1: impl Into<String>, light1: impl Into<String>, dark2: impl Into<String>, light2: impl Into<String>, accent1: impl Into<String>, accent2: impl Into<String>, accent3: impl Into<String>, accent4: impl Into<String>, accent5: impl Into<String>, accent6: impl Into<String>, hyperlink: impl Into<String>, followed_hyperlink: impl Into<String>, ) -> ColorScheme
Creates a color scheme from its 12 slots, each a 6-digit RGB hex string (no leading #).
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() -> ColorScheme
pub fn office_default() -> ColorScheme
Office’s own built-in default 12-color palette (the classic “Office” theme colors:
dk1/lt1 as plain black/white rather than Word’s own live sysClr binding — see
ColorScheme’s doc comment).
Trait Implementations§
Source§impl Clone for ColorScheme
impl Clone for ColorScheme
Source§fn clone(&self) -> ColorScheme
fn clone(&self) -> ColorScheme
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 ColorScheme
impl Debug for ColorScheme
impl Eq for ColorScheme
Source§impl PartialEq for ColorScheme
impl PartialEq for ColorScheme
impl StructuralPartialEq for ColorScheme
Auto Trait Implementations§
impl Freeze for ColorScheme
impl RefUnwindSafe for ColorScheme
impl Send for ColorScheme
impl Sync for ColorScheme
impl Unpin for ColorScheme
impl UnsafeUnpin for ColorScheme
impl UnwindSafe for ColorScheme
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.