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                 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
66 
67                 aTransformed.transform(getTransform());
68                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
69                     createPolyPolygonFillPrimitive(
70                         aTransformed,
71                         getSdrLFSTAttribute().getFill(),
72                         getSdrLFSTAttribute().getFillFloatTransGradient()));
73 			}
74 
75 			// add line
76 			if(getSdrLFSTAttribute().getLine().isDefault())
77 			{
78 				// create invisible line for HitTest/BoundRect
79 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
80 					createHiddenGeometryPrimitives2D(
81                         false,
82 						basegfx::B2DPolyPolygon(aUnitOutline),
83                         getTransform()));
84             }
85             else
86             {
87                 basegfx::B2DPolygon aTransformed(aUnitOutline);
88 
89                 aTransformed.transform(getTransform());
90                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
91                     createPolygonLinePrimitive(
92                         aTransformed,
93                         getSdrLFSTAttribute().getLine(),
94 						attribute::SdrLineStartEndAttribute()));
95 			}
96 
97 			// add text
98 			if(!getSdrLFSTAttribute().getText().isDefault())
99 			{
100 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
101                     createTextPrimitive(
102                         basegfx::B2DPolyPolygon(aUnitOutline),
103                         getTransform(),
104                         getSdrLFSTAttribute().getText(),
105                         getSdrLFSTAttribute().getLine(),
106                         false,
107                         false,
108                         false));
109 			}
110 
111 			// add shadow
112 			if(!getSdrLFSTAttribute().getShadow().isDefault())
113 			{
114                 aRetval = createEmbeddedShadowPrimitive(
115                     aRetval,
116                     getSdrLFSTAttribute().getShadow());
117 			}
118 
119 			return aRetval;
120 		}
121 
SdrEllipsePrimitive2D(const basegfx::B2DHomMatrix & rTransform,const attribute::SdrLineFillShadowTextAttribute & rSdrLFSTAttribute)122 		SdrEllipsePrimitive2D::SdrEllipsePrimitive2D(
123 			const basegfx::B2DHomMatrix& rTransform,
124 			const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute)
125 		:	BufferedDecompositionPrimitive2D(),
126 			maTransform(rTransform),
127 			maSdrLFSTAttribute(rSdrLFSTAttribute)
128 		{
129 		}
130 
operator ==(const BasePrimitive2D & rPrimitive) const131 		bool SdrEllipsePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
132 		{
133 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
134 			{
135 				const SdrEllipsePrimitive2D& rCompare = (SdrEllipsePrimitive2D&)rPrimitive;
136 
137 				return (getTransform() == rCompare.getTransform()
138 					&& getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute());
139 			}
140 
141 			return false;
142 		}
143 
144 		// provide unique ID
145 		ImplPrimitrive2DIDBlock(SdrEllipsePrimitive2D, PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D)
146 
147 	} // end of namespace primitive2d
148 } // end of namespace drawinglayer
149 
150 //////////////////////////////////////////////////////////////////////////////
151 
152 namespace drawinglayer
153 {
154 	namespace primitive2d
155 	{
create2DDecomposition(const geometry::ViewInformation2D &) const156 		Primitive2DSequence SdrEllipseSegmentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
157 		{
158 			Primitive2DSequence aRetval;
159 
160 			// create unit outline polygon
161 			basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromUnitEllipseSegment(mfStartAngle, mfEndAngle));
162 
163 			if(mbCloseSegment)
164 			{
165 				if(mbCloseUsingCenter)
166 				{
167 					// for compatibility, insert the center point at polygon start to get the same
168 					// line stroking pattern as the old painting mechanisms.
169 					aUnitOutline.insert(0L, basegfx::B2DPoint(0.0, 0.0));
170 				}
171 
172 				aUnitOutline.setClosed(true);
173 			}
174 
175 			// move and scale UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
176 			const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
177                 basegfx::tools::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
178 
179 			// apply to the geometry
180 			aUnitOutline.transform(aUnitCorrectionMatrix);
181 
182             // add fill
183             if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline.isClosed())
184             {
185                 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
186 
187                 aTransformed.transform(getTransform());
188                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
189                     createPolyPolygonFillPrimitive(
190                         aTransformed,
191                         getSdrLFSTAttribute().getFill(),
192                         getSdrLFSTAttribute().getFillFloatTransGradient()));
193 			}
194 
195 			// add line
196 			if(getSdrLFSTAttribute().getLine().isDefault())
197 			{
198 				// create invisible line for HitTest/BoundRect
199 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
200 					createHiddenGeometryPrimitives2D(
201                         false,
202 						basegfx::B2DPolyPolygon(aUnitOutline),
203                         getTransform()));
204             }
205             else
206             {
207                 basegfx::B2DPolygon aTransformed(aUnitOutline);
208 
209                 aTransformed.transform(getTransform());
210                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
211                     createPolygonLinePrimitive(
212                         aTransformed,
213                         getSdrLFSTAttribute().getLine(),
214                         getSdrLFSTAttribute().getLineStartEnd()));
215 			}
216 
217 			// add text
218 			if(!getSdrLFSTAttribute().getText().isDefault())
219 			{
220 				appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
221                     createTextPrimitive(
222                         basegfx::B2DPolyPolygon(aUnitOutline),
223                         getTransform(),
224 						getSdrLFSTAttribute().getText(),
225                         getSdrLFSTAttribute().getLine(),
226                         false,
227                         false,
228                         false));
229 			}
230 
231 			// add shadow
232 			if(!getSdrLFSTAttribute().getShadow().isDefault())
233 			{
234                 aRetval = createEmbeddedShadowPrimitive(
235                     aRetval,
236                     getSdrLFSTAttribute().getShadow());
237 			}
238 
239 			return aRetval;
240 		}
241 
SdrEllipseSegmentPrimitive2D(const basegfx::B2DHomMatrix & rTransform,const attribute::SdrLineFillShadowTextAttribute & rSdrLFSTAttribute,double fStartAngle,double fEndAngle,bool bCloseSegment,bool bCloseUsingCenter)242 		SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
243 			const basegfx::B2DHomMatrix& rTransform,
244 			const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
245 			double fStartAngle,
246 			double fEndAngle,
247 			bool bCloseSegment,
248 			bool bCloseUsingCenter)
249 		:	SdrEllipsePrimitive2D(rTransform, rSdrLFSTAttribute),
250 			mfStartAngle(fStartAngle),
251 			mfEndAngle(fEndAngle),
252 			mbCloseSegment(bCloseSegment),
253 			mbCloseUsingCenter(bCloseUsingCenter)
254 		{
255 		}
256 
operator ==(const BasePrimitive2D & rPrimitive) const257 		bool SdrEllipseSegmentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
258 		{
259 			if(SdrEllipsePrimitive2D::operator==(rPrimitive))
260 			{
261 				const SdrEllipseSegmentPrimitive2D& rCompare = (SdrEllipseSegmentPrimitive2D&)rPrimitive;
262 
263 				if(	mfStartAngle == rCompare.mfStartAngle
264 					&& mfEndAngle == rCompare.mfEndAngle
265 					&& mbCloseSegment == rCompare.mbCloseSegment
266 					&& mbCloseUsingCenter == rCompare.mbCloseUsingCenter)
267 				{
268 					return true;
269 				}
270 			}
271 
272 			return false;
273 		}
274 
275 		// provide unique ID
276 		ImplPrimitrive2DIDBlock(SdrEllipseSegmentPrimitive2D, PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D)
277 
278 	} // end of namespace primitive2d
279 } // end of namespace drawinglayer
280 
281 //////////////////////////////////////////////////////////////////////////////
282 // eof
283