diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-08-17 18:03:53 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-08-17 20:30:11 +0200 |
commit | 28102e471d3cb6b6976380ca84b1094078ac1af1 (patch) | |
tree | 12cefdf9b5c7b726b17643eb29e376ea06d840c1 /writerperfect/source | |
parent | dc9d435f6fcfe413c5891aac8d1fe236ee11ccb6 (diff) |
EPUB export: handle inline images
Just the bare minimum, so that the binary file-related member functions
of the package interface are triggered, so I can implement them.
Change-Id: I996659126667423fded1f89f8097ac726418fa00
Reviewed-on: https://gerrit.libreoffice.org/41261
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'writerperfect/source')
6 files changed, 256 insertions, 4 deletions
diff --git a/writerperfect/source/writer/EPUBPackage.cxx b/writerperfect/source/writer/EPUBPackage.cxx index 7818f584b76f..3a33dedac3eb 100644 --- a/writerperfect/source/writer/EPUBPackage.cxx +++ b/writerperfect/source/writer/EPUBPackage.cxx @@ -140,17 +140,30 @@ void EPUBPackage::closeCSSFile() void EPUBPackage::openBinaryFile(const char *pName) { - SAL_WARN("writerperfect", "EPUBPackage::openBinaryFile, " << pName << ": implement me"); + assert(pName); + assert(!mxOutputStream.is()); + + mxOutputStream.set(mxStorage->openStreamElementByHierarchicalName(OUString::fromUtf8(pName), embed::ElementModes::READWRITE), uno::UNO_QUERY); } -void EPUBPackage::insertBinaryData(const librevenge::RVNGBinaryData &/*rData*/) +void EPUBPackage::insertBinaryData(const librevenge::RVNGBinaryData &rData) { - SAL_WARN("writerperfect", "EPUBPackage::insertBinaryData: implement me"); + assert(mxOutputStream.is()); + + if (rData.empty()) + return; + + uno::Sequence<sal_Int8> aData(reinterpret_cast<const sal_Int8 *>(rData.getDataBuffer()), rData.size()); + mxOutputStream->writeBytes(aData); } void EPUBPackage::closeBinaryFile() { - SAL_WARN("writerperfect", "EPUBPackage::closeBinaryFile: implement me"); + assert(mxOutputStream.is()); + + uno::Reference<embed::XTransactedObject> xTransactedObject(mxOutputStream, uno::UNO_QUERY); + xTransactedObject->commit(); + mxOutputStream.clear(); } void EPUBPackage::openTextFile(const char *pName) diff --git a/writerperfect/source/writer/exp/XMLBase64ImportContext.cxx b/writerperfect/source/writer/exp/XMLBase64ImportContext.cxx new file mode 100644 index 000000000000..c073d8fc19bd --- /dev/null +++ b/writerperfect/source/writer/exp/XMLBase64ImportContext.cxx @@ -0,0 +1,46 @@ +/* -*- 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 "XMLBase64ImportContext.hxx" + +using namespace com::sun::star; + +namespace writerperfect +{ +namespace exp +{ + +XMLBase64ImportContext::XMLBase64ImportContext(XMLImport &rImport) + : XMLImportContext(rImport) +{ +} + +void XMLBase64ImportContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) +{ +} + +void XMLBase64ImportContext::endElement(const OUString &/*rName*/) +{ +} + +void XMLBase64ImportContext::characters(const OUString &rChars) +{ + OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8); + m_aBinaryData.appendBase64Data(librevenge::RVNGString(sCharU8.getStr())); +} + +const librevenge::RVNGBinaryData &XMLBase64ImportContext::getBinaryData() const +{ + return m_aBinaryData; +} + +} // namespace exp +} // namespace writerperfect + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/exp/XMLBase64ImportContext.hxx b/writerperfect/source/writer/exp/XMLBase64ImportContext.hxx new file mode 100644 index 000000000000..f60122b61382 --- /dev/null +++ b/writerperfect/source/writer/exp/XMLBase64ImportContext.hxx @@ -0,0 +1,43 @@ +/* -*- 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_XMLBASE64IMPORTCONTEXT_HXX +#define INCLUDED_WRITERPERFECT_SOURCE_WRITER_EXP_XMLBASE64IMPORTCONTEXT_HXX + +#include <librevenge/RVNGBinaryData.h> + +#include "xmlictxt.hxx" + +namespace writerperfect +{ +namespace exp +{ + +/// Handler for <office:binary-data>. +class XMLBase64ImportContext : public XMLImportContext +{ +public: + XMLBase64ImportContext(XMLImport &rImport); + + 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; + void SAL_CALL characters(const OUString &rChars) override; + + const librevenge::RVNGBinaryData &getBinaryData() const; + +private: + librevenge::RVNGBinaryData m_aBinaryData; +}; + +} // namespace exp +} // namespace writerperfect + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/exp/XMLTextFrameContext.cxx b/writerperfect/source/writer/exp/XMLTextFrameContext.cxx new file mode 100644 index 000000000000..60cbe2d21263 --- /dev/null +++ b/writerperfect/source/writer/exp/XMLTextFrameContext.cxx @@ -0,0 +1,99 @@ +/* -*- 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 "XMLTextFrameContext.hxx" + +#include "XMLBase64ImportContext.hxx" +#include "xmlimp.hxx" + +using namespace com::sun::star; + +namespace writerperfect +{ +namespace exp +{ + +/// Handler for <draw:image>. +class XMLTextImageContext : public XMLImportContext +{ +public: + XMLTextImageContext(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; + +private: + OString m_aMimeType; + rtl::Reference<XMLBase64ImportContext> m_xBinaryData; +}; + +XMLTextImageContext::XMLTextImageContext(XMLImport &rImport) + : XMLImportContext(rImport) +{ +} + +XMLImportContext *XMLTextImageContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) +{ + if (rName == "office:binary-data") + { + m_xBinaryData = new XMLBase64ImportContext(mrImport); + return m_xBinaryData.get(); + } + return nullptr; +} + +void XMLTextImageContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) +{ + for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i) + { + const OUString &rAttributeName = xAttribs->getNameByIndex(i); + if (rAttributeName == "loext:mime-type") + m_aMimeType = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8); + } +} + +void XMLTextImageContext::endElement(const OUString &/*rName*/) +{ + librevenge::RVNGPropertyList aPropertyList; + + aPropertyList.insert("librevenge:mime-type", m_aMimeType.getStr()); + if (m_xBinaryData.is()) + aPropertyList.insert("office:binary-data", m_xBinaryData->getBinaryData()); + + mrImport.GetGenerator().insertBinaryObject(aPropertyList); +} + +XMLTextFrameContext::XMLTextFrameContext(XMLImport &rImport) + : XMLImportContext(rImport) +{ +} + +XMLImportContext *XMLTextFrameContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) +{ + if (rName == "draw:image") + return new XMLTextImageContext(mrImport); + return nullptr; +} + +void XMLTextFrameContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) +{ + mrImport.GetGenerator().openFrame(librevenge::RVNGPropertyList()); +} + +void XMLTextFrameContext::endElement(const OUString &/*rName*/) +{ + mrImport.GetGenerator().closeFrame(); +} + +} // namespace exp +} // namespace writerperfect + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/exp/XMLTextFrameContext.hxx b/writerperfect/source/writer/exp/XMLTextFrameContext.hxx new file mode 100644 index 000000000000..2cf14889df05 --- /dev/null +++ b/writerperfect/source/writer/exp/XMLTextFrameContext.hxx @@ -0,0 +1,41 @@ +/* -*- 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_XMLTEXTFRAMECONTEXT_HXX +#define INCLUDED_WRITERPERFECT_SOURCE_WRITER_EXP_XMLTEXTFRAMECONTEXT_HXX + +#include <rtl/ref.hxx> + +#include "xmlictxt.hxx" + +namespace writerperfect +{ +namespace exp +{ + +class XMLBase64ImportContext; + +/// Handler for <draw:frame>. +class XMLTextFrameContext : public XMLImportContext +{ +public: + XMLTextFrameContext(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/txtparai.cxx b/writerperfect/source/writer/exp/txtparai.cxx index 72cc401ceb91..600709d9fec8 100644 --- a/writerperfect/source/writer/exp/txtparai.cxx +++ b/writerperfect/source/writer/exp/txtparai.cxx @@ -9,6 +9,7 @@ #include "txtparai.hxx" +#include "XMLTextFrameContext.hxx" #include "xmlimp.hxx" using namespace com::sun::star; @@ -24,6 +25,8 @@ class XMLSpanContext : public XMLImportContext public: XMLSpanContext(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; void SAL_CALL characters(const OUString &rChars) override; @@ -34,6 +37,13 @@ XMLSpanContext::XMLSpanContext(XMLImport &rImport) { } +XMLImportContext *XMLSpanContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) +{ + if (rName == "draw:frame") + return new XMLTextFrameContext(mrImport); + return nullptr; +} + void XMLSpanContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) { mrImport.GetGenerator().openSpan(librevenge::RVNGPropertyList()); |