[gnumeric] xlsx: improve export and import of passive sheet widgets.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] xlsx: improve export and import of passive sheet widgets.
- Date: Mon, 9 Feb 2015 16:56:08 +0000 (UTC)
commit 3d3def126427c05bdb39a31d6c14aaa2a4f5e324
Author: Morten Welinder <terra gnome org>
Date: Mon Feb 9 11:55:35 2015 -0500
xlsx: improve export and import of passive sheet widgets.
plugins/excel/xlsx-read-drawing.c | 45 +++++++++---
plugins/excel/xlsx-write-drawing.c | 130 +++++++++++++++++++++++-------------
plugins/excel/xlsx-write.c | 6 ++-
3 files changed, 121 insertions(+), 60 deletions(-)
---
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index 9154c11..d910eb8 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -2714,16 +2714,37 @@ static void
xlsx_drawing_preset_geom (GsfXMLIn *xin, xmlChar const **attrs)
{
XLSXReadState *state = (XLSXReadState *)xin->user_state;
+
+ static EnumVal const types[] = {
+ { "rect", 0 },
+ { "ellipse", 1 },
+ { "line", 2 },
+ { NULL, 0 }
+ };
+ int typ = -1;
+
if (NULL != state->so) /* FIXME FIXME FIXME: how does this happen? */
return;
- for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
- if (!strcmp (attrs[0], "prst")) {
- /* TODO, use a hash here for all preset geometries */
- if (!strcmp (attrs[1], "rect"))
- state->so = g_object_new (GNM_SO_FILLED_TYPE, "is_oval", FALSE, NULL);
- else if (!strcmp (attrs[1], "line"))
- state->so = g_object_new (GNM_SO_LINE_TYPE, NULL);
- }
+
+ for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) {
+ if (attr_enum (xin, attrs, "prst", types, &typ))
+ ; /* Nothing */
+ }
+
+ switch (typ) {
+ case 0:
+ state->so = g_object_new (GNM_SO_FILLED_TYPE, "is_oval", FALSE, NULL);
+ break;
+ case 1:
+ state->so = g_object_new (GNM_SO_FILLED_TYPE, "is_oval", TRUE, NULL);
+ break;
+ case 2:
+ state->so = g_object_new (GNM_SO_LINE_TYPE, NULL);
+ break;
+ default:
+ break;
+ }
+
if (state->so) {
GOStyle *style = NULL;
if (g_object_class_find_property (G_OBJECT_GET_CLASS (state->so), "style"))
@@ -2809,9 +2830,9 @@ GSF_XML_IN_NODE_FULL (START, DRAWING, XL_NS_SS_DRAW, "wsDr", GSF_XML_NO_CONTENT,
GSF_XML_IN_NODE (SP_XFRM_OFF, SP_PR_PRST_GEOM, XL_NS_DRAW, "prstGeom", GSF_XML_NO_CONTENT, NULL,
NULL),
GSF_XML_IN_NODE (SP_XFRM_OFF, SHAPE_PR_LN, XL_NS_DRAW, "ln", GSF_XML_NO_CONTENT,
xlsx_style_line_start, &xlsx_style_line_end),
GSF_XML_IN_NODE (SHAPE_PR_LN, LN_NOFILL, XL_NS_DRAW, "noFill", GSF_XML_NO_CONTENT, NULL, NULL),
- GSF_XML_IN_NODE (SHAPE_PR_LN, LN_DASH, XL_NS_DRAW, "prstDash", GSF_XML_NO_CONTENT,
&xlsx_draw_line_dash, NULL), /* 2nd Def */
- GSF_XML_IN_NODE (SHAPE_PR_LN, FILL_SOLID, XL_NS_DRAW, "solidFill", GSF_XML_NO_CONTENT, NULL,
NULL), /* 2nd Def */
- GSF_XML_IN_NODE (SHAPE_PR_LN, FILL_PATT, XL_NS_DRAW, "pattFill", GSF_XML_NO_CONTENT, NULL,
NULL), /* 2nd Def */
+ GSF_XML_IN_NODE (SHAPE_PR_LN, LN_DASH, XL_NS_DRAW, "prstDash", GSF_XML_NO_CONTENT,
&xlsx_draw_line_dash, NULL),
+ GSF_XML_IN_NODE (SHAPE_PR_LN, FILL_SOLID, XL_NS_DRAW, "solidFill", GSF_XML_NO_CONTENT,
&xlsx_chart_solid_fill, &xlsx_chart_solid_fill_end),
+ GSF_XML_IN_NODE (SHAPE_PR_LN, FILL_PATT, XL_NS_DRAW, "pattFill", GSF_XML_NO_CONTENT, NULL,
NULL),
GSF_XML_IN_NODE (SHAPE_PR_LN, LN_MITER, XL_NS_DRAW, "miter", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (SHAPE_PR_LN, LN_ROUND, XL_NS_DRAW, "round", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (SHAPE_PR_LN, LN_HEAD, XL_NS_DRAW, "headEnd", GSF_XML_NO_CONTENT, NULL,
NULL),
@@ -3298,7 +3319,7 @@ xlsx_vml_horiz (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
horiz = FALSE;
else
return; /* Blank means default. */
- //sheet_widget_adjustment_set_horizontal (state->so, horiz);
+ sheet_widget_adjustment_set_horizontal (state->so, horiz);
}
}
diff --git a/plugins/excel/xlsx-write-drawing.c b/plugins/excel/xlsx-write-drawing.c
index 31b1ba3..010d848 100644
--- a/plugins/excel/xlsx-write-drawing.c
+++ b/plugins/excel/xlsx-write-drawing.c
@@ -188,13 +188,21 @@ xlsx_write_rpr (GsfXMLOut *xml, GOStyle *style)
static void
xlsx_write_go_style_full (GsfXMLOut *xml, GOStyle *style,
- gboolean def_has_markers, gboolean def_has_lines)
+ gboolean def_has_markers, gboolean def_has_lines,
+ const char *ns, const char *shapename)
{
gboolean has_font_color = ((style->interesting_fields & GO_STYLE_FONT) &&
!style->font.auto_color);
gboolean has_font = xlsx_go_style_has_font (style);
+ char *spPr_tag = g_strconcat (ns, ":spPr", NULL);
- gsf_xml_out_start_element (xml, "c:spPr");
+ gsf_xml_out_start_element (xml, spPr_tag);
+
+ if (shapename) {
+ gsf_xml_out_start_element (xml, "a:prstGeom");
+ gsf_xml_out_add_cstr_unchecked (xml, "prst", shapename);
+ gsf_xml_out_end_element (xml); /* </a:prstGeom> */
+ }
if ((style->interesting_fields & GO_STYLE_FILL) &&
style->fill.type != GO_STYLE_FILL_NONE) {/* TODO add tests for transparent backgrounds */
@@ -272,7 +280,8 @@ xlsx_write_go_style_full (GsfXMLOut *xml, GOStyle *style,
gsf_xml_out_end_element (xml);
}
- gsf_xml_out_end_element (xml); /* "c:spPr" */
+ gsf_xml_out_end_element (xml); /* "NS:spPr" */
+ g_free (spPr_tag);
if (has_font_color || has_font) {
gsf_xml_out_start_element (xml, "c:txPr");
@@ -366,7 +375,7 @@ xlsx_write_go_style_full (GsfXMLOut *xml, GOStyle *style,
static void
xlsx_write_go_style (GsfXMLOut *xml, GOStyle *style)
{
- xlsx_write_go_style_full (xml, style, FALSE, TRUE);
+ xlsx_write_go_style_full (xml, style, FALSE, TRUE, "c", NULL);
}
static void
@@ -686,7 +695,8 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
xlsx_write_chart_int (xml, "c:order", -1, count);
xlsx_write_series_dim (state, xml, ser, "c:tx", GOG_MS_DIM_LABELS);
if (!vary_by_element) /* FIXME: we might loose some style elements */
- xlsx_write_go_style_full (xml, style, has_markers, has_lines);
+ xlsx_write_go_style_full (xml, style, has_markers, has_lines,
+ "c", NULL);
if (set_invert)
xlsx_write_chart_uint (xml, "c:invertIfNegative", 1, 0);
@@ -993,6 +1003,7 @@ xlsx_write_drawing_objects (XLSXWriteState *state, GsfOutput *sheet_part, GSList
gsf_output_close (chart_part);
g_object_unref (chart_part);
} else {
+ /* Lines etc. go here. */
rId1 = NULL;
}
@@ -1012,10 +1023,6 @@ xlsx_write_drawing_objects (XLSXWriteState *state, GsfOutput *sheet_part, GSList
const char *rId1 = rId_ptr->data;
SheetObjectAnchor const *anchor = sheet_object_get_anchor (so);
double res_pts[4] = {0.,0.,0.,0.};
- char *tmp;
-
- if (!rId1)
- continue;
sheet_object_anchor_to_offset_pts (anchor, state->sheet, res_pts);
@@ -1025,48 +1032,77 @@ xlsx_write_drawing_objects (XLSXWriteState *state, GsfOutput *sheet_part, GSList
xlsx_write_object_anchor (xml, &anchor->cell_bound.end, "xdr:to",
res_pts[2], res_pts[3]);
- gsf_xml_out_start_element (xml, "xdr:graphicFrame");
- gsf_xml_out_add_cstr_unchecked (xml, "macro", "");
-
- gsf_xml_out_start_element (xml, "xdr:nvGraphicFramePr");
-
- gsf_xml_out_start_element (xml, "xdr:cNvPr");
- gsf_xml_out_add_int (xml, "id", count+1);
- tmp = g_strdup_printf ("Chart %d", count++);
- gsf_xml_out_add_cstr_unchecked (xml, "name", tmp);
- g_free (tmp);
- gsf_xml_out_end_element (xml);
-
- gsf_xml_out_simple_element (xml, "xdr:cNvGraphicFramePr", NULL);
- gsf_xml_out_end_element (xml); /* </xdr:nvGraphicFramePr> */
-
- gsf_xml_out_start_element (xml, "xdr:xfrm");
-
- gsf_xml_out_start_element (xml, "a:off");
- gsf_xml_out_add_int (xml, "x", 0);
- gsf_xml_out_add_int (xml, "y", 0);
- gsf_xml_out_end_element (xml); /* </a:off> */
+ if (IS_SHEET_OBJECT_GRAPH (so)) {
+ char *tmp;
- gsf_xml_out_start_element (xml, "a:ext");
- gsf_xml_out_add_int (xml, "cx", 0);
- gsf_xml_out_add_int (xml, "cy", 0);
- gsf_xml_out_end_element (xml); /* </a:ext> */
+ gsf_xml_out_start_element (xml, "xdr:graphicFrame");
+ gsf_xml_out_add_cstr_unchecked (xml, "macro", "");
- gsf_xml_out_end_element (xml); /* </xdr:xfrm> */
+ gsf_xml_out_start_element (xml, "xdr:nvGraphicFramePr");
- gsf_xml_out_start_element (xml, "a:graphic");
- gsf_xml_out_start_element (xml, "a:graphicData");
- gsf_xml_out_add_cstr_unchecked (xml, "uri", ns_chart);
- gsf_xml_out_start_element (xml, "c:chart");
- gsf_xml_out_add_cstr_unchecked (xml, "xmlns:c", ns_chart);
- gsf_xml_out_add_cstr_unchecked (xml, "xmlns:r", ns_rel);
+ gsf_xml_out_start_element (xml, "xdr:cNvPr");
+ gsf_xml_out_add_int (xml, "id", count+1);
+ tmp = g_strdup_printf ("Chart %d", count++);
+ gsf_xml_out_add_cstr_unchecked (xml, "name", tmp);
+ g_free (tmp);
+ gsf_xml_out_end_element (xml);
- gsf_xml_out_add_cstr_unchecked (xml, "r:id", rId1);
- gsf_xml_out_end_element (xml); /* </c:chart> */
- gsf_xml_out_end_element (xml); /* </a:graphicData> */
- gsf_xml_out_end_element (xml); /* </a:graphic> */
- gsf_xml_out_end_element (xml); /* </xdr:graphicFrame> */
- gsf_xml_out_simple_element (xml, "xdr:clientData", NULL);
+ gsf_xml_out_simple_element (xml, "xdr:cNvGraphicFramePr", NULL);
+ gsf_xml_out_end_element (xml); /* </xdr:nvGraphicFramePr> */
+
+ gsf_xml_out_start_element (xml, "xdr:xfrm");
+
+ gsf_xml_out_start_element (xml, "a:off");
+ gsf_xml_out_add_int (xml, "x", 0);
+ gsf_xml_out_add_int (xml, "y", 0);
+ gsf_xml_out_end_element (xml); /* </a:off> */
+
+ gsf_xml_out_start_element (xml, "a:ext");
+ gsf_xml_out_add_int (xml, "cx", 0);
+ gsf_xml_out_add_int (xml, "cy", 0);
+ gsf_xml_out_end_element (xml); /* </a:ext> */
+
+ gsf_xml_out_end_element (xml); /* </xdr:xfrm> */
+
+ gsf_xml_out_start_element (xml, "a:graphic");
+ gsf_xml_out_start_element (xml, "a:graphicData");
+ gsf_xml_out_add_cstr_unchecked (xml, "uri", ns_chart);
+ gsf_xml_out_start_element (xml, "c:chart");
+ gsf_xml_out_add_cstr_unchecked (xml, "xmlns:c", ns_chart);
+ gsf_xml_out_add_cstr_unchecked (xml, "xmlns:r", ns_rel);
+
+ gsf_xml_out_add_cstr_unchecked (xml, "r:id", rId1);
+ gsf_xml_out_end_element (xml); /* </c:chart> */
+ gsf_xml_out_end_element (xml); /* </a:graphicData> */
+ gsf_xml_out_end_element (xml); /* </a:graphic> */
+ gsf_xml_out_end_element (xml); /* </xdr:graphicFrame> */
+ gsf_xml_out_simple_element (xml, "xdr:clientData", NULL);
+ } else if (IS_GNM_SO_LINE (so) ||
+ IS_GNM_SO_FILLED (so)) {
+ const char *shapename = "?";
+ GOStyle *style = NULL;
+
+ if (IS_GNM_SO_LINE (so))
+ shapename = "line";
+ else if (IS_GNM_SO_FILLED (so)) {
+ gboolean oval;
+ g_object_get (so, "is-oval", &oval, NULL);
+ shapename = oval ? "ellipse" : "rect";
+ } else {
+ shapename = "?";
+ g_assert_not_reached ();
+ }
+ if (g_object_class_find_property (G_OBJECT_GET_CLASS (so), "style"))
+ g_object_get (so, "style", &style, NULL);
+
+ if (style) {
+ gsf_xml_out_start_element (xml, "xdr:sp");
+ xlsx_write_go_style_full (xml, style, FALSE, FALSE,
+ "xdr", shapename);
+ gsf_xml_out_end_element (xml); /* </xdr:sp> */
+ g_object_unref (style);
+ }
+ }
gsf_xml_out_end_element (xml); /* </xdr:twoCellAnchor> */
}
g_slist_free (rIds);
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 68b4047..b68eab2 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -53,6 +53,8 @@
#include "sheet-object-cell-comment.h"
#include "sheet-object-graph.h"
#include "sheet-object-widget.h"
+#include "gnm-so-line.h"
+#include "gnm-so-filled.h"
#include "graph.h"
#include "style-border.h"
#include "style-conditions.h"
@@ -2708,7 +2710,9 @@ xlsx_write_sheet (XLSXWriteState *state, GsfOutfile *dir, GsfOutfile *wb_part, u
SheetObject *so = p->data;
if (IS_CELL_COMMENT (so))
comments = g_slist_prepend (comments, so);
- else if (IS_SHEET_OBJECT_GRAPH (so))
+ else if (IS_SHEET_OBJECT_GRAPH (so) ||
+ IS_GNM_SO_LINE (so) ||
+ IS_GNM_SO_FILLED (so))
drawing_objs = g_slist_prepend (drawing_objs, so);
else if (GNM_IS_SOW_SCROLLBAR (so) || GNM_IS_SOW_SLIDER (so) ||
GNM_IS_SOW_SPINBUTTON (so) ||
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]