[lasem] <svg:marker> Start implementation.



commit f18a338116d2b86c145a598c749257ae0dbc1144
Author: Emmanuel Pacaud <emmanuel pacaud lapp in2p3 fr>
Date:   Sat Aug 8 07:04:05 2009 +0200

    <svg:marker> Start implementation.

 src/Makefile.am           |    2 +
 src/lsmsvg.h              |    1 +
 src/lsmsvgattributes.h    |   10 ++++
 src/lsmsvgdocument.c      |    3 +
 src/lsmsvgenums.c         |   20 +++++++-
 src/lsmsvgenums.h         |   13 +++++
 src/lsmsvgmarkerelement.c |  128 +++++++++++++++++++++++++++++++++++++++++++++
 src/lsmsvgmarkerelement.h |   60 +++++++++++++++++++++
 src/lsmsvgtraits.c        |   52 ++++++++++++++++++
 src/lsmsvgtraits.h        |    7 +++
 10 files changed, 295 insertions(+), 1 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0d989f6..c54a255 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -79,6 +79,7 @@ liblasem_la_SOURCES =				\
 	lsmsvguseelement.c			\
 	lsmsvgimageelement.c			\
 	lsmsvgsymbolelement.c			\
+	lsmsvgmarkerelement.c			\
 	lsmsvggelement.c			\
 	lsmsvgdefselement.c			\
 	lsmsvgrectelement.c			\
@@ -167,6 +168,7 @@ liblasem_la_HEADERS = \
 	lsmsvguseelement.h			\
 	lsmsvgimageelement.h			\
 	lsmsvgsymbolelement.h			\
+	lsmsvgmarkerelement.h			\
 	lsmsvgrectelement.h			\
 	lsmsvgcircleelement.h			\
 	lsmsvgellipseelement.h			\
diff --git a/src/lsmsvg.h b/src/lsmsvg.h
index 43bc421..5510f5c 100644
--- a/src/lsmsvg.h
+++ b/src/lsmsvg.h
@@ -36,6 +36,7 @@ typedef struct _LsmSvgDefsElement LsmSvgDefsElement;
 typedef struct _LsmSvgUseElement LsmSvgUseElement;
 typedef struct _LsmSvgImageElement LsmSvgImageElement;
 typedef struct _LsmSvgSymbolElement LsmSvgSymbolElement;
+typedef struct _LsmSvgMarkerElement LsmSvgMarkerElement;
 typedef struct _LsmSvgRectElement LsmSvgRectElement;
 typedef struct _LsmSvgCircleElement LsmSvgCircleElement;
 typedef struct _LsmSvgEllipseElement LsmSvgEllipseElement;
diff --git a/src/lsmsvgattributes.h b/src/lsmsvgattributes.h
index 806ac81..7b0727f 100644
--- a/src/lsmsvgattributes.h
+++ b/src/lsmsvgattributes.h
@@ -88,6 +88,16 @@ typedef struct {
 	LsmSvgPatternUnits value;
 } LsmSvgPatternUnitsAttribute;
 
+typedef struct {
+	LsmAttribute base;
+	LsmSvgMarkerUnits value;
+} LsmSvgMarkerUnitsAttribute;
+
+typedef struct {
+	LsmAttribute base;
+	LsmSvgAngle value;
+} LsmSvgAngleAttribute;
+
 G_END_DECLS
 
 #endif
diff --git a/src/lsmsvgdocument.c b/src/lsmsvgdocument.c
index 3c41c33..9adbf61 100644
--- a/src/lsmsvgdocument.c
+++ b/src/lsmsvgdocument.c
@@ -28,6 +28,7 @@
 #include <lsmsvguseelement.h>
 #include <lsmsvgimageelement.h>
 #include <lsmsvgsymbolelement.h>
+#include <lsmsvgmarkerelement.h>
 #include <lsmsvgrectelement.h>
 #include <lsmsvgcircleelement.h>
 #include <lsmsvgellipseelement.h>
@@ -97,6 +98,8 @@ lsm_svg_document_create_element (LsmDomDocument *document, const char *tag_name)
 		node = lsm_svg_defs_element_new ();
 	else if (strcmp (tag_name, "symbol") == 0)
 		node = lsm_svg_symbol_element_new ();
+	else if (strcmp (tag_name, "marker") == 0)
+		node = lsm_svg_marker_element_new ();
 	else if (strcmp (tag_name, "clipPath") == 0)
 		node = lsm_svg_clip_path_element_new ();
 
diff --git a/src/lsmsvgenums.c b/src/lsmsvgenums.c
index ce02e1d..f0c59cb 100644
--- a/src/lsmsvgenums.c
+++ b/src/lsmsvgenums.c
@@ -121,7 +121,7 @@ lsm_svg_line_cap_from_string (const char *string)
 }
 
 static const char *lsm_svg_pattern_units_strings[] = {
-	"userSpaseOnUse",
+	"userSpaceOnUse",
 	"objectBoundingBox"
 };
 
@@ -138,6 +138,24 @@ lsm_svg_pattern_units_from_string (const char *string)
 					  G_N_ELEMENTS (lsm_svg_pattern_units_strings));
 }
 
+static const char *lsm_svg_marker_units_strings[] = {
+	"userSpaceOnUse",
+	"strokeWidth"
+};
+
+const char *
+lsm_svg_marker_units_to_string (LsmSvgMarkerUnits units)
+{
+	return lsm_svg_marker_units_strings[CLAMP (units, 0, LSM_SVG_MARKER_UNITS_STROKE_WIDTH)];
+}
+
+LsmSvgMarkerUnits
+lsm_svg_marker_units_from_string (const char *string)
+{
+	return lsm_svg_value_from_string (string, lsm_svg_marker_units_strings,
+					  G_N_ELEMENTS (lsm_svg_marker_units_strings));
+}
+
 static const char *lsm_svg_spread_method_strings[] = {
 	"pad",
 	"reflect",
diff --git a/src/lsmsvgenums.h b/src/lsmsvgenums.h
index dd1e0cf..98b3e10 100644
--- a/src/lsmsvgenums.h
+++ b/src/lsmsvgenums.h
@@ -27,6 +27,11 @@
 G_BEGIN_DECLS
 
 typedef enum {
+	LSM_SVG_ANGLE_TYPE_AUTO,
+	LSM_SVG_ANGLE_TYPE_FIXED
+} LsmSvgAngleType;
+
+typedef enum {
 	LSM_SVG_PAINT_TYPE_UNKNOWN = 0,
 	LSM_SVG_PAINT_TYPE_RGB_COLOR,
 	LSM_SVG_PAINT_TYPE_RGB_COLOR_ICC_COLOR,
@@ -107,6 +112,14 @@ const char * 		lsm_svg_pattern_units_to_string 		(LsmSvgPatternUnits units);
 LsmSvgPatternUnits	lsm_svg_pattern_units_from_string		(const char *string);
 
 typedef enum {
+	LSM_SVG_MARKER_UNITS_USER_SPACE_ON_USE,
+	LSM_SVG_MARKER_UNITS_STROKE_WIDTH
+} LsmSvgMarkerUnits;
+
+const char * 		lsm_svg_marker_units_to_string 			(LsmSvgMarkerUnits units);
+LsmSvgMarkerUnits	lsm_svg_marker_units_from_string		(const char *string);
+
+typedef enum {
 	LSM_SVG_SPREAD_METHOD_PAD,
 	LSM_SVG_SPREAD_METHOD_REFLECT,
 	LSM_SVG_SPREAD_METHOD_REPEAT
diff --git a/src/lsmsvgmarkerelement.c b/src/lsmsvgmarkerelement.c
new file mode 100644
index 0000000..f373d23
--- /dev/null
+++ b/src/lsmsvgmarkerelement.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright © 2009 Emmanuel Pacaud
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ * 	Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#include <lsmsvgmarkerelement.h>
+#include <lsmsvgview.h>
+#include <lsmdebug.h>
+#include <lsmdomdocument.h>
+#include <stdio.h>
+
+static GObjectClass *parent_class;
+
+/* GdomNode implementation */
+
+static const char *
+lsm_svg_marker_element_get_node_name (LsmDomNode *node)
+{
+	return "marker";
+}
+
+/* LsmSvgElement implementation */
+
+/* LsmSvgGraphic implementation */
+
+static void
+lsm_svg_marker_element_render (LsmSvgElement *self, LsmSvgView *view)
+{
+}
+
+/* LsmSvgMarkerElement implementation */
+
+LsmDomNode *
+lsm_svg_marker_element_new (void)
+{
+	return g_object_new (LSM_TYPE_SVG_MARKER_ELEMENT, NULL);
+}
+
+static const LsmSvgMarkerUnits units_default =   LSM_SVG_MARKER_UNITS_STROKE_WIDTH;
+static const LsmSvgLength length_default = 	 { .value_unit =   0.0, .type = LSM_SVG_LENGTH_TYPE_NUMBER};
+static const LsmSvgLength width_default = 	 { .value_unit =   3.0, .type = LSM_SVG_LENGTH_TYPE_NUMBER};
+static const LsmSvgAngle orientation_default =	 { .angle =        0.0, .type = LSM_SVG_ANGLE_TYPE_FIXED};
+
+static void
+lsm_svg_marker_element_init (LsmSvgMarkerElement *self)
+{
+	self->ref_x.length = length_default;
+	self->ref_y.length = length_default;
+	self->width.length = width_default;
+	self->height.length = width_default;
+}
+
+/* LsmSvgMarkerElement class */
+
+static const LsmAttributeInfos lsm_svg_marker_element_attribute_infos[] = {
+	{
+		.name = "markerUnits",
+		.attribute_offset = offsetof (LsmSvgMarkerElement, units),
+		.trait_class = &lsm_svg_marker_units_trait_class,
+		.trait_default = &units_default
+	},
+	{
+		.name = "refX",
+		.attribute_offset = offsetof (LsmSvgMarkerElement, ref_x),
+		.trait_class = &lsm_svg_length_trait_class,
+		.trait_default = &length_default
+	},
+	{
+		.name = "refY",
+		.attribute_offset = offsetof (LsmSvgMarkerElement, ref_y),
+		.trait_class = &lsm_svg_length_trait_class,
+		.trait_default = &length_default
+	},
+	{
+		.name = "width",
+		.attribute_offset = offsetof (LsmSvgMarkerElement, width),
+		.trait_class = &lsm_svg_length_trait_class,
+		.trait_default = &width_default
+	},
+	{
+		.name = "height",
+		.attribute_offset = offsetof (LsmSvgMarkerElement, height),
+		.trait_class = &lsm_svg_length_trait_class,
+		.trait_default = &width_default
+	},
+	{
+		.name = "orient",
+		.attribute_offset = offsetof (LsmSvgMarkerElement, orientation),
+		.trait_class = &lsm_svg_angle_trait_class,
+		.trait_default = &orientation_default
+	}
+};
+
+static void
+lsm_svg_marker_element_class_init (LsmSvgMarkerElementClass *klass)
+{
+	LsmDomNodeClass *d_node_class = LSM_DOM_NODE_CLASS (klass);
+	LsmSvgElementClass *s_element_class = LSM_SVG_ELEMENT_CLASS (klass);
+
+	parent_class = g_type_class_peek_parent (klass);
+
+	d_node_class->get_node_name = lsm_svg_marker_element_get_node_name;
+
+	s_element_class->render = lsm_svg_marker_element_render;
+	s_element_class->attribute_manager = lsm_attribute_manager_duplicate (s_element_class->attribute_manager);
+
+	lsm_attribute_manager_add_attributes (s_element_class->attribute_manager,
+					      G_N_ELEMENTS (lsm_svg_marker_element_attribute_infos),
+					      lsm_svg_marker_element_attribute_infos);
+}
+
+G_DEFINE_TYPE (LsmSvgMarkerElement, lsm_svg_marker_element, LSM_TYPE_SVG_ELEMENT)
diff --git a/src/lsmsvgmarkerelement.h b/src/lsmsvgmarkerelement.h
new file mode 100644
index 0000000..7c444ee
--- /dev/null
+++ b/src/lsmsvgmarkerelement.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright © 2009 Emmanuel Pacaud
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ * 	Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#ifndef LSM_SVG_MARKER_ELEMENT_H
+#define LSM_SVG_MARKER_ELEMENT_H
+
+#include <lsmsvg.h>
+#include <lsmsvgelement.h>
+
+G_BEGIN_DECLS
+
+#define LSM_TYPE_SVG_MARKER_ELEMENT             (lsm_svg_marker_element_get_type ())
+#define LSM_SVG_MARKER_ELEMENT(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), LSM_TYPE_SVG_MARKER_ELEMENT, LsmSvgMarkerElement))
+#define LSM_SVG_MARKER_ELEMENT_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), LSM_TYPE_SVG_MARKER_ELEMENT, LsmSvgMarkerElementClass))
+#define LSM_IS_SVG_MARKER_ELEMENT(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LSM_TYPE_SVG_MARKER_ELEMENT))
+#define LSM_IS_SVG_MARKER_ELEMENT_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), LSM_TYPE_SVG_MARKER_ELEMENT))
+#define LSM_SVG_MARKER_ELEMENT_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), LSM_TYPE_SVG_MARKER_ELEMENT, LsmSvgMarkerElementClass))
+
+typedef struct _LsmSvgMarkerElementClass LsmSvgMarkerElementClass;
+
+struct _LsmSvgMarkerElement {
+	LsmSvgElement element;
+
+	LsmSvgMarkerUnitsAttribute units;
+	LsmSvgLengthAttribute ref_x;
+	LsmSvgLengthAttribute ref_y;
+	LsmSvgLengthAttribute width;
+	LsmSvgLengthAttribute height;
+	LsmSvgAngleAttribute orientation;
+};
+
+struct _LsmSvgMarkerElementClass {
+	LsmSvgElementClass  element_class;
+};
+
+GType lsm_svg_marker_element_get_type (void);
+
+LsmDomNode *		lsm_svg_marker_element_new 		(void);
+
+G_END_DECLS
+
+#endif
diff --git a/src/lsmsvgtraits.c b/src/lsmsvgtraits.c
index 8eb4c49..db07b94 100644
--- a/src/lsmsvgtraits.c
+++ b/src/lsmsvgtraits.c
@@ -577,6 +577,28 @@ const LsmTraitClass lsm_svg_color_trait_class = {
 };
 
 static void
+lsm_svg_marker_units_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+	LsmSvgMarkerUnits *trait = (LsmSvgMarkerUnits *) abstract_trait;
+
+	*trait = lsm_svg_marker_units_from_string (string);
+}
+
+char *
+lsm_svg_marker_units_trait_to_string (LsmTrait *abstract_trait)
+{
+	LsmSvgMarkerUnits *trait = (LsmSvgMarkerUnits *) abstract_trait;
+
+	return g_strdup (lsm_svg_marker_units_to_string (*trait));
+}
+
+const LsmTraitClass lsm_svg_marker_units_trait_class = {
+	.size = sizeof (LsmSvgMarkerUnits),
+	.from_string = lsm_svg_marker_units_trait_from_string,
+	.to_string = lsm_svg_marker_units_trait_to_string
+};
+
+static void
 lsm_svg_pattern_units_trait_from_string (LsmTrait *abstract_trait, char *string)
 {
 	LsmSvgPatternUnits *trait = (LsmSvgPatternUnits *) abstract_trait;
@@ -664,3 +686,33 @@ const LsmTraitClass lsm_svg_spread_method_trait_class = {
 	.to_string = lsm_svg_spread_method_trait_to_string
 };
 
+static void
+lsm_svg_angle_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+	LsmSvgAngle *trait = (LsmSvgAngle *) abstract_trait;
+
+	if (g_strcmp0 (string, "auto")) {
+		trait->type = LSM_SVG_ANGLE_TYPE_AUTO;
+		trait->angle = 0.0;
+	} else {
+		trait->type = LSM_SVG_ANGLE_TYPE_FIXED;
+		trait->angle = g_strtod (string, NULL);
+	}
+}
+
+static char *
+lsm_svg_angle_trait_to_string (LsmTrait *abstract_trait)
+{
+	LsmSvgAngle *trait = (LsmSvgAngle *) abstract_trait;
+
+	if (trait->type == LSM_SVG_ANGLE_TYPE_AUTO)
+		return g_strdup ("auto");
+
+	return g_strdup_printf ("%g", trait->angle);
+}
+
+const LsmTraitClass lsm_svg_angle_trait_class = {
+	.size = sizeof (LsmSvgAngle),
+	.from_string = lsm_svg_angle_trait_from_string,
+	.to_string = lsm_svg_angle_trait_to_string
+};
diff --git a/src/lsmsvgtraits.h b/src/lsmsvgtraits.h
index e33c474..21ba491 100644
--- a/src/lsmsvgtraits.h
+++ b/src/lsmsvgtraits.h
@@ -60,6 +60,11 @@ typedef struct {
 	LsmSvgMeetOrSlice meet_or_slice;
 } LsmSvgPreserveAspectRatio;
 
+typedef struct {
+	LsmSvgAngleType type;
+	double angle;
+} LsmSvgAngle;
+
 extern const LsmTraitClass lsm_svg_length_trait_class;
 extern const LsmTraitClass lsm_svg_matrix_trait_class;
 extern const LsmTraitClass lsm_svg_paint_trait_class;
@@ -69,8 +74,10 @@ extern const LsmTraitClass lsm_svg_line_cap_trait_class;
 extern const LsmTraitClass lsm_svg_dash_array_trait_class;
 extern const LsmTraitClass lsm_svg_color_trait_class;
 extern const LsmTraitClass lsm_svg_pattern_units_trait_class;
+extern const LsmTraitClass lsm_svg_marker_units_trait_class;
 extern const LsmTraitClass lsm_svg_preserve_aspect_ratio_trait_class;
 extern const LsmTraitClass lsm_svg_spread_method_trait_class;
+extern const LsmTraitClass lsm_svg_angle_trait_class;
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]