diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-11-24 09:14:05 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-11-24 14:06:22 +0100 |
commit | 8b8aa6bc010fffbcd47679aa101075d702741f69 (patch) | |
tree | 2a18d605cfbd0a5240949619dd19513345286fd7 /writerperfect/qa | |
parent | ed0e7262f859adabc56a4f251f2ef1a66c98c3f5 (diff) |
EPUB export: handle total table width
This is important when e.g. the col width are 50-50%, then without
explicit total table width the table width won't be correct.
Change-Id: I5ccd6dfb5b78c564485d54cda62e12f3d1ca36c1
Reviewed-on: https://gerrit.libreoffice.org/45204
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'writerperfect/qa')
-rw-r--r-- | writerperfect/qa/unit/EPUBExportTest.cxx | 39 | ||||
-rw-r--r-- | writerperfect/qa/unit/data/writer/epubexport/table-width.fodt | 28 |
2 files changed, 52 insertions, 15 deletions
diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx index 49ef7297fa80..5f74ef71ea59 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. - static void parseCssStyle(const OUString &rStyle, std::map<OUString, OUString> &rCss); + static std::map<OUString, OUString> parseCssStyle(const OUString &rStyle); void testOutlineLevel(); void testMimetype(); void testEPUB2(); @@ -81,6 +81,7 @@ public: void testLink(); void testLinkCharFormat(); void testLinkNamedCharFormat(); + void testTableWidth(); CPPUNIT_TEST_SUITE(EPUBExportTest); CPPUNIT_TEST(testOutlineLevel); @@ -108,6 +109,7 @@ public: CPPUNIT_TEST(testLink); CPPUNIT_TEST(testLinkCharFormat); CPPUNIT_TEST(testLinkNamedCharFormat); + CPPUNIT_TEST(testTableWidth); CPPUNIT_TEST_SUITE_END(); }; @@ -192,15 +194,19 @@ void EPUBExportTest::parseCssExport(const OUString &rName, std::map< OString, st } } -void EPUBExportTest::parseCssStyle(const OUString &rStyle, std::map<OUString, OUString> &rCss) +std::map<OUString, OUString> EPUBExportTest::parseCssStyle(const OUString &rStyle) { + std::map<OUString, OUString> aCss; + for (const auto &rKeyValue : comphelper::string::split(rStyle, ';')) { OUString aKeyValue = rKeyValue.trim(); std::vector<OUString> aTokens = comphelper::string::split(aKeyValue, ':'); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aTokens.size()); - rCss[aTokens[0].trim()] = aTokens[1].trim(); + aCss[aTokens[0].trim()] = aTokens[1].trim(); } + + return aCss; } void EPUBExportTest::testOutlineLevel() @@ -498,26 +504,20 @@ void EPUBExportTest::testTableCellBorder() mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml"); OUString aStyle = getXPath(mpXmlDoc, "//xhtml:table/xhtml:tbody/xhtml:tr[1]/xhtml:td[1]", "style"); - std::map<OUString, OUString> aCss; - parseCssStyle(aStyle, aCss); // This failed, cell border wasn't exported. - CPPUNIT_ASSERT_EQUAL(OUString("0.05pt solid #000000"), aCss["border-left"]); + CPPUNIT_ASSERT_EQUAL(OUString("0.05pt solid #000000"), EPUBExportTest::parseCssStyle(aStyle)["border-left"]); } namespace { double getCellWidth(const OUString &rStyle) { - std::map<OUString, OUString> aCss; - EPUBExportTest::parseCssStyle(rStyle, aCss); - return aCss["width"].toDouble(); + return EPUBExportTest::parseCssStyle(rStyle)["width"].toDouble(); } double getRowHeight(const OUString &rStyle) { - std::map<OUString, OUString> aCss; - EPUBExportTest::parseCssStyle(rStyle, aCss); - return aCss["height"].toDouble(); + return EPUBExportTest::parseCssStyle(rStyle)["height"].toDouble(); } } @@ -575,9 +575,18 @@ void EPUBExportTest::testLinkNamedCharFormat() assertXPath(mpXmlDoc, "//xhtml:p/xhtml:a", "href", "http://libreoffice.org/"); OUString aStyle = getXPath(mpXmlDoc, "//xhtml:p/xhtml:a/xhtml:span", "style"); - std::map<OUString, OUString> aCss; - parseCssStyle(aStyle, aCss); - CPPUNIT_ASSERT_EQUAL(OUString("#ff0000"), aCss["color"]); + CPPUNIT_ASSERT_EQUAL(OUString("#ff0000"), EPUBExportTest::parseCssStyle(aStyle)["color"]); +} + +void EPUBExportTest::testTableWidth() +{ + createDoc("table-width.fodt", {}); + + mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml"); + + OUString aStyle = getXPath(mpXmlDoc, "//xhtml:table", "style"); + // This failed, relative total width of table was lost. + CPPUNIT_ASSERT_EQUAL(OUString("50%"), EPUBExportTest::parseCssStyle(aStyle)["width"]); } CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest); diff --git a/writerperfect/qa/unit/data/writer/epubexport/table-width.fodt b/writerperfect/qa/unit/data/writer/epubexport/table-width.fodt new file mode 100644 index 000000000000..17793628df0a --- /dev/null +++ b/writerperfect/qa/unit/data/writer/epubexport/table-width.fodt @@ -0,0 +1,28 @@ +<?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="8.795cm" style:rel-width="50%" table:align="left"/> + </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="4986*"/> + </style:style> + <style:style style:name="Table1.A1" style:family="table-cell"> + <style:table-cell-properties fo:padding="0.097cm" fo:border="0.05pt 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-row> + <table:table-cell table:style-name="Table1.A1" office:value-type="string"> + <text:p>In table</text:p> + </table:table-cell> + </table:table-row> + </table:table> + <text:p>After</text:p> + </office:text> + </office:body> +</office:document> |