writerperfect/source/writer/exp/txtparai.cxx | 97 +++++++++------------------ 1 file changed, 34 insertions(+), 63 deletions(-)
New commits: commit 3621c773a867eb2bbee83035c7125ca11296e44a Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Wed Sep 6 09:56:07 2017 +0200 EPUB export: pull out FillStyle() from XMLSpan/ParaContext To avoid repeating similar code 3 times. Change-Id: I76a7d2329488ba9b77b789c0393ac120e8e775d1 Reviewed-on: https://gerrit.libreoffice.org/41973 Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> Tested-by: Jenkins <c...@libreoffice.org> diff --git a/writerperfect/source/writer/exp/txtparai.cxx b/writerperfect/source/writer/exp/txtparai.cxx index 31ab25f43cad..f2df54d0e1b0 100644 --- a/writerperfect/source/writer/exp/txtparai.cxx +++ b/writerperfect/source/writer/exp/txtparai.cxx @@ -14,6 +14,37 @@ using namespace com::sun::star; +namespace +{ + +/// Looks for rName in rAutomaticStyles (and failing that, in rNamedStyles) and fills rPropertyList based on that. +void FillStyle(const OUString &rName, + std::map<OUString, librevenge::RVNGPropertyList> &rNamedStyles, + std::map<OUString, librevenge::RVNGPropertyList> &rAutomaticStyles, + librevenge::RVNGPropertyList &rPropertyList) +{ + auto itStyle = rAutomaticStyles.find(rName); + if (itStyle != rAutomaticStyles.end()) + { + // Apply properties from automatic style. + librevenge::RVNGPropertyList::Iter itProp(itStyle->second); + for (itProp.rewind(); itProp.next();) + rPropertyList.insert(itProp.key(), itProp()->clone()); + return; + } + + itStyle = rNamedStyles.find(rName); + if (itStyle != rNamedStyles.end()) + { + // Apply properties from named style. + librevenge::RVNGPropertyList::Iter itProp(itStyle->second); + for (itProp.rewind(); itProp.next();) + rPropertyList.insert(itProp.key(), itProp()->clone()); + } +} + +} + namespace writerperfect { namespace exp @@ -52,27 +83,7 @@ void XMLSpanContext::startElement(const OUString &/*rName*/, const css::uno::Ref const OUString &rAttributeName = xAttribs->getNameByIndex(i); const OUString &rAttributeValue = xAttribs->getValueByIndex(i); if (rAttributeName == "text:style-name") - { - // Reference to an automatic text style, try to look it up. - auto itStyle = mrImport.GetAutomaticTextStyles().find(rAttributeValue); - if (itStyle != mrImport.GetAutomaticTextStyles().end()) - { - // 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()); - continue; - } - - itStyle = mrImport.GetTextStyles().find(rAttributeValue); - if (itStyle != mrImport.GetTextStyles().end()) - { - // Apply properties from text style. - librevenge::RVNGPropertyList::Iter itProp(itStyle->second); - for (itProp.rewind(); itProp.next();) - aPropertyList.insert(itProp.key(), itProp()->clone()); - } - } + FillStyle(rAttributeValue, mrImport.GetAutomaticTextStyles(), mrImport.GetTextStyles(), aPropertyList); else { OString sName = OUStringToOString(rAttributeName, RTL_TEXTENCODING_UTF8); @@ -163,26 +174,7 @@ void XMLParaContext::startElement(const OUString &/*rName*/, const css::uno::Ref if (rAttributeName == "text:style-name") { m_aStyleName = rAttributeValue; - - // Reference to an automatic style, try to look it up. - auto itStyle = mrImport.GetAutomaticParagraphStyles().find(m_aStyleName); - if (itStyle != mrImport.GetAutomaticParagraphStyles().end()) - { - // Found an automatic paragraph style. - librevenge::RVNGPropertyList::Iter itProp(itStyle->second); - for (itProp.rewind(); itProp.next();) - aPropertyList.insert(itProp.key(), itProp()->clone()); - continue; - } - - itStyle = mrImport.GetParagraphStyles().find(m_aStyleName); - if (itStyle != mrImport.GetParagraphStyles().end()) - { - // Found a paragraph style. - librevenge::RVNGPropertyList::Iter itProp(itStyle->second); - for (itProp.rewind(); itProp.next();) - aPropertyList.insert(itProp.key(), itProp()->clone()); - } + FillStyle(m_aStyleName, mrImport.GetAutomaticParagraphStyles(), mrImport.GetParagraphStyles(), aPropertyList); } else { @@ -204,28 +196,7 @@ 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()); - } - else - { - itStyle = mrImport.GetTextStyles().find(m_aStyleName); - if (itStyle != mrImport.GetTextStyles().end()) - { - // Found a named text style. - librevenge::RVNGPropertyList::Iter itProp(itStyle->second); - for (itProp.rewind(); itProp.next();) - aPropertyList.insert(itProp.key(), itProp()->clone()); - } - } - } + FillStyle(m_aStyleName, mrImport.GetAutomaticTextStyles(), mrImport.GetTextStyles(), aPropertyList); mrImport.GetGenerator().openSpan(aPropertyList); OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits