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

Miklos Vajna vmiklos at collabora.co.uk
Tue Oct 1 08:28:26 PDT 2013


 sw/qa/extras/ooxmlimport/data/bnc779620.docx             |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx                 |   10 ++++++
 vcl/unx/generic/app/saldisp.cxx                          |   21 +++++++++---
 writerfilter/source/dmapper/DomainMapperTableHandler.cxx |   25 ++++++---------
 writerfilter/source/dmapper/DomainMapper_Impl.hxx        |   18 ++++++++++
 writerfilter/source/dmapper/PropertyMap.cxx              |   15 +++++++++
 6 files changed, 70 insertions(+), 19 deletions(-)

New commits:
commit bbef85c157169efa958ea1014d91d467cb243e6f
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

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 f2ab2c4..b1c4583 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -137,6 +137,7 @@ public:
     void testDefaultSectBreakCols();
     void testFdo69636();
     void testChartProp();
+    void testBnc779620();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
@@ -238,6 +239,7 @@ void Test::run()
         {"default-sect-break-cols.docx", &Test::testDefaultSectBreakCols},
         {"fdo69636.docx", &Test::testFdo69636},
         {"chart-prop.docx", &Test::testChartProp},
+        {"bnc779620.docx", &Test::testBnc779620},
     };
     header();
     for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
@@ -1584,6 +1586,14 @@ void Test::testChartProp()
     CPPUNIT_ASSERT_EQUAL(sal_Int32(8886), getProperty<sal_Int32>(xPropertySet, "Height"));
 }
 
+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 b32351a..f65cfca 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -824,19 +824,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)
         {
@@ -923,7 +911,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 9210184..fc2c7c2 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
@@ -710,6 +726,8 @@ public:
     /// If the next newline should be ignored, used by the special footnote separator paragraph.
     bool m_bIgnoreNextPara;
     bool m_bFrameBtLr; ///< Bottom to top, left to right text frame direction is requested for the current text frame.
+    /// 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 86382bb..c016a41 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -877,6 +877,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 )
     {
commit e85eadc888285a42561cc52133172cf5f4317da2
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Oct 1 16:23:31 2013 +0100

    Resolves: rhbz#1010995 div by 0 on some bizarre corner case
    
    Change-Id: Ief192ac36df7f62c9e157dce9050b37297ccf0a4

diff --git a/vcl/unx/generic/app/saldisp.cxx b/vcl/unx/generic/app/saldisp.cxx
index c7cf6e4..713e9c3 100644
--- a/vcl/unx/generic/app/saldisp.cxx
+++ b/vcl/unx/generic/app/saldisp.cxx
@@ -596,11 +596,22 @@ void SalDisplay::Init()
     }
     if( mbExactResolution == false )
     {
-        aResolution_     =
-            Pair( DPI( WidthOfScreen( DefaultScreenOfDisplay( pDisp_ ) ),
-                       DisplayWidthMM ( pDisp_, m_nXDefaultScreen.getXScreen() ) ),
-                  DPI( HeightOfScreen( DefaultScreenOfDisplay( pDisp_ ) ),
-                       DisplayHeightMM( pDisp_, m_nXDefaultScreen.getXScreen() ) ) );
+        int nDisplayWidth = DisplayWidthMM ( pDisp_, m_nXDefaultScreen.getXScreen() );
+        int nDisplayHeight = DisplayHeightMM( pDisp_, m_nXDefaultScreen.getXScreen() );
+
+        if (nDisplayHeight == 0 || nDisplayWidth == 0)
+        {
+            aResolution_ = Pair( 96, 96 );
+            SAL_WARN("vcl", "screen width/height reported as 0!, using fallback 96dpi");
+        }
+        else
+        {
+            aResolution_     =
+                Pair( DPI( WidthOfScreen( DefaultScreenOfDisplay( pDisp_ ) ),
+                           nDisplayWidth ),
+                      DPI( HeightOfScreen( DefaultScreenOfDisplay( pDisp_ ) ),
+                           nDisplayHeight ) );
+        }
     }
 
     nMaxRequestSize_    = XExtendedMaxRequestSize( pDisp_ ) * 4;


More information about the Libreoffice-commits mailing list