[gnumeric] xlsx: use extension structure to distinguish our two SOLID patterns.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] xlsx: use extension structure to distinguish our two SOLID patterns.
- Date: Sat, 14 Feb 2015 15:12:45 +0000 (UTC)
commit 715c7d75d53b7404c6b116ccc71944dfa8a78544
Author: Morten Welinder <terra gnome org>
Date: Sat Feb 14 10:12:05 2015 -0500
xlsx: use extension structure to distinguish our two SOLID patterns.
plugins/excel/ChangeLog | 6 ++++
plugins/excel/xlsx-read-drawing.c | 26 ++++++++++++++++++++
plugins/excel/xlsx-read.c | 1 +
plugins/excel/xlsx-utils.h | 1 +
plugins/excel/xlsx-write-drawing.c | 47 ++++++++++++++++++++++++++----------
plugins/excel/xlsx-write.c | 5 ++++
6 files changed, 73 insertions(+), 13 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 74694c9..9da51c0 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,9 @@
+2015-02-14 Morten Welinder <terra gnome org>
+
+ * xlsx-write-drawing.c (xlsx_write_go_style_full): When needed
+ store our pattern in extension structure. MS docs say other
+ consumers should ignore, but let's see.
+
2015-02-13 Morten Welinder <terra gnome org>
* xlsx-write-drawing.c (xlsx_write_go_style_full): When we must
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index d9e52a4..5d9863f 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -2935,6 +2935,31 @@ xlsx_blip_start (GsfXMLIn *xin, xmlChar const **attrs)
}
+static void
+xlsx_ext_gostyle (GsfXMLIn *xin, xmlChar const **attrs)
+{
+ XLSXReadState *state = (XLSXReadState *)xin->user_state;
+ GOStyle *style = state->cur_style;
+
+ if (!style)
+ return;
+
+ for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) {
+ if (strcmp (attrs[0], "pattern") == 0) {
+ GOPatternType p = go_pattern_from_str (attrs[1]);
+ if (style->fill.pattern.pattern == GO_PATTERN_FOREGROUND_SOLID &&
+ p == GO_PATTERN_SOLID) {
+ /* We read the wrong color */
+ style->fill.pattern.back = style->fill.pattern.fore;
+ style->fill.auto_back = style->fill.auto_fore;
+ style->fill.auto_fore = TRUE;
+ style->fill.pattern.fore = GO_COLOR_BLACK;
+ }
+ style->fill.pattern.pattern = p;
+ }
+ }
+}
+
static GsfXMLInNode const xlsx_drawing_dtd[] = {
GSF_XML_IN_NODE_FULL (START, START, -1, NULL, GSF_XML_NO_CONTENT, FALSE, TRUE, NULL, NULL, 0),
GSF_XML_IN_NODE_FULL (START, DRAWING, XL_NS_SS_DRAW, "wsDr", GSF_XML_NO_CONTENT, FALSE, TRUE, NULL, NULL, 0),
@@ -3053,6 +3078,7 @@ GSF_XML_IN_NODE_FULL (START, DRAWING, XL_NS_SS_DRAW, "wsDr", GSF_XML_NO_CONTENT,
GSF_XML_IN_NODE (SHAPE_PR, SP_PR_PRST_GEOM, XL_NS_DRAW, "prstGeom", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (SHAPE_PR, EXTLST, XL_NS_DRAW, "extLst", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (EXTLST, EXTITEM, XL_NS_DRAW, "ext", GSF_XML_NO_CONTENT, &xlsx_ext_begin, NULL),
+ GSF_XML_IN_NODE (EXTITEM, EXT_GOSTYLE, XL_NS_GNM_EXT, "gostyle", GSF_XML_NO_CONTENT,
&xlsx_ext_gostyle, NULL),
GSF_XML_IN_NODE (SHAPE, TX_BODY, XL_NS_SS_DRAW, "txBody", GSF_XML_NO_CONTENT, &xlsx_chart_text_start,
&xlsx_chart_text),
GSF_XML_IN_NODE (TX_BODY, LST_STYLE, XL_NS_DRAW, "lstStyle", GSF_XML_NO_CONTENT, NULL, NULL),
/* 2nd Def */
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index 01f3ec9..41c6836 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -286,6 +286,7 @@ static GsfXMLInNS const xlsx_ns[] = {
GSF_XML_IN_NS (XL_NS_CHART_DRAW, "http://schemas.openxmlformats.org/drawingml/2006/chartDrawing"),
GSF_XML_IN_NS (XL_NS_DRAW, "http://schemas.openxmlformats.org/drawingml/2006/3/main"),
/* Office 12 BETA-2 */
GSF_XML_IN_NS (XL_NS_DRAW, "http://schemas.openxmlformats.org/drawingml/2006/main"),
/* Office 12 BETA-2 Technical Refresh */
+ GSF_XML_IN_NS (XL_NS_GNM_EXT, "http://www.gnumeric.org/ext/spreadsheetml"),
GSF_XML_IN_NS (XL_NS_DOC_REL,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"),
GSF_XML_IN_NS (XL_NS_PKG_REL, "http://schemas.openxmlformats.org/package/2006/relationships"),
GSF_XML_IN_NS (XL_NS_LEG_OFF, "urn:schemas-microsoft-com:office:office"),
diff --git a/plugins/excel/xlsx-utils.h b/plugins/excel/xlsx-utils.h
index d4fd09c..0faab42 100644
--- a/plugins/excel/xlsx-utils.h
+++ b/plugins/excel/xlsx-utils.h
@@ -38,6 +38,7 @@ enum {
XL_NS_LEG_OFF,
XL_NS_LEG_XL,
XL_NS_LEG_VML,
+ XL_NS_GNM_EXT,
XL_NS_PROP_CP,
XL_NS_PROP_DC,
XL_NS_PROP_DCMITYPE,
diff --git a/plugins/excel/xlsx-write-drawing.c b/plugins/excel/xlsx-write-drawing.c
index aa2d8b1..742e88e 100644
--- a/plugins/excel/xlsx-write-drawing.c
+++ b/plugins/excel/xlsx-write-drawing.c
@@ -191,6 +191,7 @@ typedef struct {
const char *spPr_ns;
gboolean must_fill_line;
gboolean must_fill_fill;
+ XLSXWriteState *state;
/* Not strictly context, but extensions to the style. */
const char *shapename;
@@ -201,14 +202,15 @@ typedef struct {
} XLSXStyleContext;
static void
-xlsx_style_context_init (XLSXStyleContext *sctx)
+xlsx_style_context_init (XLSXStyleContext *sctx, XLSXWriteState *state)
{
sctx->def_has_markers = FALSE;
sctx->def_has_lines = TRUE;
sctx->spPr_ns = "c";
- sctx->shapename = NULL;
sctx->must_fill_line = FALSE;
sctx->must_fill_fill = FALSE;
+ sctx->state = state;
+ sctx->shapename = NULL;
sctx->start_arrow = NULL;
sctx->end_arrow = NULL;
sctx->flipH = FALSE;
@@ -221,6 +223,8 @@ xlsx_write_go_style_full (GsfXMLOut *xml, GOStyle *style, const XLSXStyleContext
gboolean has_font_color = ((style->interesting_fields & GO_STYLE_FONT) &&
!style->font.auto_color);
gboolean has_font = xlsx_go_style_has_font (style);
+ gboolean ext_fill_pattern = FALSE;
+
char *spPr_tag = g_strconcat (sctx->spPr_ns, ":spPr", NULL);
gsf_xml_out_start_element (xml, spPr_tag);
@@ -255,6 +259,7 @@ xlsx_write_go_style_full (GsfXMLOut *xml, GOStyle *style, const XLSXStyleContext
const char *pattname = NULL;
switch (style->fill.pattern.pattern) {
case GO_PATTERN_SOLID:
+ ext_fill_pattern = TRUE;
if (!style->fill.auto_back) {
gsf_xml_out_start_element (xml, "a:solidFill");
xlsx_write_rgbarea (xml, style->fill.pattern.back);
@@ -403,6 +408,20 @@ xlsx_write_go_style_full (GsfXMLOut *xml, GOStyle *style, const XLSXStyleContext
gsf_xml_out_end_element (xml);
}
+ if (sctx->state->with_extension && ext_fill_pattern) {
+ /* What namespace do we use? */
+ 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_fill_pattern) {
+ gsf_xml_out_add_cstr (xml, "pattern", go_pattern_as_str
(style->fill.pattern.pattern));
+ }
+ gsf_xml_out_end_element (xml); /* "gnmx:gostyle" */
+ gsf_xml_out_end_element (xml); /* "a:ext" */
+ gsf_xml_out_end_element (xml); /* "a:extLst" */
+ }
+
gsf_xml_out_end_element (xml); /* "NS:spPr" */
g_free (spPr_tag);
@@ -496,10 +515,10 @@ xlsx_write_go_style_full (GsfXMLOut *xml, GOStyle *style, const XLSXStyleContext
}
static void
-xlsx_write_go_style (GsfXMLOut *xml, GOStyle *style)
+xlsx_write_go_style (GsfXMLOut *xml, XLSXWriteState *state, GOStyle *style)
{
XLSXStyleContext sctx;
- xlsx_style_context_init (&sctx);
+ xlsx_style_context_init (&sctx, state);
xlsx_write_go_style_full (xml, style, &sctx);
}
@@ -543,7 +562,7 @@ xlsx_write_chart_text (XLSXWriteState *state, GsfXMLOut *xml,
style_minus_font = go_style_dup (style);
style_minus_font->interesting_fields &= ~GO_STYLE_FONT;
- xlsx_write_go_style (xml, style_minus_font);
+ xlsx_write_go_style (xml, state, style_minus_font);
g_object_unref (style_minus_font);
g_free (text);
@@ -598,13 +617,13 @@ xlsx_write_axis (XLSXWriteState *state, GsfXMLOut *xml, GogAxis *axis, GogAxisTy
grid = gog_axis_get_grid_line (axis, TRUE);
if (grid) {
gsf_xml_out_start_element (xml, "c:majorGridlines");
- xlsx_write_go_style (xml, go_styled_object_get_style (GO_STYLED_OBJECT (grid)));
+ xlsx_write_go_style (xml, state, go_styled_object_get_style (GO_STYLED_OBJECT (grid)));
gsf_xml_out_end_element (xml);
}
grid = gog_axis_get_grid_line (axis, FALSE);
if (grid) {
gsf_xml_out_start_element (xml, "c:minorGridlines");
- xlsx_write_go_style (xml, go_styled_object_get_style (GO_STYLED_OBJECT (grid)));
+ xlsx_write_go_style (xml, state, go_styled_object_get_style (GO_STYLED_OBJECT (grid)));
gsf_xml_out_end_element (xml);
}
@@ -641,7 +660,7 @@ xlsx_write_axis (XLSXWriteState *state, GsfXMLOut *xml, GogAxis *axis, GogAxisTy
marks[2 * mito + miti]);
}
- xlsx_write_go_style (xml, go_styled_object_get_style (GO_STYLED_OBJECT (axis)));
+ xlsx_write_go_style (xml, state, go_styled_object_get_style (GO_STYLED_OBJECT (axis)));
xlsx_write_chart_int (xml, "c:crossAx", 0, xlsx_get_axid (state, crossed));
g_object_get (G_OBJECT (axis), "pos", &pos, NULL);
@@ -822,7 +841,7 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
if (!vary_by_element) {
/* FIXME: we might loose some style elements */
XLSXStyleContext sctx;
- xlsx_style_context_init (&sctx);
+ xlsx_style_context_init (&sctx, state);
sctx.def_has_markers = has_markers;
sctx.def_has_lines = has_lines;
xlsx_write_go_style_full (xml, style, &sctx);
@@ -864,7 +883,7 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
name = go_data_get_scalar_string (dat);
gsf_xml_out_simple_element (xml, "c:name", name);
g_free (name);
- xlsx_write_go_style (xml, go_styled_object_get_style (GO_STYLED_OBJECT (trend)));
+ xlsx_write_go_style (xml, state, go_styled_object_get_style (GO_STYLED_OBJECT
(trend)));
xlsx_write_chart_cstr_unchecked (xml, "c:trendlineType", trend_type);
gsf_xml_out_end_element (xml); /* </c:trendline> */
@@ -1024,7 +1043,7 @@ xlsx_write_one_chart (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *ch
obj = gog_object_get_child_by_name (GOG_OBJECT (chart), "Backplane");
if (obj)
- xlsx_write_go_style (xml, go_styled_object_get_style (GO_STYLED_OBJECT (obj)));
+ xlsx_write_go_style (xml, state, go_styled_object_get_style (GO_STYLED_OBJECT (obj)));
gsf_xml_out_end_element (xml); /* </c:plotArea> */
@@ -1034,7 +1053,7 @@ xlsx_write_one_chart (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *ch
}
gsf_xml_out_end_element (xml); /* </c:chart> */
- xlsx_write_go_style (xml, go_styled_object_get_style (GO_STYLED_OBJECT (chart)));
+ xlsx_write_go_style (xml, state, go_styled_object_get_style (GO_STYLED_OBJECT (chart)));
}
static void
@@ -1149,6 +1168,8 @@ xlsx_write_drawing_objects (XLSXWriteState *state, GsfOutput *sheet_part, GSList
gsf_xml_out_start_element (xml, "xdr:wsDr");
gsf_xml_out_add_cstr_unchecked (xml, "xmlns:xdr", ns_ss_drawing);
gsf_xml_out_add_cstr_unchecked (xml, "xmlns:a", ns_drawing);
+ if (state->with_extension)
+ gsf_xml_out_add_cstr_unchecked (xml, "xmlns:gnmx", ns_gnm_ext);
for (obj = objects, rId_ptr = rIds;
obj != NULL ;
@@ -1215,7 +1236,7 @@ xlsx_write_drawing_objects (XLSXWriteState *state, GsfOutput *sheet_part, GSList
GOStyle *style = NULL;
XLSXStyleContext sctx;
- xlsx_style_context_init (&sctx);
+ xlsx_style_context_init (&sctx, state);
sctx.spPr_ns = "xdr";
sctx.must_fill_line = TRUE;
sctx.must_fill_fill = IS_GNM_SO_FILLED (so);
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index e2fc112..ac234a6 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -100,6 +100,8 @@ static char const *ns_vml = "urn:schemas-microsoft-com:vml";
static char const *ns_leg_office = "urn:schemas-microsoft-com:office:office";
static char const *ns_leg_excel = "urn:schemas-microsoft-com:office:excel";
+static char const *ns_gnm_ext = "http://www.gnumeric.org/ext/spreadsheetml";
+
static char const *ns_rel = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
static char const *ns_rel_hlink =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
static char const *ns_rel_draw =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing";
@@ -111,6 +113,7 @@ typedef struct {
XLExportBase base;
gint version;
+ gboolean with_extension;
Sheet const *sheet;
GHashTable *shared_string_hash;
@@ -3113,6 +3116,7 @@ xlsx_file_save (G_GNUC_UNUSED GOFileSaver const *fs, GOIOContext *io_context,
locale = gnm_push_C_locale ();
state.version = ECMA_376_2006;
+ state.with_extension = TRUE;
state.io_context = io_context;
state.base.wb = wb_view_get_workbook (wb_view);
state.comment = 0;
@@ -3144,6 +3148,7 @@ xlsx2_file_save (G_GNUC_UNUSED GOFileSaver const *fs, GOIOContext *io_context,
locale = gnm_push_C_locale ();
state.version = ECMA_376_2008;
+ state.with_extension = TRUE;
state.io_context = io_context;
state.base.wb = wb_view_get_workbook (wb_view);
state.comment = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]