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