[gnumeric] Improve import/export of page layout from/to ODF.



commit c992765790c7ca9560703bdba596577c41b1d0c9
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Fri Jun 5 16:17:29 2015 -0600

    Improve import/export of page layout from/to ODF.
    
    2015-06-5  Andreas J. Guelzow <aguelzow pyrshep ca>
    
        * ods-ext-schema.patch: add new attributes
    
    2015-06-05  Andreas J. Guelzow <aguelzow pyrshep ca>
    
        * openoffice-write.c (odf_write_page_layout): write scaling information
        * openoffice-read.c (odf_page_layout_properties): handle scaling

 NEWS                                  |    1 +
 plugins/openoffice/ChangeLog          |    5 ++
 plugins/openoffice/openoffice-read.c  |   75 +++++++++++++++++++++++----------
 plugins/openoffice/openoffice-write.c |   30 +++++++++++++
 test/ChangeLog                        |    4 ++
 test/ods-ext-schema.patch             |   40 +++++++++++-------
 6 files changed, 117 insertions(+), 38 deletions(-)
---
diff --git a/NEWS b/NEWS
index ad0f583..8840df2 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ Gnumeric 1.12.23
 
 Andreas:
        * Fix memory handling error on fuzzed sxc file. [#748535]
+       * Improve import/export of page layout from/to ODF.
 
 Jean:
        * Fix xlsx import of plot area manual layout. [#748016]
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 9dc89c6..6db5a97 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,8 @@
+2015-06-05  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+       * openoffice-write.c (odf_write_page_layout): write scaling information
+       * openoffice-read.c (odf_page_layout_properties): handle scaling
+
 2015-05-09  Andreas J. Guelzow <aguelzow pyrshep ca>
 
        * openoffice-write.c (odf_write_multi_chart_frame_size): add parentheses
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 70424b3..68911f8 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -5793,8 +5793,12 @@ odf_page_layout_properties (GsfXMLIn *xin, xmlChar const **attrs)
        gint orient = GTK_PAGE_ORIENTATION_PORTRAIT;
        gboolean gnm_style_print = FALSE;
        gboolean annotations_at_end = FALSE;
+       gnm_float scale_to = 1.;
+       gint scale_to_x = 0;
+       gint scale_to_y = 0;
+       GnmPrintInformation *pi = state->print.cur_pi;
 
-       if (state->print.cur_pi == NULL)
+       if (pi == NULL)
                return;
        gps = gnm_print_info_get_page_setup (state->print.cur_pi);
        gtk_page_setup_set_orientation (gps, GTK_PAGE_ORIENTATION_PORTRAIT);
@@ -5814,11 +5818,11 @@ odf_page_layout_properties (GsfXMLIn *xin, xmlChar const **attrs)
                        w_set = TRUE;
                else if (oo_attr_enum (xin, attrs, OO_NS_STYLE, "table-centering",
                                       centre_type, &tmp)) {
-                       state->print.cur_pi->center_horizontally = ((1 & tmp) != 0);
-                       state->print.cur_pi->center_vertically = ((2 & tmp) != 0);
+                       pi->center_horizontally = ((1 & tmp) != 0);
+                       pi->center_vertically = ((2 & tmp) != 0);
                } else if (oo_attr_enum (xin, attrs, OO_NS_STYLE, "print-page-order",
                                         print_order_type, &tmp)) {
-                       state->print.cur_pi->print_across_then_down = (tmp == 0);
+                       pi->print_across_then_down = (tmp == 0);
                } else if (oo_attr_enum (xin, attrs, OO_NS_STYLE, "print-orientation",
                                         print_orientation_type, &orient)) {
                        gtk_page_setup_set_orientation (gps, orient);
@@ -5826,47 +5830,72 @@ odf_page_layout_properties (GsfXMLIn *xin, xmlChar const **attrs)
                                               OO_NS_STYLE, "print")) {
                        gchar **items = g_strsplit (CXML2C (attrs[1]), " ", 0);
                        gchar **items_c = items;
-                       state->print.cur_pi->print_grid_lines = 0;
-                       state->print.cur_pi->print_titles = 0;
-                       state->print.cur_pi->comment_placement = GNM_PRINT_COMMENTS_NONE;
+                       pi->print_grid_lines = 0;
+                       pi->print_titles = 0;
+                       pi->comment_placement = GNM_PRINT_COMMENTS_NONE;
                        for (;items != NULL && *items; items++)
                                if (0 == strcmp (*items, "grid"))
-                                       state->print.cur_pi->print_grid_lines = 1;
+                                       pi->print_grid_lines = 1;
                                else if (0 == strcmp (*items, "headers"))
-                                       state->print.cur_pi->print_titles = 1;
+                                       pi->print_titles = 1;
                                else if (0 == strcmp (*items, "annotations"))
                                        /* ODF does not distinguish AT_END and IN_PLACE */
-                                       state->print.cur_pi->comment_placement = GNM_PRINT_COMMENTS_AT_END;
+                                       pi->comment_placement = GNM_PRINT_COMMENTS_AT_END;
                        g_strfreev (items_c);
                } else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]),
                                               OO_GNUM_NS_EXT, "style-print")) {
                        gchar **items = g_strsplit (CXML2C (attrs[1]), " ", 0);
                        gchar **items_c = items;
                        gnm_style_print = TRUE;
-                       state->print.cur_pi->print_black_and_white = 0;
-                       state->print.cur_pi->print_as_draft = 0;
-                       state->print.cur_pi->print_even_if_only_styles = 0;
-                       state->print.cur_pi->error_display = GNM_PRINT_ERRORS_AS_DISPLAYED;
+                       pi->print_black_and_white = 0;
+                       pi->print_as_draft = 0;
+                       pi->print_even_if_only_styles = 0;
+                       pi->error_display = GNM_PRINT_ERRORS_AS_DISPLAYED;
                        for (;items != NULL && *items; items++)
                                if (0 == strcmp (*items, "annotations_at_end"))
                                        annotations_at_end = TRUE;
                                else if (0 == strcmp (*items, "black_n_white"))
-                                       state->print.cur_pi->print_black_and_white = 1;
+                                       pi->print_black_and_white = 1;
                                else if (0 == strcmp (*items, "draft"))
-                                       state->print.cur_pi->print_as_draft = 1;
+                                       pi->print_as_draft = 1;
                                else if (0 == strcmp (*items, "errors_as_blank"))
-                                       state->print.cur_pi->error_display = GNM_PRINT_ERRORS_AS_BLANK;
+                                       pi->error_display = GNM_PRINT_ERRORS_AS_BLANK;
                                else if (0 == strcmp (*items, "errors_as_dashes"))
-                                       state->print.cur_pi->error_display = GNM_PRINT_ERRORS_AS_DASHES;
+                                       pi->error_display = GNM_PRINT_ERRORS_AS_DASHES;
                                else if (0 == strcmp (*items, "errors_as_na"))
-                                       state->print.cur_pi->error_display = GNM_PRINT_ERRORS_AS_NA;
+                                       pi->error_display = GNM_PRINT_ERRORS_AS_NA;
                                else if (0 == strcmp (*items, "print_even_if_only_styles"))
-                                       state->print.cur_pi->print_even_if_only_styles = 1;
+                                       pi->print_even_if_only_styles = 1;
                        g_strfreev (items_c);
-               }
+               } else if (oo_attr_int_range (xin, attrs, OO_NS_STYLE, "scale-to-pages",
+                                             &scale_to_x, 1, INT_MAX)) {
+                       scale_to_y = scale_to_x;
+                       scale_to = -1.;
+               } else if (oo_attr_int_range (xin, attrs, OO_NS_STYLE, "scale-to-X",
+                                             &scale_to_x, 1, INT_MAX)) {
+                       scale_to = -1.;
+               } else if (oo_attr_int_range (xin, attrs, OO_GNUM_NS_EXT, "scale-to-X",
+                                             &scale_to_x, 1, INT_MAX)) {
+                       scale_to = -1.;
+               } else if (oo_attr_int_range (xin, attrs, OO_NS_STYLE, "scale-to-Y",
+                                             &scale_to_y, 1, INT_MAX)) {
+                       scale_to = -1.;
+               } else if (oo_attr_int_range (xin, attrs, OO_GNUM_NS_EXT, "scale-to-Y",
+                                             &scale_to_y, 1, INT_MAX)) {
+                       scale_to = -1.;
+               } else if (oo_attr_percent (xin, attrs, OO_NS_STYLE, "scale-to", &scale_to))
+                       ;
+       if (scale_to < 0) {
+               pi->scaling.dim.cols = scale_to_x;
+               pi->scaling.dim.rows = scale_to_y;
+               pi->scaling.type = PRINT_SCALE_FIT_PAGES;
+       } else {
+               pi->scaling.type = PRINT_SCALE_PERCENTAGE;
+               pi->scaling.percentage.x = pi->scaling.percentage.y = scale_to;         
+       }
 
-       if (gnm_style_print && state->print.cur_pi->comment_placement != GNM_PRINT_COMMENTS_NONE)
-               state->print.cur_pi->comment_placement = annotations_at_end ? GNM_PRINT_COMMENTS_AT_END :
+       if (gnm_style_print && pi->comment_placement != GNM_PRINT_COMMENTS_NONE)
+               pi->comment_placement = annotations_at_end ? GNM_PRINT_COMMENTS_AT_END :
                        GNM_PRINT_COMMENTS_IN_PLACE;
 
        /* STYLE "writing-mode" is being ignored since we can't store it anywhere atm */
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index e9e7adf..8eff2da 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -5578,6 +5578,36 @@ odf_write_page_layout (GnmOOExport *state, GnmPrintInformation *pi,
        gsf_xml_out_add_cstr_unchecked
                (state->xml, STYLE "print", gstr->str);
 
+       switch (pi->scaling.type) {
+       case PRINT_SCALE_FIT_PAGES: {
+               int x = pi->scaling.dim.cols;
+               int y = pi->scaling.dim.rows;
+               if (state->with_extension) {
+                       /* LO uses style:scale-to-X and style:scale-to-Y but */
+                       /* these are not valid in the style: namespace       */
+                       /* So to be understood by LO we would need to write  */
+                       /* invalid ODF. They should be using one of their    */
+                       /* extension namespace, but are not!                 */
+                       if (x > 0)
+                               gsf_xml_out_add_int (state->xml, GNMSTYLE "scale-to-X", x);
+                       if (y > 0)
+                               gsf_xml_out_add_int (state->xml, GNMSTYLE "scale-to-Y", y);                   
  
+               } else {
+                       /* ODF 1.2 only allows us to specify the total number of pages. */
+                       int x = pi->scaling.dim.cols;
+                       int y = pi->scaling.dim.rows;
+                       if (x > 0 && y > 0)
+                               gsf_xml_out_add_int (state->xml, STYLE "scale-to-pages", x*y);
+               }
+               break;
+       }
+       case PRINT_SCALE_PERCENTAGE:
+               odf_add_percent (state->xml, STYLE "scale-to", pi->scaling.percentage.x);
+               break;
+       default:
+               odf_add_percent (state->xml, STYLE "scale-to", 1.);
+       }
+
        if (state->with_extension) {
                g_string_truncate (gstr, 0);
                if (pi->comment_placement == GNM_PRINT_COMMENTS_AT_END)
diff --git a/test/ChangeLog b/test/ChangeLog
index 508e9d6..1054fc9 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,7 @@
+2015-06-5  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+       * ods-ext-schema.patch: add new attributes
+
 2015-04-16  Morten Welinder <terra gnome org>
 
        * Release 1.12.22
diff --git a/test/ods-ext-schema.patch b/test/ods-ext-schema.patch
index f11d6a6..3d98426 100644
--- a/test/ods-ext-schema.patch
+++ b/test/ods-ext-schema.patch
@@ -1,5 +1,5 @@
 --- ods-schema/OpenDocument-v1.2-os-schema.rng 2015-04-08 21:49:54.058918977 -0600
-+++ ods-schema/OpenDocument-v1.2-os-ext-schema.rng     2015-04-12 15:44:20.728861320 -0600
++++ ods-schema/OpenDocument-v1.2-os-ext-schema.rng     2015-06-05 13:07:06.067557896 -0600
 @@ -62,6 +62,12 @@
        xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
        xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
@@ -317,7 +317,7 @@
                </interleave>
        </define>
        <define name="draw-stroke-dash">
-@@ -14383,6 +14507,11 @@
+@@ -14383,6 +14507,21 @@
                                        <ref name="boolean"/>
                                </attribute>
                        </optional>
@@ -326,10 +326,20 @@
 +                                      <ref name="string"/>
 +                              </attribute>
 +                      </optional>
++                      <optional>
++                              <attribute name="gnm:scale-to-X">
++                                      <ref name="positiveInteger"/>
++                              </attribute>
++                      </optional>
++                      <optional>
++                              <attribute name="gnm:scale-to-Y">
++                                      <ref name="positiveInteger"/>
++                              </attribute>
++                      </optional>
                </interleave>
        </define>
        <define name="style-page-layout-properties-elements">
-@@ -14874,11 +15003,33 @@
+@@ -14874,11 +15013,33 @@
                                </attribute>
                        </optional>
                        <optional>
@@ -363,7 +373,7 @@
                                <attribute name="style:text-line-through-mode">
                                        <ref name="lineMode"/>
                                </attribute>
-@@ -15090,6 +15241,18 @@
+@@ -15090,6 +15251,18 @@
        <define name="style-paragraph-properties-attlist">
                <interleave>
                        <optional>
@@ -382,7 +392,7 @@
                                <attribute name="fo:line-height">
                                        <choice>
                                                <value>normal</value>
-@@ -15461,14 +15624,21 @@
+@@ -15461,14 +15634,21 @@
                </optional>
        </define>
        <define name="common-background-color-attlist">
@@ -411,7 +421,7 @@
        </define>
        <define name="style-background-image">
                <optional>
-@@ -15564,6 +15734,36 @@
+@@ -15564,6 +15744,36 @@
                                <ref name="string"/>
                        </attribute>
                </optional>
@@ -448,7 +458,7 @@
        </define>
        <define name="common-border-line-width-attlist">
                <optional>
-@@ -15904,6 +16104,37 @@
+@@ -15904,6 +16114,37 @@
                                        <ref name="boolean"/>
                                </attribute>
                        </optional>
@@ -486,7 +496,7 @@
                </interleave>
        </define>
        <define name="style-table-properties-elements">
-@@ -16004,6 +16235,11 @@
+@@ -16004,6 +16245,11 @@
                                </attribute>
                        </optional>
                        <optional>
@@ -498,7 +508,7 @@
                                <attribute name="style:text-align-source">
                                        <choice>
                                                <value>fix</value>
-@@ -16028,6 +16264,16 @@
+@@ -16028,6 +16274,16 @@
                        <ref name="common-background-color-attlist"/>
                        <ref name="common-border-attlist"/>
                        <optional>
@@ -515,7 +525,7 @@
                                <attribute name="style:diagonal-tl-br">
                                        <ref name="string"/>
                                </attribute>
-@@ -16104,6 +16350,16 @@
+@@ -16104,6 +16360,16 @@
                                        <ref name="boolean"/>
                                </attribute>
                        </optional>
@@ -532,7 +542,7 @@
                </interleave>
        </define>
        <define name="common-style-direction-attlist">
-@@ -17060,6 +17316,46 @@
+@@ -17060,6 +17326,46 @@
                                        <ref name="nonNegativeInteger"/>
                                </attribute>
                        </optional>
@@ -579,7 +589,7 @@
                </interleave>
        </define>
        <define name="style-graphic-fill-properties-attlist">
-@@ -17388,6 +17684,10 @@
+@@ -17388,6 +17694,10 @@
                                                <value>none</value>
                                                <value>cubic-spline</value>
                                                <value>b-spline</value>
@@ -590,7 +600,7 @@
                                        </choice>
                                </attribute>
                        </optional>
-@@ -17661,6 +17961,10 @@
+@@ -17661,6 +17971,10 @@
                                                <value>logarithmic</value>
                                                <value>exponential</value>
                                                <value>power</value>
@@ -601,7 +611,7 @@
                                        </choice>
                                </attribute>
                        </optional>
-@@ -17697,6 +18001,62 @@
+@@ -17697,6 +18011,62 @@
                                        <ref name="boolean"/>
                                </attribute>
                        </optional>
@@ -664,7 +674,7 @@
                </interleave>
        </define>
        <define name="labelPositions">
-@@ -18124,4 +18484,85 @@
+@@ -18124,4 +18494,85 @@
                        </element>
                </zeroOrMore>
        </define>


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