use std::fmt::Write; use datamatrix::{ placement::{Bitmap, PathSegment}, DataMatrix, SymbolList, }; fn bitmap_to_svg(bitmap: Bitmap) -> String { // SVG header, begin path at coordinate (1, 1) let mut svg: String = concat!( "", " write!(svg, "h{}", n), PathSegment::Vertical(n) => write!(svg, "v{}", n), PathSegment::Move(dx, dy) => write!(svg, "m{},{}", dx, dy), PathSegment::Close => write!(svg, "z"), } .unwrap(); } svg.push_str("\"/>"); svg } fn main() { let bitmap = DataMatrix::encode(b"Hello, SVG!", SymbolList::default().enforce_rectangular()) .unwrap() .bitmap(); println!("{}", bitmap_to_svg(bitmap)); }