MicroPDF417

Struct MicroPDF417 

Source
pub struct MicroPDF417<'a> { /* private fields */ }
Expand description

Configuration and Rendering of MicroPDF417 barcodes.

Implementations§

Source§

impl<'a> MicroPDF417<'a>

Source

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?
examples/micro_pdf417.rs (line 21)
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}
Source

pub const fn scale(&self) -> (u32, u32)

Returns the scale of the MicroPDF417 as (Scale X axis, Scale Y axis).

Source

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).

Source

pub const fn set_scaled(&mut self, scale: (u32, u32)) -> &mut Self

Sets the scale of the MicroPDF417 on both axis. See also scaled.

Source

pub const fn is_inverted(&self) -> bool

Returns if the MicroPDF417 is set to be rendered with inverted colors.

Source

pub const fn inverted(self, inverted: bool) -> Self

Marks whether this MicroPDF417 should be rendered with pixel values inverted.

Source

pub const fn set_inverted(&mut self, inverted: bool) -> &mut Self

Marks whether this MicroPDF417 should be rendered with pixel values inverted.

Source

pub const fn rows(&self) -> u8

Get the number of rows of the MicroPDF417.

Source

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.

Source

pub const fn variant(&self) -> u8

Get the variant number of this MicroPDF417.

Source

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?
examples/micro_pdf417.rs (line 22)
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>

Source§

fn clone(&self) -> MicroPDF417<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for MicroPDF417<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for MicroPDF417<'a>

§

impl<'a> RefUnwindSafe for MicroPDF417<'a>

§

impl<'a> Send for MicroPDF417<'a>

§

impl<'a> Sync for MicroPDF417<'a>

§

impl<'a> Unpin for MicroPDF417<'a>

§

impl<'a> UnwindSafe for MicroPDF417<'a>

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, 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.