From dfdc113bbd852e8f4b4863db457e2938aaad0c64 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 29 Aug 2017 17:56:28 +0200 Subject: EPUB export: support char props on text outside a span The librevenge model is simpler: text is always in a span, and paragraph (automatic) styles don't contain char props, either. So handle this complexity on our side. Change-Id: I017222539d8981d2bbbc632258662444bf3a79c8 Reviewed-on: https://gerrit.libreoffice.org/41705 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- writerperfect/source/writer/exp/txtparai.cxx | 33 ++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'writerperfect/source/writer/exp/txtparai.cxx') diff --git a/writerperfect/source/writer/exp/txtparai.cxx b/writerperfect/source/writer/exp/txtparai.cxx index 50ff36352ad5..293fb10eb3d3 100644 --- a/writerperfect/source/writer/exp/txtparai.cxx +++ b/writerperfect/source/writer/exp/txtparai.cxx @@ -53,9 +53,9 @@ void XMLSpanContext::startElement(const OUString &/*rName*/, const css::uno::Ref 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()) + // Reference to an automatic text style, try to look it up. + auto itStyle = mrImport.GetAutomaticTextStyles().find(rAttributeValue); + if (itStyle == mrImport.GetAutomaticTextStyles().end()) continue; // Apply properties directly, librevenge has no notion of automatic styles. @@ -152,15 +152,17 @@ void XMLParaContext::startElement(const OUString &/*rName*/, const css::uno::Ref const OUString &rAttributeValue = xAttribs->getValueByIndex(i); if (rAttributeName == "text:style-name") { + m_aStyleName = rAttributeValue; + // Reference to an automatic style, try to look it up. - auto itStyle = mrImport.GetAutomaticStyles().find(rAttributeValue); - if (itStyle == mrImport.GetAutomaticStyles().end()) + auto itStyle = mrImport.GetAutomaticParagraphStyles().find(m_aStyleName); + if (itStyle == mrImport.GetAutomaticParagraphStyles().end()) continue; - // Apply properties directly, librevenge has no notion of automatic styles. + // Found an automatic paragraph style. librevenge::RVNGPropertyList::Iter itProp(itStyle->second); for (itProp.rewind(); itProp.next();) - aPropertyList.insert(itProp.key(), itProp()); + aPropertyList.insert(itProp.key(), itProp()->clone()); } else { @@ -180,8 +182,25 @@ void XMLParaContext::endElement(const OUString &/*rName*/) void XMLParaContext::characters(const OUString &rChars) { + librevenge::RVNGPropertyList aPropertyList; + if (!m_aStyleName.isEmpty()) + { + // Reference to an automatic style, try to look it up. + auto itStyle = mrImport.GetAutomaticTextStyles().find(m_aStyleName); + if (itStyle != mrImport.GetAutomaticTextStyles().end()) + { + // Found an automatic text style. + librevenge::RVNGPropertyList::Iter itProp(itStyle->second); + for (itProp.rewind(); itProp.next();) + aPropertyList.insert(itProp.key(), itProp()->clone()); + } + } + mrImport.GetGenerator().openSpan(aPropertyList); + OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8); mrImport.GetGenerator().insertText(librevenge::RVNGString(sCharU8.getStr())); + + mrImport.GetGenerator().closeSpan(); } } // namespace exp -- cgit v1.2.3