[gnumeric] Move GOFormat ODF handling into goffice.
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnumeric] Move GOFormat ODF handling into goffice.
- Date: Wed, 27 May 2009 18:26:14 -0400 (EDT)
commit 410ceeba7cba37c462b2f0755547ac4a3ee3a7a4
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date: Wed May 27 16:25:37 2009 -0600
Move GOFormat ODF handling into goffice.
2009-05-27 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-write.c (odf_write_day): deleted (moved to goffice)
(odf_write_month): ditto
(odf_write_year): ditto
(odf_write_hour): ditto
(odf_write_minute): ditto
(odf_write_second): ditto
(odf_write_ampm): ditto
(odf_write_date_style): ditto
(odf_write_time_style): ditto
(odf_write_number_style): ditto
(odf_write_currency_style): ditto
(odf_write_percentage_style): ditto
(odf_write_fraction_style): ditto
(odf_write_scientific_style): ditto
(odf_write_this_xl_style): use go_format_output_to_odf for all
but the conditional formats
(odf_write_data_styles): deleted
(odf_write_styles): call g_hash_table_foreach directly
---
plugins/openoffice/ChangeLog | 21 ++
plugins/openoffice/openoffice-write.c | 445 +--------------------------------
2 files changed, 25 insertions(+), 441 deletions(-)
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 3b63923..ccac4a1 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,24 @@
+2009-05-27 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * openoffice-write.c (odf_write_day): deleted (moved to goffice)
+ (odf_write_month): ditto
+ (odf_write_year): ditto
+ (odf_write_hour): ditto
+ (odf_write_minute): ditto
+ (odf_write_second): ditto
+ (odf_write_ampm): ditto
+ (odf_write_date_style): ditto
+ (odf_write_time_style): ditto
+ (odf_write_number_style): ditto
+ (odf_write_currency_style): ditto
+ (odf_write_percentage_style): ditto
+ (odf_write_fraction_style): ditto
+ (odf_write_scientific_style): ditto
+ (odf_write_this_xl_style): use go_format_output_to_odf for all
+ but the conditional formats
+ (odf_write_data_styles): deleted
+ (odf_write_styles): call g_hash_table_foreach directly
+
2009-05-26 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-write.c (xl_find_format): if the format is not simple
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index f4370b2..53b9abf 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -1929,401 +1929,6 @@ odf_write_content (GnmOOExport *state, GsfOutput *child)
/*****************************************************************************/
-static int
-odf_write_day (GnmOOExport *state, char const *xl)
-{
- int ds = strspn(xl, "d");
-
- switch (ds) {
- case 0:
- g_warning ("odf_write_day should only be called with pending 'd'!");
- return 1;
- case 1:
- gsf_xml_out_start_element (state->xml, NUMBER "day");
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "short");
- break;
- case 2:
- gsf_xml_out_start_element (state->xml, NUMBER "day");
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "long");
- break;
- case 3:
- gsf_xml_out_start_element (state->xml, NUMBER "day-of-week");
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "short");
- break;
- case 4:
- default:
- gsf_xml_out_start_element (state->xml, NUMBER "day-of-week");
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "long");
- break;
- }
- gsf_xml_out_end_element (state->xml); /* </number:day or day-of-week> */
- return ds;
-}
-
-static int
-odf_write_month (GnmOOExport *state, char const *xl)
-{
- int ds = strspn(xl, "m");
-
- gsf_xml_out_start_element (state->xml, NUMBER "month");
- gsf_xml_out_add_cstr (state->xml, NUMBER "possessive-form", "false");
- switch (ds) {
- case 0:
- g_warning ("odf_write_month should only be called with pending 'm'!");
- ds++;
- case 1:
- gsf_xml_out_add_cstr (state->xml, NUMBER "textual", "false");
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "short");
- break;
- case 2:
- gsf_xml_out_add_cstr (state->xml, NUMBER "textual", "false");
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "long");
- break;
- case 3:
- gsf_xml_out_add_cstr (state->xml, NUMBER "textual", "true");
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "short");
- break;
- case 5:
- gsf_xml_out_add_cstr (state->xml, NUMBER "textual", "true");
- /* ODF does not support the one letter abbreviation of the month */
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "short");
- break;
- case 4:
- default:
- gsf_xml_out_add_cstr (state->xml, NUMBER "textual", "true");
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "long");
- break;
- }
- gsf_xml_out_end_element (state->xml); /* </number:day or day-of-week> */
- return ds;
-}
-
-static int
-odf_write_year (GnmOOExport *state, char const *xl)
-{
- int ds = strspn(xl, "y");
-
- gsf_xml_out_start_element (state->xml, NUMBER "year");
- switch (ds) {
- case 0:
- g_warning ("odf_write_year should only be called with pending 'y'!");
- ds++;
- case 1:
- case 2:
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "short");
- break;
- default:
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "long");
- break;
- }
- gsf_xml_out_end_element (state->xml); /* </number:year> */
- return ds;
-}
-
-static int
-odf_write_hour (GnmOOExport *state, char const *xl)
-{
- int ds = strspn(xl, "h");
-
- gsf_xml_out_start_element (state->xml, NUMBER "hours");
- switch (ds) {
- case 0:
- g_warning ("odf_write_hour should only be called with pending 'h'!");
- ds++;
- case 1:
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "short");
- break;
- default:
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "long");
- break;
- }
- gsf_xml_out_end_element (state->xml); /* </number:hours> */
- return ds;
-}
-
-static int
-odf_write_minute (GnmOOExport *state, char const *xl)
-{
- int ds = strspn(xl, "m");
-
- gsf_xml_out_start_element (state->xml, NUMBER "minutes");
- switch (ds) {
- case 0:
- g_warning ("odf_write_minute should only be called with pending 'm'!");
- ds++;
- case 1:
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "short");
- break;
- default:
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "long");
- break;
- }
- gsf_xml_out_end_element (state->xml); /* </number:minutes> */
- return ds;
-}
-
-static int
-odf_write_second (GnmOOExport *state, char const *xl)
-{
- int ds = strspn(xl, "s");
- int dec = 0;
-
- gsf_xml_out_start_element (state->xml, NUMBER "seconds");
- switch (ds) {
- case 0:
- g_warning ("odf_write_second should only be called with pending 's'!");
- ds++;
- case 1:
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "short");
- break;
- default:
- gsf_xml_out_add_cstr (state->xml, NUMBER "style", "long");
- break;
- }
- if (*(xl+ds)=='.') {
- dec = strspn(xl+ds+1, "0");
- if (dec >0)
- gsf_xml_out_add_int (state->xml, NUMBER "decimal-places", dec);
- ds += 1 + dec;
- }
-
- gsf_xml_out_end_element (state->xml); /* </number:minutes> */
- return ds;
-}
-
-static int
-odf_write_ampm (GnmOOExport *state, char const *xl)
-{
- gboolean ampm = g_str_has_prefix (xl, "AM/PM");
-
- if (ampm) {
- gsf_xml_out_simple_element (state->xml, NUMBER "am-pm", NULL);
- return 5;
- }
- return 0;
-}
-
-static void
-odf_write_date_style (GnmOOExport *state, GOFormat const *format, char const *name)
-{
- char const *xl = go_format_as_XL (format);
- gboolean hour_seen = FALSE;
- gboolean ignore_A = FALSE;
- int val;
-
- /* This indicates the magic number of the style. We should only get here if *\
- \* we didn't insert this magic format by default. */
- if (*xl == '[') {
- char const *end = strchr(xl, ']');
- if (end != NULL)
- xl = end + 1;
- }
-
- gsf_xml_out_start_element (state->xml, NUMBER "date-style");
- gsf_xml_out_add_cstr (state->xml, STYLE "name", name);
- gsf_xml_out_add_cstr (state->xml, NUMBER "format-source", "fixed");
- gsf_xml_out_add_cstr (state->xml, GNMSTYLE "format", xl);
-
- while (*xl != '\0') {
- int nw;
-
- if (ignore_A) {
- nw = strcspn(xl, "dmyhs");
- ignore_A = FALSE;
- } else
- nw = strcspn(xl, "dmyhsA");
-
- if (nw > 0) {
- gsf_xml_out_start_element (state->xml, NUMBER "text");
- /* number:text preserves whitespace so no special handling needed */
- odf_add_chars_non_white (state, xl, nw);
- gsf_xml_out_end_element (state->xml); /* </number:text> */
- xl += nw;
- }
-
- switch (*xl) {
- case 'd':
- xl += odf_write_day (state, xl);
- break;
- case 'm':
- xl += hour_seen ? odf_write_minute (state, xl)
- : odf_write_month (state, xl);
- break;
- case 'y':
- xl += odf_write_year (state, xl);
- break;
- case 'h':
- xl += odf_write_hour (state, xl);
- hour_seen = TRUE;
- break;
- case 's':
- xl += odf_write_second (state, xl);
- break;
- case'A':
- val = odf_write_ampm (state, xl);
- ignore_A = (val != 0);
- xl += val;
- break;
- case '\0':
- break;
- default:
- g_warning ("We should not get here!");
- gsf_xml_out_end_element (state->xml); /* </> */
- break;
- }
- }
-
- gsf_xml_out_end_element (state->xml); /* </number:date-style> */
-}
-
-static void
-odf_write_time_style (GnmOOExport *state, GOFormat const *format, char const *name)
-{
- char const *xl = go_format_as_XL (format);
- gboolean ignore_A = FALSE;
- int val;
-
- if (*xl == '[') {
- char const *end = strchr(xl, ']');
- if (end != NULL)
- xl = end + 1;
- }
-
- gsf_xml_out_start_element (state->xml, NUMBER "time-style");
- gsf_xml_out_add_cstr (state->xml, STYLE "name", name);
- gsf_xml_out_add_cstr (state->xml, GNMSTYLE "format", go_format_as_XL (format));
-
- while (*xl != '\0') {
- int nw;
-
- if (ignore_A) {
- nw = strcspn(xl, "mhs");
- ignore_A = FALSE;
- } else
- nw = strcspn(xl, "mhsA");
-
- if (nw > 0) {
- gsf_xml_out_start_element (state->xml, NUMBER "text");
- /* number:text preserves whitespace so no special handling needed */
- odf_add_chars_non_white (state, xl, nw);
- gsf_xml_out_end_element (state->xml); /* </number:text> */
- xl += nw;
- }
-
- switch (*xl) {
- case 'm':
- xl += odf_write_minute (state, xl);
- break;
- case 'h':
- xl += odf_write_hour (state, xl);
- break;
- case 's':
- xl += odf_write_second (state, xl);
- break;
- case'A':
- val = odf_write_ampm (state, xl);
- ignore_A = (val != 0);
- xl += val;
- break;
- case '\0':
- break;
- default:
- g_warning ("We should not get here!");
- gsf_xml_out_end_element (state->xml); /* </> */
- break;
- }
- }
-
- gsf_xml_out_end_element (state->xml); /* </number:time-style> */
-}
-
-static void
-odf_write_number_style (GnmOOExport *state, GOFormat const *format, char const *name)
-{
-/* FIXME: we are using default of "#,##0.00" at this time */
- gsf_xml_out_start_element (state->xml, NUMBER "number-style");
- gsf_xml_out_add_cstr (state->xml, STYLE "name", name);
- gsf_xml_out_add_cstr (state->xml, GNMSTYLE "format", go_format_as_XL (format));
- gsf_xml_out_start_element (state->xml, NUMBER "number");
- gsf_xml_out_add_int (state->xml, NUMBER "decimal-places", 2);
-/* gsf_xml_out_add_cstr (state->xml, NUMBER "decimal-replacement", ); */
- gsf_xml_out_add_int (state->xml, NUMBER "display-factor", 1);
- odf_add_bool (state->xml, NUMBER "grouping", TRUE);
- gsf_xml_out_add_int (state->xml, NUMBER "min-integer-digits", 1);
- gsf_xml_out_end_element (state->xml); /* </number:number> */
- gsf_xml_out_end_element (state->xml); /* </number:number-style> */
-}
-
-static void
-odf_write_currency_style (GnmOOExport *state, GOFormat const *format, char const *name)
-{
-/* FIXME: goffice never yields this family, so we should not get here. */
- gsf_xml_out_start_element (state->xml, NUMBER "currency-style");
- gsf_xml_out_add_cstr (state->xml, STYLE "name", name);
- gsf_xml_out_add_cstr (state->xml, GNMSTYLE "format", go_format_as_XL (format));
- gsf_xml_out_simple_element(state->xml, NUMBER "currency-symbol", NULL);
- gsf_xml_out_start_element (state->xml, NUMBER "number");
- gsf_xml_out_add_int (state->xml, NUMBER "decimal-places", 2);
-/* gsf_xml_out_add_cstr (state->xml, NUMBER "decimal-replacement", ); */
- gsf_xml_out_add_int (state->xml, NUMBER "display-factor", 1);
- odf_add_bool (state->xml, NUMBER "grouping", TRUE);
- gsf_xml_out_add_int (state->xml, NUMBER "min-integer-digits", 1);
- gsf_xml_out_end_element (state->xml); /* </number:number> */
- gsf_xml_out_end_element (state->xml); /* </number:currency-style> */
-}
-
-static void
-odf_write_percentage_style (GnmOOExport *state, GOFormat const *format, char const *name)
-{
-/* FIXME: we are using default of "0.00%" at this time */
- gsf_xml_out_start_element (state->xml, NUMBER "percentage-style");
- gsf_xml_out_add_cstr (state->xml, STYLE "name", name);
- gsf_xml_out_add_cstr (state->xml, GNMSTYLE "format", go_format_as_XL (format));
- gsf_xml_out_start_element (state->xml, NUMBER "number");
- gsf_xml_out_add_int (state->xml, NUMBER "decimal-places", 2);
-/* gsf_xml_out_add_cstr (state->xml, NUMBER "decimal-replacement", ); */
- gsf_xml_out_add_int (state->xml, NUMBER "display-factor", 1);
- odf_add_bool (state->xml, NUMBER "grouping", FALSE);
- gsf_xml_out_add_int (state->xml, NUMBER "min-integer-digits", 1);
- gsf_xml_out_end_element (state->xml); /* </number:number> */
- gsf_xml_out_simple_element(state->xml, NUMBER "text", "%");
- gsf_xml_out_end_element (state->xml); /* </number:percentage-style> */
-}
-
-static void
-odf_write_fraction_style (GnmOOExport *state, GOFormat const *format, char const *name)
-{
-/* FIXME: we are using default of ?? at this time */
- gsf_xml_out_start_element (state->xml, NUMBER "number-style");
- gsf_xml_out_add_cstr (state->xml, STYLE "name", name);
- gsf_xml_out_add_cstr (state->xml, GNMSTYLE "format", go_format_as_XL (format));
- gsf_xml_out_start_element (state->xml, NUMBER "fraction");
-/* gsf_xml_out_add_int (state->xml, NUMBER "denominator-value", 1); */
- odf_add_bool (state->xml, NUMBER "grouping", FALSE);
- gsf_xml_out_add_int (state->xml, NUMBER "min-denominator-digits", 3);
- gsf_xml_out_add_int (state->xml, NUMBER "min-integer-digits", 0);
- gsf_xml_out_add_int (state->xml, NUMBER "min-numerator-digits", 1);
- gsf_xml_out_end_element (state->xml); /* </number:fraction> */
- gsf_xml_out_end_element (state->xml); /* </number:number-style> */
-}
-
-static void
-odf_write_scientific_style (GnmOOExport *state, GOFormat const *format, char const *name)
-{
-/* FIXME: we are using default of "0.00E+00" at this time */
- gsf_xml_out_start_element (state->xml, NUMBER "number-style");
- gsf_xml_out_add_cstr (state->xml, STYLE "name", name);
- gsf_xml_out_add_cstr (state->xml, GNMSTYLE "format", go_format_as_XL (format));
- gsf_xml_out_start_element (state->xml, NUMBER "scientific-number");
- gsf_xml_out_add_int (state->xml, NUMBER "decimal-places", 2);
- odf_add_bool (state->xml, NUMBER "grouping", FALSE);
- gsf_xml_out_add_int (state->xml, NUMBER "min-integer-digits", 1);
- gsf_xml_out_add_int (state->xml, NUMBER "min-exponent-digits", 2);
- gsf_xml_out_end_element (state->xml); /* </number:scientific-number> */
- gsf_xml_out_end_element (state->xml); /* </number:number-style> */
-}
-
-
static void
odf_write_conditional_style (GOFormat *format, char const *name, GnmOOExport *state)
{
@@ -2358,57 +1963,15 @@ odf_write_this_xl_style (char const *xl, char const *name, GnmOOExport *state)
format = go_format_new_from_XL (xl);
- if (go_format_is_simple (format)) {
- switch (go_format_get_family (format)) {
- case GO_FORMAT_NUMBER:
- odf_write_number_style (state, format, name);
- break;
- case GO_FORMAT_CURRENCY:
- case GO_FORMAT_ACCOUNTING:
- odf_write_currency_style (state, format, name);
- break;
- case GO_FORMAT_DATE:
- odf_write_date_style (state, format, name);
- break;
- case GO_FORMAT_TIME:
- odf_write_time_style (state, format, name);
- break;
- case GO_FORMAT_PERCENTAGE:
- odf_write_percentage_style (state, format, name);
- break;
- case GO_FORMAT_FRACTION:
- odf_write_fraction_style (state, format, name);
- break;
- case GO_FORMAT_SCIENTIFIC:
- odf_write_scientific_style (state, format, name);
- break;
- case GO_FORMAT_TEXT:
- case GO_FORMAT_SPECIAL:
- case GO_FORMAT_UNKNOWN:
- case GO_FORMAT_GENERAL:
- default:
- go_format_output_to_odf (state->xml, format, name);
- }
- } else
+ if (go_format_is_simple (format))
+ go_format_output_to_odf (state->xml, format, name);
+ else
odf_write_conditional_style (format, name, state);
go_format_unref (format);
}
static void
-odf_write_data_styles (GnmOOExport *state)
-{
- gboolean pp = TRUE;
-
- g_object_get (G_OBJECT (state->xml), "pretty-print", &pp, NULL);
- /* We need to switch off pretty printing since number:text preserves whitespace */
- g_object_set (G_OBJECT (state->xml), "pretty-print", FALSE, NULL);
- g_hash_table_foreach (state->xl_styles, (GHFunc) odf_write_this_xl_style, state);
- g_object_set (G_OBJECT (state->xml), "pretty-print", pp, NULL);
-}
-
-
-static void
odf_write_styles (GnmOOExport *state, GsfOutput *child)
{
int i;
@@ -2440,7 +2003,7 @@ odf_write_styles (GnmOOExport *state, GsfOutput *child)
gsf_xml_out_end_element (state->xml); /* </style:default-style */
}
- odf_write_data_styles (state);
+ g_hash_table_foreach (state->xl_styles, (GHFunc) odf_write_this_xl_style, state);
gsf_xml_out_end_element (state->xml); /* </office:styles> */
gsf_xml_out_end_element (state->xml); /* </office:document-styles> */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]