aoer_plotty_rs/context/
glyph_proxy.rs1pub use kurbo::BezPath;
2pub use kurbo::Point as BezPoint;
3use font_kit::outline::OutlineSink;
4use pathfinder_geometry::line_segment::LineSegment2F;
5use pathfinder_geometry::vector::Vector2F;
6
7
8pub struct GlyphProxy{
9 path: BezPath,
10 last_pos: Vector2F,
11 close: bool
12}
13
14impl GlyphProxy{
15
16 pub fn new(close: bool) -> GlyphProxy{
17 GlyphProxy { path: BezPath::new() , last_pos: Vector2F::zero(), close: close}
18 }
19
20 pub fn path(&self) -> BezPath{
21 self.path.clone()
23 }
24
25}
26
27impl OutlineSink for GlyphProxy{
28 fn move_to(&mut self, to: Vector2F) {
29 self.path.move_to(BezPoint::new(f64::from(to.x()), f64::from(to.y())));
31 self.last_pos = to.clone()
32 }
33
34 fn line_to(&mut self, to: Vector2F) {
35 self.path.line_to(BezPoint::new(f64::from(to.x()), f64::from(to.y())));
37 }
38
39 fn quadratic_curve_to(&mut self, ctrl: Vector2F, to: Vector2F) {
40 self.path.quad_to(
42 BezPoint::new(f64::from(ctrl.x()), f64::from(ctrl.y())),
43 BezPoint::new(f64::from(to.x()), f64::from(to.y()))
44 );
45 }
46
47 fn cubic_curve_to(&mut self, ctrl: LineSegment2F, to: Vector2F) {
48 self.path.curve_to(
50 BezPoint::new(f64::from(ctrl.from().x()), f64::from(ctrl.from().y())),
51 BezPoint::new(f64::from(ctrl.to().x()), f64::from(ctrl.to().y())),
52 BezPoint::new(f64::from(to.x()), f64::from(to.y()))
53 );
54 }
55
56 fn close(&mut self) {
57 if ! self.close{
59 self.move_to(self.last_pos.clone());
60 }else{
61 self.line_to(self.last_pos.clone());
62 }
63
64 self.path.close_path();
65 }
66
67
68}