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 <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
24 #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
25 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
26 #include <basegfx/color/bcolor.hxx>
27 #include <basegfx/matrix/b2dhommatrixtools.hxx>
28 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
32 using namespace com::sun::star
;
36 namespace drawinglayer
40 Primitive2DSequence
SdrEllipsePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*aViewInformation*/) const
42 Primitive2DSequence aRetval
;
44 // create unit outline polygon
45 // Do use createPolygonFromUnitCircle, but let create from first quadrant to mimic old geometry creation.
46 // This is needed to have the same look when stroke is used since the polygon start point defines the
48 basegfx::B2DPolygon
aUnitOutline(basegfx::tools::createPolygonFromUnitCircle(1));
50 // scale and move UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
51 const basegfx::B2DHomMatrix
aUnitCorrectionMatrix(
52 basegfx::tools::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
54 // apply to the geometry
55 aUnitOutline
.transform(aUnitCorrectionMatrix
);
58 if(!getSdrLFSTAttribute().getFill().isDefault())
60 basegfx::B2DPolyPolygon
aTransformed(aUnitOutline
);
62 aTransformed
.transform(getTransform());
63 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
64 createPolyPolygonFillPrimitive(
66 getSdrLFSTAttribute().getFill(),
67 getSdrLFSTAttribute().getFillFloatTransGradient()));
71 if(getSdrLFSTAttribute().getLine().isDefault())
73 // create invisible line for HitTest/BoundRect
74 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
75 createHiddenGeometryPrimitives2D(
77 basegfx::B2DPolyPolygon(aUnitOutline
),
82 basegfx::B2DPolygon
aTransformed(aUnitOutline
);
84 aTransformed
.transform(getTransform());
85 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
86 createPolygonLinePrimitive(
88 getSdrLFSTAttribute().getLine(),
89 attribute::SdrLineStartEndAttribute()));
93 if(!getSdrLFSTAttribute().getText().isDefault())
95 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
97 basegfx::B2DPolyPolygon(aUnitOutline
),
99 getSdrLFSTAttribute().getText(),
100 getSdrLFSTAttribute().getLine(),
107 if(!getSdrLFSTAttribute().getShadow().isDefault())
109 aRetval
= createEmbeddedShadowPrimitive(
111 getSdrLFSTAttribute().getShadow());
117 SdrEllipsePrimitive2D::SdrEllipsePrimitive2D(
118 const basegfx::B2DHomMatrix
& rTransform
,
119 const attribute::SdrLineFillShadowTextAttribute
& rSdrLFSTAttribute
)
120 : BufferedDecompositionPrimitive2D(),
121 maTransform(rTransform
),
122 maSdrLFSTAttribute(rSdrLFSTAttribute
)
126 bool SdrEllipsePrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
128 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
130 const SdrEllipsePrimitive2D
& rCompare
= static_cast<const SdrEllipsePrimitive2D
&>(rPrimitive
);
132 return (getTransform() == rCompare
.getTransform()
133 && getSdrLFSTAttribute() == rCompare
.getSdrLFSTAttribute());
140 ImplPrimitive2DIDBlock(SdrEllipsePrimitive2D
, PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D
)
142 } // end of namespace primitive2d
143 } // end of namespace drawinglayer
147 namespace drawinglayer
149 namespace primitive2d
151 Primitive2DSequence
SdrEllipseSegmentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*aViewInformation*/) const
153 Primitive2DSequence aRetval
;
155 // create unit outline polygon
156 basegfx::B2DPolygon
aUnitOutline(basegfx::tools::createPolygonFromUnitEllipseSegment(mfStartAngle
, mfEndAngle
));
160 if(mbCloseUsingCenter
)
162 // for compatibility, insert the center point at polygon start to get the same
163 // line stroking pattern as the old painting mechanisms.
164 aUnitOutline
.insert(0L, basegfx::B2DPoint(0.0, 0.0));
167 aUnitOutline
.setClosed(true);
170 // move and scale UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
171 const basegfx::B2DHomMatrix
aUnitCorrectionMatrix(
172 basegfx::tools::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
174 // apply to the geometry
175 aUnitOutline
.transform(aUnitCorrectionMatrix
);
178 if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline
.isClosed())
180 basegfx::B2DPolyPolygon
aTransformed(aUnitOutline
);
182 aTransformed
.transform(getTransform());
183 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
184 createPolyPolygonFillPrimitive(
186 getSdrLFSTAttribute().getFill(),
187 getSdrLFSTAttribute().getFillFloatTransGradient()));
191 if(getSdrLFSTAttribute().getLine().isDefault())
193 // create invisible line for HitTest/BoundRect
194 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
195 createHiddenGeometryPrimitives2D(
197 basegfx::B2DPolyPolygon(aUnitOutline
),
202 basegfx::B2DPolygon
aTransformed(aUnitOutline
);
204 aTransformed
.transform(getTransform());
205 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
206 createPolygonLinePrimitive(
208 getSdrLFSTAttribute().getLine(),
209 getSdrLFSTAttribute().getLineStartEnd()));
213 if(!getSdrLFSTAttribute().getText().isDefault())
215 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
217 basegfx::B2DPolyPolygon(aUnitOutline
),
219 getSdrLFSTAttribute().getText(),
220 getSdrLFSTAttribute().getLine(),
227 if(!getSdrLFSTAttribute().getShadow().isDefault())
229 aRetval
= createEmbeddedShadowPrimitive(
231 getSdrLFSTAttribute().getShadow());
237 SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
238 const basegfx::B2DHomMatrix
& rTransform
,
239 const attribute::SdrLineFillShadowTextAttribute
& rSdrLFSTAttribute
,
243 bool bCloseUsingCenter
)
244 : SdrEllipsePrimitive2D(rTransform
, rSdrLFSTAttribute
),
245 mfStartAngle(fStartAngle
),
246 mfEndAngle(fEndAngle
),
247 mbCloseSegment(bCloseSegment
),
248 mbCloseUsingCenter(bCloseUsingCenter
)
252 bool SdrEllipseSegmentPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
254 if(SdrEllipsePrimitive2D::operator==(rPrimitive
))
256 const SdrEllipseSegmentPrimitive2D
& rCompare
= static_cast<const SdrEllipseSegmentPrimitive2D
&>(rPrimitive
);
258 if( mfStartAngle
== rCompare
.mfStartAngle
259 && mfEndAngle
== rCompare
.mfEndAngle
260 && mbCloseSegment
== rCompare
.mbCloseSegment
261 && mbCloseUsingCenter
== rCompare
.mbCloseUsingCenter
)
271 ImplPrimitive2DIDBlock(SdrEllipseSegmentPrimitive2D
, PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D
)
273 } // end of namespace primitive2d
274 } // end of namespace drawinglayer
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */