use crate::bindgen::FPDF_PAGEOBJECT;
use crate::bindings::PdfiumLibraryBindings;
use crate::pdf::document::page::object::content_mark::PdfPageObjectContentMark;
use std::os::raw::c_ulong;
pub struct PdfPageObjectContentMarks<'a> {
object_handle: FPDF_PAGEOBJECT,
bindings: &'a dyn PdfiumLibraryBindings,
}
impl<'a> PdfPageObjectContentMarks<'a> {
pub(crate) fn from_pdfium(object_handle: FPDF_PAGEOBJECT, bindings: &'a dyn PdfiumLibraryBindings) -> Self {
Self {
object_handle,
bindings,
}
}
pub fn len(&self) -> usize {
let count = self.bindings.FPDFPageObj_CountMarks(self.object_handle);
if count < 0 { 0 } else { count as usize }
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
pub fn get(&self, index: usize) -> Option<PdfPageObjectContentMark<'_>> {
if index >= self.len() {
return None;
}
let handle = self.bindings.FPDFPageObj_GetMark(self.object_handle, index as c_ulong);
if handle.is_null() {
None
} else {
Some(PdfPageObjectContentMark::from_pdfium(handle, self.bindings))
}
}
pub fn iter(&self) -> PdfPageObjectContentMarksIterator<'_> {
PdfPageObjectContentMarksIterator { marks: self, index: 0 }
}
}
pub struct PdfPageObjectContentMarksIterator<'a> {
marks: &'a PdfPageObjectContentMarks<'a>,
index: usize,
}
impl<'a> Iterator for PdfPageObjectContentMarksIterator<'a> {
type Item = PdfPageObjectContentMark<'a>;
fn next(&mut self) -> Option<Self::Item> {
if self.index >= self.marks.len() {
None
} else {
let result = self.marks.get(self.index);
self.index += 1;
result
}
}
}