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.4.0
Copyright
Rollpie, Irohabook
Publisher
math
Published
2026-10-16
Size
1085.8 KB
Downloads
19
Checksum
df10d3447b809454aba0a9fd252d07428b819520aff22324461ba2dcbf1e43fb
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
79
80
//! Things placed on a page
//!
//! Every position and size is already decided. The origin is the top left corner of the page,
//! x is positive to the right, and y is positive downward.
//! [`crate::stream`] converts them to PDF coordinates.

/// One placed letter
#[derive(Debug, Clone, PartialEq)]
pub struct Letter {
    pub glyph: u16,
    /// The original text, so that it can be selected and copied. Empty if no character maps to
    /// the glyph
    pub text: String,
}


/// Something placed on a page
#[derive(Debug, Clone, PartialEq)]
pub enum Mark {
    /// A run of letters. x and y are the left end of the baseline
    Text {
        face: usize,
        size: f64,
        /// The factor for stretching vertically. 1 means no stretching
        stretch: f64,
        x: f64,
        y: f64,
        letter: Vec<Letter>,
    },
    /// A filled rectangle. Used for fraction bars, rules, and underlines
    Rule {x: f64, y: f64, width: f64, height: f64},
    /// A polyline
    Stroke {point: Vec<(f64, f64)>, width: f64},
    /// A filled polygon. Used for wedges in chemical structures
    Fill {point: Vec<(f64, f64)>},
    /// A circle. Used for the circle in an aromatic ring
    Circle {x: f64, y: f64, radius: f64, width: f64},
    /// An image. index is its number in the list that [`crate::image`] collected
    Image {index: usize, x: f64, y: f64, width: f64, height: f64},
}


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


/// Shifts all the placed marks together toward the lower right
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;
            }
        }
    }
}