Skip to main content

FontConfig

Struct FontConfig 

Source
pub struct FontConfig {
    pub default_font: Option<String>,
    pub code_font: Option<String>,
    pub default_font_source: Option<FontSource>,
    pub code_font_source: Option<FontSource>,
    pub fallback_fonts: Vec<String>,
    pub fallback_font_sources: Vec<FontSource>,
    pub enable_subsetting: bool,
}
Expand description

Configuration for fonts used in the generated PDF.

Both default_font and code_font accept friendly names (“Georgia”, “Helvetica”, “/path/to/font.ttf”) and are resolved at render time. Explicit *_source fields take priority when set.

Fields§

§default_font: Option<String>

Default font name for body text.

§code_font: Option<String>

Font name for code blocks.

§default_font_source: Option<FontSource>

Font source for body text. Takes priority over default_font if set.

§code_font_source: Option<FontSource>

Font source for code blocks. Takes priority over code_font if set.

§fallback_fonts: Vec<String>

Ordered list of fallback font names (system / path / built-in alias). Resolved the same way as default_font at render time. Composed with fallback_font_sources (sources first, then names) and with any fallback_fonts set on [defaults] in the TOML config.

§fallback_font_sources: Vec<FontSource>

Ordered list of pre-resolved fallback font sources. Useful when embedding fonts via include_bytes! or pointing at a known path. Composed before fallback_fonts.

§enable_subsetting: bool

Enable font subsetting for smaller PDFs.

Implementations§

Source§

impl FontConfig

Source

pub fn new() -> Self

Create a new FontConfig with default settings.

Source

pub fn with_default_font(self, font: impl Into<String>) -> Self

Set the default body font.

Source

pub fn with_code_font(self, font: impl Into<String>) -> Self

Set the code font.

Source

pub fn with_default_font_source(self, source: FontSource) -> Self

Set the font source for body text directly.

Source

pub fn with_code_font_source(self, source: FontSource) -> Self

Set the font source for code blocks directly.

Source

pub fn with_subsetting(self, enabled: bool) -> Self

Enable or disable font subsetting.

Source

pub fn with_fallback_fonts<I, S>(self, names: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Replace the fallback-font name list. See FontConfig::fallback_fonts.

Source

pub fn add_fallback_font(self, name: impl Into<String>) -> Self

Append one fallback name to the existing list.

Source

pub fn add_fallback_font_source(self, source: FontSource) -> Self

Append one pre-resolved fallback font source.

Trait Implementations§

Source§

impl Clone for FontConfig

Source§

fn clone(&self) -> Self

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 FontConfig

Source§

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

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

impl Default for FontConfig

Source§

fn default() -> Self

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

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.