render: Render table_items instead of tables.
[pspp] / src / output / odt.c
index c0a386e653d502cc9207616534ac8bd76885f18e..0d4625c8d4d39ba61046c838aa632fa6d748e811 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2009, 2010, 2011, 2012, 2014 Free Software Foundation, Inc.
+   Copyright (C) 2009-2014 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -411,7 +411,7 @@ write_xml_with_line_breaks (xmlTextWriterPtr writer, char *line)
 }
 
 static void
-odt_submit_table (struct odt_driver *odt, struct table_item *item)
+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);
@@ -421,8 +421,8 @@ odt_submit_table (struct odt_driver *odt, struct table_item *item)
   if (caption != 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)) );
       xmlTextWriterEndElement (odt->content_wtr);
@@ -455,6 +455,7 @@ odt_submit_table (struct odt_driver *odt, struct table_item *item)
       for (c = 0 ; c < table_nc (tab) ; ++c)
        {
           struct table_cell cell;
+          size_t i;
 
           table_get_cell (tab, c, r, &cell);
 
@@ -476,24 +477,37 @@ odt_submit_table (struct odt_driver *odt, struct table_item *item)
                   odt->content_wtr, _xml("table:number-rows-spanned"),
                   "%d", rowspan);
 
-             xmlTextWriterStartElement (odt->content_wtr, _xml("text:p"));
-
-             if ( r < table_ht (tab) || c < table_hl (tab) )
-               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"));
-
-             if (strchr (cell.contents, '\n'))
-               {
-                 char *line = xstrdup (cell.contents);
-                 write_xml_with_line_breaks (odt->content_wtr, line);
-                 free (line);
-               }
-             else
-               xmlTextWriterWriteString (odt->content_wtr, _xml(cell.contents));
-
-             xmlTextWriterEndElement (odt->content_wtr); /* text:p */
-             xmlTextWriterEndElement (odt->content_wtr); /* table:table-cell */
+              for (i = 0; i < cell.n_contents; i++)
+                {
+                  const struct cell_contents *contents = &cell.contents[i];
+
+                  if (contents->text)
+                    {
+                      xmlTextWriterStartElement (odt->content_wtr, _xml("text:p"));
+
+                      if ( r < table_ht (tab) || c < table_hl (tab) )
+                        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"));
+
+                      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));
+
+                      xmlTextWriterEndElement (odt->content_wtr); /* text:p */
+                    }
+                  else if (contents->table)
+                    {
+                      write_table (odt, contents->table);
+                      continue;
+                    }
+                }
+              xmlTextWriterEndElement (odt->content_wtr); /* table:table-cell */
            }
          else
            {
@@ -531,7 +545,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);