bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrellipseprimitive2d.cxx
blob6139d84d1c4f32bc6556ec814dd27dbfa4412cc0
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 <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
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 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
61 createPolyPolygonFillPrimitive(
62 basegfx::B2DPolyPolygon(aUnitOutline),
63 getTransform(),
64 getSdrLFSTAttribute().getFill(),
65 getSdrLFSTAttribute().getFillFloatTransGradient()));
68 // add line
69 if(getSdrLFSTAttribute().getLine().isDefault())
71 // create invisible line for HitTest/BoundRect
72 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
73 createHiddenGeometryPrimitives2D(
74 false,
75 basegfx::B2DPolyPolygon(aUnitOutline),
76 getTransform()));
78 else
80 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
81 createPolygonLinePrimitive(
82 aUnitOutline,
83 getTransform(),
84 getSdrLFSTAttribute().getLine(),
85 attribute::SdrLineStartEndAttribute()));
88 // add text
89 if(!getSdrLFSTAttribute().getText().isDefault())
91 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
92 createTextPrimitive(
93 basegfx::B2DPolyPolygon(aUnitOutline),
94 getTransform(),
95 getSdrLFSTAttribute().getText(),
96 getSdrLFSTAttribute().getLine(),
97 false,
98 false,
99 false));
102 // add shadow
103 if(!getSdrLFSTAttribute().getShadow().isDefault())
105 aRetval = createEmbeddedShadowPrimitive(
106 aRetval,
107 getSdrLFSTAttribute().getShadow());
110 return aRetval;
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());
132 return false;
135 // provide unique ID
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));
154 if(mbCloseSegment)
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);
173 // add fill
174 if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline.isClosed())
176 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
177 createPolyPolygonFillPrimitive(
178 basegfx::B2DPolyPolygon(aUnitOutline),
179 getTransform(),
180 getSdrLFSTAttribute().getFill(),
181 getSdrLFSTAttribute().getFillFloatTransGradient()));
184 // add line
185 if(getSdrLFSTAttribute().getLine().isDefault())
187 // create invisible line for HitTest/BoundRect
188 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
189 createHiddenGeometryPrimitives2D(
190 false,
191 basegfx::B2DPolyPolygon(aUnitOutline),
192 getTransform()));
194 else
196 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
197 createPolygonLinePrimitive(
198 aUnitOutline,
199 getTransform(),
200 getSdrLFSTAttribute().getLine(),
201 getSdrLFSTAttribute().getLineStartEnd()));
204 // add text
205 if(!getSdrLFSTAttribute().getText().isDefault())
207 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
208 createTextPrimitive(
209 basegfx::B2DPolyPolygon(aUnitOutline),
210 getTransform(),
211 getSdrLFSTAttribute().getText(),
212 getSdrLFSTAttribute().getLine(),
213 false,
214 false,
215 false));
218 // add shadow
219 if(!getSdrLFSTAttribute().getShadow().isDefault())
221 aRetval = createEmbeddedShadowPrimitive(
222 aRetval,
223 getSdrLFSTAttribute().getShadow());
226 return aRetval;
229 SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
230 const basegfx::B2DHomMatrix& rTransform,
231 const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
232 double fStartAngle,
233 double fEndAngle,
234 bool bCloseSegment,
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)
255 return true;
259 return false;
262 // provide unique ID
263 ImplPrimitive2DIDBlock(SdrEllipseSegmentPrimitive2D, PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D)
265 } // end of namespace primitive2d
266 } // end of namespace drawinglayer
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */