[Libreoffice-commits] core.git: sw/qa writerfilter/source

Justin Luth (via logerrit) logerrit at kemper.freedesktop.org
Fri Aug 20 15:12:21 UTC 2021


 sw/qa/extras/ooxmlexport/data/tdf142542_cancelledAutospacing.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport11.cxx                        |   10 ++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx                 |   36 ++++++----
 3 files changed, 32 insertions(+), 14 deletions(-)

New commits:
commit f4b80f4e060a68aa35a7ec678d18af989e82f055
Author:     Justin Luth <justin_luth at sil.org>
AuthorDate: Wed Aug 4 15:49:07 2021 +0200
Commit:     Justin Luth <justin_luth at sil.org>
CommitDate: Fri Aug 20 17:11:39 2021 +0200

    tdf#142542 writerfilter: allow para to cancel style autoSpacing
    
    Change-Id: I7535e7574c3ec9a108a810ba3209074d01aa96f3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120275
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <justin_luth at sil.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf142542_cancelledAutospacing.docx b/sw/qa/extras/ooxmlexport/data/tdf142542_cancelledAutospacing.docx
new file mode 100644
index 000000000000..615799fd7565
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf142542_cancelledAutospacing.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
index 92a841b826f8..de3eea4c0659 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
@@ -546,12 +546,22 @@ DECLARE_OOXMLEXPORT_TEST(testTdf113258_noBeforeAutospacing, "tdf113258_noBeforeA
                          getProperty<sal_Int32>(xShape->getStart(), "ParaTopMargin"));
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf142542_cancelledAutospacing, "tdf142542_cancelledAutospacing.docx")
+{
+    //Direct formatting disabling autoSpacing must override paragraph-style's autoSpacing.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), getProperty<sal_Int32>(getParagraph(1), "ParaTopMargin"));
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), getProperty<sal_Int32>(getParagraph(1), "ParaBottomMargin"));
+}
+
 DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf137655, "tdf137655.docx")
 {
     xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
     // These were 280.
     assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:p[1]/w:pPr/w:spacing", "before", "0");
     assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[2]/w:p[1]/w:pPr/w:spacing", "before", "0");
+
+    //tdf#142542: ensure that the original beforeAutospacing = 0 is not changed.
+    assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:p[1]/w:pPr/w:spacing", "beforeAutospacing", "0");
 }
 
 DECLARE_OOXMLEXPORT_TEST(testTdf120511_eatenSection, "tdf120511_eatenSection.docx")
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 9dedab0ba7da..8fffee9d32e4 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1685,7 +1685,6 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con
     const bool bAllowAdjustments = !GetSettingsTable()->GetDoNotUseHTMLParagraphAutoSpacing();
     sal_Int32 nBeforeAutospacing = -1;
     bool bIsAutoSet = pParaContext && pParaContext->isSet(PROP_PARA_TOP_MARGIN_BEFORE_AUTO_SPACING);
-    bool bIsZeroAutospacingWithoutTopmargin = false;
     const bool bNoTopmargin = pParaContext && !pParaContext->isSet(PROP_PARA_TOP_MARGIN);
     // apply INHERITED autospacing only if top margin is not set
     if ( bIsAutoSet || bNoTopmargin )
@@ -1695,44 +1694,53 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con
         // (see default_spacing = -1 in processing of LN_CT_Spacing_beforeAutospacing)
         if ( bNoTopmargin && nBeforeAutospacing == ConversionHelper::convertTwipToMM100(-1) )
         {
-            nBeforeAutospacing = 0;
-            bIsZeroAutospacingWithoutTopmargin = true;
+            sal_Int32 nStyleAuto = -1;
+            GetPropertyFromParaStyleSheet(PROP_PARA_TOP_MARGIN_BEFORE_AUTO_SPACING) >>= nStyleAuto;
+            if (nStyleAuto > 0)
+                nBeforeAutospacing = 0;
         }
     }
     if ( nBeforeAutospacing > -1 && pParaContext )
     {
-        if ( bAllowAdjustments && !bIsZeroAutospacingWithoutTopmargin )
+        if (bAllowAdjustments)
         {
             if ( GetIsFirstParagraphInShape() ||
                  (GetIsFirstParagraphInSection() && GetSectionContext() && GetSectionContext()->IsFirstSection()) ||
                  (m_bFirstParagraphInCell && m_nTableDepth > 0 && m_nTableDepth == m_nTableCellDepth) )
             {
-                nBeforeAutospacing = 0;
                 // export requires grabbag to match top_margin, so keep them in sync
-                if ( bIsAutoSet )
+                if (nBeforeAutospacing && bIsAutoSet)
                     pParaContext->Insert( PROP_PARA_TOP_MARGIN_BEFORE_AUTO_SPACING, uno::makeAny( sal_Int32(0) ),true, PARA_GRAB_BAG );
+                nBeforeAutospacing = 0;
             }
         }
-        if ( !bIsZeroAutospacingWithoutTopmargin || (m_nTableDepth > 0 && m_nTableDepth == m_nTableCellDepth) )
-            pParaContext->Insert(PROP_PARA_TOP_MARGIN, uno::makeAny(nBeforeAutospacing));
+        pParaContext->Insert(PROP_PARA_TOP_MARGIN, uno::makeAny(nBeforeAutospacing));
     }
 
     sal_Int32 nAfterAutospacing = -1;
     bIsAutoSet = pParaContext && pParaContext->isSet(PROP_PARA_BOTTOM_MARGIN_AFTER_AUTO_SPACING);
-    bool bApplyAutospacing = bIsAutoSet || (pParaContext && !pParaContext->isSet(PROP_PARA_BOTTOM_MARGIN));
-    if ( bApplyAutospacing )
+    const bool bNoBottomMargin = pParaContext && !pParaContext->isSet(PROP_PARA_BOTTOM_MARGIN);
+    bool bAppliedBottomAutospacing = false;
+    if (bIsAutoSet || bNoBottomMargin)
+    {
         GetAnyProperty(PROP_PARA_BOTTOM_MARGIN_AFTER_AUTO_SPACING, pPropertyMap) >>= nAfterAutospacing;
+        if (bNoBottomMargin && nAfterAutospacing == ConversionHelper::convertTwipToMM100(-1))
+        {
+            sal_Int32 nStyleAuto = -1;
+            GetPropertyFromParaStyleSheet(PROP_PARA_BOTTOM_MARGIN_AFTER_AUTO_SPACING) >>= nStyleAuto;
+            if (nStyleAuto > 0)
+                nAfterAutospacing = 0;
+        }
+    }
     if ( nAfterAutospacing > -1 && pParaContext )
     {
         pParaContext->Insert(PROP_PARA_BOTTOM_MARGIN, uno::makeAny(nAfterAutospacing));
-        bApplyAutospacing = bAllowAdjustments;
+        bAppliedBottomAutospacing = bAllowAdjustments;
     }
-    else
-        bApplyAutospacing = false;
 
     // tell TableManager to reset the bottom margin if it determines that this is the cell's last paragraph.
     if ( hasTableManager() && getTableManager().isInCell() )
-        getTableManager().setCellLastParaAfterAutospacing( bApplyAutospacing );
+        getTableManager().setCellLastParaAfterAutospacing(bAppliedBottomAutospacing);
 
     if (xTextAppend.is() && pParaContext && hasTableManager() && !getTableManager().isIgnore())
     {


More information about the Libreoffice-commits mailing list