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

Miklos Vajna vmiklos at collabora.co.uk
Tue May 16 16:57:44 UTC 2017


 sw/qa/extras/ooxmlexport/data/tdf107889.docx             |binary
 sw/qa/extras/ooxmlexport/ooxmlexport9.cxx                |    8 ++++++
 writerfilter/source/dmapper/DomainMapperTableHandler.cxx |    3 ++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx        |    2 +
 writerfilter/source/dmapper/DomainMapper_Impl.hxx        |    5 ++++
 writerfilter/source/dmapper/PropertyMap.cxx              |   18 ++++++++++-----
 writerfilter/source/dmapper/PropertyMap.hxx              |    2 -
 7 files changed, 31 insertions(+), 7 deletions(-)

New commits:
commit 659c0227a50d298780d72902314e03df8824bc06
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue May 16 15:26:53 2017 +0200

    tdf#107889 DOCX import: consider page breaks for multi-page floattables
    
    This is the DOCX equivalent of commit
    6aba29576df7a2a40e54040d4dd09d94d6594741 (tdf#107773 DOC import:
    consider page breaks for multi-page floattables, 2017-05-11): a specific
    case where it's clearly superior to import a multi-page floating table
    as a multi-page one, rather than a floating one.
    
    Change-Id: I71a92d2b10e52e505665831caacad2948d22b4e1
    Reviewed-on: https://gerrit.libreoffice.org/37683
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf107889.docx b/sw/qa/extras/ooxmlexport/data/tdf107889.docx
new file mode 100644
index 000000000000..452c4aa13063
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf107889.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
index 73077b4fe40a..ce8a77a02c8c 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
@@ -499,6 +499,14 @@ DECLARE_OOXMLEXPORT_TEST(testTdf100072, "tdf100072.docx")
     CPPUNIT_ASSERT(getShape(1)->getPosition().X > 0);
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf107889, "tdf107889.docx")
+{
+    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
+    // This was 1, multi-page table was imported as a floating one.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), xDrawPage->getCount());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 7ed678863e37..db2c4fa4d5c9 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -1178,6 +1178,9 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel, bool bTab
                     xTextAppendAndConvert->convertToTextFrame(xStart, xEnd, comphelper::containerToSequence(aFrameProperties));
             }
         }
+
+        // We're right after a table conversion.
+        m_rDMapper_Impl.m_bConvertedTable = true;
     }
 
     m_aTableProperties.reset();
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index af1991b67e44..fc076998fa9b 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1227,6 +1227,8 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap )
 
                     xTextRange = xTextAppend->finishParagraph( comphelper::containerToSequence(aProperties) );
                     m_xPreviousParagraph.set(xTextRange, uno::UNO_QUERY);
+                    // We're no longer right after a table conversion.
+                    m_bConvertedTable = false;
 
                     if (xCursor.is())
                     {
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index b43d310db917..65274fcc7d46 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -308,6 +308,8 @@ struct FloatingTableInfo
     css::uno::Reference<css::text::XTextRange> m_xEnd;
     css::uno::Sequence<css::beans::PropertyValue> m_aFrameProperties;
     sal_Int32 m_nTableWidth;
+    /// Break type of the section that contains this table.
+    sal_Int32 m_nBreakType = -1;
 
     FloatingTableInfo(css::uno::Reference<css::text::XTextRange> const& xStart,
             css::uno::Reference<css::text::XTextRange> const& xEnd,
@@ -753,6 +755,9 @@ public:
 
     DeletableTabStop                m_aCurrentTabStop;
 
+    /// If we're right after the end of a table.
+    bool m_bConvertedTable = false;
+
     bool IsOOXMLImport() const { return m_eDocumentType == SourceDocumentType::OOXML; }
 
     bool IsRTFImport() const { return m_eDocumentType == SourceDocumentType::RTF; }
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index 8e308940e7e0..3df7c864cd55 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -1021,12 +1021,17 @@ void SectionPropertyMap::HandleMarginsHeaderFooter( bool bFirstPage, DomainMappe
     PrepareHeaderFooterProperties( bFirstPage );
 }
 
-bool SectionPropertyMap::FloatingTableConversion( FloatingTableInfo& rInfo )
+bool SectionPropertyMap::FloatingTableConversion( DomainMapper_Impl& rDM_Impl, FloatingTableInfo& rInfo )
 {
     // Note that this is just a list of heuristics till sw core can have a
     // table that is floating and can span over multiple pages at the same
     // time.
 
+    // If there is an explicit section break right after a table, then there
+    // will be no wrapping anyway.
+    if (rDM_Impl.m_bConvertedTable && !rDM_Impl.GetIsLastSectionGroup() && rInfo.m_nBreakType == NS_ooxml::LN_Value_ST_SectionMark_nextPage)
+        return false;
+
     sal_Int32 nPageWidth = GetPageWidth();
     sal_Int32 nTextAreaWidth = nPageWidth - GetLeftMargin() - GetRightMargin();
     // Count the layout width of the table.
@@ -1113,12 +1118,17 @@ void SectionPropertyMap::InheritOrFinalizePageStyles( DomainMapper_Impl& rDM_Imp
 
 void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
 {
+    // The default section type is nextPage.
+    if ( m_nBreakType == -1 )
+        m_nBreakType = NS_ooxml::LN_Value_ST_SectionMark_nextPage;
+
     // Text area width is known at the end of a section: decide if tables should be converted or not.
     std::vector<FloatingTableInfo>& rPendingFloatingTables = rDM_Impl.m_aPendingFloatingTables;
     uno::Reference<text::XTextAppendAndConvert> xBodyText( rDM_Impl.GetBodyText(), uno::UNO_QUERY );
     for ( FloatingTableInfo & rInfo : rPendingFloatingTables )
     {
-        if ( FloatingTableConversion( rInfo ) )
+        rInfo.m_nBreakType = m_nBreakType;
+        if ( FloatingTableConversion( rDM_Impl, rInfo ) )
             xBodyText->convertToTextFrame( rInfo.m_xStart, rInfo.m_xEnd, rInfo.m_aFrameProperties );
     }
     rPendingFloatingTables.clear();
@@ -1151,10 +1161,6 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
         }
     }
 
-    // The default section type is nextPage.
-    if ( m_nBreakType == -1 )
-        m_nBreakType = NS_ooxml::LN_Value_ST_SectionMark_nextPage;
-
     // depending on the break type no page styles should be created
     // Continuous sections usually create only a section, and not a new page style
     const bool bTreatAsContinuous = m_nBreakType == NS_ooxml::LN_Value_ST_SectionMark_nextPage
diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx
index a45bef692b70..96883755159f 100644
--- a/writerfilter/source/dmapper/PropertyMap.hxx
+++ b/writerfilter/source/dmapper/PropertyMap.hxx
@@ -284,7 +284,7 @@ private:
                                    sal_uInt32 nLineWidth );
 
     // Determines if conversion of a given floating table is wanted or not.
-    bool FloatingTableConversion( FloatingTableInfo& rInfo );
+    bool FloatingTableConversion( DomainMapper_Impl& rDM_Impl, FloatingTableInfo& rInfo );
 
 public:
     enum PageType


More information about the Libreoffice-commits mailing list