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
//! Dimensions of the figure
//!
//! All lengths are stored in em. 1 em is the font size of the body text, so the figure scales
//! with the text around it. The default values match the ones chemfig has used.
/// The set of dimensions for a figure
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Style {
/// Distance from atom center to atom center. Corresponds to atom sep in chemfig
pub bond_length: f64,
/// Width of a bond line
pub line_width: f64,
/// Gap between the lines of a double or triple bond. Corresponds to double bond sep in chemfig
pub double_gap: f64,
/// Gap between an atom's ink and the end of a bond. Corresponds to bond offset in chemfig
pub bond_offset: f64,
/// Width of the wide side of a wedge. Corresponds to cram width in chemfig
pub wedge_width: f64,
/// Gap between the lines of a hashed wedge
pub hash_gap: f64,
/// Size of the circle in an aromatic ring. Multiplied by the distance from side to center
pub ring_circle: f64,
/// Scale factor for subscripts and superscripts
pub script_size: f64,
/// Lower limit on how far subscripts and superscripts shrink
///
/// Applying the scale factor at each level of nesting makes the size shrink without limit.
/// The size stops here, just as TeX stops after 2 levels
pub script_floor: f64,
/// Space added after a subscript or superscript
///
/// Scripts are small, so a character that comes right after one looks crowded.
/// The 2 and the S in `H_2SO_4` are such a case.
/// No space is added when scripts follow each other (the 4 and the 2 in `O_4^{2-}`)
pub script_space: f64,
/// How far the baseline of a subscript is lowered
pub subscript_drop: f64,
/// How far the baseline of a superscript is raised
pub superscript_rise: f64,
/// Margin placed around the outside of the figure
pub margin: f64,
/// Gap between the figure and a name placed below it. Corresponds to name sep in chemfig
pub name_gap: f64,
/// How much to thicken glyph outlines
///
/// Browsers draw text a little thicker so that thin strokes do not look faint.
/// Outlines do not get this, so next to body text in the same typeface they look lighter.
/// This makes up for the difference. Set it to 0 to get exact outlines
pub darken: f64,
}
impl Default for Style {
fn default() -> Style {
Style {
bond_length: 3.0,
line_width: 0.05,
double_gap: 0.2,
bond_offset: 0.2,
wedge_width: 0.25,
hash_gap: 0.14,
ring_circle: 0.62,
script_size: 0.7,
script_floor: 0.5,
script_space: 0.05,
subscript_drop: 0.2,
superscript_rise: 0.4,
margin: 0.3,
name_gap: 0.6,
darken: 0.011,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_default_is_usable() {
let style = Style::default();
assert!(style.bond_length > 0.0);
assert!(style.line_width > 0.0 && style.line_width < style.bond_length);
assert!(style.script_size > 0.0 && style.script_size < 1.0);
assert!(style.script_floor > 0.0 && style.script_floor < style.script_size);
assert!(style.name_gap > 0.0);
assert!(style.wedge_width > style.line_width);
assert!(style.hash_gap > 0.0 && style.hash_gap < style.bond_length);
assert!(style.ring_circle > 0.0 && style.ring_circle < 1.0);
}
}