pub mod mark;
pub mod objects;
use std::{ffi::CString, os::raw::c_ulong};
use crate::{
PdfiumClipPath, PdfiumPage, PdfiumPageObjectMark,
error::{PdfiumError, PdfiumResult},
lib,
pdfium_constants::{
FPDF_PAGEOBJ_FORM, FPDF_PAGEOBJ_IMAGE, FPDF_PAGEOBJ_PATH, FPDF_PAGEOBJ_SHADING,
FPDF_PAGEOBJ_TEXT, FPDF_PAGEOBJ_UNKNOWN,
},
pdfium_types::{
FPDF_BOOL, FPDF_PAGEOBJECT, FS_MATRIX, FS_QUADPOINTSF, Handle, PageObjectHandle,
},
};
#[derive(Debug, Clone)]
pub struct PdfiumPageObject {
handle: PageObjectHandle,
owner: Option<PdfiumPage>,
}
impl PdfiumPageObject {
pub(crate) fn new_from_handle(handle: FPDF_PAGEOBJECT) -> PdfiumResult<Self> {
if handle.is_null() {
Err(PdfiumError::NullHandle)
} else {
Ok(Self {
handle: Handle::new(handle, Some(close_page_object)),
owner: None,
})
}
}
pub(crate) fn set_owner(&mut self, owner: PdfiumPage) {
self.owner = Some(owner);
}
pub fn remove_param(&self, mark: &PdfiumPageObjectMark, key: &CString) -> PdfiumResult<()> {
lib().FPDFPageObjMark_RemoveParam(self, mark, key)
}
pub fn add_mark(&self, name: &CString) -> PdfiumResult<PdfiumPageObjectMark> {
lib().FPDFPageObj_AddMark(self, name)
}
pub fn count_marks(&self) -> i32 {
lib().FPDFPageObj_CountMarks(self)
}
pub fn get_bounds(
&self,
left: &mut f32,
bottom: &mut f32,
right: &mut f32,
top: &mut f32,
) -> PdfiumResult<()> {
lib().FPDFPageObj_GetBounds(self, left, bottom, right, top)
}
pub fn get_clip_path(&self) -> PdfiumResult<PdfiumClipPath> {
lib().FPDFPageObj_GetClipPath(self)
}
pub fn get_dash_array(&self, dash_array: &mut f32, dash_count: usize) -> PdfiumResult<()> {
lib().FPDFPageObj_GetDashArray(self, dash_array, dash_count)
}
pub fn get_dash_count(&self) -> i32 {
lib().FPDFPageObj_GetDashCount(self)
}
pub fn get_dash_phase(&self, phase: &mut f32) -> PdfiumResult<()> {
lib().FPDFPageObj_GetDashPhase(self, phase)
}
pub fn get_fill_color(
&self,
r: &mut u32,
g: &mut u32,
b: &mut u32,
a: &mut u32,
) -> PdfiumResult<()> {
lib().FPDFPageObj_GetFillColor(self, r, g, b, a)
}
pub fn get_is_active(&self, active: &mut FPDF_BOOL) -> PdfiumResult<()> {
lib().FPDFPageObj_GetIsActive(self, active)
}
pub fn get_line_cap(&self) -> i32 {
lib().FPDFPageObj_GetLineCap(self)
}
pub fn get_line_join(&self) -> i32 {
lib().FPDFPageObj_GetLineJoin(self)
}
pub fn get_mark(&self, index: c_ulong) -> PdfiumResult<PdfiumPageObjectMark> {
lib().FPDFPageObj_GetMark(self, index)
}
pub fn get_marked_content_id(&self) -> i32 {
lib().FPDFPageObj_GetMarkedContentID(self)
}
pub fn get_matrix(&self, matrix: &mut FS_MATRIX) -> PdfiumResult<()> {
lib().FPDFPageObj_GetMatrix(self, matrix)
}
pub fn get_rotated_bounds(&self, quad_points: &mut FS_QUADPOINTSF) -> PdfiumResult<()> {
lib().FPDFPageObj_GetRotatedBounds(self, quad_points)
}
pub fn get_stroke_color(
&self,
r: &mut u32,
g: &mut u32,
b: &mut u32,
a: &mut u32,
) -> PdfiumResult<()> {
lib().FPDFPageObj_GetStrokeColor(self, r, g, b, a)
}
pub fn get_stroke_width(&self, width: &mut f32) -> PdfiumResult<()> {
lib().FPDFPageObj_GetStrokeWidth(self, width)
}
pub fn get_type(&self) -> ObjectType {
lib().FPDFPageObj_GetType(self).into()
}
pub fn has_transparency(&self) -> i32 {
lib().FPDFPageObj_HasTransparency(self)
}
pub fn remove_mark(&self, mark: &PdfiumPageObjectMark) -> PdfiumResult<()> {
lib().FPDFPageObj_RemoveMark(self, mark)
}
pub fn set_blend_mode(&self, blend_mode: &CString) {
lib().FPDFPageObj_SetBlendMode(self, blend_mode)
}
pub fn set_dash_array(
&self,
dash_array: &[f32],
dash_count: usize,
phase: f32,
) -> PdfiumResult<()> {
lib().FPDFPageObj_SetDashArray(self, dash_array, dash_count, phase)
}
pub fn set_dash_phase(&self, phase: f32) -> PdfiumResult<()> {
lib().FPDFPageObj_SetDashPhase(self, phase)
}
pub fn set_fill_color(&self, r: u32, g: u32, b: u32, a: u32) -> PdfiumResult<()> {
lib().FPDFPageObj_SetFillColor(self, r, g, b, a)
}
pub fn set_is_active(&self, active: i32) -> PdfiumResult<()> {
lib().FPDFPageObj_SetIsActive(self, active)
}
pub fn set_line_cap(&self, line_cap: i32) -> PdfiumResult<()> {
lib().FPDFPageObj_SetLineCap(self, line_cap)
}
pub fn set_line_join(&self, line_join: i32) -> PdfiumResult<()> {
lib().FPDFPageObj_SetLineJoin(self, line_join)
}
pub fn set_matrix(&self, matrix: &FS_MATRIX) -> PdfiumResult<()> {
lib().FPDFPageObj_SetMatrix(self, matrix)
}
pub fn set_stroke_color(&self, r: u32, g: u32, b: u32, a: u32) -> PdfiumResult<()> {
lib().FPDFPageObj_SetStrokeColor(self, r, g, b, a)
}
pub fn set_stroke_width(&self, width: f32) -> PdfiumResult<()> {
lib().FPDFPageObj_SetStrokeWidth(self, width)
}
pub fn transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
lib().FPDFPageObj_Transform(self, a, b, c, d, e, f)
}
pub fn transform_clip_path(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
lib().FPDFPageObj_TransformClipPath(self, a, b, c, d, e, f)
}
pub fn transform_f(&self, matrix: &FS_MATRIX) -> PdfiumResult<()> {
lib().FPDFPageObj_TransformF(self, matrix)
}
}
impl From<&PdfiumPageObject> for FPDF_PAGEOBJECT {
fn from(page_object: &PdfiumPageObject) -> Self {
page_object.handle.handle()
}
}
fn close_page_object(_page_object: FPDF_PAGEOBJECT) {
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(i32)]
pub enum ObjectType {
Unsupported = FPDF_PAGEOBJ_UNKNOWN,
Text = FPDF_PAGEOBJ_TEXT,
Path = FPDF_PAGEOBJ_PATH,
Image = FPDF_PAGEOBJ_IMAGE,
Shading = FPDF_PAGEOBJ_SHADING,
Form = FPDF_PAGEOBJ_FORM,
}
impl From<i32> for ObjectType {
fn from(value: i32) -> Self {
match value {
FPDF_PAGEOBJ_TEXT => ObjectType::Text,
FPDF_PAGEOBJ_PATH => ObjectType::Path,
FPDF_PAGEOBJ_IMAGE => ObjectType::Image,
FPDF_PAGEOBJ_SHADING => ObjectType::Shading,
FPDF_PAGEOBJ_FORM => ObjectType::Form,
_ => ObjectType::Unsupported,
}
}
}
impl From<ObjectType> for i32 {
fn from(value: ObjectType) -> Self {
match value {
ObjectType::Text => FPDF_PAGEOBJ_TEXT,
ObjectType::Path => FPDF_PAGEOBJ_PATH,
ObjectType::Image => FPDF_PAGEOBJ_IMAGE,
ObjectType::Shading => FPDF_PAGEOBJ_SHADING,
ObjectType::Form => FPDF_PAGEOBJ_FORM,
ObjectType::Unsupported => FPDF_PAGEOBJ_UNKNOWN,
}
}
}