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 <sdr/primitive2d/sdrellipseprimitive2d.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
23 #include <basegfx/polygon/b2dpolypolygon.hxx>
24 #include <sdr/primitive2d/sdrdecompositiontools.hxx>
25 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
26 #include <basegfx/matrix/b2dhommatrixtools.hxx>
27 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
28 #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
32 using namespace com::sun::star
;
35 namespace drawinglayer::primitive2d
37 Primitive2DReference
SdrEllipsePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*aViewInformation*/) const
39 Primitive2DContainer aRetval
;
41 // create unit outline polygon
42 // Do use createPolygonFromUnitCircle, but let create from first quadrant to mimic old geometry creation.
43 // This is needed to have the same look when stroke is used since the polygon start point defines the
45 basegfx::B2DPolygon
aUnitOutline(basegfx::utils::createPolygonFromUnitCircle(1));
47 // scale and move UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
48 const basegfx::B2DHomMatrix
aUnitCorrectionMatrix(
49 basegfx::utils::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
51 // apply to the geometry
52 aUnitOutline
.transform(aUnitCorrectionMatrix
);
55 if(!getSdrLFSTAttribute().getFill().isDefault())
57 basegfx::B2DPolyPolygon
aTransformed(aUnitOutline
);
59 aTransformed
.transform(getTransform());
61 createPolyPolygonFillPrimitive(
63 getSdrLFSTAttribute().getFill(),
64 getSdrLFSTAttribute().getFillFloatTransGradient()));
68 if(getSdrLFSTAttribute().getLine().isDefault())
70 // create invisible line for HitTest/BoundRect
72 createHiddenGeometryPrimitives2D(
74 basegfx::B2DPolyPolygon(aUnitOutline
),
79 basegfx::B2DPolygon
aTransformed(aUnitOutline
);
81 aTransformed
.transform(getTransform());
83 createPolygonLinePrimitive(
85 getSdrLFSTAttribute().getLine(),
86 attribute::SdrLineStartEndAttribute()));
90 if(!getSdrLFSTAttribute().getText().isDefault())
94 basegfx::B2DPolyPolygon(aUnitOutline
),
96 getSdrLFSTAttribute().getText(),
97 getSdrLFSTAttribute().getLine(),
103 if(!getSdrLFSTAttribute().getShadow().isDefault())
105 aRetval
= createEmbeddedShadowPrimitive(
107 getSdrLFSTAttribute().getShadow());
110 return new GroupPrimitive2D(std::move(aRetval
));
113 SdrEllipsePrimitive2D::SdrEllipsePrimitive2D(
114 basegfx::B2DHomMatrix aTransform
,
115 const attribute::SdrLineFillEffectsTextAttribute
& rSdrLFSTAttribute
)
116 : maTransform(std::move(aTransform
)),
117 maSdrLFSTAttribute(rSdrLFSTAttribute
)
121 bool SdrEllipsePrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
123 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
125 const SdrEllipsePrimitive2D
& rCompare
= static_cast<const SdrEllipsePrimitive2D
&>(rPrimitive
);
127 return (getTransform() == rCompare
.getTransform()
128 && getSdrLFSTAttribute() == rCompare
.getSdrLFSTAttribute());
135 sal_uInt32
SdrEllipsePrimitive2D::getPrimitive2DID() const
137 return PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D
;
142 Primitive2DReference
SdrEllipseSegmentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*aViewInformation*/) const
144 Primitive2DContainer aRetval
;
146 // create unit outline polygon
147 basegfx::B2DPolygon
aUnitOutline(basegfx::utils::createPolygonFromUnitEllipseSegment(mfStartAngle
, mfEndAngle
));
151 if(mbCloseUsingCenter
)
153 // for compatibility, insert the center point at polygon start to get the same
154 // line stroking pattern as the old painting mechanisms.
155 aUnitOutline
.insert(0, basegfx::B2DPoint(0.0, 0.0));
158 aUnitOutline
.setClosed(true);
161 // move and scale UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
162 const basegfx::B2DHomMatrix
aUnitCorrectionMatrix(
163 basegfx::utils::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
165 // apply to the geometry
166 aUnitOutline
.transform(aUnitCorrectionMatrix
);
169 if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline
.isClosed())
171 basegfx::B2DPolyPolygon
aTransformed(aUnitOutline
);
173 aTransformed
.transform(getTransform());
175 createPolyPolygonFillPrimitive(
177 getSdrLFSTAttribute().getFill(),
178 getSdrLFSTAttribute().getFillFloatTransGradient()));
182 if(getSdrLFSTAttribute().getLine().isDefault())
184 // create invisible line for HitTest/BoundRect
186 createHiddenGeometryPrimitives2D(
188 basegfx::B2DPolyPolygon(aUnitOutline
),
193 basegfx::B2DPolygon
aTransformed(aUnitOutline
);
195 aTransformed
.transform(getTransform());
197 createPolygonLinePrimitive(
199 getSdrLFSTAttribute().getLine(),
200 getSdrLFSTAttribute().getLineStartEnd()));
204 if(!getSdrLFSTAttribute().getText().isDefault())
208 basegfx::B2DPolyPolygon(aUnitOutline
),
210 getSdrLFSTAttribute().getText(),
211 getSdrLFSTAttribute().getLine(),
217 if(!getSdrLFSTAttribute().getShadow().isDefault())
219 aRetval
= createEmbeddedShadowPrimitive(
221 getSdrLFSTAttribute().getShadow());
224 return new GroupPrimitive2D(std::move(aRetval
));
227 SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
228 const basegfx::B2DHomMatrix
& rTransform
,
229 const attribute::SdrLineFillEffectsTextAttribute
& rSdrLFSTAttribute
,
233 bool bCloseUsingCenter
)
234 : SdrEllipsePrimitive2D(rTransform
, rSdrLFSTAttribute
),
235 mfStartAngle(fStartAngle
),
236 mfEndAngle(fEndAngle
),
237 mbCloseSegment(bCloseSegment
),
238 mbCloseUsingCenter(bCloseUsingCenter
)
242 bool SdrEllipseSegmentPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
244 if(SdrEllipsePrimitive2D::operator==(rPrimitive
))
246 const SdrEllipseSegmentPrimitive2D
& rCompare
= static_cast<const SdrEllipseSegmentPrimitive2D
&>(rPrimitive
);
248 if( mfStartAngle
== rCompare
.mfStartAngle
249 && mfEndAngle
== rCompare
.mfEndAngle
250 && mbCloseSegment
== rCompare
.mbCloseSegment
251 && mbCloseUsingCenter
== rCompare
.mbCloseUsingCenter
)
261 sal_uInt32
SdrEllipseSegmentPrimitive2D::getPrimitive2DID() const
263 return PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D
;
266 } // end of namespace
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */