use crate::{error::PdfResult, objects::Dictionary, pdf_enum, Resolve, TypeOrArray};
use self::goto::GoToRemoteAction;
pub use self::{goto::GoToAction, uri::UriAction};
mod goto;
mod uri;
#[derive(Debug)]
pub struct Actions {
action: Action,
next: Option<Vec<Self>>,
}
#[derive(Debug)]
enum Action {
GoTo(GoToAction),
GoToRemote(GoToRemoteAction),
Uri(UriAction),
}
impl Actions {
const TYPE: &'static str = "Action";
pub fn from_dict(mut dict: Dictionary, resolver: &mut impl Resolve) -> PdfResult<Self> {
let action_type = ActionType::from_str(&dict.expect_name("S", resolver)?)?;
let next = dict
.get_type_or_arr("Next", resolver, |resolver, obj| {
Actions::from_dict(resolver.assert_dict(obj)?, resolver)
})?
.map(|type_or_array| match type_or_array {
TypeOrArray::Type(t) => vec![t],
TypeOrArray::Array(arr) => arr,
});
let action = match action_type {
ActionType::GoTo => Action::GoTo(GoToAction::from_dict(dict, resolver)?),
ActionType::GoToRemote => {
Action::GoToRemote(GoToRemoteAction::from_dict(dict, resolver)?)
}
ActionType::Uri => Action::Uri(UriAction::from_dict(dict, resolver)?),
_ => todo!(),
};
Ok(Self { action, next })
}
}
pdf_enum!(
#[derive(Debug)]
pub enum ActionType {
GoTo = "GoTo",
GoToRemote = "GoToR",
GoToEmbedded = "GoToE",
Launch = "Launch",
Thread = "Thread",
Uri = "URI",
Sound = "Sound",
Movie = "Movie",
Hide = "Hide",
Named = "Named",
SubmitForm = "SubmitForm",
ResetForm = "ResetForm",
ImportData = "ImportData",
JavaScript = "JavaScript",
SetOptionalContentGroupState = "SetOCGState",
Rendition = "Rendition",
Trans = "Trans",
GoTo3DView = "GoTo3DView",
}
);