aboutsummaryrefslogtreecommitdiff
path: root/server/book-export/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-10-17 23:00:08 +0200
committermetamuffin <metamuffin@disroot.org>2025-10-17 23:00:12 +0200
commit03969d3b83a07abe0b6707e21230bd6c3a184942 (patch)
treeea8e9d797a454acfc794ab436c6f07a7e828c004 /server/book-export/src
parent8eb1c82af34587abacd03b9e6c6695e084f900d7 (diff)
downloadhurrycurry-03969d3b83a07abe0b6707e21230bd6c3a184942.tar
hurrycurry-03969d3b83a07abe0b6707e21230bd6c3a184942.tar.bz2
hurrycurry-03969d3b83a07abe0b6707e21230bd6c3a184942.tar.zst
Fix problems caused by negative viewBox in diagram svg
Diffstat (limited to 'server/book-export/src')
-rw-r--r--server/book-export/src/book_html.css5
-rw-r--r--server/book-export/src/diagram_svg.rs11
2 files changed, 15 insertions, 1 deletions
diff --git a/server/book-export/src/book_html.css b/server/book-export/src/book_html.css
index 9171aa5e..252604b6 100644
--- a/server/book-export/src/book_html.css
+++ b/server/book-export/src/book_html.css
@@ -39,3 +39,8 @@ body {
height: auto;
overflow-y: auto;
}
+
+svg {
+ width: 100%;
+ height: 100%;
+} \ No newline at end of file
diff --git a/server/book-export/src/diagram_svg.rs b/server/book-export/src/diagram_svg.rs
index a9a2c0a6..290db072 100644
--- a/server/book-export/src/diagram_svg.rs
+++ b/server/book-export/src/diagram_svg.rs
@@ -30,13 +30,22 @@ const HSIZE: f32 = SIZE / 2.;
pub fn diagram_svg(data: &Gamedata, diagram: &Diagram) -> Result<String> {
let mut out = String::new();
- let (vb_min, vb_max) = diagram
+ let (mut vb_min, mut vb_max) = diagram
.nodes
.iter()
.map(|n| (n.position, n.position))
.reduce(|(xa, xb), (ya, yb)| (xa.min(ya), xb.max(yb)))
.unwrap();
+ // negative viewBox causes weird issues
+ let new_origin = vb_min - Vec2::splat(HSIZE);
+ let mut diagram = diagram.to_owned();
+ for n in &mut diagram.nodes {
+ n.position -= new_origin;
+ }
+ vb_min -= new_origin;
+ vb_max -= new_origin;
+
writeln!(
out,
r#"<svg xmlns="http://www.w3.org/2000/svg" viewBox="{} {} {} {}" width="{}" height="{}">"#,