use crate::bindgen::{
FPDF_ACTION, FPDF_DOCUMENT, PDFACTION_EMBEDDEDGOTO, PDFACTION_GOTO, PDFACTION_LAUNCH,
PDFACTION_REMOTEGOTO, PDFACTION_UNSUPPORTED, PDFACTION_URI,
};
use crate::bindings::PdfiumLibraryBindings;
use crate::error::PdfiumError;
#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)]
pub enum PdfActionType {
GoToDestinationInSameDocument = PDFACTION_GOTO as isize,
GoToDestinationInRemoteDocument = PDFACTION_REMOTEGOTO as isize,
GoToDestinationInEmbeddedDocument = PDFACTION_EMBEDDEDGOTO as isize,
Launch = PDFACTION_LAUNCH as isize,
URI = PDFACTION_URI as isize,
Unsupported = PDFACTION_UNSUPPORTED as isize,
}
impl PdfActionType {
pub(crate) fn from_pdfium(action_type: u32) -> Result<PdfActionType, PdfiumError> {
match action_type {
PDFACTION_GOTO => Ok(PdfActionType::GoToDestinationInSameDocument),
PDFACTION_REMOTEGOTO => Ok(PdfActionType::GoToDestinationInRemoteDocument),
PDFACTION_EMBEDDEDGOTO => Ok(PdfActionType::GoToDestinationInEmbeddedDocument),
PDFACTION_LAUNCH => Ok(PdfActionType::Launch),
PDFACTION_URI => Ok(PdfActionType::URI),
PDFACTION_UNSUPPORTED => Ok(PdfActionType::Unsupported),
_ => Err(PdfiumError::UnknownActionType),
}
}
}
pub struct PdfAction<'a> {
handle: FPDF_ACTION,
#[allow(dead_code)]
document_handle: FPDF_DOCUMENT,
bindings: &'a dyn PdfiumLibraryBindings,
}
impl<'a> PdfAction<'a> {
#[inline]
pub(crate) fn from_pdfium(
handle: FPDF_ACTION,
document_handle: FPDF_DOCUMENT,
bindings: &'a dyn PdfiumLibraryBindings,
) -> Self {
Self {
handle,
document_handle,
bindings,
}
}
#[inline]
pub fn action_type(&self) -> PdfActionType {
PdfActionType::from_pdfium(self.bindings.FPDFAction_GetType(self.handle) as u32)
.unwrap_or(PdfActionType::Unsupported)
}
}