Registry / RepositoryTypeScriptRustPython
Rollpie
ReadmeFiles
Versions
Info
Download
0.2.0528.5 KB2026-10-160.1.1542.8 KB2026-10-150.1.0541.1 KB2026-10-15
Version
0.1.0
Copyright
Rollpie, Irohabook
Publisher
math
Published
2026-10-15
Size
541.1 KB
Downloads
7
Checksum
67f9c361d04f05b0299dd8e9ef5e2a0120d67be36205a76945eb5f7ef90443be
Dependencies
None

style.rs

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
//! 図の寸法
//!
//! 長さはすべて em で持つ。1 em が本文の文字サイズにあたるので、図はまわりの文字に
//! 合わせて伸び縮みする。既定の値は chemfig が使ってきたものに合わせてある。

/// 図の寸法をまとめたもの
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Style {
    /// 原子の中心から中心までの長さ。chemfig の atom sep にあたる
    pub bond_length: f64,
    /// 結合の線の太さ
    pub line_width: f64,
    /// 二重結合と三重結合の、線と線のあいだ。chemfig の double bond sep にあたる
    pub double_gap: f64,
    /// 原子の墨と結合の端のあいだの空き。chemfig の bond offset にあたる
    pub bond_offset: f64,
    /// くさびの太い側の幅。chemfig の cram width にあたる
    pub wedge_width: f64,
    /// 破線のくさびの、線と線のあいだ
    pub hash_gap: f64,
    /// 芳香環の丸の大きさ。辺から中心までの長さに掛ける
    pub ring_circle: f64,
    /// 下付きと上付きの縮小率
    pub script_size: f64,
    /// 下付きと上付きが縮む下限
    ///
    /// 入れ子にするたびに縮小率を掛けると、際限なく小さくなる。
    /// TeX が 2 段でやめるのと同じで、ここで止める
    pub script_floor: f64,
    /// 下付きと上付きの後ろに入れる空き
    ///
    /// 添字は小さいので、次の字がすぐ続くと詰まって見える。`H_2SO_4` の 2 と S がこれにあたる。
    /// 添字が続けて並ぶとき(`O_4^{2-}` の 4 と 2)は入れない
    pub script_space: f64,
    /// 下付きのベースラインを下げる量
    pub subscript_drop: f64,
    /// 上付きのベースラインを上げる量
    pub superscript_rise: f64,
    /// 図の外周に置く余白
    pub margin: f64,
    /// 名前を図の下に置くときの空き。chemfig の name sep にあたる
    pub name_gap: f64,
    /// 字形の輪郭を太らせる量
    ///
    /// ブラウザは文字を描くとき、細い線が薄く沈まないように少しだけ太らせる。
    /// 輪郭にはそれが掛からないので、同じ書体の地の文と並べると輪郭のほうが薄く見える。
    /// その差を埋める。忠実な輪郭がほしいときは 0 にする
    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);
    }
}