From 14f6b169b5d04f4bfcb28bf7e10fad21dc6f191c Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sat, 3 Feb 2024 14:18:19 +0200 Subject: Move mnTransparenceForShadow down to SdrCellPrimitive2D where it belongs. It appears it was only put into BufferedDecompositionPrimitive2D so that it can be accessed by Primitive2DXmlDump, so fix that by creating an extended version of the dumper for use in svx. Change-Id: Idb0b849c4fa538bbede882e48c2d090669c2325a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162949 Tested-by: Jenkins Reviewed-by: Noel Grandin --- .../BufferedDecompositionPrimitive2D.cxx | 1 - drawinglayer/source/tools/primitive2dxmldump.cxx | 29 ++++----- .../BufferedDecompositionPrimitive2D.hxx | 11 ---- include/drawinglayer/tools/primitive2dxmldump.hxx | 9 ++- svx/Library_svxcore.mk | 1 + svx/inc/extendedprimitive2dxmldump.hxx | 31 ++++++++++ svx/inc/sdr/primitive2d/sdrcellprimitive.hxx | 70 ++++++++++++++++++++++ svx/qa/unit/sdr.cxx | 12 ++-- svx/qa/unit/svdraw.cxx | 6 +- svx/qa/unit/table.cxx | 4 +- svx/qa/unit/unodraw.cxx | 4 +- svx/source/core/extendedprimitive2dxmldump.cxx | 49 +++++++++++++++ .../sdr/primitive2d/sdrdecompositiontools.cxx | 3 +- svx/source/table/viewcontactoftableobj.cxx | 37 +----------- 14 files changed, 184 insertions(+), 83 deletions(-) create mode 100644 svx/inc/extendedprimitive2dxmldump.hxx create mode 100644 svx/inc/sdr/primitive2d/sdrcellprimitive.hxx create mode 100644 svx/source/core/extendedprimitive2dxmldump.cxx diff --git a/drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx b/drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx index 22b6450e7f2d..92d32a4dd73a 100644 --- a/drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx +++ b/drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx @@ -109,7 +109,6 @@ BufferedDecompositionPrimitive2D::BufferedDecompositionPrimitive2D() , maCallbackTimer() , maCallbackLock() , maCallbackSeconds(0) - , mnTransparenceForShadow(0) { } diff --git a/drawinglayer/source/tools/primitive2dxmldump.cxx b/drawinglayer/source/tools/primitive2dxmldump.cxx index f3b9ef1bc919..1a8aa542df7b 100644 --- a/drawinglayer/source/tools/primitive2dxmldump.cxx +++ b/drawinglayer/source/tools/primitive2dxmldump.cxx @@ -663,6 +663,11 @@ xmlDocUniquePtr Primitive2dXmlDump::dumpAndParse( return xmlDocUniquePtr(xmlParseDoc(reinterpret_cast(pBuffer.get()))); } +OUString Primitive2dXmlDump::idToString(sal_uInt32 nId) +{ + return drawinglayer::primitive2d::idToString(nId); +} + void Primitive2dXmlDump::decomposeAndWrite( const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence, ::tools::XmlWriter& rWriter) @@ -674,6 +679,10 @@ void Primitive2dXmlDump::decomposeAndWrite( if (nId < maFilter.size() && maFilter[nId]) continue; + // handled by subclass + if (decomposeAndWrite(*pBasePrimitive, rWriter)) + continue; + OUString sCurrentElementTag = drawinglayer::primitive2d::idToString(nId); switch (nId) @@ -1207,28 +1216,10 @@ void Primitive2dXmlDump::decomposeAndWrite( default: { - const char* aName = "unhandled"; - switch (nId) - { - case PRIMITIVE2D_ID_RANGE_SVX | 14: // PRIMITIVE2D_ID_SDRCELLPRIMITIVE2D - { - aName = "sdrCell"; - break; - } - } - rWriter.startElement(aName); + rWriter.startElement("unhandled"); rWriter.attribute("id", sCurrentElementTag); rWriter.attribute("idNumber", nId); - auto pBufferedDecomposition - = dynamic_cast(pBasePrimitive); - if (pBufferedDecomposition) - { - rWriter.attribute( - "transparenceForShadow", - OString::number(pBufferedDecomposition->getTransparenceForShadow())); - } - drawinglayer::primitive2d::Primitive2DContainer aPrimitiveContainer; pBasePrimitive->get2DDecomposition(aPrimitiveContainer, drawinglayer::geometry::ViewInformation2D()); diff --git a/include/drawinglayer/primitive2d/BufferedDecompositionPrimitive2D.hxx b/include/drawinglayer/primitive2d/BufferedDecompositionPrimitive2D.hxx index cc36ddb93cd5..f4f618029627 100644 --- a/include/drawinglayer/primitive2d/BufferedDecompositionPrimitive2D.hxx +++ b/include/drawinglayer/primitive2d/BufferedDecompositionPrimitive2D.hxx @@ -74,10 +74,6 @@ private: mutable std::mutex maCallbackLock; sal_uInt16 maCallbackSeconds; - /// When a shadow wraps a list of primitives, this primitive wants to influence the transparency - /// of the shadow. - sal_uInt16 mnTransparenceForShadow; - protected: /** access methods to maBuffered2DDecomposition. The usage of this methods may allow later thread-safe stuff to be added if needed. Only to be used by getDecomposition() @@ -111,13 +107,6 @@ public: virtual void get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const override; - - void setTransparenceForShadow(sal_uInt16 nTransparenceForShadow) - { - mnTransparenceForShadow = nTransparenceForShadow; - } - - sal_uInt16 getTransparenceForShadow() const { return mnTransparenceForShadow; } }; } // end of namespace drawinglayer::primitive2d diff --git a/include/drawinglayer/tools/primitive2dxmldump.hxx b/include/drawinglayer/tools/primitive2dxmldump.hxx index 9dc06e7b674d..29c432f24680 100644 --- a/include/drawinglayer/tools/primitive2dxmldump.hxx +++ b/include/drawinglayer/tools/primitive2dxmldump.hxx @@ -22,15 +22,18 @@ namespace tools { class XmlWriter; } namespace drawinglayer { -class DRAWINGLAYER_DLLPUBLIC Primitive2dXmlDump final +class DRAWINGLAYER_DLLPUBLIC Primitive2dXmlDump { private: std::vector maFilter; + +protected: void decomposeAndWrite(const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence, tools::XmlWriter& rWriter); + static OUString idToString(sal_uInt32 nId); public: Primitive2dXmlDump(); - ~Primitive2dXmlDump(); + virtual ~Primitive2dXmlDump(); /** Dumps the input primitive sequence to xml into a file or memory stream and parses the xml for testing. * @@ -44,6 +47,8 @@ public: /** Dumps the input primitive sequence to xml into a file. */ void dump(const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence, const OUString& rStreamName); + /** overridden by svx::ExtendedPrimitive2dXmlDump */ + virtual bool decomposeAndWrite( const drawinglayer::primitive2d::BasePrimitive2D& /*rPrimitive2DSequence*/, ::tools::XmlWriter& /*rWriter*/) { return false; } }; } diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk index 51dc332b26e0..5fcaba011431 100644 --- a/svx/Library_svxcore.mk +++ b/svx/Library_svxcore.mk @@ -108,6 +108,7 @@ endif $(eval $(call gb_Library_add_exception_objects,svxcore,\ svx/source/core/extedit \ svx/source/core/graphichelper \ + svx/source/core/extendedprimitive2dxmldump \ svx/source/customshapes/EnhancedCustomShape2d \ svx/source/customshapes/EnhancedCustomShapeFunctionParser \ svx/source/customshapes/EnhancedCustomShapeGeometry \ diff --git a/svx/inc/extendedprimitive2dxmldump.hxx b/svx/inc/extendedprimitive2dxmldump.hxx new file mode 100644 index 000000000000..86824468dcf7 --- /dev/null +++ b/svx/inc/extendedprimitive2dxmldump.hxx @@ -0,0 +1,31 @@ +/* -*- 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/. + */ +#pragma once + +#include +#include + +namespace svx +{ +/** + * Extends the normal dumper to include svx primitives + */ +class SVXCORE_DLLPUBLIC ExtendedPrimitive2dXmlDump : public drawinglayer::Primitive2dXmlDump +{ +public: + ExtendedPrimitive2dXmlDump(); + virtual ~ExtendedPrimitive2dXmlDump(); + virtual bool + decomposeAndWrite(const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive2DSequence, + ::tools::XmlWriter& rWriter); +}; + +} // namespace svx + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/inc/sdr/primitive2d/sdrcellprimitive.hxx b/svx/inc/sdr/primitive2d/sdrcellprimitive.hxx new file mode 100644 index 000000000000..17088b84b17c --- /dev/null +++ b/svx/inc/sdr/primitive2d/sdrcellprimitive.hxx @@ -0,0 +1,70 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include +#include +#include + +namespace drawinglayer::primitive2d +{ +class SdrCellPrimitive2D : public BufferedDecompositionPrimitive2D +{ +private: + basegfx::B2DHomMatrix maTransform; + attribute::SdrFillTextAttribute maSdrFTAttribute; + /// When a shadow wraps a list of primitives, this primitive wants to influence the transparency + /// of the shadow. + sal_uInt16 mnTransparenceForShadow; + +protected: + // local decomposition. + virtual void + create2DDecomposition(Primitive2DContainer& rContainer, + const geometry::ViewInformation2D& aViewInformation) const override; + +public: + SdrCellPrimitive2D(basegfx::B2DHomMatrix aTransform, + const attribute::SdrFillTextAttribute& rSdrFTAttribute) + : maTransform(std::move(aTransform)) + , maSdrFTAttribute(rSdrFTAttribute) + , mnTransparenceForShadow(0) + { + } + + // data access + const basegfx::B2DHomMatrix& getTransform() const { return maTransform; } + const attribute::SdrFillTextAttribute& getSdrFTAttribute() const { return maSdrFTAttribute; } + + void setTransparenceForShadow(sal_uInt16 nTransparenceForShadow) + { + mnTransparenceForShadow = nTransparenceForShadow; + } + sal_uInt16 getTransparenceForShadow() const { return mnTransparenceForShadow; } + + // compare operator + virtual bool operator==(const BasePrimitive2D& rPrimitive) const override; + + // provide unique ID + virtual sal_uInt32 getPrimitive2DID() const override; +}; + +} // namespace drawinglayer::primitive2d + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/qa/unit/sdr.cxx b/svx/qa/unit/sdr.cxx index 15759a2f406f..a58209941b5c 100644 --- a/svx/qa/unit/sdr.cxx +++ b/svx/qa/unit/sdr.cxx @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include #include @@ -67,7 +67,7 @@ CPPUNIT_TEST_FIXTURE(SdrTest, testShadowScaleOrigin) = renderPageToPrimitives(xDrawPage); // Examine the created primitives. - drawinglayer::Primitive2dXmlDump aDumper; + svx::ExtendedPrimitive2dXmlDump aDumper; xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence); sal_Int32 fShadowX = getXPath(pDocument, "//shadow/transform"_ostr, "xy13"_ostr).toInt32(); sal_Int32 fShadowY = getXPath(pDocument, "//shadow/transform"_ostr, "xy23"_ostr).toInt32(); @@ -93,7 +93,7 @@ CPPUNIT_TEST_FIXTURE(SdrTest, testShadowAlignment) = renderPageToPrimitives(xDrawPage); // Examine the created primitives. - drawinglayer::Primitive2dXmlDump aDumper; + svx::ExtendedPrimitive2dXmlDump aDumper; xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence); // Without the accompanying fix in place, this test would have failed with: @@ -136,7 +136,7 @@ CPPUNIT_TEST_FIXTURE(SdrTest, testShadowAlignment) = renderPageToPrimitives(xDrawPage); // Examine the created primitives. - drawinglayer::Primitive2dXmlDump aDumper; + svx::ExtendedPrimitive2dXmlDump aDumper; xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence); // Without the accompanying fix in place, this test would have failed with: @@ -159,7 +159,7 @@ CPPUNIT_TEST_FIXTURE(SdrTest, testZeroWidthTextWrap) = renderPageToPrimitives(xDrawPage); // Examine the created primitives. - drawinglayer::Primitive2dXmlDump aDumper; + svx::ExtendedPrimitive2dXmlDump aDumper; xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 @@ -181,7 +181,7 @@ CPPUNIT_TEST_FIXTURE(SdrTest, testSlideBackground) = renderPageToPrimitives(xDrawPage); // Then make sure that the background has a bitmap: - drawinglayer::Primitive2dXmlDump aDumper; + svx::ExtendedPrimitive2dXmlDump aDumper; xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 diff --git a/svx/qa/unit/svdraw.cxx b/svx/qa/unit/svdraw.cxx index 66f4528d889f..53f2d2a9f981 100644 --- a/svx/qa/unit/svdraw.cxx +++ b/svx/qa/unit/svdraw.cxx @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include @@ -80,7 +80,7 @@ xmlDocUniquePtr lcl_dumpAndParseFirstObjectWithAssert(SdrPage* pSdrPage) drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence; rDrawPageVOContact.getPrimitive2DSequenceHierarchy(aDisplayInfo, xPrimitiveSequence); - drawinglayer::Primitive2dXmlDump aDumper; + svx::ExtendedPrimitive2dXmlDump aDumper; xmlDocUniquePtr pXmlDoc = aDumper.dumpAndParse(xPrimitiveSequence); CPPUNIT_ASSERT(pXmlDoc); return pXmlDoc; @@ -285,7 +285,7 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testRectangleObject) drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence; rDrawPageVOContact.getPrimitive2DSequenceHierarchy(aDisplayInfo, xPrimitiveSequence); - drawinglayer::Primitive2dXmlDump aDumper; + svx::ExtendedPrimitive2dXmlDump aDumper; xmlDocUniquePtr pXmlDoc = aDumper.dumpAndParse(xPrimitiveSequence); assertXPath(pXmlDoc, "/primitive2D"_ostr, 1); diff --git a/svx/qa/unit/table.cxx b/svx/qa/unit/table.cxx index e51cd3f860ce..e5abaeb06e57 100644 --- a/svx/qa/unit/table.cxx +++ b/svx/qa/unit/table.cxx @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include #include @@ -74,7 +74,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTableShadowBlur) = renderPageToPrimitives(xDrawPage); // Then make sure that the cell fill part of the shadow has the expected transparency: - drawinglayer::Primitive2dXmlDump aDumper; + svx::ExtendedPrimitive2dXmlDump aDumper; xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence); // Without the accompanying fix in place, this test would have failed with: //- Expected: 0 diff --git a/svx/qa/unit/unodraw.cxx b/svx/qa/unit/unodraw.cxx index c077fd53a4bc..a7417356e13a 100644 --- a/svx/qa/unit/unodraw.cxx +++ b/svx/qa/unit/unodraw.cxx @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -145,7 +145,7 @@ CPPUNIT_TEST_FIXTURE(UnodrawTest, testTableShadowDirect) rDrawPageVOContact.getPrimitive2DSequenceHierarchy(aDisplayInfo, xPrimitiveSequence); // Check the primitives. - drawinglayer::Primitive2dXmlDump aDumper; + svx::ExtendedPrimitive2dXmlDump aDumper; xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence); assertXPath(pDocument, "//shadow"_ostr, /*nNumberOfNodes=*/1); diff --git a/svx/source/core/extendedprimitive2dxmldump.cxx b/svx/source/core/extendedprimitive2dxmldump.cxx new file mode 100644 index 000000000000..18b8e1028755 --- /dev/null +++ b/svx/source/core/extendedprimitive2dxmldump.cxx @@ -0,0 +1,49 @@ +/* -*- 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 +#include +#include +#include + +namespace svx +{ +ExtendedPrimitive2dXmlDump::ExtendedPrimitive2dXmlDump() {} + +ExtendedPrimitive2dXmlDump::~ExtendedPrimitive2dXmlDump() {} + +bool ExtendedPrimitive2dXmlDump::decomposeAndWrite( + const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive, ::tools::XmlWriter& rWriter) +{ + sal_uInt32 nId = rPrimitive.getPrimitive2DID(); + if (nId == PRIMITIVE2D_ID_SDRCELLPRIMITIVE2D) + { + OUString sCurrentElementTag = idToString(nId); + rWriter.startElement("sdrCell"); + rWriter.attribute("id", sCurrentElementTag); + rWriter.attribute("idNumber", nId); + + auto& rSdrCellPrimitive2D + = dynamic_cast(rPrimitive); + rWriter.attribute("transparenceForShadow", + OString::number(rSdrCellPrimitive2D.getTransparenceForShadow())); + + drawinglayer::primitive2d::Primitive2DContainer aPrimitiveContainer; + rPrimitive.get2DDecomposition(aPrimitiveContainer, + drawinglayer::geometry::ViewInformation2D()); + Primitive2dXmlDump::decomposeAndWrite(aPrimitiveContainer, rWriter); + rWriter.endElement(); + return true; + } + return false; +} + +} // end namespace svx + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx b/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx index d5fd05cd58d3..ccb927649ebe 100644 --- a/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx +++ b/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -818,7 +819,7 @@ sal_uInt32 SlideBackgroundFillPrimitive2D::getPrimitive2DID() const int nContentWithTransparence = std::count_if( rContentForShadow.begin(), rContentForShadow.end(), [](const Primitive2DReference& xChild) { - auto pChild = dynamic_cast(xChild.get()); + auto pChild = dynamic_cast(xChild.get()); return pChild && pChild->getTransparenceForShadow() != 0; }); if (nContentWithTransparence == 0) diff --git a/svx/source/table/viewcontactoftableobj.cxx b/svx/source/table/viewcontactoftableobj.cxx index b0accab93498..8bf8a2b13729 100644 --- a/svx/source/table/viewcontactoftableobj.cxx +++ b/svx/source/table/viewcontactoftableobj.cxx @@ -24,12 +24,11 @@ #include #include #include +#include #include #include #include #include -#include -#include #include #include #include @@ -57,40 +56,6 @@ using namespace com::sun::star; namespace drawinglayer::primitive2d { - namespace { - - class SdrCellPrimitive2D : public BufferedDecompositionPrimitive2D - { - private: - basegfx::B2DHomMatrix maTransform; - attribute::SdrFillTextAttribute maSdrFTAttribute; - - protected: - // local decomposition. - virtual void create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& aViewInformation) const override; - - public: - SdrCellPrimitive2D( - basegfx::B2DHomMatrix aTransform, - const attribute::SdrFillTextAttribute& rSdrFTAttribute) - : maTransform(std::move(aTransform)), - maSdrFTAttribute(rSdrFTAttribute) - { - } - - // data access - const basegfx::B2DHomMatrix& getTransform() const { return maTransform; } - const attribute::SdrFillTextAttribute& getSdrFTAttribute() const { return maSdrFTAttribute; } - - // compare operator - virtual bool operator==(const BasePrimitive2D& rPrimitive) const override; - - // provide unique ID - virtual sal_uInt32 getPrimitive2DID() const override; - }; - - } - void SdrCellPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*aViewInformation*/) const { // prepare unit polygon -- cgit