Skip to content

Commit a1ef580

Browse files
committed
add style argument to SVG writer
1 parent 7a810a9 commit a1ef580

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

geozero/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## UNRELEASED
22

3+
* Add `style` option to SVGWriter for writing \<style\> tags
34
* Add `BoundsProcessor` to compute bounds of geometry
45
* Update Deps:
56
* BREAKING: `flatgeobuf` to 4.5.0

geozero/src/svg/writer.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub struct SvgWriter<W: Write> {
77
out: W,
88
invert_y: bool,
99
view_box: Option<(f64, f64, f64, f64)>,
10+
style: Option<String>,
1011
size: Option<(u32, u32)>,
1112
}
1213

@@ -16,6 +17,7 @@ impl<W: Write> SvgWriter<W> {
1617
out,
1718
invert_y,
1819
view_box: None,
20+
style: None,
1921
size: None,
2022
}
2123
}
@@ -35,6 +37,9 @@ impl<W: Write> SvgWriter<W> {
3537
};
3638
self.size = Some((width, height));
3739
}
40+
pub fn set_style(&mut self, style: Option<String>) {
41+
self.style = style;
42+
}
3843
}
3944

4045
impl<W: Write> FeatureProcessor for SvgWriter<W> {
@@ -55,7 +60,14 @@ impl<W: Write> FeatureProcessor for SvgWriter<W> {
5560
}
5661
self.out.write_all(
5762
br#"stroke-linecap="round" stroke-linejoin="round">
58-
<g id=""#,
63+
"#)?;
64+
65+
if let Some(style) = &self.style {
66+
writeln!(self.out, "<style>{style}</style>")?;
67+
}
68+
69+
self.out.write_all(
70+
br#"<g id=""#,
5971
)?;
6072
if let Some(name) = name {
6173
self.out.write_all(name.as_bytes())?;

0 commit comments

Comments
 (0)