use crate::bindgen::{FPDF_ANNOTATION, FPDF_DOCUMENT, FPDF_PAGE};
#[derive(Copy, Clone)]
pub(crate) struct PdfPageObjectOwnedByDocument {
document_handle: FPDF_DOCUMENT,
}
impl PdfPageObjectOwnedByDocument {
pub fn document_handle(&self) -> FPDF_DOCUMENT {
self.document_handle
}
}
#[derive(Copy, Clone)]
pub(crate) struct PdfPageObjectOwnedByPage {
document_handle: FPDF_DOCUMENT,
page_handle: FPDF_PAGE,
}
impl PdfPageObjectOwnedByPage {
pub fn document_handle(&self) -> FPDF_DOCUMENT {
self.document_handle
}
pub fn page_handle(&self) -> FPDF_PAGE {
self.page_handle
}
}
#[derive(Copy, Clone)]
pub(crate) struct PdfPageObjectOwnedByAttachedAnnotation {
document_handle: FPDF_DOCUMENT,
page_handle: FPDF_PAGE,
annotation_handle: FPDF_ANNOTATION,
}
impl PdfPageObjectOwnedByAttachedAnnotation {
pub fn document_handle(&self) -> FPDF_DOCUMENT {
self.document_handle
}
pub fn page_handle(&self) -> FPDF_PAGE {
self.page_handle
}
pub fn annotation_handle(&self) -> FPDF_ANNOTATION {
self.annotation_handle
}
}
#[derive(Copy, Clone)]
pub(crate) struct PdfPageObjectOwnedByUnattachedAnnotation {
document_handle: FPDF_DOCUMENT,
annotation_handle: FPDF_ANNOTATION,
}
impl PdfPageObjectOwnedByUnattachedAnnotation {
pub fn document_handle(&self) -> FPDF_DOCUMENT {
self.document_handle
}
pub fn annotation_handle(&self) -> FPDF_ANNOTATION {
self.annotation_handle
}
}
#[derive(Copy, Clone)]
pub(crate) enum PdfPageObjectOwnership {
Unowned,
Document(PdfPageObjectOwnedByDocument),
Page(PdfPageObjectOwnedByPage),
AttachedAnnotation(PdfPageObjectOwnedByAttachedAnnotation),
UnattachedAnnotation(PdfPageObjectOwnedByUnattachedAnnotation),
}
impl PdfPageObjectOwnership {
pub fn unowned() -> Self {
Self::Unowned
}
pub fn owned_by_document(document_handle: FPDF_DOCUMENT) -> Self {
Self::Document(PdfPageObjectOwnedByDocument { document_handle })
}
pub fn owned_by_page(document_handle: FPDF_DOCUMENT, page_handle: FPDF_PAGE) -> Self {
Self::Page(PdfPageObjectOwnedByPage {
document_handle,
page_handle,
})
}
pub fn owned_by_attached_annotation(
document_handle: FPDF_DOCUMENT,
page_handle: FPDF_PAGE,
annotation_handle: FPDF_ANNOTATION,
) -> Self {
Self::AttachedAnnotation(PdfPageObjectOwnedByAttachedAnnotation {
document_handle,
page_handle,
annotation_handle,
})
}
pub fn owned_by_unattached_annotation(
document_handle: FPDF_DOCUMENT,
annotation_handle: FPDF_ANNOTATION,
) -> Self {
Self::UnattachedAnnotation(PdfPageObjectOwnedByUnattachedAnnotation {
document_handle,
annotation_handle,
})
}
pub fn is_owned(&self) -> bool {
!matches!(self, PdfPageObjectOwnership::Unowned)
}
}