[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - 3 commits - drawinglayer/source include/svx svx/CppunitTest_svx_unit.mk svx/inc svx/qa svx/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Tue May 12 08:20:43 UTC 2020
drawinglayer/source/tools/primitive2dxmldump.cxx | 20 ++
include/svx/sdr/primitive2d/sdrdecompositiontools.hxx | 4
svx/CppunitTest_svx_unit.mk | 1
svx/inc/sdr/primitive2d/sdrcustomshapeprimitive2d.hxx | 5
svx/qa/unit/data/shadow-scale-origin.pptx |binary
svx/qa/unit/sdr.cxx | 96 ++++++++++++++
svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx | 19 +-
svx/source/sdr/primitive2d/sdrcustomshapeprimitive2d.cxx | 9 -
svx/source/sdr/primitive2d/sdrdecompositiontools.cxx | 23 ++-
svx/source/sdr/primitive2d/sdrgrafprimitive2d.cxx | 8 -
10 files changed, 161 insertions(+), 24 deletions(-)
New commits:
commit eb9f59aac5c31816cb95cbc7023f44f1e9245ea0
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon May 11 16:38:12 2020 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue May 12 10:11:35 2020 +0200
tdf#129916 svx: fix origin of scaled shadow
We assumed that the top left corner is the origin for scaling, but that
is not necessarily the case. The intention is that the shadow direction
can be determined from its x and y offset, and the origin is the
opposite corner of the shape.
(cherry picked from commit e21d522dddce2590ed435890ae8d5fe39658a71a)
Conflicts:
svx/CppunitTest_svx_unit.mk
Change-Id: I6759302767d20739b6e2be79d379740dd06f70f5
diff --git a/drawinglayer/source/tools/primitive2dxmldump.cxx b/drawinglayer/source/tools/primitive2dxmldump.cxx
index f94896e347f2..64117de878bd 100644
--- a/drawinglayer/source/tools/primitive2dxmldump.cxx
+++ b/drawinglayer/source/tools/primitive2dxmldump.cxx
@@ -397,9 +397,27 @@ void Primitive2dXmlDump::decomposeAndWrite(
break;
}
+ case PRIMITIVE2D_ID_SHADOWPRIMITIVE2D:
+ {
+ // ShadowPrimitive2D.
+ rWriter.startElement("shadow");
+ drawinglayer::primitive2d::Primitive2DContainer aPrimitiveContainer;
+ pBasePrimitive->get2DDecomposition(aPrimitiveContainer,
+ drawinglayer::geometry::ViewInformation2D());
+ decomposeAndWrite(aPrimitiveContainer, rWriter);
+ rWriter.endElement();
+ break;
+ }
+
default:
{
- rWriter.element(OUStringToOString(sCurrentElementTag, RTL_TEXTENCODING_UTF8));
+ rWriter.startElement("unhandled");
+ rWriter.attribute("id", OUStringToOString(sCurrentElementTag, RTL_TEXTENCODING_UTF8));
+ drawinglayer::primitive2d::Primitive2DContainer aPrimitiveContainer;
+ pBasePrimitive->get2DDecomposition(aPrimitiveContainer,
+ drawinglayer::geometry::ViewInformation2D());
+ decomposeAndWrite(aPrimitiveContainer, rWriter);
+ rWriter.endElement();
}
break;
}
diff --git a/svx/CppunitTest_svx_unit.mk b/svx/CppunitTest_svx_unit.mk
index 8514f438c8f0..12c5358b3ab7 100644
--- a/svx/CppunitTest_svx_unit.mk
+++ b/svx/CppunitTest_svx_unit.mk
@@ -25,6 +25,7 @@ $(eval $(call gb_CppunitTest_set_include,svx_unit,\
$(eval $(call gb_CppunitTest_add_exception_objects,svx_unit, \
svx/qa/unit/svdraw/test_SdrTextObject \
svx/qa/unit/customshapes \
+ svx/qa/unit/sdr \
svx/qa/unit/svdraw \
svx/qa/unit/unodraw \
svx/qa/unit/xoutdev \
diff --git a/svx/qa/unit/data/shadow-scale-origin.pptx b/svx/qa/unit/data/shadow-scale-origin.pptx
new file mode 100644
index 000000000000..a0a164a3cddf
Binary files /dev/null and b/svx/qa/unit/data/shadow-scale-origin.pptx differ
diff --git a/svx/qa/unit/sdr.cxx b/svx/qa/unit/sdr.cxx
new file mode 100644
index 000000000000..093264549db7
--- /dev/null
+++ b/svx/qa/unit/sdr.cxx
@@ -0,0 +1,96 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/bootstrapfixture.hxx>
+#include <unotest/macros_test.hxx>
+#include <test/xmltesttools.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
+#include <com/sun/star/drawing/XDrawPage.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/text/XTextRange.hpp>
+
+#include <drawinglayer/tools/primitive2dxmldump.hxx>
+#include <rtl/ustring.hxx>
+#include <svx/sdr/contact/displayinfo.hxx>
+#include <svx/sdr/contact/viewcontact.hxx>
+#include <svx/sdr/contact/viewobjectcontact.hxx>
+#include <svx/svdpage.hxx>
+#include <svx/unopage.hxx>
+#include <vcl/virdev.hxx>
+#include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
+
+using namespace ::com::sun::star;
+
+namespace
+{
+/// Tests for svx/source/sdr/ code.
+class SdrTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools
+{
+protected:
+ uno::Reference<lang::XComponent> mxComponent;
+
+public:
+ virtual void setUp() override
+ {
+ test::BootstrapFixture::setUp();
+ mxDesktop.set(frame::Desktop::create(m_xContext));
+ }
+
+ virtual void tearDown() override
+ {
+ if (mxComponent.is())
+ {
+ mxComponent->dispose();
+ }
+ test::BootstrapFixture::tearDown();
+ }
+ uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
+};
+
+CPPUNIT_TEST_FIXTURE(SdrTest, testShadowScaleOrigin)
+{
+ // Load a document containing a custom shape.
+ test::Directories aDirectories;
+ OUString aURL = aDirectories.getURLFromSrc("svx/qa/unit/data/shadow-scale-origin.pptx");
+ getComponent() = loadFromDesktop(aURL);
+ uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+ uno::UNO_QUERY);
+
+ // Render it.
+ auto pDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPage.get());
+ CPPUNIT_ASSERT(pDrawPage);
+ SdrPage* pSdrPage = pDrawPage->GetSdrPage();
+ ScopedVclPtrInstance<VirtualDevice> aVirtualDevice;
+ sdr::contact::ObjectContactOfObjListPainter aObjectContact(*aVirtualDevice,
+ { pSdrPage->GetObj(0) }, nullptr);
+ const sdr::contact::ViewObjectContact& rDrawPageVOContact
+ = pSdrPage->GetViewContact().GetViewObjectContact(aObjectContact);
+ sdr::contact::DisplayInfo aDisplayInfo;
+ drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
+ = rDrawPageVOContact.getPrimitive2DSequenceHierarchy(aDisplayInfo);
+
+ // Examine the created primitives.
+ drawinglayer::tools::Primitive2dXmlDump aDumper;
+ xmlDocPtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence);
+ double fShadowX = getXPath(pDocument, "//shadow/transform", "xy13").toDouble();
+ double fShadowY = getXPath(pDocument, "//shadow/transform", "xy23").toDouble();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: -705
+ // - Actual : -158
+ // i.e. the shadow origin was not the top right corner for scaling (larger x position, so it was
+ // visible on the right of the shape as well).
+ CPPUNIT_ASSERT_EQUAL(-705., std::round(fShadowX));
+ CPPUNIT_ASSERT_EQUAL(-685., std::round(fShadowY));
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx b/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx
index 42c0bb60ecc9..48575d3b4917 100644
--- a/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx
+++ b/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx
@@ -499,9 +499,19 @@ namespace drawinglayer
double fShearX = 0;
rObjectMatrix.decompose(aScale, aTranslate, fRotate, fShearX);
// Scale the shadow
- aShadowOffset.translate(-aTranslate.getX(), -aTranslate.getY());
+ double nTranslateX = aTranslate.getX();
+ double nTranslateY = aTranslate.getY();
+
+ // The origin for scaling is the top left corner by default. A negative
+ // shadow offset changes the origin.
+ if (rShadow.getOffset().getX() < 0)
+ nTranslateX += aScale.getX();
+ if (rShadow.getOffset().getY() < 0)
+ nTranslateY += aScale.getY();
+
+ aShadowOffset.translate(-nTranslateX, -nTranslateY);
aShadowOffset.scale(rShadow.getSize().getX() * 0.00001, rShadow.getSize().getY() * 0.00001);
- aShadowOffset.translate(aTranslate.getX(), aTranslate.getY());
+ aShadowOffset.translate(nTranslateX, nTranslateY);
}
aShadowOffset.translate(rShadow.getOffset().getX(), rShadow.getOffset().getY());
commit f9dcb113bc2f81ef6abd2044d8512cd4e02f176c
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon May 11 10:10:34 2020 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue May 12 10:01:31 2020 +0200
Related: tdf#129916 svx: clean up duplicated matrix decompose for shadow size
Pass the object's transform matrix to createEmbeddedShadowPrimitive(),
this allows decomposing it only at a single place. Also, this will allow
creating the shadow based on the object size.
(cherry picked from commit 4ba368a3dd793bdc703858f358e1af7112decadd)
Conflicts:
svx/inc/sdr/primitive2d/sdrdecompositiontools.hxx
svx/source/sdr/primitive2d/sdrdecompositiontools.cxx
Change-Id: I8d8bf59934b00e13cda1da0398910aa9f1ce3c59
diff --git a/include/svx/sdr/primitive2d/sdrdecompositiontools.hxx b/include/svx/sdr/primitive2d/sdrdecompositiontools.hxx
index 844da339c111..8635981dc0ae 100644
--- a/include/svx/sdr/primitive2d/sdrdecompositiontools.hxx
+++ b/include/svx/sdr/primitive2d/sdrdecompositiontools.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_SVX_SDR_PRIMITIVE2D_SDRDECOMPOSITIONTOOLS_HXX
#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
+#include <basegfx/matrix/b2dhommatrix.hxx>
#include <svx/svxdllapi.h>
@@ -72,8 +73,7 @@ namespace drawinglayer
Primitive2DContainer SVX_DLLPUBLIC createEmbeddedShadowPrimitive(
const Primitive2DContainer& rContent,
const attribute::SdrShadowAttribute& rShadow,
- sal_Int32 nGraphicTranslateX = 0,
- sal_Int32 nGraphicTranslateY = 0);
+ const basegfx::B2DHomMatrix& rObjectMatrix = basegfx::B2DHomMatrix());
} // end of namespace primitive2d
} // end of namespace drawinglayer
diff --git a/svx/source/sdr/primitive2d/sdrcustomshapeprimitive2d.cxx b/svx/source/sdr/primitive2d/sdrcustomshapeprimitive2d.cxx
index 3e0350aaf56c..2334b1d7fef6 100644
--- a/svx/source/sdr/primitive2d/sdrcustomshapeprimitive2d.cxx
+++ b/svx/source/sdr/primitive2d/sdrcustomshapeprimitive2d.cxx
@@ -68,13 +68,8 @@ namespace drawinglayer
// shadow will be correct (using ColorModifierStack), but expensive.
if(!get3DShape())
{
- basegfx::B2DTuple aScale;
- basegfx::B2DTuple aTranslate;
- double fRotate = 0;
- double fShearX = 0;
- maTransform.decompose(aScale, aTranslate, fRotate, fShearX);
aRetval = createEmbeddedShadowPrimitive(aRetval, getSdrSTAttribute().getShadow(),
- aTranslate.getX(), aTranslate.getY());
+ maTransform);
}
}
diff --git a/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx b/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx
index d6822bfd1519..42c0bb60ecc9 100644
--- a/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx
+++ b/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx
@@ -44,6 +44,7 @@
#include <drawinglayer/attribute/sdrlineattribute.hxx>
#include <drawinglayer/attribute/sdrlinestartendattribute.hxx>
#include <drawinglayer/attribute/sdrshadowattribute.hxx>
+#include <sal/log.hxx>
using namespace com::sun::star;
@@ -482,8 +483,7 @@ namespace drawinglayer
Primitive2DContainer createEmbeddedShadowPrimitive(
const Primitive2DContainer& rContent,
const attribute::SdrShadowAttribute& rShadow,
- sal_Int32 nGraphicTranslateX,
- sal_Int32 nGraphicTranslateY)
+ const basegfx::B2DHomMatrix& rObjectMatrix)
{
if(!rContent.empty())
{
@@ -493,10 +493,15 @@ namespace drawinglayer
{
if(rShadow.getSize().getX() != 100000)
{
+ basegfx::B2DTuple aScale;
+ basegfx::B2DTuple aTranslate;
+ double fRotate = 0;
+ double fShearX = 0;
+ rObjectMatrix.decompose(aScale, aTranslate, fRotate, fShearX);
// Scale the shadow
- aShadowOffset.translate(-nGraphicTranslateX, -nGraphicTranslateY);
+ aShadowOffset.translate(-aTranslate.getX(), -aTranslate.getY());
aShadowOffset.scale(rShadow.getSize().getX() * 0.00001, rShadow.getSize().getY() * 0.00001);
- aShadowOffset.translate(nGraphicTranslateX, nGraphicTranslateY);
+ aShadowOffset.translate(aTranslate.getX(), aTranslate.getY());
}
aShadowOffset.translate(rShadow.getOffset().getX(), rShadow.getOffset().getY());
diff --git a/svx/source/sdr/primitive2d/sdrgrafprimitive2d.cxx b/svx/source/sdr/primitive2d/sdrgrafprimitive2d.cxx
index 676b26183b09..be25a1278e64 100644
--- a/svx/source/sdr/primitive2d/sdrgrafprimitive2d.cxx
+++ b/svx/source/sdr/primitive2d/sdrgrafprimitive2d.cxx
@@ -35,7 +35,6 @@ namespace drawinglayer
void SdrGrafPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*aViewInformation*/) const
{
Primitive2DContainer aRetval;
- basegfx::B2DTuple aTranslateGrf;
// create unit outline polygon
const basegfx::B2DPolygon& aUnitOutline(basegfx::utils::createUnitPolygon());
@@ -62,10 +61,6 @@ namespace drawinglayer
getTransform(),
getGraphicObject(),
getGraphicAttr()));
- double fRotate = 0;
- double fShearX = 0;
- basegfx::B2DTuple aScaleGrf;
- getTransform().decompose(aScaleGrf, aTranslateGrf, fRotate, fShearX);
aRetval.push_back(xGraphicContentPrimitive);
}
@@ -127,8 +122,7 @@ namespace drawinglayer
aRetval = createEmbeddedShadowPrimitive(
aRetval,
getSdrLFSTAttribute().getShadow(),
- aTranslateGrf.getX(),
- aTranslateGrf.getY());
+ getTransform());
}
rContainer.insert(rContainer.end(), aRetval.begin(), aRetval.end());
commit b4ed373a15b1e8d90c94ec7030ee3d3785f7e8f9
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri May 8 16:43:22 2020 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue May 12 09:56:56 2020 +0200
Related: tdf#129916 svx: improve shadow size of custom shapes
There are multiple problems with this bug document, the first is that
the shadow primitive got the default position (0) of the owning shape.
Do it the same way as commit 6454b6336b8de9a4c5899adeab552af6f794cdc4
(tdf#130058 Import shadow size., 2020-04-14) did for graphic objects.
This requires constructing a transform matrix in
ViewContactOfSdrObjCustomShape::createViewIndependentPrimitive2DSequence(),
include position and size in that as a start.
(cherry picked from commit e2b0e614e1185c960b3015414919f69a1ed35aa0)
Change-Id: Ia51df555c1984971afe7c52ba3f2658099a4e7b3
diff --git a/svx/inc/sdr/primitive2d/sdrcustomshapeprimitive2d.hxx b/svx/inc/sdr/primitive2d/sdrcustomshapeprimitive2d.hxx
index 285185684f15..84488906470a 100644
--- a/svx/inc/sdr/primitive2d/sdrcustomshapeprimitive2d.hxx
+++ b/svx/inc/sdr/primitive2d/sdrcustomshapeprimitive2d.hxx
@@ -47,6 +47,8 @@ namespace drawinglayer
// making exceptions with shadow generation
bool const mb3DShape : 1;
+ basegfx::B2DHomMatrix maTransform;
+
protected:
// local decomposition.
virtual void create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& aViewInformation) const override;
@@ -57,7 +59,8 @@ namespace drawinglayer
const Primitive2DContainer& rSubPrimitives,
const basegfx::B2DHomMatrix& rTextBox,
bool bWordWrap,
- bool b3DShape);
+ bool b3DShape,
+ const basegfx::B2DHomMatrix& rObjectMatrix);
// data access
const attribute::SdrShadowTextAttribute& getSdrSTAttribute() const { return maSdrSTAttribute; }
diff --git a/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx b/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx
index 8630b6dd1923..7a5c0487a13f 100644
--- a/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx
+++ b/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx
@@ -157,13 +157,13 @@ namespace sdr
basegfx::B2DHomMatrix aTextBoxMatrix;
bool bWordWrap(false);
+ // take unrotated snap rect as default, then get the
+ // unrotated text box. Rotation needs to be done centered
+ const tools::Rectangle aObjectBound(GetCustomShapeObj().GetGeoRect());
+ const basegfx::B2DRange aObjectRange = vcl::unotools::b2DRectangleFromRectangle(aObjectBound);
+
if(bHasText)
{
- // take unrotated snap rect as default, then get the
- // unrotated text box. Rotation needs to be done centered
- const tools::Rectangle aObjectBound(GetCustomShapeObj().GetGeoRect());
- const basegfx::B2DRange aObjectRange = vcl::unotools::b2DRectangleFromRectangle(aObjectBound);
-
// #i101684# get the text range unrotated and absolute to the object range
const basegfx::B2DRange aTextRange(getCorrectedTextBoundRect());
@@ -238,6 +238,12 @@ namespace sdr
bWordWrap = GetCustomShapeObj().GetMergedItem(SDRATTR_TEXT_WORDWRAP).GetValue();
}
+ // fill object matrix
+ const basegfx::B2DHomMatrix aObjectMatrix(basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix(
+ aObjectRange.getWidth(), aObjectRange.getHeight(),
+ /*fShearX=*/0, /*fRotate=*/0,
+ aObjectRange.getMinX(), aObjectRange.getMinY()));
+
// create primitive
const drawinglayer::primitive2d::Primitive2DReference xReference(
new drawinglayer::primitive2d::SdrCustomShapePrimitive2D(
@@ -245,7 +251,8 @@ namespace sdr
xGroup,
aTextBoxMatrix,
bWordWrap,
- b3DShape));
+ b3DShape,
+ aObjectMatrix));
xRetval = drawinglayer::primitive2d::Primitive2DContainer { xReference };
}
diff --git a/svx/source/sdr/primitive2d/sdrcustomshapeprimitive2d.cxx b/svx/source/sdr/primitive2d/sdrcustomshapeprimitive2d.cxx
index fb3018f7ff88..3e0350aaf56c 100644
--- a/svx/source/sdr/primitive2d/sdrcustomshapeprimitive2d.cxx
+++ b/svx/source/sdr/primitive2d/sdrcustomshapeprimitive2d.cxx
@@ -68,7 +68,13 @@ namespace drawinglayer
// shadow will be correct (using ColorModifierStack), but expensive.
if(!get3DShape())
{
- aRetval = createEmbeddedShadowPrimitive(aRetval, getSdrSTAttribute().getShadow());
+ basegfx::B2DTuple aScale;
+ basegfx::B2DTuple aTranslate;
+ double fRotate = 0;
+ double fShearX = 0;
+ maTransform.decompose(aScale, aTranslate, fRotate, fShearX);
+ aRetval = createEmbeddedShadowPrimitive(aRetval, getSdrSTAttribute().getShadow(),
+ aTranslate.getX(), aTranslate.getY());
}
}
@@ -80,13 +86,15 @@ namespace drawinglayer
const Primitive2DContainer& rSubPrimitives,
const basegfx::B2DHomMatrix& rTextBox,
bool bWordWrap,
- bool b3DShape)
+ bool b3DShape,
+ const basegfx::B2DHomMatrix& rTransform)
: BufferedDecompositionPrimitive2D(),
maSdrSTAttribute(rSdrSTAttribute),
maSubPrimitives(rSubPrimitives),
maTextBox(rTextBox),
mbWordWrap(bWordWrap),
- mb3DShape(b3DShape)
+ mb3DShape(b3DShape),
+ maTransform(rTransform)
{
}
More information about the Libreoffice-commits
mailing list