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
extern crate lopdf;
#[derive(Default, Debug, Clone)]
pub struct OCGList {
pub(crate) layers: Vec<(OCGRef, lopdf::Object)>,
}
impl OCGList {
pub fn new()
-> Self
{
Self::default()
}
pub fn add_ocg(&mut self, obj: lopdf::Object)
-> OCGRef
{
let len = self.layers.len();
let ocg_ref = OCGRef::new(len);
self.layers.push((ocg_ref.clone(), obj));
ocg_ref
}
}
impl Into<lopdf::Dictionary> for OCGList {
#[cfg_attr(feature = "cargo-clippy", allow(needless_return))]
fn into(self)
-> lopdf::Dictionary
{
let mut dict = lopdf::Dictionary::new();
for entry in self.layers {
dict.set(entry.0.name, entry.1);
}
return dict;
}
}
#[derive(Debug, Clone)]
pub struct OCGRef {
pub(crate) name: String,
}
impl OCGRef {
pub fn new(index: usize)
-> Self
{
Self {
name: format!("MC{}", index),
}
}
}