use crate::error::PdfiumError;
use crate::pdf::document::page::text::chars::PdfPageTextChars;
use crate::pdf::document::page::text::PdfPageText;
use crate::pdf::points::PdfPoints;
use crate::pdf::rect::PdfRect;
#[cfg(doc)]
use {
crate::pdf::document::page::text::char::PdfPageTextChar, crate::pdf::document::page::PdfPage,
};
pub struct PdfPageTextSegment<'a> {
text: &'a PdfPageText<'a>,
bounds: PdfRect,
}
impl<'a> PdfPageTextSegment<'a> {
pub(crate) fn from_pdfium(text: &'a PdfPageText<'a>, bounds: PdfRect) -> Self {
PdfPageTextSegment { text, bounds }
}
#[inline]
pub fn bounds(&self) -> PdfRect {
self.bounds
}
#[inline]
pub fn width(&self) -> PdfPoints {
self.bounds.width()
}
#[inline]
pub fn height(&self) -> PdfPoints {
self.bounds.height()
}
#[inline]
pub fn is_inside_rect(&self, rect: &PdfRect) -> bool {
self.bounds.is_inside(rect)
}
#[inline]
pub fn does_overlap_rect(&self, rect: &PdfRect) -> bool {
self.bounds.does_overlap(rect)
}
#[inline]
pub fn text(&self) -> String {
self.text.inside_rect(self.bounds)
}
#[inline]
pub fn chars(&self) -> Result<PdfPageTextChars<'_>, PdfiumError> {
self.text.chars_inside_rect(self.bounds)
}
}