dia r4247 - in trunk: . lib plug-ins/python
- From: hans svn gnome org
- To: svn-commits-list gnome org
- Subject: dia r4247 - in trunk: . lib plug-ins/python
- Date: Sat, 31 Jan 2009 23:20:58 +0000 (UTC)
Author: hans
Date: Sat Jan 31 23:20:57 2009
New Revision: 4247
URL: http://svn.gnome.org/viewvc/dia?rev=4247&view=rev
Log:
2009-01-31 Hans Breuer <hans breuer org>
* lib/dia_xml.[ch] lib/libdia.def : implement data_(add_)bezpoint to
serialize bezier points
* lib/prop_geomtypes.c : use it instead of g_error() for an attempt to
save a bezpoint array (not used by any object implementation yet)
* plug-ins/python/diasvg_import.py : fixed typo
Modified:
trunk/ChangeLog
trunk/lib/dia_xml.c
trunk/lib/dia_xml.h
trunk/lib/libdia.def
trunk/lib/prop_geomtypes.c
trunk/plug-ins/python/diasvg_import.py
Modified: trunk/lib/dia_xml.c
==============================================================================
--- trunk/lib/dia_xml.c (original)
+++ trunk/lib/dia_xml.c Sat Jan 31 23:20:57 2009
@@ -245,7 +245,7 @@
} else {
/* the XML file is good. libxml is "old enough" to handle it correctly.
*/
- return xmlDoParseFile(filename);
+ return xmlDoParseFile(filename);
}
} else {
return xmlDoParseFile(filename);
@@ -420,6 +420,8 @@
return DATATYPE_STRING;
} else if (strcmp(name, "font")==0) {
return DATATYPE_FONT;
+ } else if (strcmp(name, "bezpoint")==0) {
+ return DATATYPE_BEZPOINT;
}
message_error("Unknown type of DataNode");
@@ -622,6 +624,74 @@
xmlFree(val);
}
+/** Return the value of a bezpoint-type data node.
+ * @param data The XML node to read from
+ * @param point A place to store the resulting values. If the node does
+ * not contain a valid bezpoint zero initialization is performed.
+ */
+void
+data_bezpoint(DataNode data, BezPoint *point)
+{
+ xmlChar *val;
+ gchar *str;
+ if (data_type(data)!=DATATYPE_BEZPOINT) {
+ message_error(_("Taking bezpoint value of non-point node."));
+ return;
+ }
+ val = xmlGetProp(data, (const xmlChar *)"type");
+ if (val) {
+ if (strcmp(val, "moveto") == 0)
+ point->type = BEZ_MOVE_TO;
+ else if (strcmp(val, "lineto") == 0)
+ point->type = BEZ_LINE_TO;
+ else
+ point->type = BEZ_CURVE_TO;
+ xmlFree(val);
+ }
+ val = xmlGetProp(data, (const xmlChar *)"p1");
+ if (val) {
+ point->p1.x = g_ascii_strtod((char *)val, &str);
+ if (*str==0) {
+ point->p1.y = 0;
+ g_warning(_("Error parsing bezpoint p1."));
+ } else {
+ point->p1.y = g_ascii_strtod(str+1, NULL);
+ }
+ xmlFree(val);
+ } else {
+ point->p1.x = 0;
+ point->p1.y = 0;
+ }
+ val = xmlGetProp(data, (const xmlChar *)"p2");
+ if (val) {
+ point->p2.x = g_ascii_strtod((char *)val, &str);
+ if (*str==0) {
+ point->p2.y = 0;
+ g_warning(_("Error parsing bezpoint p2."));
+ } else {
+ point->p2.y = g_ascii_strtod(str+1, NULL);
+ }
+ xmlFree(val);
+ } else {
+ point->p2.x = 0;
+ point->p2.y = 0;
+ }
+ val = xmlGetProp(data, (const xmlChar *)"p3");
+ if (val) {
+ point->p3.x = g_ascii_strtod((char *)val, &str);
+ if (*str==0) {
+ point->p3.y = 0;
+ g_warning(_("Error parsing bezpoint p3."));
+ } else {
+ point->p3.y = g_ascii_strtod(str+1, NULL);
+ }
+ xmlFree(val);
+ } else {
+ point->p3.x = 0;
+ point->p3.y = 0;
+ }
+}
+
/** Return the value of a rectangle-type data node.
* @param data The data node to read from.
* @param rect A place to store the resulting values. If the node does
@@ -954,14 +1024,9 @@
xmlSetProp(data_node, (const xmlChar *)"val", (xmlChar *)buffer);
}
-/** Add point data to an attribute node.
- * @param attr The attribute node.
- * @param point The value to set.
- */
-void
-data_add_point(AttributeNode attr, const Point *point)
+static gchar *
+_str_point (const Point *point)
{
- DataNode data_node;
gchar *buffer;
gchar px_buf[G_ASCII_DTOSTR_BUF_SIZE];
gchar py_buf[G_ASCII_DTOSTR_BUF_SIZE];
@@ -970,11 +1035,60 @@
g_ascii_formatd(py_buf, sizeof(py_buf), "%g", point->y);
buffer = g_strconcat(px_buf, ",", py_buf, NULL);
+ return buffer;
+}
+
+/** Add point data to an attribute node.
+ * @param attr The attribute node.
+ * @param point The value to set.
+ */
+void
+data_add_point(AttributeNode attr, const Point *point)
+{
+ DataNode data_node;
+ gchar *buffer = _str_point (point);
+
data_node = xmlNewChild(attr, NULL, (const xmlChar *)"point", NULL);
xmlSetProp(data_node, (const xmlChar *)"val", (xmlChar *)buffer);
g_free(buffer);
}
+void
+data_add_bezpoint(AttributeNode attr, const BezPoint *point)
+{
+ DataNode data_node;
+ gchar *buffer;
+ gchar px_buf[G_ASCII_DTOSTR_BUF_SIZE];
+ gchar py_buf[G_ASCII_DTOSTR_BUF_SIZE];
+
+ data_node = xmlNewChild(attr, NULL, (const xmlChar *)"bezpoint", NULL);
+ switch (point->type) {
+ case BEZ_MOVE_TO :
+ xmlSetProp(data_node, (const xmlChar *)"type", (const xmlChar *)"moveto");
+ break;
+ case BEZ_LINE_TO :
+ xmlSetProp(data_node, (const xmlChar *)"type", (const xmlChar *)"lineto");
+ break;
+ case BEZ_CURVE_TO :
+ xmlSetProp(data_node, (const xmlChar *)"type", (const xmlChar *)"curveto");
+ break;
+ default :
+ g_assert_not_reached();
+ }
+
+ buffer = _str_point (&point->p1);
+ xmlSetProp(data_node, (const xmlChar *)"p1", (xmlChar *)buffer);
+ g_free (buffer);
+ if (point->type == BEZ_CURVE_TO) {
+ buffer = _str_point (&point->p2);
+ xmlSetProp(data_node, (const xmlChar *)"p2", (xmlChar *)buffer);
+ g_free (buffer);
+ buffer = _str_point (&point->p3);
+ xmlSetProp(data_node, (const xmlChar *)"p3", (xmlChar *)buffer);
+ g_free (buffer);
+ }
+}
+
/** Add rectangle data to an attribute node.
* @param attr The attribute node.
* @param rect The value to set.
Modified: trunk/lib/dia_xml.h
==============================================================================
--- trunk/lib/dia_xml.h (original)
+++ trunk/lib/dia_xml.h Sat Jan 31 23:20:57 2009
@@ -56,7 +56,8 @@
DATATYPE_POINT,
DATATYPE_RECTANGLE,
DATATYPE_STRING,
- DATATYPE_FONT
+ DATATYPE_FONT,
+ DATATYPE_BEZPOINT,
} DataType;
AttributeNode object_find_attribute(ObjectNode obj_node,
@@ -73,6 +74,7 @@
int data_boolean(DataNode data);
void data_color(DataNode data, Color *col);
void data_point(DataNode data, Point *point);
+void data_bezpoint(DataNode data, BezPoint *point);
void data_rectangle(DataNode data, Rectangle *rect);
char *data_string(DataNode data);
char *data_filename(DataNode data);
@@ -87,6 +89,7 @@
void data_add_boolean(AttributeNode attr, int data);
void data_add_color(AttributeNode attr, const Color *col);
void data_add_point(AttributeNode attr, const Point *point);
+void data_add_bezpoint(AttributeNode attr, const BezPoint *point);
void data_add_rectangle(AttributeNode attr, const Rectangle *rect);
void data_add_string(AttributeNode attr, const char *str);
void data_add_filename(AttributeNode attr, const char *str);
Modified: trunk/lib/libdia.def
==============================================================================
--- trunk/lib/libdia.def (original)
+++ trunk/lib/libdia.def Sat Jan 31 23:20:57 2009
@@ -136,6 +136,7 @@
data_add_layer
data_add_layer_at
data_add_point
+ data_add_bezpoint
data_add_real
data_add_string
data_add_text
@@ -153,6 +154,7 @@
data_lower_layer
data_next
data_point
+ data_bezpoint
data_raise_layer
data_real
data_remove_all_selected
Modified: trunk/lib/prop_geomtypes.c
==============================================================================
--- trunk/lib/prop_geomtypes.c (original)
+++ trunk/lib/prop_geomtypes.c Sat Jan 31 23:20:57 2009
@@ -571,21 +571,13 @@
static void
bezpointprop_load(BezPointProperty *prop, AttributeNode attr, DataNode data)
{
-#if 0
data_bezpoint(data,&prop->bezpoint_data);
-#else
- g_error("BezPoint_load() not implemented. Missing data_bezpoint().");
-#endif
}
static void
bezpointprop_save(BezPointProperty *prop, AttributeNode attr)
{
-#if 0
data_add_bezpoint(attr, &prop->bezpoint_data);
-#else
- g_error("BezPoint_save() not implemented. Missing data_bezpoint().");
-#endif
}
static void
@@ -657,7 +649,6 @@
bezpointarrayprop_load(BezPointarrayProperty *prop,
AttributeNode attr, DataNode data)
{
-#if 0
guint nvals = attribute_num_data(attr);
guint i;
@@ -668,22 +659,15 @@
if (i != nvals)
g_warning("attribute_num_data() and actual data count mismatch "
"(shouldn't happen)");
-#else
- g_error("BezPointArray_load() not implemented. Missing data_bezpoint().");
-#endif
}
static void
bezpointarrayprop_save(BezPointarrayProperty *prop, AttributeNode attr)
{
-#if 0
guint i;
for (i = 0; i < prop->bezpointarray_data->len; i++)
data_add_bezpoint(attr,
&g_array_index(prop->bezpointarray_data,BezPoint,i));
-#else
- g_error("BezPointArray_load() not implemented. Missing data_bezpoint().");
-#endif
}
static void
Modified: trunk/plug-ins/python/diasvg_import.py
==============================================================================
--- trunk/plug-ins/python/diasvg_import.py (original)
+++ trunk/plug-ins/python/diasvg_import.py Sat Jan 31 23:20:57 2009
@@ -7,7 +7,7 @@
# this will _not_ be the case. Known issues (at least) :
# - xlink stuff (should probably have some StdProp equivalent)
# - lack of full transformation dealing
-# - real percentage scaling, is it woth it ?
+# - real percentage scaling, is it worth it ?
# - see FIXME in this file
# This program is free software; you can redistribute it and/or modify
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]