From 0ba2229a57527e78f237119efa413f122c9ca74b Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 30 Aug 2016 09:14:47 +0200 Subject: Related: tdf#44986 DOCX import: handle w:gridAfter by faking cells This is similar to the w:gridBefore handling code introduced in commit cf33af732ed0d3d553bb74636e3b14c55d44c153 (handle w:gridBefore by faking cells (fdo#38414), 2014-04-23), except that the fake cells here are inserted after the real ones, not before. Change-Id: I4c03bd49e52016a58e0e002ae85dede6a96e5f55 Reviewed-on: https://gerrit.libreoffice.org/28487 Reviewed-by: Miklos Vajna Tested-by: Jenkins (cherry picked from commit 1d1748d143ab4270a2ca1b5117852b1b1bb4c526) Reviewed-on: https://gerrit.libreoffice.org/28624 Reviewed-by: jan iversen Tested-by: jan iversen --- writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 19 +++++++++++++++++++ writerfilter/source/ooxml/OOXMLFastContextHandler.hxx | 4 ++++ writerfilter/source/ooxml/factoryimpl_ns.py | 2 +- writerfilter/source/ooxml/model.xml | 12 +++++++++--- 4 files changed, 33 insertions(+), 4 deletions(-) (limited to 'writerfilter') diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index 5edac7a4f46d..645ade6f7b98 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -1331,6 +1331,14 @@ 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()) @@ -1364,6 +1372,17 @@ 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); + } +} + // 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 ) diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx index 34c118dcc3d3..f713fcfe5414 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx @@ -188,6 +188,8 @@ public: virtual void setDefaultStringValue(); void sendPropertyToParent(); + OOXMLFastContextHandler* getParent() const { return mpParent; } + void setGridAfter(const OOXMLValue::Pointer_t& pGridAfter) { mpGridAfter = pGridAfter; } protected: OOXMLFastContextHandler * mpParent; @@ -222,6 +224,7 @@ protected: const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() { return m_xContext;} bool inPositionV; + OOXMLValue::Pointer_t mpGridAfter; private: void operator =(OOXMLFastContextHandler &) = delete; @@ -403,6 +406,7 @@ public: static void startRow(); void endRow(); void handleGridBefore( const OOXMLValue::Pointer_t& val ); + void handleGridAfter(const OOXMLValue::Pointer_t& rValue); private: static OOXMLProperty::Pointer_t fakeNoBorder( Id id ); }; diff --git a/writerfilter/source/ooxml/factoryimpl_ns.py b/writerfilter/source/ooxml/factoryimpl_ns.py index 6ad9a83038a0..d9baaa1c3613 100644 --- a/writerfilter/source/ooxml/factoryimpl_ns.py +++ b/writerfilter/source/ooxml/factoryimpl_ns.py @@ -439,7 +439,7 @@ 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": + 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"))) elif actionNode.getAttribute("action") in ("sendProperty", "handleHyperlink"): diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml index 32935c98fb83..61438c3d1f58 100644 --- a/writerfilter/source/ooxml/model.xml +++ b/writerfilter/source/ooxml/model.xml @@ -14382,7 +14382,7 @@ - + @@ -14415,6 +14415,11 @@ + + + + + @@ -18298,8 +18303,6 @@ - - @@ -18312,6 +18315,9 @@ + + + -- cgit v1.2.3