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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Jul 20 08:44:40 UTC 2018


 sw/qa/extras/ooxmlexport/data/tdf118521_marginsLR.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport11.cxx             |   17 ++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx      |   59 +++++++++++------
 3 files changed, 57 insertions(+), 19 deletions(-)

New commits:
commit eab67995d7056682c250efa3c903b1fffd812700
Author:     Justin Luth <justin_luth at sil.org>
AuthorDate: Thu Jul 19 19:20:26 2018 +0300
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Fri Jul 20 10:44:15 2018 +0200

    tdf#118521 DOCX import: style sets unset left/right/hanging margin
    
    followup to commit 480ac84f2f5049fb4337b36f12fd6796e005761b which
    nicely paved the way by doing this for top/bottom.
    
    Change-Id: I61b4e298e8732391b4f0467b459d9c15298925fa
    Reviewed-on: https://gerrit.libreoffice.org/57742
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <justin_luth at sil.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>
    Tested-by: László Németh <nemeth at numbertext.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf118521_marginsLR.docx b/sw/qa/extras/ooxmlexport/data/tdf118521_marginsLR.docx
new file mode 100644
index 000000000000..66170ede470c
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf118521_marginsLR.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
index bc9e3f7f3328..3246fe5eec4d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
@@ -464,6 +464,23 @@ DECLARE_OOXMLEXPORT_TEST(testMarginsFromStyle, "margins_from_style.docx")
     CPPUNIT_ASSERT_EQUAL(sal_Int32(600), getProperty<sal_Int32>(getParagraph(3), "ParaBottomMargin"));
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf118521_marginsLR, "tdf118521_marginsLR.docx")
+{
+    // tdf#118521 paragraphs with direct formatting of only some of left, right, or first margins have
+    // lost the other unset margins coming from paragraph style, getting a bad margin from the default style instead
+
+    uno::Reference<beans::XPropertySet> xMyStyle(getStyles("ParagraphStyles")->getByName("MyStyle"), uno::UNO_QUERY);
+    // from paragraph style - this is what direct formatting should equal
+    sal_Int32 nMargin = getProperty<sal_Int32>(xMyStyle, "ParaLeftMargin");
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nMargin);
+    // from direct formatting
+    CPPUNIT_ASSERT_EQUAL(nMargin, getProperty<sal_Int32>(getParagraph(1), "ParaLeftMargin"));
+
+    nMargin = getProperty<sal_Int32>(xMyStyle, "ParaRightMargin");
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1900), nMargin);
+    CPPUNIT_ASSERT_EQUAL(nMargin, getProperty<sal_Int32>(getParagraph(2), "ParaRightMargin"));
+}
+
 DECLARE_OOXMLIMPORT_TEST(testTdf104797, "tdf104797.docx")
 {
     // check moveFrom and moveTo
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index a1fde6baae1b..2939902f03ca 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1122,16 +1122,16 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap )
     TagLogger::getInstance().attribute("isTextAppend", sal_uInt32(xTextAppend.is()));
 #endif
 
+    const StyleSheetEntryPtr pEntry = GetStyleSheetTable()->FindStyleSheetByConvertedStyleName( GetCurrentParaStyleName() );
+    OSL_ENSURE( pEntry.get(), "no style sheet found" );
+    const StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast<const StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : nullptr);
     //apply numbering to paragraph if it was set at the style, but only if the paragraph itself
     //does not specify the numbering
-    if( pParaContext && !pParaContext->isSet(PROP_NUMBERING_RULES) )
+    if ( pStyleSheetProperties && pParaContext && !pParaContext->isSet(PROP_NUMBERING_RULES) )
     {
-        const StyleSheetEntryPtr pEntry = GetStyleSheetTable()->FindStyleSheetByConvertedStyleName( GetCurrentParaStyleName() );
-        OSL_ENSURE( pEntry.get(), "no style sheet found" );
-        const StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast<const StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : nullptr);
 
         sal_Int32 nListId = pEntry ? lcl_getListId(pEntry, GetStyleSheetTable()) : -1;
-        if( pStyleSheetProperties && nListId >= 0 )
+        if ( nListId >= 0 )
         {
             pParaContext->Insert( PROP_NUMBERING_STYLE_NAME, uno::makeAny( ListDef::GetStyleName( nListId ) ), false);
 
@@ -1169,7 +1169,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap )
             }
         }
 
-        if( pStyleSheetProperties && pStyleSheetProperties->GetListLevel() >= 0 )
+        if ( pStyleSheetProperties->GetListLevel() >= 0 )
             pParaContext->Insert( PROP_NUMBERING_LEVEL, uno::makeAny(pStyleSheetProperties->GetListLevel()), false);
     }
 
@@ -1418,28 +1418,49 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap )
 
                 // tdf#118521 set paragraph top or bottom margin based on the paragraph style
                 // if we already set the other margin with direct formatting
-                if (pParaContext && m_xPreviousParagraph.is() &&
+                if (pStyleSheetProperties && pParaContext && m_xPreviousParagraph.is() &&
                         pParaContext->isSet(PROP_PARA_TOP_MARGIN) != pParaContext->isSet(PROP_PARA_BOTTOM_MARGIN))
                 {
-                    const StyleSheetEntryPtr pEntry = GetStyleSheetTable()->FindStyleSheetByConvertedStyleName( GetCurrentParaStyleName() );
-                    OSL_ENSURE( pEntry.get(), "no style sheet found" );
-                    const StyleSheetPropertyMap* pStyleSheetProperties =
-                            dynamic_cast<const StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : nullptr);
-                    if (pStyleSheetProperties) {
+                    boost::optional<PropertyMap::Property> oProperty;
+                    if (pParaContext->isSet(PROP_PARA_TOP_MARGIN))
+                    {
+                        if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_BOTTOM_MARGIN)) )
+                            m_xPreviousParagraph->setPropertyValue("ParaBottomMargin", oProperty->second);
+                    }
+                    else
+                    {
+                        if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_TOP_MARGIN)) )
+                            m_xPreviousParagraph->setPropertyValue("ParaTopMargin", oProperty->second);
+                    }
+                }
+
+                // Left, Right, and Hanging settings are also grouped. Ensure that all or none are set.
+                // m_xPreviousParagraph was set earlier, so really it still is the current paragraph...
+                if ( pStyleSheetProperties && pParaContext && m_xPreviousParagraph.is() )
+                {
+                    const bool bLeftSet  = pParaContext->isSet(PROP_PARA_LEFT_MARGIN);
+                    const bool bRightSet = pParaContext->isSet(PROP_PARA_RIGHT_MARGIN);
+                    const bool bFirstSet = pParaContext->isSet(PROP_PARA_FIRST_LINE_INDENT);
+                    if ( !(bLeftSet == bRightSet && bRightSet == bFirstSet) )
+                    {
                         boost::optional<PropertyMap::Property> oProperty;
-                        if (pParaContext->isSet(PROP_PARA_TOP_MARGIN))
+                        if ( !bLeftSet )
                         {
-                            if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_BOTTOM_MARGIN)) )
-                                m_xPreviousParagraph->setPropertyValue("ParaBottomMargin", oProperty->second);
+                            if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_LEFT_MARGIN)) )
+                                m_xPreviousParagraph->setPropertyValue("ParaLeftMargin", oProperty->second);
                         }
-                        else
+                        if ( !bRightSet )
                         {
-                            if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_TOP_MARGIN)) )
-                                m_xPreviousParagraph->setPropertyValue("ParaTopMargin", oProperty->second);
+                            if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_RIGHT_MARGIN)) )
+                                m_xPreviousParagraph->setPropertyValue("ParaRightMargin", oProperty->second);
+                        }
+                        if ( !bFirstSet )
+                        {
+                            if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_FIRST_LINE_INDENT)) )
+                                m_xPreviousParagraph->setPropertyValue("ParaFirstLineIndent", oProperty->second);
                         }
                     }
                 }
-
             }
             if( !bKeepLastParagraphProperties )
                 rAppendContext.pLastParagraphProperties = pToBeSavedProperties;


More information about the Libreoffice-commits mailing list