From b2c6d2d961a6113d0f111fab45ae12a40d389a23 Mon Sep 17 00:00:00 2001 From: László Németh Date: Thu, 5 Dec 2019 09:47:18 +0100 Subject: fdo#38414 tdf#44986: DOCX table import: handle gridBefore/After MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit without serious regressions, ie. losing the import of complex forms with multiple or nested tables. Complete the fix for tdf#116194 (DOCX import: fix missing tables with w:gridBefore) with handling gridAfter on DomainMapper level. This consists of also rejections (except their unit tests) of commit cf33af732ed0d3d553bb74636e3b14c55d44c153 (handle w:gridBefore by faking cells (fdo#38414)) and commit 1d1748d143ab4270a2ca1b5117852b1b1bb4c526 (Related: tdf#44986 DOCX import: handle w:gridAfter by faking cells) Change-Id: I31fa1de03bcdf42424fa5507fb5a3e06aa47107d Reviewed-on: https://gerrit.libreoffice.org/84517 Tested-by: Jenkins Reviewed-by: László Németh --- .../source/ooxml/OOXMLFastContextHandler.cxx | 83 ---------------------- .../source/ooxml/OOXMLFastContextHandler.hxx | 5 -- writerfilter/source/ooxml/factoryimpl_ns.py | 3 - writerfilter/source/ooxml/model.xml | 19 +---- 4 files changed, 2 insertions(+), 108 deletions(-) (limited to 'writerfilter/source/ooxml') diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index 6f7839d0512b..31fb07774552 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -1397,14 +1397,6 @@ void OOXMLFastContextHandlerTextTableRow::startRow() void OOXMLFastContextHandlerTextTableRow::endRow() { - if (mpGridAfter) - { - // Grid after is the same as grid before, the empty cells are just - // inserted after the real ones, not before. - handleGridBefore(mpGridAfter); - mpGridAfter = nullptr; - } - startParagraphGroup(); if (isForwardEvents()) @@ -1435,81 +1427,6 @@ void OOXMLFastContextHandlerTextTableRow::endRow() endParagraphGroup(); } -void OOXMLFastContextHandlerTextTableRow::handleGridAfter(const OOXMLValue::Pointer_t& rValue) -{ - if (OOXMLFastContextHandler* pTableRowProperties = getParent()) - { - if (OOXMLFastContextHandler* pTableRow = pTableRowProperties->getParent()) - // Save the value into the table row context, so it can be handled - // right before the end of the row. - pTableRow->setGridAfter(rValue); - } -} - -namespace { -OOXMLValue::Pointer_t fakeNoBorder() -{ - OOXMLPropertySet::Pointer_t pProps( new OOXMLPropertySet ); - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(0); - pProps->add(NS_ooxml::LN_CT_Border_val, pVal, OOXMLProperty::ATTRIBUTE); - OOXMLValue::Pointer_t pValue( new OOXMLPropertySetValue( pProps )); - return pValue; -} -} - -// Handle w:gridBefore here by faking necessary input that'll fake cells. I'm apparently -// not insane enough to find out how to add cells in dmapper. -void OOXMLFastContextHandlerTextTableRow::handleGridBefore( const OOXMLValue::Pointer_t& val ) -{ - // start removing: disable for w:gridBefore - if (!mpGridAfter) - return; - - int count = val->getInt(); - for( int i = 0; - i < count; - ++i ) - { - endOfParagraph(); - - if (isForwardEvents()) - { - // This whole part is OOXMLFastContextHandlerTextTableCell::endCell() . - OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); - { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); - pProps->add(NS_ooxml::LN_tblDepth, pVal, OOXMLProperty::SPRM); - } - { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); - pProps->add(NS_ooxml::LN_inTbl, pVal, OOXMLProperty::SPRM); - } - { - OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0); - pProps->add(NS_ooxml::LN_tblCell, pVal, OOXMLProperty::SPRM); - } - - mpStream->props(pProps.get()); - - // fake with no border - OOXMLPropertySet::Pointer_t pCellProps( new OOXMLPropertySet ); - { - OOXMLPropertySet::Pointer_t pBorderProps( new OOXMLPropertySet ); - static Id borders[] = { NS_ooxml::LN_CT_TcBorders_top, NS_ooxml::LN_CT_TcBorders_bottom, - NS_ooxml::LN_CT_TcBorders_start, NS_ooxml::LN_CT_TcBorders_end }; - for(sal_uInt32 border : borders) - pBorderProps->add(border, fakeNoBorder(), OOXMLProperty::SPRM); - OOXMLValue::Pointer_t pValue( new OOXMLPropertySetValue( pBorderProps )); - pCellProps->add(NS_ooxml::LN_CT_TcPrBase_tcBorders, pValue, OOXMLProperty::SPRM); - mpParserState->setCellProperties(pCellProps); - } - } - - sendCellProperties(); - endParagraphGroup(); - } -} - /* class OOXMLFastContextHandlerTextTable */ diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx index d5de5a778ee0..0da8b9cdff9c 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx @@ -186,8 +186,6 @@ public: virtual void setDefaultStringValue(); void sendPropertyToParent(); - OOXMLFastContextHandler* getParent() const { return mpParent; } - void setGridAfter(const OOXMLValue::Pointer_t& pGridAfter) { mpGridAfter = pGridAfter; } protected: OOXMLFastContextHandler * mpParent; @@ -226,7 +224,6 @@ protected: const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() const { return m_xContext;} bool inPositionV; - OOXMLValue::Pointer_t mpGridAfter; private: void operator =(OOXMLFastContextHandler const &) = delete; @@ -407,8 +404,6 @@ public: static void startRow(); void endRow(); - void handleGridBefore( const OOXMLValue::Pointer_t& val ); - void handleGridAfter(const OOXMLValue::Pointer_t& rValue); }; class OOXMLFastContextHandlerTextTable : public OOXMLFastContextHandler diff --git a/writerfilter/source/ooxml/factoryimpl_ns.py b/writerfilter/source/ooxml/factoryimpl_ns.py index 41fa714678c7..5bdf25c91478 100644 --- a/writerfilter/source/ooxml/factoryimpl_ns.py +++ b/writerfilter/source/ooxml/factoryimpl_ns.py @@ -440,9 +440,6 @@ def factoryChooseAction(actionNode): elif actionNode.getAttribute("action") in ("startRow", "endRow"): ret.append(" %sif (OOXMLFastContextHandlerTextTableRow* pTextTableRow = dynamic_cast(pHandler))" % extra_space) ret.append(" %s pTextTableRow->%s();" % (extra_space, actionNode.getAttribute("action"))) - elif actionNode.getAttribute("action") == "handleGridBefore" or actionNode.getAttribute("action") == "handleGridAfter": - ret.append(" %sif (OOXMLFastContextHandlerTextTableRow* pTextTableRow = dynamic_cast(pHandler))" % extra_space) - ret.append(" %s pTextTableRow->%s();" % (extra_space, actionNode.getAttribute("action"))) # tdf#111550 elif actionNode.getAttribute("action") in ("start_P_Tbl"): ret.append(" %sif (OOXMLFastContextHandlerTextTable* pTextTable = dynamic_cast(pHandler))" % extra_space) diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml index 17c8f5217fec..4c712e0b71fb 100644 --- a/writerfilter/source/ooxml/model.xml +++ b/writerfilter/source/ooxml/model.xml @@ -14445,7 +14445,7 @@ - + @@ -14473,16 +14473,6 @@ - - - - - - - - - - @@ -18405,6 +18395,7 @@ + @@ -18414,12 +18405,6 @@ - - - - - - -- cgit v1.2.3