Skip to main content

EmbeddedFont

Struct EmbeddedFont 

Source
pub struct EmbeddedFont {
    pub typeface: String,
    pub regular: Option<Vec<u8>>,
    pub bold: Option<Vec<u8>>,
    pub italic: Option<Vec<u8>>,
    pub bold_italic: Option<Vec<u8>>,
}
Expand description

A TrueType/OpenType font embedded directly in the package (<p:embeddedFont><p:font typeface="."/>{variants}</p:embeddedFont>, CT_EmbeddedFontListEntry).

Not grounded on a real fixture — no .pptx in this project’s local corpus embeds a font. Built directly from ECMA-376’s own CT_EmbeddedFontListEntry/ CT_EmbeddedFontDataId schema text instead — flagged for extra scrutiny once opened in real PowerPoint, same posture already used for Connector/SlideComment and crate::MediaFormat’s p14:media non-support.

Fields§

§typeface: String

<p:font typeface=".."> — the font family name real PowerPoint resolves text runs against.

§regular: Option<Vec<u8>>

<p:regular r:id="..">’s own .fntdata bytes.

§bold: Option<Vec<u8>>

<p:bold r:id="..">’s own .fntdata bytes.

§italic: Option<Vec<u8>>

<p:italic r:id="..">’s own .fntdata bytes.

§bold_italic: Option<Vec<u8>>

<p:boldItalic r:id="..">’s own .fntdata bytes.

Implementations§

Source§

impl EmbeddedFont

Source

pub fn new(typeface: impl Into<String>) -> EmbeddedFont

Creates an embedded font entry with no variants set yet (use with_regular/with_bold/with_italic/with_bold_italic to attach at least one).

Examples found in repository?
examples/pptx_theme_and_metadata.rs (line 47)
19fn main() -> office_toolkit::Result<()> {
20    // A custom theme and an embedded font. `Theme`/`ColorScheme`/
21    // `FontScheme` have no `with_*` builders in this crate — only
22    // `office_default()` or plain struct literals.
23    let custom_theme = Theme {
24        name: "Custom Brand".to_string(),
25        colors: ColorScheme {
26            dark1: "1B1B1B".to_string(),
27            light1: "FFFFFF".to_string(),
28            dark2: "0A2540".to_string(),
29            light2: "F5F5F5".to_string(),
30            accent1: "0A2540".to_string(),
31            accent2: "E8622C".to_string(),
32            accent3: "2E86AB".to_string(),
33            accent4: "6FB98F".to_string(),
34            accent5: "F4A259".to_string(),
35            accent6: "8E4585".to_string(),
36            hyperlink: "1155CC".to_string(),
37            followed_hyperlink: "6B3FA0".to_string(),
38        },
39        fonts: FontScheme {
40            major_latin: "Georgia".to_string(),
41            minor_latin: "Verdana".to_string(),
42        },
43    };
44
45    // Placeholder bytes — a real .pptx would carry genuine TrueType/
46    // OpenType font data here.
47    let embedded_font = EmbeddedFont::new("Custom Sans")
48        .with_regular(vec![0u8; 16])
49        .with_bold(vec![0u8; 16]);
50
51    // A slide with no shapes at all renders as a blank page — nothing shows
52    // the custom theme actually took effect. `drawing::Color` has no
53    // scheme-relative variant yet (`<a:schemeClr>` isn't modeled, see that
54    // enum's own doc comment), so this can't reference the theme's accent1
55    // symbolically; it uses the same literal hex values the theme itself
56    // was built from, purely so the slide visibly matches the palette above.
57    let title_shape = AutoShape::new(2, "Title")
58        .with_properties(
59            ShapeProperties::new()
60                .with_transform(
61                    Transform2D::new()
62                        .with_offset(838_200, 838_200)
63                        .with_extent(6_000_000, 1_500_000),
64                )
65                .with_fill(Fill::Solid(Color::Rgb(custom_theme.colors.accent1.clone()))),
66        )
67        .with_text_body(
68            TextBody::new().with_paragraph(
69                TextParagraph::new().with_run(TextRun::text_with_properties(
70                    "Custom Brand theme — Georgia / Verdana, accent1 = #0A2540",
71                    TextRunProperties::new()
72                        .with_font_family(custom_theme.fonts.major_latin.clone())
73                        .with_font_size_points(24.0)
74                        .with_fill(Fill::Solid(Color::Rgb(custom_theme.colors.light1.clone()))),
75                )),
76            ),
77        );
78
79    let themed_presentation = Presentation::new()
80        .with_theme(custom_theme)
81        .with_embedded_font(embedded_font)
82        .with_slide(Slide::new().with_shape(Shape::AutoShape(title_shape)));
83    let theme_path = output_path("pptx_theme.pptx");
84    themed_presentation.save_to_file(&theme_path)?;
85    println!("Wrote {}", theme_path.display());
86
87    // Document metadata (docProps/core.xml, app.xml, and custom.xml).
88    let properties = DocumentProperties::new()
89        .with_title("Metadata example")
90        .with_author("Example Author")
91        .with_subject("Presentation-level features")
92        .with_custom_property(
93            "ProjectCode",
94            CustomPropertyValue::Text("PPTX-META".to_string()),
95        );
96    // Same reasoning as `title_shape` above: an empty slide would render
97    // blank, so a text shape spells out where the metadata actually lives.
98    let metadata_shape = AutoShape::new(2, "Note")
99        .with_properties(ShapeProperties::new().with_transform(Transform2D::new().with_offset(838_200, 838_200).with_extent(7_000_000, 1_000_000)))
100        .with_text_body(TextBody::new().with_paragraph(TextParagraph::new().with_run(TextRun::text(
101            "This presentation's metadata is in File > Info (title, author, subject, and a custom \"ProjectCode\" property) — not on this slide.",
102        ))));
103    let metadata_presentation = Presentation::new()
104        .with_properties(properties)
105        .with_slide(Slide::new().with_shape(Shape::AutoShape(metadata_shape)));
106    let metadata_path = output_path("pptx_metadata.pptx");
107    metadata_presentation.save_to_file(&metadata_path)?;
108    println!("Wrote {}", metadata_path.display());
109
110    Ok(())
111}
Source

pub fn with_regular(self, data: impl Into<Vec<u8>>) -> EmbeddedFont

Examples found in repository?
examples/pptx_theme_and_metadata.rs (line 48)
19fn main() -> office_toolkit::Result<()> {
20    // A custom theme and an embedded font. `Theme`/`ColorScheme`/
21    // `FontScheme` have no `with_*` builders in this crate — only
22    // `office_default()` or plain struct literals.
23    let custom_theme = Theme {
24        name: "Custom Brand".to_string(),
25        colors: ColorScheme {
26            dark1: "1B1B1B".to_string(),
27            light1: "FFFFFF".to_string(),
28            dark2: "0A2540".to_string(),
29            light2: "F5F5F5".to_string(),
30            accent1: "0A2540".to_string(),
31            accent2: "E8622C".to_string(),
32            accent3: "2E86AB".to_string(),
33            accent4: "6FB98F".to_string(),
34            accent5: "F4A259".to_string(),
35            accent6: "8E4585".to_string(),
36            hyperlink: "1155CC".to_string(),
37            followed_hyperlink: "6B3FA0".to_string(),
38        },
39        fonts: FontScheme {
40            major_latin: "Georgia".to_string(),
41            minor_latin: "Verdana".to_string(),
42        },
43    };
44
45    // Placeholder bytes — a real .pptx would carry genuine TrueType/
46    // OpenType font data here.
47    let embedded_font = EmbeddedFont::new("Custom Sans")
48        .with_regular(vec![0u8; 16])
49        .with_bold(vec![0u8; 16]);
50
51    // A slide with no shapes at all renders as a blank page — nothing shows
52    // the custom theme actually took effect. `drawing::Color` has no
53    // scheme-relative variant yet (`<a:schemeClr>` isn't modeled, see that
54    // enum's own doc comment), so this can't reference the theme's accent1
55    // symbolically; it uses the same literal hex values the theme itself
56    // was built from, purely so the slide visibly matches the palette above.
57    let title_shape = AutoShape::new(2, "Title")
58        .with_properties(
59            ShapeProperties::new()
60                .with_transform(
61                    Transform2D::new()
62                        .with_offset(838_200, 838_200)
63                        .with_extent(6_000_000, 1_500_000),
64                )
65                .with_fill(Fill::Solid(Color::Rgb(custom_theme.colors.accent1.clone()))),
66        )
67        .with_text_body(
68            TextBody::new().with_paragraph(
69                TextParagraph::new().with_run(TextRun::text_with_properties(
70                    "Custom Brand theme — Georgia / Verdana, accent1 = #0A2540",
71                    TextRunProperties::new()
72                        .with_font_family(custom_theme.fonts.major_latin.clone())
73                        .with_font_size_points(24.0)
74                        .with_fill(Fill::Solid(Color::Rgb(custom_theme.colors.light1.clone()))),
75                )),
76            ),
77        );
78
79    let themed_presentation = Presentation::new()
80        .with_theme(custom_theme)
81        .with_embedded_font(embedded_font)
82        .with_slide(Slide::new().with_shape(Shape::AutoShape(title_shape)));
83    let theme_path = output_path("pptx_theme.pptx");
84    themed_presentation.save_to_file(&theme_path)?;
85    println!("Wrote {}", theme_path.display());
86
87    // Document metadata (docProps/core.xml, app.xml, and custom.xml).
88    let properties = DocumentProperties::new()
89        .with_title("Metadata example")
90        .with_author("Example Author")
91        .with_subject("Presentation-level features")
92        .with_custom_property(
93            "ProjectCode",
94            CustomPropertyValue::Text("PPTX-META".to_string()),
95        );
96    // Same reasoning as `title_shape` above: an empty slide would render
97    // blank, so a text shape spells out where the metadata actually lives.
98    let metadata_shape = AutoShape::new(2, "Note")
99        .with_properties(ShapeProperties::new().with_transform(Transform2D::new().with_offset(838_200, 838_200).with_extent(7_000_000, 1_000_000)))
100        .with_text_body(TextBody::new().with_paragraph(TextParagraph::new().with_run(TextRun::text(
101            "This presentation's metadata is in File > Info (title, author, subject, and a custom \"ProjectCode\" property) — not on this slide.",
102        ))));
103    let metadata_presentation = Presentation::new()
104        .with_properties(properties)
105        .with_slide(Slide::new().with_shape(Shape::AutoShape(metadata_shape)));
106    let metadata_path = output_path("pptx_metadata.pptx");
107    metadata_presentation.save_to_file(&metadata_path)?;
108    println!("Wrote {}", metadata_path.display());
109
110    Ok(())
111}
Source

pub fn with_bold(self, data: impl Into<Vec<u8>>) -> EmbeddedFont

Examples found in repository?
examples/pptx_theme_and_metadata.rs (line 49)
19fn main() -> office_toolkit::Result<()> {
20    // A custom theme and an embedded font. `Theme`/`ColorScheme`/
21    // `FontScheme` have no `with_*` builders in this crate — only
22    // `office_default()` or plain struct literals.
23    let custom_theme = Theme {
24        name: "Custom Brand".to_string(),
25        colors: ColorScheme {
26            dark1: "1B1B1B".to_string(),
27            light1: "FFFFFF".to_string(),
28            dark2: "0A2540".to_string(),
29            light2: "F5F5F5".to_string(),
30            accent1: "0A2540".to_string(),
31            accent2: "E8622C".to_string(),
32            accent3: "2E86AB".to_string(),
33            accent4: "6FB98F".to_string(),
34            accent5: "F4A259".to_string(),
35            accent6: "8E4585".to_string(),
36            hyperlink: "1155CC".to_string(),
37            followed_hyperlink: "6B3FA0".to_string(),
38        },
39        fonts: FontScheme {
40            major_latin: "Georgia".to_string(),
41            minor_latin: "Verdana".to_string(),
42        },
43    };
44
45    // Placeholder bytes — a real .pptx would carry genuine TrueType/
46    // OpenType font data here.
47    let embedded_font = EmbeddedFont::new("Custom Sans")
48        .with_regular(vec![0u8; 16])
49        .with_bold(vec![0u8; 16]);
50
51    // A slide with no shapes at all renders as a blank page — nothing shows
52    // the custom theme actually took effect. `drawing::Color` has no
53    // scheme-relative variant yet (`<a:schemeClr>` isn't modeled, see that
54    // enum's own doc comment), so this can't reference the theme's accent1
55    // symbolically; it uses the same literal hex values the theme itself
56    // was built from, purely so the slide visibly matches the palette above.
57    let title_shape = AutoShape::new(2, "Title")
58        .with_properties(
59            ShapeProperties::new()
60                .with_transform(
61                    Transform2D::new()
62                        .with_offset(838_200, 838_200)
63                        .with_extent(6_000_000, 1_500_000),
64                )
65                .with_fill(Fill::Solid(Color::Rgb(custom_theme.colors.accent1.clone()))),
66        )
67        .with_text_body(
68            TextBody::new().with_paragraph(
69                TextParagraph::new().with_run(TextRun::text_with_properties(
70                    "Custom Brand theme — Georgia / Verdana, accent1 = #0A2540",
71                    TextRunProperties::new()
72                        .with_font_family(custom_theme.fonts.major_latin.clone())
73                        .with_font_size_points(24.0)
74                        .with_fill(Fill::Solid(Color::Rgb(custom_theme.colors.light1.clone()))),
75                )),
76            ),
77        );
78
79    let themed_presentation = Presentation::new()
80        .with_theme(custom_theme)
81        .with_embedded_font(embedded_font)
82        .with_slide(Slide::new().with_shape(Shape::AutoShape(title_shape)));
83    let theme_path = output_path("pptx_theme.pptx");
84    themed_presentation.save_to_file(&theme_path)?;
85    println!("Wrote {}", theme_path.display());
86
87    // Document metadata (docProps/core.xml, app.xml, and custom.xml).
88    let properties = DocumentProperties::new()
89        .with_title("Metadata example")
90        .with_author("Example Author")
91        .with_subject("Presentation-level features")
92        .with_custom_property(
93            "ProjectCode",
94            CustomPropertyValue::Text("PPTX-META".to_string()),
95        );
96    // Same reasoning as `title_shape` above: an empty slide would render
97    // blank, so a text shape spells out where the metadata actually lives.
98    let metadata_shape = AutoShape::new(2, "Note")
99        .with_properties(ShapeProperties::new().with_transform(Transform2D::new().with_offset(838_200, 838_200).with_extent(7_000_000, 1_000_000)))
100        .with_text_body(TextBody::new().with_paragraph(TextParagraph::new().with_run(TextRun::text(
101            "This presentation's metadata is in File > Info (title, author, subject, and a custom \"ProjectCode\" property) — not on this slide.",
102        ))));
103    let metadata_presentation = Presentation::new()
104        .with_properties(properties)
105        .with_slide(Slide::new().with_shape(Shape::AutoShape(metadata_shape)));
106    let metadata_path = output_path("pptx_metadata.pptx");
107    metadata_presentation.save_to_file(&metadata_path)?;
108    println!("Wrote {}", metadata_path.display());
109
110    Ok(())
111}
Source

pub fn with_italic(self, data: impl Into<Vec<u8>>) -> EmbeddedFont

Source

pub fn with_bold_italic(self, data: impl Into<Vec<u8>>) -> EmbeddedFont

Trait Implementations§

Source§

impl Clone for EmbeddedFont

Source§

fn clone(&self) -> EmbeddedFont

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EmbeddedFont

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for EmbeddedFont

Source§

fn default() -> EmbeddedFont

Returns the “default value” for a type. Read more
Source§

impl PartialEq for EmbeddedFont

Source§

fn eq(&self, other: &EmbeddedFont) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for EmbeddedFont

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.