1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// This file is intentionally small and hand-curated.
//
// We use these overrides to close the last few 1/64px-level timeline text parity gaps where
// Mermaid@11.12.2 upstream baselines reflect browser `getBBox()` quirks for overflowing single-run
// labels that are difficult to model purely from vendored font metrics.
const DEFAULT_FONT_KEY: &str = "trebuchetms,verdana,arial,sans-serif";
fn normalize_font_key(font_key: &str) -> String {
let normalized: String = font_key
.chars()
.filter_map(|ch| {
if ch.is_whitespace() || ch == '"' || ch == '\'' || ch == ';' {
None
} else {
Some(ch.to_ascii_lowercase())
}
})
.collect();
if normalized.is_empty() {
DEFAULT_FONT_KEY.to_string()
} else {
normalized
}
}
pub fn lookup_timeline_svg_bbox_x_with_ascii_overhang_px(
font_key: &str,
font_size_px: f64,
text: &str,
) -> Option<(f64, f64)> {
if (font_size_px - 16.0).abs() > 0.01 {
return None;
}
let font_key = normalize_font_key(font_key);
match (font_key.as_str(), text) {
// fixtures/timeline/upstream_long_word_wrap.mmd
// fixtures/upstream-svgs/timeline/upstream_long_word_wrap.svg
(
DEFAULT_FONT_KEY,
"SupercalifragilisticexpialidociousSupercalifragilisticexpialidocious",
) => Some((235.3203125, 235.3203125)),
_ => None,
}
}