[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.1' - 2 commits - writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Jan 5 10:31:15 UTC 2017


 writerfilter/source/dmapper/DomainMapper.cxx             |   39 ++++++++++++++-
 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 
 10 files changed, 80 insertions(+), 8 deletions(-)

New commits:
commit 53b2600e999ee80432b8302cd5141de04e365e0c
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-by: Aron Budea <aron.budea at collabora.com>

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index fc03eea..c736068 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -2528,6 +2528,11 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, 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
@@ -2568,6 +2573,13 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, 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 d13d509..57ce82d 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -976,7 +976,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");
@@ -1124,7 +1124,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 b5a34b8..a0020c8 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx
@@ -102,7 +102,7 @@ public:
      */
     void startTable(unsigned int nRows, unsigned int nDepth, 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 40c2e18..e1d4ebb 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -232,6 +232,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),
@@ -1023,6 +1025,7 @@ void DomainMapper_Impl::finishParagraph( 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 b602a70..7bb1ef6 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -818,6 +818,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 be5a618..cf1d900 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 2429f4d..327b946 100644
--- a/writerfilter/source/dmapper/TableManager.hxx
+++ b/writerfilter/source/dmapper/TableManager.hxx
@@ -319,6 +319,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
@@ -520,6 +522,7 @@ public:
     bool isIgnore() const;
 
 
+    void setTableStartsAtCellStart(bool bTableStartsAtCellStart);
 };
 
 }
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index 5f80c97..b483c1a 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -1297,6 +1297,17 @@ OOXMLFastContextHandlerTextTableCell::~OOXMLFastContextHandlerTextTableCell()
 
 void OOXMLFastContextHandlerTextTableCell::startCell()
 {
+    if (isForwardEvents())
+    {
+        OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
+        {
+            OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0);
+            OOXMLProperty::Pointer_t pProp(new OOXMLPropertyImpl(NS_ooxml::LN_tcStart, pVal, OOXMLPropertyImpl::SPRM));
+            pProps->add(pProp);
+        }
+
+        mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
+    }
 }
 
 void OOXMLFastContextHandlerTextTableCell::endCell()
@@ -1322,6 +1333,11 @@ void OOXMLFastContextHandlerTextTableCell::endCell()
                 (new OOXMLPropertyImpl(NS_ooxml::LN_tblCell, pVal, OOXMLPropertyImpl::SPRM));
             pProps->add(pProp);
         }
+        {
+            OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0);
+            OOXMLProperty::Pointer_t pProp(new OOXMLPropertyImpl(NS_ooxml::LN_tcEnd, pVal, OOXMLPropertyImpl::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 38becc9..e1c4418 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
@@ -395,7 +395,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 4f4c113..bbff988 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"/>
commit 89f7f15a94904214663b3caae7b721779d48bcef
Author: Justin Luth <justin_luth at sil.org>
Date:   Sat Oct 22 15:20:38 2016 +0300

    tdf#89377 writerfilter: table honors ParaStyle break-before-page
    
    .doc format handled in prior patch.
    
    This import .docx patch checks to see if the very first paragraph style
    in a table is set with a page-break, and if so, then transfers
    that setting to the table itself.
    
    Change-Id: Ibb87eeb0fbdb7fdd84ef43dd1d7e0a6f8e1f8ad5
    Reviewed-by: Aron Budea <aron.budea at collabora.com>

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 7f2d246..fc03eea 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -2527,7 +2527,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext )
     }
     break;
     case NS_ooxml::LN_tblStart:
-
+    {
         /*
          * Hack for Importing Section Properties
          * LO is not able to import section properties if first element in the
@@ -2539,8 +2539,31 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext )
         {
             m_pImpl->AddDummyParaForTableInSection();
         }
-        m_pImpl->m_nTableDepth++;
 
+        // if first paragraph style in table has break-before-page, transfer that setting to the table itself.
+        if( m_pImpl->m_nTableDepth == 0 )
+        {
+            const uno::Any aBreakType = uno::makeAny(style::BreakType_PAGE_BEFORE);
+            const PropertyMapPtr pParagraphProps = m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH);
+            if( pParagraphProps && pParagraphProps->isSet(PROP_PARA_STYLE_NAME) )
+            {
+                StyleSheetEntryPtr pStyle = nullptr;
+                OUString sStyleName;
+                pParagraphProps->getProperty(PROP_PARA_STYLE_NAME)->second >>= sStyleName;
+                if( !sStyleName.isEmpty() && GetStyleSheetTable() )
+                    pStyle = GetStyleSheetTable()->FindStyleSheetByStyleName( sStyleName );
+
+                if( pStyle && pStyle->pProperties
+                    && pStyle->pProperties->isSet(PROP_BREAK_TYPE)
+                    && pStyle->pProperties->getProperty(PROP_BREAK_TYPE)->second == aBreakType )
+                {
+                    pParagraphProps->Insert(PROP_BREAK_TYPE, aBreakType);
+                }
+            }
+        }
+
+        m_pImpl->m_nTableDepth++;
+    }
     break;
     case NS_ooxml::LN_tblEnd:
         m_pImpl->m_nTableDepth--;


More information about the Libreoffice-commits mailing list