X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fodt.c;h=97109cef4276a4bbd830c2fd9b4a6a79f1aa9016;hb=d950831f83004457e69c3e6e44131aef3e57efd3;hp=90a76186a7d81f7cdedd7f8510388aa30a0306ae;hpb=1aef11b9589a534333bbecd528efe1022a4bb9bb;p=pspp diff --git a/src/output/odt.c b/src/output/odt.c index 90a76186a7..97109cef42 100644 --- a/src/output/odt.c +++ b/src/output/odt.c @@ -51,6 +51,10 @@ #define _xml(X) (CHAR_CAST (const xmlChar *, X)) +/* This file uses TABLE_HORZ and TABLE_VERT enough to warrant abbreviating. */ +#define H TABLE_HORZ +#define V TABLE_VERT + struct odt_driver { struct output_driver driver; @@ -80,26 +84,6 @@ odt_driver_cast (struct output_driver *driver) return UP_CAST (driver, struct odt_driver, driver); } -/* Create the "mimetype" file needed by ODF */ -static bool -create_mimetype (struct zip_writer *zip) -{ - FILE *fp; - - fp = create_temp_file (); - if (fp == NULL) - { - msg_error (errno, _("error creating temporary file")); - return false; - } - - fprintf (fp, "application/vnd.oasis.opendocument.text"); - zip_writer_add (zip, fp, "mimetype"); - close_temp_file (fp); - - return true; -} - /* Creates a new temporary file and stores it in *FILE, then creates an XML writer for it and stores it in *W. */ static void @@ -140,7 +124,7 @@ write_style_data (struct odt_driver *odt) _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") ); + _xml ("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0")); xmlTextWriterWriteAttribute (w, _xml ("office:version"), _xml ("1.1")); @@ -306,11 +290,8 @@ odt_create (struct file_handle *fh, enum settings_output_devices device_type, odt->handle = fh; odt->file_name = xstrdup (file_name); - if (!create_mimetype (zip)) - { - output_driver_destroy (d); - return NULL; - } + zip_writer_add_string (zip, "mimetype", + "application/vnd.oasis.opendocument.text"); /* Create the manifest */ create_writer (&odt->manifest_file, &odt->manifest_wtr); @@ -455,12 +436,48 @@ write_table_item_text (struct odt_driver *odt, xmlTextWriterStartElement (odt->content_wtr, _xml("text:h")); xmlTextWriterWriteFormatAttribute (odt->content_wtr, _xml("text:outline-level"), "%d", 2); - xmlTextWriterWriteString (odt->content_wtr, _xml (text->content) ); + xmlTextWriterWriteString (odt->content_wtr, _xml (text->content)); for (size_t i = 0; i < text->n_footnotes; i++) write_footnote (odt, text->footnotes[i]); xmlTextWriterEndElement (odt->content_wtr); } +static void +write_table_item_cell (struct odt_driver *odt, + const struct table_cell *cell) +{ + if (!cell) + return; + + xmlTextWriterStartElement (odt->content_wtr, _xml("text:h")); + xmlTextWriterWriteFormatAttribute (odt->content_wtr, + _xml("text:outline-level"), "%d", 2); + xmlTextWriterWriteString (odt->content_wtr, _xml (cell->text)); + for (size_t i = 0; i < cell->n_footnotes; i++) + write_footnote (odt, cell->footnotes[i]); + xmlTextWriterEndElement (odt->content_wtr); +} + +static void +write_table_item_layers (struct odt_driver *odt, + const struct table_item_layers *layers) +{ + if (!layers) + return; + + for (size_t i = 0; i < layers->n_layers; i++) + { + const struct table_item_layer *layer = &layers->layers[i]; + xmlTextWriterStartElement (odt->content_wtr, _xml("text:h")); + xmlTextWriterWriteFormatAttribute (odt->content_wtr, + _xml("text:outline-level"), "%d", 2); + xmlTextWriterWriteString (odt->content_wtr, _xml (layer->content)); + for (size_t i = 0; i < layer->n_footnotes; i++) + write_footnote (odt, layer->footnotes[i]); + xmlTextWriterEndElement (odt->content_wtr); + } +} + static void write_table (struct odt_driver *odt, const struct table_item *item) { @@ -468,8 +485,8 @@ write_table (struct odt_driver *odt, const struct table_item *item) int r, c; /* Write a heading for the table */ - write_table_item_text (odt, table_item_get_title (item)); - write_table_item_text (odt, table_item_get_layers (item)); + write_table_item_cell (odt, table_item_get_title (item)); + write_table_item_layers (odt, table_item_get_layers (item)); /* Start table */ xmlTextWriterStartElement (odt->content_wtr, _xml("table:table")); @@ -479,29 +496,29 @@ write_table (struct odt_driver *odt, const struct table_item *item) /* Start column definitions */ xmlTextWriterStartElement (odt->content_wtr, _xml("table:table-column")); - xmlTextWriterWriteFormatAttribute (odt->content_wtr, _xml("table:number-columns-repeated"), "%d", table_nc (tab)); + xmlTextWriterWriteFormatAttribute (odt->content_wtr, _xml("table:number-columns-repeated"), "%d", tab->n[H]); xmlTextWriterEndElement (odt->content_wtr); /* Deal with row headers */ - if ( table_ht (tab) > 0) + if (tab->h[V][0] > 0) xmlTextWriterStartElement (odt->content_wtr, _xml("table:table-header-rows")); /* Write all the rows */ - for (r = 0 ; r < table_nr (tab); ++r) + for (r = 0 ; r < tab->n[V]; ++r) { /* Start row definition */ xmlTextWriterStartElement (odt->content_wtr, _xml("table:table-row")); /* Write all the columns */ - for (c = 0 ; c < table_nc (tab) ; ++c) + for (c = 0 ; c < tab->n[H] ; ++c) { struct table_cell cell; table_get_cell (tab, c, r, &cell); - if (c == cell.d[TABLE_HORZ][0] && r == cell.d[TABLE_VERT][0]) + if (c == cell.d[H][0] && r == cell.d[V][0]) { int colspan = table_cell_colspan (&cell); int rowspan = table_cell_rowspan (&cell); @@ -521,7 +538,7 @@ write_table (struct odt_driver *odt, const struct table_item *item) xmlTextWriterStartElement (odt->content_wtr, _xml("text:p")); - if ( r < table_ht (tab) || c < table_hl (tab) ) + if (r < tab->h[V][0] || c < tab->h[H][0]) xmlTextWriterWriteAttribute (odt->content_wtr, _xml("text:style-name"), _xml("Table_20_Heading")); else xmlTextWriterWriteAttribute (odt->content_wtr, _xml("text:style-name"), _xml("Table_20_Contents")); @@ -547,13 +564,12 @@ write_table (struct odt_driver *odt, const struct table_item *item) xmlTextWriterStartElement (odt->content_wtr, _xml("table:covered-table-cell")); xmlTextWriterEndElement (odt->content_wtr); } - - table_cell_free (&cell); } xmlTextWriterEndElement (odt->content_wtr); /* row */ - if ( table_ht (tab) > 0 && r == table_ht (tab) - 1) + int ht = tab->h[V][0]; + if (ht > 0 && r == ht - 1) xmlTextWriterEndElement (odt->content_wtr); /* table-header-rows */ }