[gnumeric] ODF: some symbol handling in XY charts
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] ODF: some symbol handling in XY charts
- Date: Wed, 18 Aug 2010 06:59:28 +0000 (UTC)
commit 10d4b253c54d1bc6e7109efa89333254fef7f835
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Wed Aug 18 00:58:56 2010 -0600
ODF: some symbol handling in XY charts
2010-08-18 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-write.c (odf_write_line_chart_style): check the plot
(odf_write_scatter_chart_style): ditto
(odf_get_marker): new
(odf_write_scatter_series_style): handle symbol-type
and symbol-name
(odf_write_plot): add argument to odf_write_series_style
* openoffice-read.c (oo_prop_list_to_series): handle symbol-type
and symbol-name
(od_style_prop_chart): ditto
plugins/openoffice/ChangeLog | 12 +++++
plugins/openoffice/openoffice-read.c | 74 +++++++++++++++++++++++++++--
plugins/openoffice/openoffice-write.c | 85 +++++++++++++++++++++++++++++---
3 files changed, 159 insertions(+), 12 deletions(-)
---
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index ff73562..ee153d0 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,15 @@
+2010-08-18 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * openoffice-write.c (odf_write_line_chart_style): check the plot
+ (odf_write_scatter_chart_style): ditto
+ (odf_get_marker): new
+ (odf_write_scatter_series_style): handle symbol-type
+ and symbol-name
+ (odf_write_plot): add argument to odf_write_series_style
+ * openoffice-read.c (oo_prop_list_to_series): handle symbol-type
+ and symbol-name
+ (od_style_prop_chart): ditto
+
2010-08-17 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-write.c (odf_write_scatter_series_style): expand
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 371d6a8..d87511b 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -84,6 +84,12 @@ attr_eq (xmlChar const *a, char const *s)
return !strcmp (CXML2C (a), s);
}
+enum {
+ OO_SYMBOL_TYPE_AUTO = 1,
+ OO_SYMBOL_TYPE_NONE = 2,
+ OO_SYMBOL_TYPE_NAMED = 3
+};
+
/* Filter Type */
typedef enum {
OOO_VER_UNKNOWN = -1,
@@ -3012,6 +3018,8 @@ oo_prop_list_to_series (GSList *props, GObject *obj)
{
GOStyle *style = NULL;
GSList *l;
+ int symbol_type = -1, symbol_name = GO_MARKER_DIAMOND;
+ GOMarker *m;
g_object_get (obj, "style", &style, NULL);
@@ -3025,9 +3033,33 @@ oo_prop_list_to_series (GSList *props, GObject *obj)
style->line.dash_type = GO_LINE_SOLID;
style->line.auto_dash = FALSE;
}
- }
+ } else if (0 == strcmp (prop->name, "symbol-type"))
+ symbol_type = g_value_get_int (&prop->value);
+ else if (0 == strcmp (prop->name, "symbol-name"))
+ symbol_name = g_value_get_int (&prop->value);
}
+
+ switch (symbol_type) {
+ case OO_SYMBOL_TYPE_AUTO:
+ style->marker.auto_shape = TRUE;
+ break;
+ case OO_SYMBOL_TYPE_NONE:
+ style->marker.auto_shape = FALSE;
+ m = go_marker_new ();
+ go_marker_set_shape (m, GO_MARKER_NONE);
+ go_style_set_marker (style, m);
+ break;
+ case OO_SYMBOL_TYPE_NAMED:
+ style->marker.auto_shape = FALSE;
+ m = go_marker_new ();
+ go_marker_set_shape (m, symbol_name);
+ go_style_set_marker (style, m);
+ break;
+ default:
+ break;
+ }
+
g_object_set (obj, "style", style, NULL);
g_object_unref (G_OBJECT (style));
}
@@ -3101,6 +3133,31 @@ oo_style_have_multi_series (GSList *styles)
static void
od_style_prop_chart (GsfXMLIn *xin, xmlChar const **attrs)
{
+ static OOEnum const symbol_type [] = {
+ {"automatic" , OO_SYMBOL_TYPE_AUTO},
+ {"none" , OO_SYMBOL_TYPE_NONE},
+ {"named-symbol", OO_SYMBOL_TYPE_NAMED},
+ {NULL , 0},
+ };
+ static OOEnum const named_symbols [] = {
+ { "square", GO_MARKER_SQUARE},
+ { "diamond", GO_MARKER_DIAMOND},
+ { "arrow-down", GO_MARKER_TRIANGLE_DOWN},
+ { "arrow-up", GO_MARKER_TRIANGLE_UP},
+ { "arrow-right", GO_MARKER_TRIANGLE_RIGHT},
+ { "arrow-left", GO_MARKER_TRIANGLE_LEFT},
+ { "circle", GO_MARKER_CIRCLE},
+ { "x", GO_MARKER_X},
+ { "plus", GO_MARKER_CROSS},
+ { "asterisk", GO_MARKER_ASTERISK},
+ { "horizontal-bar", GO_MARKER_BAR},
+ { "bow-tie", GO_MARKER_BUTTERFLY},
+ { "hourglass", GO_MARKER_HOURGLASS},
+ { "star", GO_MARKER_LEFT_HALF_BAR},
+ { "vertical-bar", GO_MARKER_HALF_BAR},
+ { NULL, 0},
+ };
+
OOParseState *state = (OOParseState *)xin->user_state;
OOChartStyle *style = state->chart.cur_graph_style;
gboolean btmp;
@@ -3158,12 +3215,21 @@ od_style_prop_chart (GsfXMLIn *xin, xmlChar const **attrs)
} else if (oo_attr_int (xin, attrs, OO_NS_CHART, "gap-width", &tmp))
style->plot_props = g_slist_prepend (style->plot_props,
oo_prop_new_int ("gap-percentage", tmp));
- else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_CHART, "symbol-type"))
+ else if (oo_attr_enum (xin, attrs, OO_NS_CHART, "symbol-type",
+ symbol_type, &tmp)) {
style->plot_props = g_slist_prepend
(style->plot_props,
oo_prop_new_bool ("default-style-has-markers",
- !attr_eq (attrs[1], "none")));
- else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_DRAW, "stroke")) {
+ tmp != OO_SYMBOL_TYPE_NONE));
+ style->series_props = g_slist_prepend
+ (style->series_props,
+ oo_prop_new_int ("symbol-type", tmp));
+ } else if (oo_attr_enum (xin, attrs, OO_NS_CHART, "symbol-name",
+ named_symbols, &tmp)) {
+ style->series_props = g_slist_prepend
+ (style->series_props,
+ oo_prop_new_int ("symbol-name", tmp));
+ } else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_DRAW, "stroke")) {
draw_stroke = !attr_eq (attrs[1], "none");
draw_stroke_set = TRUE;
style->series_props = g_slist_prepend
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 54b9993..cc238a7 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -3635,14 +3635,26 @@ odf_write_ring_plot_style (GnmOOExport *state, G_GNUC_UNUSED GogObject const *ch
}
static void
-odf_write_line_chart_style (GnmOOExport *state, G_GNUC_UNUSED GogObject const *chart, G_GNUC_UNUSED GogObject const *plot)
+odf_write_line_chart_style (GnmOOExport *state, G_GNUC_UNUSED GogObject const *chart, GogObject const *plot)
{
- gsf_xml_out_add_cstr (state->xml, CHART "symbol-type", "none");
+ gboolean has_marker = TRUE;
+ g_object_get (G_OBJECT (plot), "default-style-has-markers",
+ &has_marker, NULL);
+
+ gsf_xml_out_add_cstr (state->xml, CHART "symbol-type",
+ has_marker ? "automatic" : "none");
}
static void
-odf_write_scatter_chart_style (GnmOOExport *state, G_GNUC_UNUSED GogObject const *chart, G_GNUC_UNUSED GogObject const *plot)
+odf_write_scatter_chart_style (GnmOOExport *state, G_GNUC_UNUSED GogObject const *chart, GogObject const *plot)
{
+ gboolean has_marker = TRUE;
+ g_object_get (G_OBJECT (plot), "default-style-has-markers",
+ &has_marker, NULL);
+
+ gsf_xml_out_add_cstr (state->xml, CHART "symbol-type",
+ has_marker ? "automatic" : "none");
+
gsf_xml_out_add_cstr (state->xml, DRAW "stroke", "none");
odf_add_bool (state->xml, CHART "lines", FALSE);
}
@@ -3667,10 +3679,44 @@ odf_write_contour_chart_style (GnmOOExport *state, G_GNUC_UNUSED GogObject const
odf_add_bool (state->xml, CHART "three-dimensional", FALSE);
}
+static char const *
+odf_get_marker (GOMarkerShape m)
+{
+ static struct {
+ guint m;
+ char const *str;
+ } marks [] =
+ {{GO_MARKER_NONE, "none"},
+ {GO_MARKER_SQUARE, "square"},
+ {GO_MARKER_DIAMOND,"diamond"},
+ {GO_MARKER_TRIANGLE_DOWN,"arrow-down"},
+ {GO_MARKER_TRIANGLE_UP,"arrow-up"},
+ {GO_MARKER_TRIANGLE_RIGHT,"arrow-right"},
+ {GO_MARKER_TRIANGLE_LEFT,"arrow-left"},
+ {GO_MARKER_CIRCLE,"circle"},
+ {GO_MARKER_X,"x"},
+ {GO_MARKER_CROSS,"plus"},
+ {GO_MARKER_ASTERISK,"asterisk"},
+ {GO_MARKER_BAR,"horizontal-bar"},
+ {GO_MARKER_HALF_BAR,"vertical-bar"}, /* Not ODF */
+ {GO_MARKER_BUTTERFLY,"bow-tie"},
+ {GO_MARKER_HOURGLASS,"hourglass"},
+ {GO_MARKER_LEFT_HALF_BAR,"star"},/* Not ODF */
+ {GO_MARKER_MAX, "star"}, /* not used by us */
+ {GO_MARKER_MAX + 1, "vertical-bar"},/* not used by us */
+ {0, NULL}
+ };
+ int i;
+ for (i = 0; marks[i].str != NULL; i++)
+ if (marks[i].m == m)
+ return marks[i].str;
+ return "diamond";
+}
+
static void
-odf_write_scatter_series_style (GnmOOExport *state, GogObject const *series)
+odf_write_scatter_series_style (GnmOOExport *state, GogObject const *plot, GogObject const *series)
{
- GOStyle const *style = NULL;
+ GOStyle *style = NULL;
g_object_get (G_OBJECT (series), "style", &style, NULL);
@@ -3681,7 +3727,30 @@ odf_write_scatter_series_style (GnmOOExport *state, GogObject const *series)
gsf_xml_out_add_cstr (state->xml, DRAW "stroke", "none");
odf_add_bool (state->xml, CHART "lines", FALSE);
}
- gsf_xml_out_add_cstr (state->xml, CHART "symbol-type", "automatic");
+
+ if (style->marker.auto_shape) {
+ gboolean has_marker = TRUE;
+ g_object_get (G_OBJECT (plot), "default-style-has-markers",
+ &has_marker, NULL);
+ if (has_marker)
+ gsf_xml_out_add_cstr (state->xml, CHART "symbol-type",
+ "automatic");
+ else
+ gsf_xml_out_add_cstr (state->xml, CHART "symbol-type",
+ "none");
+ } else {
+ GOMarkerShape m
+ = go_marker_get_shape (go_style_get_marker (style));
+ if (m == GO_MARKER_NONE)
+ gsf_xml_out_add_cstr (state->xml, CHART "symbol-type",
+ "none");
+ else {
+ gsf_xml_out_add_cstr (state->xml, CHART "symbol-type",
+ "named-symbol");
+ gsf_xml_out_add_cstr
+ (state->xml, CHART "symbol-name", odf_get_marker (m));
+ }
+ }
g_object_unref (G_OBJECT (style));
}
@@ -3921,7 +3990,7 @@ odf_write_plot (GnmOOExport *state, SheetObject *so, GogObject const *chart, Gog
void (*odf_write_plot_styles) (GnmOOExport *state, GogObject const *chart,
GogObject const *plot);
void (*odf_write_series) (GnmOOExport *state, GSList const *series);
- void (*odf_write_series_style) (GnmOOExport *state, GogObject const *series);
+ void (*odf_write_series_style) (GnmOOExport *state, GogObject const * plot, GogObject const *series);
void (*odf_write_x_axis) (GnmOOExport *state, GogObject const *chart,
char const *axis_role, char const *style_label,
char const *dimension, odf_chart_type_t gtype,
@@ -4060,7 +4129,7 @@ odf_write_plot (GnmOOExport *state, SheetObject *so, GogObject const *chart, Gog
gsf_xml_out_start_element (state->xml, STYLE "chart-properties");
odf_add_bool (state->xml, CHART "auto-size", TRUE);
if (this_plot->odf_write_series_style != NULL)
- this_plot->odf_write_series_style (state, l->data);
+ this_plot->odf_write_series_style (state, plot, l->data);
gsf_xml_out_end_element (state->xml); /* </style:chart-properties> */
gsf_xml_out_end_element (state->xml); /* </style:style> */
g_free (name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]