[Libreoffice-commits] core.git: Branch 'distro/suse/suse-4.0' - sw/qa writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Wed Oct 2 01:43:06 PDT 2013


 sw/qa/extras/ooxmlimport/data/bnc779620.docx             |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx                 |   10 ++++++
 writerfilter/source/dmapper/DomainMapperTableHandler.cxx |   25 ++++++---------
 writerfilter/source/dmapper/DomainMapper_Impl.hxx        |   18 ++++++++++
 writerfilter/source/dmapper/PropertyMap.cxx              |   15 +++++++++
 5 files changed, 54 insertions(+), 14 deletions(-)

New commits:
commit 8ae425160d4376a1453b4e80cb2aeded1b7b4d18
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Oct 1 16:57:56 2013 +0200

    bnc#779620 DOCX import: try harder to convert floating tables to text frames
    
    Since 78d1f1c2835b9fae0f91ed771fc1d594c7817502, we convert floating
    tables to text frames only in case it's possible that there will be
    wrapping, to give better results for multi-page tables, which are
    multi-page, and technically floating ones, but that has no effect on the
    layout.
    
    The problem was that we try to do this decision too early, effectively
    the page width and margins were counted from the default letter size,
    instead of the actual values, which did not arrive at the time of the
    decision. Fix this by moving this logic at the section end.
    
    Change-Id: Ic1fbceb54c8ec223ed01836fafe6220bb3b2410a
    (cherry picked from commit bbef85c157169efa958ea1014d91d467cb243e6f)
    
    Conflicts:
    	sw/qa/extras/ooxmlimport/ooxmlimport.cxx
    	writerfilter/source/dmapper/DomainMapper_Impl.hxx

diff --git a/sw/qa/extras/ooxmlimport/data/bnc779620.docx b/sw/qa/extras/ooxmlimport/data/bnc779620.docx
new file mode 100644
index 0000000..23c126d
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/bnc779620.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 648baba..33c0ece 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -138,6 +138,7 @@ public:
     void testFdo68607();
     void testVmlTextVerticalAdjust();
     void testGroupshapeSdt();
+    void testBnc779620();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
@@ -224,6 +225,7 @@ void Test::run()
         {"fdo68607.docx", &Test::testFdo68607},
         {"vml-text-vertical-adjust.docx", &Test::testVmlTextVerticalAdjust},
         {"groupshape-sdt.docx", &Test::testGroupshapeSdt},
+        {"bnc779620.docx", &Test::testBnc779620},
     };
     for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
     {
@@ -1398,6 +1400,14 @@ void Test::testGroupshapeSdt()
     CPPUNIT_ASSERT_EQUAL(sal_Int32(20), getProperty<sal_Int32>(getRun(getParagraphOfText(1, xShape->getText()), 1), "CharKerning"));
 }
 
+void Test::testBnc779620()
+{
+    // The problem was that the floating table was imported as a non-floating one.
+    uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 571ef77..1facd2a 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -765,19 +765,7 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel)
         uno::Reference<text::XTextRange> xStart;
         uno::Reference<text::XTextRange> xEnd;
 
-        bool bNoFly = false;
-        if (SectionPropertyMap* pSectionContext = m_rDMapper_Impl.GetSectionContext())
-        {
-            sal_Int32 nTextAreaWidth = pSectionContext->GetPageWidth() - pSectionContext->GetLeftMargin() - pSectionContext->GetRightMargin();
-            sal_Int32 nTableWidth = 0;
-            m_aTableProperties->getValue( TablePropertyMap::TABLE_WIDTH, nTableWidth );
-            // If the table is wider than the text area, then don't create a fly
-            // for the table: no wrapping will be performed anyway, but multi-page
-            // tables will be broken.
-            bNoFly = nTableWidth >= nTextAreaWidth;
-        }
-
-        bool bFloating = aFrameProperties.hasElements() && !bNoFly;
+        bool bFloating = aFrameProperties.hasElements();
         // Additional checks: if we can do this.
         if (bFloating && (*m_pTableSeq)[0].getLength() > 0 && (*m_pTableSeq)[0][0].getLength() > 0)
         {
@@ -864,7 +852,16 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel)
             // A non-zero left margin would move the table out of the frame, move the frame itself instead.
             xTableProperties->setPropertyValue("LeftMargin", uno::makeAny(sal_Int32(0)));
 
-            uno::Reference< text::XTextContent > xFrame = m_xText->convertToTextFrame(xStart, xEnd, aFrameProperties);
+            // In case the document ends with a table, we're called after
+            // SectionPropertyMap::CloseSectionGroup(), so we'll have no idea
+            // about the text area width, nor can fix this by delaying the text
+            // frame conversion: just do it here.
+            sal_Int32 nTableWidth = 0;
+            m_aTableProperties->getValue(TablePropertyMap::TABLE_WIDTH, nTableWidth);
+            if (m_rDMapper_Impl.GetSectionContext())
+                m_rDMapper_Impl.m_aPendingFloatingTables.push_back(FloatingTableInfo(xStart, xEnd, aFrameProperties, nTableWidth));
+            else
+                m_xText->convertToTextFrame(xStart, xEnd, aFrameProperties);
         }
     }
 
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index ccca0dc..fe5ac78 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -281,6 +281,22 @@ struct LineNumberSettings
 
 };
 
+/// Contains information about a table that will be potentially converted to a floating one at the section end.
+struct FloatingTableInfo
+{
+    uno::Reference<text::XTextRange> m_xStart;
+    uno::Reference<text::XTextRange> m_xEnd;
+    uno::Sequence<beans::PropertyValue> m_aFrameProperties;
+    sal_Int32 m_nTableWidth;
+
+    FloatingTableInfo(uno::Reference<text::XTextRange> xStart, uno::Reference<text::XTextRange> xEnd, uno::Sequence<beans::PropertyValue> aFrameProperties, sal_Int32 nTableWidth)
+        : m_xStart(xStart),
+        m_xEnd(xEnd),
+        m_aFrameProperties(aFrameProperties),
+        m_nTableWidth(nTableWidth)
+    {
+    }
+};
 
 class DomainMapper;
 class WRITERFILTER_DLLPRIVATE DomainMapper_Impl
@@ -692,6 +708,8 @@ public:
      * PFInTable SPRM or not).
      */
     sal_Int32 m_nTableDepth;
+    /// Pending floating tables: they may be converted to text frames at the section end.
+    std::vector<FloatingTableInfo> m_aPendingFloatingTables;
 };
 } //namespace dmapper
 } //namespace writerfilter
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index 62c6272..38f6c61 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -845,6 +845,21 @@ void SectionPropertyMap::HandleMarginsHeaderFooter(DomainMapper_Impl& rDM_Impl)
 
 void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
 {
+    // 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;
+    sal_Int32 nTextAreaWidth = GetPageWidth() - GetLeftMargin() - GetRightMargin();
+    uno::Reference<text::XTextAppendAndConvert> xBodyText( rDM_Impl.GetBodyText(), uno::UNO_QUERY );
+    for (size_t i = 0; i < rPendingFloatingTables.size(); ++i)
+    {
+        FloatingTableInfo& rInfo = rPendingFloatingTables[i];
+        // If the table is wider than the text area, then don't create a fly
+        // for the table: no wrapping will be performed anyway, but multi-page
+        // tables will be broken.
+        if (rInfo.m_nTableWidth < nTextAreaWidth)
+            xBodyText->convertToTextFrame(rInfo.m_xStart, rInfo.m_xEnd, rInfo.m_aFrameProperties);
+    }
+    rPendingFloatingTables.clear();
+
     PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     if( m_nLnnMod )
     {


More information about the Libreoffice-commits mailing list