Skip to content

Commit

Permalink
add style argument to SVG writer
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkirk committed Jan 15, 2025
1 parent a763e51 commit 85826ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions geozero/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## UNRELEASED

* Add `style` option to SVGWriter for writing \<style\> tags
* Add `BoundsProcessor` to compute bounds of geometry
* Update Deps:
* BREAKING: `flatgeobuf` to 4.5.0
Expand Down
14 changes: 13 additions & 1 deletion geozero/src/svg/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct SvgWriter<W: Write> {
out: W,
invert_y: bool,
view_box: Option<(f64, f64, f64, f64)>,
style: Option<String>,
size: Option<(u32, u32)>,
}

Expand All @@ -16,6 +17,7 @@ impl<W: Write> SvgWriter<W> {
out,
invert_y,
view_box: None,
style: None,
size: None,
}
}
Expand All @@ -35,6 +37,9 @@ impl<W: Write> SvgWriter<W> {
};
self.size = Some((width, height));
}
pub fn set_style(&mut self, style: Option<String>) {
self.style = style;
}
}

impl<W: Write> FeatureProcessor for SvgWriter<W> {
Expand All @@ -55,7 +60,14 @@ impl<W: Write> FeatureProcessor for SvgWriter<W> {
}
self.out.write_all(
br#"stroke-linecap="round" stroke-linejoin="round">
<g id=""#,
"#)?;

if let Some(style) = &self.style {
writeln!(self.out, "<style>{style}</style>")?;
}

self.out.write_all(
br#"<g id=""#,
)?;
if let Some(name) = name {
self.out.write_all(name.as_bytes())?;
Expand Down

0 comments on commit 85826ef

Please sign in to comment.