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
use libc;
use std;
use std::mem;
pub mod content;
pub mod surface_type;
pub mod format;
#[allow(non_camel_case_types)]
#[repr(i32)]
pub enum SVGVersion {
SVGVersion_1_1 = 0,
SVGVersion_1_2 = 1
}
pub struct Surface {
pub opaque: *mut libc::c_void
}
impl Surface {
pub fn create_similar_image(format: format::Format, width: libc::c_int, height: libc::c_int) -> Surface {
unsafe {
let foreign_result = cairo_surface_create_similar_image(format, width, height);
return Surface { opaque: foreign_result as *mut libc::c_void };
}
}
pub fn create_for_rectangle(x: f64, y: f64, width: f64, height: f64) -> Surface {
unsafe {
let foreign_result = cairo_surface_create_for_rectangle(x, y, width, height);
return Surface { opaque: foreign_result as *mut libc::c_void };
}
}
pub fn status(&mut self) -> super::Status {
unsafe {
let foreign_result = cairo_surface_status(self.opaque);
return foreign_result;
}
}
pub fn finish(&mut self) {
unsafe {
cairo_surface_finish(self.opaque);
}
}
pub fn flush(&mut self) {
unsafe {
cairo_surface_flush(self.opaque);
}
}
pub fn get_device(&mut self) -> super::device::Device {
unsafe {
let foreign_result = cairo_surface_get_device(self.opaque);
return super::device::Device { opaque: foreign_result as *mut libc::c_void };
}
}
pub fn get_font_options(&mut self, options: &mut super::font::Options) {
unsafe {
cairo_surface_get_font_options(self.opaque, options.opaque);
}
}
pub fn get_content(&mut self) -> content::Content {
unsafe {
let foreign_result = cairo_surface_get_content(self.opaque);
return foreign_result;
}
}
pub fn mark_dirty(&mut self) {
unsafe {
cairo_surface_mark_dirty(self.opaque);
}
}
pub fn mark_dirty_rectangle(&mut self, x: f64, y: f64, width: f64, height: f64) {
unsafe {
cairo_surface_mark_dirty_rectangle(self.opaque, x, y, width, height);
}
}
pub fn set_device_offset(&mut self, x_offset: f64, y_offset: f64) {
unsafe {
cairo_surface_set_device_offset(self.opaque, x_offset, y_offset);
}
}
pub fn get_device_offset(&mut self) -> (f64, f64) {
unsafe {
let mut x_offset:f64 = mem::zeroed();
let mut y_offset:f64 = mem::zeroed();
cairo_surface_get_device_offset(self.opaque, &mut x_offset, &mut y_offset);
return (x_offset, y_offset);
}
}
pub fn set_fallback_resolution(&mut self, x_pixels_per_inch: f64, y_pixels_per_inch: f64) {
unsafe {
cairo_surface_set_fallback_resolution(self.opaque, x_pixels_per_inch, y_pixels_per_inch);
}
}
pub fn get_fallback_resolution(&mut self) -> (f64, f64) {
unsafe {
let mut x_pixels_per_inch:f64 = mem::zeroed();
let mut y_pixels_per_inch:f64 = mem::zeroed();
cairo_surface_get_fallback_resolution(self.opaque, &mut x_pixels_per_inch, &mut y_pixels_per_inch);
return (x_pixels_per_inch, y_pixels_per_inch);
}
}
pub fn get_type(&mut self) -> surface_type::SurfaceType {
unsafe {
let foreign_result = cairo_surface_get_type(self.opaque);
return foreign_result;
}
}
pub fn get_reference_count(&mut self) -> libc::c_uint {
unsafe {
let foreign_result = cairo_surface_get_reference_count(self.opaque);
return foreign_result;
}
}
pub fn copy_page(&mut self) {
unsafe {
cairo_surface_copy_page(self.opaque);
}
}
pub fn show_page(&mut self) {
unsafe {
cairo_surface_show_page(self.opaque);
}
}
pub fn create_image(format: format::Format, width: libc::c_int, height: libc::c_int) -> Surface {
unsafe {
let foreign_result = cairo_image_surface_create(format, width, height);
return Surface { opaque: foreign_result as *mut libc::c_void };
}
}
pub fn get_format(&mut self) -> format::Format {
unsafe {
let foreign_result = cairo_image_surface_get_format(self.opaque);
return foreign_result;
}
}
pub fn get_width(&mut self) -> libc::c_int {
unsafe {
let foreign_result = cairo_image_surface_get_width(self.opaque);
return foreign_result;
}
}
pub fn get_height(&mut self) -> libc::c_int {
unsafe {
let foreign_result = cairo_image_surface_get_height(self.opaque);
return foreign_result;
}
}
pub fn get_stride(&mut self) -> libc::c_int {
unsafe {
let foreign_result = cairo_image_surface_get_stride(self.opaque);
return foreign_result;
}
}
pub fn create_from_png(filename: &str) -> Surface {
use std::ffi::CString;
let cstr_filename = CString::new(filename.as_bytes()).unwrap();
unsafe {
let foreign_result = cairo_image_surface_create_from_png(cstr_filename.as_ptr());
return Surface { opaque: foreign_result as *mut libc::c_void };
}
}
pub fn write_to_png(&mut self, filename: &str) -> super::Status {
use std::ffi::CString;
let cstr_filename = CString::new(filename.as_bytes()).unwrap();
unsafe {
let foreign_result = cairo_surface_write_to_png(self.opaque, cstr_filename.as_ptr());
return foreign_result;
}
}
pub fn create_svg(&mut self, filename: &str, width: f64, height: f64) {
use std::ffi::CString;
let cstr_filename = CString::new(filename.as_bytes()).unwrap();
unsafe {
cairo_svg_surface_create(self.opaque, cstr_filename.as_ptr(), width, height);
}
}
pub fn restrict_to_svg_version(&mut self, version: SVGVersion) {
unsafe {
cairo_svg_surface_restrict_to_version(self.opaque, version);
}
}
pub fn svg_version_to_string(version: SVGVersion) -> std::string::String {
unsafe {
let foreign_result = cairo_svg_version_to_string(version);
return std::string::String::from_utf8_lossy(std::ffi::CStr::from_ptr(foreign_result).to_bytes()).into_owned()
}
}
}
extern {
fn cairo_surface_create_similar_image(format: format::Format, width: libc::c_int, height: libc::c_int) -> *mut libc::c_void;
fn cairo_surface_create_for_rectangle(x: f64, y: f64, width: f64, height: f64) -> *mut libc::c_void;
fn cairo_surface_status(self_arg: *mut libc::c_void) -> super::Status;
fn cairo_surface_finish(self_arg: *mut libc::c_void);
fn cairo_surface_flush(self_arg: *mut libc::c_void);
fn cairo_surface_get_device(self_arg: *mut libc::c_void) -> *mut libc::c_void;
fn cairo_surface_get_font_options(self_arg: *mut libc::c_void, options: *mut libc::c_void);
fn cairo_surface_get_content(self_arg: *mut libc::c_void) -> content::Content;
fn cairo_surface_mark_dirty(self_arg: *mut libc::c_void);
fn cairo_surface_mark_dirty_rectangle(self_arg: *mut libc::c_void, x: f64, y: f64, width: f64, height: f64);
fn cairo_surface_set_device_offset(self_arg: *mut libc::c_void, x_offset: f64, y_offset: f64);
fn cairo_surface_get_device_offset(self_arg: *mut libc::c_void, x_offset: *mut f64, y_offset: *mut f64);
fn cairo_surface_set_fallback_resolution(self_arg: *mut libc::c_void, x_pixels_per_inch: f64, y_pixels_per_inch: f64);
fn cairo_surface_get_fallback_resolution(self_arg: *mut libc::c_void, x_pixels_per_inch: *mut f64, y_pixels_per_inch: *mut f64);
fn cairo_surface_get_type(self_arg: *mut libc::c_void) -> surface_type::SurfaceType;
fn cairo_surface_get_reference_count(self_arg: *mut libc::c_void) -> libc::c_uint;
fn cairo_surface_copy_page(self_arg: *mut libc::c_void);
fn cairo_surface_show_page(self_arg: *mut libc::c_void);
fn cairo_image_surface_create(format: format::Format, width: libc::c_int, height: libc::c_int) -> *mut libc::c_void;
fn cairo_image_surface_get_format(self_arg: *mut libc::c_void) -> format::Format;
fn cairo_image_surface_get_width(self_arg: *mut libc::c_void) -> libc::c_int;
fn cairo_image_surface_get_height(self_arg: *mut libc::c_void) -> libc::c_int;
fn cairo_image_surface_get_stride(self_arg: *mut libc::c_void) -> libc::c_int;
fn cairo_image_surface_create_from_png(filename: *const libc::c_char) -> *mut libc::c_void;
fn cairo_surface_write_to_png(self_arg: *mut libc::c_void, filename: *const libc::c_char) -> super::Status;
fn cairo_svg_surface_create(self_arg: *mut libc::c_void, filename: *const libc::c_char, width: f64, height: f64);
fn cairo_svg_surface_restrict_to_version(self_arg: *mut libc::c_void, version: SVGVersion);
fn cairo_svg_version_to_string(version: SVGVersion) -> *const libc::c_char;
}
impl std::clone::Clone for Surface {
fn clone(&self) -> Surface {
unsafe {
let foreign_result = cairo_surface_reference(self.opaque);
return Surface { opaque: foreign_result as *mut libc::c_void };
}
}
}
extern {
fn cairo_surface_reference(self_arg: *mut libc::c_void) -> *mut libc::c_void;
}
impl std::ops::Drop for Surface {
fn drop(&mut self) {
unsafe {
cairo_surface_destroy(self.opaque);
}
}
}
extern {
fn cairo_surface_destroy(self_arg: *mut libc::c_void);
}