summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorTobias Wiese <tobias@tobiaswiese.com>2026-01-27 00:31:06 +0100
committerTobias Wiese <tobias@tobiaswiese.com>2026-01-27 01:11:06 +0100
commit31f39660aa62d8e451f43bc32c994eba6e61e972 (patch)
tree79355039a5c10d8d243e668b565583ef6233980b /src/lib.rs
parent45d7335d8e18410728a0384fd6456c609aec3be8 (diff)
svg: convert data matrix to svgHEADv0.2.0master
Diffstat (limited to 'src/lib.rs')
-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 {