diff options
Diffstat (limited to 'writerperfect')
-rw-r--r-- | writerperfect/Library_wpftwriter.mk | 1 | ||||
-rw-r--r-- | writerperfect/qa/unit/EPUBExportTest.cxx | 12 | ||||
-rw-r--r-- | writerperfect/qa/unit/data/writer/epubexport/footnote.fodt | 8 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/XMLFootnoteImportContext.cxx | 121 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/XMLFootnoteImportContext.hxx | 44 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/txtparai.cxx | 4 |
6 files changed, 190 insertions, 0 deletions
diff --git a/writerperfect/Library_wpftwriter.mk b/writerperfect/Library_wpftwriter.mk index bf605e718dc1..5e356304544d 100644 --- a/writerperfect/Library_wpftwriter.mk +++ b/writerperfect/Library_wpftwriter.mk @@ -78,6 +78,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/XMLFootnoteImportContext \ writerperfect/source/writer/exp/XMLSectionContext \ writerperfect/source/writer/exp/XMLTextFrameContext \ writerperfect/source/writer/exp/XMLTextListContext \ diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx index d04c2eeeaaa3..04df33257b6d 100644 --- a/writerperfect/qa/unit/EPUBExportTest.cxx +++ b/writerperfect/qa/unit/EPUBExportTest.cxx @@ -88,6 +88,7 @@ public: void testTextBox(); void testFontEmbedding(); void testImageLink(); + void testFootnote(); CPPUNIT_TEST_SUITE(EPUBExportTest); CPPUNIT_TEST(testOutlineLevel); @@ -124,6 +125,7 @@ public: CPPUNIT_TEST(testTextBox); CPPUNIT_TEST(testFontEmbedding); CPPUNIT_TEST(testImageLink); + CPPUNIT_TEST(testFootnote); CPPUNIT_TEST_SUITE_END(); }; @@ -690,6 +692,16 @@ void EPUBExportTest::testImageLink() assertXPath(mpXmlDoc, "//xhtml:p/xhtml:a/xhtml:img", 1); } +void EPUBExportTest::testFootnote() +{ + createDoc("footnote.fodt", {}); + + mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml"); + // These were missing, footnote was lost. + assertXPath(mpXmlDoc, "//xhtml:body/xhtml:p/xhtml:sup/xhtml:a", "type", "noteref"); + assertXPath(mpXmlDoc, "//xhtml:body/xhtml:aside", "type", "footnote"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest); } diff --git a/writerperfect/qa/unit/data/writer/epubexport/footnote.fodt b/writerperfect/qa/unit/data/writer/epubexport/footnote.fodt new file mode 100644 index 000000000000..a846d64ed03d --- /dev/null +++ b/writerperfect/qa/unit/data/writer/epubexport/footnote.fodt @@ -0,0 +1,8 @@ +<?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:body> + <office:text> + <text:p>before<text:note text:id="ftn0" text:note-class="footnote"><text:note-citation>1</text:note-citation><text:note-body><text:p>Footnote content</text:p></text:note-body></text:note>after</text:p> + </office:text> + </office:body> +</office:document> diff --git a/writerperfect/source/writer/exp/XMLFootnoteImportContext.cxx b/writerperfect/source/writer/exp/XMLFootnoteImportContext.cxx new file mode 100644 index 000000000000..e23f60932773 --- /dev/null +++ b/writerperfect/source/writer/exp/XMLFootnoteImportContext.cxx @@ -0,0 +1,121 @@ +/* -*- 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 "XMLFootnoteImportContext.hxx" + +#include "xmlimp.hxx" +#include "xmltext.hxx" + +using namespace com::sun::star; + +namespace writerperfect +{ +namespace exp +{ +/// Handler for <text:note-citation>. +class XMLTextNoteCitationContext : public XMLImportContext +{ +public: + XMLTextNoteCitationContext(XMLImport& rImport, librevenge::RVNGPropertyList& rProperties); + + void SAL_CALL characters(const OUString& rCharacters) override; + void SAL_CALL endElement(const OUString& rName) override; + +private: + librevenge::RVNGPropertyList& m_rProperties; + OUString m_aCharacters; +}; + +XMLTextNoteCitationContext::XMLTextNoteCitationContext(XMLImport& rImport, + librevenge::RVNGPropertyList& rProperties) + : XMLImportContext(rImport) + , m_rProperties(rProperties) +{ +} + +void XMLTextNoteCitationContext::endElement(const OUString& /*rName*/) +{ + m_rProperties.insert("librevenge:number", m_aCharacters.toUtf8().getStr()); +} + +void XMLTextNoteCitationContext::characters(const OUString& rCharacters) +{ + m_aCharacters += rCharacters; +} + +/// Handler for <text:note-body>. +class XMLFootnoteBodyImportContext : public XMLImportContext +{ +public: + XMLFootnoteBodyImportContext(XMLImport& rImport, + const librevenge::RVNGPropertyList& rProperties); + + 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: + const librevenge::RVNGPropertyList& m_rProperties; +}; + +XMLFootnoteBodyImportContext::XMLFootnoteBodyImportContext( + XMLImport& rImport, const librevenge::RVNGPropertyList& rProperties) + : XMLImportContext(rImport) + , m_rProperties(rProperties) +{ +} + +rtl::Reference<XMLImportContext> XMLFootnoteBodyImportContext::CreateChildContext( + const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) +{ + return CreateTextChildContext(mrImport, rName); +} + +void XMLFootnoteBodyImportContext::startElement( + const OUString& /*rName*/, + const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) +{ + mrImport.GetGenerator().openFootnote(m_rProperties); +} + +void XMLFootnoteBodyImportContext::endElement(const OUString& /*rName*/) +{ + mrImport.GetGenerator().closeFootnote(); +} + +XMLFootnoteImportContext::XMLFootnoteImportContext(XMLImport& rImport) + : XMLImportContext(rImport) +{ +} + +rtl::Reference<XMLImportContext> XMLFootnoteImportContext::CreateChildContext( + const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) +{ + if (rName == "text:note-citation") + return new XMLTextNoteCitationContext(mrImport, m_aProperties); + if (rName == "text:note-body") + return new XMLFootnoteBodyImportContext(mrImport, m_aProperties); + SAL_WARN("writerperfect", "XMLFootnoteImportContext::CreateChildContext: unhandled " << rName); + return nullptr; +} + +void XMLFootnoteImportContext::startElement( + const OUString& /*rName*/, + const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) +{ +} +} // namespace exp +} // namespace writerperfect + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/exp/XMLFootnoteImportContext.hxx b/writerperfect/source/writer/exp/XMLFootnoteImportContext.hxx new file mode 100644 index 000000000000..7bd221162bb9 --- /dev/null +++ b/writerperfect/source/writer/exp/XMLFootnoteImportContext.hxx @@ -0,0 +1,44 @@ +/* -*- 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_XMLFOOTNOTEIMPORTCONTEXT_HXX +#define INCLUDED_WRITERPERFECT_SOURCE_WRITER_EXP_XMLFOOTNOTEIMPORTCONTEXT_HXX + +#include <rtl/ref.hxx> + +#include "xmlictxt.hxx" + +namespace writerperfect +{ +namespace exp +{ +/// Handler for <text:note>. +class XMLFootnoteImportContext : public XMLImportContext +{ +public: + XMLFootnoteImportContext(XMLImport& rImport); + + 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; + +private: + librevenge::RVNGPropertyList m_aProperties; +}; + +} // namespace exp +} // namespace writerperfect + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/exp/txtparai.cxx b/writerperfect/source/writer/exp/txtparai.cxx index a7d899547759..bfd1b2842a83 100644 --- a/writerperfect/source/writer/exp/txtparai.cxx +++ b/writerperfect/source/writer/exp/txtparai.cxx @@ -9,6 +9,7 @@ #include "txtparai.hxx" +#include "XMLFootnoteImportContext.hxx" #include "XMLTextFrameContext.hxx" #include "xmlimp.hxx" @@ -425,6 +426,9 @@ rtl::Reference<XMLImportContext> CreateParagraphOrSpanChildContext(XMLImport &rI return new XMLTextFrameContext(rImport); if (rName == "text:sequence") return new XMLTextSequenceContext(rImport, rTextPropertyList); + if (rName == "text:note") + return new XMLFootnoteImportContext(rImport); + SAL_WARN("writerperfect", "CreateParagraphOrSpanChildContext: unhandled " << rName); return nullptr; } |