Kaydet (Commit) d1027af3 authored tarafından Armin Le Grand's avatar Armin Le Grand

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
üst 9886a69c
......@@ -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();
......
......@@ -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;
......
......@@ -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);
}
}
}
......
......@@ -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 };
}
......
......@@ -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());
}
......
......@@ -285,7 +285,8 @@ void SdrObject::SetBoundRectDirty()
SdrObject::SdrObject() :
pPage(nullptr)
mpFillGeometryDefiningShape(nullptr)
,pPage(nullptr)
,pModel(nullptr)
,pUserCall(nullptr)
,pPlusData(nullptr)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment