Skip to content

Commit

Permalink
fix: calculate the correct image size
Browse files Browse the repository at this point in the history
Implements a work-around for the following issue:
<ivanceras/svgbob#77>
  • Loading branch information
yvt committed Jul 23, 2021
1 parent 1a14818 commit 7fa219e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/textproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,24 @@ fn convert_diagram(art: &str, output: &mut String) {
true
});

// Fix the height of the image
// <https://github.com/ivanceras/svgbob/issues/77>
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();
Expand Down

0 comments on commit 7fa219e

Please sign in to comment.