Skip to main content

GenerateWebfontsResult

Struct GenerateWebfontsResult 

Source
pub struct GenerateWebfontsResult { /* private fields */ }
Expand description

Result of a successful generateWebfonts call. Exposes the generated font bytes (or null for formats that were not requested) and methods to render the CSS and HTML preview.

Implementations§

Source§

impl GenerateWebfontsResult

Source

pub fn regenerate( &mut self, ordered_paths: &[String], changes: &[(String, GlyphChange)], ) -> Result<()>

Rebuild after a batch of file changes, reusing cached glyph geometry for files whose contents are unchanged. Requires the result to have been generated with incremental enabled. ordered_paths is the complete file set after the changes, in the order a fresh build would use (e.g. the glob result); the rebuilt glyphs are ordered to match it, so auto-assigned codepoints and glyph order — and therefore the output bytes — are identical to a fresh generate of that set, including for additions that sort before existing glyphs. changes describes what to do per affected file: added/changed files are read from disk and re-parsed; any file absent from ordered_paths is dropped (an explicit Removed is optional but harmless). Every requested format is rebuilt in memory, and — matching generate — when the result was built with write_files enabled the refreshed fonts are written to disk too, while CSS/HTML companion files are skipped if their rendered bytes are unchanged from the previous write. Rendered CSS/HTML is reused when the glyph names and codepoints the templates read are unchanged (a content edit), and re-rendered otherwise.

use webfont_generator::{
    generate_sync, FontType, GenerateWebfontsOptions, GlyphChange,
};

let files = vec![
    "icons/add.svg".to_owned(),
    "icons/remove.svg".to_owned(),
];
let mut result = generate_sync(
    GenerateWebfontsOptions {
        dest: "dist".to_owned(),
        files: files.clone(),
        incremental: Some(true),
        types: Some(vec![FontType::Woff2]),
        write_files: Some(false),
        ..Default::default()
    },
    None,
)?;

result.regenerate(
    &files,
    &[(
        "icons/add.svg".to_owned(),
        GlyphChange::Changed { name: None },
    )],
)?;
Source

pub fn regenerate_all(&mut self, ordered_paths: &[String]) -> Result<()>

Rebuild after re-diffing the complete ordered file set against the retained incremental cache. This is useful when the caller has a fresh file list but not a reliable watcher change batch: every current path is re-read and hashed, missing prior paths are treated as removed, new paths as added, and paths whose content hash changed as changed. Existing glyph names are preserved; added paths derive their glyph name from the file stem.

Source§

impl GenerateWebfontsResult

Source

pub fn eot_bytes(&self) -> Option<&[u8]>

Returns the EOT font bytes, if generated.

Source

pub fn svg_string(&self) -> Option<&str>

Returns the SVG font string, if generated.

Source

pub fn ttf_bytes(&self) -> Option<&[u8]>

Returns the TTF font bytes, if generated.

Source

pub fn woff_bytes(&self) -> Option<&[u8]>

Returns the WOFF font bytes, if generated.

Source

pub fn woff2_bytes(&self) -> Option<&[u8]>

Returns the WOFF2 font bytes, if generated.

Source

pub fn generate_css_pure( &self, urls: Option<HashMap<FontType, String>>, ) -> Result<String>

Generate a CSS string for this webfont result.

Pass urls to override the default font URLs in the CSS output.

Source

pub fn generate_html_pure( &self, urls: Option<HashMap<FontType, String>>, ) -> Result<String>

Generate an HTML string for this webfont result.

Pass urls to override the default font URLs in the HTML output.

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

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.