[gnumeric] xlsx: improve import of rich text colours.



commit ff6c32ee6870310d013bc5a86dee5a6f9d78053e
Author: Morten Welinder <terra gnome org>
Date:   Tue Jun 3 15:15:24 2014 -0400

    xlsx: improve import of rich text colours.
    
    This handles also indexed colours, a silly idea that only Excel writes.

 NEWS                      |    1 +
 plugins/excel/ChangeLog   |    4 ++++
 plugins/excel/xlsx-read.c |   28 +++++++++++++++++-----------
 3 files changed, 22 insertions(+), 11 deletions(-)
---
diff --git a/NEWS b/NEWS
index 7d96655..18d8f37 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ Morten:
        * Fix UMR.  [#730727]
        * Fix crashes on exit.  [#730857]  [#730884]
        * Handle value formats for xlsx export.  [#724517]
+       * Improve xlsx import of rich text.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.16
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index dbae4a3..62b0f6e 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,7 @@
+2014-06-03  Morten Welinder  <terra gnome org>
+
+       * xlsx-read.c (xlsx_run_color): Handle indexed colours.
+
 2014-06-02  Morten Welinder  <terra gnome org>
 
        * xlsx-read.c (handle_delayed_names): Handle empty string for
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index 8de1265..b0ce95e 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -3596,22 +3596,28 @@ static void
 xlsx_run_color (GsfXMLIn *xin, xmlChar const **attrs)
 {
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
-       for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
+       GOColor c = GO_COLOR_BLACK;
+
+       for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) {
                if (gsf_xml_in_namecmp (xin, attrs[0], XL_NS_SS, "rgb")) {
-                       PangoAttribute *attr;
-                       unsigned a, r = 0, g = 0, b = 0;
+                       unsigned r, g, b, a;
                        if (4 != sscanf (attrs[1], "%02x%02x%02x%02x", &a, &r, &g, &b)) {
                                xlsx_warning (xin,
-                                       _("Invalid color '%s' for attribute rgb"),
-                                       attrs[1]);
+                                             _("Invalid color '%s' for attribute rgb"),
+                                             attrs[1]);
+                               continue;
                        }
-                       attr = pango_attr_foreground_new (CLAMP ((int)r * 257, 0, 65535),
-                                                         CLAMP ((int)g * 257, 0, 65535),
-                                                         CLAMP ((int)b * 257, 0, 65535));
-                       if (state->run_attrs == NULL)
-                               state->run_attrs = pango_attr_list_new ();
-                       pango_attr_list_insert (state->run_attrs, attr);
+
+                       c = GO_COLOR_FROM_RGBA (r, g, b, a);
+               } else if (gsf_xml_in_namecmp (xin, attrs[0], XL_NS_SS, "indexed")) {
+                       int idx = atoi (CXML2C (attrs[1]));
+                       c = indexed_color (state, idx);
                }
+       }
+
+       if (state->run_attrs == NULL)
+               state->run_attrs = pango_attr_list_new ();
+       pango_attr_list_insert (state->run_attrs, go_color_to_pango (c, TRUE));
 }
 
 static void


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