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

New commits:
commit a43cd444b6c1b22e22eaf9279d8eb19de0f8ec5a
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Jan 24 12:53:25 2022 +0100
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu Jan 27 09:19:37 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.
    
    (cherry picked from commit e993638d5ecd33783f2eebdccfa87a81e5a8a2c5)
    
    Conflicts:
            writerfilter/source/dmapper/GraphicImport.cxx
    
    Change-Id: I6ca7511d46d7a70df11a65dc67c182f4fff4ae69
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128972
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx 
b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
index 0d0cd12c8c1c..a0286ac96a2b 100644
--- a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
@@ -275,6 +275,29 @@ 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);
+    // Not "Frame".
+    CPPUNIT_ASSERT(xNamedShape->getName().startsWith("Text Box"));
+    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 07669e8e66b5..23aa3cc36ac3 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -986,6 +986,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