writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx                        
|   22 ++++++++++
 writerfilter/qa/cppunittests/dmapper/data/layout-in-cell-wrapnone-column.docx 
|binary
 writerfilter/source/dmapper/GraphicImport.cxx                                 
|    7 +++
 3 files changed, 29 insertions(+)

New commits:
commit e993638d5ecd33783f2eebdccfa87a81e5a8a2c5
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Jan 24 12:53:25 2022 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Jan 24 15:10:24 2022 +0100

    DOCX import: fix <wp:anchor layoutInCell="1"> with <wp:wrapNone>
    
    If wrap is set to none ("in front of text"), then <wp:positionH
    relativeFrom="column"> ignores layoutInCell="1" in Word. But in case
    relativeFrom is something else (e.g. page) or wrap is not none, then the
    old behavior is OK.
    
    Adjust our import so that Writer's layout also allows this shape to
    leave the cell.
    
    Change-Id: I6ca7511d46d7a70df11a65dc67c182f4fff4ae69
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128862
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx 
b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
index edd6e02ff8ea..2f9faefab55f 100644
--- a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
@@ -366,6 +366,28 @@ CPPUNIT_TEST_FIXTURE(Test, testTextboxTextlineTop)
     sal_Int16 nExpectedOrient = text::VertOrientation::BOTTOM;
     CPPUNIT_ASSERT_EQUAL(nExpectedOrient, nActualOrient);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testLayoutInCellWrapnoneColumn)
+{
+    // Given a file with a table, then a shape anchored inside the cell:
+    OUString aURL
+        = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"layout-in-cell-wrapnone-column.docx";
+
+    // When loading that document:
+    getComponent() = loadFromDesktop(aURL);
+
+    // Then make sure the shape can leave the cell:
+    uno::Reference<drawing::XDrawPageSupplier> 
xDrawPageSupplier(getComponent(), uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> xDrawPage = 
xDrawPageSupplier->getDrawPage();
+    uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(1), 
uno::UNO_QUERY);
+    uno::Reference<container::XNamed> xNamedShape(xShape, uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Text Box 1"), xNamedShape->getName());
+    bool bFollowingTextFlow = true;
+    // Without the accompanying fix in place, this test would have failed, the 
shape was not allowed
+    // to leave the cell, leading to incorrect layout.
+    CPPUNIT_ASSERT(xShape->getPropertyValue("IsFollowingTextFlow") >>= 
bFollowingTextFlow);
+    CPPUNIT_ASSERT(!bFollowingTextFlow);
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git 
a/writerfilter/qa/cppunittests/dmapper/data/layout-in-cell-wrapnone-column.docx 
b/writerfilter/qa/cppunittests/dmapper/data/layout-in-cell-wrapnone-column.docx
new file mode 100644
index 000000000000..d88761421154
Binary files /dev/null and 
b/writerfilter/qa/cppunittests/dmapper/data/layout-in-cell-wrapnone-column.docx 
differ
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx 
b/writerfilter/source/dmapper/GraphicImport.cxx
index 704774ec504a..bb3b2077e4aa 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -1228,6 +1228,13 @@ void GraphicImport::lcl_attribute(Id nName, Value& 
rValue)
                         // But they aren't Writer pictures, either (which are 
already handled above).
                         uno::Reference< beans::XPropertySet > 
xShapeProps(m_xShape, uno::UNO_QUERY_THROW);
 
+                        if (m_pImpl->nWrap == text::WrapTextMode_THROUGH && 
m_pImpl->nHoriRelation == text::RelOrientation::FRAME)
+                        {
+                            // text::RelOrientation::FRAME is OOXML's 
"column", which behaves as if
+                            // layout-in-cell would be always off.
+                            m_pImpl->bLayoutInCell = false;
+                        }
+
                         // Anchored: Word only supports at-char in that case.
                         text::TextContentAnchorType eAnchorType = 
text::TextContentAnchorType_AT_CHARACTER;
 

Reply via email to