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