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

Miklos Vajna vmiklos at collabora.co.uk
Tue Nov 8 09:52:08 UTC 2016


 sw/qa/extras/ooxmlexport/data/tdf79329.docx              |binary
 sw/qa/extras/ooxmlexport/ooxmlexport9.cxx                |    8 +++++++
 writerfilter/source/dmapper/DomainMapper.cxx             |   12 +++++++++++
 writerfilter/source/dmapper/DomainMapperTableHandler.cxx |    7 ++++--
 writerfilter/source/dmapper/DomainMapperTableHandler.hxx |    2 -
 writerfilter/source/dmapper/DomainMapper_Impl.cxx        |    3 ++
 writerfilter/source/dmapper/DomainMapper_Impl.hxx        |    4 +++
 writerfilter/source/dmapper/TableManager.cxx             |   10 +++++++--
 writerfilter/source/dmapper/TableManager.hxx             |    3 ++
 writerfilter/source/ooxml/OOXMLFastContextHandler.cxx    |   16 +++++++++++++++
 writerfilter/source/ooxml/OOXMLFastContextHandler.hxx    |    2 -
 writerfilter/source/ooxml/model.xml                      |    2 +
 12 files changed, 63 insertions(+), 6 deletions(-)

New commits:
commit c1eebcdac9f2b289fd363399130c485ca5ff444c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Nov 8 09:11:33 2016 +0100

    tdf#79329 DOCX import: fix missing outer table with floattable at cell start
    
    The bug document has a normal table, then its C1 cell starts with a
    nested table, which is floating. The problem is that converting the
    nested table to a textframe invalidates the start text range of the C1
    cell in the outer table we store, so the conversion of the outer table
    from text to table fails.
    
    This never worked, so to avoid the regression just don't convert inner
    floating tables to textframes when they're anchored at the cell start.
    A more general fix in the future can be addressing the actual
    invalidation of the cell start/end text ranges, and then this specific
    fix will not be necessary anymore.
    
    Change-Id: I12cefa41977cf719b07b0fb3ef9ec423c17ef3b1
    Reviewed-on: https://gerrit.libreoffice.org/30685
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf79329.docx b/sw/qa/extras/ooxmlexport/data/tdf79329.docx
new file mode 100644
index 0000000..142f295
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf79329.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
index 48bd118..a445ea2 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
@@ -110,6 +110,14 @@ DECLARE_OOXMLEXPORT_TEST(testTdf103573, "tdf103573.docx")
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Not centered horizontally relatively to right page border", text::RelOrientation::PAGE_RIGHT, nValue);
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf79329, "tdf79329.docx")
+{
+    uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY);
+    // This was 1: only the inner, not the outer table was created.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xTables->getCount());
+}
+
 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 0cb770f..18c991b 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -2535,6 +2535,11 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
     break;
     case NS_ooxml::LN_tblStart:
     {
+        if (m_pImpl->hasTableManager())
+        {
+            bool bTableStartsAtCellStart = m_pImpl->m_nTableDepth > 0 && m_pImpl->m_nTableCellDepth > m_pImpl->m_nLastTableCellParagraphDepth + 1;
+            m_pImpl->getTableManager().setTableStartsAtCellStart(bTableStartsAtCellStart);
+        }
         /*
          * Hack for Importing Section Properties
          * LO is not able to import section properties if first element in the
@@ -2575,6 +2580,13 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
     case NS_ooxml::LN_tblEnd:
         m_pImpl->m_nTableDepth--;
     break;
+    case NS_ooxml::LN_tcStart:
+        m_pImpl->m_nTableCellDepth++;
+    break;
+    case NS_ooxml::LN_tcEnd:
+        m_pImpl->m_nTableCellDepth--;
+        m_pImpl->m_nLastTableCellParagraphDepth = 0;
+    break;
     case NS_ooxml::LN_glow_glow:
     case NS_ooxml::LN_shadow_shadow:
     case NS_ooxml::LN_reflection_reflection:
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 99087d5..9cdfe1c 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -982,7 +982,7 @@ static void lcl_ApplyCellParaProps(uno::Reference<table::XCell> const& xCell,
     }
 }
 
-void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel)
+void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel, bool bTableStartsAtCellStart)
 {
 #ifdef DEBUG_WRITERFILTER
     TagLogger::getInstance().startElement("tablehandler.endTable");
@@ -1127,7 +1127,10 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel)
             {
                 // m_xText points to the body text, get the current xText from m_rDMapper_Impl, in case e.g. we would be in a header.
                 uno::Reference<text::XTextAppendAndConvert> xTextAppendAndConvert(m_rDMapper_Impl.GetTopTextAppend(), uno::UNO_QUERY);
-                if (xTextAppendAndConvert.is())
+                // Only execute the conversion if the table is not anchored at
+                // the start of an outer table cell, that's not yet
+                // implemented.
+                if (xTextAppendAndConvert.is() && !bTableStartsAtCellStart)
                     xTextAppendAndConvert->convertToTextFrame(xStart, xEnd, comphelper::containerToSequence(aFrameProperties));
             }
         }
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx
index 5ae0700..f779387 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx
@@ -94,7 +94,7 @@ public:
      */
     void startTable(unsigned int nDepth, const TablePropertyMapPtr& pProps);
     /// Handle end of table.
-    void endTable(unsigned int nestedTableLevel);
+    void endTable(unsigned int nestedTableLevel, bool bTableStartsAtCellStart);
     /**
        Handle start of row.
 
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 1408a62..0c3a144 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -233,6 +233,8 @@ DomainMapper_Impl::DomainMapper_Impl(
         m_bIsNewDoc(!rMediaDesc.getUnpackedValueOrDefault("InsertMode", false)),
         m_bInTableStyleRunProps(false),
         m_nTableDepth(0),
+        m_nTableCellDepth(0),
+        m_nLastTableCellParagraphDepth(0),
         m_bHasFtnSep(false),
         m_bIgnoreNextPara(false),
         m_bIgnoreNextTab(false),
@@ -1034,6 +1036,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap )
     TagLogger::getInstance().startElement("finishParagraph");
 #endif
 
+    m_nLastTableCellParagraphDepth = m_nTableCellDepth;
     ParagraphPropertyMap* pParaContext = dynamic_cast< ParagraphPropertyMap* >( pPropertyMap.get() );
     if (m_aTextAppendStack.empty())
         return;
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 84afc50..c69e114 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -820,6 +820,10 @@ public:
      * inTbl SPRM or not).
      */
     sal_Int32 m_nTableDepth;
+    /// Raw table cell depth.
+    sal_Int32 m_nTableCellDepth;
+    /// Table cell depth of the last finished paragraph.
+    sal_Int32 m_nLastTableCellParagraphDepth;
 
     /// If the document has a footnote separator.
     bool m_bHasFtnSep;
diff --git a/writerfilter/source/dmapper/TableManager.cxx b/writerfilter/source/dmapper/TableManager.cxx
index bbb2806..c14ec25 100644
--- a/writerfilter/source/dmapper/TableManager.cxx
+++ b/writerfilter/source/dmapper/TableManager.cxx
@@ -314,7 +314,7 @@ void TableManager::resolveCurrentTable()
                 mpTableDataHandler->endRow();
             }
 
-            mpTableDataHandler->endTable(mTableDataStack.size() - 1);
+            mpTableDataHandler->endTable(mTableDataStack.size() - 1, m_bTableStartsAtCellStart);
         }
         catch (css::uno::Exception const& e)
         {
@@ -454,8 +454,14 @@ void TableManager::cellDepth(sal_uInt32 nDepth)
     mnTableDepthNew = nDepth;
 }
 
+void TableManager::setTableStartsAtCellStart(bool bTableStartsAtCellStart)
+{
+    m_bTableStartsAtCellStart = bTableStartsAtCellStart;
+}
+
 TableManager::TableManager()
-    : mnTableDepthNew(0), mnTableDepth(0), mbKeepUnfinishedRow(false)
+    : mnTableDepthNew(0), mnTableDepth(0), mbKeepUnfinishedRow(false),
+      m_bTableStartsAtCellStart(false)
 {
     setRowEnd(false);
     setInCell(false);
diff --git a/writerfilter/source/dmapper/TableManager.hxx b/writerfilter/source/dmapper/TableManager.hxx
index d9d9826..8aad021 100644
--- a/writerfilter/source/dmapper/TableManager.hxx
+++ b/writerfilter/source/dmapper/TableManager.hxx
@@ -275,6 +275,8 @@ private:
     std::stack<TableData::Pointer_t> mTableDataStack;
     RowData::Pointer_t mpUnfinishedRow;
     bool mbKeepUnfinishedRow;
+    /// If this is a nested table, does it start at cell start?
+    bool m_bTableStartsAtCellStart;
 
     /**
        handler for resolveCurrentTable
@@ -476,6 +478,7 @@ public:
     bool isIgnore() const;
 
 
+    void setTableStartsAtCellStart(bool bTableStartsAtCellStart);
 };
 
 }
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index 50fcef3..17ce14f 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -1306,6 +1306,17 @@ OOXMLFastContextHandlerTextTableCell::~OOXMLFastContextHandlerTextTableCell()
 
 void OOXMLFastContextHandlerTextTableCell::startCell()
 {
+    if (isForwardEvents())
+    {
+        OOXMLPropertySet * pProps = new OOXMLPropertySet;
+        {
+            OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0);
+            OOXMLProperty::Pointer_t pProp(new OOXMLProperty(NS_ooxml::LN_tcStart, pVal, OOXMLProperty::SPRM));
+            pProps->add(pProp);
+        }
+
+        mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
+    }
 }
 
 void OOXMLFastContextHandlerTextTableCell::endCell()
@@ -1328,6 +1339,11 @@ void OOXMLFastContextHandlerTextTableCell::endCell()
             OOXMLProperty::Pointer_t pProp(new OOXMLProperty(NS_ooxml::LN_tblCell, pVal, OOXMLProperty::SPRM));
             pProps->add(pProp);
         }
+        {
+            OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0);
+            OOXMLProperty::Pointer_t pProp(new OOXMLProperty(NS_ooxml::LN_tcEnd, pVal, OOXMLProperty::SPRM));
+            pProps->add(pProp);
+        }
 
         mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
     }
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
index 0550eec..d761b46 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
@@ -392,7 +392,7 @@ public:
 
     virtual std::string getType() const override { return "TextTableCell"; }
 
-    static void startCell();
+    void startCell();
     void endCell();
 };
 
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index 89c8af8..3040eb9 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -40,6 +40,8 @@
   <token tokenid="ooxml:object"/>
   <token tokenid="ooxml:tblStart"/>
   <token tokenid="ooxml:tblEnd"/>
+  <token tokenid="ooxml:tcStart"/>
+  <token tokenid="ooxml:tcEnd"/>
 
   <!-- These are not directly generated from OOXML XML elements / attributes, need to clean them up in the future. -->
   <token tokenid="ooxml:tblDepth"/>


More information about the Libreoffice-commits mailing list