[librsvg/rustification] path_builder.rs: Start porting RsvgPathBuilder
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustification] path_builder.rs: Start porting RsvgPathBuilder
- Date: Wed, 2 Nov 2016 01:31:53 +0000 (UTC)
commit e354165200256446aef64c56e892c831806afe6b
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Oct 31 21:59:54 2016 -0600
path_builder.rs: Start porting RsvgPathBuilder
We'll keep the entire C API of that function for now, as it
is used from rsvg-shapes.c.
rust/src/lib.rs | 10 +++++
rust/src/path_builder.rs | 100 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 110 insertions(+), 0 deletions(-)
---
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 963ad74..5dc77a9 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -1,5 +1,15 @@
+pub use path_builder::{
+ rsvg_path_builder_new,
+ rsvg_path_builder_destroy,
+ rsvg_path_builder_move_to,
+ rsvg_path_builder_line_to,
+ rsvg_path_builder_curve_to,
+ rsvg_path_builder_close_path
+};
+
pub use marker::{
rsvg_rust_render_markers,
};
+mod path_builder;
mod marker;
diff --git a/rust/src/path_builder.rs b/rust/src/path_builder.rs
new file mode 100644
index 0000000..7cebce5
--- /dev/null
+++ b/rust/src/path_builder.rs
@@ -0,0 +1,100 @@
+extern crate cairo;
+
+#[repr(C)]
+pub struct RsvgPathBuilder {
+ path_data: Vec<cairo::PathSegment>,
+ last_move_to_index: Option<usize>
+}
+
+impl RsvgPathBuilder {
+ fn move_to (&mut self, x: f64, y: f64) {
+ self.path_data.push (cairo::PathSegment::MoveTo ((x, y)));
+ self.last_move_to_index = Some (self.path_data.len () - 1);
+ }
+
+ fn line_to (&mut self, x: f64, y: f64) {
+ self.path_data.push (cairo::PathSegment::LineTo ((x, y)));
+ }
+
+ fn curve_to (&mut self, x2: f64, y2: f64, x3: f64, y3: f64, x4: f64, y4: f64) {
+ self.path_data.push (cairo::PathSegment::CurveTo ((x2, y2), (x3, y3), (x4, y4)));
+ }
+
+ fn close_path (&mut self) {
+ if let Some (idx) = self.last_move_to_index {
+ let segment = self.path_data[idx];
+
+ if let cairo::PathSegment::MoveTo ((x, y)) = segment {
+ self.move_to (x, y);
+ } else {
+ unreachable! ();
+ }
+ }
+ }
+}
+
+#[no_mangle]
+pub unsafe extern fn rsvg_path_builder_new () -> *mut RsvgPathBuilder {
+ let builder = RsvgPathBuilder {
+ path_data: Vec::new (),
+ last_move_to_index: None
+ };
+
+ let boxed_builder = Box::new (builder);
+
+ Box::into_raw (boxed_builder)
+}
+
+#[no_mangle]
+pub unsafe extern fn rsvg_path_builder_destroy (raw_builder: *mut RsvgPathBuilder) {
+ assert! (!raw_builder.is_null ());
+
+ let _ = Box::from_raw (raw_builder);
+}
+
+#[no_mangle]
+pub extern fn rsvg_path_builder_move_to (raw_builder: *mut RsvgPathBuilder,
+ x: f64,
+ y: f64) {
+ assert! (!raw_builder.is_null ());
+
+ let builder: &mut RsvgPathBuilder;
+ unsafe { builder = &mut (*raw_builder); }
+
+ builder.move_to (x, y);
+}
+
+#[no_mangle]
+pub extern fn rsvg_path_builder_line_to (raw_builder: *mut RsvgPathBuilder,
+ x: f64,
+ y: f64) {
+ assert! (!raw_builder.is_null ());
+
+ let builder: &mut RsvgPathBuilder;
+ unsafe { builder = &mut (*raw_builder); }
+
+ builder.line_to (x, y);
+}
+
+#[no_mangle]
+pub extern fn rsvg_path_builder_curve_to (raw_builder: *mut RsvgPathBuilder,
+ x2: f64, y2: f64,
+ x3: f64, y3: f64,
+ x4: f64, y4: f64) {
+ assert! (!raw_builder.is_null ());
+
+ let builder: &mut RsvgPathBuilder;
+ unsafe { builder = &mut (*raw_builder); }
+
+ builder.curve_to (x2, y2, x3, y3, x4, y4);
+}
+
+#[no_mangle]
+pub extern fn rsvg_path_builder_close_path (raw_builder: *mut RsvgPathBuilder) {
+ assert! (!raw_builder.is_null ());
+
+ let builder: &mut RsvgPathBuilder;
+ unsafe { builder = &mut (*raw_builder); }
+
+ builder.close_path ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]