diff options
| author | Tobias Wiese <tobias@tobiaswiese.com> | 2026-01-27 00:31:06 +0100 |
|---|---|---|
| committer | Tobias Wiese <tobias@tobiaswiese.com> | 2026-01-27 01:11:06 +0100 |
| commit | 31f39660aa62d8e451f43bc32c994eba6e61e972 (patch) | |
| tree | 79355039a5c10d8d243e668b565583ef6233980b /src | |
| parent | 45d7335d8e18410728a0384fd6456c609aec3be8 (diff) | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -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 { |
