[gnumeric] write table columns



commit 45c2fb3096bd3b803baf717322d8f5a21d278217
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Sun May 17 23:55:27 2009 -0600

    write table columns
    
    2009-05-17  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-write.c (odf_write_character_styles): also write the
    	  default style
    	(equal_style): new
    	(filter_style): new
    	(write_last_col_style): new
    	(odf_write_sheet): set default column styles for all columns
---
 plugins/openoffice/ChangeLog          |   11 +++++-
 plugins/openoffice/openoffice-write.c |   64 +++++++++++++++++++++++++++++++-
 2 files changed, 72 insertions(+), 3 deletions(-)

diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 65a9801..3af7642 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,6 +1,15 @@
 2009-05-17  Andreas J. Guelzow <aguelzow pyrshep ca>
 
-	* openoffice-read.c (odf_find_style): make sure that we would 
+	* openoffice-write.c (odf_write_character_styles): also write the 
+	  default style
+	(equal_style): new
+	(filter_style): new
+	(write_last_col_style): new
+	(odf_write_sheet): set default column styles for all columns
+
+2009-05-17  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-write.c (odf_find_style): make sure that we would 
 	  correctly handle the case that we are trying to find a style we
 	  did not write.
 	
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 8b85793..a29e26c 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -782,6 +782,9 @@ odf_write_character_styles (GnmOOExport *state)
 	gsf_xml_out_end_element (state->xml); /* </style:text-properties> */
 	gsf_xml_out_end_element (state->xml); /* </style:style> */
 
+	if (state->default_style != NULL)
+		odf_find_style (state, state->default_style, TRUE);
+
 	odf_load_required_automatic_styles (state);
 }
 
@@ -1045,6 +1048,33 @@ odf_write_cell (GnmOOExport *state, GnmCell *cell, GnmRange const *merge_range,
 	gsf_xml_out_end_element (state->xml);   /* table-cell */
 }
 
+static gboolean
+equal_style (GnmStyle *that, GnmStyle * this)
+{
+	if (this == that)
+		return TRUE;
+	if (this == NULL || that == NULL)
+		return FALSE;
+	return gnm_style_equal (that, this);
+}
+
+static GnmStyle *
+filter_style (GnmStyle *default_style, GnmStyle * this)
+{
+	return (equal_style (default_style, this) ? NULL : this);
+}
+
+static void
+write_last_col_style (GnmOOExport *state, GnmStyle *last_col_style)
+{
+	if (last_col_style != NULL) {					
+		char const * name = odf_find_style (state, last_col_style, FALSE); 
+		if (name != NULL)					
+			gsf_xml_out_add_cstr (state->xml,		
+					      TABLE "default-cell-style-name", name); 
+	}
+}
+
 static void
 odf_write_sheet (GnmOOExport *state, Sheet const *sheet)
 {
@@ -1057,6 +1087,9 @@ odf_write_sheet (GnmOOExport *state, Sheet const *sheet)
 	int covered_cell;
 	GnmCellPos pos;
 	GSList *sheet_merges = NULL;
+	int number_cols_rep;
+	GnmStyle *last_col_style = NULL;
+	
 
 	extent = sheet_get_extent (sheet, FALSE);
 	sheet_style_get_extent (sheet, &extent, col_styles);
@@ -1073,11 +1106,37 @@ odf_write_sheet (GnmOOExport *state, Sheet const *sheet)
 			break;
 		}
 
+	/* Writing Table Columns */
+	
 	gsf_xml_out_start_element (state->xml, TABLE "table-column");
-	gsf_xml_out_add_int (state->xml, TABLE "number-columns-repeated",
-			     extent.end.col + 1);
+	number_cols_rep = 1;
+	last_col_style = filter_style (state->default_style, col_styles[0]); 
+	write_last_col_style (state, last_col_style);
+
+	for (i = 1; i < max_cols; i++) {
+		GnmStyle *this_col_style = filter_style (state->default_style, col_styles[i]);
+
+		if (equal_style (this_col_style, last_col_style))
+			number_cols_rep++;
+		else {
+			if (number_cols_rep > 1)
+				gsf_xml_out_add_int (state->xml, TABLE "number-columns-repeated",
+						     number_cols_rep);
+			gsf_xml_out_end_element (state->xml); /* table-column */
+			gsf_xml_out_start_element (state->xml, TABLE "table-column");
+			number_cols_rep = 1;
+			last_col_style = this_col_style;
+			write_last_col_style (state, last_col_style);
+		}
+	}
+
+	if (number_cols_rep > 1)
+		gsf_xml_out_add_int (state->xml, TABLE "number-columns-repeated",
+				     number_cols_rep);
 	gsf_xml_out_end_element (state->xml); /* table-column */
 
+	/* Done Writing Table Columns */
+
 	if (extent.start.row > 0) {
 		/* We need to write a bunch of empty rows !*/
 		gsf_xml_out_start_element (state->xml, TABLE "table-row");
@@ -1139,6 +1198,7 @@ odf_write_sheet (GnmOOExport *state, Sheet const *sheet)
 	g_free (col_styles);
 }
 
+
 static void
 odf_write_filter_cond (GnmOOExport *state, GnmFilter const *filter, int i)
 {



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