[lasem] tspan: start the implementation of tspan element.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [lasem] tspan: start the implementation of tspan element.
- Date: Tue, 3 Aug 2010 23:00:42 +0000 (UTC)
commit c49496fbfe1d5877c3581e2e032407062534424c
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Wed Aug 4 00:59:25 2010 +0200
tspan: start the implementation of tspan element.
Not much been done, but at least lasem renders something.
src/Makefile.am | 2 +
src/lsmsvg.h | 1 +
src/lsmsvgdocument.c | 3 +
src/lsmsvgtextelement.c | 7 ++-
src/lsmsvgtspanelement.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++
src/lsmsvgtspanelement.h | 57 +++++++++++++++++++
6 files changed, 207 insertions(+), 1 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index a43daf6..b35fb4a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -98,6 +98,7 @@ liblasem_ LASEM_API_VERSION@_la_SOURCES = \
lsmsvgpolygonelement.c \
lsmsvgpathelement.c \
lsmsvgtextelement.c \
+ lsmsvgtspanelement.c \
lsmsvggradientelement.c \
lsmsvglineargradientelement.c \
lsmsvgradialgradientelement.c \
@@ -185,6 +186,7 @@ LASEM_HDRS = \
lsmsvgpolylineelement.h \
lsmsvgpolygonelement.h \
lsmsvgtextelement.h \
+ lsmsvgtspanelement.h \
lsmsvggradientelement.h \
lsmsvglineargradientelement.h \
lsmsvgradialgradientelement.h \
diff --git a/src/lsmsvg.h b/src/lsmsvg.h
index 1d9b3c1..a6b61d5 100644
--- a/src/lsmsvg.h
+++ b/src/lsmsvg.h
@@ -46,6 +46,7 @@ typedef struct _LsmSvgPolylineElement LsmSvgPolylineElement;
typedef struct _LsmSvgPolygonElement LsmSvgPolygonElement;
typedef struct _LsmSvgPathElement LsmSvgPathElement;
typedef struct _LsmSvgTextElement LsmSvgTextElement;
+typedef struct _LsmSvgTspanElement LsmSvgTspanElement;
typedef struct _LsmSvgGradientElement LsmSvgGradientElement;
typedef struct _LsmSvgLinearGradientElement LsmSvgLinearGradientElement;
typedef struct _LsmSvgRadialGradientElement LsmSvgRadialGradientElement;
diff --git a/src/lsmsvgdocument.c b/src/lsmsvgdocument.c
index 9a0747c..8684cc2 100644
--- a/src/lsmsvgdocument.c
+++ b/src/lsmsvgdocument.c
@@ -38,6 +38,7 @@
#include <lsmsvgpolygonelement.h>
#include <lsmsvgpathelement.h>
#include <lsmsvgtextelement.h>
+#include <lsmsvgtspanelement.h>
#include <lsmsvglineargradientelement.h>
#include <lsmsvgradialgradientelement.h>
#include <lsmsvgstopelement.h>
@@ -104,6 +105,8 @@ lsm_svg_document_create_element (LsmDomDocument *document, const char *tag_name)
node = lsm_svg_polygon_element_new ();
else if (strcmp (tag_name, "text") == 0)
node = lsm_svg_text_element_new ();
+ else if (strcmp (tag_name, "tspan") == 0)
+ node = lsm_svg_tspan_element_new ();
else if (strcmp (tag_name, "linearGradient") == 0)
node = lsm_svg_linear_gradient_element_new ();
else if (strcmp (tag_name, "radialGradient") == 0)
diff --git a/src/lsmsvgtextelement.c b/src/lsmsvgtextelement.c
index 3d112d6..3e5647d 100644
--- a/src/lsmsvgtextelement.c
+++ b/src/lsmsvgtextelement.c
@@ -21,6 +21,7 @@
*/
#include <lsmsvgtextelement.h>
+#include <lsmsvgtspanelement.h>
#include <lsmsvgview.h>
#include <lsmdomtext.h>
@@ -37,7 +38,7 @@ lsm_svg_text_element_get_node_name (LsmDomNode *node)
static gboolean
lsm_svg_text_element_can_append_child (LsmDomNode *self, LsmDomNode *child)
{
- return (LSM_IS_DOM_TEXT (child));
+ return (LSM_IS_SVG_TSPAN_ELEMENT (child) || LSM_IS_DOM_TEXT (child));
}
/* LsmSvgElement implementation */
@@ -68,6 +69,10 @@ lsm_svg_text_element_render (LsmSvgElement *self, LsmSvgView *view)
lsm_svg_view_show_text (view, g_strstrip (string->str), x, y);
g_string_free (string, TRUE);
+
+ for (iter = LSM_DOM_NODE (self)->first_child; iter != NULL; iter = iter->next_sibling)
+ if (LSM_IS_SVG_ELEMENT (iter))
+ lsm_svg_element_render (LSM_SVG_ELEMENT (iter), view);
}
/* LsmSvgTextElement implementation */
diff --git a/src/lsmsvgtspanelement.c b/src/lsmsvgtspanelement.c
new file mode 100644
index 0000000..776cb07
--- /dev/null
+++ b/src/lsmsvgtspanelement.c
@@ -0,0 +1,138 @@
+/*
+ * Copyright © 2009 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author:
+ * Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#include <lsmsvgtspanelement.h>
+#include <lsmsvgview.h>
+#include <lsmdomtext.h>
+#include <lsmdebug.h>
+
+static GObjectClass *parent_class;
+
+/* GdomNode implementation */
+
+static const char *
+lsm_svg_tspan_element_get_node_name (LsmDomNode *node)
+{
+ return "tspan";
+}
+
+static gboolean
+lsm_svg_tspan_element_can_append_child (LsmDomNode *self, LsmDomNode *child)
+{
+ return (LSM_IS_DOM_TEXT (child));
+}
+
+/* LsmSvgElement implementation */
+
+/* LsmSvgGraphic implementation */
+
+static void
+lsm_svg_tspan_element_render (LsmSvgElement *self, LsmSvgView *view)
+{
+ LsmSvgTspanElement *tspan = LSM_SVG_TSPAN_ELEMENT (self);
+ LsmDomNode *node = LSM_DOM_NODE (self);
+ LsmDomNode *iter;
+ GString *string = g_string_new ("");
+ double x, y;
+
+ lsm_debug ("render", "[LsmSvgTspanElement::render] Render");
+
+ if (node->first_child == NULL)
+ return;
+
+ for (iter = LSM_DOM_NODE (self)->first_child; iter != NULL; iter = iter->next_sibling) {
+ if (LSM_IS_DOM_TEXT (iter)) {
+ g_string_append (string, lsm_dom_node_get_node_value (iter));
+ }
+ }
+
+ x = lsm_svg_view_normalize_length (view, &tspan->x.length, LSM_SVG_LENGTH_DIRECTION_HORIZONTAL);
+ y = lsm_svg_view_normalize_length (view, &tspan->y.length, LSM_SVG_LENGTH_DIRECTION_VERTICAL);
+
+ lsm_svg_view_show_text (view, g_strstrip (string->str), x, y);
+
+ g_string_free (string, TRUE);
+}
+
+/* LsmSvgTspanElement implementation */
+
+LsmDomNode *
+lsm_svg_tspan_element_new (void)
+{
+ return g_object_new (LSM_TYPE_SVG_TSPAN_ELEMENT, NULL);
+}
+
+static const LsmSvgLength length_default = { .value_unit = 0.0, .type = LSM_SVG_LENGTH_TYPE_PX};
+
+static void
+lsm_svg_tspan_element_init (LsmSvgTspanElement *self)
+{
+ self->x.length = length_default;
+ self->y.length = length_default;
+}
+
+static void
+lsm_svg_tspan_element_finalize (GObject *object)
+{
+ parent_class->finalize (object);
+}
+
+/* LsmSvgTspanElement class */
+
+static const LsmAttributeInfos lsm_svg_tspan_element_attribute_infos[] = {
+ {
+ .name = "x",
+ .attribute_offset = offsetof (LsmSvgTspanElement, x),
+ .trait_class = &lsm_svg_length_trait_class,
+ .trait_default = &length_default
+ },
+ {
+ .name = "y",
+ .attribute_offset = offsetof (LsmSvgTspanElement, y),
+ .trait_class = &lsm_svg_length_trait_class,
+ .trait_default = &length_default
+ }
+};
+
+static void
+lsm_svg_tspan_element_class_init (LsmSvgTspanElementClass *s_tspan_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (s_tspan_class);
+ LsmDomNodeClass *d_node_class = LSM_DOM_NODE_CLASS (s_tspan_class);
+ LsmSvgElementClass *s_element_class = LSM_SVG_ELEMENT_CLASS (s_tspan_class);
+
+ parent_class = g_type_class_peek_parent (s_tspan_class);
+
+ object_class->finalize = lsm_svg_tspan_element_finalize;
+
+ d_node_class->get_node_name = lsm_svg_tspan_element_get_node_name;
+ d_node_class->can_append_child = lsm_svg_tspan_element_can_append_child;
+
+ s_element_class->render = lsm_svg_tspan_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_tspan_element_attribute_infos),
+ lsm_svg_tspan_element_attribute_infos);
+}
+
+G_DEFINE_TYPE (LsmSvgTspanElement, lsm_svg_tspan_element, LSM_TYPE_SVG_ELEMENT)
diff --git a/src/lsmsvgtspanelement.h b/src/lsmsvgtspanelement.h
new file mode 100644
index 0000000..a913feb
--- /dev/null
+++ b/src/lsmsvgtspanelement.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2009 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author:
+ * Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#ifndef LSM_SVG_TSPAN_ELEMENT_H
+#define LSM_SVG_TSPAN_ELEMENT_H
+
+#include <lsmsvg.h>
+#include <lsmsvgelement.h>
+
+G_BEGIN_DECLS
+
+#define LSM_TYPE_SVG_TSPAN_ELEMENT (lsm_svg_tspan_element_get_type ())
+#define LSM_SVG_TSPAN_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LSM_TYPE_SVG_TSPAN_ELEMENT, LsmSvgTspanElement))
+#define LSM_SVG_TSPAN_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LSM_TYPE_SVG_TSPAN_ELEMENT, LsmSvgTspanElementClass))
+#define LSM_IS_SVG_TSPAN_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LSM_TYPE_SVG_TSPAN_ELEMENT))
+#define LSM_IS_SVG_TSPAN_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LSM_TYPE_SVG_TSPAN_ELEMENT))
+#define LSM_SVG_TSPAN_ELEMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), LSM_TYPE_SVG_TSPAN_ELEMENT, LsmSvgTspanElementClass))
+
+typedef struct _LsmSvgTspanElementClass LsmSvgTspanElementClass;
+
+struct _LsmSvgTspanElement {
+ LsmSvgElement element;
+
+ LsmSvgLengthAttribute x;
+ LsmSvgLengthAttribute y;
+};
+
+struct _LsmSvgTspanElementClass {
+ LsmSvgElementClass element_class;
+};
+
+GType lsm_svg_tspan_element_get_type (void);
+
+LsmDomNode * lsm_svg_tspan_element_new (void);
+
+G_END_DECLS
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]