// This file was generated by gir (https://github.com/gtk-rs/gir)
// from ../gir-files
// from ../pps-girs
// DO NOT EDIT

use crate::{ffi, Page, Rectangle};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    #[doc(alias = "PpsDocumentText")]
    pub struct DocumentText(Interface<ffi::PpsDocumentText, ffi::PpsDocumentTextInterface>);

    match fn {
        type_ => || ffi::pps_document_text_get_type(),
    }
}

impl DocumentText {
    pub const NONE: Option<&'static DocumentText> = None;
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::DocumentText>> Sealed for T {}
}

pub trait DocumentTextExt: IsA<DocumentText> + sealed::Sealed + 'static {
    #[doc(alias = "pps_document_text_get_text")]
    #[doc(alias = "get_text")]
    fn text(&self, page: &impl IsA<Page>) -> Option<glib::GString> {
        unsafe {
            from_glib_full(ffi::pps_document_text_get_text(
                self.as_ref().to_glib_none().0,
                page.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "pps_document_text_get_text_attrs")]
    #[doc(alias = "get_text_attrs")]
    fn text_attrs(&self, page: &impl IsA<Page>) -> Option<pango::AttrList> {
        unsafe {
            from_glib_full(ffi::pps_document_text_get_text_attrs(
                self.as_ref().to_glib_none().0,
                page.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(feature = "v47")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v47")))]
    #[doc(alias = "pps_document_text_get_text_in_area")]
    #[doc(alias = "get_text_in_area")]
    fn text_in_area(&self, page: &impl IsA<Page>, area: &mut Rectangle) -> Option<glib::GString> {
        unsafe {
            from_glib_full(ffi::pps_document_text_get_text_in_area(
                self.as_ref().to_glib_none().0,
                page.as_ref().to_glib_none().0,
                area.to_glib_none_mut().0,
            ))
        }
    }

    #[doc(alias = "pps_document_text_get_text_layout")]
    #[doc(alias = "get_text_layout")]
    fn text_layout(&self, page: &impl IsA<Page>) -> Option<Vec<Rectangle>> {
        unsafe {
            let mut areas = std::ptr::null_mut();
            let mut n_areas = std::mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::pps_document_text_get_text_layout(
                self.as_ref().to_glib_none().0,
                page.as_ref().to_glib_none().0,
                &mut areas,
                n_areas.as_mut_ptr(),
            ));
            if ret {
                Some(FromGlibContainer::from_glib_container_num(
                    areas,
                    n_areas.assume_init() as _,
                ))
            } else {
                None
            }
        }
    }

    #[doc(alias = "pps_document_text_get_text_mapping")]
    #[doc(alias = "get_text_mapping")]
    fn text_mapping(&self, page: &impl IsA<Page>) -> Option<cairo::Region> {
        unsafe {
            from_glib_full(ffi::pps_document_text_get_text_mapping(
                self.as_ref().to_glib_none().0,
                page.as_ref().to_glib_none().0,
            ))
        }
    }
}

impl<O: IsA<DocumentText>> DocumentTextExt for O {}
