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),
}
}
}