Skip to main content

poppler/auto/
page.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5#![allow(deprecated)]
6
7#[cfg(feature = "v25_2")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v25_2")))]
9use crate::RenderAnnotsFlags;
10use crate::{
11    Annot, AnnotMapping, Color, FindFlags, FormFieldMapping, ImageMapping, LinkMapping, PSFile,
12    PageTransition, PrintFlags, Rectangle, SelectionStyle, TextAttributes, ffi,
13};
14use glib::{
15    prelude::*,
16    signal::{SignalHandlerId, connect_raw},
17    translate::*,
18};
19use std::boxed::Box as Box_;
20
21glib::wrapper! {
22    #[doc(alias = "PopplerPage")]
23    pub struct Page(Object<ffi::PopplerPage>);
24
25    match fn {
26        type_ => || ffi::poppler_page_get_type(),
27    }
28}
29
30impl Page {
31    #[doc(alias = "poppler_page_add_annot")]
32    pub fn add_annot(&self, annot: &impl IsA<Annot>) {
33        unsafe {
34            ffi::poppler_page_add_annot(self.to_glib_none().0, annot.as_ref().to_glib_none().0);
35        }
36    }
37
38    #[doc(alias = "poppler_page_find_text")]
39    pub fn find_text(&self, text: &str) -> Vec<Rectangle> {
40        unsafe {
41            FromGlibPtrContainer::from_glib_full(ffi::poppler_page_find_text(
42                self.to_glib_none().0,
43                text.to_glib_none().0,
44            ))
45        }
46    }
47
48    #[doc(alias = "poppler_page_find_text_with_options")]
49    pub fn find_text_with_options(&self, text: &str, options: FindFlags) -> Vec<Rectangle> {
50        unsafe {
51            FromGlibPtrContainer::from_glib_full(ffi::poppler_page_find_text_with_options(
52                self.to_glib_none().0,
53                text.to_glib_none().0,
54                options.into_glib(),
55            ))
56        }
57    }
58
59    #[doc(alias = "poppler_page_get_annot_mapping")]
60    #[doc(alias = "get_annot_mapping")]
61    pub fn annot_mapping(&self) -> Vec<AnnotMapping> {
62        unsafe {
63            FromGlibPtrContainer::from_glib_full(ffi::poppler_page_get_annot_mapping(
64                self.to_glib_none().0,
65            ))
66        }
67    }
68
69    #[doc(alias = "poppler_page_get_bounding_box")]
70    pub fn get_bounding_box(&self, rect: &mut Rectangle) -> bool {
71        unsafe {
72            from_glib(ffi::poppler_page_get_bounding_box(
73                self.to_glib_none().0,
74                rect.to_glib_none_mut().0,
75            ))
76        }
77    }
78
79    #[doc(alias = "poppler_page_get_duration")]
80    #[doc(alias = "get_duration")]
81    pub fn duration(&self) -> f64 {
82        unsafe { ffi::poppler_page_get_duration(self.to_glib_none().0) }
83    }
84
85    #[doc(alias = "poppler_page_get_form_field_mapping")]
86    #[doc(alias = "get_form_field_mapping")]
87    pub fn form_field_mapping(&self) -> Vec<FormFieldMapping> {
88        unsafe {
89            FromGlibPtrContainer::from_glib_full(ffi::poppler_page_get_form_field_mapping(
90                self.to_glib_none().0,
91            ))
92        }
93    }
94
95    #[doc(alias = "poppler_page_get_image")]
96    #[doc(alias = "get_image")]
97    pub fn image(&self, image_id: i32) -> Option<cairo::Surface> {
98        unsafe { from_glib_full(ffi::poppler_page_get_image(self.to_glib_none().0, image_id)) }
99    }
100
101    #[doc(alias = "poppler_page_get_image_mapping")]
102    #[doc(alias = "get_image_mapping")]
103    pub fn image_mapping(&self) -> Vec<ImageMapping> {
104        unsafe {
105            FromGlibPtrContainer::from_glib_full(ffi::poppler_page_get_image_mapping(
106                self.to_glib_none().0,
107            ))
108        }
109    }
110
111    #[doc(alias = "poppler_page_get_index")]
112    #[doc(alias = "get_index")]
113    pub fn index(&self) -> i32 {
114        unsafe { ffi::poppler_page_get_index(self.to_glib_none().0) }
115    }
116
117    #[doc(alias = "poppler_page_get_label")]
118    #[doc(alias = "get_label")]
119    pub fn label(&self) -> Option<glib::GString> {
120        unsafe { from_glib_full(ffi::poppler_page_get_label(self.to_glib_none().0)) }
121    }
122
123    #[doc(alias = "poppler_page_get_link_mapping")]
124    #[doc(alias = "get_link_mapping")]
125    pub fn link_mapping(&self) -> Vec<LinkMapping> {
126        unsafe {
127            FromGlibPtrContainer::from_glib_full(ffi::poppler_page_get_link_mapping(
128                self.to_glib_none().0,
129            ))
130        }
131    }
132
133    #[doc(alias = "poppler_page_get_selected_region")]
134    #[doc(alias = "get_selected_region")]
135    pub fn selected_region(
136        &self,
137        scale: f64,
138        style: SelectionStyle,
139        selection: &mut Rectangle,
140    ) -> Option<cairo::Region> {
141        unsafe {
142            from_glib_full(ffi::poppler_page_get_selected_region(
143                self.to_glib_none().0,
144                scale,
145                style.into_glib(),
146                selection.to_glib_none_mut().0,
147            ))
148        }
149    }
150
151    #[doc(alias = "poppler_page_get_selected_text")]
152    #[doc(alias = "get_selected_text")]
153    pub fn selected_text(
154        &self,
155        style: SelectionStyle,
156        selection: &mut Rectangle,
157    ) -> Option<glib::GString> {
158        unsafe {
159            from_glib_full(ffi::poppler_page_get_selected_text(
160                self.to_glib_none().0,
161                style.into_glib(),
162                selection.to_glib_none_mut().0,
163            ))
164        }
165    }
166
167    #[doc(alias = "poppler_page_get_size")]
168    #[doc(alias = "get_size")]
169    pub fn size(&self) -> (f64, f64) {
170        unsafe {
171            let mut width = std::mem::MaybeUninit::uninit();
172            let mut height = std::mem::MaybeUninit::uninit();
173            ffi::poppler_page_get_size(
174                self.to_glib_none().0,
175                width.as_mut_ptr(),
176                height.as_mut_ptr(),
177            );
178            (width.assume_init(), height.assume_init())
179        }
180    }
181
182    #[doc(alias = "poppler_page_get_text")]
183    #[doc(alias = "get_text")]
184    pub fn text(&self) -> Option<glib::GString> {
185        unsafe { from_glib_full(ffi::poppler_page_get_text(self.to_glib_none().0)) }
186    }
187
188    #[doc(alias = "poppler_page_get_text_attributes")]
189    #[doc(alias = "get_text_attributes")]
190    pub fn text_attributes(&self) -> Vec<TextAttributes> {
191        unsafe {
192            FromGlibPtrContainer::from_glib_full(ffi::poppler_page_get_text_attributes(
193                self.to_glib_none().0,
194            ))
195        }
196    }
197
198    #[doc(alias = "poppler_page_get_text_attributes_for_area")]
199    #[doc(alias = "get_text_attributes_for_area")]
200    pub fn text_attributes_for_area(&self, area: &mut Rectangle) -> Vec<TextAttributes> {
201        unsafe {
202            FromGlibPtrContainer::from_glib_full(ffi::poppler_page_get_text_attributes_for_area(
203                self.to_glib_none().0,
204                area.to_glib_none_mut().0,
205            ))
206        }
207    }
208
209    #[doc(alias = "poppler_page_get_text_for_area")]
210    #[doc(alias = "get_text_for_area")]
211    pub fn text_for_area(&self, area: &mut Rectangle) -> Option<glib::GString> {
212        unsafe {
213            from_glib_full(ffi::poppler_page_get_text_for_area(
214                self.to_glib_none().0,
215                area.to_glib_none_mut().0,
216            ))
217        }
218    }
219
220    #[doc(alias = "poppler_page_get_thumbnail")]
221    #[doc(alias = "get_thumbnail")]
222    pub fn thumbnail(&self) -> Option<cairo::Surface> {
223        unsafe { from_glib_full(ffi::poppler_page_get_thumbnail(self.to_glib_none().0)) }
224    }
225
226    #[doc(alias = "poppler_page_get_thumbnail_size")]
227    #[doc(alias = "get_thumbnail_size")]
228    pub fn thumbnail_size(&self) -> Option<(i32, i32)> {
229        unsafe {
230            let mut width = std::mem::MaybeUninit::uninit();
231            let mut height = std::mem::MaybeUninit::uninit();
232            let ret = from_glib(ffi::poppler_page_get_thumbnail_size(
233                self.to_glib_none().0,
234                width.as_mut_ptr(),
235                height.as_mut_ptr(),
236            ));
237            if ret {
238                Some((width.assume_init(), height.assume_init()))
239            } else {
240                None
241            }
242        }
243    }
244
245    #[doc(alias = "poppler_page_get_transition")]
246    #[doc(alias = "get_transition")]
247    pub fn transition(&self) -> Option<PageTransition> {
248        unsafe { from_glib_full(ffi::poppler_page_get_transition(self.to_glib_none().0)) }
249    }
250
251    #[doc(alias = "poppler_page_remove_annot")]
252    pub fn remove_annot(&self, annot: &impl IsA<Annot>) {
253        unsafe {
254            ffi::poppler_page_remove_annot(self.to_glib_none().0, annot.as_ref().to_glib_none().0);
255        }
256    }
257
258    #[doc(alias = "poppler_page_render")]
259    pub fn render(&self, cairo: &cairo::Context) {
260        unsafe {
261            ffi::poppler_page_render(self.to_glib_none().0, mut_override(cairo.to_glib_none().0));
262        }
263    }
264
265    #[doc(alias = "poppler_page_render_for_printing")]
266    pub fn render_for_printing(&self, cairo: &cairo::Context) {
267        unsafe {
268            ffi::poppler_page_render_for_printing(
269                self.to_glib_none().0,
270                mut_override(cairo.to_glib_none().0),
271            );
272        }
273    }
274
275    #[cfg_attr(feature = "v25_2", deprecated = "Since 25.2")]
276    #[allow(deprecated)]
277    #[doc(alias = "poppler_page_render_for_printing_with_options")]
278    pub fn render_for_printing_with_options(&self, cairo: &cairo::Context, options: PrintFlags) {
279        unsafe {
280            ffi::poppler_page_render_for_printing_with_options(
281                self.to_glib_none().0,
282                mut_override(cairo.to_glib_none().0),
283                options.into_glib(),
284            );
285        }
286    }
287
288    #[cfg(feature = "v25_2")]
289    #[cfg_attr(docsrs, doc(cfg(feature = "v25_2")))]
290    #[doc(alias = "poppler_page_render_full")]
291    pub fn render_full(&self, cairo: &cairo::Context, printing: bool, flags: RenderAnnotsFlags) {
292        unsafe {
293            ffi::poppler_page_render_full(
294                self.to_glib_none().0,
295                mut_override(cairo.to_glib_none().0),
296                printing.into_glib(),
297                flags.into_glib(),
298            );
299        }
300    }
301
302    #[doc(alias = "poppler_page_render_selection")]
303    pub fn render_selection(
304        &self,
305        cairo: &cairo::Context,
306        selection: &mut Rectangle,
307        old_selection: &mut Rectangle,
308        style: SelectionStyle,
309        glyph_color: &mut Color,
310        background_color: &mut Color,
311    ) {
312        unsafe {
313            ffi::poppler_page_render_selection(
314                self.to_glib_none().0,
315                mut_override(cairo.to_glib_none().0),
316                selection.to_glib_none_mut().0,
317                old_selection.to_glib_none_mut().0,
318                style.into_glib(),
319                glyph_color.to_glib_none_mut().0,
320                background_color.to_glib_none_mut().0,
321            );
322        }
323    }
324
325    #[doc(alias = "poppler_page_render_to_ps")]
326    pub fn render_to_ps(&self, ps_file: &PSFile) {
327        unsafe {
328            ffi::poppler_page_render_to_ps(self.to_glib_none().0, ps_file.to_glib_none().0);
329        }
330    }
331
332    #[cfg(feature = "v25_8")]
333    #[cfg_attr(docsrs, doc(cfg(feature = "v25_8")))]
334    #[doc(alias = "poppler_page_render_transparent_selection")]
335    pub fn render_transparent_selection(
336        &self,
337        cairo: &cairo::Context,
338        selection: &mut Rectangle,
339        old_selection: &mut Rectangle,
340        style: SelectionStyle,
341        background_color: &mut Color,
342        background_opacity: f64,
343    ) {
344        unsafe {
345            ffi::poppler_page_render_transparent_selection(
346                self.to_glib_none().0,
347                mut_override(cairo.to_glib_none().0),
348                selection.to_glib_none_mut().0,
349                old_selection.to_glib_none_mut().0,
350                style.into_glib(),
351                background_color.to_glib_none_mut().0,
352                background_opacity,
353            );
354        }
355    }
356
357    #[doc(alias = "label")]
358    pub fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
359        unsafe extern "C" fn notify_label_trampoline<F: Fn(&Page) + 'static>(
360            this: *mut ffi::PopplerPage,
361            _param_spec: glib::ffi::gpointer,
362            f: glib::ffi::gpointer,
363        ) {
364            unsafe {
365                let f: &F = &*(f as *const F);
366                f(&from_glib_borrow(this))
367            }
368        }
369        unsafe {
370            let f: Box_<F> = Box_::new(f);
371            connect_raw(
372                self.as_ptr() as *mut _,
373                c"notify::label".as_ptr(),
374                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
375                    notify_label_trampoline::<F> as *const (),
376                )),
377                Box_::into_raw(f),
378            )
379        }
380    }
381}