diff options
author | Armin Le Grand <Armin.Le.Grand@cib.de (CIB)> | 2018-02-23 16:57:41 +0100 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@cib.de (CIB)> | 2018-03-17 23:15:49 +0100 |
commit | d1027af3c74529827d53e8cf7b0d42a0ee47d1ba (patch) | |
tree | 488efdfb60e5e9bd01af54679872a8b91b0e14c4 | |
parent | 9886a69c472f212d88f11cfa0f3835e5dcf485b2 (diff) |
OperationSmiley: Added support for using same FillGeometry
It is now possible to use a single FillGeometry to fill objects that
are made of multiple filled objects (e.g. CustomShapes) so that
they look as using a single fill. This is used for CustomShapes,
but may later be 'extended' to be used for more cases. The basic
functionality was already in the primitives, but had to be added
to SDrObject due to these being used for CustomShapeVisualization
(currently - would be better to change this to primitives, too).
Change-Id: I1d9fb158191a9ec663e46f3911213be2f3d88986
-rw-r--r-- | include/svx/svdobj.hxx | 21 | ||||
-rw-r--r-- | svx/inc/sdr/primitive2d/sdrpathprimitive2d.hxx | 18 | ||||
-rw-r--r-- | svx/source/customshapes/EnhancedCustomShape2d.cxx | 26 | ||||
-rw-r--r-- | svx/source/sdr/contact/viewcontactofsdrpathobj.cxx | 28 | ||||
-rw-r--r-- | svx/source/sdr/primitive2d/sdrpathprimitive2d.cxx | 37 | ||||
-rw-r--r-- | svx/source/svdraw/svdobj.cxx | 3 |
6 files changed, 106 insertions, 27 deletions
diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx index 3e97a472084f..7bd547f20d71 100644 --- a/include/svx/svdobj.hxx +++ b/include/svx/svdobj.hxx @@ -270,11 +270,32 @@ public: class SvxShape; class SVX_DLLPUBLIC SdrObject: public SfxListener, public virtual tools::WeakBase { +private: friend class SdrObjListIter; friend class SdrVirtObj; friend class SdrRectObj; friend class SdrDelayBroadcastObjectChange; + // OperationSmiley: Allow at each SdrObject to set a FillGeometryDefiningShape, + // so that for SdrObjects where this is set, the definition of a defined FillStyle + // will use this, but the local geometry will be filled. This allows to fill + // multiple shapes with a unified fill, e.g think about CustomShapes. + // Currently this is *only* used for CustomShapes, but may be developed to get a + // common mechanism - usages for it are easy to be found. The current limitation + // to CustomShapes allows to to think about these SdrObjects to 'vanish' during the + // lifetime of 'this' - the SdrObjects without SdrPage and SdrModel are used as helper + // objects for SdrObjCustomShape and thus their lifetime is limited to the lifetime + // of this local object. For unifying this mechanism, some weak reference of + // SdrObjects would have to be thought about (not easy with the current implementation). + // So - allow *only* EnhancedCustomShape2d (which creates the visualizations for + // SdrObjCustomShape) to set this. Already allow unified read to use it - thus already + // allowing to implement as standard case for all kinds of SdrObjects. + friend class EnhancedCustomShape2d; + const SdrObject* mpFillGeometryDefiningShape; + void setFillGeometryDefiningShape(const SdrObject* pNew) { mpFillGeometryDefiningShape = pNew; } +public: + const SdrObject* getFillGeometryDefiningShape() const { return mpFillGeometryDefiningShape; } + public: SdrObject(); diff --git a/svx/inc/sdr/primitive2d/sdrpathprimitive2d.hxx b/svx/inc/sdr/primitive2d/sdrpathprimitive2d.hxx index b60e9b3df565..e165344b26c1 100644 --- a/svx/inc/sdr/primitive2d/sdrpathprimitive2d.hxx +++ b/svx/inc/sdr/primitive2d/sdrpathprimitive2d.hxx @@ -40,20 +40,36 @@ namespace drawinglayer attribute::SdrLineFillShadowTextAttribute maSdrLFSTAttribute; basegfx::B2DPolyPolygon maUnitPolyPolygon; + // OperationSmiley: Added to be able to define a FillGeometry different from local + // geometry. It is ignored when empty and/or equal to UnitPolyPolygon. + // If used and there is a fill, object's geomery (maUnitPolyPolygon) will be filled, + // but UnitDefinitionPolyPolygon will be used to define the FillStyle. Thus when + // using the 'same' UnitDefinitionPolyPolygon for multiple definitions, + // all filled stuff using it will fit seamless together. + // 'same' is in quotes since it is a UnitPolygon, so being relative to the + // unit polygon of the local geometry (UnitPolyPolygon). The definition is complete + // when applying the also given transfomation (maTransform) + basegfx::B2DPolyPolygon maUnitDefinitionPolyPolygon; + protected: // local decomposition. virtual void create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& aViewInformation) const override; public: + // OperationSmiley: Extended to UnitDefinitionPolyPolygon, but when needed + // a 2nd version without can be defined that just does not set the + // maUnitDefinitionPolyPolygon or set equal to UnitPolyPolygon SdrPathPrimitive2D( const basegfx::B2DHomMatrix& rTransform, const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute, - const basegfx::B2DPolyPolygon& rUnitPolyPolygon); + const basegfx::B2DPolyPolygon& rUnitPolyPolygon, + const basegfx::B2DPolyPolygon& rUnitDefinitionPolyPolygon); // data access const basegfx::B2DHomMatrix& getTransform() const { return maTransform; } const attribute::SdrLineFillShadowTextAttribute& getSdrLFSTAttribute() const { return maSdrLFSTAttribute; } const basegfx::B2DPolyPolygon& getUnitPolyPolygon() const { return maUnitPolyPolygon; } + const basegfx::B2DPolyPolygon& getUnitDefinitionPolyPolygon() const { return maUnitDefinitionPolyPolygon; } // compare operator virtual bool operator==(const BasePrimitive2D& rPrimitive) const override; diff --git a/svx/source/customshapes/EnhancedCustomShape2d.cxx b/svx/source/customshapes/EnhancedCustomShape2d.cxx index b50836fd138f..39d694b112a8 100644 --- a/svx/source/customshapes/EnhancedCustomShape2d.cxx +++ b/svx/source/customshapes/EnhancedCustomShape2d.cxx @@ -1963,22 +1963,6 @@ void EnhancedCustomShape2d::CreateSubPath( if(aNewB2DPolyPolygon.count()) { - if( !bLineGeometryNeededOnly ) - { - // hack aNewB2DPolyPolygon to fill logic rect - this is - // needed to produce gradient fills that look like mso - aNewB2DPolygon.clear(); - aNewB2DPolygon.append(basegfx::B2DPoint(0,0)); - aNewB2DPolygon.setClosed(true); - aNewB2DPolyPolygon.append(aNewB2DPolygon); - - aNewB2DPolygon.clear(); - aNewB2DPolygon.append(basegfx::B2DPoint(aLogicRect.GetWidth(), - aLogicRect.GetHeight())); - aNewB2DPolygon.setClosed(true); - aNewB2DPolyPolygon.append(aNewB2DPolygon); - } - // #i37011# bool bForceCreateTwoObjects(false); @@ -2335,6 +2319,16 @@ SdrObject* EnhancedCustomShape2d::CreatePathObj( bool bLineGeometryNeededOnly ) rCustomShapeSet, nColorIndex, nColorCount); + + // OperationSmiley: when we have access to the SdrObjCustomShape and the + // CustomShape is built with more than a single filled Geometry, use it + // to define that all helper geometites defined here (SdrObjects currently) + // will use the same FillGeometryDefinition (from the referenced SdrObjCustomShape). + // This will all same-filled objects look like filled smoothly with the same style. + if(pCustomShapeObj) + { + pObj->setFillGeometryDefiningShape(pCustomShapeObj); + } } } diff --git a/svx/source/sdr/contact/viewcontactofsdrpathobj.cxx b/svx/source/sdr/contact/viewcontactofsdrpathobj.cxx index 2f203971ad4f..c3033bf71337 100644 --- a/svx/source/sdr/contact/viewcontactofsdrpathobj.cxx +++ b/svx/source/sdr/contact/viewcontactofsdrpathobj.cxx @@ -83,6 +83,7 @@ namespace sdr // prepare object transformation and unit polygon (direct model data) basegfx::B2DHomMatrix aObjectMatrix; + basegfx::B2DPolyPolygon aUnitDefinitionPolyPolygon; bool bIsLine( !aUnitPolyPolygon.areControlPointsUsed() && 1 == nPolyCount @@ -166,6 +167,30 @@ namespace sdr basegfx::B2DHomMatrix aInverse(aObjectMatrix); aInverse.invert(); aUnitPolyPolygon.transform(aInverse); + + // OperationSmiley: Check if a FillGeometryDefiningShape is set + const SdrObject* pFillGeometryDefiningShape(GetPathObj().getFillGeometryDefiningShape()); + + if(nullptr != pFillGeometryDefiningShape) + { + // If yes, get it's BoundRange and use as defining Geometry for the FillStyle. + // If no, aUnitDefinitionPolyPolygon will just be empty and thus be interpreted + // as unused. + // Using SnapRect will make the FillDefinition to always be extended e.g. + // for rotated/sheared objects. + const tools::Rectangle& rSnapRect(pFillGeometryDefiningShape->GetSnapRect()); + + aUnitDefinitionPolyPolygon.append( + basegfx::utils::createPolygonFromRect( + basegfx::B2DRange( + rSnapRect.Left(), rSnapRect.Top(), + rSnapRect.Right(), rSnapRect.Bottom()))); + + // use same coordinate system as the shape geometry -> this + // makes it relative to shape's unit geometry and thus freely + // transformable with the shape + aUnitDefinitionPolyPolygon.transform(aInverse); + } } // create primitive. Always create primitives to allow the decomposition of @@ -174,7 +199,8 @@ namespace sdr new drawinglayer::primitive2d::SdrPathPrimitive2D( aObjectMatrix, aAttribute, - aUnitPolyPolygon)); + aUnitPolyPolygon, + aUnitDefinitionPolyPolygon)); return drawinglayer::primitive2d::Primitive2DContainer { xReference }; } diff --git a/svx/source/sdr/primitive2d/sdrpathprimitive2d.cxx b/svx/source/sdr/primitive2d/sdrpathprimitive2d.cxx index 37d4f5850b05..804cccf67e80 100644 --- a/svx/source/sdr/primitive2d/sdrpathprimitive2d.cxx +++ b/svx/source/sdr/primitive2d/sdrpathprimitive2d.cxx @@ -43,13 +43,31 @@ namespace drawinglayer // #i108255# no need to use correctOrientations here; target is // straight visualisation basegfx::B2DPolyPolygon aTransformed(getUnitPolyPolygon()); - aTransformed.transform(getTransform()); - aRetval.push_back( - createPolyPolygonFillPrimitive( - aTransformed, - getSdrLFSTAttribute().getFill(), - getSdrLFSTAttribute().getFillFloatTransGradient())); + + // OperationSmiley: Check if a UnitDefinitionPolyPolygon is set + if(getUnitDefinitionPolyPolygon().count() + && getUnitDefinitionPolyPolygon() != getUnitPolyPolygon()) + { + // if yes, use the B2DRange of it's transformed form + basegfx::B2DPolyPolygon aTransformedDefinition(getUnitDefinitionPolyPolygon()); + aTransformedDefinition.transform(getTransform()); + + aRetval.push_back( + createPolyPolygonFillPrimitive( + aTransformed, + aTransformedDefinition.getB2DRange(), + getSdrLFSTAttribute().getFill(), + getSdrLFSTAttribute().getFillFloatTransGradient())); + } + else + { + aRetval.push_back( + createPolyPolygonFillPrimitive( + aTransformed, + getSdrLFSTAttribute().getFill(), + getSdrLFSTAttribute().getFillFloatTransGradient())); + } } // add line @@ -107,11 +125,13 @@ namespace drawinglayer SdrPathPrimitive2D::SdrPathPrimitive2D( const basegfx::B2DHomMatrix& rTransform, const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute, - const basegfx::B2DPolyPolygon& rUnitPolyPolygon) + const basegfx::B2DPolyPolygon& rUnitPolyPolygon, + const basegfx::B2DPolyPolygon& rUnitDefinitionPolyPolygon) : BufferedDecompositionPrimitive2D(), maTransform(rTransform), maSdrLFSTAttribute(rSdrLFSTAttribute), - maUnitPolyPolygon(rUnitPolyPolygon) + maUnitPolyPolygon(rUnitPolyPolygon), + maUnitDefinitionPolyPolygon(rUnitDefinitionPolyPolygon) { } @@ -122,6 +142,7 @@ namespace drawinglayer const SdrPathPrimitive2D& rCompare = static_cast<const SdrPathPrimitive2D&>(rPrimitive); return (getUnitPolyPolygon() == rCompare.getUnitPolyPolygon() + && getUnitDefinitionPolyPolygon() == rCompare.getUnitDefinitionPolyPolygon() && getTransform() == rCompare.getTransform() && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()); } diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx index 7980458914df..7fe409c8bd64 100644 --- a/svx/source/svdraw/svdobj.cxx +++ b/svx/source/svdraw/svdobj.cxx @@ -285,7 +285,8 @@ void SdrObject::SetBoundRectDirty() SdrObject::SdrObject() : - pPage(nullptr) + mpFillGeometryDefiningShape(nullptr) + ,pPage(nullptr) ,pModel(nullptr) ,pUserCall(nullptr) ,pPlusData(nullptr) |