ZplEngine

Struct ZplEngine 

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

The main entry point for processing and rendering ZPL labels.

ZplEngine holds the parsed instructions, label dimensions, and configuration required to render a label using a specific backend.

Implementations§

Source§

impl ZplEngine

Source

pub fn new( zpl: &str, width: Unit, height: Unit, resolution: Resolution, ) -> ZplResult<Self>

Creates a new ZplEngine instance by parsing a ZPL string.

§Arguments
  • zpl - The raw ZPL string to parse.
  • width - The physical width of the label.
  • height - The physical height of the label.
  • resolution - The printing resolution (DPI).
§Errors

Returns an error if the ZPL is invalid or if the instruction building fails.

Examples found in repository?
examples/basic.rs (lines 15-20)
5fn main() {
6    let zpl_input = r#"
7        ^XA
8        ^FO50,50^A0N,50,50^FDZPL Forge^FS
9        ^FO50,120^GB300,100,2^FS
10        ^FO70,140^A0N,30,30^FDHello World!^FS
11        ^FO50,250^BCN,100,Y,N,N^FD12345678^FS
12        ^XZ
13    "#;
14
15    let engine = ZplEngine::new(
16        zpl_input,
17        Unit::Inches(4.0),
18        Unit::Inches(3.0),
19        Resolution::Dpi203,
20    )
21    .expect("Error parsing ZPL");
22
23    let png_backend = PngBackend::new();
24    let png_bytes = engine
25        .render(png_backend, &HashMap::new())
26        .expect("Error rendering");
27
28    std::fs::write("example_output.png", png_bytes).expect("Error writing file");
29    println!("Label successfully generated in 'example_output.png'");
30}
Source

pub fn set_fonts(&mut self, fonts: Arc<FontManager>)

Sets the font manager to be used during rendering.

If no font manager is provided, a default one will be used.

Source

pub fn render<B: ZplForgeBackend>( &self, backend: B, variables: &HashMap<String, String>, ) -> ZplResult<Vec<u8>>

Renders the parsed instructions using the provided backend.

§Arguments
  • backend - An implementation of ZplForgeBackend (e.g., PNG, PDF).
  • variables - A map of template variables to replace in text fields (format: {{key}}).
§Errors

Returns an error if rendering fails at the backend level.

Examples found in repository?
examples/basic.rs (line 25)
5fn main() {
6    let zpl_input = r#"
7        ^XA
8        ^FO50,50^A0N,50,50^FDZPL Forge^FS
9        ^FO50,120^GB300,100,2^FS
10        ^FO70,140^A0N,30,30^FDHello World!^FS
11        ^FO50,250^BCN,100,Y,N,N^FD12345678^FS
12        ^XZ
13    "#;
14
15    let engine = ZplEngine::new(
16        zpl_input,
17        Unit::Inches(4.0),
18        Unit::Inches(3.0),
19        Resolution::Dpi203,
20    )
21    .expect("Error parsing ZPL");
22
23    let png_backend = PngBackend::new();
24    let png_bytes = engine
25        .render(png_backend, &HashMap::new())
26        .expect("Error rendering");
27
28    std::fs::write("example_output.png", png_bytes).expect("Error writing file");
29    println!("Label successfully generated in 'example_output.png'");
30}

Trait Implementations§

Source§

impl Debug for ZplEngine

Source§

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

Formats the value using the given formatter. 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> Finish for T

Source§

fn finish(self)

Does nothing but move self, equivalent to drop.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more