X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fodt.c;h=521e5b877fd1f905681ce9f3c67cbf384f1acdaa;hb=a016af53bdf60d1ab95e680e6b31311b21518b75;hp=24da4522c0799b15d38ed90ca003ca538227994d;hpb=93ec42221da8b677420bf11435e0d24d0503601b;p=pspp diff --git a/src/output/odt.c b/src/output/odt.c index 24da4522c0..521e5b877f 100644 --- a/src/output/odt.c +++ b/src/output/odt.c @@ -36,6 +36,7 @@ #include "libpspp/temp-file.h" #include "libpspp/version.h" #include "libpspp/zip-writer.h" +#include "data/file-handle-def.h" #include "output/driver-provider.h" #include "output/message-item.h" #include "output/options.h" @@ -71,12 +72,13 @@ struct odt_driver /* Name of current command. */ char *command_name; + + /* Number of footnotes so far. */ + int n_footnotes; }; static const struct output_driver_class odt_driver_class; -static void write_table (struct odt_driver *, const struct table *); - static struct odt_driver * odt_driver_cast (struct output_driver *driver) { @@ -243,7 +245,7 @@ write_meta_data (struct odt_driver *odt) xmlTextWriterStartElement (w, _xml ("office:meta")); { xmlTextWriterStartElement (w, _xml ("meta:generator")); - xmlTextWriterWriteString (w, _xml (stat_version)); + xmlTextWriterWriteString (w, _xml (version)); xmlTextWriterEndElement (w); } @@ -289,12 +291,13 @@ write_meta_data (struct odt_driver *odt) } static struct output_driver * -odt_create (const char *file_name, enum settings_output_devices device_type, +odt_create (struct file_handle *fh, enum settings_output_devices device_type, struct string_map *o UNUSED) { struct output_driver *d; struct odt_driver *odt; struct zip_writer *zip; + const char *file_name = fh_get_file_name (fh); zip = zip_writer_create (file_name); if (zip == NULL) @@ -302,6 +305,7 @@ odt_create (const char *file_name, enum settings_output_devices device_type, odt = xzalloc (sizeof *odt); d = &odt->driver; + output_driver_init (d, &odt_driver_class, file_name, device_type); odt->zip = zip; @@ -388,54 +392,86 @@ odt_destroy (struct output_driver *driver) } static void -write_xml_with_line_breaks (xmlTextWriterPtr writer, char *line) +write_xml_with_line_breaks (struct odt_driver *odt, const char *line_) { - char *newline; - char *p; + xmlTextWriterPtr writer = odt->content_wtr; - for (p = line; *p; p = newline + 1) + if (!strchr (line_, '\n')) + xmlTextWriterWriteString (writer, _xml(line_)); + else { - newline = strchr (p, '\n'); + char *line = xstrdup (line_); + char *newline; + char *p; - if (!newline) + for (p = line; *p; p = newline + 1) { + newline = strchr (p, '\n'); + + if (!newline) + { + xmlTextWriterWriteString (writer, _xml(p)); + free (line); + return; + } + + if (newline > p && newline[-1] == '\r') + newline[-1] = '\0'; + else + *newline = '\0'; xmlTextWriterWriteString (writer, _xml(p)); - return; + xmlTextWriterWriteElement (writer, _xml("text:line-break"), _xml("")); } - - if (newline > p && newline[-1] == '\r') - newline[-1] = '\0'; - else - *newline = '\0'; - xmlTextWriterWriteString (writer, _xml(p)); - xmlTextWriterWriteElement (writer, _xml("text:line-break"), _xml("")); } } static void -odt_submit_table (struct odt_driver *odt, struct table_item *item) +write_footnote (struct odt_driver *odt, const char *footnote) +{ + char marker[16]; + + xmlTextWriterStartElement (odt->content_wtr, _xml("text:note")); + xmlTextWriterWriteAttribute (odt->content_wtr, _xml("text:note-class"), + _xml("footnote")); + + xmlTextWriterStartElement (odt->content_wtr, _xml("text:note-citation")); + str_format_26adic (++odt->n_footnotes, false, marker, sizeof marker); + if (strlen (marker) > 1) + xmlTextWriterWriteFormatAttribute (odt->content_wtr, _xml("text:label"), + "(%s)", marker); + else + xmlTextWriterWriteAttribute (odt->content_wtr, _xml("text:label"), + _xml(marker)); + xmlTextWriterEndElement (odt->content_wtr); + + xmlTextWriterStartElement (odt->content_wtr, _xml("text:note-body")); + xmlTextWriterStartElement (odt->content_wtr, _xml("text:p")); + write_xml_with_line_breaks (odt, footnote); + xmlTextWriterEndElement (odt->content_wtr); + xmlTextWriterEndElement (odt->content_wtr); + + xmlTextWriterEndElement (odt->content_wtr); +} + +static void +write_table (struct odt_driver *odt, const struct table_item *item) { + const struct table *tab = table_item_get_table (item); const char *caption = table_item_get_caption (item); + const char *title = table_item_get_title (item); + int r, c; /* Write a heading for the table */ - if (caption != NULL) + if (title != NULL) { xmlTextWriterStartElement (odt->content_wtr, _xml("text:h")); - xmlTextWriterWriteFormatAttribute (odt->content_wtr, _xml("text:level"), - "%d", 2); + xmlTextWriterWriteFormatAttribute (odt->content_wtr, + _xml("text:outline-level"), "%d", 2); xmlTextWriterWriteString (odt->content_wtr, - _xml (table_item_get_caption (item)) ); + _xml (table_item_get_title (item)) ); xmlTextWriterEndElement (odt->content_wtr); } - write_table (odt, table_item_get_table (item)); -} - -static void -write_table (struct odt_driver *odt, const struct table *tab) -{ - int r, c; - /* Start table */ xmlTextWriterStartElement (odt->content_wtr, _xml("table:table")); xmlTextWriterWriteFormatAttribute (odt->content_wtr, _xml("table:name"), @@ -488,6 +524,7 @@ write_table (struct odt_driver *odt, const struct table *tab) for (i = 0; i < cell.n_contents; i++) { const struct cell_contents *contents = &cell.contents[i]; + int j; if (contents->text) { @@ -498,22 +535,16 @@ write_table (struct odt_driver *odt, const struct table *tab) else xmlTextWriterWriteAttribute (odt->content_wtr, _xml("text:style-name"), _xml("Table_20_Contents")); - if (strchr (contents->text, '\n')) - { - char *line = xstrdup (contents->text); - write_xml_with_line_breaks (odt->content_wtr, line); - free (line); - } - else - xmlTextWriterWriteString (odt->content_wtr, _xml(contents->text)); + write_xml_with_line_breaks (odt, contents->text); + + for (j = 0; j < contents->n_footnotes; j++) + write_footnote (odt, contents->footnotes[j]); xmlTextWriterEndElement (odt->content_wtr); /* text:p */ } else if (contents->table) - { - write_table (odt, contents->table); - continue; - } + write_table (odt, contents->table); + } xmlTextWriterEndElement (odt->content_wtr); /* table:table-cell */ } @@ -533,6 +564,18 @@ write_table (struct odt_driver *odt, const struct table *tab) } xmlTextWriterEndElement (odt->content_wtr); /* table */ + + /* Write a caption for the table */ + if (caption != NULL) + { + xmlTextWriterStartElement (odt->content_wtr, _xml("text:h")); + xmlTextWriterWriteFormatAttribute (odt->content_wtr, + _xml("text:outline-level"), "%d", 2); + xmlTextWriterWriteString (odt->content_wtr, + _xml (table_item_get_caption (item)) ); + xmlTextWriterEndElement (odt->content_wtr); + } + } static void @@ -553,7 +596,7 @@ odt_submit (struct output_driver *driver, output_driver_track_current_command (output_item, &odt->command_name); if (is_table_item (output_item)) - odt_submit_table (odt, to_table_item (output_item)); + write_table (odt, to_table_item (output_item)); else if (is_text_item (output_item)) { struct text_item *text_item = to_text_item (output_item);