[gnumeric] xlsx: don't use truncated pointers as axis ids.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] xlsx: don't use truncated pointers as axis ids.
- Date: Sun, 18 Jan 2015 01:10:24 +0000 (UTC)
commit a92413cba8cb6f134b71732324b88c83439f9fe2
Author: Morten Welinder <terra gnome org>
Date: Sat Jan 17 20:09:06 2015 -0500
xlsx: don't use truncated pointers as axis ids.
Avoid using lower-32-bits-of-pointer as numeric ids. Use reproducible
indices instead.
plugins/excel/ChangeLog | 3 +++
plugins/excel/xlsx-write-drawing.c | 17 ++++++++++++++---
plugins/excel/xlsx-write.c | 4 ++++
3 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 616faed..1ba323d 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,8 @@
2015-01-17 Morten Welinder <terra gnome org>
+ * xlsx-write-drawing.c (xlsx_get_axid): New function allowing us
+ to get away from storing truncated pointers as axis ids.
+
* xlsx-read-drawing.c (xlsx_chart_bar_overlap)
(xlsx_chart_bar_gap): Fix reading percentages.
(xlsx_chart_no_fill): Handle noFill when used to avoid lines
diff --git a/plugins/excel/xlsx-write-drawing.c b/plugins/excel/xlsx-write-drawing.c
index 58cc111..ce53c1d 100644
--- a/plugins/excel/xlsx-write-drawing.c
+++ b/plugins/excel/xlsx-write-drawing.c
@@ -301,6 +301,17 @@ xlsx_write_chart_text (XLSXWriteState *state, GsfXMLOut *xml,
g_free (text);
}
+static unsigned
+xlsx_get_axid (XLSXWriteState *state, GogAxis *axis)
+{
+ gpointer l = g_hash_table_lookup (state->axids, axis);
+ if (!l) {
+ l = GUINT_TO_POINTER (1 + g_hash_table_size (state->axids));
+ g_hash_table_insert (state->axids, axis, l);
+ }
+ return GPOINTER_TO_UINT (l);
+}
+
static void
xlsx_write_axis (XLSXWriteState *state, GsfXMLOut *xml, GogAxis *axis, GogAxisType at)
@@ -315,7 +326,7 @@ xlsx_write_axis (XLSXWriteState *state, GsfXMLOut *xml, GogAxis *axis, GogAxisTy
gsf_xml_out_start_element (xml, "c:catAx");
else
gsf_xml_out_start_element (xml, "c:valAx");
- xlsx_write_chart_int (xml, "c:axId", 0, GPOINTER_TO_UINT (axis));
+ xlsx_write_chart_uint (xml, "c:axId", 0, xlsx_get_axid (state, axis));
gsf_xml_out_start_element (xml, "c:scaling");
xlsx_write_chart_cstr_unchecked (xml, "c:orientation", gog_axis_is_inverted (axis)? "maxMin":
"minMax");
// TODO: export min, max, an others
@@ -356,7 +367,7 @@ xlsx_write_axis (XLSXWriteState *state, GsfXMLOut *xml, GogAxis *axis, GogAxisTy
xlsx_write_go_style (xml, go_styled_object_get_style (GO_STYLED_OBJECT (axis)));
- xlsx_write_chart_int (xml, "c:crossAx", 0, GPOINTER_TO_UINT (crossed));
+ xlsx_write_chart_int (xml, "c:crossAx", 0, xlsx_get_axid (state, crossed));
g_object_get (G_OBJECT (axis), "pos", &pos, NULL);
switch (pos) {
default:
@@ -609,7 +620,7 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
/* write axes Ids */
for (i = 0; i < 3; i++)
if (axis_type[i] != GOG_AXIS_UNKNOWN)
- xlsx_write_chart_uint (xml, "c:axId", 0, GPOINTER_TO_UINT (gog_plot_get_axis
(GOG_PLOT (plot), axis_type[i])));
+ xlsx_write_chart_uint (xml, "c:axId", 0, xlsx_get_axid (state, gog_plot_get_axis
(GOG_PLOT (plot), axis_type[i])));
gsf_xml_out_end_element (xml);
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 3186c81..484addd 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -97,6 +97,7 @@ static char const *ns_rel_hlink = "http://schemas.openxmlformats.org/officeDocu
static char const *ns_rel_draw =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing";
static char const *ns_rel_chart =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart";
static char const *ns_rel_com =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
+
typedef struct {
XLExportBase base;
@@ -111,6 +112,7 @@ typedef struct {
GPtrArray *dxfs_array;
GnmConventions *convs;
GOIOContext *io_context;
+ GHashTable *axids;
GsfOutfile *xl_dir;
struct {
@@ -2917,6 +2919,7 @@ xlsx_write_workbook (XLSXWriteState *state, GsfOutfile *root_part)
state->styles_array = g_ptr_array_new ();
state->dxfs_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
state->dxfs_array = g_ptr_array_new ();
+ state->axids = g_hash_table_new (NULL, NULL);
xlsx_get_style_id (state, style);
gnm_style_unref (style);
@@ -3014,6 +3017,7 @@ xlsx_write_workbook (XLSXWriteState *state, GsfOutfile *root_part)
g_ptr_array_free (state->styles_array, TRUE);
g_hash_table_destroy (state->dxfs_hash);
g_ptr_array_free (state->dxfs_array, TRUE);
+ g_hash_table_destroy (state->axids);
if (NULL != state->chart.dir)
gsf_output_close (GSF_OUTPUT (state->chart.dir));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]