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
impl ZplEngine
Sourcepub fn new(
zpl: &str,
width: Unit,
height: Unit,
resolution: Resolution,
) -> ZplResult<Self>
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}Sourcepub fn set_fonts(&mut self, fonts: Arc<FontManager>)
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.
Sourcepub fn render<B: ZplForgeBackend>(
&self,
backend: B,
variables: &HashMap<String, String>,
) -> ZplResult<Vec<u8>>
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 ofZplForgeBackend(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§
Auto Trait Implementations§
impl Freeze for ZplEngine
impl !RefUnwindSafe for ZplEngine
impl Send for ZplEngine
impl Sync for ZplEngine
impl Unpin for ZplEngine
impl !UnwindSafe for ZplEngine
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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 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>
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 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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
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 Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
Convert this type into
T, using the provided data to resolve any offsets.