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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#![cfg_attr(feature = "dox", feature(doc_cfg))]
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::wrong_self_convention)]
#![allow(clippy::non_send_fields_in_send_ty)]
#![doc = include_str!("../README.md")]
pub use ffi;
#[cfg(feature = "freetype")]
pub use freetype_crate as freetype;
#[cfg(feature = "use_glib")]
pub use glib;
#[cfg(feature = "use_glib")]
macro_rules! gvalue_impl_inner {
($name:ty, $ffi_name:ty, $get_type:expr) => {
#[allow(unused_imports)]
use glib::translate::*;
impl glib::types::StaticType for $name {
fn static_type() -> glib::types::Type {
unsafe { from_glib($get_type()) }
}
}
impl glib::value::ValueType for $name {
type Type = Self;
}
impl glib::value::ValueTypeOptional for $name {}
};
}
#[cfg(feature = "use_glib")]
macro_rules! gvalue_impl {
($name:ty, $ffi_name:ty, $get_type:expr) => {
gvalue_impl_inner!($name, $ffi_name, $get_type);
unsafe impl<'a> glib::value::FromValue<'a> for $name {
type Checker = glib::value::GenericValueTypeOrNoneChecker<Self>;
unsafe fn from_value(value: &'a glib::Value) -> Self {
let ptr = glib::gobject_ffi::g_value_dup_boxed(
glib::translate::ToGlibPtr::to_glib_none(value).0,
);
assert!(!ptr.is_null());
<$name as glib::translate::FromGlibPtrFull<*mut $ffi_name>>::from_glib_full(
ptr as *mut $ffi_name,
)
}
}
unsafe impl<'a> glib::value::FromValue<'a> for &'a $name {
type Checker = glib::value::GenericValueTypeOrNoneChecker<Self>;
unsafe fn from_value(value: &'a glib::Value) -> Self {
assert_eq!(
std::mem::size_of::<Self>(),
std::mem::size_of::<glib::ffi::gpointer>()
);
let value = &*(value as *const glib::Value as *const glib::gobject_ffi::GValue);
let ptr = &value.data[0].v_pointer as *const glib::ffi::gpointer
as *const *const $ffi_name;
assert!(!(*ptr).is_null());
&*(ptr as *const $name)
}
}
impl glib::value::ToValue for $name {
fn to_value(&self) -> glib::Value {
unsafe {
let mut value =
glib::Value::from_type(<$name as glib::StaticType>::static_type());
glib::gobject_ffi::g_value_take_boxed(
value.to_glib_none_mut().0,
self.to_glib_full() as *mut _,
);
value
}
}
fn value_type(&self) -> glib::Type {
<$name as glib::StaticType>::static_type()
}
}
impl glib::value::ToValueOptional for $name {
fn to_value_optional(s: Option<&Self>) -> glib::Value {
let mut value = glib::Value::for_value_type::<Self>();
unsafe {
glib::gobject_ffi::g_value_take_boxed(
value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::to_glib_full(&s) as *mut _,
);
}
value
}
}
};
}
#[cfg(feature = "use_glib")]
macro_rules! gvalue_impl_inline {
($name:ty, $ffi_name:ty, $get_type:expr) => {
gvalue_impl_inner!($name, $ffi_name, $get_type);
unsafe impl<'a> glib::value::FromValue<'a> for $name {
type Checker = glib::value::GenericValueTypeOrNoneChecker<Self>;
unsafe fn from_value(value: &'a glib::Value) -> Self {
let ptr = glib::gobject_ffi::g_value_get_boxed(
glib::translate::ToGlibPtr::to_glib_none(value).0,
);
assert!(!ptr.is_null());
<$name as glib::translate::FromGlibPtrNone<*mut $ffi_name>>::from_glib_none(
ptr as *mut $ffi_name,
)
}
}
unsafe impl<'a> glib::value::FromValue<'a> for &'a $name {
type Checker = glib::value::GenericValueTypeOrNoneChecker<Self>;
unsafe fn from_value(value: &'a glib::Value) -> Self {
let ptr = glib::gobject_ffi::g_value_get_boxed(
glib::translate::ToGlibPtr::to_glib_none(value).0,
);
assert!(!ptr.is_null());
&*(ptr as *mut $name)
}
}
impl glib::value::ToValue for $name {
fn to_value(&self) -> glib::Value {
unsafe {
let mut value =
glib::Value::from_type(<$name as glib::StaticType>::static_type());
glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0,
self.to_glib_none().0 as *mut _,
);
value
}
}
fn value_type(&self) -> glib::Type {
<$name as glib::StaticType>::static_type()
}
}
impl glib::value::ToValueOptional for $name {
fn to_value_optional(s: Option<&Self>) -> glib::Value {
let mut value = glib::Value::for_value_type::<Self>();
unsafe {
glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0,
s.to_glib_none().0 as *mut _,
);
}
value
}
}
};
}
pub use crate::user_data::UserDataKey;
pub use crate::context::{Context, RectangleList};
pub use crate::paths::{Path, PathSegment, PathSegments};
pub use crate::device::Device;
pub use crate::enums::*;
pub use crate::error::{BorrowError, Error, IoError, Result};
pub use crate::patterns::{
Gradient, LinearGradient, Mesh, Pattern, RadialGradient, SolidPattern, SurfacePattern,
};
pub use crate::font::{
FontExtents, FontFace, FontOptions, FontSlant, FontType, FontWeight, Glyph, ScaledFont,
TextCluster, TextExtents,
};
pub use crate::matrices::Matrix;
pub use crate::recording_surface::RecordingSurface;
pub use crate::rectangle::Rectangle;
pub use crate::rectangle_int::RectangleInt;
pub use crate::region::Region;
pub use crate::surface::{MappedImageSurface, Surface};
pub use crate::image_surface::{ImageSurface, ImageSurfaceData, ImageSurfaceDataOwned};
#[cfg(any(feature = "pdf", feature = "svg", feature = "ps", feature = "dox"))]
pub use stream::StreamWithError;
#[cfg(any(feature = "pdf", feature = "dox"))]
pub use pdf::PdfSurface;
#[cfg(any(feature = "ps", feature = "dox"))]
pub use ps::PsSurface;
#[cfg(any(feature = "svg", feature = "dox"))]
pub use svg::SvgSurface;
#[cfg(any(feature = "xcb", feature = "dox"))]
pub use xcb::{
XCBConnection, XCBDrawable, XCBPixmap, XCBRenderPictFormInfo, XCBScreen, XCBSurface,
XCBVisualType,
};
#[macro_use]
mod surface_macros;
#[macro_use]
mod user_data;
mod constants;
pub use crate::constants::*;
mod utils;
pub use crate::utils::{debug_reset_static_data, version_string, Version};
mod context;
mod device;
mod enums;
mod error;
mod font;
mod image_surface;
#[cfg(any(feature = "png", feature = "dox"))]
mod image_surface_png;
mod matrices;
mod paths;
mod patterns;
mod recording_surface;
mod rectangle;
mod rectangle_int;
mod region;
mod surface;
#[cfg(any(feature = "xcb", feature = "dox"))]
mod xcb;
#[cfg(any(feature = "pdf", feature = "svg", feature = "ps", feature = "dox"))]
#[macro_use]
mod stream;
#[cfg(any(feature = "pdf", feature = "dox"))]
mod pdf;
#[cfg(any(feature = "ps", feature = "dox"))]
mod ps;
#[cfg(any(feature = "svg", feature = "dox"))]
mod svg;
#[cfg(any(target_os = "macos", feature = "dox"))]
mod quartz_surface;
#[cfg(any(target_os = "macos", feature = "dox"))]
pub use quartz_surface::QuartzSurface;
#[cfg(any(all(windows, feature = "win32-surface"), feature = "dox"))]
mod win32_surface;
#[cfg(any(all(windows, feature = "win32-surface"), feature = "dox"))]
pub use win32_surface::Win32Surface;
#[cfg(not(feature = "use_glib"))]
mod borrowed {
use std::mem;
#[derive(Debug)]
pub struct Borrowed<T>(mem::ManuallyDrop<T>);
impl<T> Borrowed<T> {
pub fn new(val: T) -> Self {
Self(mem::ManuallyDrop::new(val))
}
pub unsafe fn into_inner(self) -> T {
mem::ManuallyDrop::into_inner(self.0)
}
}
impl<T> AsRef<T> for Borrowed<T> {
fn as_ref(&self) -> &T {
&*self.0
}
}
impl<T> std::ops::Deref for Borrowed<T> {
type Target = T;
fn deref(&self) -> &T {
&*self.0
}
}
}
#[cfg(not(feature = "use_glib"))]
pub use borrowed::Borrowed;
#[cfg(feature = "use_glib")]
pub(crate) use glib::translate::Borrowed;