#[allow(dead_code)]
fn font_size_key(font_size: f64) -> u16 {
if !(font_size.is_finite() && font_size > 0.0) {
return 0;
}
let k = (font_size * 100.0).round();
if !(k.is_finite() && k >= 0.0 && k <= (u16::MAX as f64)) {
return 0;
}
k as u16
}
static HTML_WIDTH_OVERRIDES_PX: &[(u16, &str, f64)] = &[
(1600, "&`", 172.28125),
(1600, "&`bold&` plus plain em", 172.28125),
(1600, "&`plain", 183.734375),
(1600, "&`plain em and strong&`", 183.734375),
(1600, "A", 9.4375),
(1600, "A cloud", 52.265625),
(
1600,
"A few small words then supercalifragilisticexpialidocioussupercalifragilisticexpialidocious",
468.203125,
),
(
1600,
"A few smaller words but then averylongsetofcharacterswithoutwhitespacetoseparate that we expect to wrapontonextlinesandnotexceedwidthparameters",
398.5,
),
(
1600,
"A few smaller words then averylongsetofcharacterswithoutwhitespacetoseparate that we expect to wrap",
398.515625,
),
(
1600,
"A node with an icon and with a long text that wraps to keep the node size in check",
200.0,
),
(1600, "A root with a long", 127.609375),
(
1600,
"A root with a long text that wraps to keep the node size in check",
200.0,
),
(1600, "A second line", 121.421875),
(1600, "A1", 17.828125),
(1600, "A1b-i", 37.1875),
(
1600,
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
717.25,
),
(1600, "ASCII + Unicode — … “quotes” ‘single’ © ™ ✓", 200.0),
(1600, "Actually child due to indent", 199.671875),
(1600, "Adding new diagrams", 151.921875),
(1600, "Alpha", 40.21875),
(1600, "Another bang", 95.71875),
(1600, "Another long word", 132.140625),
(
1600,
"AntidisestablishmentarianismAntidisestablishmentarianismAntidisestablishmentarianism",
630.46875,
),
(1600, "Argument mapping", 135.203125),
(1600, "B", 9.0625),
(1600, "B1", 17.453125),
(1600, "B1.1", 31.71875),
(1600, "B1.2", 31.71875),
(1600, "B2", 17.453125),
(1600, "B2.1", 31.71875),
(1600, "B2.1.1", 45.984375),
(1600, "B3", 17.453125),
(
1600,
"Backslash \\ and slash / and pipe | and colon :",
200.0,
),
(1600, "Balanced", 64.890625),
(1600, "Bang", 34.234375),
(1600, "Bang: wow!", 83.203125),
(
1600,
"Brackets and parentheses: left/right bracket, and like this",
200.0,
),
(1600, "Branch A", 62.46875),
(1600, "Branch B", 62.96875),
(1600, "Branch C", 63.484375),
(1600, "Branch D", 63.71875),
(1600, "Bravo", 40.109375),
(1600, "Breaks", 46.953125),
(1600, "British popular psychology author Tony Buzan", 200.0),
(1600, "C", 9.578125),
(1600, "C_child", 52.828125),
(1600, "Charlie", 50.953125),
(1600, "Child", 36.515625),
(1600, "Child A", 49.890625),
(1600, "Child B", 50.390625),
(1600, "Child B1", 64.890625),
(1600, "Circle", 41.71875),
(1600, "Circle: &♥ ∞", 86.421875),
(
1600,
"Classification and monitoring of incoming issues",
200.0,
),
(1600, "Cloud", 40.53125),
(1600, "Cloud: x,y", 73.015625),
(1600, "Contains", 150.140625),
(1600, "Contributing", 89.359375),
(1600, "Coordinating the work", 159.5),
(1600, "Creative techniques", 143.109375),
(1600, "D", 9.8125),
(1600, "Deep + Wide", 89.828125),
(1600, "Deep leaf 1", 81.984375),
(1600, "Deep leaf 2", 81.984375),
(1600, "Default", 52.671875),
(1600, "Delta", 38.015625),
(1600, "Development", 94.421875),
(1600, "Echo", 33.828125),
(1600, "Emoji-like text: :rocket: :sparkles:", 200.0),
(1600, "Emoji: 😀 😅 🤯 ✅ ⚠️", 170.84375),
(1600, "Escaping", 61.625),
(1600, "Foxtrot", 52.5),
(1600, "Geography", 76.34375),
(1600, "Golf", 30.046875),
(1600, "Grandchild A1", 99.734375),
(1600, "GreatGrandchild A1a", 148.65625),
(1600, "Greek: αβγδεζηθ", 121.1875),
(1600, "Handling pull requests", 159.953125),
(1600, "Hex", 27.21875),
(1600, "Hex?", 33.09375),
(1600, "Hexagon: &{braces&}", 152.6875),
(1600, "Hotel", 38.84375),
(1600, "I am a bang", 83.109375),
(1600, "I am a circle", 89.078125),
(1600, "I am a cloud", 87.890625),
(1600, "I am a hexagon", 108.265625),
(1600, "I am a rounded square", 160.15625),
(1600, "I am a square", 96.5),
(1600, "I am the default shape", 162.265625),
(1600, "Icons", 36.1875),
(1600, "India", 35.078125),
(1600, "Inline code:", 200.0),
(1600, "Inline code: code and emoji 🤓", 200.0),
(1600, "Juliet", 40.71875),
(1600, "L", 8.109375),
(1600, "L1", 16.5),
(1600, "L2", 16.5),
(1600, "Landscape", 74.609375),
(1600, "Leaf", 31.15625),
(1600, "Leaf A1", 52.921875),
(1600, "Leaf A1a", 61.328125),
(1600, "Leaf A1b", 61.828125),
(1600, "Leaf A2", 66.1875),
(1600, "Leaf B1a", 61.828125),
(1600, "Leaf B1b", 62.328125),
(1600, "Leaf B2a", 61.828125),
(1600, "Leaf C", 45.546875),
(1600, "Left branch", 82.859375),
(1600, "Long history", 87.109375),
(1600, "Management", 90.765625),
(1600, "Many siblings", 93.703125),
(1600, "Mermaid", 61.46875),
(
1600,
"Mixed — em-dash, en–dash, quotes “like this”, and symbols ✓✗",
200.0,
),
(1600, "More shapes", 87.453125),
(1600, "Mountains", 71.953125),
(1600, "Nested", 64.40625),
(1600, "New Stuff", 70.28125),
(1600, "Node", 36.4375),
(1600, "Node 01", 58.046875),
(1600, "Node 02", 58.046875),
(1600, "Node 03", 58.046875),
(1600, "Node 04", 58.046875),
(1600, "Node 05", 58.046875),
(1600, "Node 06", 58.046875),
(1600, "Node 07", 58.046875),
(1600, "Node 08", 58.046875),
(1600, "Node 09", 58.046875),
(1600, "Node 1", 49.65625),
(1600, "Node 10", 58.046875),
(1600, "Node 11", 58.046875),
(1600, "Node 12", 58.046875),
(1600, "Node 13", 58.046875),
(1600, "Node 14", 58.046875),
(1600, "Node 15", 58.046875),
(1600, "Node 16", 58.046875),
(1600, "Node 17", 58.046875),
(1600, "Node 18", 58.046875),
(1600, "Node 19", 58.046875),
(1600, "Node 2", 49.65625),
(1600, "Node 20", 58.046875),
(1600, "Node A", 49.8125),
(1600, "Node A1", 76.71875),
(1600, "Node A2", 58.203125),
(1600, "Node A3", 58.203125),
(1600, "Node B", 50.3125),
(1600, "Node B1", 58.703125),
(1600, "Node C", 50.828125),
(1600, "Node C1", 59.21875),
(1600, "Node C2", 59.21875),
(1600, "Node C3", 59.21875),
(1600, "Node D", 51.078125),
(1600, "Node D1", 59.46875),
(1600, "Node D2", 59.46875),
(1600, "Node D3", 59.46875),
(1600, "Node1", 44.828125),
(1600, "Node10", 53.21875),
(1600, "Node11", 53.21875),
(1600, "Node12", 53.21875),
(1600, "Node13", 53.21875),
(1600, "Node14", 53.21875),
(1600, "Node15", 53.21875),
(1600, "Node2", 44.828125),
(1600, "Node3", 44.828125),
(1600, "Node4", 44.828125),
(1600, "Node5", 44.828125),
(1600, "Node6", 44.828125),
(1600, "Node7", 44.828125),
(1600, "Node8", 44.828125),
(1600, "Node9", 44.828125),
(1600, "On Automatic creation", 161.421875),
(1600, "On effectiveness", 119.4375),
(1600, "Origins", 49.375),
(1600, "Pen and paper", 102.53125),
(1600, "Photograph", 80.75),
(1600, "Plain (Round) Node", 136.828125),
(1600, "Popularisation", 101.4375),
(1600, "Quotes: \"double\" and 'single'", 200.0),
(1600, "R", 9.3125),
(1600, "R1", 17.703125),
(1600, "R2", 17.703125),
(1600, "RTL + LTR: مرحبا hello 123 🤖", 200.0),
(
1600,
"Regression testing in connection with releases",
200.0,
),
(1600, "Regular labels still works", 178.015625),
(1600, "Research", 63.890625),
(1600, "Right branch", 90.765625),
(1600, "Rocks", 39.71875),
(1600, "Root", 32.1875),
(1600, "Root with", 162.9375),
(1600, "Root with emphasis and strong", 200.0),
(1600, "Round", 67.84375),
(1600, "Round rectangle", 116.3125),
(1600, "Rounded: \"quotes\" and - dashes -", 200.0),
(1600, "Single line", 74.046875),
(1600, "Solving issues", 96.453125),
(1600, "Spacing", 85.375),
(1600, "Square", 48.703125),
(1600, "Square: a/b/c", 101.421875),
(1600, "Strategic planning", 129.9375),
(1600, "String containing ()", 137.625),
(1600, "String containing () and [] and", 200.0),
(1600, "String containing []", 137.625),
(1600, "String containing [] ( ) and :::decorators", 200.0),
(
1600,
"SupercalifragilisticexpialidociousSupercalifragilisticexpialidocious",
470.640625,
),
(1600, "Testing", 50.1875),
(1600, "Testing pull requests", 147.546875),
(
1600,
"Text with punctuation: commas, periods... and dashes - should still wrap",
200.0,
),
(1600, "The dog in", 200.0),
(
1600,
"The dog in the hog... a very long text that wraps to a new line",
200.0,
),
(1600, "The root", 61.3125),
(1600, "This is a mindmap", 129.078125),
(1600, "Tools", 35.671875),
(1600, "Two-line label", 100.5),
(1600, "Unclear indent attaches near b1", 200.0),
(1600, "Unicode works too: 🤓", 162.9375),
(1600, "Unicode/标点", 98.21875),
(1600, "Updating tooling", 118.6875),
(1600, "Uses", 32.0625),
(1600, "Verification of fixed issues", 189.46875),
(1600, "Waterfall", 66.203125),
(1600, "With", 46.953125),
(1600, "Wrapping", 66.625),
(1600, "[brackets] and (parens) together", 200.0),
(1600, "`**Start** with a second line ð`", 200.0),
(
1600,
"`The dog in **the** hog... a *very long text* about it Word!`",
200.0,
),
(1600, "a", 8.40625),
(1600, "a second line", 162.9375),
(
1600,
"a-very-very-very-long-hyphenated-word-with-dashes",
200.0,
),
(1600, "and Unicode 🤓", 113.53125),
(1600, "and entities", 85.375),
(1600, "and features", 119.4375),
(
1600,
"averylongsetofcharacterswithoutwhitespacetoseparateandweexpectitnottoexceedwidth",
630.046875,
),
(1600, "b", 8.921875),
(1600, "bang", 34.09375),
(1600, "child", 34.859375),
(1600, "child 1", 48.078125),
(1600, "child 2", 48.078125),
(1600, "child 3", 48.078125),
(1600, "child 6", 48.078125),
(1600, "child 8", 48.078125),
(1600, "child1", 43.25),
(1600, "child2", 43.25),
(1600, "child3", 43.25),
(1600, "constructor", 82.109375),
(1600, "docs", 31.90625),
(1600, "emoji 🤓🤖 and unicode ✓✗ αβγ", 200.0),
(1600, "grand", 48.078125),
(1600, "grandchild 1", 88.390625),
(1600, "grandchild 2", 88.390625),
(1600, "grandchild 3", 88.390625),
(1600, "grandchild 4", 88.390625),
(1600, "grandchild 5", 88.390625),
(1600, "grandchild 6", 88.390625),
(1600, "label", 48.703125),
(1600, "leaf", 27.765625),
(1600, "leaf1", 36.15625),
(1600, "line 1", 39.96875),
(1600, "line 2", 39.96875),
(1600, "literal and HTML-ish:", 150.140625),
(1600, "mindmap", 66.109375),
(1600, "mindmap is a long thing", 171.328125),
(
1600,
"mix: punctuation, commas, and (parens) + [brackets]",
200.0,
),
(1600, "multiline", 64.40625),
(1600, "normal", 49.953125),
(1600, "normal words should wrap too", 200.0),
(1600, "note about mermaid", 173.390625),
(1600, "plain", 144.359375),
(1600, "plain em and strong", 144.359375),
(1600, "proto", 40.609375),
(1600, "prototype", 70.53125),
(1600, "pseudopseudohypoparathyroidism", 242.375),
(1600, "rectangle", 67.84375),
(1600, "root", 29.734375),
(1600, "shape", 41.71875),
(1600, "supercalifragilisticexpialidocious", 234.109375),
(1600, "tags", 200.0),
(1600, "the root", 58.375),
(1600, "toString", 56.53125),
(1600, "two lines", 64.890625),
(1600, "with break", 76.71875),
(1600, "with icon", 100.5),
(1600, "with inline HTML", 121.421875),
(1600, "wrapping label", 127.609375),
(1600, "xss", 20.96875),
(1600, "שלום עולם", 66.265625),
(1600, "العربية: مرحبا", 75.4375),
(1600, "مرحبا بالعالم", 64.59375),
(1600, "中文节点", 64.0),
(1600, "中文:你好,世界!", 144.0),
(1600, "中文:全角标点,逗号,句号。", 200.0),
(1600, "日本語ノード", 96.0),
(1600, "日本語:カタカナ・ひらがな", 200.0),
];
pub fn lookup_html_width_px(font_size: f64, text: &str) -> Option<f64> {
let fs = font_size_key(font_size);
if fs == 0 || text.is_empty() {
return None;
}
let mut lo = 0usize;
let mut hi = HTML_WIDTH_OVERRIDES_PX.len();
while lo < hi {
let mid = (lo + hi) / 2;
let (k_fs, k_text, w) = HTML_WIDTH_OVERRIDES_PX[mid];
match k_fs.cmp(&fs) {
std::cmp::Ordering::Equal => match k_text.cmp(text) {
std::cmp::Ordering::Equal => return Some(w),
std::cmp::Ordering::Less => lo = mid + 1,
std::cmp::Ordering::Greater => hi = mid,
},
std::cmp::Ordering::Less => lo = mid + 1,
std::cmp::Ordering::Greater => hi = mid,
}
}
None
}