Skip to main content

pdfkit/
action_remote_goto.rs

1use std::ptr;
2
3use crate::action::{sealed, PdfActionLike};
4use crate::error::Result;
5use crate::ffi;
6use crate::handle::ObjectHandle;
7use crate::types::PdfPoint;
8use crate::util::{c_string, take_string};
9
10/// Wraps `PDFActionRemoteGoTo`.
11#[derive(Debug, Clone)]
12pub struct PdfActionRemoteGoTo {
13    handle: ObjectHandle,
14}
15
16impl PdfActionRemoteGoTo {
17    pub(crate) fn from_handle(handle: ObjectHandle) -> Self {
18        Self { handle }
19    }
20
21    /// Wraps `PDFActionRemoteGoTo(pageIndex:at:fileURL:)`.
22    pub fn new(page_index: usize, point: PdfPoint, url: &str) -> Result<Self> {
23        let url = c_string(url)?;
24        let mut out_action = ptr::null_mut();
25        let mut out_error = ptr::null_mut();
26        let status = unsafe {
27            ffi::pdf_action_remote_goto_new(
28                page_index as u64,
29                point.x,
30                point.y,
31                url.as_ptr(),
32                &mut out_action,
33                &mut out_error,
34            )
35        };
36        crate::util::status_result(status, out_error)?;
37        Ok(Self::from_handle(crate::util::required_handle(
38            out_action,
39            "PDFActionRemoteGoTo",
40        )?))
41    }
42
43    /// Wraps the corresponding `PDFActionRemoteGoTo` API.
44    #[must_use]
45    pub fn page_index(&self) -> usize {
46        unsafe { ffi::pdf_action_remote_goto_page_index(self.handle.as_ptr()) as usize }
47    }
48
49    /// Wraps the corresponding `PDFActionRemoteGoTo` API.
50    pub fn set_page_index(&self, page_index: usize) {
51        unsafe {
52            ffi::pdf_action_remote_goto_set_page_index(self.handle.as_ptr(), page_index as u64);
53        };
54    }
55
56    /// Wraps the corresponding `PDFActionRemoteGoTo` API.
57    #[must_use]
58    pub fn point(&self) -> PdfPoint {
59        PdfPoint {
60            x: unsafe { ffi::pdf_action_remote_goto_point_x(self.handle.as_ptr()) },
61            y: unsafe { ffi::pdf_action_remote_goto_point_y(self.handle.as_ptr()) },
62        }
63    }
64
65    /// Wraps the corresponding `PDFActionRemoteGoTo` API.
66    pub fn set_point(&self, point: PdfPoint) {
67        unsafe { ffi::pdf_action_remote_goto_set_point(self.handle.as_ptr(), point.x, point.y) };
68    }
69
70    /// Wraps the corresponding `PDFActionRemoteGoTo` API.
71    #[must_use]
72    pub fn url(&self) -> Option<String> {
73        take_string(unsafe { ffi::pdf_action_remote_goto_url_string(self.handle.as_ptr()) })
74    }
75
76    /// Wraps the corresponding `PDFActionRemoteGoTo` API.
77    pub fn set_url(&self, url: &str) -> Result<()> {
78        let url = c_string(url)?;
79        let mut out_error = ptr::null_mut();
80        let status = unsafe {
81            ffi::pdf_action_remote_goto_set_url(self.handle.as_ptr(), url.as_ptr(), &mut out_error)
82        };
83        crate::util::status_result(status, out_error)
84    }
85
86    /// Wraps the corresponding `PDFActionRemoteGoTo` API.
87    #[must_use]
88    pub fn action_type(&self) -> Option<String> {
89        take_string(unsafe { ffi::pdf_action_remote_goto_type_string(self.handle.as_ptr()) })
90    }
91
92    pub(crate) fn as_handle_ptr(&self) -> *mut core::ffi::c_void {
93        self.handle.as_ptr()
94    }
95}
96
97impl sealed::Sealed for PdfActionRemoteGoTo {}
98
99impl PdfActionLike for PdfActionRemoteGoTo {
100    fn as_action_handle_ptr(&self) -> *mut core::ffi::c_void {
101        self.as_handle_ptr()
102    }
103}