Skip to main content

FontManager

Struct FontManager 

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

Manages fonts and their mapping to ZPL font identifiers.

This structure tracks registered fonts and maps them to the single-character identifiers used in ZPL commands (e.g., ‘^A0’, ‘^AA’).

Implementations§

Source§

impl FontManager

Source

pub fn get_font_bytes(&self, name: &str) -> Option<&[u8]>

Retrieves the raw TTF/OTF bytes for a font by its ZPL identifier.

This is used by backends that need the raw font data (e.g., PDF embedding).

Source

pub fn get_font_name(&self, name: &str) -> Option<&str>

Returns the internal font name mapped to a ZPL identifier.

Source

pub fn get_font(&self, name: &str) -> Option<&FontArc>

Retrieves a font by its ZPL identifier.

§Arguments
  • name - The ZPL font identifier (e.g., “0”, “A”).
Source

pub fn register_font( &mut self, name: &str, bytes: &[u8], from: char, to: char, ) -> ZplResult<()>

Registers a new font and maps it to a range of ZPL identifiers.

Custom fonts must be in TrueType (.ttf) or OpenType (.otf) format. Once registered, the font can be used in ZPL commands like ^A or ^CF by referencing the assigned identifiers.

§Arguments
  • name - An internal name for the font.
  • bytes - The raw TrueType/OpenType font data.
  • from - The starting ZPL identifier in the range (A-Z, 0-9).
  • to - The ending ZPL identifier in the range (A-Z, 0-9).
§Errors

Returns an error if the font data is invalid.

§Example
use zpl_forge::FontManager;

let mut font_manager = FontManager::default();

// Load your font file bytes
// let font_bytes = std::fs::read("fonts/IosevkaTermSlab-Regular.ttf")?;

// Register it for a range of ZPL identifiers (e.g., from 'A' to 'Z')
// font_manager.register_font("Iosevka Term Slab", &font_bytes, 'A', 'Z')?;

Trait Implementations§

Source§

impl Clone for FontManager

Source§

fn clone(&self) -> FontManager

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 FontManager

Source§

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

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

impl Default for FontManager

Source§

fn default() -> Self

Creates a FontManager with high-fidelity, lightweight open-source fonts registered for their respective identifiers.

  • TeX Gyre Heros Cn (GUST Font License) is registered for scalable/sans identifiers (‘0’ to ‘9’).
  • Iosevka Term Slab (SIL Open Font License) is registered for monospace/slab identifiers (‘A’ to ‘Z’).
  • OCR-A is registered for OCR-A identifier (‘H’).
  • OCR-B is registered for OCR-B identifier (‘E’).

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

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.