sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx |   65 +++++++------------
 1 file changed, 25 insertions(+), 40 deletions(-)

New commits:
commit ceec6eacfc69e71d85b360da6e25edbd9676628a
Author:     Mike Kaganski <[email protected]>
AuthorDate: Wed Oct 23 10:53:11 2024 +0200
Commit:     Mike Kaganski <[email protected]>
CommitDate: Wed Oct 23 15:39:06 2024 +0200

    Try to apply indents a bit saner
    
    It was too convoluted; the three properties that were set there
    all used different logic (PROP_PARA_FIRST_LINE_INDENT was only
    set when the parent style id was present; PROP_PARA_LEFT_MARGIN
    was set when it was found either in the entry or in its parent;
    PROP_PARA_RIGHT_MARGIN was only set when parent style was found,
    and it had properties). It seems to be just some leftovers from
    iterative partial changes of the code.
    
    This makes the code more uniform. For PROP_PARA_RIGHT_MARGIN it
    keeps setting PROP_PARA_FIRST_LINE_INDENT/PROP_PARA_LEFT_MARGIN
    from getNumberingProperty; but otherwise, all three are handled
    similarly: if the property is set either in the entry itself or
    in its parent, it is processed. This changes the logic slightly,
    but hopefully in the correct direction.
    
    Change-Id: I1a8fb95d055101dcbc3aaec6207721146c94cc21
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175437
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins

diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
index ef4bdaec411d..bd444bab73b6 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
@@ -2285,25 +2285,22 @@ void DomainMapper_Impl::finishParagraph( const 
PropertyMapPtr& pPropertyMap, con
             // But since import has just copied para-style's 
PROP_NUMBERING_STYLE_NAME directly onto the paragraph,
             // the numbering indents now have the priority.
             // So now import must also copy the para-style indents directly 
onto the paragraph to compensate.
-            std::optional<PropertyMap::Property> oProperty;
-            const StyleSheetEntryPtr pParent = lcl_getParent(pEntry, 
GetStyleSheetTable());
-            const StyleSheetPropertyMap* pParentProperties = pParent ? 
pParent->m_pProperties.get() : nullptr;
-            if (!pEntry->m_sBaseStyleIdentifier.isEmpty())
+            auto getOptProperty
+                = [&pEntry, parent = lcl_getParent(pEntry, 
GetStyleSheetTable())](PropertyIds id, bool useParent)
             {
-                oProperty = 
pEntry->m_pProperties->getProperty(PROP_PARA_FIRST_LINE_INDENT);
-                if ( oProperty
-                    // If the numbering comes from a base style, indent of the 
base style has also priority.
-                    || (bNumberingFromBaseStyle && pParentProperties && 
(oProperty = pParentProperties->getProperty(PROP_PARA_FIRST_LINE_INDENT))) )
-                    pParaContext->Insert(PROP_PARA_FIRST_LINE_INDENT, 
oProperty->second, /*bOverwrite=*/false);
-            }
-            oProperty = 
pEntry->m_pProperties->getProperty(PROP_PARA_LEFT_MARGIN);
-            if ( oProperty
-                || (bNumberingFromBaseStyle && pParentProperties && (oProperty 
= pParentProperties->getProperty(PROP_PARA_LEFT_MARGIN))) )
+                auto p = pEntry->m_pProperties->getProperty(id);
+                if (!p && useParent && parent && parent->m_pProperties)
+                    p = parent->m_pProperties->getProperty(id);
+                return p;
+            };
+            if (auto oProperty = getOptProperty(PROP_PARA_FIRST_LINE_INDENT, 
bNumberingFromBaseStyle))
+                pParaContext->Insert(PROP_PARA_FIRST_LINE_INDENT, 
oProperty->second, /*bOverwrite=*/false);
+            if (auto oProperty = getOptProperty(PROP_PARA_LEFT_MARGIN, 
bNumberingFromBaseStyle))
                 pParaContext->Insert(PROP_PARA_LEFT_MARGIN, oProperty->second, 
/*bOverwrite=*/false);
 
             // We're inheriting properties from a numbering style. Make sure a 
possible right margin is inherited from the base style.
-            sal_Int32 nParaRightMargin;
-            if  ( pParentProperties && (oProperty = 
pParentProperties->getProperty(PROP_PARA_RIGHT_MARGIN)) && (nParaRightMargin = 
oProperty->second.get<sal_Int32>()) != 0 )
+            if (auto oProperty = getOptProperty(PROP_PARA_RIGHT_MARGIN, true);
+                oProperty && oProperty->second.get<sal_Int32>() != 0)
             {
                 // If we're setting the right margin, we should set the first 
/ left margin as well from the numbering style.
                 const sal_Int32 nFirstLineIndent = 
getNumberingProperty(nListId, nListLevel, u"FirstLineIndent"_ustr);
@@ -2313,11 +2310,7 @@ void DomainMapper_Impl::finishParagraph( const 
PropertyMapPtr& pPropertyMap, con
                 if (nParaLeftMargin != 0)
                     pParaContext->Insert(PROP_PARA_LEFT_MARGIN, 
uno::Any(nParaLeftMargin), /*bOverwrite=*/false);
 
-                // Override right margin value with value from current style, 
if any
-                if (pEntry->m_pProperties->isSet(PROP_PARA_RIGHT_MARGIN))
-                    nParaRightMargin = 
pEntry->m_pProperties->getProperty(PROP_PARA_RIGHT_MARGIN)->second.get<sal_Int32>();
-
-                pParaContext->Insert(PROP_PARA_RIGHT_MARGIN, 
uno::Any(nParaRightMargin), /*bOverwrite=*/false);
+                pParaContext->Insert(PROP_PARA_RIGHT_MARGIN, 
oProperty->second, /*bOverwrite=*/false);
             }
         }
         // Paragraph style based right paragraph indentation affects not 
paragraph style based lists in DOCX.
commit f57203e5eba95a1f10e3a4f92c4c3f42e1360536
Author:     Mike Kaganski <[email protected]>
AuthorDate: Wed Oct 23 12:51:51 2024 +0200
Commit:     Mike Kaganski <[email protected]>
CommitDate: Wed Oct 23 15:38:58 2024 +0200

    Deduplicate a bit
    
    Change-Id: Iace3fdfdaed79054fda2894b5d9f4275f80a5e0a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175440
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
index 962ab0668934..ef4bdaec411d 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
@@ -218,6 +218,13 @@ static void lcl_handleTextField( const uno::Reference< 
beans::XPropertySet >& rx
     }
 }
 
+static StyleSheetEntryPtr lcl_getParent(StyleSheetEntryPtr pEntry, 
StyleSheetTablePtr pStyleSheet)
+{
+    if (!pEntry->m_sBaseStyleIdentifier.isEmpty())
+        return 
pStyleSheet->FindStyleSheetByISTD(pEntry->m_sBaseStyleIdentifier);
+    return nullptr;
+}
+
 /**
  Very similar to DomainMapper_Impl::GetPropertyFromStyleSheet
  It is focused on paragraph properties search in current & parent stylesheet 
entries.
@@ -242,10 +249,7 @@ static uno::Any 
lcl_GetPropertyFromParaStyleSheetNoNum(PropertyIds eId, StyleShe
             }
         }
         //search until the property is set or no parent is available
-        StyleSheetEntryPtr pNewEntry;
-        if (!pEntry->m_sBaseStyleIdentifier.isEmpty())
-            pNewEntry = 
rStyleSheet->FindStyleSheetByISTD(pEntry->m_sBaseStyleIdentifier);
-
+        StyleSheetEntryPtr pNewEntry = lcl_getParent(pEntry, rStyleSheet);
         SAL_WARN_IF(pEntry == pNewEntry, "writerfilter.dmapper", "circular 
loop in style hierarchy?");
 
         if (pEntry == pNewEntry) //fdo#49587
@@ -1496,9 +1500,7 @@ uno::Any 
DomainMapper_Impl::GetPropertyFromStyleSheet(PropertyIds eId, const Sty
             }
         }
         //search until the property is set or no parent is available
-        StyleSheetEntryPtr pNewEntry;
-        if ( !pEntry->m_sBaseStyleIdentifier.isEmpty() )
-            pNewEntry = 
GetStyleSheetTable()->FindStyleSheetByISTD(pEntry->m_sBaseStyleIdentifier);
+        StyleSheetEntryPtr pNewEntry = lcl_getParent(pEntry, 
GetStyleSheetTable());
 
         SAL_WARN_IF( pEntry == pNewEntry, "writerfilter.dmapper", "circular 
loop in style hierarchy?");
 
@@ -1833,9 +1835,7 @@ DomainMapper_Impl::MakeFrameProperties(const 
ParagraphProperties& rProps)
         {
             vProps.emplace_back(&pStyle->m_pProperties->props());
             assert(pStyle->m_sBaseStyleIdentifier != pStyle->m_sStyleName);
-            if (pStyle->m_sBaseStyleIdentifier.isEmpty())
-                break;
-            pStyle = 
GetStyleSheetTable()->FindStyleSheetByISTD(pStyle->m_sBaseStyleIdentifier);
+            pStyle = lcl_getParent(pStyle, GetStyleSheetTable());
         }
         SAL_WARN_IF(!nSafetyLimit, "writerfilter.dmapper", "Inheritance loop 
likely: early exit");
 
@@ -2091,11 +2091,7 @@ static sal_Int32 lcl_getListId(const StyleSheetEntryPtr& 
rEntry, const StyleShee
     if (nListId >= 0)
         return nListId;
 
-    // The style has no parent.
-    if (rEntry->m_sBaseStyleIdentifier.isEmpty())
-        return -1;
-
-    const StyleSheetEntryPtr pParent = 
rStyleTable->FindStyleSheetByISTD(rEntry->m_sBaseStyleIdentifier);
+    const StyleSheetEntryPtr pParent = lcl_getParent(rEntry, rStyleTable);
     // No such parent style or loop in the style hierarchy.
     if (!pParent || pParent == rEntry)
         return -1;
@@ -2136,11 +2132,7 @@ sal_Int16 DomainMapper_Impl::GetListLevel(const 
StyleSheetEntryPtr& pEntry,
     if (nListLevel >= 0)
         return nListLevel;
 
-    // The style has no parent.
-    if (pEntry->m_sBaseStyleIdentifier.isEmpty())
-        return -1;
-
-    const StyleSheetEntryPtr pParent = 
GetStyleSheetTable()->FindStyleSheetByISTD(pEntry->m_sBaseStyleIdentifier);
+    const StyleSheetEntryPtr pParent = lcl_getParent(pEntry, 
GetStyleSheetTable());
     // No such parent style or loop in the style hierarchy.
     if (!pParent || pParent == pEntry)
         return -1;
@@ -2294,7 +2286,7 @@ void DomainMapper_Impl::finishParagraph( const 
PropertyMapPtr& pPropertyMap, con
             // the numbering indents now have the priority.
             // So now import must also copy the para-style indents directly 
onto the paragraph to compensate.
             std::optional<PropertyMap::Property> oProperty;
-            const StyleSheetEntryPtr pParent = 
(!pEntry->m_sBaseStyleIdentifier.isEmpty()) ? 
GetStyleSheetTable()->FindStyleSheetByISTD(pEntry->m_sBaseStyleIdentifier) : 
nullptr;
+            const StyleSheetEntryPtr pParent = lcl_getParent(pEntry, 
GetStyleSheetTable());
             const StyleSheetPropertyMap* pParentProperties = pParent ? 
pParent->m_pProperties.get() : nullptr;
             if (!pEntry->m_sBaseStyleIdentifier.isEmpty())
             {

Reply via email to