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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//! Turning a label's text into a measured block of lines.
//!
//! Every box in the diagram is sized from this, and everything downstream — rank assignment,
//! ordering, coordinates — is derived from the box sizes, so this is the top of the causal chain
//! (`text_metrics`'s module docs say the same thing from the other end).
//!
//! Two decisions worth stating because they are not obvious:
//!
//! * **Width comes from [`text_metrics`], never from a per-character estimate.** That module
//! measures with the same font database and the same font-resolution rules resvg will use, and
//! the test that pins the two together is this renderer's main instrument
//! (`docs/FEATURE-MERMAID-RENDERER.md` §6).
//! * **Height is a declared constant, not a measurement.** mermaid gets it from `getBBox()` on a
//! real `<text>`, which has no counterpart here; §4-4 records that konoma is effectively
//! `htmlLabels: false`, where mermaid's own line spacing is `1.1em`. Using that ratio keeps the
//! number honest about being a convention rather than a measurement.
//!
//! There is **no automatic wrapping**. §2-5 puts `wrappingWidth` in the "not implemented" list
//! (it is a px-space idea), so a line breaks only where the author wrote `<br>` or `\n` — which
//! the parser has already turned into a real newline by the time the text arrives here.
use crateflowchart;
use crate;
/// Line spacing as a multiple of the font size. mermaid's SVG-label spacing (§4-4).
pub const LINE_HEIGHT_RATIO: f64 = 1.1;
/// Where a line's baseline sits below the middle of its line box, as a multiple of the font size.
///
/// Roughly half a capital's height: sans-serif cap heights cluster around `0.7em`, so centring
/// capitals puts the baseline `0.35em` below centre. CJK, whose ink runs about `-0.88em..0.12em`,
/// wants `0.38em`; one constant covers both within half a pixel at 14px, and picking it by script
/// would make a mixed-script line jump.
pub const BASELINE_RATIO: f64 = 0.35;
/// Height of one line of text, in px.
/// A label, split into lines and measured.