pub struct Code128 { /* private fields */ }Expand description
A Code 128.
You can use the modules iterator and the size to compute a visualization. A module corresponds to a “black line” of the code and has a unitless width between one and four, as well as a free space after it, also sized between one and four.
Pseudo code for visualization
Be aware that the standard demands a quiet zone of size 10 around the code.
To compute the size of a block, multiply its width with the available space
for the code (with a unit) divided by 20 + len(). Here 20 corresponds to
the quiet zone.
let code = Code128::encode(b"Code128 <3");
let available_space = 100.0; // unit is, say, "pt"
let line_width = available_space / code.len() as f64;
let mut pos = 10;
for module in code.modules() {
let x = pos as f64 * line_width;
let width = module.width as f64 * line_width;
// print line at `x` pt, `width` pt wide
pos += module.width + module.space;
}Implementations§
source§impl Code128
impl Code128
sourcepub fn encode(data: &[u8]) -> Self
pub fn encode(data: &[u8]) -> Self
Encode the bytes as Code 128.
See the module documentation for hints on charsets.
sourcepub fn encode_str(text: &str) -> Option<Self>
pub fn encode_str(text: &str) -> Option<Self>
Encode the string as Code 128 using Latin 1.
The functions returns None if the string includes characters not
included in Latin 1.
The control characters of ASCII, 0x00 to 0x19, are also encoded.
sourcepub fn modules(&self) -> impl Iterator<Item = Module> + '_
pub fn modules(&self) -> impl Iterator<Item = Module> + '_
Get the sequence of modules this Code 128 consists of.