diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-08-25 16:12:03 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-08-25 17:46:01 +0200 |
commit | bb4e52096db668533bae40f5155749a9986108a2 (patch) | |
tree | 0a74e2a14db6efe469ab4dbba2e10169c6971a8e /writerperfect | |
parent | 8e246b5cccadbac1e6d6c39fcd2a872727683f75 (diff) |
EPUB export: add support for page breaks
EPUB_SPLIT_METHOD is still hardcoded to HEADING, so while we send the
page break info to librevenge now, it's ignored on that end.
This requies basic infrastructure for automatic styles.
Change-Id: Ibafead0dedd9dbfa6223a9c701a62611ba2671fd
Reviewed-on: https://gerrit.libreoffice.org/41573
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'writerperfect')
-rw-r--r-- | writerperfect/Library_wpftwriter.mk | 2 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/txtparai.cxx | 17 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/txtstyli.cxx | 90 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/txtstyli.hxx | 44 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/xmlfmt.cxx | 37 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/xmlfmt.hxx | 36 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/xmlimp.cxx | 8 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/xmlimp.hxx | 4 |
8 files changed, 235 insertions, 3 deletions
diff --git a/writerperfect/Library_wpftwriter.mk b/writerperfect/Library_wpftwriter.mk index 9cbef7f31309..67c1d999f887 100644 --- a/writerperfect/Library_wpftwriter.mk +++ b/writerperfect/Library_wpftwriter.mk @@ -78,6 +78,8 @@ $(eval $(call gb_Library_add_exception_objects,wpftwriter,\ writerperfect/source/writer/exp/XMLBase64ImportContext \ writerperfect/source/writer/exp/XMLTextFrameContext \ writerperfect/source/writer/exp/txtparai \ + writerperfect/source/writer/exp/txtstyli \ + writerperfect/source/writer/exp/xmlfmt \ writerperfect/source/writer/exp/xmlictxt \ writerperfect/source/writer/exp/xmlimp \ writerperfect/source/writer/exp/xmlmetai \ diff --git a/writerperfect/source/writer/exp/txtparai.cxx b/writerperfect/source/writer/exp/txtparai.cxx index 600709d9fec8..e669cf89edf8 100644 --- a/writerperfect/source/writer/exp/txtparai.cxx +++ b/writerperfect/source/writer/exp/txtparai.cxx @@ -124,10 +124,23 @@ void XMLParaContext::startElement(const OUString &/*rName*/, const css::uno::Ref for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i) { const OUString &rAttributeName = xAttribs->getNameByIndex(i); - if (rAttributeName != "text:style-name") + const OUString &rAttributeValue = xAttribs->getValueByIndex(i); + if (rAttributeName == "text:style-name") + { + // Reference to an automatic style, try to look it up. + auto itStyle = mrImport.GetAutomaticStyles().find(rAttributeValue); + if (itStyle == mrImport.GetAutomaticStyles().end()) + continue; + + // Apply properties directly, librevenge has no notion of automatic styles. + librevenge::RVNGPropertyList::Iter itProp(itStyle->second); + for (itProp.rewind(); itProp.next();) + aPropertyList.insert(itProp.key(), itProp()); + } + else { OString sName = OUStringToOString(rAttributeName, RTL_TEXTENCODING_UTF8); - OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8); + OString sValue = OUStringToOString(rAttributeValue, RTL_TEXTENCODING_UTF8); aPropertyList.insert(sName.getStr(), sValue.getStr()); } } diff --git a/writerperfect/source/writer/exp/txtstyli.cxx b/writerperfect/source/writer/exp/txtstyli.cxx new file mode 100644 index 000000000000..a7460a47c1b6 --- /dev/null +++ b/writerperfect/source/writer/exp/txtstyli.cxx @@ -0,0 +1,90 @@ +/* -*- 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 "txtstyli.hxx" + +#include "xmlimp.hxx" + +using namespace com::sun::star; + +namespace writerperfect +{ +namespace exp +{ + +/// Handler for <style:paragraph-properties>. +class XMLParagraphPropertiesContext : public XMLImportContext +{ +public: + XMLParagraphPropertiesContext(XMLImport &rImport, XMLStyleContext &rStyle); + + void SAL_CALL startElement(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override; + +private: + XMLStyleContext &mrStyle; +}; + +XMLParagraphPropertiesContext::XMLParagraphPropertiesContext(XMLImport &rImport, XMLStyleContext &rStyle) + : XMLImportContext(rImport) + , mrStyle(rStyle) +{ +} + +void XMLParagraphPropertiesContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) +{ + for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i) + { + OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8); + OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8); + mrStyle.GetPropertyList().insert(sName.getStr(), sValue.getStr()); + } +} + +XMLStyleContext::XMLStyleContext(XMLImport &rImport) + : XMLImportContext(rImport) +{ +} + +XMLImportContext *XMLStyleContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) +{ + if (rName == "style:paragraph-properties") + return new XMLParagraphPropertiesContext(mrImport, *this); + return nullptr; +} + +void XMLStyleContext::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 == "style:name") + { + m_aName = xAttribs->getValueByIndex(i); + break; + } + } +} + +void XMLStyleContext::endElement(const OUString &/*rName*/) +{ + if (m_aName.isEmpty()) + return; + + mrImport.GetAutomaticStyles()[m_aName] = m_aPropertyList; +} + +librevenge::RVNGPropertyList &XMLStyleContext::GetPropertyList() +{ + return m_aPropertyList; +} + +} // namespace exp +} // namespace writerperfect + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/exp/txtstyli.hxx b/writerperfect/source/writer/exp/txtstyli.hxx new file mode 100644 index 000000000000..89d3483b7ba7 --- /dev/null +++ b/writerperfect/source/writer/exp/txtstyli.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_TXTSTYLI_HXX +#define INCLUDED_WRITERPERFECT_SOURCE_WRITER_EXP_TXTSTYLI_HXX + +#include <librevenge/librevenge.h> + +#include "xmlictxt.hxx" + +namespace writerperfect +{ +namespace exp +{ + +/// Handler for <style:style>. +class XMLStyleContext : public XMLImportContext +{ +public: + XMLStyleContext(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; + + librevenge::RVNGPropertyList &GetPropertyList(); + +private: + OUString m_aName; + librevenge::RVNGPropertyList m_aPropertyList; +}; + +} // namespace exp +} // namespace writerperfect + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/exp/xmlfmt.cxx b/writerperfect/source/writer/exp/xmlfmt.cxx new file mode 100644 index 000000000000..64fe313e2f08 --- /dev/null +++ b/writerperfect/source/writer/exp/xmlfmt.cxx @@ -0,0 +1,37 @@ +/* -*- 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 "xmlfmt.hxx" + +#include "txtstyli.hxx" +#include "xmlimp.hxx" + +using namespace com::sun::star; + +namespace writerperfect +{ +namespace exp +{ + +XMLAutomaticStylesContext::XMLAutomaticStylesContext(XMLImport &rImport) + : XMLImportContext(rImport) +{ +} + +XMLImportContext *XMLAutomaticStylesContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) +{ + if (rName == "style:style") + return new XMLStyleContext(mrImport); + return nullptr; +} + +} // namespace exp +} // namespace writerperfect + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/exp/xmlfmt.hxx b/writerperfect/source/writer/exp/xmlfmt.hxx new file mode 100644 index 000000000000..1ace95bc36a7 --- /dev/null +++ b/writerperfect/source/writer/exp/xmlfmt.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_XMLFMT_HXX +#define INCLUDED_WRITERPERFECT_SOURCE_WRITER_EXP_XMLFMT_HXX + +#include <librevenge/librevenge.h> + +#include "xmlictxt.hxx" + +namespace writerperfect +{ +namespace exp +{ + +/// Handler for <office:automatic-styles>. +class XMLAutomaticStylesContext : public XMLImportContext +{ +public: + XMLAutomaticStylesContext(XMLImport &rImport); + + XMLImportContext *CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override; +}; + +} // namespace exp +} // namespace writerperfect + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/exp/xmlimp.cxx b/writerperfect/source/writer/exp/xmlimp.cxx index 1b2365e16f5e..2fa46cdad98f 100644 --- a/writerperfect/source/writer/exp/xmlimp.cxx +++ b/writerperfect/source/writer/exp/xmlimp.cxx @@ -9,6 +9,7 @@ #include "xmlimp.hxx" +#include "xmlfmt.hxx" #include "xmlictxt.hxx" #include "xmlmetai.hxx" #include "xmltext.hxx" @@ -61,6 +62,8 @@ XMLImportContext *XMLOfficeDocContext::CreateChildContext(const OUString &rName, return new XMLBodyContext(mrImport); else if (rName == "office:meta") return new XMLMetaDocumentContext(mrImport); + else if (rName == "office:automatic-styles") + return new XMLAutomaticStylesContext(mrImport); return nullptr; } @@ -81,6 +84,11 @@ librevenge::RVNGTextInterface &XMLImport::GetGenerator() const return mrGenerator; } +std::map<OUString, librevenge::RVNGPropertyList> &XMLImport::GetAutomaticStyles() +{ + return maAutomaticStyles; +} + void XMLImport::startDocument() { mrGenerator.startDocument(librevenge::RVNGPropertyList()); diff --git a/writerperfect/source/writer/exp/xmlimp.hxx b/writerperfect/source/writer/exp/xmlimp.hxx index 6e6cc8c82491..5ba8d37c73aa 100644 --- a/writerperfect/source/writer/exp/xmlimp.hxx +++ b/writerperfect/source/writer/exp/xmlimp.hxx @@ -10,7 +10,7 @@ #ifndef INCLUDED_WRITERPERFECT_SOURCE_WRITER_EXP_XMLIMP_HXX #define INCLUDED_WRITERPERFECT_SOURCE_WRITER_EXP_XMLIMP_HXX -#include <memory> +#include <map> #include <stack> #include <librevenge/librevenge.h> @@ -35,6 +35,7 @@ class XMLImport : public cppu::WeakImplHelper { librevenge::RVNGTextInterface &mrGenerator; std::stack< rtl::Reference<XMLImportContext> > maContexts; + std::map<OUString, librevenge::RVNGPropertyList> maAutomaticStyles; public: XMLImport(librevenge::RVNGTextInterface &rGenerator); @@ -42,6 +43,7 @@ public: XMLImportContext *CreateContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs); librevenge::RVNGTextInterface &GetGenerator() const; + std::map<OUString, librevenge::RVNGPropertyList> &GetAutomaticStyles(); // XDocumentHandler void SAL_CALL startDocument() override; |