[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - writerfilter/qa writerfilter/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Mon May 31 08:08:19 UTC 2021


 writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx              |   40 ++++++++--
 writerfilter/qa/cppunittests/dmapper/data/textbox-textline-top.docx |binary
 writerfilter/source/dmapper/GraphicImport.cxx                       |   13 ++-
 3 files changed, 40 insertions(+), 13 deletions(-)

New commits:
commit 2ff02e6d31702611d0294c31b69f043b61d22a47
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed May 26 11:56:04 2021 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon May 31 10:07:46 2021 +0200

    tdf#139915 DOCX import: fix anchored obj position with to-char and TEXT_LINE
    
    There were multiple problems here:
    
    - commit 8f1a1092d47947847e1d888b0284e8364c663d1f (tdf#97371 DOCX
    import: fix text covered by shape, 2016-01-28) disabled to-char
    anchoring for TEXT_LINE (e.g. "alignment top, relative to line") because
    changing the anchor type of a TextBox could not be changed, but this has
    been implemented in sw/ in the meantime, so it can be dropped
    
    - Now that the anchor type is to-char, we can set the vertical relation
    to TEXT_LINE, but Word's positive value is "below line", and ours mean
    "towards the top of the page, from the bottom of the line", so we need
    to drop the workaround of commit
    3303a4c5f21874453e634d84408c50e7a0055a4d (tdf#135153 DOCX import: avoid
    line-of-text relation with to-para anchoring, 2021-01-18)
    
    Once these are in place, we can fix the remaining problem by inverting
    the vertical position of the shape, which instantly fixes the
    overlapping textboxes in the bugdoc.
    
    (cherry picked from commit 2f21e4f357ec60450df84ddd858c3cf0a4711b02)
    
    Conflicts:
            writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
            writerfilter/source/dmapper/GraphicImport.cxx
    
    Change-Id: I895abb76d3bd3bbe3a84e5c27a77df722b96226a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116231
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
index bc0271fa13a4..122996d2a675 100644
--- a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
@@ -18,6 +18,7 @@
 #include <com/sun/star/text/XTextTablesSupplier.hpp>
 #include <com/sun/star/text/RelOrientation.hpp>
 #include <com/sun/star/container/XNamed.hpp>
+#include <com/sun/star/text/VertOrientation.hpp>
 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
 
 #include <comphelper/processfactory.hxx>
@@ -181,16 +182,39 @@ CPPUNIT_TEST_FIXTURE(Test, testTextboxTextline)
     uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(getComponent(), uno::UNO_QUERY);
     uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
     uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
-    sal_Int16 nActual{};
-    CPPUNIT_ASSERT(xShape->getPropertyValue("VertOrientRelation") >>= nActual);
+    sal_Int16 nActualRelation{};
+    CPPUNIT_ASSERT(xShape->getPropertyValue("VertOrientRelation") >>= nActualRelation);
+    sal_Int32 nActualPosition{};
+    CPPUNIT_ASSERT(xShape->getPropertyValue("VertOrientPosition") >>= nActualPosition);
+
+    sal_Int16 nExpectedRelation = text::RelOrientation::TEXT_LINE;
+    CPPUNIT_ASSERT_EQUAL(nExpectedRelation, nActualRelation);
+    // 0 on this branch, but sw/qa/extras/ooxmlexport/data/tdf97371.docx shows that negative values
+    // work fine in general, don't bother:
+    // sal_Int32 nExpectedPosition = -2;
+    // CPPUNIT_ASSERT_EQUAL(nExpectedPosition, nActualPosition);
+}
 
+CPPUNIT_TEST_FIXTURE(Test, testTextboxTextlineTop)
+{
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "textbox-textline-top.docx";
+    getComponent() = loadFromDesktop(aURL);
+    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(getComponent(), uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
+    uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+    sal_Int16 nActualRelation{};
+    CPPUNIT_ASSERT(xShape->getPropertyValue("VertOrientRelation") >>= nActualRelation);
+    sal_Int16 nExpectedRelation = text::RelOrientation::TEXT_LINE;
     // Without the accompanying fix in place, this test would have failed with:
-    // - Expected: 0 (text::RelOrientation::FRAME)
-    // - Actual  : 9 (text::RelOrientation::TEXT_LINE)
-    // i.e. the relation had a value which doesn't make sense for to-para anchoring (only for
-    // to-char anchoring).
-    sal_Int16 nExpected = text::RelOrientation::FRAME;
-    CPPUNIT_ASSERT_EQUAL(nExpected, nActual);
+    // - Expected: 9 (TEXT_LINE)
+    // - Actual  : 0 (FRAME)
+    // i.e. the anchor point for the positioning was wrong, resulting in overlapping textboxes.
+    CPPUNIT_ASSERT_EQUAL(nExpectedRelation, nActualRelation);
+
+    sal_Int16 nActualOrient{};
+    CPPUNIT_ASSERT(xShape->getPropertyValue("VertOrient") >>= nActualOrient);
+    sal_Int16 nExpectedOrient = text::VertOrientation::BOTTOM;
+    CPPUNIT_ASSERT_EQUAL(nExpectedOrient, nActualOrient);
 }
 }
 
diff --git a/writerfilter/qa/cppunittests/dmapper/data/textbox-textline-top.docx b/writerfilter/qa/cppunittests/dmapper/data/textbox-textline-top.docx
new file mode 100644
index 000000000000..dbd750092811
Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/textbox-textline-top.docx differ
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index ae98dadfc004..4af792ecd733 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -836,16 +836,19 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
                         // Avoid setting AnchorType for TextBoxes till SwTextBoxHelper::syncProperty() doesn't handle transition.
                         bool bTextBox = false;
                         xShapeProps->getPropertyValue("TextBox") >>= bTextBox;
-                        if (m_pImpl->nVertRelation == text::RelOrientation::TEXT_LINE && !bTextBox)
+                        if (m_pImpl->nVertRelation == text::RelOrientation::TEXT_LINE)
                             eAnchorType = text::TextContentAnchorType_AT_CHARACTER;
 
                         xShapeProps->setPropertyValue("AnchorType", uno::makeAny(eAnchorType));
 
-                        if (m_pImpl->nVertRelation == text::RelOrientation::TEXT_LINE && bTextBox)
+                        if (m_pImpl->nVertRelation == text::RelOrientation::TEXT_LINE)
                         {
-                            // TEXT_LINE to specific to to-char anchoring, we have to-para, so reset
-                            // to default.
-                            m_pImpl->nVertRelation = text::RelOrientation::FRAME;
+                            // Word's "line" is "below the bottom of the line", our TEXT_LINE is
+                            // "towards top, from the bottom of the line", so invert the vertical
+                            // position.
+                            awt::Point aPoint = xShape->getPosition();
+                            aPoint.Y *= -1;
+                            xShape->setPosition(aPoint);
                         }
 
                         //only the position orientation is handled in applyPosition()


More information about the Libreoffice-commits mailing list