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
use crate::action_goto::PdfActionGoTo;
use crate::action_named::PdfActionNamed;
use crate::action_remote_goto::PdfActionRemoteGoTo;
use crate::action_url::PdfActionUrl;
use crate::ffi;
use crate::handle::ObjectHandle;
use crate::util::take_string;
pub(crate) mod sealed {
pub trait Sealed {}
}
pub trait PdfActionLike: sealed::Sealed {
#[doc(hidden)]
fn as_action_handle_ptr(&self) -> *mut core::ffi::c_void;
}
#[derive(Debug, Clone)]
pub struct PdfAction {
handle: ObjectHandle,
}
impl PdfAction {
pub(crate) fn from_handle(handle: ObjectHandle) -> Self {
Self { handle }
}
#[must_use]
pub fn action_type(&self) -> Option<String> {
take_string(unsafe { ffi::pdf_action_type_string(self.handle.as_ptr()) })
}
#[must_use]
pub fn as_url(&self) -> Option<PdfActionUrl> {
let ptr = unsafe { ffi::pdf_action_as_url(self.handle.as_ptr()) };
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(PdfActionUrl::from_handle)
}
#[must_use]
pub fn as_goto(&self) -> Option<PdfActionGoTo> {
let ptr = unsafe { ffi::pdf_action_as_goto(self.handle.as_ptr()) };
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(PdfActionGoTo::from_handle)
}
#[must_use]
pub fn as_named(&self) -> Option<PdfActionNamed> {
let ptr = unsafe { ffi::pdf_action_as_named(self.handle.as_ptr()) };
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(PdfActionNamed::from_handle)
}
#[must_use]
pub fn as_remote_goto(&self) -> Option<PdfActionRemoteGoTo> {
let ptr = unsafe { ffi::pdf_action_as_remote_goto(self.handle.as_ptr()) };
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(PdfActionRemoteGoTo::from_handle)
}
pub(crate) fn as_handle_ptr(&self) -> *mut core::ffi::c_void {
self.handle.as_ptr()
}
}
impl sealed::Sealed for PdfAction {}
impl PdfActionLike for PdfAction {
fn as_action_handle_ptr(&self) -> *mut core::ffi::c_void {
self.as_handle_ptr()
}
}