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 <svx/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>
30 //////////////////////////////////////////////////////////////////////////////
32 using namespace com::sun::star
;
34 //////////////////////////////////////////////////////////////////////////////
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 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
61 createPolyPolygonFillPrimitive(
62 basegfx::B2DPolyPolygon(aUnitOutline
),
64 getSdrLFSTAttribute().getFill(),
65 getSdrLFSTAttribute().getFillFloatTransGradient()));
69 if(getSdrLFSTAttribute().getLine().isDefault())
71 // create invisible line for HitTest/BoundRect
72 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
73 createHiddenGeometryPrimitives2D(
75 basegfx::B2DPolyPolygon(aUnitOutline
),
80 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
81 createPolygonLinePrimitive(
84 getSdrLFSTAttribute().getLine(),
85 attribute::SdrLineStartEndAttribute()));
89 if(!getSdrLFSTAttribute().getText().isDefault())
91 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
93 basegfx::B2DPolyPolygon(aUnitOutline
),
95 getSdrLFSTAttribute().getText(),
96 getSdrLFSTAttribute().getLine(),
103 if(!getSdrLFSTAttribute().getShadow().isDefault())
105 aRetval
= createEmbeddedShadowPrimitive(
107 getSdrLFSTAttribute().getShadow());
113 SdrEllipsePrimitive2D::SdrEllipsePrimitive2D(
114 const basegfx::B2DHomMatrix
& rTransform
,
115 const attribute::SdrLineFillShadowTextAttribute
& rSdrLFSTAttribute
)
116 : BufferedDecompositionPrimitive2D(),
117 maTransform(rTransform
),
118 maSdrLFSTAttribute(rSdrLFSTAttribute
)
122 bool SdrEllipsePrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
124 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
126 const SdrEllipsePrimitive2D
& rCompare
= (SdrEllipsePrimitive2D
&)rPrimitive
;
128 return (getTransform() == rCompare
.getTransform()
129 && getSdrLFSTAttribute() == rCompare
.getSdrLFSTAttribute());
136 ImplPrimitive2DIDBlock(SdrEllipsePrimitive2D
, PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D
)
138 } // end of namespace primitive2d
139 } // end of namespace drawinglayer
141 //////////////////////////////////////////////////////////////////////////////
143 namespace drawinglayer
145 namespace primitive2d
147 Primitive2DSequence
SdrEllipseSegmentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*aViewInformation*/) const
149 Primitive2DSequence aRetval
;
151 // create unit outline polygon
152 basegfx::B2DPolygon
aUnitOutline(basegfx::tools::createPolygonFromUnitEllipseSegment(mfStartAngle
, mfEndAngle
));
156 if(mbCloseUsingCenter
)
158 // for compatibility, insert the center point at polygon start to get the same
159 // line stroking pattern as the old painting mechanisms.
160 aUnitOutline
.insert(0L, basegfx::B2DPoint(0.0, 0.0));
163 aUnitOutline
.setClosed(true);
166 // move and scale UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
167 const basegfx::B2DHomMatrix
aUnitCorrectionMatrix(
168 basegfx::tools::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
170 // apply to the geometry
171 aUnitOutline
.transform(aUnitCorrectionMatrix
);
174 if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline
.isClosed())
176 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
177 createPolyPolygonFillPrimitive(
178 basegfx::B2DPolyPolygon(aUnitOutline
),
180 getSdrLFSTAttribute().getFill(),
181 getSdrLFSTAttribute().getFillFloatTransGradient()));
185 if(getSdrLFSTAttribute().getLine().isDefault())
187 // create invisible line for HitTest/BoundRect
188 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
189 createHiddenGeometryPrimitives2D(
191 basegfx::B2DPolyPolygon(aUnitOutline
),
196 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
197 createPolygonLinePrimitive(
200 getSdrLFSTAttribute().getLine(),
201 getSdrLFSTAttribute().getLineStartEnd()));
205 if(!getSdrLFSTAttribute().getText().isDefault())
207 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
,
209 basegfx::B2DPolyPolygon(aUnitOutline
),
211 getSdrLFSTAttribute().getText(),
212 getSdrLFSTAttribute().getLine(),
219 if(!getSdrLFSTAttribute().getShadow().isDefault())
221 aRetval
= createEmbeddedShadowPrimitive(
223 getSdrLFSTAttribute().getShadow());
229 SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
230 const basegfx::B2DHomMatrix
& rTransform
,
231 const attribute::SdrLineFillShadowTextAttribute
& rSdrLFSTAttribute
,
235 bool bCloseUsingCenter
)
236 : SdrEllipsePrimitive2D(rTransform
, rSdrLFSTAttribute
),
237 mfStartAngle(fStartAngle
),
238 mfEndAngle(fEndAngle
),
239 mbCloseSegment(bCloseSegment
),
240 mbCloseUsingCenter(bCloseUsingCenter
)
244 bool SdrEllipseSegmentPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
246 if(SdrEllipsePrimitive2D::operator==(rPrimitive
))
248 const SdrEllipseSegmentPrimitive2D
& rCompare
= (SdrEllipseSegmentPrimitive2D
&)rPrimitive
;
250 if( mfStartAngle
== rCompare
.mfStartAngle
251 && mfEndAngle
== rCompare
.mfEndAngle
252 && mbCloseSegment
== rCompare
.mbCloseSegment
253 && mbCloseUsingCenter
== rCompare
.mbCloseUsingCenter
)
263 ImplPrimitive2DIDBlock(SdrEllipseSegmentPrimitive2D
, PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D
)
265 } // end of namespace primitive2d
266 } // end of namespace drawinglayer
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */