sw/source/writerfilter/dmapper/DomainMapper.cxx      |   56 -----------------
 sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx |   62 +++++++++++++++++++
 sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx |    2 
 3 files changed, 65 insertions(+), 55 deletions(-)

New commits:
commit e4e35dca3f93b4d235731fa5a98d45c9cc8fbd87
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Wed Jul 17 17:56:06 2024 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Fri Jul 19 02:44:02 2024 +0200

    NFC tdf#125469 writerfilter: move code into SetLineSpacing function
    
    I didn't make any logic changes to the function yet,
    just moved it to a shared location so it can be called elsewhere.
    
    This is preparation for fixing bug 125469,
    and I want to keep the fixing patch clean to show the real changes.
    
    Change-Id: I50a9ad1c61c7e885f40defc38554e0cb2ca51a9a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170668
    Reviewed-by: Justin Luth <jl...@mail.com>
    Tested-by: Jenkins

diff --git a/sw/source/writerfilter/dmapper/DomainMapper.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper.cxx
index 902e299d8d68..3bc6444ef15e 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper.cxx
@@ -508,61 +508,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
         case NS_ooxml::LN_CT_Spacing_line: //91434
         case NS_ooxml::LN_CT_Spacing_lineRule: //91435
         {
-            style::LineSpacing aSpacing;
-            PropertyMapPtr pTopContext = m_pImpl->GetTopContext();
-            std::optional<PropertyMap::Property> aLineSpacingVal;
-            if (pTopContext && (aLineSpacingVal = 
pTopContext->getProperty(PROP_PARA_LINE_SPACING)) )
-            {
-                aLineSpacingVal->second >>= aSpacing;
-            }
-            else
-            {
-                //default to single line spacing
-                aSpacing.Mode = style::LineSpacingMode::FIX;
-                aSpacing.Height = convertTwipToMm100(nSingleLineSpacing);
-            }
-            if( nName == NS_ooxml::LN_CT_Spacing_line )
-            {
-                m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, 
u"line"_ustr, OUString::number(nIntValue));
-                //now set the value depending on the Mode
-                if( aSpacing.Mode == style::LineSpacingMode::PROP )
-                    aSpacing.Height = sal_Int16(nIntValue * 100 / 
nSingleLineSpacing );
-                else
-                    aSpacing.Height = 
sal_Int16(ConversionHelper::convertTwipToMm100_Limited( nIntValue ));
-            }
-            else //NS_ooxml::LN_CT_Spacing_lineRule:
-            {
-                    // exactly, atLeast, auto
-                    if( sal::static_int_cast<Id>(nIntValue) == 
NS_ooxml::LN_Value_doc_ST_LineSpacingRule_auto)
-                    {
-                        m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, 
u"lineRule"_ustr, u"auto"_ustr);
-                        if (aSpacing.Height >= 0)
-                        {
-                            aSpacing.Mode = style::LineSpacingMode::PROP;
-                            //reinterpret the already set value
-                            aSpacing.Height = sal_Int16( aSpacing.Height * 100 
/  ConversionHelper::convertTwipToMm100_Limited( nSingleLineSpacing ));
-                        }
-                        else
-                        {
-                            // Negative value still means a positive height,
-                            // just the mode is "exact".
-                            aSpacing.Mode = style::LineSpacingMode::FIX;
-                            aSpacing.Height *= -1;
-                        }
-                    }
-                    else if( sal::static_int_cast<Id>(nIntValue) == 
NS_ooxml::LN_Value_doc_ST_LineSpacingRule_atLeast)
-                    {
-                        m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, 
u"lineRule"_ustr, u"atLeast"_ustr);
-                        aSpacing.Mode = style::LineSpacingMode::MINIMUM;
-                    }
-                    else // NS_ooxml::LN_Value_doc_ST_LineSpacingRule_exact
-                    {
-                        m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, 
u"lineRule"_ustr, u"exact"_ustr);
-                        aSpacing.Mode = style::LineSpacingMode::FIX;
-                    }
-            }
-            if (pTopContext)
-                pTopContext->Insert(PROP_PARA_LINE_SPACING, uno::Any( aSpacing 
));
+            m_pImpl->SetLineSpacing(nName, nIntValue);
         }
         break;
         case NS_ooxml::LN_CT_Ind_start:
diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
index a6bbf5302f89..79ae5e629263 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
@@ -5079,6 +5079,68 @@ bool DomainMapper_Impl::IsDiscardHeaderFooter() const
     return m_bDiscardHeaderFooter;
 }
 
+void DomainMapper_Impl::SetLineSpacing(const Id nName, sal_Int32 nIntValue)
+{
+    static const int nSingleLineSpacing = 240;
+
+    style::LineSpacing aSpacing;
+    const PropertyMapPtr pTopContext = GetTopContext();
+    std::optional<PropertyMap::Property> aLineSpacingVal;
+    if (pTopContext && (aLineSpacingVal = 
pTopContext->getProperty(PROP_PARA_LINE_SPACING)))
+        aLineSpacingVal->second >>= aSpacing;
+    else
+    {
+        // default to exact 12pt spacing
+        aSpacing.Mode = style::LineSpacingMode::FIX;
+        aSpacing.Height = convertTwipToMm100(nSingleLineSpacing);
+    }
+    if (nName == NS_ooxml::LN_CT_Spacing_line)
+    {
+        appendGrabBag(m_aSubInteropGrabBag, u"line"_ustr, 
OUString::number(nIntValue));
+        // now set the value depending on the Mode
+        if (aSpacing.Mode == style::LineSpacingMode::PROP)
+            aSpacing.Height = sal_Int16(nIntValue * 100 / nSingleLineSpacing);
+        else
+            aSpacing.Height = 
sal_Int16(ConversionHelper::convertTwipToMm100_Limited(nIntValue));
+    }
+    else // NS_ooxml::LN_CT_Spacing_lineRule:
+    {
+        // exactly, atLeast, auto
+        if (sal::static_int_cast<Id>(nIntValue) == 
NS_ooxml::LN_Value_doc_ST_LineSpacingRule_auto)
+        {
+            appendGrabBag(m_aSubInteropGrabBag, u"lineRule"_ustr, 
u"auto"_ustr);
+            if (aSpacing.Height >= 0)
+            {
+                aSpacing.Mode = style::LineSpacingMode::PROP;
+                // reinterpret the already set value
+                aSpacing.Height
+                    = sal_Int16(aSpacing.Height * 100
+                                / 
ConversionHelper::convertTwipToMm100_Limited(nSingleLineSpacing));
+            }
+            else
+            {
+                // Negative value still means a positive height,
+                // just the mode is "exact".
+                aSpacing.Mode = style::LineSpacingMode::FIX;
+                aSpacing.Height *= -1;
+            }
+        }
+        else if (sal::static_int_cast<Id>(nIntValue)
+                 == NS_ooxml::LN_Value_doc_ST_LineSpacingRule_atLeast)
+        {
+            appendGrabBag(m_aSubInteropGrabBag, u"lineRule"_ustr, 
u"atLeast"_ustr);
+            aSpacing.Mode = style::LineSpacingMode::MINIMUM;
+        }
+        else // NS_ooxml::LN_Value_doc_ST_LineSpacingRule_exact
+        {
+            appendGrabBag(m_aSubInteropGrabBag, u"lineRule"_ustr, 
u"exact"_ustr);
+            aSpacing.Mode = style::LineSpacingMode::FIX;
+        }
+    }
+    if (pTopContext)
+        pTopContext->Insert(PROP_PARA_LINE_SPACING, uno::Any(aSpacing));
+}
+
 // called from TableManager::closeCell()
 void DomainMapper_Impl::ClearPreviousParagraph()
 {
diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx 
b/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx
index 9ab2e6f789f8..5bb82fc715ae 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx
@@ -1212,6 +1212,8 @@ public:
 
     void SetParaAutoBefore(bool const bParaAutoBefore) { 
m_StreamStateStack.top().bParaAutoBefore = bParaAutoBefore; }
 
+    void SetLineSpacing(const Id nName, sal_Int32 nIntValue);
+
     /// Forget about the previous paragraph, as it's not inside the same
     /// start/end node.
     void ClearPreviousParagraph();

Reply via email to