summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index ddb4405..e53ea75 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -108,6 +108,30 @@ impl DataMatrix {
let idx = row * self.width + col;
self.grid()[idx]
}
+
+ #[cfg(feature = "svg")]
+ pub fn svg(&self) -> svg::Document {
+ use svg::node::element::Rectangle;
+
+ let mut svg = svg::Document::new()
+ // -1, -1 for quiet zone
+ // +2 for size of quiet zone
+ .set("viewBox", format!("-1 -1 {} {}", self.width() + 2, self.height() + 2));
+ for row in 0..self.height() {
+ for col in 0..self.width() {
+ if self.get(row, col) {
+ svg = svg.add(
+ Rectangle::new()
+ .set("width", "1")
+ .set("height", "1")
+ .set("x", col)
+ .set("y", self.height() - row - 1),
+ );
+ }
+ }
+ }
+ svg
+ }
}
impl Drop for DataMatrix {