[lasem] [SVG] Boilerplate code for clip-path element.



commit ad5fc39051564bcad25960fe7dcd8412369933ed
Author: Emmanuel Pacaud <emmanuel pacaud lapp in2p3 fr>
Date:   Mon May 18 14:36:49 2009 +0200

    [SVG] Boilerplate code for clip-path element.
---
 src/Makefile.am             |    2 +
 src/lsmsvg.h                |    1 +
 src/lsmsvgclippathelement.c |   94 +++++++++++++++++++++++++++++++++++++++++++
 src/lsmsvgclippathelement.h |   55 +++++++++++++++++++++++++
 src/lsmsvgdocument.c        |    3 +
 5 files changed, 155 insertions(+), 0 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 9a460bb..58d7bd1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -63,6 +63,7 @@ liblasem_la_SOURCES =				\
 	lsmsvgdocument.c			\
 	lsmsvgelement.c				\
 	lsmsvggraphic.c				\
+	lsmsvgclippathelement.c			\
 	lsmsvgsvgelement.c			\
 	lsmsvguseelement.c			\
 	lsmsvgimageelement.c			\
@@ -144,6 +145,7 @@ liblasem_la_HEADERS = \
 	lsmsvgdocument.h			\
 	lsmsvgelement.h				\
 	lsmsvggraphic.h				\
+	lsmsvgclippathelement.h			\
 	lsmsvgsvgelement.h			\
 	lsmsvggelement.h			\
 	lsmsvgdefselement.h			\
diff --git a/src/lsmsvg.h b/src/lsmsvg.h
index 853b823..8277921 100644
--- a/src/lsmsvg.h
+++ b/src/lsmsvg.h
@@ -29,6 +29,7 @@ G_BEGIN_DECLS
 typedef struct _LsmSvgDocument LsmSvgDocument;
 typedef struct _LsmSvgElement LsmSvgElement;
 typedef struct _LsmSvgGraphic LsmSvgGraphic;
+typedef struct _LsmSvgClipPathElement LsmSvgClipPathElement;
 typedef struct _LsmSvgSvgElement LsmSvgSvgElement;
 typedef struct _LsmSvgGElement LsmSvgGElement;
 typedef struct _LsmSvgDefsElement LsmSvgDefsElement;
diff --git a/src/lsmsvgclippathelement.c b/src/lsmsvgclippathelement.c
new file mode 100644
index 0000000..23d0332
--- /dev/null
+++ b/src/lsmsvgclippathelement.c
@@ -0,0 +1,94 @@
+/*
+ * 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 <lsmsvgclippathelement.h>
+#include <lsmsvgview.h>
+#include <lsmdebug.h>
+#include <stdio.h>
+
+static GObjectClass *parent_class;
+
+/* GdomNode implementation */
+
+static const char *
+_clip_path_element_get_node_name (LsmDomNode *node)
+{
+	return "clip-path";
+}
+
+/* LsmSvgElement implementation */
+
+static void
+_clip_path_element_update (LsmSvgElement *self, LsmSvgStyle *parent_style)
+{
+	LsmSvgClipPathElement *pattern = LSM_SVG_CLIP_PATH_ELEMENT (self);
+	LsmSvgPatternUnits units;
+
+	units = LSM_SVG_PATTERN_UNITS_OBJECT_BOUNDING_BOX;
+	lsm_svg_pattern_units_attribute_parse (&pattern->units, &units);
+
+	LSM_SVG_ELEMENT_CLASS (parent_class)->update (self, parent_style);
+}
+
+/* LsmSvgClipPathElement implementation */
+
+LsmDomNode *
+lsm_svg_clip_path_element_new (void)
+{
+	return g_object_new (LSM_TYPE_SVG_CLIP_PATH_ELEMENT, NULL);
+}
+
+static void
+lsm_svg_clip_path_element_init (LsmSvgClipPathElement *self)
+{
+	/* Hack - Force the creation of the attribute bags,
+	   making sure the properties will be inherited from the
+	   pattern element ancestor, not the referencing one. */
+
+	lsm_dom_element_set_attribute (LSM_DOM_ELEMENT (self), "fill", NULL);
+	lsm_dom_element_set_attribute (LSM_DOM_ELEMENT (self), "stroke", NULL);
+	lsm_dom_element_set_attribute (LSM_DOM_ELEMENT (self), "transform", NULL);
+	lsm_dom_element_set_attribute (LSM_DOM_ELEMENT (self), "font-family", NULL);
+	lsm_dom_element_set_attribute (LSM_DOM_ELEMENT (self), "stop-color", NULL);
+}
+
+/* LsmSvgClipPathElement class */
+
+static void
+lsm_svg_clip_path_element_class_init (LsmSvgClipPathElementClass *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 = _clip_path_element_get_node_name;
+
+	s_element_class->update = _clip_path_element_update;
+	s_element_class->render = NULL;
+
+	s_element_class->attributes = lsm_dom_attribute_map_duplicate (s_element_class->attributes);
+
+	lsm_dom_attribute_map_add_attribute (s_element_class->attributes, "clipPathUnits",
+					     offsetof (LsmSvgClipPathElement, units));
+}
+
+G_DEFINE_TYPE (LsmSvgClipPathElement, lsm_svg_clip_path_element, LSM_TYPE_SVG_GRAPHIC)
diff --git a/src/lsmsvgclippathelement.h b/src/lsmsvgclippathelement.h
new file mode 100644
index 0000000..9959a1e
--- /dev/null
+++ b/src/lsmsvgclippathelement.h
@@ -0,0 +1,55 @@
+/*
+ * 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_CLIP_PATH_ELEMENT_H
+#define LSM_SVG_CLIP_PATH_ELEMENT_H
+
+#include <lsmsvg.h>
+#include <lsmsvggraphic.h>
+
+G_BEGIN_DECLS
+
+#define LSM_TYPE_SVG_CLIP_PATH_ELEMENT             (lsm_svg_clip_path_element_get_type ())
+#define LSM_SVG_CLIP_PATH_ELEMENT(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), LSM_TYPE_SVG_CLIP_PATH_ELEMENT, LsmSvgClipPathElement))
+#define LSM_SVG_CLIP_PATH_ELEMENT_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), LSM_TYPE_SVG_CLIP_PATH_ELEMENT, LsmSvgClipPathElementClass))
+#define LSM_IS_SVG_CLIP_PATH_ELEMENT(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LSM_TYPE_SVG_CLIP_PATH_ELEMENT))
+#define LSM_IS_SVG_CLIP_PATH_ELEMENT_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), LSM_TYPE_SVG_CLIP_PATH_ELEMENT))
+#define LSM_SVG_CLIP_PATH_ELEMENT_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), LSM_TYPE_SVG_CLIP_PATH_ELEMENT, LsmSvgClipPathElementClass))
+
+typedef struct _LsmSvgClipPathElementClass LsmSvgClipPathElementClass;
+
+struct _LsmSvgClipPathElement {
+	LsmSvgGraphic graphic;
+
+	LsmDomEnumAttribute 		units;
+};
+
+struct _LsmSvgClipPathElementClass {
+	LsmSvgGraphicClass  parent_class;
+};
+
+GType lsm_svg_clip_path_element_get_type (void);
+
+LsmDomNode * 	lsm_svg_clip_path_element_new 	(void);
+
+G_END_DECLS
+
+#endif
diff --git a/src/lsmsvgdocument.c b/src/lsmsvgdocument.c
index 3ef121e..cc7f744 100644
--- a/src/lsmsvgdocument.c
+++ b/src/lsmsvgdocument.c
@@ -21,6 +21,7 @@
 
 #include <lsmdebug.h>
 #include <lsmsvgdocument.h>
+#include <lsmsvgclippathelement.h>
 #include <lsmsvgsvgelement.h>
 #include <lsmsvggelement.h>
 #include <lsmsvgdefselement.h>
@@ -93,6 +94,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, "clip-path") == 0)
+		node = lsm_svg_clip_path_element_new ();
 
 	if (node != NULL)
 		lsm_debug ("[LsmSvgDocument::create_element] Create a %s element", tag_name);



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