From 7fa219e296dfe08ab0d9e09d14f83df85b6d8743 Mon Sep 17 00:00:00 2001 From: yvt Date: Fri, 23 Jul 2021 18:34:22 +0900 Subject: [PATCH] fix: calculate the correct image size Implements a work-around for the following issue: --- src/textproc.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/textproc.rs b/src/textproc.rs index f6178c7..815d12f 100644 --- a/src/textproc.rs +++ b/src/textproc.rs @@ -241,6 +241,24 @@ fn convert_diagram(art: &str, output: &mut String) { true }); + // Fix the height of the image + // + let new_height = settings.scale * 2.0 * art.lines().count() as f32; + match &mut node { + svgbob::Node::Element(elem) => { + for attr in elem.attrs.iter_mut() { + if attr.name() == &"height" { + *attr = Attribute::new( + None, + "height", + AttributeValue::from_value(new_height.into()), + ); + } + } + } + _ => unreachable!(), + } + use svgbob::Render; let mut svg_code = String::new(); node.render(&mut svg_code).unwrap();