sw/qa/core/objectpositioning/objectpositioning.cxx | 33 ++++++++++ sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx | 12 +++ 2 files changed, 45 insertions(+)
New commits: commit dd52fdba87d0cfee039cc236b86241708d4e63b8 Author: Miklos Vajna <[email protected]> AuthorDate: Tue Apr 28 17:28:16 2020 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Apr 28 19:26:17 2020 +0200 sw from-bottom relative orientation: add layout The implementation is a combination of what "bottom" and "from-top" already provided. Change-Id: Id7bac8cbcccbadcca377fe9946a21ccb3e368913 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93086 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins diff --git a/sw/qa/core/objectpositioning/objectpositioning.cxx b/sw/qa/core/objectpositioning/objectpositioning.cxx index c73e97567f20..e240f7f84926 100644 --- a/sw/qa/core/objectpositioning/objectpositioning.cxx +++ b/sw/qa/core/objectpositioning/objectpositioning.cxx @@ -9,6 +9,8 @@ #include <swmodeltestbase.hxx> +#include <com/sun/star/text/VertOrientation.hpp> + #include <comphelper/classids.hxx> #include <svtools/embedhlp.hxx> #include <svx/svdpage.hxx> @@ -48,6 +50,37 @@ CPPUNIT_TEST_FIXTURE(SwCoreObjectpositioningTest, testOverlapCrash) pWrtShell->SplitNode(); } +CPPUNIT_TEST_FIXTURE(SwCoreObjectpositioningTest, testVertPosFromBottom) +{ + // Create a document, insert a shape and position it 1cm above the bottom of the body area. + mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + uno::Reference<css::lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XShape> xShape( + xFactory->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY); + xShape->setSize(awt::Size(10000, 10000)); + uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY); + xShapeProps->setPropertyValue("AnchorType", + uno::makeAny(text::TextContentAnchorType_AT_CHARACTER)); + xShapeProps->setPropertyValue("VertOrient", uno::makeAny(text::VertOrientation::NONE)); + xShapeProps->setPropertyValue("VertOrientRelation", + uno::makeAny(text::RelOrientation::PAGE_PRINT_AREA_BOTTOM)); + xShapeProps->setPropertyValue("VertOrientPosition", + uno::makeAny(static_cast<sal_Int32>(-11000))); + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); + xDrawPageSupplier->getDrawPage()->add(xShape); + + // Verify that the distance between the body and anchored object bottom is indeed around 1cm. + xmlDocPtr pXmlDoc = parseLayoutDump(); + sal_Int32 nBodyBottom = getXPath(pXmlDoc, "//body/infos/bounds", "bottom").toInt32(); + sal_Int32 nAnchoredBottom + = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "bottom").toInt32(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 564 + // - Actual : 9035 + // i.e. the vertical position was from-top, not from-bottom. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(564), nBodyBottom - nAnchoredBottom); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx index 3c40f3b91aef..95331da7f8a2 100644 --- a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx +++ b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx @@ -543,6 +543,18 @@ void SwToContentAnchoredObjectPosition::CalcPosition() aRectFnSet.GetTop(aPgPrtRect), nTopOfOrient ); } + else if (aVert.GetRelationOrient() == text::RelOrientation::PAGE_PRINT_AREA_BOTTOM) + { + // The anchored object is relative from the bottom of the page's print area. + SwRect aPgPrtRect(rPageAlignLayFrame.getFrameArea()); + if (rPageAlignLayFrame.IsPageFrame()) + { + auto& rPageFrame = static_cast<const SwPageFrame&>(rPageAlignLayFrame); + aPgPrtRect = rPageFrame.PrtWithoutHeaderAndFooter(); + } + SwTwips nPageBottom = aRectFnSet.GetBottom(aPgPrtRect); + nVertOffsetToFrameAnchorPos += aRectFnSet.YDiff(nPageBottom, nTopOfOrient); + } nRelPosY = nVertOffsetToFrameAnchorPos + aVert.GetPos(); } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
