[Libreoffice-commits] core.git: Branch 'libreoffice-6-0' - sw/qa writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Fri Feb 16 09:23:20 UTC 2018


 sw/qa/extras/ooxmlexport/data/tdf113258.docx      |binary
 sw/qa/extras/ooxmlexport/ooxmlexport11.cxx        |    9 +++++++++
 writerfilter/source/dmapper/DomainMapper.cxx      |   22 ++++++++++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |    7 +++++++
 writerfilter/source/dmapper/DomainMapper_Impl.hxx |    3 +++
 5 files changed, 41 insertions(+)

New commits:
commit 3779c742a52d8dde3fa7b74c2a8ca8bc7d071b4e
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Feb 12 22:04:55 2018 +0100

    tdf#113258 DOCX import: fix beforeAutospacing for shape first paragraph
    
    Commit c761df1e42fd11acc5fc05b0baacd803c3788ca6 (tdf#84678 DOCX import:
    fix handling of textbox margins, 2016-10-25) uncovered a previously
    harder to notice problem that single-paragraph shapes have an incorrect
    upper paragraph margin for the first paragraph. Now that the shape
    margins are correct this problematic paragraph margin causes crop of the
    shape text.
    
    Fix the problem by adapting the DOCX import to the WW8 import's
    SwWW8ImplReader::AppendTextNode() (the "If this is the first paragraph
    in the document" part), where it seems the first paragraph is not only
    the literally first paragraph in the document, but also the first
    paragraph of shapes as well.
    
    (cherry picked from commit f737c9386a605cb7d8c9dbc210c557f98f6cdc19)
    
    Conflicts:
            writerfilter/source/dmapper/DomainMapper.cxx
    
    Change-Id: I9d99b9cfabae2c9a7c33eefefb5a9f008669e93d
    Reviewed-on: https://gerrit.libreoffice.org/49626
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf113258.docx b/sw/qa/extras/ooxmlexport/data/tdf113258.docx
new file mode 100644
index 000000000000..d60a2ee6413c
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf113258.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
index 98e207c81d81..91697a80f920 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
@@ -161,6 +161,15 @@ DECLARE_OOXMLEXPORT_TEST(testTdf114703, "tdf114703.docx")
         comphelper::SequenceAsHashMap(xRules->getByIndex(0))["FirstLineIndent"].get<sal_Int32>());
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf113258, "tdf113258.docx")
+{
+    uno::Reference<text::XTextRange> xShape(getShape(1), uno::UNO_QUERY);
+    // This was 494, i.e. automatic spacing resulted in non-zero paragraph top
+    // margin for the first paragraph in a shape.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0),
+                         getProperty<sal_Int32>(xShape->getStart(), "ParaTopMargin"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 83698f4553de..5569f91a23de 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -2170,7 +2170,27 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
         StyleSheetTablePtr pStyleTable = m_pImpl->GetStyleSheetTable();
         const OUString sConvertedStyleName = pStyleTable->ConvertStyleName( sStringValue, true );
         if (m_pImpl->GetTopContext() && m_pImpl->GetTopContextType() != CONTEXT_SECTION)
+        {
             m_pImpl->GetTopContext()->Insert( PROP_PARA_STYLE_NAME, uno::makeAny( sConvertedStyleName ));
+
+            if (m_pImpl->GetIsFirstParagraphInShape())
+            {
+                // First paragraph in shape: see if we need to disable
+                // paragraph top margin from style.
+                StyleSheetEntryPtr pEntry
+                    = m_pImpl->GetStyleSheetTable()->FindStyleSheetByConvertedStyleName(
+                        sConvertedStyleName);
+                if (pEntry)
+                {
+                    boost::optional<PropertyMap::Property> pParaAutoBefore
+                        = pEntry->pProperties->getProperty(
+                            PROP_PARA_TOP_MARGIN_BEFORE_AUTO_SPACING);
+                    if (pParaAutoBefore)
+                        m_pImpl->GetTopContext()->Insert(PROP_PARA_TOP_MARGIN,
+                                                         uno::makeAny(static_cast<sal_Int32>(0)));
+                }
+            }
+        }
         //apply numbering to paragraph if it was set at the style, but only if the paragraph itself
         //does not specify the numbering
         if( !rContext->isSet(PROP_NUMBERING_RULES) ) // !contains
@@ -3080,6 +3100,8 @@ void DomainMapper::lcl_startShape(uno::Reference<drawing::XShape> const& xShape)
         // No context? Then this image should not appear directly inside the
         // document, just save it for later usage.
         m_pImpl->PushPendingShape(xShape);
+
+    m_pImpl->SetIsFirstParagraphInShape(true);
 }
 
 void DomainMapper::lcl_endShape( )
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index ff412635b6fa..de2a959f019d 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -464,6 +464,10 @@ void DomainMapper_Impl::SetIsFirstParagraphInSection( bool bIsFirst )
     m_bIsFirstParaInSection = bIsFirst;
 }
 
+void DomainMapper_Impl::SetIsFirstParagraphInShape(bool bIsFirst)
+{
+    m_bIsFirstParaInShape = bIsFirst;
+}
 
 void DomainMapper_Impl::SetIsDummyParaAddedForTableInSection( bool bIsAdded )
 {
@@ -1309,6 +1313,9 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap )
         SetIsLastParagraphInSection(false);
     }
 
+    if (m_bIsFirstParaInShape)
+        m_bIsFirstParaInShape = false;
+
     if (pParaContext)
     {
         // Reset the frame properties for the next paragraph
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 807f80164342..29b0cc22086f 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -503,6 +503,7 @@ private:
     /// If the current paragraph has any runs.
     bool                            m_bParaChanged;
     bool                            m_bIsFirstParaInSection;
+    bool                            m_bIsFirstParaInShape = false;
     bool                            m_bDummyParaAddedForTableInSection;
     bool                            m_bTextFrameInserted;
     bool                            m_bIsPreviousParagraphFramed;
@@ -593,6 +594,8 @@ public:
     bool GetIsLastSectionGroup() { return m_bIsLastSectionGroup;}
     void SetIsFirstParagraphInSection( bool bIsFirst );
     bool GetIsFirstParagraphInSection() { return m_bIsFirstParaInSection;}
+    void SetIsFirstParagraphInShape(bool bIsFirst);
+    bool GetIsFirstParagraphInShape() { return m_bIsFirstParaInShape; }
     void SetIsDummyParaAddedForTableInSection( bool bIsAdded );
     bool GetIsDummyParaAddedForTableInSection() { return m_bDummyParaAddedForTableInSection;}
     void SetIsTextFrameInserted( bool bIsInserted );


More information about the Libreoffice-commits mailing list