rsvg-shapes.c is gone now; all the basic shapes are in shapes.rs now

parent 6cfbc00b
......@@ -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 \
......
......@@ -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, */
......
......@@ -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>
......
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set sw=4 sts=4 ts=4 expandtab: */
/*
rsvg-shapes.c: Draw SVG shapes
Copyright (C) 2000 Eazel, Inc.
Copyright (C) 2002 Dom Lachowicz <cinamod@hotmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Raph Levien <raph@artofcode.com>,
Dom Lachowicz <cinamod@hotmail.com>,
Caleb Moore <c.moore@student.unsw.edu.au>
*/
#include <string.h>
#include <math.h>
#include <errno.h>
#include <stdio.h>
#include "rsvg-private.h"
#include "rsvg-styles.h"
#include "rsvg-shapes.h"
#include "rsvg-css.h"
#include "rsvg-defs.h"
#include "rsvg-path-builder.h"
#include "rsvg-marker.h"
typedef struct _RsvgNodePoly RsvgNodePoly;
struct _RsvgNodePoly {
RsvgPathBuilder *builder;
};
static RsvgPathBuilder *
rsvg_node_poly_create_builder (const char *value,
gboolean close_path);
static void
rsvg_node_poly_set_atts (RsvgNode *node, gpointer impl, RsvgHandle *handle, RsvgPropertyBag *atts)
{
RsvgNodePoly *poly = impl;
const char *value;
/* support for svg < 1.0 which used verts */
if ((value = rsvg_property_bag_lookup (atts, "verts"))
|| (value = rsvg_property_bag_lookup (atts, "points"))) {
if (poly->builder)
rsvg_path_builder_destroy (poly->builder);
poly->builder = rsvg_node_poly_create_builder (value,
rsvg_node_get_type (node) == RSVG_NODE_TYPE_POLYGON);
}
}
static RsvgPathBuilder *
rsvg_node_poly_create_builder (const char *value,
gboolean close_path)
{
double *pointlist;
guint pointlist_len, i;
RsvgPathBuilder *builder;
pointlist = rsvg_css_parse_number_list (value, &pointlist_len);
if (pointlist == NULL)
return NULL;
if (pointlist_len < 2) {
g_free (pointlist);
return NULL;
}
builder = rsvg_path_builder_new ();
rsvg_path_builder_move_to (builder, pointlist[0], pointlist[1]);
for (i = 2; i < pointlist_len; i += 2) {
double x, y;
x = pointlist[i];
/* We expect points to come in coordinate pairs. But if there is a
* missing part of one pair in a corrupt SVG, we'll have an incomplete
* list. In that case, we reuse the last-known Y coordinate.
*/
if (i + 1 < pointlist_len)
y = pointlist[i + 1];
else
y = pointlist[i - 1];
rsvg_path_builder_line_to (builder, x, y);
}
if (close_path)
rsvg_path_builder_close_path (builder);
g_free (pointlist);
return builder;
}
static void
rsvg_node_poly_draw (RsvgNode *node, gpointer impl, RsvgDrawingCtx *ctx, int dominate)
{
RsvgNodePoly *poly = impl;
if (poly->builder == NULL)
return;
rsvg_state_reinherit_top (ctx, rsvg_node_get_state (node), dominate);
rsvg_render_path_builder (ctx, poly->builder);
rsvg_render_markers (ctx, poly->builder);
}
static void
rsvg_node_poly_free (gpointer impl)
{
RsvgNodePoly *poly = impl;
if (poly->builder)
rsvg_path_builder_destroy (poly->builder);
g_free (poly);
}
static RsvgNode *
rsvg_new_any_poly (RsvgNodeType type, RsvgNode *parent)
{
RsvgNodePoly *poly;
poly = g_new0 (RsvgNodePoly, 1);
poly->builder = NULL;
return rsvg_rust_cnode_new (type,
parent,
rsvg_state_new (),
poly,
rsvg_node_poly_set_atts,
rsvg_node_poly_draw,
rsvg_node_poly_free);
}
RsvgNode *
rsvg_new_polygon (const char *element_name, RsvgNode *parent)
{
return rsvg_new_any_poly (RSVG_NODE_TYPE_POLYGON, parent);
}
RsvgNode *
rsvg_new_polyline (const char *element_name, RsvgNode *parent)
{
return rsvg_new_any_poly (RSVG_NODE_TYPE_POLYLINE, parent);
}
......@@ -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
......@@ -40,6 +38,14 @@ G_BEGIN_DECLS
G_GNUC_INTERNAL
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);
......@@ -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 */
......@@ -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::{
......
......@@ -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 *****/
......@@ -488,6 +521,20 @@ pub extern fn rsvg_node_path_new (_: *const libc::c_char, raw_parent: *const Rsv
Box::new (NodePath::new ()))
}
#[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,
......
......@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment