[gnumeric] Accept formulas in chart title when importing from xlsx.
- From: Jean Bréfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Accept formulas in chart title when importing from xlsx.
- Date: Sat, 5 Mar 2011 19:29:57 +0000 (UTC)
commit 3ae5efc54acb05167cfce2b5f456eb8f02e16d18
Author: Jean Brefort <jean brefort normalesup org>
Date: Sat Mar 5 20:29:27 2011 +0100
Accept formulas in chart title when importing from xlsx.
plugins/excel/ChangeLog | 7 ++++
plugins/excel/xlsx-read.c | 27 +++++++++++---
plugins/excel/xlsx-write.c | 84 ++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 110 insertions(+), 8 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 0f2ea0a..84a2807 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,12 @@
2011-03-05 Jean Brefort <jean brefort normalesup org>
+ * xlsx-read.c (xlsx_chart_ser_f), (xlsx_chart_text_start),
+ (xlsx_chart_text): accept formulas in labels.
+ * xlsx-write.c (xlsx_write_series_dim), (xlsx_write_rgbarea),
+ (xlsx_write_go_style), (xlsx_write_chart): export chart background.
+
+2011-03-05 Jean Brefort <jean brefort normalesup org>
+
* xlsx-read.c (xlsx_chart_xy), (xlsx_scatter_style): import the scatter
plot default series style.
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index 1416f9b..6ace999 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -1423,6 +1423,13 @@ xlsx_chart_ser_f (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
(state->dim_type != GOG_MS_DIM_LABELS)
? gnm_go_data_vector_new_expr (state->sheet, texpr)
: gnm_go_data_scalar_new_expr (state->sheet, texpr));
+ } else if (GOG_IS_LABEL (state->cur_obj)) {
+ GnmParsePos pp;
+ GnmExprTop const *texpr = xlsx_parse_expr (xin, xin->content->str,
+ parse_pos_init_sheet (&pp, state->sheet));
+
+ gog_dataset_set_dim (GOG_DATASET (state->cur_obj), 0,
+ gnm_go_data_scalar_new_expr (state->sheet, texpr), NULL);
}
}
@@ -1722,20 +1729,30 @@ xlsx_chart_marker_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
}
static void
+xlsx_chart_text_start (GsfXMLIn *xin, G_GNUC_UNUSED xmlChar const **attrs)
+{
+ XLSXReadState *state = (XLSXReadState *)xin->user_state;
+ if (NULL == state->series) { /* Hmm, why? */
+ GogObject *label = gog_object_add_by_name (state->cur_obj,
+ (state->cur_obj == (GogObject *)state->chart) ? "Title" : "Label", NULL);
+ xlsx_chart_push_obj (state, label);
+ }
+}
+
+static void
xlsx_chart_text (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
{
XLSXReadState *state = (XLSXReadState *)xin->user_state;
if (NULL == state->series) {
- GogObject *label = gog_object_add_by_name (state->cur_obj,
- (state->cur_obj == (GogObject *)state->chart) ? "Title" : "Label", NULL);
- if (NULL != label && state->chart_tx) {
+ if (state->cur_obj && state->chart_tx) {
GnmValue *value = value_new_string_nocopy (state->chart_tx);
GnmExprTop const *texpr = gnm_expr_top_new_constant (value);
- gog_dataset_set_dim (GOG_DATASET (label), 0,
+ gog_dataset_set_dim (GOG_DATASET (state->cur_obj), 0,
gnm_go_data_scalar_new_expr (state->sheet, texpr), NULL);
state->chart_tx = NULL;
}
+ xlsx_chart_pop_obj (state);
}
g_free (state->chart_tx);
state->chart_tx = NULL;
@@ -1903,7 +1920,7 @@ GSF_XML_IN_NODE_FULL (START, CHART_SPACE, XL_NS_CHART, "chartSpace", GSF_XML_NO_
GSF_XML_IN_NODE (MAN_LAYOUT, MAN_LAYOUT_Y, XL_NS_CHART, "y", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (MAN_LAYOUT, MAN_LAYOUT_YMODE, XL_NS_CHART, "yMode", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (TITLE, SHAPE_PR, XL_NS_CHART, "spPr", GSF_XML_NO_CONTENT, NULL, NULL), /* 2nd Def */
- GSF_XML_IN_NODE (TITLE, TEXT, XL_NS_CHART, "tx", GSF_XML_NO_CONTENT, NULL, &xlsx_chart_text),
+ GSF_XML_IN_NODE (TITLE, TEXT, XL_NS_CHART, "tx", GSF_XML_NO_CONTENT, &xlsx_chart_text_start, &xlsx_chart_text),
GSF_XML_IN_NODE (TEXT, TX_RICH, XL_NS_CHART, "rich", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (TX_RICH, TX_RICH_BODY, XL_NS_CHART, "bodyP", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (TX_RICH, TX_RICH_BODY_PR, XL_NS_DRAW, "bodyPr", GSF_XML_NO_CONTENT, NULL, NULL),
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 129853e..d0577e1 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -955,9 +955,18 @@ xlsx_write_plot_1_5_type (GsfXMLOut *xml, GogObject const *plot)
static void
xlsx_write_series_dim (XLSXWriteState *state, GsfXMLOut *xml, GogSeries const *series,
- char const *name, int dim)
+ char const *name, GogMSDimType ms_type)
{
- GOData const *dat = gog_dataset_get_dim (GOG_DATASET (series), dim);
+ GogSeriesDesc const *desc = &gog_plot_description (gog_series_get_plot (series))->series;
+ unsigned dim;
+ GOData const *dat;
+
+ for (dim = 0; dim < desc->num_dim; dim++)
+ if (desc->dim[dim].ms_type == ms_type)
+ break;
+ if (dim == desc->num_dim)
+ return;
+ dat = gog_dataset_get_dim (GOG_DATASET (series), dim);
if (NULL != dat) {
GnmExprTop const *texpr = gnm_go_data_get_expr (dat);
if (NULL != texpr) {
@@ -977,6 +986,60 @@ xlsx_write_series_dim (XLSXWriteState *state, GsfXMLOut *xml, GogSeries const *s
}
static void
+xlsx_write_rgbarea (GsfXMLOut *xml, GOColor color)
+{
+ char *buf = g_strdup_printf ("%06x", (guint) color >> 8);
+ int alpha = GO_COLOR_UINT_A (color);
+ gsf_xml_out_start_element (xml, "a:srgbClr");
+ gsf_xml_out_add_cstr_unchecked (xml, "val", buf);
+ g_free (buf);
+ if (alpha < 255) {
+ gsf_xml_out_start_element (xml, "a:alpha");
+ gsf_xml_out_add_int (xml, "val", alpha * 100000 / 255);
+ gsf_xml_out_end_element (xml);
+ }
+ gsf_xml_out_end_element (xml);
+}
+
+static void
+xlsx_write_go_style (GsfXMLOut *xml, GOStyle *style)
+{
+ if (style->interesting_fields & (GO_STYLE_LINE | GO_STYLE_OUTLINE)) {
+ gsf_xml_out_start_element (xml, "c:spPr");
+ switch (style->fill.type) {
+ default :
+ g_warning ("invalid fill type, saving as none");
+ case GO_STYLE_FILL_IMAGE:
+ /* FIXME: export image */
+ case GO_STYLE_FILL_NONE:
+ /* hmm, how should we do that? */
+ break;
+ case GO_STYLE_FILL_PATTERN:
+ switch (style->fill.pattern.pattern) {
+ case GO_PATTERN_SOLID:
+ gsf_xml_out_start_element (xml, "a:solidFill");
+ xlsx_write_rgbarea (xml, style->fill.pattern.back);
+ gsf_xml_out_end_element (xml);
+ break;
+ case GO_PATTERN_FOREGROUND_SOLID:
+ gsf_xml_out_start_element (xml, "a:solidFill");
+ xlsx_write_rgbarea (xml, style->fill.pattern.fore);
+ gsf_xml_out_end_element (xml);
+ break;
+ }
+ break;
+ case GO_STYLE_FILL_GRADIENT:
+ break;
+ }
+ gsf_xml_out_end_element (xml);
+ }
+ if (style->interesting_fields & GO_STYLE_FILL) {
+ }
+ if (style->interesting_fields & GO_STYLE_MARKER) {
+ }
+}
+
+static void
xlsx_write_chart (XLSXWriteState *state, GsfOutput *chart_part, SheetObject *so)
{
GogGraph const *graph;
@@ -1003,9 +1066,11 @@ xlsx_write_chart (XLSXWriteState *state, GsfOutput *chart_part, SheetObject *so)
gsf_xml_out_add_cstr_unchecked (xml, "xmlns:c", ns_chart);
gsf_xml_out_add_cstr_unchecked (xml, "xmlns:a", ns_drawing);
gsf_xml_out_add_cstr_unchecked (xml, "xmlns:r", ns_rel);
+ xlsx_write_go_style (xml, go_styled_object_get_style (GO_STYLED_OBJECT (chart)));
gsf_xml_out_start_element (xml, "c:chart");
gsf_xml_out_start_element (xml, "c:plotArea");
+ /* save grid style here */
if (0 == strcmp (plot_type, "GogAreaPlot")) {
gsf_xml_out_start_element (xml, "c:areaChart");
xlsx_write_plot_1_5_type (xml, plot);
@@ -1025,7 +1090,7 @@ xlsx_write_chart (XLSXWriteState *state, GsfOutput *chart_part, SheetObject *so)
gsf_xml_out_start_element (xml, "c:overlap");
gsf_xml_out_add_int (xml, "val", -overlap_percentage);
gsf_xml_out_end_element (xml); /* </c:grouping> */
-
+
gsf_xml_out_start_element (xml, "c:gapWidth");
gsf_xml_out_add_int (xml, "val", gap_percentage);
gsf_xml_out_end_element (xml); /* </c:grouping> */
@@ -1076,8 +1141,21 @@ xlsx_write_chart (XLSXWriteState *state, GsfOutput *chart_part, SheetObject *so)
xlsx_write_chart_bool (xml, "c:bubble3D", TRUE);
use_xy = TRUE;
} else if ( 0 == strcmp (plot_type, "GogXYPlot")) {
+ gboolean has_lines, has_markers, use_splines;
+ char const *style;
+ g_object_get (G_OBJECT (plot),
+ "default-style-has-lines", &has_lines,
+ "default-style-has-markers", &has_markers,
+ "use-splines", &use_splines,
+ NULL);
+ style = (has_lines)?
+ (use_splines?
+ (has_markers? "smoothMarker": "smooth"):
+ (has_markers? "lineMarker": "line")):
+ (has_markers? "markers": "none");
use_xy = TRUE;
gsf_xml_out_start_element (xml, "c:scatterChart");
+ xlsx_write_chart_cstr_unchecked (xml, "c:scatterStyle", style);
} else if (0 == strcmp (plot_type, "GogContourPlot") ||
0 == strcmp (plot_type, "XLContourPlot")) {
gsf_xml_out_start_element (xml, "c:surfaceChart");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]