diff options
author | Bakos Attila <bakos.attilakaroly@nisz.hu> | 2020-01-16 13:45:47 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-01-17 12:51:52 +0100 |
commit | 14ad64270e4fbca3c24da6f55f260b1fb229556a (patch) | |
tree | dd783e9a7c290cd0bcc437ab33c265c63ef547c5 | |
parent | f7e071a00542c414a7e9d7bcf4434d908f225e59 (diff) |
tdf#129888 DOCX shape import: handle o:allowincell
(VML) and layoutInCell (DrawingML) attributes to fix
regressions caused by commit 10f29d8bf05d44ca8bc11d34d1294ec17f8ac0f1
(tdf#87569 tdf#109411 DOCX import: fix shape anchor in tables).
Position of shapes anchored to tables is calculated from
the cell margin only if the previous attributes allow that.
Change-Id: Ifcfcb7f4959aea522dd45dff00cefd1bb9f4edda
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86922
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf129888dml.docx | bin | 0 -> 17003 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf129888vml.docx | bin | 0 -> 17979 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport14.cxx | 28 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 14 | ||||
-rw-r--r-- | writerfilter/source/dmapper/GraphicImport.cxx | 2 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 24 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFastContextHandler.hxx | 1 |
7 files changed, 54 insertions, 15 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf129888dml.docx b/sw/qa/extras/ooxmlexport/data/tdf129888dml.docx Binary files differnew file mode 100644 index 000000000000..1f6b03034fda --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf129888dml.docx diff --git a/sw/qa/extras/ooxmlexport/data/tdf129888vml.docx b/sw/qa/extras/ooxmlexport/data/tdf129888vml.docx Binary files differnew file mode 100644 index 000000000000..ee7c60f8a8dc --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf129888vml.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index 61f3a2ab60a7..a94263f05c41 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -43,6 +43,34 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf128207, "tdf128207.docx") assertXPathContent(p_XmlDoc, "/w:document/w:body/w:p[1]/w:r[1]/w:drawing/wp:anchor/wp:positionH/wp:posOffset", "4445"); } +DECLARE_OOXMLIMPORT_TEST(testTdf129888vml, "tdf129888vml.docx") +{ + //the line shape has anchor in the first cell however it has to + //be positioned to an another cell. To reach this we must handle + //the o:allowincell attribute of the shape, and its position has + //to be calculated from the page frame instead of the table: + + uno::Reference<beans::XPropertySet> xShapeProperties(getShape(1), uno::UNO_QUERY); + sal_Int16 nValue; + xShapeProperties->getPropertyValue("HoriOrientRelation") >>= nValue; + CPPUNIT_ASSERT_EQUAL_MESSAGE("tdf129888vml The line shape has bad place!", + text::RelOrientation::PAGE_FRAME, nValue); +} + +DECLARE_OOXMLIMPORT_TEST(testTdf129888dml, "tdf129888dml.docx") +{ + //the shape has anchor in the first cell however it has to + //be positioned to the right side of the page. To reach this we must handle + //the layoutInCell attribute of the shape, and its position has + //to be calculated from the page frame instead of the table: + + uno::Reference<beans::XPropertySet> xShapeProperties(getShape(1), uno::UNO_QUERY); + sal_Int16 nValue; + xShapeProperties->getPropertyValue("HoriOrientRelation") >>= nValue; + CPPUNIT_ASSERT_EQUAL_MESSAGE("tdf129888dml The shape has bad place!", + text::RelOrientation::PAGE_FRAME, nValue); +} + DECLARE_OOXMLEXPORT_TEST(testTdf87569v, "tdf87569_vml.docx") { //the original tdf87569 sample has vml shapes... diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 8a62a2ebda83..0da610f7ab53 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -3043,20 +3043,6 @@ void DomainMapper::lcl_startShape(uno::Reference<drawing::XShape> const& xShape) m_pImpl->SetIsFirstParagraphInShape(true); - //tdf#87569: Fix table layout with correcting anchoring - //If anchored object is in table, Word calculates its position from cell border - //instead of page (what is set in the sample document) - if (m_pImpl->m_nTableDepth > 0) //if we had a table - { - uno::Reference<beans::XPropertySet> xShapePropSet(xShape, uno::UNO_QUERY); - sal_Int16 nCurrentHorOriRel; //A temp variable to store the current setting - xShapePropSet->getPropertyValue("HoriOrientRelation") >>= nCurrentHorOriRel; - //and the correction: - if (nCurrentHorOriRel == text::RelOrientation::PAGE_FRAME) - xShapePropSet->setPropertyValue("HoriOrientRelation", - uno::makeAny(text::RelOrientation::FRAME)); - } - } void DomainMapper::lcl_endShape( ) diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx index 6c2b7ba81511..b730d5eff1bd 100644 --- a/writerfilter/source/dmapper/GraphicImport.cxx +++ b/writerfilter/source/dmapper/GraphicImport.cxx @@ -875,7 +875,7 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue) //tdf#109411 If anchored object is in table, Word calculates its position from cell border //instead of page (what is set in the sample document) - if (m_pImpl->rDomainMapper.IsInTable() && + if (m_pImpl->rDomainMapper.IsInTable() && m_pImpl->bLayoutInCell && m_pImpl->nHoriRelation == text::RelOrientation::PAGE_FRAME && IsGraphic()) { m_pImpl->nHoriRelation = text::RelOrientation::FRAME; diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index 6f7839d0512b..19dc3bb917e0 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -17,6 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/text/RelOrientation.hpp> #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/xml/sax/FastShapeContextHandler.hpp> @@ -65,6 +67,7 @@ OOXMLFastContextHandler::OOXMLFastContextHandler mpStream(nullptr), mnTableDepth(0), inPositionV(false), + mbLayoutInCell(true), m_xContext(context), m_bDiscardChildren(false), m_bTookChoice(false) @@ -85,6 +88,7 @@ OOXMLFastContextHandler::OOXMLFastContextHandler(OOXMLFastContextHandler * pCont mpParserState(pContext->mpParserState), mnTableDepth(pContext->mnTableDepth), inPositionV(pContext->inPositionV), + mbLayoutInCell(pContext->mbLayoutInCell), m_xContext(pContext->m_xContext), m_bDiscardChildren(pContext->m_bDiscardChildren), m_bTookChoice(pContext->m_bTookChoice) @@ -1663,6 +1667,21 @@ void OOXMLFastContextHandlerShape::sendShape( Token_t Element ) bool bIsPicture = Element == ( NMSP_dmlPicture | XML_pic ); + + //tdf#87569: Fix table layout with correcting anchoring + //If anchored object is in table, Word calculates its position from cell border + //instead of page (what is set in the sample document) + if (mnTableDepth > 0 && mbLayoutInCell) //if we had a table + { + uno::Reference<beans::XPropertySet> xShapePropSet(xShape, uno::UNO_QUERY); + sal_Int16 nCurrentHorOriRel; //A temp variable for storaging the current setting + xShapePropSet->getPropertyValue("HoriOrientRelation") >>= nCurrentHorOriRel; + //and the correction: + if (nCurrentHorOriRel == com::sun::star::text::RelOrientation::PAGE_FRAME) + xShapePropSet->setPropertyValue("HoriOrientRelation", + uno::makeAny(text::RelOrientation::FRAME)); + } + // Notify the dmapper that the shape is ready to use if ( !bIsPicture ) { @@ -1735,6 +1754,11 @@ OOXMLFastContextHandlerShape::lcl_createFastChildContext pChildContext, this); + //tdf129888 store allowincell attribute of the VML shape + if (Attribs->hasAttribute(NMSP_vmlOffice | XML_allowincell)) + mbLayoutInCell + = !(Attribs->getValue(NMSP_vmlOffice | XML_allowincell) == "f"); + if (!bGroupShape) { pWrapper->addNamespace(NMSP_doc); diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx index d5de5a778ee0..0cc3fb1791a9 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx @@ -226,6 +226,7 @@ protected: const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() const { return m_xContext;} bool inPositionV; + bool mbLayoutInCell; // o:allowincell OOXMLValue::Pointer_t mpGridAfter; private: |