summaryrefslogtreecommitdiff
path: root/writerperfect/source/writer
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-09-06 09:56:07 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-09-06 11:21:45 +0200
commit3621c773a867eb2bbee83035c7125ca11296e44a (patch)
treea7b271ba4770695f6ab760e6d7afeb4d0f4bc81b /writerperfect/source/writer
parent128856d5810ef4b103885a0a3c145ed3016a5950 (diff)
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 <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'writerperfect/source/writer')
-rw-r--r--writerperfect/source/writer/exp/txtparai.cxx97
1 files changed, 34 insertions, 63 deletions
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);