summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/dmtx_text.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/dmtx_text.rs b/examples/dmtx_text.rs
new file mode 100644
index 0000000..a8a4687
--- /dev/null
+++ b/examples/dmtx_text.rs
@@ -0,0 +1,31 @@
+use iec16022::DataMatrix;
+use std::env::args_os;
+use std::os::unix::ffi::OsStringExt;
+
+fn main() {
+ let data = args_os()
+ .skip(1) // program name
+ .map(|arg| arg.into_vec())
+ .collect::<Vec<_>>()
+ .join(&b' ');
+ let dmtx = DataMatrix::encode(&data).unwrap();
+
+ let capacity = (dmtx.width() + 1) * dmtx.height();
+ let mut out = String::with_capacity(capacity);
+ for row in (0..dmtx.height()).rev() {
+ for col in 0..dmtx.width() {
+ if dmtx.get(row, col) {
+ out.push('*');
+ } else {
+ out.push(' ');
+ }
+ }
+ out.push('\n');
+ }
+ debug_assert!(
+ capacity == out.capacity(),
+ "caculated capacity is not correct"
+ );
+
+ print!("{}", out);
+}