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
use crate::Document;

#[cfg(any(feature = "v0_80", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v0_80")))]
use crate::PageRange;

#[cfg(any(feature = "v0_80", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v0_80")))]
use glib::translate::*;

impl Document {
    /// Returns the suggested page ranges to print in the form of array
    /// of [`PageRange`][crate::PageRange]<!-- -->s and number of ranges.
    /// [`None`] pointer means that the document does not specify page ranges
    /// for printing.
    ///
    /// # Returns
    ///
    /// an array
    ///  of [`PageRange`][crate::PageRange]<!-- -->s or [`None`]. Free the array when
    ///  it is no longer needed.
    #[cfg(any(feature = "v0_80", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v0_80")))]
    #[doc(alias = "poppler_document_get_print_page_ranges")]
    #[doc(alias = "get_print_page_ranges")]
    pub fn print_page_ranges(&self) -> &[PageRange] {
        unsafe {
            let mut n_ranges = std::mem::MaybeUninit::uninit();
            let pages = std::slice::from_raw_parts(
                ffi::poppler_document_get_print_page_ranges(
                    self.to_glib_none().0,
                    n_ranges.as_mut_ptr(),
                ),
                n_ranges.assume_init() as usize,
            );
            &*(pages as *const [ffi::PopplerPageRange] as *const [PageRange])
        }
    }
}