pub struct MicroPDF417<'a> { /* private fields */ }Expand description
Configuration and Rendering of MicroPDF417 barcodes.
Implementations§
Source§impl<'a> MicroPDF417<'a>
impl<'a> MicroPDF417<'a>
Sourcepub const fn new(codewords: &'a [u16], variant: u8) -> Self
pub const fn new(codewords: &'a [u16], variant: u8) -> Self
Creates a new MicroPDF417 with the user’s data section (codewords slice) and the layout configuration (variant). See get_variant, find_variant and variant_dim for more information. Please make sure your codewords slice is valid, you can use PDF417Encoder to fill it accordingly.
Examples found in repository?
14fn main() {
15 let variant = V.unwrap();
16 let mut input = [0u16; (COLS*ROWS) as usize];
17 PDF417Encoder::new(&mut input, true).append_num(12345678)
18 .seal(variant);
19
20 let mut storage = [false; W * H];
21 let pdf417 = MicroPDF417::new(&input, variant);
22 pdf417.render(&mut storage[..]);
23
24 let mut col = 0;
25 for _ in 0..((PADDING+1)/2) {
26 println!("{}", str::repeat(WHITE, W + PADDING * 2));
27 }
28 print!("{}", str::repeat(WHITE, PADDING));
29 for on in storage {
30 print!("{}", if on { BLACK } else { WHITE });
31 col += 1;
32 if col == W {
33 col = 0;
34 print!("{b}\n{b}", b = str::repeat(WHITE, PADDING));
35 }
36 }
37 println!("{}", str::repeat(WHITE, W + PADDING));
38 for _ in 0..((PADDING-1)/2) {
39 println!("{}", str::repeat(WHITE, W + PADDING * 2));
40 }
41 println!("\x1B[0m");
42}Sourcepub const fn scale(&self) -> (u32, u32)
pub const fn scale(&self) -> (u32, u32)
Returns the scale of the MicroPDF417 as (Scale X axis, Scale Y axis).
Sourcepub const fn scaled(self, scale: (u32, u32)) -> Self
pub const fn scaled(self, scale: (u32, u32)) -> Self
Sets the scale of the MicroPDF417 on both axis. The scale tuple stores the non-zero scale values as (Scale X axis, Scale Y axis).
Sourcepub const fn set_scaled(&mut self, scale: (u32, u32)) -> &mut Self
pub const fn set_scaled(&mut self, scale: (u32, u32)) -> &mut Self
Sets the scale of the MicroPDF417 on both axis. See also scaled.
Sourcepub const fn is_inverted(&self) -> bool
pub const fn is_inverted(&self) -> bool
Returns if the MicroPDF417 is set to be rendered with inverted colors.
Sourcepub const fn inverted(self, inverted: bool) -> Self
pub const fn inverted(self, inverted: bool) -> Self
Marks whether this MicroPDF417 should be rendered with pixel values inverted.
Sourcepub const fn set_inverted(&mut self, inverted: bool) -> &mut Self
pub const fn set_inverted(&mut self, inverted: bool) -> &mut Self
Marks whether this MicroPDF417 should be rendered with pixel values inverted.
Sourcepub const fn cols(&self) -> u8
pub const fn cols(&self) -> u8
Get the number of columns of the MicroPDF417. This is used to lay down the left, center and right indicators in the render function.
Sourcepub fn render<Target: RenderTarget + ?Sized>(&self, storage: &mut Target)
pub fn render<Target: RenderTarget + ?Sized>(&self, storage: &mut Target)
Render the MicroPDF417 to a suitable render target. The scale, variant number values are used here to lay down the pixels to construct a valid barcode according to the specification.
Note: Both scale and inverted parameters are handled by the RenderTarget which allows for specialized (and faster) ways of copying or updating pixel values.
Examples found in repository?
14fn main() {
15 let variant = V.unwrap();
16 let mut input = [0u16; (COLS*ROWS) as usize];
17 PDF417Encoder::new(&mut input, true).append_num(12345678)
18 .seal(variant);
19
20 let mut storage = [false; W * H];
21 let pdf417 = MicroPDF417::new(&input, variant);
22 pdf417.render(&mut storage[..]);
23
24 let mut col = 0;
25 for _ in 0..((PADDING+1)/2) {
26 println!("{}", str::repeat(WHITE, W + PADDING * 2));
27 }
28 print!("{}", str::repeat(WHITE, PADDING));
29 for on in storage {
30 print!("{}", if on { BLACK } else { WHITE });
31 col += 1;
32 if col == W {
33 col = 0;
34 print!("{b}\n{b}", b = str::repeat(WHITE, PADDING));
35 }
36 }
37 println!("{}", str::repeat(WHITE, W + PADDING));
38 for _ in 0..((PADDING-1)/2) {
39 println!("{}", str::repeat(WHITE, W + PADDING * 2));
40 }
41 println!("\x1B[0m");
42}Trait Implementations§
Source§impl<'a> Clone for MicroPDF417<'a>
impl<'a> Clone for MicroPDF417<'a>
Source§fn clone(&self) -> MicroPDF417<'a>
fn clone(&self) -> MicroPDF417<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more