pub struct Code128 { /* private fields */ }
Expand description
A Code 128.
You can use the bars iterators bars()
or
bar_coordinates()
, and the size
to compute a visualization. A bars 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.
A bar with width one is called a “module”. You can say a bar consists of one
or more modules. The width of a module is often called “X”, denoting one
unit in the “x-dimension” of the barcode. A multiple of a module’s width is
usually written <multiplier>X
, for example 1X
or 2.5X
.
§Pseudo code for visualization
The standard demands a quiet zone of size 10X (see above for notation) on the left and right side of the code. To compute the size of a bar, multiply its width with the available space for the code divided by the code’s length.
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;
for bar in code.bar_coordinates() {
let x = bar.x as f64 * line_width;
let width = bar.width as f64 * line_width;
// print line at `x` pt, `width` pt wide
}
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 bars(&self) -> impl Iterator<Item = Bar> + '_
pub fn bars(&self) -> impl Iterator<Item = Bar> + '_
Get the sequence of bars this Code 128 consists of.
Sourcepub fn bar_coordinates(&self) -> impl Iterator<Item = BarCoordinate> + '_
pub fn bar_coordinates(&self) -> impl Iterator<Item = BarCoordinate> + '_
Get the coordinates of the bars this Code 128 consists of.