[librsvg/rustification] rsvg-path.h: Fully implemented in Rust now
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustification] rsvg-path.h: Fully implemented in Rust now
- Date: Tue, 8 Nov 2016 22:06:48 +0000 (UTC)
commit e6706865d712f8ec5aeb069d0483123da4dfc684
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Nov 8 15:39:18 2016 -0600
rsvg-path.h: Fully implemented in Rust now
We finish the Rustification of rsvg-path with the implementation of
rsvg_path_parser_from_str_into_builder(),
equivalent to the old rsvg_path_builder_parse_path().
Makefile.am | 1 -
rsvg-path.c | 489 -----------------------------------------------
rsvg-path.h | 5 +-
rsvg-shapes.c | 2 +-
rust/Cargo.toml | 3 +
rust/src/lib.rs | 4 +
rust/src/path_parser.rs | 28 +++-
7 files changed, 35 insertions(+), 497 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 19dcad4..17b25ba 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -32,7 +32,6 @@ librsvg_@RSVG_API_MAJOR_VERSION@_la_SOURCES = \
rsvg-io.h \
rsvg-paint-server.c \
rsvg-paint-server.h \
- rsvg-path.c \
rsvg-path.h \
rsvg-private.h \
rsvg-base-file-util.c \
diff --git a/rsvg-path.h b/rsvg-path.h
index 7166421..9857f26 100644
--- a/rsvg-path.h
+++ b/rsvg-path.h
@@ -34,6 +34,9 @@
G_BEGIN_DECLS
+/* All the following functions and types are implemented in the Rust code.
+ */
+
typedef struct _RsvgPathBuilder RsvgPathBuilder;
G_GNUC_INTERNAL
@@ -74,7 +77,7 @@ G_GNUC_INTERNAL
void rsvg_path_builder_add_to_cairo_context (RsvgPathBuilder *builder, cairo_t *cr);
G_GNUC_INTERNAL
-RsvgPathBuilder *rsvg_path_builder_parse_path (const char *path_str);
+RsvgPathBuilder *rsvg_path_parser_from_str_into_builder (const char *path_str);
G_END_DECLS
diff --git a/rsvg-shapes.c b/rsvg-shapes.c
index 94424ef..0ac27c1 100644
--- a/rsvg-shapes.c
+++ b/rsvg-shapes.c
@@ -80,7 +80,7 @@ rsvg_node_path_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * at
if ((value = rsvg_property_bag_lookup (atts, "d"))) {
if (path->builder)
rsvg_path_builder_destroy (path->builder);
- path->builder = rsvg_path_builder_parse_path (value);
+ path->builder = rsvg_path_parser_from_str_into_builder (value);
}
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index d671baa..188362a 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -12,6 +12,9 @@ git = "https://github.com/gtk-rs/cairo.git"
[dependencies.cairo-rs]
git = "https://github.com/gtk-rs/cairo.git"
+[dependencies.glib]
+git = "https://github.com/gtk-rs/glib"
+
[lib]
name = "rsvg_internals"
crate-type = ["staticlib"]
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 8b359fe..345ff55 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -13,6 +13,10 @@ pub use marker::{
rsvg_rust_render_markers,
};
+pub use path_parser::{
+ rsvg_path_parser_from_str_into_builder
+};
+
mod path_builder;
mod path_parser;
mod marker;
diff --git a/rust/src/path_parser.rs b/rust/src/path_parser.rs
index 7c154fd..7d4ab1d 100644
--- a/rust/src/path_parser.rs
+++ b/rust/src/path_parser.rs
@@ -1,12 +1,16 @@
+extern crate libc;
+extern crate glib;
+
use std::str;
use std::str::Chars;
use std::iter::Enumerate;
use path_builder::*;
+use self::glib::translate::*;
+
extern crate cairo;
pub struct PathParser<'external> {
- path_str: &'external str,
chars_enumerator: Enumerate<Chars<'external>>,
lookahead: Option <char>, /* None if we are in EOF */
current_pos: usize,
@@ -67,7 +71,6 @@ pub struct PathParser<'external> {
impl<'external> PathParser<'external> {
pub fn new (builder: &'external mut RsvgPathBuilder, path_str: &'external str) -> PathParser<'external> {
PathParser {
- path_str: path_str,
chars_enumerator: path_str.chars ().enumerate (),
lookahead: None,
current_pos: 0,
@@ -984,6 +987,21 @@ fn char_to_digit (c: char) -> i32 {
c as i32 - '0' as i32
}
+#[no_mangle]
+pub extern fn rsvg_path_parser_from_str_into_builder (path_str: *const libc::c_char) -> *mut RsvgPathBuilder
{
+ let mut builder = RsvgPathBuilder::new ();
+ let my_path_str = unsafe { &String::from_glib_none (path_str) };
+
+ {
+ let mut parser = PathParser::new (&mut builder, my_path_str);
+ parser.parse ();
+ /* FIXME: we aren't passing errors back to the caller. */
+ }
+
+ let boxed_builder = Box::new (builder);
+
+ Box::into_raw (boxed_builder)
+}
#[cfg(test)]
mod tests {
@@ -1056,11 +1074,11 @@ mod tests {
true
}
- fn print_error (parser: &PathParser) {
+ fn print_error (parser: &PathParser, path_str: &str) {
let prefix = "Error in \"";
println! ("");
- println! ("{}{}\"", prefix, &parser.path_str);
+ println! ("{}{}\"", prefix, path_str);
for _ in 0 .. (prefix.len() + parser.current_pos) {
print! (" ");
@@ -1076,7 +1094,7 @@ mod tests {
{
let mut parser = PathParser::new (&mut builder, path_str);
if !parser.parse () {
- print_error (&parser);
+ print_error (&parser, path_str);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]