#[doc(hidden)]
use crate::bindgen::FPDF_CLIPPATH;
use crate::bindings::PdfiumLibraryBindings;
use crate::error::{PdfiumError, PdfiumInternalError};
use crate::path_segment::PdfPathSegment;
use crate::path_segments::{PdfPathSegmentIndex, PdfPathSegments, PdfPathSegmentsIterator};
use std::convert::TryInto;
use std::os::raw::c_int;
#[allow(dead_code)]
pub struct PdfClipPath {
}
pub struct PdfClipPathSegments<'a> {
handle: FPDF_CLIPPATH,
path_index: c_int,
bindings: &'a dyn PdfiumLibraryBindings,
}
impl<'a> PdfClipPathSegments<'a> {
#[inline]
#[allow(dead_code)]
pub(crate) fn from_pdfium(
handle: FPDF_CLIPPATH,
path_index: c_int,
bindings: &'a dyn PdfiumLibraryBindings,
) -> Self {
Self {
handle,
path_index,
bindings,
}
}
}
impl<'a> PdfPathSegments<'a> for PdfClipPathSegments<'a> {
#[inline]
fn bindings(&self) -> &'a dyn PdfiumLibraryBindings {
self.bindings
}
#[inline]
fn len(&self) -> PdfPathSegmentIndex {
self.bindings()
.FPDFClipPath_CountPathSegments(self.handle, self.path_index)
.try_into()
.unwrap_or(0)
}
fn get(&self, index: PdfPathSegmentIndex) -> Result<PdfPathSegment<'a>, PdfiumError> {
let handle = self.bindings().FPDFClipPath_GetPathSegment(
self.handle,
self.path_index,
index as c_int,
);
if handle.is_null() {
if let Some(error) = self.bindings().get_pdfium_last_error() {
Err(PdfiumError::PdfiumLibraryInternalError(error))
} else {
Err(PdfiumError::PdfiumLibraryInternalError(
PdfiumInternalError::Unknown,
))
}
} else {
Ok(PdfPathSegment::from_pdfium(handle, self.bindings()))
}
}
#[inline]
fn iter(&'a self) -> PdfPathSegmentsIterator<'a> {
PdfPathSegmentsIterator::new(self)
}
}