1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_svx.hxx"
25cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrellipseprimitive2d.hxx>
26cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
27cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
28cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
29cdf0e10cSrcweir #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
30cdf0e10cSrcweir #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
31cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx>
32cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
33cdf0e10cSrcweir #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace com::sun::star;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace drawinglayer
42cdf0e10cSrcweir {
43cdf0e10cSrcweir 	namespace primitive2d
44cdf0e10cSrcweir 	{
create2DDecomposition(const geometry::ViewInformation2D &) const45cdf0e10cSrcweir 		Primitive2DSequence SdrEllipsePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
46cdf0e10cSrcweir 		{
47cdf0e10cSrcweir 			Primitive2DSequence aRetval;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 			// create unit outline polygon
50cdf0e10cSrcweir 			// Do use createPolygonFromUnitCircle, but let create from first quadrant to mimic old geometry creation.
51cdf0e10cSrcweir 			// This is needed to have the same look when stroke is used since the polygon start point defines the
52cdf0e10cSrcweir 			// stroke start, too.
53cdf0e10cSrcweir 			basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromUnitCircle(1));
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 			// scale and move UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
56cdf0e10cSrcweir 			const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
57cdf0e10cSrcweir                 basegfx::tools::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 			// apply to the geometry
60cdf0e10cSrcweir 			aUnitOutline.transform(aUnitCorrectionMatrix);
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 			// add fill
63cdf0e10cSrcweir 			if(!getSdrLFSTAttribute().getFill().isDefault())
64cdf0e10cSrcweir 			{
65cdf0e10cSrcweir 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
66cdf0e10cSrcweir                     createPolyPolygonFillPrimitive(
67cdf0e10cSrcweir                         basegfx::B2DPolyPolygon(aUnitOutline),
68cdf0e10cSrcweir                         getTransform(),
69cdf0e10cSrcweir                         getSdrLFSTAttribute().getFill(),
70cdf0e10cSrcweir                         getSdrLFSTAttribute().getFillFloatTransGradient()));
71cdf0e10cSrcweir 			}
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 			// add line
74cdf0e10cSrcweir 			if(getSdrLFSTAttribute().getLine().isDefault())
75cdf0e10cSrcweir 			{
76cdf0e10cSrcweir 				// create invisible line for HitTest/BoundRect
77cdf0e10cSrcweir 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
78cdf0e10cSrcweir 					createHiddenGeometryPrimitives2D(
79cdf0e10cSrcweir                         false,
80cdf0e10cSrcweir 						basegfx::B2DPolyPolygon(aUnitOutline),
81cdf0e10cSrcweir                         getTransform()));
82cdf0e10cSrcweir 			}
83cdf0e10cSrcweir 			else
84cdf0e10cSrcweir 			{
85cdf0e10cSrcweir 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
86cdf0e10cSrcweir                     createPolygonLinePrimitive(
87cdf0e10cSrcweir                         aUnitOutline,
88cdf0e10cSrcweir                         getTransform(),
89cdf0e10cSrcweir                         getSdrLFSTAttribute().getLine(),
90cdf0e10cSrcweir 						attribute::SdrLineStartEndAttribute()));
91cdf0e10cSrcweir 			}
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 			// add text
94cdf0e10cSrcweir 			if(!getSdrLFSTAttribute().getText().isDefault())
95cdf0e10cSrcweir 			{
96cdf0e10cSrcweir 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
97cdf0e10cSrcweir                     createTextPrimitive(
98cdf0e10cSrcweir                         basegfx::B2DPolyPolygon(aUnitOutline),
99cdf0e10cSrcweir                         getTransform(),
100cdf0e10cSrcweir                         getSdrLFSTAttribute().getText(),
101cdf0e10cSrcweir                         getSdrLFSTAttribute().getLine(),
102cdf0e10cSrcweir                         false,
103cdf0e10cSrcweir                         false,
104cdf0e10cSrcweir                         false));
105cdf0e10cSrcweir 			}
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 			// add shadow
108cdf0e10cSrcweir 			if(!getSdrLFSTAttribute().getShadow().isDefault())
109cdf0e10cSrcweir 			{
110cdf0e10cSrcweir                 aRetval = createEmbeddedShadowPrimitive(
111cdf0e10cSrcweir                     aRetval,
112cdf0e10cSrcweir                     getSdrLFSTAttribute().getShadow());
113cdf0e10cSrcweir 			}
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 			return aRetval;
116cdf0e10cSrcweir 		}
117cdf0e10cSrcweir 
SdrEllipsePrimitive2D(const basegfx::B2DHomMatrix & rTransform,const attribute::SdrLineFillShadowTextAttribute & rSdrLFSTAttribute)118cdf0e10cSrcweir 		SdrEllipsePrimitive2D::SdrEllipsePrimitive2D(
119cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rTransform,
120cdf0e10cSrcweir 			const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute)
121cdf0e10cSrcweir 		:	BufferedDecompositionPrimitive2D(),
122cdf0e10cSrcweir 			maTransform(rTransform),
123cdf0e10cSrcweir 			maSdrLFSTAttribute(rSdrLFSTAttribute)
124cdf0e10cSrcweir 		{
125cdf0e10cSrcweir 		}
126cdf0e10cSrcweir 
operator ==(const BasePrimitive2D & rPrimitive) const127cdf0e10cSrcweir 		bool SdrEllipsePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
128cdf0e10cSrcweir 		{
129cdf0e10cSrcweir 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
130cdf0e10cSrcweir 			{
131cdf0e10cSrcweir 				const SdrEllipsePrimitive2D& rCompare = (SdrEllipsePrimitive2D&)rPrimitive;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 				return (getTransform() == rCompare.getTransform()
134cdf0e10cSrcweir 					&& getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute());
135cdf0e10cSrcweir 			}
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 			return false;
138cdf0e10cSrcweir 		}
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 		// provide unique ID
141cdf0e10cSrcweir 		ImplPrimitrive2DIDBlock(SdrEllipsePrimitive2D, PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D)
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	} // end of namespace primitive2d
144cdf0e10cSrcweir } // end of namespace drawinglayer
145cdf0e10cSrcweir 
146cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
147cdf0e10cSrcweir 
148cdf0e10cSrcweir namespace drawinglayer
149cdf0e10cSrcweir {
150cdf0e10cSrcweir 	namespace primitive2d
151cdf0e10cSrcweir 	{
create2DDecomposition(const geometry::ViewInformation2D &) const152cdf0e10cSrcweir 		Primitive2DSequence SdrEllipseSegmentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
153cdf0e10cSrcweir 		{
154cdf0e10cSrcweir 			Primitive2DSequence aRetval;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 			// create unit outline polygon
157cdf0e10cSrcweir 			basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromUnitEllipseSegment(mfStartAngle, mfEndAngle));
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 			if(mbCloseSegment)
160cdf0e10cSrcweir 			{
161cdf0e10cSrcweir 				if(mbCloseUsingCenter)
162cdf0e10cSrcweir 				{
163cdf0e10cSrcweir 					// for compatibility, insert the center point at polygon start to get the same
164cdf0e10cSrcweir 					// line stroking pattern as the old painting mechanisms.
165cdf0e10cSrcweir 					aUnitOutline.insert(0L, basegfx::B2DPoint(0.0, 0.0));
166cdf0e10cSrcweir 				}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 				aUnitOutline.setClosed(true);
169cdf0e10cSrcweir 			}
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 			// move and scale UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
172cdf0e10cSrcweir 			const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
173cdf0e10cSrcweir                 basegfx::tools::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 			// apply to the geometry
176cdf0e10cSrcweir 			aUnitOutline.transform(aUnitCorrectionMatrix);
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 			// add fill
179cdf0e10cSrcweir 			if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline.isClosed())
180cdf0e10cSrcweir 			{
181cdf0e10cSrcweir 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
182cdf0e10cSrcweir                     createPolyPolygonFillPrimitive(
183cdf0e10cSrcweir                         basegfx::B2DPolyPolygon(aUnitOutline),
184cdf0e10cSrcweir                         getTransform(),
185cdf0e10cSrcweir                         getSdrLFSTAttribute().getFill(),
186cdf0e10cSrcweir                         getSdrLFSTAttribute().getFillFloatTransGradient()));
187cdf0e10cSrcweir 			}
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 			// add line
190cdf0e10cSrcweir 			if(getSdrLFSTAttribute().getLine().isDefault())
191cdf0e10cSrcweir 			{
192cdf0e10cSrcweir 				// create invisible line for HitTest/BoundRect
193cdf0e10cSrcweir 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
194cdf0e10cSrcweir 					createHiddenGeometryPrimitives2D(
195cdf0e10cSrcweir                         false,
196cdf0e10cSrcweir 						basegfx::B2DPolyPolygon(aUnitOutline),
197cdf0e10cSrcweir                         getTransform()));
198cdf0e10cSrcweir 			}
199cdf0e10cSrcweir 			else
200cdf0e10cSrcweir 			{
201cdf0e10cSrcweir 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
202cdf0e10cSrcweir                     createPolygonLinePrimitive(
203cdf0e10cSrcweir                         aUnitOutline,
204cdf0e10cSrcweir                         getTransform(),
205cdf0e10cSrcweir                         getSdrLFSTAttribute().getLine(),
206cdf0e10cSrcweir                         getSdrLFSTAttribute().getLineStartEnd()));
207cdf0e10cSrcweir 			}
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 			// add text
210cdf0e10cSrcweir 			if(!getSdrLFSTAttribute().getText().isDefault())
211cdf0e10cSrcweir 			{
212cdf0e10cSrcweir 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
213cdf0e10cSrcweir                     createTextPrimitive(
214cdf0e10cSrcweir                         basegfx::B2DPolyPolygon(aUnitOutline),
215cdf0e10cSrcweir                         getTransform(),
216cdf0e10cSrcweir 						getSdrLFSTAttribute().getText(),
217cdf0e10cSrcweir                         getSdrLFSTAttribute().getLine(),
218cdf0e10cSrcweir                         false,
219cdf0e10cSrcweir                         false,
220cdf0e10cSrcweir                         false));
221cdf0e10cSrcweir 			}
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 			// add shadow
224cdf0e10cSrcweir 			if(!getSdrLFSTAttribute().getShadow().isDefault())
225cdf0e10cSrcweir 			{
226cdf0e10cSrcweir                 aRetval = createEmbeddedShadowPrimitive(
227cdf0e10cSrcweir                     aRetval,
228cdf0e10cSrcweir                     getSdrLFSTAttribute().getShadow());
229cdf0e10cSrcweir 			}
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 			return aRetval;
232cdf0e10cSrcweir 		}
233cdf0e10cSrcweir 
SdrEllipseSegmentPrimitive2D(const basegfx::B2DHomMatrix & rTransform,const attribute::SdrLineFillShadowTextAttribute & rSdrLFSTAttribute,double fStartAngle,double fEndAngle,bool bCloseSegment,bool bCloseUsingCenter)234cdf0e10cSrcweir 		SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
235cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rTransform,
236cdf0e10cSrcweir 			const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
237cdf0e10cSrcweir 			double fStartAngle,
238cdf0e10cSrcweir 			double fEndAngle,
239cdf0e10cSrcweir 			bool bCloseSegment,
240cdf0e10cSrcweir 			bool bCloseUsingCenter)
241cdf0e10cSrcweir 		:	SdrEllipsePrimitive2D(rTransform, rSdrLFSTAttribute),
242cdf0e10cSrcweir 			mfStartAngle(fStartAngle),
243cdf0e10cSrcweir 			mfEndAngle(fEndAngle),
244cdf0e10cSrcweir 			mbCloseSegment(bCloseSegment),
245cdf0e10cSrcweir 			mbCloseUsingCenter(bCloseUsingCenter)
246cdf0e10cSrcweir 		{
247cdf0e10cSrcweir 		}
248cdf0e10cSrcweir 
operator ==(const BasePrimitive2D & rPrimitive) const249cdf0e10cSrcweir 		bool SdrEllipseSegmentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
250cdf0e10cSrcweir 		{
251cdf0e10cSrcweir 			if(SdrEllipsePrimitive2D::operator==(rPrimitive))
252cdf0e10cSrcweir 			{
253cdf0e10cSrcweir 				const SdrEllipseSegmentPrimitive2D& rCompare = (SdrEllipseSegmentPrimitive2D&)rPrimitive;
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 				if(	mfStartAngle == rCompare.mfStartAngle
256cdf0e10cSrcweir 					&& mfEndAngle == rCompare.mfEndAngle
257cdf0e10cSrcweir 					&& mbCloseSegment == rCompare.mbCloseSegment
258cdf0e10cSrcweir 					&& mbCloseUsingCenter == rCompare.mbCloseUsingCenter)
259cdf0e10cSrcweir 				{
260cdf0e10cSrcweir 					return true;
261cdf0e10cSrcweir 				}
262cdf0e10cSrcweir 			}
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 			return false;
265cdf0e10cSrcweir 		}
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 		// provide unique ID
268cdf0e10cSrcweir 		ImplPrimitrive2DIDBlock(SdrEllipseSegmentPrimitive2D, PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D)
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 	} // end of namespace primitive2d
271cdf0e10cSrcweir } // end of namespace drawinglayer
272cdf0e10cSrcweir 
273cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
274cdf0e10cSrcweir // eof
275