[gnumeric] xlsx: improve roundtrip.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] xlsx: improve roundtrip.
- Date: Tue, 24 Mar 2015 13:19:51 +0000 (UTC)
commit c80645043b67303f52a212102f0ee26c29467b85
Author: Morten Welinder <terra gnome org>
Date: Tue Mar 24 09:19:06 2015 -0400
xlsx: improve roundtrip.
This uses extensions for handling auto-dash and a few marker types
that XL lacks.
NEWS | 1 +
plugins/excel/xlsx-read-drawing.c | 22 +++++++++++++--
plugins/excel/xlsx-write-drawing.c | 53 +++++++++++++++++++++++++++++-------
3 files changed, 63 insertions(+), 13 deletions(-)
---
diff --git a/NEWS b/NEWS
index c3559c0..8923094 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ Morten:
* Fix PERMUATIONA corner case.
* Fix RANDLOG.
* Fix RANDGEOM to use same distribution as R.DGEOM.
+ * Improve xlsx roundtrip of GOStyle.
--------------------------------------------------------------------------
Gnumeric 1.12.21
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index f864ea6..2a18cbc 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -2215,6 +2215,22 @@ xlsx_ext_gostyle (GsfXMLIn *xin, xmlChar const **attrs)
end_arrow->c = f;
} else if (attr_bool (xin, attrs, "reverse-gradient", &rev_gradient)) {
/* Nothing */
+ } else if (strcmp (attrs[0], "markerSymbol") == 0) {
+ const char *s = attrs[1];
+ if (strcmp (s, "auto") == 0) {
+ style->marker.auto_shape = TRUE;
+ } else {
+ style->marker.auto_shape = FALSE;
+ go_marker_set_shape (style->marker.mark, go_marker_shape_from_str (s));
+ }
+ } else if (strcmp (attrs[0], "dashType") == 0) {
+ const char *s = attrs[1];
+ if (strcmp (s, "auto") == 0) {
+ style->line.auto_dash = TRUE;
+ } else {
+ style->line.auto_dash = FALSE;
+ style->line.dash_type = go_line_dash_from_str (s);
+ }
}
}
@@ -2563,6 +2579,9 @@ GSF_XML_IN_NODE_FULL (START, CHART_SPACE, XL_NS_CHART, "chartSpace", GSF_XML_NO_
GSF_XML_IN_NODE (MARKER, SHAPE_PR, XL_NS_CHART, "spPr", GSF_XML_NO_CONTENT, NULL, NULL),
/* 2nd Def */
GSF_XML_IN_NODE (MARKER, MARKER_SYMBOL, XL_NS_CHART, "symbol", GSF_XML_NO_CONTENT,
&xlsx_chart_marker_symbol, NULL),
GSF_XML_IN_NODE (MARKER, MARKER_SIZE, XL_NS_CHART, "size", GSF_XML_NO_CONTENT,
&xlsx_chart_marker_size, NULL),
+ GSF_XML_IN_NODE (MARKER, EXTLST_C, XL_NS_CHART, "extLst", GSF_XML_NO_CONTENT, NULL, NULL),
+ GSF_XML_IN_NODE (EXTLST_C, EXTITEM_C, XL_NS_CHART, "ext", GSF_XML_NO_CONTENT,
&xlsx_ext_begin, &xlsx_ext_end),
+ GSF_XML_IN_NODE (EXTITEM_C, EXT_GOSTYLE, XL_NS_GNM_EXT, "gostyle", GSF_XML_NO_CONTENT,
NULL, NULL), /* 2nd Def */
GSF_XML_IN_NODE (SERIES, SERIES_ERR_BARS, XL_NS_CHART,"errBars", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (SERIES_ERR_BARS, SERIES_ERR_BARS_ERRBARTYPE, XL_NS_CHART, "errBarType",
GSF_XML_NO_CONTENT, NULL, NULL),
@@ -2598,9 +2617,6 @@ GSF_XML_IN_NODE_FULL (START, CHART_SPACE, XL_NS_CHART, "chartSpace", GSF_XML_NO_
GSF_XML_IN_NODE (LINE, PLOT_AXIS_ID, XL_NS_CHART,"axId", GSF_XML_NO_CONTENT, NULL, NULL),
/* 2nd Def */
GSF_XML_IN_NODE (LINE, SERIES, XL_NS_CHART, "ser", GSF_XML_NO_CONTENT, NULL, NULL),
/* 2nd Def */
GSF_XML_IN_NODE (SERIES, MARKER, XL_NS_CHART, "marker", GSF_XML_NO_CONTENT, NULL, NULL),
- GSF_XML_IN_NODE (MARKER, SHAPE_PR, XL_NS_CHART, "spPr", GSF_XML_NO_CONTENT, NULL, NULL),
/* 2nd Def */
- GSF_XML_IN_NODE (MARKER, MARKER_SYMBOL, XL_NS_CHART, "symbol", GSF_XML_NO_CONTENT, NULL, NULL),
- GSF_XML_IN_NODE (MARKER, MARKER_SIZE, XL_NS_CHART, "size", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (LINE, PLOT_AXIS_ID, XL_NS_CHART,"axId", GSF_XML_NO_CONTENT, NULL, NULL),
/* 2nd Def */
GSF_XML_IN_NODE (LINE, GROUPING, XL_NS_CHART, "grouping", GSF_XML_NO_CONTENT, NULL, NULL),
/* 2nd Def */
GSF_XML_IN_NODE (LINE, LINE_MARKER, XL_NS_CHART, "marker", GSF_XML_NO_CONTENT,
&xlsx_chart_line_marker, NULL),
diff --git a/plugins/excel/xlsx-write-drawing.c b/plugins/excel/xlsx-write-drawing.c
index cded54c..52f4327 100644
--- a/plugins/excel/xlsx-write-drawing.c
+++ b/plugins/excel/xlsx-write-drawing.c
@@ -228,9 +228,11 @@ xlsx_write_go_style_marker (GsfXMLOut *xml, GOStyle *style, const XLSXStyleConte
"diamond", /* GO_MARKER_HOURGLASS */ /* FIXME: dubious */
"dot" /* GO_MARKER_LEFT_HALF_BAR */
};
- static gint8 nqturns[] = { 0, 0, 0, 2, 0, +1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- static gint8 flipH[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 };
+ static const gint8 nqturns[] = { 0, 0, 0, 2, 0, +1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ static const gint8 flipH[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 };
+ static const gint8 extS[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 };
gboolean need_spPr;
+ gboolean ext_symbol = FALSE;
GOMarkerShape s;
if ((style->interesting_fields & GO_STYLE_MARKER) == 0)
@@ -239,6 +241,10 @@ xlsx_write_go_style_marker (GsfXMLOut *xml, GOStyle *style, const XLSXStyleConte
s = style->marker.auto_shape
? (sctx->def_has_markers ? GO_MARKER_MAX : GO_MARKER_NONE)
: go_marker_get_shape (style->marker.mark);
+ if (!style->marker.auto_shape && s < G_N_ELEMENTS (extS) && extS[s])
+ ext_symbol = TRUE;
+ if (style->marker.auto_shape && s == GO_MARKER_NONE)
+ ext_symbol = TRUE;
gsf_xml_out_start_element (xml, "c:marker");
@@ -285,6 +291,24 @@ xlsx_write_go_style_marker (GsfXMLOut *xml, GOStyle *style, const XLSXStyleConte
gsf_xml_out_end_element (xml);
}
+ if (sctx->state->with_extension && ext_symbol) {
+ gsf_xml_out_start_element (xml, "c:extLst");
+ gsf_xml_out_start_element (xml, "c:ext");
+ gsf_xml_out_add_cstr_unchecked (xml, "uri", ns_gnm_ext);
+ gsf_xml_out_start_element (xml, "gnmx:gostyle");
+
+ if (ext_symbol) {
+ gsf_xml_out_add_cstr (xml, "markerSymbol",
+ style->marker.auto_shape
+ ? "auto"
+ : go_marker_shape_as_str (s));
+ }
+
+ gsf_xml_out_end_element (xml); /* "gnmx:gostyle" */
+ gsf_xml_out_end_element (xml); /* "c:ext" */
+ gsf_xml_out_end_element (xml); /* "c:extLst" */
+ }
+
gsf_xml_out_end_element (xml);
}
@@ -298,6 +322,7 @@ xlsx_write_go_style_full (GsfXMLOut *xml, GOStyle *style, const XLSXStyleContext
gboolean ext_start_arrow = FALSE;
gboolean ext_end_arrow = FALSE;
gboolean ext_gradient_rev = FALSE;
+ gboolean ext_dash_type = FALSE;
char *spPr_tag = g_strconcat (sctx->spPr_ns, ":spPr", NULL);
@@ -481,12 +506,15 @@ xlsx_write_go_style_full (GsfXMLOut *xml, GOStyle *style, const XLSXStyleContext
NULL);
}
- if (!style->line.auto_dash &&
- style->line.dash_type < G_N_ELEMENTS (dashes) &&
- dashes[style->line.dash_type]) {
- xlsx_write_chart_cstr_unchecked (xml,
- "a:prstDash",
- dashes[style->line.dash_type]);
+ if (style->line.auto_dash) {
+ ext_dash_type = TRUE;
+ } else {
+ if (style->line.dash_type < G_N_ELEMENTS (dashes) &&
+ dashes[style->line.dash_type]) {
+ xlsx_write_chart_cstr_unchecked (xml,
+ "a:prstDash",
+ dashes[style->line.dash_type]);
+ }
}
for (i = 0; i < 2; i++) {
@@ -528,12 +556,17 @@ xlsx_write_go_style_full (GsfXMLOut *xml, GOStyle *style, const XLSXStyleContext
if (sctx->state->with_extension &&
(ext_fill_pattern || ext_start_arrow || ext_end_arrow ||
- ext_gradient_rev)) {
- /* What namespace do we use? */
+ ext_gradient_rev || ext_dash_type)) {
gsf_xml_out_start_element (xml, "a:extLst");
gsf_xml_out_start_element (xml, "a:ext");
gsf_xml_out_add_cstr_unchecked (xml, "uri", ns_gnm_ext);
gsf_xml_out_start_element (xml, "gnmx:gostyle");
+ if (ext_dash_type) {
+ gsf_xml_out_add_cstr (xml, "dashType",
+ style->line.auto_dash
+ ? "auto"
+ : go_line_dash_as_str (style->line.dash_type));
+ }
if (ext_fill_pattern) {
gsf_xml_out_add_cstr (xml, "pattern", go_pattern_as_str
(style->fill.pattern.pattern));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]