[Libreoffice-commits] core.git: writerperfect/source

Miklos Vajna vmiklos at collabora.co.uk
Mon Aug 7 09:21:10 UTC 2017


 writerperfect/source/writer/EPUBExportFilter.cxx |   14 ++++++------
 writerperfect/source/writer/EPUBPackage.cxx      |    4 +--
 writerperfect/source/writer/exp/xmlimp.cxx       |   26 +++++++++++++++++++----
 writerperfect/source/writer/exp/xmlimp.hxx       |    7 +++++-
 4 files changed, 37 insertions(+), 14 deletions(-)

New commits:
commit 7915f35d7fca5d0720d96954beaa97c00a2c3821
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Aug 7 10:09:19 2017 +0200

    EPUB export: implement doc/para open/close and text in doc handler
    
    This should be enough for plain text of multiple paragraphs, but the
    package part is still missing.
    
    Change-Id: I05fe87fd01e078262a1be9ce76eaaa016de484bf
    Reviewed-on: https://gerrit.libreoffice.org/40822
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/writerperfect/source/writer/EPUBExportFilter.cxx b/writerperfect/source/writer/EPUBExportFilter.cxx
index 75032cae6ada..2bfe9b8b0824 100644
--- a/writerperfect/source/writer/EPUBExportFilter.cxx
+++ b/writerperfect/source/writer/EPUBExportFilter.cxx
@@ -9,6 +9,8 @@
 
 #include "EPUBExportFilter.hxx"
 
+#include <libepubgen/EPUBTextGenerator.h>
+
 #include <com/sun/star/lang/XInitialization.hpp>
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
@@ -30,16 +32,14 @@ EPUBExportFilter::EPUBExportFilter(const uno::Reference<uno::XComponentContext>
 
 sal_Bool EPUBExportFilter::filter(const uno::Sequence<beans::PropertyValue> &rDescriptor)
 {
-    // The package writes to the output file.
+    // Build the export filter chain: the package has direct access to the ZIP
+    // file, the flat ODF filter has access to the doc model, everything else
+    // is in-between.
     EPUBPackage aPackage(mxContext, rDescriptor);
+    libepubgen::EPUBTextGenerator aGenerator(&aPackage);
+    uno::Reference<xml::sax::XDocumentHandler> xExportHandler(new exp::XMLImport(aGenerator));
 
-    // Create ODT exporter, this will feed our document handler.
     uno::Reference<lang::XInitialization> xInitialization(mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.comp.Writer.XMLOasisExporter", mxContext), uno::UNO_QUERY);
-
-    // The document handler will make the calls on the text interface provided by the EPUB export.
-    uno::Reference<xml::sax::XDocumentHandler> xExportHandler(new exp::XMLImport);
-
-    // Let the ODT exporter read the doc model and invoke the doc handler.
     xInitialization->initialize({uno::makeAny(xExportHandler)});
     uno::Reference<document::XExporter> xExporter(xInitialization, uno::UNO_QUERY);
     xExporter->setSourceDocument(mxSourceDocument);
diff --git a/writerperfect/source/writer/EPUBPackage.cxx b/writerperfect/source/writer/EPUBPackage.cxx
index 0296b183327c..54300c2fbf0a 100644
--- a/writerperfect/source/writer/EPUBPackage.cxx
+++ b/writerperfect/source/writer/EPUBPackage.cxx
@@ -38,9 +38,9 @@ void EPUBPackage::closeElement(const char *pName)
     SAL_WARN("writerperfect", "EPUBPackage::closeElement, " << pName << ": implement me");
 }
 
-void EPUBPackage::insertCharacters(const librevenge::RVNGString &/*rCharacters*/)
+void EPUBPackage::insertCharacters(const librevenge::RVNGString &rCharacters)
 {
-    SAL_WARN("writerperfect", "EPUBPackage::insertCharacters: implement me");
+    SAL_WARN("writerperfect", "EPUBPackage::insertCharacters, " << rCharacters.cstr() << ": implement me");
 }
 
 void EPUBPackage::closeXMLFile()
diff --git a/writerperfect/source/writer/exp/xmlimp.cxx b/writerperfect/source/writer/exp/xmlimp.cxx
index 1c915857413e..21c4809ffc57 100644
--- a/writerperfect/source/writer/exp/xmlimp.cxx
+++ b/writerperfect/source/writer/exp/xmlimp.cxx
@@ -16,28 +16,46 @@ namespace writerperfect
 namespace exp
 {
 
-XMLImport::XMLImport()
+XMLImport::XMLImport(librevenge::RVNGTextInterface &rGenerator)
+    : mrGenerator(rGenerator)
 {
 }
 
 void XMLImport::startDocument()
 {
+    mrGenerator.startDocument(librevenge::RVNGPropertyList());
 }
 
 void XMLImport::endDocument()
 {
+    mrGenerator.endDocument();
 }
 
-void XMLImport::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/)
+void XMLImport::startElement(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/)
 {
+    if (rName == "text:p")
+    {
+        mrGenerator.openParagraph(librevenge::RVNGPropertyList());
+        mbParagraphOpened = true;
+    }
 }
 
-void XMLImport::endElement(const OUString &/*rName*/)
+void XMLImport::endElement(const OUString &rName)
 {
+    if (rName == "text:p")
+    {
+        mrGenerator.closeParagraph();
+        mbParagraphOpened = false;
+    }
 }
 
-void XMLImport::characters(const OUString &/*rChars*/)
+void XMLImport::characters(const OUString &rChars)
 {
+    if (mbParagraphOpened)
+    {
+        OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8);
+        mrGenerator.insertText(librevenge::RVNGString(sCharU8.getStr()));
+    }
 }
 
 void XMLImport::ignorableWhitespace(const OUString &/*rWhitespaces*/)
diff --git a/writerperfect/source/writer/exp/xmlimp.hxx b/writerperfect/source/writer/exp/xmlimp.hxx
index 9d6d1eb4c0c6..2b1c743fcf03 100644
--- a/writerperfect/source/writer/exp/xmlimp.hxx
+++ b/writerperfect/source/writer/exp/xmlimp.hxx
@@ -12,6 +12,8 @@
 
 #include <cppuhelper/implbase.hxx>
 
+#include <librevenge/librevenge.h>
+
 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
 
 namespace writerperfect
@@ -25,8 +27,11 @@ class XMLImport : public cppu::WeakImplHelper
     css::xml::sax::XDocumentHandler
     >
 {
+    librevenge::RVNGTextInterface &mrGenerator;
+    bool mbParagraphOpened = false;
+
 public:
-    XMLImport();
+    XMLImport(librevenge::RVNGTextInterface &rGenerator);
 
     // XDocumentHandler
     void SAL_CALL startDocument() override;


More information about the Libreoffice-commits mailing list