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
impl FontManager
Sourcepub fn get_font_bytes(&self, name: &str) -> Option<&[u8]>
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).
Sourcepub fn get_font_name(&self, name: &str) -> Option<&str>
pub fn get_font_name(&self, name: &str) -> Option<&str>
Returns the internal font name mapped to a ZPL identifier.
Sourcepub fn register_font(
&mut self,
name: &str,
bytes: &[u8],
from: char,
to: char,
) -> ZplResult<()>
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
impl Clone for FontManager
Source§fn clone(&self) -> FontManager
fn clone(&self) -> FontManager
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 FontManager
impl Debug for FontManager
Source§impl Default for FontManager
impl Default for FontManager
Source§fn default() -> Self
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§
impl !RefUnwindSafe for FontManager
impl !UnwindSafe for FontManager
impl Freeze for FontManager
impl Send for FontManager
impl Sync for FontManager
impl Unpin for FontManager
impl UnsafeUnpin for FontManager
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.