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]

draw.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
//! ページに置いたもの
//!
//! 位置と寸法はすべて決まっている。座標はページの左上が原点で、x は右、y は下を正とする。
//! PDF の座標に直すのは [`crate::stream`] が行う。

/// 置いた字 1 つ
#[derive(Debug, Clone, PartialEq)]
pub struct Letter {
    pub glyph: u16,
    /// 選んで写せるようにするための元の文字。字形に文字が当たっていなければ空
    pub text: String,
}


/// ページに置いたもの
#[derive(Debug, Clone, PartialEq)]
pub enum Mark {
    /// 字の並び。x と y はベースラインの左端
    Text {
        face: usize,
        size: f64,
        /// 縦に伸ばす率。1 なら伸ばさない
        stretch: f64,
        x: f64,
        y: f64,
        letter: Vec<Letter>,
    },
    /// 塗りつぶした矩形。分数線、罫、下線に使う
    Rule {x: f64, y: f64, width: f64, height: f64},
    /// 折れ線
    Stroke {point: Vec<(f64, f64)>, width: f64},
    /// 塗りつぶした多角形。化学式のくさびに使う
    Fill {point: Vec<(f64, f64)>},
    /// 円。芳香環の丸に使う
    Circle {x: f64, y: f64, radius: f64, width: f64},
    /// 画像。index は [`crate::image`] が集めた並びの番号
    Image {index: usize, x: f64, y: f64, width: f64, height: f64},
}


/// 1 ページ
#[derive(Debug, Clone, PartialEq)]
pub struct Page {
    pub mark: Vec<Mark>,
    pub width: f64,
    pub height: f64,
}


/// 置いたものを、まとめて右下へずらす
pub fn shift(mark: &mut [Mark], dx: f64, dy: f64) {
    for one in mark {
        match one {
            Mark::Text {x, y, ..} => {
                *x += dx;
                *y += dy;
            }
            Mark::Rule {x, y, ..} => {
                *x += dx;
                *y += dy;
            }
            Mark::Stroke {point, ..} | Mark::Fill {point} => {
                for place in point.iter_mut() {
                    place.0 += dx;
                    place.1 += dy;
                }
            }
            Mark::Circle {x, y, ..} => {
                *x += dx;
                *y += dy;
            }
            Mark::Image {x, y, ..} => {
                *x += dx;
                *y += dy;
            }
        }
    }
}