diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-09-08 15:39:14 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-09-08 19:19:23 +0200 |
commit | 6e260dbebc91f137d6f797dd10d64e53a063dc0b (patch) | |
tree | a0c74c73b2df4b47e51dece0b17ddede0d4d98fc | |
parent | 1079893be5593268eff0867be87b0291546d88c7 (diff) |
EPUB export: handle section content
Just the minimum so content is not completely ignored on export.
Change-Id: I2880780ed3ce5d1dd15adbd9222296f52a5e7c3d
Reviewed-on: https://gerrit.libreoffice.org/42115
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r-- | writerperfect/Library_wpftwriter.mk | 1 | ||||
-rw-r--r-- | writerperfect/qa/unit/EPUBExportTest.cxx | 11 | ||||
-rw-r--r-- | writerperfect/qa/unit/data/writer/epubexport/section.fodt | 12 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/XMLSectionContext.cxx | 45 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/XMLSectionContext.hxx | 36 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/xmltbli.cxx | 7 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/xmltext.cxx | 12 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/xmltext.hxx | 3 |
8 files changed, 120 insertions, 7 deletions
diff --git a/writerperfect/Library_wpftwriter.mk b/writerperfect/Library_wpftwriter.mk index 67c1d999f887..826ffe600e12 100644 --- a/writerperfect/Library_wpftwriter.mk +++ b/writerperfect/Library_wpftwriter.mk @@ -76,6 +76,7 @@ $(eval $(call gb_Library_add_exception_objects,wpftwriter,\ writerperfect/source/writer/StarOfficeWriterImportFilter \ writerperfect/source/writer/WordPerfectImportFilter \ writerperfect/source/writer/exp/XMLBase64ImportContext \ + writerperfect/source/writer/exp/XMLSectionContext \ writerperfect/source/writer/exp/XMLTextFrameContext \ writerperfect/source/writer/exp/txtparai \ writerperfect/source/writer/exp/txtstyli \ diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx index 06278d19eb81..706536c9423a 100644 --- a/writerperfect/qa/unit/EPUBExportTest.cxx +++ b/writerperfect/qa/unit/EPUBExportTest.cxx @@ -65,6 +65,7 @@ public: void testLineBreak(); void testEscape(); void testParaCharProps(); + void testSection(); CPPUNIT_TEST_SUITE(EPUBExportTest); CPPUNIT_TEST(testOutlineLevel); @@ -81,6 +82,7 @@ public: CPPUNIT_TEST(testLineBreak); CPPUNIT_TEST(testEscape); CPPUNIT_TEST(testParaCharProps); + CPPUNIT_TEST(testSection); CPPUNIT_TEST_SUITE_END(); }; @@ -362,6 +364,15 @@ void EPUBExportTest::testParaCharProps() assertCss(aCssDoc, aMiddle, " font-weight: bold;"); } +void EPUBExportTest::testSection() +{ + createDoc("section.fodt", {}); + + mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml"); + // This was "After.", i.e. in-section content was ignored. + assertXPathContent(mpXmlDoc, "//xhtml:p[2]/xhtml:span", "In section."); +} + CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest); } diff --git a/writerperfect/qa/unit/data/writer/epubexport/section.fodt b/writerperfect/qa/unit/data/writer/epubexport/section.fodt new file mode 100644 index 000000000000..84fb6d2ae940 --- /dev/null +++ b/writerperfect/qa/unit/data/writer/epubexport/section.fodt @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:body> + <office:text> + <text:p>Before.</text:p> + <text:section text:name="Section1"> + <text:p>In section.</text:p> + </text:section> + <text:p>After.</text:p> + </office:text> + </office:body> +</office:document> diff --git a/writerperfect/source/writer/exp/XMLSectionContext.cxx b/writerperfect/source/writer/exp/XMLSectionContext.cxx new file mode 100644 index 000000000000..ba6e1a7944f7 --- /dev/null +++ b/writerperfect/source/writer/exp/XMLSectionContext.cxx @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "XMLSectionContext.hxx" + +#include "xmlimp.hxx" +#include "xmltext.hxx" + +using namespace com::sun::star; + +namespace writerperfect +{ +namespace exp +{ + +XMLSectionContext::XMLSectionContext(XMLImport &rImport) + : XMLImportContext(rImport) +{ +} + +XMLImportContext *XMLSectionContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) +{ + return CreateTextChildContext(mrImport, rName); +} + +void XMLSectionContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) +{ + mrImport.GetGenerator().openSection(librevenge::RVNGPropertyList()); +} + +void XMLSectionContext::endElement(const OUString &/*rName*/) +{ + mrImport.GetGenerator().closeSection(); +} + +} // namespace exp +} // namespace writerperfect + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/exp/XMLSectionContext.hxx b/writerperfect/source/writer/exp/XMLSectionContext.hxx new file mode 100644 index 000000000000..5aa49a444a9a --- /dev/null +++ b/writerperfect/source/writer/exp/XMLSectionContext.hxx @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERPERFECT_SOURCE_WRITER_EXP_XMLSECTIONCONTEXT_HXX +#define INCLUDED_WRITERPERFECT_SOURCE_WRITER_EXP_XMLSECTIONCONTEXT_HXX + +#include "xmlictxt.hxx" + +namespace writerperfect +{ +namespace exp +{ + +/// Handler for <text:section>. +class XMLSectionContext : public XMLImportContext +{ +public: + XMLSectionContext(XMLImport &rImport); + + 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; +}; + +} // namespace exp +} // namespace writerperfect + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/exp/xmltbli.cxx b/writerperfect/source/writer/exp/xmltbli.cxx index bcdc4cb46220..735e276de241 100644 --- a/writerperfect/source/writer/exp/xmltbli.cxx +++ b/writerperfect/source/writer/exp/xmltbli.cxx @@ -11,6 +11,7 @@ #include "txtparai.hxx" #include "xmlimp.hxx" +#include "xmltext.hxx" using namespace com::sun::star; @@ -38,11 +39,7 @@ XMLTableCellContext::XMLTableCellContext(XMLImport &rImport) XMLImportContext *XMLTableCellContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) { - if (rName == "text:p" || rName == "text:h") - return new XMLParaContext(mrImport); - if (rName == "table:table") - return new XMLTableContext(mrImport); - return nullptr; + return CreateTextChildContext(mrImport, rName); } void XMLTableCellContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) diff --git a/writerperfect/source/writer/exp/xmltext.cxx b/writerperfect/source/writer/exp/xmltext.cxx index f2e47c18ecff..73a6f5e73465 100644 --- a/writerperfect/source/writer/exp/xmltext.cxx +++ b/writerperfect/source/writer/exp/xmltext.cxx @@ -11,6 +11,7 @@ #include "txtparai.hxx" #include "xmltbli.hxx" +#include "XMLSectionContext.hxx" using namespace com::sun::star; @@ -26,10 +27,17 @@ XMLBodyContentContext::XMLBodyContentContext(XMLImport &rImport) XMLImportContext *XMLBodyContentContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) { + return CreateTextChildContext(mrImport, rName); +} + +XMLImportContext *CreateTextChildContext(XMLImport &rImport, const OUString &rName) +{ if (rName == "text:p" || rName == "text:h") - return new XMLParaContext(mrImport); + return new XMLParaContext(rImport); + if (rName == "text:section") + return new XMLSectionContext(rImport); if (rName == "table:table") - return new XMLTableContext(mrImport); + return new XMLTableContext(rImport); return nullptr; } diff --git a/writerperfect/source/writer/exp/xmltext.hxx b/writerperfect/source/writer/exp/xmltext.hxx index aa82aeb00122..dc8f35f33fbd 100644 --- a/writerperfect/source/writer/exp/xmltext.hxx +++ b/writerperfect/source/writer/exp/xmltext.hxx @@ -26,6 +26,9 @@ public: XMLImportContext *CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) override; }; +/// Context factory for body text, section, table cell, etc. +XMLImportContext *CreateTextChildContext(XMLImport &rImport, const OUString &rName); + } // namespace exp } // namespace writerperfect |