pdfkit/
action_remote_goto.rs1use 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 {
48 ffi::pdf_action_remote_goto_set_page_index(self.handle.as_ptr(), page_index as u64);
49 };
50 }
51
52 #[must_use]
53 pub fn point(&self) -> PdfPoint {
54 PdfPoint {
55 x: unsafe { ffi::pdf_action_remote_goto_point_x(self.handle.as_ptr()) },
56 y: unsafe { ffi::pdf_action_remote_goto_point_y(self.handle.as_ptr()) },
57 }
58 }
59
60 pub fn set_point(&self, point: PdfPoint) {
61 unsafe { ffi::pdf_action_remote_goto_set_point(self.handle.as_ptr(), point.x, point.y) };
62 }
63
64 #[must_use]
65 pub fn url(&self) -> Option<String> {
66 take_string(unsafe { ffi::pdf_action_remote_goto_url_string(self.handle.as_ptr()) })
67 }
68
69 pub fn set_url(&self, url: &str) -> Result<()> {
70 let url = c_string(url)?;
71 let mut out_error = ptr::null_mut();
72 let status = unsafe {
73 ffi::pdf_action_remote_goto_set_url(self.handle.as_ptr(), url.as_ptr(), &mut out_error)
74 };
75 crate::util::status_result(status, out_error)
76 }
77
78 #[must_use]
79 pub fn action_type(&self) -> Option<String> {
80 take_string(unsafe { ffi::pdf_action_remote_goto_type_string(self.handle.as_ptr()) })
81 }
82
83 pub(crate) fn as_handle_ptr(&self) -> *mut core::ffi::c_void {
84 self.handle.as_ptr()
85 }
86}
87
88impl sealed::Sealed for PdfActionRemoteGoTo {}
89
90impl PdfActionLike for PdfActionRemoteGoTo {
91 fn as_action_handle_ptr(&self) -> *mut core::ffi::c_void {
92 self.as_handle_ptr()
93 }
94}