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;
}
}
}
}