-
Notifications
You must be signed in to change notification settings - Fork 0
/
spiro_to_beziers.rs
57 lines (52 loc) · 1.71 KB
/
spiro_to_beziers.rs
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
use spiro_sys::{self, bezctx};
use std::os::raw::c_int;
macro_rules! spiro_cp {
({$x:literal, $y:literal, $ty:literal}) => {
spiro_sys::spiro_cp {
x: $x as f64,
y: $y as f64,
ty: $ty as i8
}
}
}
unsafe extern "C" fn println_moveto(_bc: *mut bezctx, x: f64, y: f64, _is_open: c_int) {
println!("M {}, {} ", x, y);
}
unsafe extern "C" fn println_lineto(_bc: *mut bezctx, x: f64, y: f64) {
println!("L {}, {} ", x, y);
}
unsafe extern "C" fn println_quadto(_bc: *mut bezctx, x1: f64, y1: f64, x2: f64, y2: f64) {
println!("Q {}, {}, {}, {} ", x1, y1, x2, y2);
}
unsafe extern "C" fn println_curveto(_bc: *mut bezctx, x1: f64, y1: f64, x2: f64, y2: f64, x3: f64, y3: f64) {
println!("C {}, {}, {}, {}, {}, {} ", x1, y1, x2, y2, x3, y3);
}
#[test]
fn spiro_to_beziers() {
// Path from
// https://github.com/fontforge/libspiro/blob/84ce4dfd24f0e3ee83589bbfb02723dff5c03414/tests/call-test.c#L278
let mut path5 = vec![
spiro_cp!({ 0, 0, '{'}),
spiro_cp!({100, 100, 'c'}),
spiro_cp!({200, 200, '['}),
spiro_cp!({300, 200, ']'}),
spiro_cp!({400, 150, 'c'}),
spiro_cp!({300, 100, '['}),
spiro_cp!({200, 100, ']'}),
spiro_cp!({150, 50, 'c'}),
spiro_cp!({100, 0, '['}),
spiro_cp!({ 0,-100, ']'}),
spiro_cp!({-50,-200, 'c'}),
spiro_cp!({-80,-250, '}'}),
];
let mut ctx = bezctx {
moveto: Some(println_moveto),
lineto: Some(println_lineto),
quadto: Some(println_quadto),
curveto: Some(println_curveto),
mark_knot: None
};
unsafe {
spiro_sys::TaggedSpiroCPsToBezier(path5.as_mut_ptr(), &mut ctx);
}
}