Skip to content

Commit

Permalink
Merge pull request #252 from jasonrhansen/generic-font-families
Browse files Browse the repository at this point in the history
Don't quote generic font families in CSS
  • Loading branch information
jonhoo committed Jun 23, 2022
2 parents acc8981 + 7f2d74a commit d6a6e21
Show file tree
Hide file tree
Showing 8 changed files with 723 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Changed
- Don't quote generic font families in CSS. [#252](https://github.com/jonhoo/inferno/pull/252)

### Removed

Expand Down
11 changes: 10 additions & 1 deletion src/flamegraph/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use str_stack::StrStack;

use super::{Direction, Options, TextTruncateDirection};

/// The generic font families should not have quotes around them in the CSS.
const GENERIC_FONT_FAMILIES: &[&str] = &["cursive", "fantasy", "monospace", "serif", "sans-serif"];

pub(super) enum TextArgument<'a> {
String(Cow<'a, str>),
FromBuffer(usize),
Expand Down Expand Up @@ -116,13 +119,19 @@ where
BytesStart::borrowed_name(b"style").with_attributes(iter::once(("type", "text/css"))),
))?;

let font_type: Cow<str> = if GENERIC_FONT_FAMILIES.contains(&opt.font_type.as_str()) {
Cow::Borrowed(&opt.font_type)
} else {
Cow::Owned(enquote('\"', &opt.font_type))
};

let titlesize = &opt.font_size + 5;
svg.write_event(Event::Text(BytesText::from_escaped_str(&format!(
"
text {{ font-family:{}; font-size:{}px; fill:rgb(0,0,0); }}
#title {{ text-anchor:middle; font-size:{}px; }}
{}",
enquote('\"', &opt.font_type),
font_type,
&opt.font_size,
titlesize,
include_str!("flamegraph.css")
Expand Down
139 changes: 139 additions & 0 deletions tests/data/flamegraph/options/font_type_cursive.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
139 changes: 139 additions & 0 deletions tests/data/flamegraph/options/font_type_fantasy.svg
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 d6a6e21

Please sign in to comment.