[gnumeric] xlsx: store complete arrow details in extension if needed



commit a3aa3f4065336200bc6d42f58ae57fa70bc3cef9
Author: Morten Welinder <terra gnome org>
Date:   Sat Feb 14 13:47:37 2015 -0500

    xlsx: store complete arrow details in extension if needed

 plugins/excel/ChangeLog            |    2 ++
 plugins/excel/xlsx-read-drawing.c  |   30 ++++++++++++++++++++++++++++++
 plugins/excel/xlsx-write-drawing.c |   32 +++++++++++++++++++++++++++++---
 3 files changed, 61 insertions(+), 3 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 9da51c0..c20a1c4 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -3,6 +3,8 @@
        * 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.
+       (xlsx_write_go_style_full): If translation loses information,
+       store complete arrow details in extension.
 
 2015-02-13  Morten Welinder  <terra gnome org>
 
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index 5d9863f..6b925aa 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -2940,11 +2940,19 @@ xlsx_ext_gostyle (GsfXMLIn *xin, xmlChar const **attrs)
 {
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
        GOStyle *style = state->cur_style;
+       GOArrow *start_arrow = NULL;
+       GOArrow *end_arrow = NULL;
+       gboolean has_arrow = IS_GNM_SO_LINE (state->so);
 
        if (!style)
                return;
 
+       if (has_arrow)
+               g_object_get (state->so, "start_arrow", &start_arrow, "end_arrow", &end_arrow, NULL);
+
        for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) {
+               gnm_float f;
+
                if (strcmp (attrs[0], "pattern") == 0) {
                        GOPatternType p = go_pattern_from_str (attrs[1]);
                        if (style->fill.pattern.pattern == GO_PATTERN_FOREGROUND_SOLID &&
@@ -2956,8 +2964,30 @@ xlsx_ext_gostyle (GsfXMLIn *xin, xmlChar const **attrs)
                                style->fill.pattern.fore = GO_COLOR_BLACK;
                        }
                        style->fill.pattern.pattern = p;
+               } else if (start_arrow && strcmp (attrs[0], "StartArrowType") == 0) {
+                       start_arrow->typ = go_arrow_type_from_str (attrs[1]);
+               } else if (start_arrow && attr_float (xin, attrs, "StartArrowShapeA", &f)) {
+                       start_arrow->a = f;
+               } else if (start_arrow && attr_float (xin, attrs, "StartArrowShapeB", &f)) {
+                       start_arrow->b = f;
+               } else if (start_arrow && attr_float (xin, attrs, "StartArrowShapeC", &f)) {
+                       start_arrow->c = f;
+               } else if (start_arrow && strcmp (attrs[0], "EndArrowType") == 0) {
+                       end_arrow->typ = go_arrow_type_from_str (attrs[1]);
+               } else if (end_arrow && attr_float (xin, attrs, "EndArrowShapeA", &f)) {
+                       end_arrow->a = f;
+               } else if (end_arrow && attr_float (xin, attrs, "EndArrowShapeB", &f)) {
+                       end_arrow->b = f;
+               } else if (end_arrow && attr_float (xin, attrs, "EndArrowShapeC", &f)) {
+                       end_arrow->c = f;
                }
        }
+
+       if (has_arrow) {
+               g_object_set (state->so, "start_arrow", start_arrow, "end_arrow", end_arrow, NULL);
+               g_free (start_arrow);
+               g_free (end_arrow);
+       }
 }
 
 static GsfXMLInNode const xlsx_drawing_dtd[] = {
diff --git a/plugins/excel/xlsx-write-drawing.c b/plugins/excel/xlsx-write-drawing.c
index 742e88e..a25ce55 100644
--- a/plugins/excel/xlsx-write-drawing.c
+++ b/plugins/excel/xlsx-write-drawing.c
@@ -224,6 +224,8 @@ xlsx_write_go_style_full (GsfXMLOut *xml, GOStyle *style, const XLSXStyleContext
                                   !style->font.auto_color);
        gboolean has_font = xlsx_go_style_has_font (style);
        gboolean ext_fill_pattern = FALSE;
+       gboolean ext_start_arrow = FALSE;
+       gboolean ext_end_arrow = FALSE;
 
        char *spPr_tag = g_strconcat (sctx->spPr_ns, ":spPr", NULL);
 
@@ -390,17 +392,26 @@ xlsx_write_go_style_full (GsfXMLOut *xml, GOStyle *style, const XLSXStyleContext
                        };
                        static const char *sizes[] = { "sm", "med", "lg" };
                        double width;
+                       GOArrow res_arrow;
 
                        if (!arr) continue;
 
                        width = style->line.auto_width ? 0 : style->line.width;
 
                        xls_arrow_to_xl (arr, width, &typ, &l, &w);
+                       xls_arrow_from_xl (&res_arrow, width, typ, l, w);
+                       if (!go_arrow_equal (&res_arrow, arr)) {
+                               if (i)
+                                       ext_end_arrow = TRUE;
+                               else
+                                       ext_start_arrow = TRUE;
+                       }
+
                        gsf_xml_out_start_element (xml, i ? "a:tailEnd" : "a:headEnd");
                        gsf_xml_out_add_cstr_unchecked (xml, "type", types[typ]);
                        if (typ) {
-                               gsf_xml_out_add_cstr_unchecked (xml, "w", sizes[CLAMP(w,0,2)]);
-                               gsf_xml_out_add_cstr_unchecked (xml, "len", sizes[CLAMP(l,0,2)]);
+                               gsf_xml_out_add_cstr_unchecked (xml, "w", sizes[w]);
+                               gsf_xml_out_add_cstr_unchecked (xml, "len", sizes[l]);
                        }
                        gsf_xml_out_end_element (xml);
                }
@@ -408,7 +419,8 @@ 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) {
+       if (sctx->state->with_extension &&
+           (ext_fill_pattern || ext_start_arrow || ext_end_arrow)) {
                /* What namespace do we use?  */
                gsf_xml_out_start_element (xml, "a:extLst");
                gsf_xml_out_start_element (xml, "a:ext");
@@ -417,6 +429,20 @@ xlsx_write_go_style_full (GsfXMLOut *xml, GOStyle *style, const XLSXStyleContext
                if (ext_fill_pattern) {
                        gsf_xml_out_add_cstr (xml, "pattern", go_pattern_as_str 
(style->fill.pattern.pattern));
                }
+               if (ext_start_arrow) {
+                       GOArrow const *arrow = sctx->start_arrow;
+                       gsf_xml_out_add_cstr (xml, "StartArrowType", go_arrow_type_as_str (arrow->typ));
+                       gsf_xml_out_add_float (xml, "StartArrowShapeA", arrow->a, -1);
+                       gsf_xml_out_add_float (xml, "StartArrowShapeB", arrow->b, -1);
+                       gsf_xml_out_add_float (xml, "StartArrowShapeC", arrow->c, -1);
+               }
+               if (ext_end_arrow) {
+                       GOArrow const *arrow = sctx->end_arrow;
+                       gsf_xml_out_add_cstr (xml, "EndArrowType", go_arrow_type_as_str (arrow->typ));
+                       gsf_xml_out_add_float (xml, "EndArrowShapeA", arrow->a, -1);
+                       gsf_xml_out_add_float (xml, "EndArrowShapeB", arrow->b, -1);
+                       gsf_xml_out_add_float (xml, "EndArrowShapeC", arrow->c, -1);
+               }
                gsf_xml_out_end_element (xml);  /* "gnmx:gostyle" */
                gsf_xml_out_end_element (xml);  /* "a:ext" */
                gsf_xml_out_end_element (xml);  /* "a:extLst" */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]