[Libreoffice-commits] core.git: sw/qa sw/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Tue Sep 24 14:17:53 UTC 2019
sw/qa/extras/layout/layout.cxx | 50 ++++++++++
sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx | 13 ++
2 files changed, 63 insertions(+)
New commits:
commit ac7047f72087f09f2ab223f1af2518778382c06a
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Sep 24 14:57:53 2019 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Sep 24 16:16:48 2019 +0200
Related: tdf#124600 sw anchored object allow overlap: wrap-through handling
Wrap-through and allow-overlap are conflicting requirements. Word gives
wrap-though a priority, i.e. those objects can still overlap, even if
allow-overlap=false is set.
Let Writer have the same priority, this flag was added primarily for
interoperability purposes.
[ No compatibility flag, AllowOverlap is "@since LibreOffice 6.4", so
the behavior can be just changed. ]
Change-Id: I3743e6c94f8430c86c1ab5ffe0aabc4537e35ccc
Reviewed-on: https://gerrit.libreoffice.org/79458
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
Tested-by: Jenkins
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index ccbfd0b944a3..a6d70234f423 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -12,6 +12,7 @@
#include <comphelper/propertysequence.hxx>
#include <com/sun/star/linguistic2/LinguServiceManager.hpp>
#include <com/sun/star/frame/DispatchHelper.hpp>
+#include <com/sun/star/text/WrapTextMode.hpp>
#include <comphelper/scopeguard.hxx>
#include <unotools/syslocaleoptions.hxx>
#include <i18nlangtag/languagetag.hxx>
@@ -3154,6 +3155,55 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testShapeAllowOverlap)
#endif
}
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testShapeAllowOverlapWrap)
+{
+ // Create an empty document with two, intentionally overlapping shapes.
+ // Set their AllowOverlap property to false and their wrap to through.
+ loadURL("private:factory/swriter", nullptr);
+ uno::Reference<lang::XMultiServiceFactory> xDocument(mxComponent, uno::UNO_QUERY);
+ awt::Point aPoint(1000, 1000);
+ awt::Size aSize(2000, 2000);
+ uno::Reference<drawing::XShape> xShape(
+ xDocument->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY);
+ xShape->setPosition(aPoint);
+ xShape->setSize(aSize);
+ uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xDocument, uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY);
+ xShapeProperties->setPropertyValue("AllowOverlap", uno::makeAny(false));
+ xShapeProperties->setPropertyValue("AnchorType",
+ uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
+ xShapeProperties->setPropertyValue("Surround", uno::makeAny(text::WrapTextMode_THROUGH));
+ xDrawPageSupplier->getDrawPage()->add(xShape);
+
+ aPoint = awt::Point(2000, 2000);
+ xShape.set(xDocument->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY);
+ xShape->setPosition(aPoint);
+ xShape->setSize(aSize);
+ xShapeProperties.set(xShape, uno::UNO_QUERY);
+ xShapeProperties->setPropertyValue("AllowOverlap", uno::makeAny(false));
+ xShapeProperties->setPropertyValue("AnchorType",
+ uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
+ xShapeProperties->setPropertyValue("Surround", uno::makeAny(text::WrapTextMode_THROUGH));
+ xDrawPageSupplier->getDrawPage()->add(xShape);
+
+ // Now verify that the rectangle of the anchored objects do overlap.
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+ SwFrame* pPageFrame = pLayout->GetLower();
+ SwFrame* pBodyFrame = pPageFrame->GetLower();
+ SwFrame* pTextFrame = pBodyFrame->GetLower();
+ CPPUNIT_ASSERT(pTextFrame->GetDrawObjs());
+ SwSortedObjs& rObjs = *pTextFrame->GetDrawObjs();
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rObjs.size());
+ SwAnchoredObject* pFirst = rObjs[0];
+ SwAnchoredObject* pSecond = rObjs[1];
+ // Without the accompanying fix in place, this test would have failed: AllowOverlap=no had
+ // priority over Surround=through (which is bad for Word compat).
+ CPPUNIT_ASSERT(pSecond->GetObjRect().IsOver(pFirst->GetObjRect()));
+}
+
CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf124600)
{
createDoc("tdf124600.docx");
diff --git a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
index 0fc56d1af80e..ec4ceeb61578 100644
--- a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
@@ -1083,6 +1083,12 @@ void SwToContentAnchoredObjectPosition::CalcOverlap(const SwTextFrame* pAnchorFr
return;
}
+ if (rFrameFormat.GetSurround().GetSurround() == css::text::WrapTextMode_THROUGH)
+ {
+ // This is explicit wrap through: allowed to overlap.
+ return;
+ }
+
if (SwTextBoxHelper::isTextBox(&rFrameFormat, RES_FLYFRMFMT))
{
// This is the frame part of a textbox, just take the offset from the textbox's shape part.
@@ -1116,6 +1122,13 @@ void SwToContentAnchoredObjectPosition::CalcOverlap(const SwTextFrame* pAnchorFr
continue;
}
+ css::text::WrapTextMode eWrap = pAnchoredObj->GetFrameFormat().GetSurround().GetSurround();
+ if (eWrap == css::text::WrapTextMode_THROUGH)
+ {
+ // The other object is wrap through: allowed to overlap.
+ continue;
+ }
+
if (!GetAnchoredObj().GetObjRect().IsOver(pAnchoredObj->GetObjRect()))
{
// Found an already positioned object, but it doesn't overlap, ignore.
More information about the Libreoffice-commits
mailing list