[gnumeric] Read fraction formats correctly from ODF 1.2 files.



commit e6b5bf1aa46ef5360085390e1f8714757be5a51f
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Thu Jun 9 00:27:46 2011 -0600

    Read fraction formats correctly from ODF 1.2 files.
    
    2011-06-09  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* developer/odf-foreign.txt: update
    
    2011-06-09  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (odf_fraction): handle absence of min_i_digits
    	correctly depending on ODF version
    	(odf_find_version): new
    	(styles_dtd): connect odf_find_version and add a bunch of stubs
    	(opendoc_content_dtd): connect odf_find_version
    	(openoffice_file_open): initialize new field ver_odf

 NEWS                                 |    1 +
 doc/ChangeLog                        |    4 ++
 doc/developer/odf-foreign.txt        |   17 +++++-----
 plugins/openoffice/ChangeLog         |    9 +++++
 plugins/openoffice/openoffice-read.c |   54 +++++++++++++++++++++++++++-------
 src/gui-util.c                       |    2 +-
 6 files changed, 67 insertions(+), 20 deletions(-)
---
diff --git a/NEWS b/NEWS
index ee2092a..5c71c71 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ Andreas
 	  [#651173][#646612]
 	* Import external references from ODF. [#645580]
 	* Some documentation improvements.
+	* Read fraction formats correctly from ODF 1.2 files.
 
 Morten:
 	* Fix leaks in SHEET.  [#650761]
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 7658d40..1da6162 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,7 @@
+2011-06-09  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* developer/odf-foreign.txt: update
+
 2011-06-08  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* developer/odf-foreign.txt: update
diff --git a/doc/developer/odf-foreign.txt b/doc/developer/odf-foreign.txt
index 372b51f..73dcab1 100644
--- a/doc/developer/odf-foreign.txt
+++ b/doc/developer/odf-foreign.txt
@@ -4,7 +4,12 @@ Note: Any reference to ODF 1.3 refers tot eh current work-in-progress in the OAS
 
 Part 1: In ODF 1.0 and 1.1 files only.
 
-1) Attributes added by Gnumeric:
+2) Attributes added by GOffice:
+
+gnm:no-integer-part
+An attribute to <number:fraction> determining whether an integer portion is shown or not. Defaults to "false" (i.e. an integer part is shown.)
+
+2) Attributes added by Gnumeric:
 
 gnm:reverse-direction
 gnm:automatic-content
@@ -20,6 +25,9 @@ gnm:engineering
 An attribute to <number:scientific-number>. A value of "true" indicates that the exponent will always be a multiple of 3.
 (In ODF 1.3 to be replaced by number:exponent-base=1 ("false") or =3 ("true") resp.)
 
+gnm:max-denominator-digits
+An attribute to <number:fraction> giving the maximum number of denominator digits to be used.
+
 2) Attribute _values_ added by Gnumeric. 
 Since these are not eleemnts or new attributes they are used in all ODF exports.
 
@@ -39,13 +47,6 @@ An attribute to <number:time-style> and <number:date-style> to specify Gnumeric'
 gnm:truncate-on-overflow
 An attribute to <number:hours>, <number:minutes> and <number:seconds>. An attribute value of "false" indicates that this item is not restricted to its natural range and so is used for elapsed time. This attribute defaults to "true". Note that ODF has the attribute number:truncate-on-overflow of the <number:time-style> with a similar effect, but with unclear specification to which element it applies. For an element where gnm:truncate-on-overflow is not set, number:truncate-on-overflow applies.
 
-gnm:max-denominator-digits
-An attribute to <number:fraction> giving the maximum number of denominator digits to be used.
-
-gnm:no-integer-part
-An attribute to <number:fraction> determining whether an integer portion is shown or not. Defaults to "false" (i.e. an integer part is shown.)
-
-
 2) Elements and attributes added by Gnumeric:
 
 gnm:border-line-style-top
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 32e8cb8..d8d3e35 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,12 @@
+2011-06-09  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-read.c (odf_fraction): handle absence of min_i_digits
+	correctly depending on ODF version
+	(odf_find_version): new
+	(styles_dtd): connect odf_find_version and add a bunch of stubs
+	(opendoc_content_dtd): connect odf_find_version
+	(openoffice_file_open): initialize new field ver_odf
+
 2011-05-28  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* openoffice-write.c (odf_write_comment): fix leak
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 6580bd1..f245a75 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -299,6 +299,7 @@ typedef struct {
 	GOIOContext	*context;	/* The IOcontext managing things */
 	WorkbookView	*wb_view;	/* View for the new workbook */
 	OOVer		 ver;		/* Its an OOo v1.0 or v2.0? */
+	gnm_float	 ver_odf;	/* specific ODF version */
 	GsfInfile	*zip;		/* Reference to the open file, to load graphs and images*/
 	OOChartInfo	 chart;
 	GnmParsePos	 pos;
@@ -3663,7 +3664,7 @@ odf_fraction (GsfXMLIn *xin, xmlChar const **attrs)
 	int denominator = 0;
 	int min_d_digits = 0;
 	int max_d_digits = 3;
-	int min_i_digits = 0;
+	int min_i_digits = -1;
 	int min_n_digits = 0;
 
 
@@ -3688,10 +3689,10 @@ odf_fraction (GsfXMLIn *xin, xmlChar const **attrs)
 					       "min-numerator-digits", &min_n_digits, 0, 30))
 			;
 
-	if (!no_int_part) {
+	if (!no_int_part && (state->ver_odf < 1.2 || min_i_digits >= 0)) {
 		g_string_append_c (state->cur_format.accum, '#');
 		odf_go_string_append_c_n (state->cur_format.accum, '0',
-					  min_i_digits);
+					  min_i_digits > 0 ? min_i_digits : 0);
 		g_string_append_c (state->cur_format.accum, ' ');
 	}
 	g_string_append_c (state->cur_format.accum, '?');
@@ -7847,18 +7848,31 @@ oo_marker (GsfXMLIn *xin, xmlChar const **attrs)
 
 /**************************************************************************/
 
+static void
+odf_find_version (GsfXMLIn *xin, xmlChar const **attrs)
+{
+	OOParseState *state = (OOParseState *)xin->user_state;
+	
+	for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
+		if (oo_attr_float (xin, attrs, OO_NS_OFFICE,
+					"version", &state->ver_odf));
+}
+
+/**************************************************************************/
+
 static GsfXMLInNode const styles_dtd[] = {
 GSF_XML_IN_NODE_FULL (START, START, -1, NULL, GSF_XML_NO_CONTENT, FALSE, TRUE, NULL, NULL, 0),
 
 /* ooo-1.x */
-GSF_XML_IN_NODE (START, OFFICE_FONTS, OO_NS_OFFICE, "font-decls", GSF_XML_NO_CONTENT, NULL, NULL),
-  GSF_XML_IN_NODE (OFFICE_FONTS, FONT_DECL, OO_NS_STYLE, "font-decl", GSF_XML_NO_CONTENT, NULL, NULL),
+GSF_XML_IN_NODE (START, OFFICE_FONTS_OOO1, OO_NS_OFFICE, "font-decls", GSF_XML_NO_CONTENT, NULL, NULL),
+  GSF_XML_IN_NODE (OFFICE_FONTS_OOO1, FONT_DECL_OOO1, OO_NS_STYLE, "font-decl", GSF_XML_NO_CONTENT, NULL, NULL),
 
-/* ooo-2.x */
-GSF_XML_IN_NODE (START, OFFICE_FONTS, OO_NS_OFFICE, "font-face-decls", GSF_XML_NO_CONTENT, NULL, NULL),
-  GSF_XML_IN_NODE (OFFICE_FONTS, FONT_DECL, OO_NS_STYLE, "font-face", GSF_XML_NO_CONTENT, NULL, NULL),
+/* ooo-2.x, ooo-3.x */
+GSF_XML_IN_NODE (START, OFFICE_DOC_STYLES, OO_NS_OFFICE, "document-styles", GSF_XML_NO_CONTENT, &odf_find_version, NULL),
+GSF_XML_IN_NODE (OFFICE_DOC_STYLES, OFFICE_FONTS, OO_NS_OFFICE, "font-face-decls", GSF_XML_NO_CONTENT, NULL, NULL),
+  GSF_XML_IN_NODE (OFFICE_FONTS, FONT_DECL, OO_NS_STYLE, "font-face", GSF_XML_NO_CONTENT, NULL, NULL), /* 2nd */
 
-GSF_XML_IN_NODE (START, OFFICE_STYLES, OO_NS_OFFICE, "styles", GSF_XML_NO_CONTENT, NULL, NULL),
+GSF_XML_IN_NODE (OFFICE_DOC_STYLES, OFFICE_STYLES, OO_NS_OFFICE, "styles", GSF_XML_NO_CONTENT, NULL, NULL),
   GSF_XML_IN_NODE (OFFICE_STYLES, FILLIMAGE, OO_NS_DRAW, "fill-image", GSF_XML_NO_CONTENT, &oo_fill_image, NULL),
   GSF_XML_IN_NODE (OFFICE_STYLES, DASH, OO_NS_DRAW, "stroke-dash", GSF_XML_NO_CONTENT, &oo_dash, NULL),
   GSF_XML_IN_NODE (OFFICE_STYLES, HATCH, OO_NS_DRAW, "hatch", GSF_XML_NO_CONTENT, &oo_hatch, NULL),
@@ -7941,6 +7955,22 @@ GSF_XML_IN_NODE (START, OFFICE_STYLES, OO_NS_OFFICE, "styles", GSF_XML_NO_CONTEN
     GSF_XML_IN_NODE (STYLE_TEXT, STYLE_TEXT_MAP, OO_NS_STYLE,		"map", GSF_XML_NO_CONTENT, &odf_map, NULL),
     GSF_XML_IN_NODE (STYLE_TEXT, STYLE_TEXT_TEXT_PROP, OO_NS_STYLE,	"text-properties", GSF_XML_NO_CONTENT, &odf_number_color, NULL),
 
+GSF_XML_IN_NODE (OFFICE_DOC_STYLES, AUTOMATIC_STYLES, OO_NS_OFFICE, "automatic-styles", GSF_XML_NO_CONTENT, NULL, NULL),
+  GSF_XML_IN_NODE (AUTOMATIC_STYLES, STYLE, OO_NS_STYLE, "style", GSF_XML_NO_CONTENT, NULL, NULL), /* 2nd */
+  GSF_XML_IN_NODE (AUTOMATIC_STYLES, PAGE_LAYOUT, OO_NS_STYLE, "page-layout", GSF_XML_NO_CONTENT, NULL, NULL),
+  GSF_XML_IN_NODE (AUTOMATIC_STYLES, NUMBER_STYLE, OO_NS_NUMBER, "number-style", GSF_XML_NO_CONTENT, NULL, NULL), /* 2nd */
+  GSF_XML_IN_NODE (AUTOMATIC_STYLES, DATE_STYLE, OO_NS_NUMBER, "date-style", GSF_XML_NO_CONTENT, NULL, NULL), /* 2nd */
+  GSF_XML_IN_NODE (AUTOMATIC_STYLES, TIME_STYLE, OO_NS_NUMBER, "time-style", GSF_XML_NO_CONTENT, NULL, NULL), /* 2nd */
+  GSF_XML_IN_NODE (AUTOMATIC_STYLES, STYLE_BOOL, OO_NS_NUMBER, "boolean-style", GSF_XML_NO_CONTENT, NULL, NULL), /* 2nd */
+  GSF_XML_IN_NODE (AUTOMATIC_STYLES, STYLE_CURRENCY, OO_NS_NUMBER,   "currency-style", GSF_XML_NO_CONTENT, NULL, NULL), /* 2nd */
+  GSF_XML_IN_NODE (AUTOMATIC_STYLES, STYLE_PERCENTAGE, OO_NS_NUMBER, "percentage-style", GSF_XML_NO_CONTENT, NULL, NULL), /* 2nd */
+  GSF_XML_IN_NODE (AUTOMATIC_STYLES, STYLE_TEXT, OO_NS_NUMBER, "text-style", GSF_XML_NO_CONTENT, NULL, NULL), /* 2nd */
+
+GSF_XML_IN_NODE (OFFICE_DOC_STYLES, MASTER_STYLES, OO_NS_OFFICE, "master-styles", GSF_XML_NO_CONTENT, NULL, NULL),
+  GSF_XML_IN_NODE (MASTER_STYLES, MASTER_PAGE, OO_NS_STYLE, "master-page", GSF_XML_NO_CONTENT, NULL, NULL),
+  GSF_XML_IN_NODE (MASTER_PAGE, MASTER_PAGE_HEADER_LEFT, OO_NS_STYLE, "header-left", GSF_XML_NO_CONTENT, NULL, NULL),
+  GSF_XML_IN_NODE (MASTER_PAGE, MASTER_PAGE_FOOTER_LEFT, OO_NS_STYLE, "footer-left", GSF_XML_NO_CONTENT, NULL, NULL),
+  GSF_XML_IN_NODE (MASTER_PAGE, MASTER_PAGE_FOOTER, OO_NS_STYLE, "footer", GSF_XML_NO_CONTENT, NULL, NULL),
 GSF_XML_IN_NODE_END
 };
 
@@ -8070,7 +8100,7 @@ GSF_XML_IN_NODE_END
 static GsfXMLInNode const opendoc_content_dtd [] =
 {
 	GSF_XML_IN_NODE_FULL (START, START, -1, NULL, GSF_XML_NO_CONTENT, FALSE, TRUE, NULL, NULL, 0),
-	GSF_XML_IN_NODE (START, OFFICE, OO_NS_OFFICE, "document-content", GSF_XML_NO_CONTENT, NULL, NULL),
+	GSF_XML_IN_NODE (START, OFFICE, OO_NS_OFFICE, "document-content", GSF_XML_NO_CONTENT, &odf_find_version, NULL),
 	  GSF_XML_IN_NODE (OFFICE, SCRIPT, OO_NS_OFFICE, "scripts", GSF_XML_NO_CONTENT, NULL, NULL),
 	  GSF_XML_IN_NODE (OFFICE, OFFICE_FONTS, OO_NS_OFFICE, "font-face-decls", GSF_XML_NO_CONTENT, NULL, NULL),
 	    GSF_XML_IN_NODE (OFFICE_FONTS, FONT_FACE, OO_NS_STYLE, "font-face", GSF_XML_NO_CONTENT, NULL, NULL),
@@ -9129,7 +9159,9 @@ openoffice_file_open (GOFileOpener const *fo, GOIOContext *io_context,
 					     _("Unknown mimetype for openoffice file."));
 		g_object_unref (zip);
 		return;
-	}
+	} else if (state.ver == OOO_VER_OPENDOC)
+		state.ver_odf = 1.2; /* Probably most common at this time */
+	else  state.ver_odf = 0.;
 
 	contents = gsf_infile_child_by_name (zip, "content.xml");
 	if (contents == NULL) {
diff --git a/src/gui-util.c b/src/gui-util.c
index 17790e8..78e67db 100644
--- a/src/gui-util.c
+++ b/src/gui-util.c
@@ -769,7 +769,7 @@ gnm_create_std_tags_for_buffer (GtkTextBuffer *buffer)
 static gint
 gnm_load_pango_byte_to_char (gchar const *str, gint byte)
 {
-	if (byte >= strlen (str))
+	if (byte >= (gint) strlen (str))
 		return g_utf8_strlen (str, -1);
 	return g_utf8_pointer_to_offset (str, 
 					 g_utf8_prev_char (str + byte + 1));



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