1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <drawinglayer/primitive2d/PolyPolygonSelectionPrimitive2D.hxx>
22 #include <basegfx/polygon/b2dpolypolygontools.hxx>
23 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
24 #include <drawinglayer/geometry/viewinformation2d.hxx>
25 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
26 #include <drawinglayer/primitive2d/PolyPolygonStrokePrimitive2D.hxx>
27 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
30 using namespace com::sun::star
;
32 namespace drawinglayer::primitive2d
34 void PolyPolygonSelectionPrimitive2D::create2DDecomposition(
35 Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& /*rViewInformation*/) const
37 if (getTransparence() >= 1.0 || !getB2DPolyPolygon().count())
40 Primitive2DContainer aRetval
;
42 if (getFill() && getB2DPolyPolygon().isClosed())
44 // create fill primitive
45 const Primitive2DReference
aFill(
46 new PolyPolygonColorPrimitive2D(getB2DPolyPolygon(), getColor()));
48 aRetval
= Primitive2DContainer
{ aFill
};
51 if (getDiscreteGrow() > 0.0)
53 const attribute::LineAttribute
aLineAttribute(getColor(),
54 getDiscreteGrow() * getDiscreteUnit() * 2.0);
55 const Primitive2DReference
aFatLine(
56 new PolyPolygonStrokePrimitive2D(getB2DPolyPolygon(), aLineAttribute
));
58 aRetval
.push_back(aFatLine
);
61 // embed filled to transparency (if used)
62 if (!aRetval
.empty() && getTransparence() > 0.0)
64 const Primitive2DReference
aTrans(
65 new UnifiedTransparencePrimitive2D(std::move(aRetval
), getTransparence()));
67 aRetval
= Primitive2DContainer
{ aTrans
};
70 rContainer
.append(std::move(aRetval
));
73 PolyPolygonSelectionPrimitive2D::PolyPolygonSelectionPrimitive2D(
74 basegfx::B2DPolyPolygon aPolyPolygon
, const basegfx::BColor
& rColor
, double fTransparence
,
75 double fDiscreteGrow
, bool bFill
)
76 : maPolyPolygon(std::move(aPolyPolygon
))
78 , mfTransparence(fTransparence
)
79 , mfDiscreteGrow(fabs(fDiscreteGrow
))
84 bool PolyPolygonSelectionPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
86 if (DiscreteMetricDependentPrimitive2D::operator==(rPrimitive
))
88 const PolyPolygonSelectionPrimitive2D
& rCompare
89 = static_cast<const PolyPolygonSelectionPrimitive2D
&>(rPrimitive
);
92 getB2DPolyPolygon() == rCompare
.getB2DPolyPolygon() && getColor() == rCompare
.getColor()
93 && getTransparence() == rCompare
.getTransparence()
94 && getDiscreteGrow() == rCompare
.getDiscreteGrow() && getFill() == rCompare
.getFill());
100 basegfx::B2DRange
PolyPolygonSelectionPrimitive2D::getB2DRange(
101 const geometry::ViewInformation2D
& rViewInformation
) const
103 basegfx::B2DRange
aRetval(basegfx::utils::getRange(getB2DPolyPolygon()));
105 if (getDiscreteGrow() > 0.0)
107 // get the current DiscreteUnit (not sure if getDiscreteUnit() is updated here, better go safe way)
108 const double fDiscreteUnit(
109 (rViewInformation
.getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 0.0))
112 aRetval
.grow(fDiscreteUnit
* getDiscreteGrow());
119 sal_uInt32
PolyPolygonSelectionPrimitive2D::getPrimitive2DID() const
121 return PRIMITIVE2D_ID_POLYPOLYGONSELECTIONPRIMITIVE2D
;
124 } // end drawinglayer::primitive2d namespace
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */