[gnumeric] Fix font and background colour import of LibreOffice generated xlsx files. Part of [#644496]



commit c9513348b9002c91013dbc821391c6bb6f58e118
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Tue Jun 14 11:27:14 2011 -0600

    Fix font and background colour import of LibreOffice generated xlsx files. Part of [#644496]
    
    2011-06-14  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* xlsx-read.c (elem_color): add allow_alpha argument, change all
    	callers and set alpha to 0xFF if it is not allowed
    	(xlsx_pattern_fg_bg): if we are reading a colour for a solid fill, ignore
    	alpha. LibreOffice 3.3.2 sets the alpha to 0 and Excel seems to ignore it
    	(xlsx_font_color): ditto

 NEWS                      |    2 ++
 plugins/excel/ChangeLog   |    8 ++++++++
 plugins/excel/xlsx-read.c |   21 ++++++++++++++-------
 3 files changed, 24 insertions(+), 7 deletions(-)
---
diff --git a/NEWS b/NEWS
index 236a46c..38f0869 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ Andreas
 	* Some documentation improvements.
 	* Read fraction formats correctly from ODF 1.2 files.
 	* Fix regression line export to ODF.
+	* Fix font and background colour import of LibreOffice generated xlsx
+	  files. Part of [#644496]
 
 Morten:
 	* Fix leaks in SHEET.  [#650761]
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index b050569..71225d2 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,11 @@
+2011-06-14  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* xlsx-read.c (elem_color): add allow_alpha argument, change all
+	callers and set alpha to 0xFF if it is not allowed
+	(xlsx_pattern_fg_bg): if we are reading a colour for a solid fill, ignore
+	alpha. LibreOffice 3.3.2 sets the alpha to 0 and Excel seems to ignore it
+	(xlsx_font_color): ditto
+
 2011-05-22  Morten Welinder  <terra gnome org>
 
 	* ms-excel-write.c (excel_write_autofilter_names): Use proper
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index 1d4315e..8a91b2b 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -1061,7 +1061,7 @@ apply_tint (GOColor orig, double tint)
 }
 
 static GnmColor *
-elem_color (GsfXMLIn *xin, xmlChar const **attrs)
+elem_color (GsfXMLIn *xin, xmlChar const **attrs, gboolean allow_alpha)
 {
 	XLSXReadState	*state = (XLSXReadState *)xin->user_state;
 	int indx;
@@ -1093,6 +1093,8 @@ elem_color (GsfXMLIn *xin, xmlChar const **attrs)
 	if (!has_color)
 		return NULL;
 	c = apply_tint (c, tint);
+	if (!allow_alpha)
+		c |= 0xFF;
 	return style_color_new_go (c);
 }
 
@@ -1463,7 +1465,7 @@ static void
 xlsx_sheet_tabcolor (GsfXMLIn *xin, xmlChar const **attrs)
 {
 	XLSXReadState *state = (XLSXReadState *)xin->user_state;
-	GnmColor *text_color, *color = elem_color (xin, attrs);
+	GnmColor *text_color, *color = elem_color (xin, attrs, TRUE);
 	if (NULL != color) {
 		int contrast =
 			GO_COLOR_UINT_R (color->go_color) +
@@ -3510,7 +3512,9 @@ static void
 xlsx_font_color (GsfXMLIn *xin, xmlChar const **attrs)
 {
 	XLSXReadState *state = (XLSXReadState *)xin->user_state;
-	GnmColor *color = elem_color (xin, attrs);
+	/* LibreOffice 3.3.2 sets the alpha to 0, so text becomes invisible */
+	/* (Excel drops the alpha too it seems.) */
+	GnmColor *color = elem_color (xin, attrs, FALSE);
 	if (NULL != color)
 		gnm_style_set_font_color (state->style_accum, color);
 }
@@ -3597,13 +3601,16 @@ static void
 xlsx_pattern_fg_bg (GsfXMLIn *xin, xmlChar const **attrs)
 {
 	XLSXReadState *state = (XLSXReadState *)xin->user_state;
+	gboolean solid_pattern = gnm_style_is_element_set (state->style_accum, MSTYLE_PATTERN)
+		&& (1 == gnm_style_get_pattern (state->style_accum));
 	/* MAGIC :
 	 * Looks like pattern background and forground colours are inverted for
 	 * dxfs with solid fills for no apparent reason. */
 	gboolean const invert = state->style_accum_partial
-		&& gnm_style_is_element_set (state->style_accum, MSTYLE_PATTERN)
-		&& (1 == gnm_style_get_pattern (state->style_accum));
-	GnmColor *color = elem_color (xin, attrs);
+		&& solid_pattern;
+	/* LibreOffice 3.3.2 sets the alpha to 0, so solid fill becomes invisible */
+	/* (Excel drops the alpha too it seems.) */
+	GnmColor *color = elem_color (xin, attrs, !solid_pattern);
 	if (NULL == color)
 		return;
 
@@ -3677,7 +3684,7 @@ static void
 xlsx_border_color (GsfXMLIn *xin, xmlChar const **attrs)
 {
 	XLSXReadState *state = (XLSXReadState *)xin->user_state;
-	GnmColor *color = elem_color (xin, attrs);
+	GnmColor *color = elem_color (xin, attrs, TRUE);
 	if (state->border_color)
 		style_color_unref (state->border_color);
 	state->border_color = color;



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