[Libreoffice-commits] core.git: external/libepubgen writerperfect/qa writerperfect/source
Miklos Vajna
vmiklos at collabora.co.uk
Fri Nov 24 10:15:33 UTC 2017
external/libepubgen/libepubgen-epub3.patch.1 | 315 ++++++++++
writerperfect/qa/unit/EPUBExportTest.cxx | 27
writerperfect/qa/unit/data/writer/epubexport/table-cell-width.fodt | 45 +
writerperfect/source/writer/exp/txtstyli.cxx | 37 +
writerperfect/source/writer/exp/txtstyli.hxx | 2
writerperfect/source/writer/exp/xmlfmt.cxx | 11
writerperfect/source/writer/exp/xmlfmt.hxx | 5
writerperfect/source/writer/exp/xmlimp.cxx | 16
writerperfect/source/writer/exp/xmlimp.hxx | 4
writerperfect/source/writer/exp/xmltbli.cxx | 94 ++
writerperfect/source/writer/exp/xmltbli.hxx | 4
11 files changed, 543 insertions(+), 17 deletions(-)
New commits:
commit af72d1b9d1745944cd7842905d2d8ac3f8d1d640
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Fri Nov 24 09:12:26 2017 +0100
EPUB export: handle cell width
By handling relative column widths in libepubgen (since LO may only know
that one, when layout is not available) and parsing column properties in
writerperfect.
Change-Id: I8fae5f1a3c970b97c2b452f3c20eff0911a56ba8
Reviewed-on: https://gerrit.libreoffice.org/45202
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
diff --git a/external/libepubgen/libepubgen-epub3.patch.1 b/external/libepubgen/libepubgen-epub3.patch.1
index a45b9666568c..3ce4fe034f75 100644
--- a/external/libepubgen/libepubgen-epub3.patch.1
+++ b/external/libepubgen/libepubgen-epub3.patch.1
@@ -2782,3 +2782,318 @@ index 20056ad..135a144 100644
--
2.12.3
+From 6c8e86ccebb11df7ece32d10da2894c6698c5515 Mon Sep 17 00:00:00 2001
+From: Miklos Vajna <vmiklos at collabora.co.uk>
+Date: Thu, 2 Nov 2017 12:07:02 +0100
+Subject: [PATCH 1/4] EPUBTableStyleManager: witdh -> width
+
+---
+ src/lib/EPUBTableStyleManager.cpp | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/lib/EPUBTableStyleManager.cpp b/src/lib/EPUBTableStyleManager.cpp
+index 4e24611..5795524 100644
+--- a/src/lib/EPUBTableStyleManager.cpp
++++ b/src/lib/EPUBTableStyleManager.cpp
+@@ -48,7 +48,7 @@ void EPUBTableStyleManager::closeTable()
+ {
+ if (!m_columWitdhsStack.size())
+ {
+- EPUBGEN_DEBUG_MSG(("EPUBTableStyleManager::closeTable: can not find the columns witdh\n"));
++ EPUBGEN_DEBUG_MSG(("EPUBTableStyleManager::closeTable: can not find the columns width\n"));
+ return;
+ }
+ m_columWitdhsStack.pop_back();
+@@ -61,7 +61,7 @@ bool EPUBTableStyleManager::getColumnsWidth(int col, int numSpanned, double &w)
+ std::vector<double> const &widths=m_columWitdhsStack.back();
+ if (col < 0 || size_t(col+numSpanned-1) >= widths.size())
+ {
+- EPUBGEN_DEBUG_MSG(("EPUBTableStyleManager::getColumnsWidth: can not compute the columns witdh\n"));
++ EPUBGEN_DEBUG_MSG(("EPUBTableStyleManager::getColumnsWidth: can not compute the columns width\n"));
+ return false;
+ }
+ bool fixed = true;
+--
+2.13.6
+
+From 45bf16a8b384010814148538d86ee584b9295c7a Mon Sep 17 00:00:00 2001
+From: Miklos Vajna <vmiklos at collabora.co.uk>
+Date: Fri, 3 Nov 2017 12:30:13 +0100
+Subject: [PATCH 2/4] Witdh -> Width
+
+---
+ src/lib/EPUBTableStyleManager.cpp | 10 +++++-----
+ src/lib/EPUBTableStyleManager.h | 4 ++--
+ 2 files changed, 7 insertions(+), 7 deletions(-)
+
+diff --git a/src/lib/EPUBTableStyleManager.cpp b/src/lib/EPUBTableStyleManager.cpp
+index 5795524..6f8b2af 100644
+--- a/src/lib/EPUBTableStyleManager.cpp
++++ b/src/lib/EPUBTableStyleManager.cpp
+@@ -41,24 +41,24 @@ void EPUBTableStyleManager::openTable(RVNGPropertyListVector const &colList)
+ }
+ colWidths.push_back(width);
+ }
+- m_columWitdhsStack.push_back(colWidths);
++ m_columWidthsStack.push_back(colWidths);
+ }
+
+ void EPUBTableStyleManager::closeTable()
+ {
+- if (!m_columWitdhsStack.size())
++ if (!m_columWidthsStack.size())
+ {
+ EPUBGEN_DEBUG_MSG(("EPUBTableStyleManager::closeTable: can not find the columns width\n"));
+ return;
+ }
+- m_columWitdhsStack.pop_back();
++ m_columWidthsStack.pop_back();
+ }
+
+ bool EPUBTableStyleManager::getColumnsWidth(int col, int numSpanned, double &w) const
+ {
+- if (!m_columWitdhsStack.size())
++ if (!m_columWidthsStack.size())
+ return false;
+- std::vector<double> const &widths=m_columWitdhsStack.back();
++ std::vector<double> const &widths=m_columWidthsStack.back();
+ if (col < 0 || size_t(col+numSpanned-1) >= widths.size())
+ {
+ EPUBGEN_DEBUG_MSG(("EPUBTableStyleManager::getColumnsWidth: can not compute the columns width\n"));
+diff --git a/src/lib/EPUBTableStyleManager.h b/src/lib/EPUBTableStyleManager.h
+index 135a144..5f704a1 100644
+--- a/src/lib/EPUBTableStyleManager.h
++++ b/src/lib/EPUBTableStyleManager.h
+@@ -32,7 +32,7 @@ class EPUBTableStyleManager
+
+ public:
+ //! constructor
+- EPUBTableStyleManager() : m_cellContentNameMap(), m_rowContentNameMap(), m_columWitdhsStack()
++ EPUBTableStyleManager() : m_cellContentNameMap(), m_rowContentNameMap(), m_columWidthsStack()
+ {
+ }
+ //! destructor
+@@ -65,7 +65,7 @@ private:
+ //! a map row content -> name
+ ContentNameMap_t m_rowContentNameMap;
+ //! a stack of column width (in inches )
+- std::vector<std::vector<double> > m_columWitdhsStack;
++ std::vector<std::vector<double> > m_columWidthsStack;
+
+ EPUBTableStyleManager(EPUBTableStyleManager const &orig);
+ EPUBTableStyleManager operator=(EPUBTableStyleManager const &orig);
+--
+2.13.6
+
+From 85fe982b2ad158f6e050c15e4a59d51d863cc28d Mon Sep 17 00:00:00 2001
+From: Miklos Vajna <vmiklos at collabora.co.uk>
+Date: Fri, 3 Nov 2017 15:33:35 +0100
+Subject: [PATCH 3/4] columWidths -> columnWidths
+
+---
+ src/lib/EPUBTableStyleManager.cpp | 10 +++++-----
+ src/lib/EPUBTableStyleManager.h | 4 ++--
+ 2 files changed, 7 insertions(+), 7 deletions(-)
+
+diff --git a/src/lib/EPUBTableStyleManager.cpp b/src/lib/EPUBTableStyleManager.cpp
+index 6f8b2af..b610c20 100644
+--- a/src/lib/EPUBTableStyleManager.cpp
++++ b/src/lib/EPUBTableStyleManager.cpp
+@@ -41,24 +41,24 @@ void EPUBTableStyleManager::openTable(RVNGPropertyListVector const &colList)
+ }
+ colWidths.push_back(width);
+ }
+- m_columWidthsStack.push_back(colWidths);
++ m_columnWidthsStack.push_back(colWidths);
+ }
+
+ void EPUBTableStyleManager::closeTable()
+ {
+- if (!m_columWidthsStack.size())
++ if (!m_columnWidthsStack.size())
+ {
+ EPUBGEN_DEBUG_MSG(("EPUBTableStyleManager::closeTable: can not find the columns width\n"));
+ return;
+ }
+- m_columWidthsStack.pop_back();
++ m_columnWidthsStack.pop_back();
+ }
+
+ bool EPUBTableStyleManager::getColumnsWidth(int col, int numSpanned, double &w) const
+ {
+- if (!m_columWidthsStack.size())
++ if (!m_columnWidthsStack.size())
+ return false;
+- std::vector<double> const &widths=m_columWidthsStack.back();
++ std::vector<double> const &widths=m_columnWidthsStack.back();
+ if (col < 0 || size_t(col+numSpanned-1) >= widths.size())
+ {
+ EPUBGEN_DEBUG_MSG(("EPUBTableStyleManager::getColumnsWidth: can not compute the columns width\n"));
+diff --git a/src/lib/EPUBTableStyleManager.h b/src/lib/EPUBTableStyleManager.h
+index 5f704a1..4de70e3 100644
+--- a/src/lib/EPUBTableStyleManager.h
++++ b/src/lib/EPUBTableStyleManager.h
+@@ -32,7 +32,7 @@ class EPUBTableStyleManager
+
+ public:
+ //! constructor
+- EPUBTableStyleManager() : m_cellContentNameMap(), m_rowContentNameMap(), m_columWidthsStack()
++ EPUBTableStyleManager() : m_cellContentNameMap(), m_rowContentNameMap(), m_columnWidthsStack()
+ {
+ }
+ //! destructor
+@@ -65,7 +65,7 @@ private:
+ //! a map row content -> name
+ ContentNameMap_t m_rowContentNameMap;
+ //! a stack of column width (in inches )
+- std::vector<std::vector<double> > m_columWidthsStack;
++ std::vector<std::vector<double> > m_columnWidthsStack;
+
+ EPUBTableStyleManager(EPUBTableStyleManager const &orig);
+ EPUBTableStyleManager operator=(EPUBTableStyleManager const &orig);
+--
+2.13.6
+
+From 20930e2d8151fd2ec44feb9cdb8ca502df99365f Mon Sep 17 00:00:00 2001
+From: Miklos Vajna <vmiklos at collabora.co.uk>
+Date: Fri, 3 Nov 2017 17:00:12 +0100
+Subject: [PATCH 4/4] EPUBTableStyleManager: handle style:rel-column-width col
+ prop
+
+Previously only fixed width was supported, but relative width works
+better for reflowable formats and ODF has markup to express this.
+---
+ src/lib/EPUBTableStyleManager.cpp | 42 ++++++++++++++++++++++++++++++++----
+ src/lib/EPUBTableStyleManager.h | 6 +++++-
+ src/test/EPUBTextGeneratorTest.cpp | 44 ++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 87 insertions(+), 5 deletions(-)
+
+diff --git a/src/lib/EPUBTableStyleManager.cpp b/src/lib/EPUBTableStyleManager.cpp
+index b610c20..92078a2 100644
+--- a/src/lib/EPUBTableStyleManager.cpp
++++ b/src/lib/EPUBTableStyleManager.cpp
+@@ -7,6 +7,7 @@
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
++#include <numeric>
+ #include <sstream>
+
+ #include <librevenge/librevenge.h>
+@@ -25,6 +26,7 @@ using librevenge::RVNGString;
+ void EPUBTableStyleManager::openTable(RVNGPropertyListVector const &colList)
+ {
+ std::vector<double> colWidths;
++ std::vector<double> relColWidths;
+ for (unsigned long i = 0; i < colList.count(); i++)
+ {
+ RVNGPropertyList const &prop=colList[i];
+@@ -40,8 +42,15 @@ void EPUBTableStyleManager::openTable(RVNGPropertyListVector const &colList)
+ width=prop["style:column-width"]->getDouble()/1440.;
+ }
+ colWidths.push_back(width);
++
++ if (prop["style:rel-column-width"])
++ {
++ width = prop["style:rel-column-width"]->getDouble();
++ relColWidths.push_back(width);
++ }
+ }
+ m_columnWidthsStack.push_back(colWidths);
++ m_relColumnWidthsStack.push_back(relColWidths);
+ }
+
+ void EPUBTableStyleManager::closeTable()
+@@ -54,14 +63,18 @@ void EPUBTableStyleManager::closeTable()
+ m_columnWidthsStack.pop_back();
+ }
+
+-bool EPUBTableStyleManager::getColumnsWidth(int col, int numSpanned, double &w) const
++namespace
+ {
+- if (!m_columnWidthsStack.size())
++bool extractColumnsWidth(const std::vector< std::vector<double> > &columnWidthsStack, int col, int numSpanned, bool relative, double &w)
++{
++ if (!columnWidthsStack.size())
+ return false;
+- std::vector<double> const &widths=m_columnWidthsStack.back();
++ std::vector<double> const &widths=columnWidthsStack.back();
++ double total = std::accumulate(widths.begin(), widths.end(), static_cast<double>(0));
+ if (col < 0 || size_t(col+numSpanned-1) >= widths.size())
+ {
+- EPUBGEN_DEBUG_MSG(("EPUBTableStyleManager::getColumnsWidth: can not compute the columns width\n"));
++ if (!relative)
++ EPUBGEN_DEBUG_MSG(("EPUBTableStyleManager::getColumnsWidth: can not compute the columns width\n"));
+ return false;
+ }
+ bool fixed = true;
+@@ -82,8 +95,22 @@ bool EPUBTableStyleManager::getColumnsWidth(int col, int numSpanned, double &w)
+ }
+ }
+ if (!fixed) w = -w;
++ if (relative)
++ // Expected unit is percents.
++ w = w * 100 / total;
+ return true;
+ }
++}
++
++bool EPUBTableStyleManager::getColumnsWidth(int col, int numSpanned, double &w) const
++{
++ return extractColumnsWidth(m_columnWidthsStack, col, numSpanned, false, w);
++}
++
++bool EPUBTableStyleManager::getRelColumnsWidth(int col, int numSpanned, double &w) const
++{
++ return extractColumnsWidth(m_relColumnWidthsStack, col, numSpanned, true, w);
++}
+
+ std::string EPUBTableStyleManager::getCellClass(RVNGPropertyList const &pList)
+ {
+@@ -176,6 +203,13 @@ void EPUBTableStyleManager::extractCellProperties(RVNGPropertyList const &pList,
+ width << -w << "in";
+ cssProps["min-width"] = width.str();
+ }
++
++ if (getRelColumnsWidth(c, span, w))
++ {
++ std::ostringstream width;
++ width << w << "%";
++ cssProps["width"] = width.str();
++ }
+ }
+ if (pList["fo:text-align"])
+ {
+diff --git a/src/lib/EPUBTableStyleManager.h b/src/lib/EPUBTableStyleManager.h
+index 4de70e3..24ae1a5 100644
+--- a/src/lib/EPUBTableStyleManager.h
++++ b/src/lib/EPUBTableStyleManager.h
+@@ -32,7 +32,7 @@ class EPUBTableStyleManager
+
+ public:
+ //! constructor
+- EPUBTableStyleManager() : m_cellContentNameMap(), m_rowContentNameMap(), m_columnWidthsStack()
++ EPUBTableStyleManager() : m_cellContentNameMap(), m_rowContentNameMap(), m_columnWidthsStack(), m_relColumnWidthsStack()
+ {
+ }
+ //! destructor
+@@ -60,12 +60,16 @@ private:
+ void extractRowProperties(librevenge::RVNGPropertyList const &pList, EPUBCSSProperties &cssProps) const;
+ //! try to return the col width
+ bool getColumnsWidth(int i, int numSpanned, double &w) const;
++ //! try to return the relative col width
++ bool getRelColumnsWidth(int i, int numSpanned, double &w) const;
+ //! a map cell content -> name
+ ContentNameMap_t m_cellContentNameMap;
+ //! a map row content -> name
+ ContentNameMap_t m_rowContentNameMap;
+ //! a stack of column width (in inches )
+ std::vector<std::vector<double> > m_columnWidthsStack;
++ //! a stack of relative column width (in percents )
++ std::vector<std::vector<double> > m_relColumnWidthsStack;
+
+ EPUBTableStyleManager(EPUBTableStyleManager const &orig);
+ EPUBTableStyleManager operator=(EPUBTableStyleManager const &orig);
+--
+2.13.6
+
diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx
index 31ad665a62a0..411aed3eac6b 100644
--- a/writerperfect/qa/unit/EPUBExportTest.cxx
+++ b/writerperfect/qa/unit/EPUBExportTest.cxx
@@ -55,7 +55,7 @@ public:
/// Loads a CSS representation of the stream named rName in the exported package into rTree.
void parseCssExport(const OUString &rName, std::map< OString, std::vector<OString> > &rTree);
/// Loads a CSS style string into a map.
- void parseCssStyle(const OUString &rStyle, std::map<OUString, OUString> &rCss);
+ static void parseCssStyle(const OUString &rStyle, std::map<OUString, OUString> &rCss);
void testOutlineLevel();
void testMimetype();
void testEPUB2();
@@ -76,6 +76,7 @@ public:
void testTable();
void testTableRowSpan();
void testTableCellBorder();
+ void testTableCellWidth();
void testLink();
void testLinkCharFormat();
void testLinkNamedCharFormat();
@@ -101,6 +102,7 @@ public:
CPPUNIT_TEST(testTable);
CPPUNIT_TEST(testTableRowSpan);
CPPUNIT_TEST(testTableCellBorder);
+ CPPUNIT_TEST(testTableCellWidth);
CPPUNIT_TEST(testLink);
CPPUNIT_TEST(testLinkCharFormat);
CPPUNIT_TEST(testLinkNamedCharFormat);
@@ -500,6 +502,29 @@ void EPUBExportTest::testTableCellBorder()
CPPUNIT_ASSERT_EQUAL(OUString("0.05pt solid #000000"), aCss["border-left"]);
}
+namespace
+{
+double getCellWidth(const OUString &rStyle)
+{
+ std::map<OUString, OUString> aCss;
+ EPUBExportTest::parseCssStyle(rStyle, aCss);
+ return aCss["width"].toDouble();
+}
+}
+
+void EPUBExportTest::testTableCellWidth()
+{
+ createDoc("table-cell-width.fodt", {});
+
+ mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml");
+ OUString aStyle1 = getXPath(mpXmlDoc, "//xhtml:table/xhtml:tbody/xhtml:tr[1]/xhtml:td[1]", "style");
+ OUString aStyle2 = getXPath(mpXmlDoc, "//xhtml:table/xhtml:tbody/xhtml:tr[1]/xhtml:td[2]", "style");
+ OUString aStyle3 = getXPath(mpXmlDoc, "//xhtml:table/xhtml:tbody/xhtml:tr[1]/xhtml:td[3]", "style");
+ // These failed, all widths were 0.
+ CPPUNIT_ASSERT_GREATER(getCellWidth(aStyle2), getCellWidth(aStyle1));
+ CPPUNIT_ASSERT_GREATER(getCellWidth(aStyle3), getCellWidth(aStyle1));
+}
+
void EPUBExportTest::testLink()
{
createDoc("link.fodt", {});
diff --git a/writerperfect/qa/unit/data/writer/epubexport/table-cell-width.fodt b/writerperfect/qa/unit/data/writer/epubexport/table-cell-width.fodt
new file mode 100644
index 000000000000..345550928256
--- /dev/null
+++ b/writerperfect/qa/unit/data/writer/epubexport/table-cell-width.fodt
@@ -0,0 +1,45 @@
+<?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:oas
is: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:shadow="none"/>
+ </style:style>
+ <style:style style:name="Table1.A" style:family="table-column">
+ <style:table-column-properties style:column-width="8.999cm" style:rel-column-width="5102*"/>
+ </style:style>
+ <style:style style:name="Table1.B" style:family="table-column">
+ <style:table-column-properties style:column-width="4.191cm" style:rel-column-width="2376*"/>
+ </style:style>
+ <style:style style:name="Table1.C" style:family="table-column">
+ <style:table-column-properties style:column-width="4.399cm" style:rel-column-width="2494*"/>
+ </style:style>
+ <style:style style:name="Table1.A1" style:family="table-cell">
+ <style:table-cell-properties fo:padding="0.097cm" fo:border-left="1pt solid #000000" fo:border-right="none" fo:border-top="1pt solid #000000" fo:border-bottom="1pt solid #000000"/>
+ </style:style>
+ <style:style style:name="Table1.C1" style:family="table-cell">
+ <style:table-cell-properties fo:padding="0.097cm" fo:border="1pt solid #000000"/>
+ </style:style>
+ </office:automatic-styles>
+ <office:body>
+ <office:text>
+ <text:p>Before</text:p>
+ <table:table table:name="Table1" table:style-name="Table1">
+ <table:table-column table:style-name="Table1.A"/>
+ <table:table-column table:style-name="Table1.B"/>
+ <table:table-column table:style-name="Table1.C"/>
+ <table:table-row>
+ <table:table-cell table:style-name="Table1.A1" office:value-type="string">
+ <text:p>A1, this is wider</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="Table1.A1" office:value-type="string">
+ <text:p>B1, than this</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="Table1.C1" office:value-type="string">
+ <text:p>C1, or this</text:p>
+ </table:table-cell>
+ </table:table-row>
+ </table:table>
+ <text:p>After</text:p>
+ </office:text>
+ </office:body>
+</office:document>
diff --git a/writerperfect/source/writer/exp/txtstyli.cxx b/writerperfect/source/writer/exp/txtstyli.cxx
index a6f04e20c39e..15889877e883 100644
--- a/writerperfect/source/writer/exp/txtstyli.cxx
+++ b/writerperfect/source/writer/exp/txtstyli.cxx
@@ -75,6 +75,34 @@ void XMLTextPropertiesContext::startElement(const OUString &/*rName*/, const css
}
}
+/// Handler for <style:table-column-properties>.
+class XMLTableColumnPropertiesContext : public XMLImportContext
+{
+public:
+ XMLTableColumnPropertiesContext(XMLImport &rImport, XMLStyleContext &rStyle);
+
+ void SAL_CALL startElement(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
+
+private:
+ XMLStyleContext &mrStyle;
+};
+
+XMLTableColumnPropertiesContext::XMLTableColumnPropertiesContext(XMLImport &rImport, XMLStyleContext &rStyle)
+ : XMLImportContext(rImport)
+ , mrStyle(rStyle)
+{
+}
+
+void XMLTableColumnPropertiesContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs)
+{
+ for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
+ {
+ OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
+ OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
+ mrStyle.GetColumnPropertyList().insert(sName.getStr(), sValue.getStr());
+ }
+}
+
/// Handler for <style:table-cell-properties>.
class XMLTableCellPropertiesContext : public XMLImportContext
{
@@ -117,6 +145,8 @@ rtl::Reference<XMLImportContext> XMLStyleContext::CreateChildContext(const OUStr
return new XMLTextPropertiesContext(mrImport, *this);
if (rName == "style:table-cell-properties")
return new XMLTableCellPropertiesContext(mrImport, *this);
+ if (rName == "style:table-column-properties")
+ return new XMLTableColumnPropertiesContext(mrImport, *this);
return nullptr;
}
@@ -150,6 +180,8 @@ void XMLStyleContext::endElement(const OUString &/*rName*/)
m_rStyles.GetCurrentParagraphStyles()[m_aName] = m_aParagraphPropertyList;
if (m_aFamily == "table-cell")
m_rStyles.GetCurrentCellStyles()[m_aName] = m_aCellPropertyList;
+ if (m_aFamily == "table-column")
+ m_rStyles.GetCurrentColumnStyles()[m_aName] = m_aColumnPropertyList;
}
librevenge::RVNGPropertyList &XMLStyleContext::GetTextPropertyList()
@@ -167,6 +199,11 @@ librevenge::RVNGPropertyList &XMLStyleContext::GetCellPropertyList()
return m_aCellPropertyList;
}
+librevenge::RVNGPropertyList &XMLStyleContext::GetColumnPropertyList()
+{
+ return m_aColumnPropertyList;
+}
+
} // namespace exp
} // namespace writerperfect
diff --git a/writerperfect/source/writer/exp/txtstyli.hxx b/writerperfect/source/writer/exp/txtstyli.hxx
index 8550cb66d879..1321beae9385 100644
--- a/writerperfect/source/writer/exp/txtstyli.hxx
+++ b/writerperfect/source/writer/exp/txtstyli.hxx
@@ -34,6 +34,7 @@ public:
librevenge::RVNGPropertyList &GetTextPropertyList();
librevenge::RVNGPropertyList &GetParagraphPropertyList();
librevenge::RVNGPropertyList &GetCellPropertyList();
+ librevenge::RVNGPropertyList &GetColumnPropertyList();
private:
OUString m_aName;
@@ -41,6 +42,7 @@ private:
librevenge::RVNGPropertyList m_aTextPropertyList;
librevenge::RVNGPropertyList m_aParagraphPropertyList;
librevenge::RVNGPropertyList m_aCellPropertyList;
+ librevenge::RVNGPropertyList m_aColumnPropertyList;
XMLStylesContext &m_rStyles;
};
diff --git a/writerperfect/source/writer/exp/xmlfmt.cxx b/writerperfect/source/writer/exp/xmlfmt.cxx
index 52698fec8740..c3854e5323c4 100644
--- a/writerperfect/source/writer/exp/xmlfmt.cxx
+++ b/writerperfect/source/writer/exp/xmlfmt.cxx
@@ -21,11 +21,13 @@ namespace exp
XMLStylesContext::XMLStylesContext(XMLImport &rImport, std::map<OUString, librevenge::RVNGPropertyList> &rParagraphStyles,
std::map<OUString, librevenge::RVNGPropertyList> &rTextStyles,
- std::map<OUString, librevenge::RVNGPropertyList> &rCellStyles)
+ std::map<OUString, librevenge::RVNGPropertyList> &rCellStyles,
+ std::map<OUString, librevenge::RVNGPropertyList> &rColumnStyles)
: XMLImportContext(rImport),
m_rParagraphStyles(rParagraphStyles),
m_rTextStyles(rTextStyles),
- m_rCellStyles(rCellStyles)
+ m_rCellStyles(rCellStyles),
+ m_rColumnStyles(rColumnStyles)
{
}
@@ -51,6 +53,11 @@ std::map<OUString, librevenge::RVNGPropertyList> &XMLStylesContext::GetCurrentCe
return m_rCellStyles;
}
+std::map<OUString, librevenge::RVNGPropertyList> &XMLStylesContext::GetCurrentColumnStyles()
+{
+ return m_rColumnStyles;
+}
+
} // namespace exp
} // namespace writerperfect
diff --git a/writerperfect/source/writer/exp/xmlfmt.hxx b/writerperfect/source/writer/exp/xmlfmt.hxx
index cd89121b7dd5..5d575fa065d5 100644
--- a/writerperfect/source/writer/exp/xmlfmt.hxx
+++ b/writerperfect/source/writer/exp/xmlfmt.hxx
@@ -27,17 +27,20 @@ class XMLStylesContext : public XMLImportContext
public:
XMLStylesContext(XMLImport &rImport, std::map<OUString, librevenge::RVNGPropertyList> &rParagraphStyles,
std::map<OUString, librevenge::RVNGPropertyList> &rTextStyles,
- std::map<OUString, librevenge::RVNGPropertyList> &rCellStyles);
+ std::map<OUString, librevenge::RVNGPropertyList> &rCellStyles,
+ std::map<OUString, librevenge::RVNGPropertyList> &rColumnStyles);
rtl::Reference<XMLImportContext> CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
std::map<OUString, librevenge::RVNGPropertyList> &GetCurrentParagraphStyles();
std::map<OUString, librevenge::RVNGPropertyList> &GetCurrentTextStyles();
std::map<OUString, librevenge::RVNGPropertyList> &GetCurrentCellStyles();
+ std::map<OUString, librevenge::RVNGPropertyList> &GetCurrentColumnStyles();
private:
std::map<OUString, librevenge::RVNGPropertyList> &m_rParagraphStyles;
std::map<OUString, librevenge::RVNGPropertyList> &m_rTextStyles;
std::map<OUString, librevenge::RVNGPropertyList> &m_rCellStyles;
+ std::map<OUString, librevenge::RVNGPropertyList> &m_rColumnStyles;
};
} // namespace exp
diff --git a/writerperfect/source/writer/exp/xmlimp.cxx b/writerperfect/source/writer/exp/xmlimp.cxx
index 67b4fd713149..20e20e76f870 100644
--- a/writerperfect/source/writer/exp/xmlimp.cxx
+++ b/writerperfect/source/writer/exp/xmlimp.cxx
@@ -65,11 +65,13 @@ rtl::Reference<XMLImportContext> XMLOfficeDocContext::CreateChildContext(const O
else if (rName == "office:automatic-styles")
return new XMLStylesContext(mrImport, mrImport.GetAutomaticParagraphStyles(),
mrImport.GetAutomaticTextStyles(),
- mrImport.GetAutomaticCellStyles());
+ mrImport.GetAutomaticCellStyles(),
+ mrImport.GetAutomaticColumnStyles());
else if (rName == "office:styles")
return new XMLStylesContext(mrImport, mrImport.GetParagraphStyles(),
mrImport.GetTextStyles(),
- mrImport.GetCellStyles());
+ mrImport.GetCellStyles(),
+ mrImport.GetColumnStyles());
return nullptr;
}
@@ -105,6 +107,11 @@ std::map<OUString, librevenge::RVNGPropertyList> &XMLImport::GetAutomaticCellSty
return maAutomaticCellStyles;
}
+std::map<OUString, librevenge::RVNGPropertyList> &XMLImport::GetAutomaticColumnStyles()
+{
+ return maAutomaticColumnStyles;
+}
+
std::map<OUString, librevenge::RVNGPropertyList> &XMLImport::GetTextStyles()
{
return maTextStyles;
@@ -120,6 +127,11 @@ std::map<OUString, librevenge::RVNGPropertyList> &XMLImport::GetCellStyles()
return maCellStyles;
}
+std::map<OUString, librevenge::RVNGPropertyList> &XMLImport::GetColumnStyles()
+{
+ return maColumnStyles;
+}
+
void XMLImport::startDocument()
{
mrGenerator.startDocument(librevenge::RVNGPropertyList());
diff --git a/writerperfect/source/writer/exp/xmlimp.hxx b/writerperfect/source/writer/exp/xmlimp.hxx
index 2540e4db8d22..8b833b1f7054 100644
--- a/writerperfect/source/writer/exp/xmlimp.hxx
+++ b/writerperfect/source/writer/exp/xmlimp.hxx
@@ -41,6 +41,8 @@ class XMLImport : public cppu::WeakImplHelper
std::map<OUString, librevenge::RVNGPropertyList> maParagraphStyles;
std::map<OUString, librevenge::RVNGPropertyList> maAutomaticCellStyles;
std::map<OUString, librevenge::RVNGPropertyList> maCellStyles;
+ std::map<OUString, librevenge::RVNGPropertyList> maAutomaticColumnStyles;
+ std::map<OUString, librevenge::RVNGPropertyList> maColumnStyles;
public:
XMLImport(librevenge::RVNGTextInterface &rGenerator);
@@ -51,9 +53,11 @@ public:
std::map<OUString, librevenge::RVNGPropertyList> &GetAutomaticTextStyles();
std::map<OUString, librevenge::RVNGPropertyList> &GetAutomaticParagraphStyles();
std::map<OUString, librevenge::RVNGPropertyList> &GetAutomaticCellStyles();
+ std::map<OUString, librevenge::RVNGPropertyList> &GetAutomaticColumnStyles();
std::map<OUString, librevenge::RVNGPropertyList> &GetTextStyles();
std::map<OUString, librevenge::RVNGPropertyList> &GetParagraphStyles();
std::map<OUString, librevenge::RVNGPropertyList> &GetCellStyles();
+ std::map<OUString, librevenge::RVNGPropertyList> &GetColumnStyles();
// XDocumentHandler
void SAL_CALL startDocument() override;
diff --git a/writerperfect/source/writer/exp/xmltbli.cxx b/writerperfect/source/writer/exp/xmltbli.cxx
index 15444bc33e0b..c698c9d1ce9c 100644
--- a/writerperfect/source/writer/exp/xmltbli.cxx
+++ b/writerperfect/source/writer/exp/xmltbli.cxx
@@ -20,20 +20,41 @@ namespace writerperfect
namespace exp
{
+/// Handler for <table:table-row>.
+class XMLTableRowContext : public XMLImportContext
+{
+public:
+ XMLTableRowContext(XMLImport &rImport);
+
+ rtl::Reference<XMLImportContext> CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
+ int GetColumn() const;
+ void SetColumn(int nColumn);
+
+ void SAL_CALL startElement(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
+ void SAL_CALL endElement(const OUString &rName) override;
+
+private:
+ int m_nColumn = 0;
+};
+
/// Handler for <table:cell>.
class XMLTableCellContext : public XMLImportContext
{
public:
- XMLTableCellContext(XMLImport &rImport);
+ XMLTableCellContext(XMLImport &rImport, XMLTableRowContext &rRow);
rtl::Reference<XMLImportContext> CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
void SAL_CALL startElement(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
void SAL_CALL endElement(const OUString &rName) override;
+
+private:
+ XMLTableRowContext &m_rRow;
};
-XMLTableCellContext::XMLTableCellContext(XMLImport &rImport)
- : XMLImportContext(rImport)
+XMLTableCellContext::XMLTableCellContext(XMLImport &rImport, XMLTableRowContext &rRow)
+ : XMLImportContext(rImport),
+ m_rRow(rRow)
{
}
@@ -59,7 +80,9 @@ void XMLTableCellContext::startElement(const OUString &/*rName*/, const css::uno
aPropertyList.insert(sName.getStr(), sValue.getStr());
}
}
+ aPropertyList.insert("librevenge:column", m_rRow.GetColumn());
mrImport.GetGenerator().openTableCell(aPropertyList);
+ m_rRow.SetColumn(m_rRow.GetColumn() + 1);
}
void XMLTableCellContext::endElement(const OUString &/*rName*/)
@@ -67,18 +90,38 @@ void XMLTableCellContext::endElement(const OUString &/*rName*/)
mrImport.GetGenerator().closeTableCell();
}
-/// Handler for <table:row>.
-class XMLTableRowContext : public XMLImportContext
+/// Handler for <table:table-column>.
+class XMLTableColumnContext : public XMLImportContext
{
public:
- XMLTableRowContext(XMLImport &rImport);
-
- rtl::Reference<XMLImportContext> CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
+ XMLTableColumnContext(XMLImport &rImport, librevenge::RVNGPropertyListVector &rColumns);
void SAL_CALL startElement(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
- void SAL_CALL endElement(const OUString &rName) override;
+
+private:
+ librevenge::RVNGPropertyListVector &m_rColumns;
};
+XMLTableColumnContext::XMLTableColumnContext(XMLImport &rImport, librevenge::RVNGPropertyListVector &rColumns)
+ : XMLImportContext(rImport),
+ m_rColumns(rColumns)
+{
+}
+
+void XMLTableColumnContext::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);
+
+ if (rAttributeName == "table:style-name")
+ FillStyles(rAttributeValue, mrImport.GetAutomaticColumnStyles(), mrImport.GetColumnStyles(), aPropertyList);
+ }
+ m_rColumns.append(aPropertyList);
+}
+
XMLTableRowContext::XMLTableRowContext(XMLImport &rImport)
: XMLImportContext(rImport)
{
@@ -87,9 +130,12 @@ XMLTableRowContext::XMLTableRowContext(XMLImport &rImport)
rtl::Reference<XMLImportContext> XMLTableRowContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/)
{
if (rName == "table:table-cell")
- return new XMLTableCellContext(mrImport);
+ return new XMLTableCellContext(mrImport, *this);
if (rName == "table:covered-table-cell")
+ {
+ ++m_nColumn;
mrImport.GetGenerator().insertCoveredTableCell(librevenge::RVNGPropertyList());
+ }
else
SAL_WARN("writerperfect", "XMLTableRowContext::CreateChildContext: unhandled " << rName);
return nullptr;
@@ -105,6 +151,16 @@ void XMLTableRowContext::endElement(const OUString &/*rName*/)
mrImport.GetGenerator().closeTableRow();
}
+int XMLTableRowContext::GetColumn() const
+{
+ return m_nColumn;
+}
+
+void XMLTableRowContext::SetColumn(int nColumn)
+{
+ m_nColumn = nColumn;
+}
+
XMLTableContext::XMLTableContext(XMLImport &rImport)
: XMLImportContext(rImport)
{
@@ -112,14 +168,30 @@ XMLTableContext::XMLTableContext(XMLImport &rImport)
rtl::Reference<XMLImportContext> XMLTableContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/)
{
+ if (rName == "table:table-column")
+ // Make sure columns are parsed before we open the table.
+ return new XMLTableColumnContext(mrImport, m_aColumns);
+
+ if (!m_bTableOpened)
+ {
+ librevenge::RVNGPropertyList aPropertyList;
+ if (!m_aColumns.empty())
+ aPropertyList.insert("librevenge:table-columns", m_aColumns);
+ mrImport.GetGenerator().openTable(aPropertyList);
+ m_bTableOpened = true;
+ }
+
if (rName == "table:table-row")
return new XMLTableRowContext(mrImport);
+
+ SAL_WARN("writerperfect", "XMLTableContext::CreateChildContext: unhandled " << rName);
+
return nullptr;
}
void XMLTableContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/)
{
- mrImport.GetGenerator().openTable(librevenge::RVNGPropertyList());
+ m_bTableOpened = false;
}
void XMLTableContext::endElement(const OUString &/*rName*/)
diff --git a/writerperfect/source/writer/exp/xmltbli.hxx b/writerperfect/source/writer/exp/xmltbli.hxx
index 07ae0a647181..8f0d06092f06 100644
--- a/writerperfect/source/writer/exp/xmltbli.hxx
+++ b/writerperfect/source/writer/exp/xmltbli.hxx
@@ -27,6 +27,10 @@ public:
void SAL_CALL startElement(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
void SAL_CALL endElement(const OUString &rName) override;
+
+private:
+ bool m_bTableOpened = false;
+ librevenge::RVNGPropertyListVector m_aColumns;
};
} // namespace exp
More information about the Libreoffice-commits
mailing list