[librsvg] rsvg-shapes.c is gone now; all the basic shapes are in shapes.rs now
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] rsvg-shapes.c is gone now; all the basic shapes are in shapes.rs now
- Date: Fri, 24 Feb 2017 17:08:31 +0000 (UTC)
commit 0dc61d3b499dd4e180e4dac2685f1f21140cc35c
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Feb 24 08:37:50 2017 -0600
rsvg-shapes.c is gone now; all the basic shapes are in shapes.rs now
Makefile.am | 1 -
rsvg-base.c | 4 +-
rsvg-cairo-clip.c | 1 +
rsvg-shapes.c | 165 ---------------------------------------------------
rsvg-shapes.h | 17 +++---
rust/src/lib.rs | 2 +
rust/src/shapes.rs | 61 +++++++++++++++++--
rust/src/viewbox.rs | 2 -
8 files changed, 68 insertions(+), 185 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index facd9ca..6a243eb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -41,7 +41,6 @@ librsvg_@RSVG_API_MAJOR_VERSION@_la_SOURCES = \
rsvg-marker.h \
rsvg-mask.c \
rsvg-mask.h \
- rsvg-shapes.c \
rsvg-shapes.h \
rsvg-structure.c \
rsvg-structure.h \
diff --git a/rsvg-base.c b/rsvg-base.c
index de7155b..6fb33d3 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -315,8 +315,8 @@ static const NodeCreator node_creators[] = {
{ "multiImage", FALSE, rsvg_new_switch }, /* hack to make multiImage sort-of work */
{ "path", TRUE, rsvg_node_path_new },
{ "pattern", TRUE, rsvg_new_pattern },
- { "polygon", TRUE, rsvg_new_polygon },
- { "polyline", TRUE, rsvg_new_polyline },
+ { "polygon", TRUE, rsvg_node_polygon_new },
+ { "polyline", TRUE, rsvg_node_polyline_new },
{ "radialGradient", TRUE, rsvg_new_radial_gradient },
{ "rect", TRUE, rsvg_node_rect_new },
/* "script", FALSE, */
diff --git a/rsvg-cairo-clip.c b/rsvg-cairo-clip.c
index d4361bb..db82936 100644
--- a/rsvg-cairo-clip.c
+++ b/rsvg-cairo-clip.c
@@ -32,6 +32,7 @@
#include "rsvg-cairo-render.h"
#include "rsvg-styles.h"
#include "rsvg-path-builder.h"
+#include "rsvg-structure.h"
#include <math.h>
#include <string.h>
diff --git a/rsvg-shapes.h b/rsvg-shapes.h
index d6a0150..a52f602 100644
--- a/rsvg-shapes.h
+++ b/rsvg-shapes.h
@@ -30,9 +30,7 @@
#ifndef RSVG_SHAPES_H
#define RSVG_SHAPES_H
-#include <cairo.h>
-
-#include "rsvg-structure.h"
+#include "rsvg-private.h"
G_BEGIN_DECLS
@@ -42,6 +40,14 @@ RsvgNode *rsvg_node_path_new (const char *element_name, RsvgNode *parent);
/* Implemented in rust/src/shapes.rs */
G_GNUC_INTERNAL
+RsvgNode *rsvg_node_polygon_new (const char *element_name, RsvgNode *parent);
+
+/* Implemented in rust/src/shapes.rs */
+G_GNUC_INTERNAL
+RsvgNode *rsvg_node_polyline_new (const char *element_name, RsvgNode *parent);
+
+/* Implemented in rust/src/shapes.rs */
+G_GNUC_INTERNAL
RsvgNode *rsvg_node_line_new (const char *element_name, RsvgNode *parent);
/* Implemented in rust/src/shapes.rs */
@@ -56,11 +62,6 @@ RsvgNode *rsvg_node_circle_new (const char *element_name, RsvgNode *parent);
G_GNUC_INTERNAL
RsvgNode *rsvg_node_ellipse_new (const char *element_name, RsvgNode *parent);
-G_GNUC_INTERNAL
-RsvgNode *rsvg_new_polygon (const char *element_name, RsvgNode *parent);
-G_GNUC_INTERNAL
-RsvgNode *rsvg_new_polyline (const char *element_name, RsvgNode *parent);
-
G_END_DECLS
#endif /* RSVG_SHAPES_H */
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 487a481..34b5c7f 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -86,6 +86,8 @@ pub use shapes::{
rsvg_node_ellipse_new,
rsvg_node_line_new,
rsvg_node_path_new,
+ rsvg_node_polygon_new,
+ rsvg_node_polyline_new,
rsvg_node_rect_new,
};
pub use viewbox::{
diff --git a/rust/src/shapes.rs b/rust/src/shapes.rs
index cea37a4..1187596 100644
--- a/rust/src/shapes.rs
+++ b/rust/src/shapes.rs
@@ -9,6 +9,7 @@ use handle::RsvgHandle;
use length::*;
use marker;
use node::*;
+use parsers;
use path_builder::*;
use path_parser;
use property_bag;
@@ -107,15 +108,23 @@ impl NodeTrait for NodePath {
}
/***** NodePoly *****/
-/*
+
+#[derive(Debug, PartialEq)]
+enum PolyKind {
+ Open,
+ Closed
+}
+
struct NodePoly {
- builder: RefCell<RsvgPathBuilder>
+ points: RefCell <Option<Vec<(f64, f64)>>>,
+ kind: PolyKind
}
impl NodePoly {
- fn new () -> NodePoly {
+ fn new (kind: PolyKind) -> NodePoly {
NodePoly {
- builder: RefCell::new (RsvgPathBuilder::new ())
+ points: RefCell::new (None),
+ kind: kind
}
}
}
@@ -124,21 +133,45 @@ impl NodeTrait for NodePoly {
fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) {
// support for svg < 1.0 which used verts
if let Some (value) = property_bag::lookup (pbag, "verts").or (property_bag::lookup (pbag,
"points")) {
- let mut builder = self.builder.borrow_mut ();
+ let result = parsers::list_of_points (value.as_bytes ()).to_full_result ();
+ match result {
+ Ok (v) => {
+ *self.points.borrow_mut () = Some (v);
+ },
+ Err (_) => {
+ // FIXME: propagate errors upstream
+ *self.points.borrow_mut () = None;
+ }
+ }
}
}
fn draw (&self, node: &RsvgNode, draw_ctx: *const RsvgDrawingCtx, dominate: i32) {
- render_path_builder (&*self.builder.borrow (), draw_ctx, node.get_state (), dominate, true);
+ if let Some (ref points) = *self.points.borrow () {
+ let mut builder = RsvgPathBuilder::new ();
+
+ for (i, &(x, y)) in points.iter ().enumerate () {
+ if i == 0 {
+ builder.move_to (x, y);
+ } else {
+ builder.line_to (x, y);
+ }
+ }
+
+ if self.kind == PolyKind::Closed {
+ builder.close_path ();
+ }
+
+ render_path_builder (&builder, draw_ctx, node.get_state (), dominate, true);
+ }
}
fn get_c_impl (&self) -> *const RsvgCNodeImpl {
ptr::null ()
}
}
-*/
/***** NodeLine *****/
@@ -489,6 +522,20 @@ pub extern fn rsvg_node_path_new (_: *const libc::c_char, raw_parent: *const Rsv
}
#[no_mangle]
+pub extern fn rsvg_node_polygon_new (_: *const libc::c_char, raw_parent: *const RsvgNode) -> *const RsvgNode
{
+ boxed_node_new (NodeType::Path,
+ raw_parent,
+ Box::new (NodePoly::new (PolyKind::Closed)))
+}
+
+#[no_mangle]
+pub extern fn rsvg_node_polyline_new (_: *const libc::c_char, raw_parent: *const RsvgNode) -> *const
RsvgNode {
+ boxed_node_new (NodeType::Path,
+ raw_parent,
+ Box::new (NodePoly::new (PolyKind::Open)))
+}
+
+#[no_mangle]
pub extern fn rsvg_node_line_new (_: *const libc::c_char, raw_parent: *const RsvgNode) -> *const RsvgNode {
boxed_node_new (NodeType::Line,
raw_parent,
diff --git a/rust/src/viewbox.rs b/rust/src/viewbox.rs
index e878bdb..fdef9c5 100644
--- a/rust/src/viewbox.rs
+++ b/rust/src/viewbox.rs
@@ -3,8 +3,6 @@ extern crate cairo;
use std::fmt;
use std::str::FromStr;
-use nom::{IResult};
-
use parsers;
/* Keep this in sync with rsvg-private.h:RsvgViewBox */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]