diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-08-29 13:39:23 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-08-29 16:56:43 +0200 |
commit | 2a55916a929524fd4f9e72bb1d7968d73ddc25f4 (patch) | |
tree | f8a29fac4945dfb2ee08c8c4e3bc1dd35c949aa0 /writerperfect/source | |
parent | 507247697dc6c4a41fe17a29d522511f97040738 (diff) |
EPUB export: initial character properties as direct formatting
Handle the case when the formatting comes from an autostyle on the text
span.
Change-Id: I12f9a752c4f2934a3e155a4442ad3db68a43d395
Reviewed-on: https://gerrit.libreoffice.org/41694
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'writerperfect/source')
-rw-r--r-- | writerperfect/source/writer/exp/txtparai.cxx | 29 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/txtstyli.cxx | 30 |
2 files changed, 57 insertions, 2 deletions
diff --git a/writerperfect/source/writer/exp/txtparai.cxx b/writerperfect/source/writer/exp/txtparai.cxx index e669cf89edf8..50ff36352ad5 100644 --- a/writerperfect/source/writer/exp/txtparai.cxx +++ b/writerperfect/source/writer/exp/txtparai.cxx @@ -44,9 +44,34 @@ XMLImportContext *XMLSpanContext::CreateChildContext(const OUString &rName, cons return nullptr; } -void XMLSpanContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/) +void XMLSpanContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) { - mrImport.GetGenerator().openSpan(librevenge::RVNGPropertyList()); + librevenge::RVNGPropertyList aPropertyList; + for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i) + { + const OUString &rAttributeName = xAttribs->getNameByIndex(i); + 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()->clone()); + } + else + { + OString sName = OUStringToOString(rAttributeName, RTL_TEXTENCODING_UTF8); + OString sValue = OUStringToOString(rAttributeValue, RTL_TEXTENCODING_UTF8); + aPropertyList.insert(sName.getStr(), sValue.getStr()); + } + } + + mrImport.GetGenerator().openSpan(aPropertyList); } void XMLSpanContext::endElement(const OUString &/*rName*/) diff --git a/writerperfect/source/writer/exp/txtstyli.cxx b/writerperfect/source/writer/exp/txtstyli.cxx index a7460a47c1b6..2d39816da4ef 100644 --- a/writerperfect/source/writer/exp/txtstyli.cxx +++ b/writerperfect/source/writer/exp/txtstyli.cxx @@ -46,6 +46,34 @@ void XMLParagraphPropertiesContext::startElement(const OUString &/*rName*/, cons } } +/// Handler for <style:text-properties>. +class XMLTextPropertiesContext : public XMLImportContext +{ +public: + XMLTextPropertiesContext(XMLImport &rImport, XMLStyleContext &rStyle); + + void SAL_CALL startElement(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override; + +private: + XMLStyleContext &mrStyle; +}; + +XMLTextPropertiesContext::XMLTextPropertiesContext(XMLImport &rImport, XMLStyleContext &rStyle) + : XMLImportContext(rImport) + , mrStyle(rStyle) +{ +} + +void XMLTextPropertiesContext::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) { @@ -55,6 +83,8 @@ XMLImportContext *XMLStyleContext::CreateChildContext(const OUString &rName, con { if (rName == "style:paragraph-properties") return new XMLParagraphPropertiesContext(mrImport, *this); + if (rName == "style:text-properties") + return new XMLTextPropertiesContext(mrImport, *this); return nullptr; } |