Skip to content

Commit

Permalink
fix(svg): Fix the width
Browse files Browse the repository at this point in the history
I chose the width by seeing what fit the content for `rainbow.svg` in
Firefox on PopOS with the current font family.
No idea how universal this will be.
  • Loading branch information
epage committed Feb 18, 2024
1 parent 1934891 commit f8b0684
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion crates/anstyle-svg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ impl Term {
.map(|l| l.iter().map(|(_, t)| t.width()).sum())
.max()
.unwrap_or(20);
let width_px = max_width as f64 * 8.4;

use std::fmt::Write as _;
let mut buffer = String::new();
writeln!(
&mut buffer,
r#"<svg width="{max_width}em" height="{height}px" xmlns="http://www.w3.org/2000/svg">"#
r#"<svg width="{width_px}px" height="{height}px" xmlns="http://www.w3.org/2000/svg">"#
)
.unwrap();
writeln!(&mut buffer, r#" <style>"#).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/anstyle-svg/tests/rainbow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion crates/anstyle-svg/tests/rg_linus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f8b0684

Please sign in to comment.