Registry / RepositoryTypeScriptRustPython
Rollpie
ReadmeFiles
Versions
Info
Download
0.4.01085.8 KB2026-10-160.3.21087.6 KB2026-10-160.3.11087.5 KB2026-10-160.3.0117.8 KB2026-10-160.2.1106.1 KB2026-10-150.2.0105.5 KB2026-10-15
Version
0.2.0
Copyright
Rollpie, Irohabook
Publisher
math
Published
2026-10-15
Size
105.5 KB
Downloads
24
Checksum
f438a48f6f2fc61d892f930eb4fb56fb5a8e302e733a8c3a6283d0ff7350cd08
Dependencies
rust/[email protected]
rust/[email protected]

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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//! 版面と組み方の決めごと
//!
//! 長さの単位はすべて PDF の点(1 インチ 72 点)である。

/// 見出しの深さの数。part から subparagraph まで
pub const LEVEL: usize = 7;


/// 組み方の決めごと
#[derive(Debug, Clone, PartialEq)]
pub struct Style {
    pub page_width: f64,
    pub page_height: f64,
    pub margin_top: f64,
    pub margin_bottom: f64,
    pub margin_left: f64,
    pub margin_right: f64,
    /// 本文の字の大きさ
    pub size: f64,
    /// 行送り
    pub leading: f64,
    /// 段落の先頭の下げ幅
    pub indent: f64,
    /// 段落と段落のあいだの空き
    pub paragraph_skip: f64,
    /// 語間の空きと、その伸び縮み。本文の大きさに対する倍率
    pub space: f64,
    pub space_stretch: f64,
    pub space_shrink: f64,
    /// 和文の字間で伸ばせる量と詰められる量。本文の大きさに対する倍率
    pub wide_stretch: f64,
    pub wide_shrink: f64,
    /// 見出しの大きさ。本文に対する倍率
    pub heading_size: [f64; LEVEL],
    /// 見出しの前の空き
    pub heading_before: [f64; LEVEL],
    /// 見出しの後の空き
    pub heading_after: [f64; LEVEL],
    /// 番号と見出しのあいだの空き(em)
    pub heading_gap: f64,
    /// 箇条書きの下げ幅と、印と中身のあいだ
    pub list_indent: f64,
    pub list_gap: f64,
    /// 箇条書きの項目のあいだの空き
    pub list_skip: f64,
    /// 引用の左右の下げ幅
    pub quote_indent: f64,
    /// 脚注の大きさ、本文とのあいだ、区切りの線の長さ
    pub footnote_size: f64,
    pub footnote_gap: f64,
    pub footnote_rule: f64,
    /// 浮かせるものと本文のあいだの空き
    pub float_gap: f64,
    /// 1 ページのうち浮かせるものに使ってよい割合
    pub float_fraction: f64,
    /// 図表の説明と図のあいだの空き
    pub caption_gap: f64,
    /// 表の枡の左右の余白と、上下の余白
    pub cell_padding: f64,
    pub cell_lead: f64,
    /// 罫の太さ
    pub rule_width: f64,
    /// 分数線などに使う線の太さ
    pub line_width: f64,
    /// 行分割の厳しさ。大きいほど間延びした行を許す
    pub tolerance: f64,
    /// 段落の最後の 1 行だけが次のページに残るときの罰点
    pub last_line_penalty: f64,
    /// 段落の最初の 1 行だけがページの終わりに残るときの罰点
    pub first_line_penalty: f64,
    /// ノンブルを出すか
    pub page_number: bool,
    /// 化学式の結合の長さ(em)
    pub bond_length: f64,
}


impl Default for Style {
    fn default() -> Style {
        let size = 10.0;

        Style {
            page_width: 595.28,
            page_height: 841.89,
            margin_top: 80.0,
            margin_bottom: 80.0,
            margin_left: 72.0,
            margin_right: 72.0,
            size,
            leading: size * 1.7,
            indent: size,
            paragraph_skip: 0.0,
            space: 0.333,
            space_stretch: 0.167,
            space_shrink: 0.111,
            wide_stretch: 0.08,
            wide_shrink: 0.04,
            heading_size: [2.074, 1.728, 1.44, 1.2, 1.0, 1.0, 1.0],
            heading_before: [36.0, 30.0, 20.0, 16.0, 13.0, 11.0, 11.0],
            heading_after: [24.0, 20.0, 11.0, 9.0, 8.0, 4.0, 4.0],
            heading_gap: 0.7,
            list_indent: 20.0,
            list_gap: 6.0,
            list_skip: 3.0,
            quote_indent: 24.0,
            footnote_size: 8.0,
            footnote_gap: 14.0,
            footnote_rule: 120.0,
            float_gap: 14.0,
            float_fraction: 0.7,
            caption_gap: 8.0,
            cell_padding: 5.0,
            cell_lead: 3.0,
            rule_width: 0.5,
            line_width: 0.6,
            tolerance: 4.0,
            last_line_penalty: 300.0,
            first_line_penalty: 300.0,
            page_number: true,
            bond_length: 3.0,
        }
    }
}


/// 本文を組む幅
pub fn body_width(style: &Style) -> f64 {
    style.page_width - style.margin_left - style.margin_right
}


/// 本文を組む高さ
pub fn body_height(style: &Style) -> f64 {
    style.page_height - style.margin_top - style.margin_bottom
}


/// `\documentclass` に書いた選び方を読み取る
pub fn apply(style: &mut Style, option: &[String]) {
    for one in option {
        match one.as_str() {
            "a4paper" => {
                style.page_width = 595.28;
                style.page_height = 841.89;
            }
            "a5paper" => {
                style.page_width = 419.53;
                style.page_height = 595.28;
            }
            "b5paper" => {
                style.page_width = 498.9;
                style.page_height = 708.66;
            }
            "letterpaper" => {
                style.page_width = 612.0;
                style.page_height = 792.0;
            }
            "landscape" => {
                std::mem::swap(&mut style.page_width, &mut style.page_height);
            }
            "9pt" | "10pt" | "11pt" | "12pt" | "14pt" => {
                let size: f64 = one.trim_end_matches("pt").parse().unwrap_or(10.0);
                style.size = size;
                style.leading = size * 1.7;
                style.indent = size;
            }
            _ => {}
        }
    }
}