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
#[derive(Copy, Clone, Default)]
pub struct Color {
pub alpha: u8,
pub red: u8,
pub green: u8,
pub blue: u8,
}
// We'll be using this in a later PR, just adding the struct right now
#[expect(dead_code)]
impl Color {
fn into_bytes(self) -> [u8; 4] {
let Color {
alpha,
red,
green,
blue,
} = self;
[alpha, red, green, blue]
}
pub(crate) fn into_mupdf_float(self) -> f32 {
f32::from_be_bytes(self.into_bytes())
}
pub(crate) fn from_mupdf_float(f: f32) -> Self {
let [alpha, red, green, blue] = f.to_be_bytes();
Self {
alpha,
red,
green,
blue,
}
}
pub(crate) fn into_mupdf_int(self) -> i32 {
i32::from_be_bytes(self.into_bytes())
}
pub(crate) fn from_mupdf_int(i: i32) -> Self {
let [alpha, red, green, blue] = i.to_be_bytes();
Self {
alpha,
red,
green,
blue,
}
}
}
/// The method used to set colors for [`PdfAnnotation::set_color`] - each float inside should
/// contain a value between [0, 1.0], with 1.0 being the most intense. A 1.0 for Self::Gray
/// indicates white.
///
/// [`PdfAnnotation::set_color`]: crate::pdf::annotation::PdfAnnotation::set_color
pub enum AnnotationColor {
Gray(f32),
Rgb {
red: f32,
green: f32,
blue: f32,
},
Cmyk {
cyan: f32,
magenta: f32,
yellow: f32,
key: f32,
},
}