1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use crate::bindgen::{
FPDF_PATHSEGMENT, FPDF_SEGMENT_BEZIERTO, FPDF_SEGMENT_LINETO, FPDF_SEGMENT_MOVETO,
FPDF_SEGMENT_UNKNOWN,
};
use crate::bindings::PdfiumLibraryBindings;
use crate::error::PdfiumError;
use crate::page::PdfPoints;
use std::os::raw::c_float;
#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)]
pub enum PdfPathSegmentType {
Unknown = FPDF_SEGMENT_UNKNOWN as isize,
LineTo = FPDF_SEGMENT_LINETO as isize,
BezierTo = FPDF_SEGMENT_BEZIERTO as isize,
MoveTo = FPDF_SEGMENT_MOVETO as isize,
}
impl PdfPathSegmentType {
#[inline]
pub(crate) fn from_pdfium(segment_type: i32) -> Result<PdfPathSegmentType, PdfiumError> {
if segment_type == FPDF_SEGMENT_UNKNOWN {
return Ok(PdfPathSegmentType::Unknown);
}
match segment_type as u32 {
FPDF_SEGMENT_LINETO => Ok(PdfPathSegmentType::LineTo),
FPDF_SEGMENT_BEZIERTO => Ok(PdfPathSegmentType::BezierTo),
FPDF_SEGMENT_MOVETO => Ok(PdfPathSegmentType::MoveTo),
_ => Err(PdfiumError::UnknownPathSegmentType),
}
}
}
pub struct PdfPathSegment<'a> {
handle: FPDF_PATHSEGMENT,
bindings: &'a dyn PdfiumLibraryBindings,
}
impl<'a> PdfPathSegment<'a> {
#[inline]
pub(crate) fn from_pdfium(
handle: FPDF_PATHSEGMENT,
bindings: &'a dyn PdfiumLibraryBindings,
) -> Self {
Self { handle, bindings }
}
#[inline]
pub fn bindings(&self) -> &'a dyn PdfiumLibraryBindings {
self.bindings
}
#[inline]
pub fn segment_type(&self) -> PdfPathSegmentType {
PdfPathSegmentType::from_pdfium(self.bindings().FPDFPathSegment_GetType(self.handle))
.unwrap_or(PdfPathSegmentType::Unknown)
}
#[inline]
pub fn is_close(&self) -> bool {
self.bindings()
.is_true(self.bindings().FPDFPathSegment_GetClose(self.handle))
}
pub fn point(&self) -> (PdfPoints, PdfPoints) {
let mut x: c_float = 0.0;
let mut y: c_float = 0.0;
if self
.bindings()
.is_true(
self.bindings()
.FPDFPathSegment_GetPoint(self.handle, &mut x, &mut y),
)
{
(PdfPoints::new(x as f32), PdfPoints::new(y as f32))
} else {
(PdfPoints::ZERO, PdfPoints::ZERO)
}
}
#[inline]
pub fn x(&self) -> PdfPoints {
self.point().0
}
#[inline]
pub fn y(&self) -> PdfPoints {
self.point().1
}
}