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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#![warn(missing_docs)]
mod document;
mod page;
mod outline;
mod destination;
mod encoder;
mod error;
mod context;
pub mod prelude;
pub type Real = libharu_sys::HPDF_REAL;
#[derive(Debug, Clone)]
pub struct Color {
pub red: Real,
pub green: Real,
pub blue: Real,
}
impl Copy for Color {}
impl From<(Real, Real, Real)> for Color {
fn from(v: (Real, Real, Real)) -> Self {
Self { red: v.0, green: v.1, blue: v.2 }
}
}
#[derive(Debug, Clone)]
pub struct CmykColor {
pub cyan: Real,
pub magenta: Real,
pub yellow: Real,
pub keyplate: Real,
}
impl Copy for CmykColor {}
impl From<(Real, Real, Real, Real)> for CmykColor {
fn from(v: (Real, Real, Real, Real)) -> Self {
Self { cyan: v.0, magenta: v.1, yellow: v.2, keyplate: v.3 }
}
}
#[derive(Debug, Clone)]
pub struct Point {
pub x: Real,
pub y: Real,
}
impl Copy for Point {}
impl From<(Real, Real)> for Point {
fn from(v: (Real, Real)) -> Self {
Self { x: v.0, y: v.1 }
}
}
#[derive(Debug, Clone)]
pub struct Rect {
pub left: Real,
pub top: Real,
pub right: Real,
pub bottom: Real,
}
impl Copy for Rect {}
impl From<(Real, Real, Real, Real)> for Rect {
fn from(v: (Real, Real, Real, Real)) -> Self {
Self { left: v.0, top: v.1, right: v.2, bottom: v.3 }
}
}
pub struct Font<'a> {
font: libharu_sys::HPDF_Font,
_doc: &'a prelude::Document,
}
impl<'a> Font<'a> {
pub(crate) fn new(_doc: &'a prelude::Document, font: libharu_sys::HPDF_Font) -> Self {
Self { font, _doc }
}
#[inline]
pub(crate) fn handle(&self) -> libharu_sys::HPDF_Font {
self.font
}
pub fn name(&self) -> anyhow::Result<&str> {
unsafe {
let name = libharu_sys::HPDF_Font_GetFontName(self.handle());
let s = std::ffi::CStr::from_ptr(name).to_str()?;
Ok(s)
}
}
}