bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrellipseprimitive2d.cxx
blob7838393d63a92b1a86edb6ead97de4081784fe79
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
38 namespace primitive2d
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
47 // stroke start, too.
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);
57 // add fill
58 if(!getSdrLFSTAttribute().getFill().isDefault())
60 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
62 aTransformed.transform(getTransform());
63 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
64 createPolyPolygonFillPrimitive(
65 aTransformed,
66 getSdrLFSTAttribute().getFill(),
67 getSdrLFSTAttribute().getFillFloatTransGradient()));
70 // add line
71 if(getSdrLFSTAttribute().getLine().isDefault())
73 // create invisible line for HitTest/BoundRect
74 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
75 createHiddenGeometryPrimitives2D(
76 false,
77 basegfx::B2DPolyPolygon(aUnitOutline),
78 getTransform()));
80 else
82 basegfx::B2DPolygon aTransformed(aUnitOutline);
84 aTransformed.transform(getTransform());
85 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
86 createPolygonLinePrimitive(
87 aTransformed,
88 getSdrLFSTAttribute().getLine(),
89 attribute::SdrLineStartEndAttribute()));
92 // add text
93 if(!getSdrLFSTAttribute().getText().isDefault())
95 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
96 createTextPrimitive(
97 basegfx::B2DPolyPolygon(aUnitOutline),
98 getTransform(),
99 getSdrLFSTAttribute().getText(),
100 getSdrLFSTAttribute().getLine(),
101 false,
102 false,
103 false));
106 // add shadow
107 if(!getSdrLFSTAttribute().getShadow().isDefault())
109 aRetval = createEmbeddedShadowPrimitive(
110 aRetval,
111 getSdrLFSTAttribute().getShadow());
114 return aRetval;
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());
136 return false;
139 // provide unique ID
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));
158 if(mbCloseSegment)
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);
177 // add fill
178 if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline.isClosed())
180 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
182 aTransformed.transform(getTransform());
183 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
184 createPolyPolygonFillPrimitive(
185 aTransformed,
186 getSdrLFSTAttribute().getFill(),
187 getSdrLFSTAttribute().getFillFloatTransGradient()));
190 // add line
191 if(getSdrLFSTAttribute().getLine().isDefault())
193 // create invisible line for HitTest/BoundRect
194 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
195 createHiddenGeometryPrimitives2D(
196 false,
197 basegfx::B2DPolyPolygon(aUnitOutline),
198 getTransform()));
200 else
202 basegfx::B2DPolygon aTransformed(aUnitOutline);
204 aTransformed.transform(getTransform());
205 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
206 createPolygonLinePrimitive(
207 aTransformed,
208 getSdrLFSTAttribute().getLine(),
209 getSdrLFSTAttribute().getLineStartEnd()));
212 // add text
213 if(!getSdrLFSTAttribute().getText().isDefault())
215 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
216 createTextPrimitive(
217 basegfx::B2DPolyPolygon(aUnitOutline),
218 getTransform(),
219 getSdrLFSTAttribute().getText(),
220 getSdrLFSTAttribute().getLine(),
221 false,
222 false,
223 false));
226 // add shadow
227 if(!getSdrLFSTAttribute().getShadow().isDefault())
229 aRetval = createEmbeddedShadowPrimitive(
230 aRetval,
231 getSdrLFSTAttribute().getShadow());
234 return aRetval;
237 SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
238 const basegfx::B2DHomMatrix& rTransform,
239 const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
240 double fStartAngle,
241 double fEndAngle,
242 bool bCloseSegment,
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)
263 return true;
267 return false;
270 // provide unique ID
271 ImplPrimitive2DIDBlock(SdrEllipseSegmentPrimitive2D, PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D)
273 } // end of namespace primitive2d
274 } // end of namespace drawinglayer
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */