[gnumeric] Export and import chart titles and subtitles to and from ODF.



commit 42d9695db2248c69acaa80afbc2e3cffe9d3617f
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Mon Aug 16 22:42:43 2010 -0600

    Export and import chart titles and subtitles to and from ODF.
    
    2010-08-16  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (oo_chart_title): renamed to
    	  oo_chart_title_text
    	(oo_chart_title): new
    	(oo_chart_title_end): new
    	(opendoc_content_dtd): connect the above
    	* openoffice-write.c (odf_write_title): new
    	(odf_write_plot): use odf_write_title for title and subtitle

 NEWS                                  |    2 +-
 plugins/openoffice/ChangeLog          |   13 ++++-
 plugins/openoffice/openoffice-read.c  |   73 ++++++++++++++++++++++++---
 plugins/openoffice/openoffice-write.c |   90 ++++++++++++++++++++-------------
 4 files changed, 132 insertions(+), 46 deletions(-)
---
diff --git a/NEWS b/NEWS
index 317656b..8b0c2a7 100644
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,7 @@
 Gnumeric 1.10.10
 
 Andreas:
-	* Export chart titles to ODF.
+	* Export and import chart titles and subtitles to and from ODF.
 
 --------------------------------------------------------------------------
 Gnumeric 1.10.9
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 2ddc64c..7424dc4 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,6 +1,17 @@
 2010-08-16  Andreas J. Guelzow <aguelzow pyrshep ca>
 
-	* openoffice-read.c (oo_date_style_end): set accum to NULL after freeing
+	* openoffice-read.c (oo_chart_title): renamed to 
+	  oo_chart_title_text
+	(oo_chart_title): new
+	(oo_chart_title_end): new
+	(opendoc_content_dtd): connect the above
+	* openoffice-write.c (odf_write_title): new
+	(odf_write_plot): use odf_write_title for title and subtitle
+
+2010-08-16  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-read.c (oo_date_style_end): set accum to NULL 
+	  after freeing
 	(odf_number_style): set all fields
 	(odf_number_style_end): check for NULL name
 
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 34a0531..9f4bf1b 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -182,6 +182,8 @@ typedef struct {
 
 	GogObject	*axis;
 
+	GnmExprTop const        *title_expr;
+
 	OOChartStyle		*cur_graph_style;
 	GHashTable		*graph_styles;	/* contain links to OOChartStyle GSLists */
 	GSList                  *these_plot_styles;  /* currently active styles */
@@ -3554,15 +3556,68 @@ od_draw_text_box_p_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
 }
 
 static void
-oo_chart_title (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+oo_chart_title (GsfXMLIn *xin, xmlChar const **attrs)
+{
+	OOParseState *state = (OOParseState *)xin->user_state;
+	state->chart.title_expr = NULL;
+
+	for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2){
+		if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), 
+					OO_NS_TABLE, "cell-address")
+		    && state->chart.title_expr == NULL) {
+			GnmParsePos   pp;
+			char *end_str = g_strconcat ("[", CXML2C (attrs[1]), "]", NULL);
+			parse_pos_init_sheet (&pp, state->chart.src_sheet);
+			state->chart.title_expr 
+				= oo_expr_parse_str 
+				(xin, end_str, &pp,
+				 GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
+				 FORMULA_OPENFORMULA);
+			g_free (end_str);
+		} else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), 
+					       OO_GNUM_NS_EXT, "expression")) {
+			GnmParsePos   pp;
+
+			if (state->chart.title_expr != NULL)
+				gnm_expr_top_unref (state->chart.title_expr);
+
+			parse_pos_init_sheet (&pp, state->chart.src_sheet);
+			state->chart.title_expr 
+				= oo_expr_parse_str 
+				(xin, CXML2C (attrs[1]), &pp,
+				 GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
+				 FORMULA_OPENFORMULA);
+		}
+	}
+}
+
+static void
+oo_chart_title_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+	OOParseState *state = (OOParseState *)xin->user_state;
+	if (state->chart.title_expr) {
+		GOData *data = gnm_go_data_scalar_new_expr 
+			(state->chart.src_sheet, state->chart.title_expr);
+		GogObject *label = NULL;
+		label = gog_object_add_by_name 
+			((GogObject *)state->chart.chart, "Title", NULL);
+		gog_dataset_set_dim (GOG_DATASET (label), 0,
+				     data,
+				     NULL);
+		state->chart.title_expr = NULL;
+	}
+		
+}
+
+static void
+oo_chart_title_text (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
 {
-	GogObject *label = NULL;
 	OOParseState *state = (OOParseState *)xin->user_state;
 
-	label = gog_object_add_by_name ((GogObject *)state->chart.chart, "Title", NULL);
-	gog_dataset_set_dim (GOG_DATASET (label), 0,
-			     go_data_scalar_str_new (g_strdup (xin->content->str), TRUE),
-			     NULL);
+	if (state->chart.title_expr == NULL)
+		state->chart.title_expr = 
+			gnm_expr_top_new_constant 
+			(value_new_string (xin->content->str));
 }
 
 static void
@@ -4530,8 +4585,10 @@ static GsfXMLInNode const opendoc_content_dtd [] =
 	          GSF_XML_IN_NODE (CHART_TABLE_HCOLS, CHART_TABLE_HCOL, OO_NS_TABLE, "table-header-column", GSF_XML_NO_CONTENT, NULL, NULL),
 	          GSF_XML_IN_NODE (CHART_TABLE_HCOLS, CHART_TABLE_COL, OO_NS_TABLE, "table-column", GSF_XML_NO_CONTENT, NULL, NULL),		/* 2nd Def */
 
-	      GSF_XML_IN_NODE (CHART_CHART, CHART_TITLE, OO_NS_CHART, "title", GSF_XML_NO_CONTENT, NULL, NULL),
-		GSF_XML_IN_NODE (CHART_TITLE, TITLE_TEXT, OO_NS_TEXT, "p", GSF_XML_CONTENT, NULL, &oo_chart_title),
+	      GSF_XML_IN_NODE (CHART_CHART, CHART_TITLE, OO_NS_CHART, "title", GSF_XML_NO_CONTENT,  &oo_chart_title, &oo_chart_title_end),
+		GSF_XML_IN_NODE (CHART_TITLE, TITLE_TEXT, OO_NS_TEXT, "p", GSF_XML_CONTENT, NULL, &oo_chart_title_text),
+	      GSF_XML_IN_NODE (CHART_CHART, CHART_SUBTITLE, OO_NS_CHART, "subtitle", GSF_XML_NO_CONTENT, &oo_chart_title, &oo_chart_title_end),	
+	        GSF_XML_IN_NODE (CHART_SUBTITLE, TITLE_TEXT, OO_NS_TEXT, "p", GSF_XML_NO_CONTENT, NULL, NULL),                                     /* 2nd Def */
 	      GSF_XML_IN_NODE (CHART_CHART, CHART_LEGEND, OO_NS_CHART, "legend", GSF_XML_NO_CONTENT, &oo_legend, NULL),
 	      GSF_XML_IN_NODE (CHART_CHART, CHART_PLOT_AREA, OO_NS_CHART, "plot-area", GSF_XML_NO_CONTENT, &oo_plot_area, &oo_plot_area_end),
 		GSF_XML_IN_NODE (CHART_PLOT_AREA, CHART_SERIES, OO_NS_CHART, "series", GSF_XML_NO_CONTENT, &oo_plot_series, &oo_plot_series_end),
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 69178bb..4b6e88f 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -3775,6 +3775,49 @@ odf_write_axis (GnmOOExport *state, GogObject const *chart, char const *axis_rol
 }
 
 static void
+odf_write_title (GnmOOExport *state, GogObject const *title, char const *id)
+{
+	if (title != NULL && id != NULL) {
+		GOData const *dat = gog_dataset_get_dim (GOG_DATASET(title),0);
+		if (dat != NULL) {
+			GnmExprTop const *texpr = gnm_go_data_get_expr (dat);
+			if (texpr != NULL) {
+				GnmParsePos pp;
+				char *formula;
+				parse_pos_init_sheet (&pp, state->sheet);
+				formula = gnm_expr_top_as_string (texpr, &pp, state->conv);
+
+				gsf_xml_out_start_element (state->xml, id);
+
+				if (gnm_expr_top_is_rangeref (texpr)) {
+					gsf_xml_out_add_cstr (state->xml, TABLE "cell-address",
+								      odf_strip_brackets (formula));
+				} else if (GNM_EXPR_GET_OPER (texpr->expr) == GNM_EXPR_OP_CONSTANT 
+					   && texpr->expr->constant.value->type == VALUE_STRING) {
+					gboolean white_written = TRUE;
+					char const *str;
+					gsf_xml_out_start_element (state->xml, TEXT "p");
+					str = value_peek_string (texpr->expr->constant.value);
+					odf_add_chars (state, str, strlen (str), &white_written);	
+					gsf_xml_out_end_element (state->xml); /* </text:p> */
+				} else {
+					gboolean white_written = TRUE;
+					if (state->with_extension)
+						gsf_xml_out_add_cstr (state->xml, GNMSTYLE "expression",
+								      formula);
+					gsf_xml_out_start_element (state->xml, TEXT "p");
+					odf_add_chars (state, formula, strlen (formula), 
+						       &white_written);	
+					gsf_xml_out_end_element (state->xml); /* </text:p> */	
+				}
+				gsf_xml_out_end_element (state->xml); /* </chart:title> */
+				g_free (formula);
+			}
+		}
+	}	
+}
+
+static void
 odf_write_plot (GnmOOExport *state, SheetObject *so, GogObject const *chart, GogObject const *plot)
 {
 	char const *plot_type = G_OBJECT_TYPE_NAME (plot);
@@ -3784,7 +3827,7 @@ odf_write_plot (GnmOOExport *state, SheetObject *so, GogObject const *chart, Gog
 	int i;
 	GogObject const *wall = gog_object_get_child_by_name (plot, "Backplane");
 	GogObject const *legend = gog_object_get_child_by_name (chart, "Legend");
-	GogObject const *title = gog_object_get_child_by_name (chart, "Title");
+	GSList *titles = gog_object_get_children (chart, gog_object_find_role_by_name (chart, "Title"));
 
 	static struct {
 		char const * type;
@@ -3977,45 +4020,20 @@ odf_write_plot (GnmOOExport *state, SheetObject *so, GogObject const *chart, Gog
 
 	/* Set up title */
 
-	if (title != NULL) {
-		GOData const *dat = gog_dataset_get_dim (GOG_DATASET(title),0);
-		if (dat != NULL) {
-			GnmExprTop const *texpr = gnm_go_data_get_expr (dat);
-			if (texpr != NULL) {
-				GnmParsePos pp;
-				char *formula;
-				parse_pos_init_sheet (&pp, state->sheet);
-				formula = gnm_expr_top_as_string (texpr, &pp, state->conv);
-
-				gsf_xml_out_start_element (state->xml, CHART "title");
+	if (titles != NULL) {
+		GogObject const *title = NULL;
 
-				if (gnm_expr_top_is_rangeref (texpr)) {
-					gsf_xml_out_add_cstr (state->xml, TABLE "cell-range-address",
-								      odf_strip_brackets (formula));
-				} else if (GNM_EXPR_GET_OPER (texpr->expr) == GNM_EXPR_OP_CONSTANT 
-					   && texpr->expr->constant.value->type == VALUE_STRING) {
-					gboolean white_written = TRUE;
-					char const *str;
-					gsf_xml_out_start_element (state->xml, TEXT "p");
-					str = value_peek_string (texpr->expr->constant.value);
-					odf_add_chars (state, str, strlen (str), &white_written);	
-					gsf_xml_out_end_element (state->xml); /* </text:p> */
-				} else {
-					gboolean white_written = TRUE;
-					if (state->with_extension)
-						gsf_xml_out_add_cstr (state->xml, GNMSTYLE "expression",
-								      formula);
-					gsf_xml_out_start_element (state->xml, TEXT "p");
-					odf_add_chars (state, formula, strlen (formula), 
-						       &white_written);	
-					gsf_xml_out_end_element (state->xml); /* </text:p> */	
-				}
-				gsf_xml_out_end_element (state->xml); /* </chart:title> */
-				g_free (formula);
-			}
+		title = titles->data;
+		odf_write_title (state, title, CHART "title");
+		if (titles->next != NULL) {
+			title = titles->next->data;
+			odf_write_title (state, title, CHART "subtitle");			
 		}
+
+		g_slist_free (titles);
 	}
 
+
 	/* Set up legend if appropriate*/
 
 	if (legend != NULL) {



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