summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-11-24 09:09:25 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-11-24 11:13:42 +0100
commit0baecd418e79a703dcf89fec3f66e416beefcf56 (patch)
tree9b12af15996927341bc81f6dd4cf00e0c8bb4ae0
parent7b355976ab65d059073978e4ab334c94a7dd450e (diff)
EPUB export: implement row span for tables
By turning <table:table-cell> attributes into librevenge properties. Also make sure that row/cell styles are inline at a libepubgen level. Change-Id: Ic23058748d241209845f76d8edc548bab8212c5f
-rw-r--r--external/libepubgen/libepubgen-epub3.patch.1177
-rw-r--r--writerperfect/qa/unit/EPUBExportTest.cxx11
-rw-r--r--writerperfect/qa/unit/data/writer/epubexport/table-row-span.fodt42
-rw-r--r--writerperfect/source/writer/exp/xmltbli.cxx20
4 files changed, 247 insertions, 3 deletions
diff --git a/external/libepubgen/libepubgen-epub3.patch.1 b/external/libepubgen/libepubgen-epub3.patch.1
index d6f41f13f61e..a45b9666568c 100644
--- a/external/libepubgen/libepubgen-epub3.patch.1
+++ b/external/libepubgen/libepubgen-epub3.patch.1
@@ -2605,3 +2605,180 @@ index 11bf7de..25294c6 100644
--
2.12.3
+From f3a04df200d818b4aaa9d54910b670cd6cf3149f Mon Sep 17 00:00:00 2001
+From: Miklos Vajna <vmiklos@collabora.co.uk>
+Date: Tue, 31 Oct 2017 15:50:50 +0100
+Subject: [PATCH] EPUBHTMLGenerator: librevenge:type -> xlink:type
+
+That's what libetonyek and LO's librevenge producer generates, also
+matches librevenge documentation. This isn't really a behavior change,
+just makes the warning go away in the xlink case.
+---
+ src/lib/EPUBHTMLGenerator.cpp | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/lib/EPUBHTMLGenerator.cpp b/src/lib/EPUBHTMLGenerator.cpp
+index 25294c6..0d39c00 100644
+--- a/src/lib/EPUBHTMLGenerator.cpp
++++ b/src/lib/EPUBHTMLGenerator.cpp
+@@ -657,9 +657,9 @@ void EPUBHTMLGenerator::openLink(const RVNGPropertyList &propList)
+ if (m_impl->m_ignore)
+ return;
+
+- if (!propList["librevenge:type"])
++ if (!propList["xlink:type"])
+ {
+- EPUBGEN_DEBUG_MSG(("EPUBHTMLGenerator::openLink: librevenge:type: not filled, suppose link\n"));
++ EPUBGEN_DEBUG_MSG(("EPUBHTMLGenerator::openLink: xlink:type: not filled, suppose link\n"));
+ }
+ RVNGPropertyList attrs;
+ if (propList["xlink:href"])
+--
+2.12.3
+
+From c5e32608ecea8410b11760284d49e1f1958c6f75 Mon Sep 17 00:00:00 2001
+From: Miklos Vajna <vmiklos@collabora.co.uk>
+Date: Tue, 31 Oct 2017 16:50:50 +0100
+Subject: [PATCH] EPUBTableStyleManager: handle EPUB_STYLES_METHOD_INLINE for
+ rows
+
+This was working for paragraphs and spans only previously.
+---
+ src/lib/EPUBHTMLGenerator.cpp | 10 +++++++++-
+ src/lib/EPUBTableStyleManager.cpp | 11 +++++++++++
+ src/lib/EPUBTableStyleManager.h | 2 ++
+ src/test/EPUBTextGeneratorTest.cpp | 28 ++++++++++++++++++++++++++++
+ 4 files changed, 50 insertions(+), 1 deletion(-)
+
+diff --git a/src/lib/EPUBHTMLGenerator.cpp b/src/lib/EPUBHTMLGenerator.cpp
+index 0d39c00..42e8e3e 100644
+--- a/src/lib/EPUBHTMLGenerator.cpp
++++ b/src/lib/EPUBHTMLGenerator.cpp
+@@ -858,7 +858,15 @@ void EPUBHTMLGenerator::openTableRow(const RVNGPropertyList &propList)
+ if (m_impl->m_ignore)
+ return;
+ RVNGPropertyList attrs;
+- attrs.insert("class", m_impl->m_tableManager.getRowClass(propList).c_str());
++ switch (m_impl->m_stylesMethod)
++ {
++ case EPUB_STYLES_METHOD_CSS:
++ attrs.insert("class", m_impl->m_tableManager.getRowClass(propList).c_str());
++ break;
++ case EPUB_STYLES_METHOD_INLINE:
++ attrs.insert("style", m_impl->m_tableManager.getRowStyle(propList).c_str());
++ break;
++ }
+ m_impl->output().openElement("tr", attrs);
+ }
+
+diff --git a/src/lib/EPUBTableStyleManager.cpp b/src/lib/EPUBTableStyleManager.cpp
+index 52b6959..ead9170 100644
+--- a/src/lib/EPUBTableStyleManager.cpp
++++ b/src/lib/EPUBTableStyleManager.cpp
+@@ -111,6 +111,17 @@ std::string EPUBTableStyleManager::getRowClass(RVNGPropertyList const &pList)
+ return s.str();
+ }
+
++std::string EPUBTableStyleManager::getRowStyle(RVNGPropertyList const &pList)
++{
++ EPUBCSSProperties content;
++ extractRowProperties(pList, content);
++
++ std::stringstream s;
++ for (const auto &property : content)
++ s << property.first << ": " << property.second << "; ";
++ return s.str();
++}
++
+ void EPUBTableStyleManager::send(EPUBCSSSink &out)
+ {
+ for (ContentNameMap_t::const_iterator it=m_cellContentNameMap.begin(); m_cellContentNameMap.end() != it; ++it)
+diff --git a/src/lib/EPUBTableStyleManager.h b/src/lib/EPUBTableStyleManager.h
+index e6d09bc..20056ad 100644
+--- a/src/lib/EPUBTableStyleManager.h
++++ b/src/lib/EPUBTableStyleManager.h
+@@ -47,6 +47,8 @@ public:
+ std::string getCellClass(librevenge::RVNGPropertyList const &pList);
+ //! returns the class name corresponding to a propertylist
+ std::string getRowClass(librevenge::RVNGPropertyList const &pList);
++ //! returns the style string corresponding to a propertylist
++ std::string getRowStyle(librevenge::RVNGPropertyList const &pList);
+ //! send the data to the sink
+ void send(EPUBCSSSink &out);
+ private:
+--
+2.12.3
+
+From 258dcc4a98405238f4e32f89d122a7ccbb9a1357 Mon Sep 17 00:00:00 2001
+From: Miklos Vajna <vmiklos@collabora.co.uk>
+Date: Tue, 31 Oct 2017 17:45:22 +0100
+Subject: [PATCH] EPUBTableStyleManager: handle EPUB_STYLES_METHOD_INLINE for
+ cells
+
+So that a typical table has an empty CSS when requested.
+---
+ src/lib/EPUBHTMLGenerator.cpp | 10 +++++++++-
+ src/lib/EPUBTableStyleManager.cpp | 11 +++++++++++
+ src/lib/EPUBTableStyleManager.h | 2 ++
+ src/test/EPUBTextGeneratorTest.cpp | 13 +++++++++----
+ 4 files changed, 31 insertions(+), 5 deletions(-)
+
+diff --git a/src/lib/EPUBHTMLGenerator.cpp b/src/lib/EPUBHTMLGenerator.cpp
+index 42e8e3e..86b3ac2 100644
+--- a/src/lib/EPUBHTMLGenerator.cpp
++++ b/src/lib/EPUBHTMLGenerator.cpp
+@@ -882,7 +882,15 @@ void EPUBHTMLGenerator::openTableCell(const RVNGPropertyList &propList)
+ if (m_impl->m_ignore)
+ return;
+ RVNGPropertyList attrs;
+- attrs.insert("class", m_impl->m_tableManager.getCellClass(propList).c_str());
++ switch (m_impl->m_stylesMethod)
++ {
++ case EPUB_STYLES_METHOD_CSS:
++ attrs.insert("class", m_impl->m_tableManager.getCellClass(propList).c_str());
++ break;
++ case EPUB_STYLES_METHOD_INLINE:
++ attrs.insert("style", m_impl->m_tableManager.getCellStyle(propList).c_str());
++ break;
++ }
+ if (propList["table:number-columns-spanned"])
+ attrs.insert("colspan", propList["table:number-columns-spanned"]->getInt());
+ if (propList["table:number-rows-spanned"])
+diff --git a/src/lib/EPUBTableStyleManager.cpp b/src/lib/EPUBTableStyleManager.cpp
+index ead9170..4e24611 100644
+--- a/src/lib/EPUBTableStyleManager.cpp
++++ b/src/lib/EPUBTableStyleManager.cpp
+@@ -98,6 +98,17 @@ std::string EPUBTableStyleManager::getCellClass(RVNGPropertyList const &pList)
+ return s.str();
+ }
+
++std::string EPUBTableStyleManager::getCellStyle(RVNGPropertyList const &pList)
++{
++ EPUBCSSProperties content;
++ extractCellProperties(pList, content);
++
++ std::stringstream s;
++ for (const auto &property : content)
++ s << property.first << ": " << property.second << "; ";
++ return s.str();
++}
++
+ std::string EPUBTableStyleManager::getRowClass(RVNGPropertyList const &pList)
+ {
+ EPUBCSSProperties content;
+diff --git a/src/lib/EPUBTableStyleManager.h b/src/lib/EPUBTableStyleManager.h
+index 20056ad..135a144 100644
+--- a/src/lib/EPUBTableStyleManager.h
++++ b/src/lib/EPUBTableStyleManager.h
+@@ -45,6 +45,8 @@ public:
+ void closeTable();
+ //! returns the class name corresponding to a propertylist
+ std::string getCellClass(librevenge::RVNGPropertyList const &pList);
++ //! returns the style string corresponding to a propertylist
++ std::string getCellStyle(librevenge::RVNGPropertyList const &pList);
+ //! returns the class name corresponding to a propertylist
+ std::string getRowClass(librevenge::RVNGPropertyList const &pList);
+ //! returns the style string corresponding to a propertylist
+--
+2.12.3
+
diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx
index aba848ce9688..b92d5763276a 100644
--- a/writerperfect/qa/unit/EPUBExportTest.cxx
+++ b/writerperfect/qa/unit/EPUBExportTest.cxx
@@ -74,6 +74,7 @@ public:
void testList();
void testImage();
void testTable();
+ void testTableRowSpan();
void testLink();
void testLinkCharFormat();
void testLinkNamedCharFormat();
@@ -97,6 +98,7 @@ public:
CPPUNIT_TEST(testList);
CPPUNIT_TEST(testImage);
CPPUNIT_TEST(testTable);
+ CPPUNIT_TEST(testTableRowSpan);
CPPUNIT_TEST(testLink);
CPPUNIT_TEST(testLinkCharFormat);
CPPUNIT_TEST(testLinkNamedCharFormat);
@@ -475,6 +477,15 @@ void EPUBExportTest::testTable()
assertXPath(mpXmlDoc, "//xhtml:table/xhtml:tbody/xhtml:tr/xhtml:td", 4);
}
+void EPUBExportTest::testTableRowSpan()
+{
+ createDoc("table-row-span.fodt", {});
+
+ mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml");
+ // This failed, row span wasn't exported.
+ assertXPath(mpXmlDoc, "//xhtml:table/xhtml:tbody/xhtml:tr[1]/xhtml:td[1]", "rowspan", "2");
+}
+
void EPUBExportTest::testLink()
{
createDoc("link.fodt", {});
diff --git a/writerperfect/qa/unit/data/writer/epubexport/table-row-span.fodt b/writerperfect/qa/unit/data/writer/epubexport/table-row-span.fodt
new file mode 100644
index 000000000000..dd007dcc19d2
--- /dev/null
+++ b/writerperfect/qa/unit/data/writer/epubexport/table-row-span.fodt
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:automatic-styles>
+ <style:style style:name="Table1" style:family="table">
+ <style:table-properties style:width="17.59cm" table:align="margins"/>
+ </style:style>
+ <style:style style:name="Table1.A" style:family="table-column">
+ <style:table-column-properties style:column-width="8.795cm" style:rel-column-width="32767*"/>
+ </style:style>
+ <style:style style:name="Table1.A1" style:family="table-cell">
+ <style:table-cell-properties fo:padding="0.097cm" fo:border-left="0.05pt solid #000000" fo:border-right="none" fo:border-top="0.05pt solid #000000" fo:border-bottom="0.05pt solid #000000"/>
+ </style:style>
+ <style:style style:name="Table1.B1" style:family="table-cell">
+ <style:table-cell-properties fo:padding="0.097cm" fo:border="0.05pt solid #000000"/>
+ </style:style>
+ <style:style style:name="Table1.B2" style:family="table-cell">
+ <style:table-cell-properties fo:padding="0.097cm" fo:border-left="0.05pt solid #000000" fo:border-right="0.05pt solid #000000" fo:border-top="none" fo:border-bottom="0.05pt solid #000000"/>
+ </style:style>
+ </office:automatic-styles>
+ <office:body>
+ <office:text>
+ <table:table table:name="Table1" table:style-name="Table1">
+ <table:table-column table:style-name="Table1.A" table:number-columns-repeated="2"/>
+ <table:table-row>
+ <table:table-cell table:style-name="Table1.A1" table:number-rows-spanned="2" office:value-type="string">
+ <text:p>Row spanning</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="Table1.B1" office:value-type="string">
+ <text:p>B1</text:p>
+ </table:table-cell>
+ </table:table-row>
+ <table:table-row>
+ <table:covered-table-cell/>
+ <table:table-cell table:style-name="Table1.B2" office:value-type="string">
+ <text:p>B2</text:p>
+ </table:table-cell>
+ </table:table-row>
+ </table:table>
+ <text:p/>
+ </office:text>
+ </office:body>
+</office:document>
diff --git a/writerperfect/source/writer/exp/xmltbli.cxx b/writerperfect/source/writer/exp/xmltbli.cxx
index d5844fd18d5c..cdaabdab0349 100644
--- a/writerperfect/source/writer/exp/xmltbli.cxx
+++ b/writerperfect/source/writer/exp/xmltbli.cxx
@@ -42,9 +42,19 @@ rtl::Reference<XMLImportContext> XMLTableCellContext::CreateChildContext(const O
return CreateTextChildContext(mrImport, rName);
}
-void XMLTableCellContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/)
-{
- mrImport.GetGenerator().openTableCell(librevenge::RVNGPropertyList());
+void XMLTableCellContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs)
+{
+ librevenge::RVNGPropertyList aPropertyList;
+ for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
+ {
+ const OUString &rAttributeName = xAttribs->getNameByIndex(i);
+ const OUString &rAttributeValue = xAttribs->getValueByIndex(i);
+
+ OString sName = OUStringToOString(rAttributeName, RTL_TEXTENCODING_UTF8);
+ OString sValue = OUStringToOString(rAttributeValue, RTL_TEXTENCODING_UTF8);
+ aPropertyList.insert(sName.getStr(), sValue.getStr());
+ }
+ mrImport.GetGenerator().openTableCell(aPropertyList);
}
void XMLTableCellContext::endElement(const OUString &/*rName*/)
@@ -73,6 +83,10 @@ rtl::Reference<XMLImportContext> XMLTableRowContext::CreateChildContext(const OU
{
if (rName == "table:table-cell")
return new XMLTableCellContext(mrImport);
+ if (rName == "table:covered-table-cell")
+ mrImport.GetGenerator().insertCoveredTableCell(librevenge::RVNGPropertyList());
+ else
+ SAL_WARN("writerperfect", "XMLTableRowContext::CreateChildContext: unhandled " << rName);
return nullptr;
}