X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fodt.c;h=8cc3da9ae72324fc6a38be4cf4e47bedf6d4af1c;hb=3c1d80a71e11e8678dc96bc49e69a13fd0f499fa;hp=f557278de8d41b8ac9adbb1ffd2ca07d20f79e25;hpb=a7a2de8a6346ede44d011a0554a60afa3699f5ee;p=pspp-builds.git diff --git a/src/output/odt.c b/src/output/odt.c index f557278d..8cc3da9a 100644 --- a/src/output/odt.c +++ b/src/output/odt.c @@ -105,6 +105,98 @@ register_file (struct odt_driver_ext *x, const char *filename) xmlTextWriterEndElement (x->manifest_wtr); } +static void +write_style_data (struct odt_driver_ext *x) +{ + xmlTextWriterPtr w = create_writer (x, "styles.xml"); + register_file (x, "styles.xml"); + + xmlTextWriterStartElement (w, _xml ("office:document-styles")); + xmlTextWriterWriteAttribute (w, _xml ("xmlns:office"), + _xml ("urn:oasis:names:tc:opendocument:xmlns:office:1.0")); + + xmlTextWriterWriteAttribute (w, _xml ("xmlns:style"), + _xml ("urn:oasis:names:tc:opendocument:xmlns:style:1.0")); + + xmlTextWriterWriteAttribute (w, _xml ("xmlns:fo"), + _xml ("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0") ); + + xmlTextWriterWriteAttribute (w, _xml ("office:version"), _xml ("1.1")); + + + + xmlTextWriterStartElement (w, _xml ("office:styles")); + + + { + xmlTextWriterStartElement (w, _xml ("style:style")); + xmlTextWriterWriteAttribute (w, _xml ("style:name"), + _xml ("Standard")); + + xmlTextWriterWriteAttribute (w, _xml ("style:family"), + _xml ("paragraph")); + + xmlTextWriterWriteAttribute (w, _xml ("style:class"), + _xml ("text")); + + xmlTextWriterEndElement (w); /* style:style */ + } + + { + xmlTextWriterStartElement (w, _xml ("style:style")); + xmlTextWriterWriteAttribute (w, _xml ("style:name"), + _xml ("Table_20_Contents")); + + xmlTextWriterWriteAttribute (w, _xml ("style:display-name"), + _xml ("Table Contents")); + + xmlTextWriterWriteAttribute (w, _xml ("style:family"), + _xml ("paragraph")); + + xmlTextWriterWriteAttribute (w, _xml ("style:parent-style-name"), + _xml ("Standard")); + + xmlTextWriterWriteAttribute (w, _xml ("style:class"), + _xml ("extra")); + + xmlTextWriterEndElement (w); /* style:style */ + } + + { + xmlTextWriterStartElement (w, _xml ("style:style")); + xmlTextWriterWriteAttribute (w, _xml ("style:name"), + _xml ("Table_20_Heading")); + + xmlTextWriterWriteAttribute (w, _xml ("style:display-name"), + _xml ("Table Heading")); + + xmlTextWriterWriteAttribute (w, _xml ("style:family"), + _xml ("paragraph")); + + xmlTextWriterWriteAttribute (w, _xml ("style:parent-style-name"), + _xml ("Table_20_Contents")); + + xmlTextWriterWriteAttribute (w, _xml ("style:class"), + _xml ("extra")); + + + xmlTextWriterStartElement (w, _xml ("style:text-properties")); + xmlTextWriterWriteAttribute (w, _xml ("fo:font-weight"), _xml ("bold")); + xmlTextWriterWriteAttribute (w, _xml ("style:font-weight-asian"), _xml ("bold")); + xmlTextWriterWriteAttribute (w, _xml ("style:font-weight-complex"), _xml ("bold")); + xmlTextWriterEndElement (w); /* style:text-properties */ + + xmlTextWriterEndElement (w); /* style:style */ + } + + + xmlTextWriterEndElement (w); /* office:styles */ + xmlTextWriterEndElement (w); /* office:document-styles */ + + xmlTextWriterEndDocument (w); + xmlFreeTextWriter (w); +} + static void write_meta_data (struct odt_driver_ext *x) { @@ -189,6 +281,7 @@ odt_open_driver (const char *name, int types, struct substring option_string) write_meta_data (x); + write_style_data (x); x->content_wtr = create_writer (x, "content.xml"); register_file (x, "content.xml"); @@ -236,10 +329,11 @@ odt_close_driver (struct outp_driver *this) /* Zip up the directory */ ds_init_empty (&zip_cmd); - ds_put_format (&zip_cmd, "cd %s ; zip -r ../pspp.odt . > /dev/null", x->dirname); + ds_put_format (&zip_cmd, "cd %s ; rm -f ../pspp.odt; zip -q -X ../pspp.odt mimetype; zip -q -X -u -r ../pspp.odt .", x->dirname); system (ds_cstr (&zip_cmd)); ds_destroy (&zip_cmd); + /* Remove the temp dir */ ds_init_empty (&rm_cmd); ds_put_format (&rm_cmd, "rm -r %s", x->dirname); @@ -305,20 +399,52 @@ odt_submit (struct outp_driver *this, struct som_entity *e) /* Write all the rows */ for (r = 0 ; r < tab->nr; ++r) { + int spanned_columns = 0; /* Start row definition */ xmlTextWriterStartElement (x->content_wtr, _xml("table:table-row")); /* Write all the columns */ for (c = 0 ; c < tab->nc ; ++c) { - int opts = tab->ct[tab->nc * r + c]; - xmlTextWriterStartElement (x->content_wtr, _xml("table:table-cell")); - xmlTextWriterWriteAttribute (x->content_wtr, _xml("office:value-type"), _xml("string")); + char *s = NULL; + unsigned int opts = tab->ct[tab->nc * r + c]; + struct substring ss = tab->cc[tab->nc * r + c]; - if (! (opts & TAB_EMPTY) ) + if (opts & TAB_EMPTY) { - char *s = ss_xstrdup (tab->cc[tab->nc * r + c]); + xmlTextWriterStartElement (x->content_wtr, _xml("table:table-cell")); + xmlTextWriterEndElement (x->content_wtr); + continue; + } + + if ( opts & TAB_JOIN) + { + if ( spanned_columns == 0) + { + struct tab_joined_cell *j = (struct tab_joined_cell*) ss_data (ss); + s = ss_xstrdup (j->contents); + } + } + else + s = ss_xstrdup (ss); + + if ( spanned_columns == 0 ) + { + xmlTextWriterStartElement (x->content_wtr, _xml("table:table-cell")); + xmlTextWriterWriteAttribute (x->content_wtr, _xml("office:value-type"), _xml("string")); + + if ( opts & TAB_JOIN ) + { + struct tab_joined_cell *j = (struct tab_joined_cell*) ss_data (ss); + spanned_columns = j->x2 - j->x1; + + xmlTextWriterWriteFormatAttribute (x->content_wtr, + _xml("table:number-columns-spanned"), + "%d", spanned_columns); + } + xmlTextWriterStartElement (x->content_wtr, _xml("text:p")); + if ( r < tab->t || c < tab->l ) xmlTextWriterWriteAttribute (x->content_wtr, _xml("text:style-name"), _xml("Table_20_Heading")); else @@ -326,10 +452,18 @@ odt_submit (struct outp_driver *this, struct som_entity *e) xmlTextWriterWriteString (x->content_wtr, _xml (s)); + xmlTextWriterEndElement (x->content_wtr); /* text:p */ + xmlTextWriterEndElement (x->content_wtr); /* table:table-cell */ + } + else + { + xmlTextWriterStartElement (x->content_wtr, _xml("table:covered-table-cell")); xmlTextWriterEndElement (x->content_wtr); - free (s); } - xmlTextWriterEndElement (x->content_wtr); + if ( opts & TAB_JOIN ) + spanned_columns --; + + free (s); } xmlTextWriterEndElement (x->content_wtr); /* row */