- 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)
- {
- 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
- xmlTextWriterWriteAttribute (x->content_wtr, _xml("text:style-name"), _xml("Table_20_Contents"));
-
- xmlTextWriterWriteString (x->content_wtr, _xml (s));
-
- xmlTextWriterEndElement (x->content_wtr); /* text:p */
- xmlTextWriterEndElement (x->content_wtr); /* table:table-cell */
+ struct table_cell cell;
+ size_t i;
+
+ table_get_cell (tab, c, r, &cell);
+
+ if (c == cell.d[TABLE_HORZ][0] && r == cell.d[TABLE_VERT][0])
+ {
+ int colspan = table_cell_colspan (&cell);
+ int rowspan = table_cell_rowspan (&cell);
+
+ xmlTextWriterStartElement (odt->content_wtr, _xml("table:table-cell"));
+ xmlTextWriterWriteAttribute (odt->content_wtr, _xml("office:value-type"), _xml("string"));
+
+ if (colspan > 1)
+ xmlTextWriterWriteFormatAttribute (
+ odt->content_wtr, _xml("table:number-columns-spanned"),
+ "%d", colspan);
+
+ if (rowspan > 1)
+ xmlTextWriterWriteFormatAttribute (
+ odt->content_wtr, _xml("table:number-rows-spanned"),
+ "%d", rowspan);
+
+ 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 */