Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "fumorph.hxx"
21 : #include <svx/xfillit.hxx>
22 : #include <svx/xlineit.hxx>
23 : #include <vcl/msgbox.hxx>
24 : #include <svx/svdpool.hxx>
25 : #include <tools/poly.hxx>
26 : #include <svx/svdopath.hxx>
27 : #include <svx/svdogrp.hxx>
28 : #include <editeng/eeitem.hxx>
29 :
30 : #include "View.hxx"
31 : #include "ViewShell.hxx"
32 : #include "Window.hxx"
33 : #include <basegfx/polygon/b2dpolygontools.hxx>
34 : #include <basegfx/polygon/b2dpolypolygontools.hxx>
35 : #include <basegfx/matrix/b2dhommatrix.hxx>
36 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
37 :
38 : #include "strings.hrc"
39 : #include "sdresid.hxx"
40 :
41 : #include "sdabstdlg.hxx"
42 :
43 : // #i48168#
44 : #include <svx/svditer.hxx>
45 :
46 : #include <basegfx/color/bcolor.hxx>
47 :
48 : namespace sd {
49 :
50 : #define ITEMVALUE( ItemSet, Id, Cast ) ( ( (const Cast&) (ItemSet).Get( (Id) ) ).GetValue() )
51 0 : TYPEINIT1( FuMorph, FuPoor );
52 :
53 : //////////////////////////////////////////////////////////////////////////////
54 : // constructor
55 : //
56 0 : FuMorph::FuMorph (
57 : ViewShell* pViewSh,
58 : ::sd::Window* pWin,
59 : ::sd::View* pView,
60 : SdDrawDocument* pDoc,
61 : SfxRequest& rReq )
62 0 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
63 : {
64 0 : }
65 :
66 0 : FunctionReference FuMorph::Create(
67 : ViewShell* pViewSh,
68 : ::sd::Window* pWin,
69 : ::sd::View* pView,
70 : SdDrawDocument* pDoc,
71 : SfxRequest& rReq
72 : )
73 : {
74 0 : FunctionReference xFunc( new FuMorph( pViewSh, pWin, pView, pDoc, rReq ) );
75 0 : xFunc->DoExecute(rReq);
76 0 : return xFunc;
77 : }
78 :
79 0 : void FuMorph::DoExecute( SfxRequest& )
80 : {
81 0 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
82 :
83 0 : if(rMarkList.GetMarkCount() == 2)
84 : {
85 : // Clones erzeugen
86 0 : SdrObject* pObj1 = rMarkList.GetMark(0)->GetMarkedSdrObj();
87 0 : SdrObject* pObj2 = rMarkList.GetMark(1)->GetMarkedSdrObj();
88 0 : SdrObject* pCloneObj1 = pObj1->Clone();
89 0 : SdrObject* pCloneObj2 = pObj2->Clone();
90 :
91 : // Text am Clone loeschen, da wir sonst kein richtiges PathObj bekommen
92 0 : pCloneObj1->SetOutlinerParaObject(NULL);
93 0 : pCloneObj2->SetOutlinerParaObject(NULL);
94 :
95 : // Path-Objekte erzeugen
96 0 : SdrObject* pPolyObj1 = pCloneObj1->ConvertToPolyObj(sal_False, sal_False);
97 0 : SdrObject* pPolyObj2 = pCloneObj2->ConvertToPolyObj(sal_False, sal_False);
98 0 : SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
99 0 : AbstractMorphDlg* pDlg = pFact ? pFact->CreateMorphDlg( static_cast< ::Window*>(mpWindow), pObj1, pObj2 ) : 0;
100 0 : if(pPolyObj1 && pPolyObj2 && pDlg && (pDlg->Execute() == RET_OK))
101 : {
102 0 : B2DPolyPolygonList_impl aPolyPolyList;
103 0 : ::basegfx::B2DPolyPolygon aPolyPoly1;
104 0 : ::basegfx::B2DPolyPolygon aPolyPoly2;
105 :
106 0 : pDlg->SaveSettings();
107 :
108 : // #i48168# Not always is the pPolyObj1/pPolyObj2 a SdrPathObj, it may also be a group object
109 : // containing SdrPathObjs. To get the polygons, i add two iters here
110 0 : SdrObjListIter aIter1(*pPolyObj1);
111 0 : SdrObjListIter aIter2(*pPolyObj2);
112 :
113 0 : while(aIter1.IsMore())
114 : {
115 0 : SdrObject* pObj = aIter1.Next();
116 0 : if(pObj && pObj->ISA(SdrPathObj))
117 0 : aPolyPoly1.append(((SdrPathObj*)pObj)->GetPathPoly());
118 : }
119 :
120 0 : while(aIter2.IsMore())
121 : {
122 0 : SdrObject* pObj = aIter2.Next();
123 0 : if(pObj && pObj->ISA(SdrPathObj))
124 0 : aPolyPoly2.append(((SdrPathObj*)pObj)->GetPathPoly());
125 : }
126 :
127 : // Morphing durchfuehren
128 0 : if(aPolyPoly1.count() && aPolyPoly2.count())
129 : {
130 0 : aPolyPoly1 = ::basegfx::tools::correctOrientations(aPolyPoly1);
131 0 : aPolyPoly1.removeDoublePoints();
132 0 : ::basegfx::B2VectorOrientation eIsClockwise1(::basegfx::tools::getOrientation(aPolyPoly1.getB2DPolygon(0L)));
133 :
134 0 : aPolyPoly2 = ::basegfx::tools::correctOrientations(aPolyPoly2);
135 0 : aPolyPoly2.removeDoublePoints();
136 0 : ::basegfx::B2VectorOrientation eIsClockwise2(::basegfx::tools::getOrientation(aPolyPoly2.getB2DPolygon(0L)));
137 :
138 : // set same orientation
139 0 : if(eIsClockwise1 != eIsClockwise2)
140 0 : aPolyPoly2.flip();
141 :
142 : // force same poly count
143 0 : if(aPolyPoly1.count() < aPolyPoly2.count())
144 0 : ImpAddPolys(aPolyPoly1, aPolyPoly2);
145 0 : else if(aPolyPoly2.count() < aPolyPoly1.count())
146 0 : ImpAddPolys(aPolyPoly2, aPolyPoly1);
147 :
148 : // use orientation flag from dialog
149 0 : if(!pDlg->IsOrientationFade())
150 0 : aPolyPoly2.flip();
151 :
152 : // force same point counts
153 0 : for( sal_uInt32 a(0L); a < aPolyPoly1.count(); a++ )
154 : {
155 0 : ::basegfx::B2DPolygon aSub1(aPolyPoly1.getB2DPolygon(a));
156 0 : ::basegfx::B2DPolygon aSub2(aPolyPoly2.getB2DPolygon(a));
157 :
158 0 : if(aSub1.count() < aSub2.count())
159 0 : ImpEqualizePolyPointCount(aSub1, aSub2);
160 0 : else if(aSub2.count() < aSub1.count())
161 0 : ImpEqualizePolyPointCount(aSub2, aSub1);
162 :
163 0 : aPolyPoly1.setB2DPolygon(a, aSub1);
164 0 : aPolyPoly2.setB2DPolygon(a, aSub2);
165 0 : }
166 :
167 0 : if(ImpMorphPolygons(aPolyPoly1, aPolyPoly2, pDlg->GetFadeSteps(), aPolyPolyList))
168 : {
169 0 : String aString(mpView->GetDescriptionOfMarkedObjects());
170 :
171 0 : aString.Append(sal_Unicode(' '));
172 0 : aString.Append(String(SdResId(STR_UNDO_MORPHING)));
173 :
174 0 : mpView->BegUndo(aString);
175 0 : ImpInsertPolygons(aPolyPolyList, pDlg->IsAttributeFade(), pObj1, pObj2);
176 0 : mpView->EndUndo();
177 : }
178 :
179 0 : for( size_t i = 0, n = aPolyPolyList.size(); i < n; ++i ) {
180 0 : delete aPolyPolyList[ i ];
181 : }
182 0 : }
183 : }
184 0 : delete pDlg;
185 0 : SdrObject::Free( pCloneObj1 );
186 0 : SdrObject::Free( pCloneObj2 );
187 :
188 0 : SdrObject::Free( pPolyObj1 );
189 0 : SdrObject::Free( pPolyObj2 );
190 : }
191 0 : }
192 :
193 0 : ::basegfx::B2DPolygon ImpGetExpandedPolygon(
194 : const ::basegfx::B2DPolygon& rCandidate,
195 : sal_uInt32 nNum
196 : )
197 : {
198 0 : if(rCandidate.count() && nNum && rCandidate.count() != nNum)
199 : {
200 : // length of step in dest poly
201 0 : ::basegfx::B2DPolygon aRetval;
202 0 : const double fStep(::basegfx::tools::getLength(rCandidate) / (double)(rCandidate.isClosed() ? nNum : nNum - 1L));
203 0 : double fDestPos(0.0);
204 0 : double fSrcPos(0.0);
205 0 : sal_uInt32 nSrcPos(0L);
206 0 : sal_uInt32 nSrcPosNext((nSrcPos + 1L == rCandidate.count()) ? 0L : nSrcPos + 1L);
207 0 : double fNextSrcLen(::basegfx::B2DVector(rCandidate.getB2DPoint(nSrcPos) - rCandidate.getB2DPoint(nSrcPosNext)).getLength());
208 :
209 0 : for(sal_uInt32 b(0L); b < nNum; b++)
210 : {
211 : // calc fDestPos in source
212 0 : while(fSrcPos + fNextSrcLen < fDestPos)
213 : {
214 0 : fSrcPos += fNextSrcLen;
215 0 : nSrcPos++;
216 0 : nSrcPosNext = (nSrcPos + 1L == rCandidate.count()) ? 0L : nSrcPos + 1L;
217 0 : fNextSrcLen = ::basegfx::B2DVector(rCandidate.getB2DPoint(nSrcPos) - rCandidate.getB2DPoint(nSrcPosNext)).getLength();
218 : }
219 :
220 : // fDestPos is between fSrcPos and (fSrcPos + fNextSrcLen)
221 0 : const double fLenA((fDestPos - fSrcPos) / fNextSrcLen);
222 0 : const ::basegfx::B2DPoint aOld1(rCandidate.getB2DPoint(nSrcPos));
223 0 : const ::basegfx::B2DPoint aOld2(rCandidate.getB2DPoint(nSrcPosNext));
224 0 : ::basegfx::B2DPoint aNewPoint(basegfx::interpolate(aOld1, aOld2, fLenA));
225 0 : aRetval.append(aNewPoint);
226 :
227 : // next step
228 0 : fDestPos += fStep;
229 0 : }
230 :
231 0 : if(aRetval.count() >= 3L)
232 : {
233 0 : aRetval.setClosed(rCandidate.isClosed());
234 : }
235 :
236 0 : return aRetval;
237 : }
238 : else
239 : {
240 0 : return rCandidate;
241 : }
242 : }
243 :
244 : //////////////////////////////////////////////////////////////////////////////
245 : // make the point count of the polygons equal in adding points
246 : //
247 0 : void FuMorph::ImpEqualizePolyPointCount(
248 : ::basegfx::B2DPolygon& rSmall,
249 : const ::basegfx::B2DPolygon& rBig
250 : )
251 : {
252 : // create poly with equal point count
253 0 : const sal_uInt32 nCnt(rBig.count());
254 0 : ::basegfx::B2DPolygon aPoly1(ImpGetExpandedPolygon(rSmall, nCnt));
255 :
256 : // create transformation for rBig to do the compare
257 0 : const ::basegfx::B2DRange aSrcSize(::basegfx::tools::getRange(rBig));
258 0 : const ::basegfx::B2DPoint aSrcPos(aSrcSize.getCenter());
259 0 : const ::basegfx::B2DRange aDstSize(::basegfx::tools::getRange(rSmall));
260 0 : const ::basegfx::B2DPoint aDstPos(aDstSize.getCenter());
261 :
262 0 : basegfx::B2DHomMatrix aTrans(basegfx::tools::createTranslateB2DHomMatrix(-aSrcPos.getX(), -aSrcPos.getY()));
263 0 : aTrans.scale(aDstSize.getWidth() / aSrcSize.getWidth(), aDstSize.getHeight() / aSrcSize.getHeight());
264 0 : aTrans.translate(aDstPos.getX(), aDstPos.getY());
265 :
266 : // transpose points to have smooth linear blending
267 0 : ::basegfx::B2DPolygon aPoly2;
268 0 : aPoly2.append(::basegfx::B2DPoint(), nCnt);
269 0 : sal_uInt32 nInd(ImpGetNearestIndex(aPoly1, aTrans * rBig.getB2DPoint(0L)));
270 :
271 0 : for(sal_uInt32 a(0L); a < nCnt; a++)
272 : {
273 0 : aPoly2.setB2DPoint((a + nCnt - nInd) % nCnt, aPoly1.getB2DPoint(a));
274 : }
275 :
276 0 : aPoly2.setClosed(rBig.isClosed());
277 0 : rSmall = aPoly2;
278 0 : }
279 :
280 : //////////////////////////////////////////////////////////////////////////////
281 : //
282 0 : sal_uInt32 FuMorph::ImpGetNearestIndex(
283 : const ::basegfx::B2DPolygon& rPoly,
284 : const ::basegfx::B2DPoint& rPos
285 : )
286 : {
287 0 : double fMinDist = 0.0;
288 0 : sal_uInt32 nActInd = 0;
289 :
290 0 : for(sal_uInt32 a(0L); a < rPoly.count(); a++)
291 : {
292 0 : double fNewDist(::basegfx::B2DVector(rPoly.getB2DPoint(a) - rPos).getLength());
293 :
294 0 : if(!a || fNewDist < fMinDist)
295 : {
296 0 : fMinDist = fNewDist;
297 0 : nActInd = a;
298 : }
299 : }
300 :
301 0 : return nActInd;
302 : }
303 :
304 : //////////////////////////////////////////////////////////////////////////////
305 : // add to a point reduced polys until count is same
306 : //
307 0 : void FuMorph::ImpAddPolys(
308 : ::basegfx::B2DPolyPolygon& rSmaller,
309 : const ::basegfx::B2DPolyPolygon& rBigger
310 : )
311 : {
312 0 : while(rSmaller.count() < rBigger.count())
313 : {
314 0 : const ::basegfx::B2DPolygon aToBeCopied(rBigger.getB2DPolygon(rSmaller.count()));
315 0 : const ::basegfx::B2DRange aToBeCopiedPolySize(::basegfx::tools::getRange(aToBeCopied));
316 0 : ::basegfx::B2DPoint aNewPoint(aToBeCopiedPolySize.getCenter());
317 0 : ::basegfx::B2DPolygon aNewPoly;
318 :
319 0 : const ::basegfx::B2DRange aSrcSize(::basegfx::tools::getRange(rBigger.getB2DPolygon(0L)));
320 0 : const ::basegfx::B2DPoint aSrcPos(aSrcSize.getCenter());
321 0 : const ::basegfx::B2DRange aDstSize(::basegfx::tools::getRange(rSmaller.getB2DPolygon(0L)));
322 0 : const ::basegfx::B2DPoint aDstPos(aDstSize.getCenter());
323 0 : aNewPoint = aNewPoint - aSrcPos + aDstPos;
324 :
325 0 : for(sal_uInt32 a(0L); a < aToBeCopied.count(); a++)
326 : {
327 0 : aNewPoly.append(aNewPoint);
328 : }
329 :
330 0 : rSmaller.append(aNewPoly);
331 0 : }
332 0 : }
333 :
334 : //////////////////////////////////////////////////////////////////////////////
335 : // create group object with morphed polygons
336 : //
337 0 : void FuMorph::ImpInsertPolygons(
338 : B2DPolyPolygonList_impl& rPolyPolyList3D,
339 : sal_Bool bAttributeFade,
340 : const SdrObject* pObj1,
341 : const SdrObject* pObj2
342 : )
343 : {
344 0 : Color aStartFillCol;
345 0 : Color aEndFillCol;
346 0 : Color aStartLineCol;
347 0 : Color aEndLineCol;
348 0 : long nStartLineWidth = 0;
349 0 : long nEndLineWidth = 0;
350 0 : SdrPageView* pPageView = mpView->GetSdrPageView();
351 0 : SfxItemPool* pPool = pObj1->GetObjectItemPool();
352 0 : SfxItemSet aSet1( *pPool,SDRATTR_START,SDRATTR_NOTPERSIST_FIRST-1,EE_ITEMS_START,EE_ITEMS_END,0 );
353 0 : SfxItemSet aSet2( aSet1 );
354 0 : sal_Bool bLineColor = sal_False;
355 0 : sal_Bool bFillColor = sal_False;
356 0 : sal_Bool bLineWidth = sal_False;
357 0 : sal_Bool bIgnoreLine = sal_False;
358 0 : sal_Bool bIgnoreFill = sal_False;
359 :
360 0 : aSet1.Put(pObj1->GetMergedItemSet());
361 0 : aSet2.Put(pObj2->GetMergedItemSet());
362 :
363 0 : const XLineStyle eLineStyle1 = ITEMVALUE( aSet1, XATTR_LINESTYLE, XLineStyleItem );
364 0 : const XLineStyle eLineStyle2 = ITEMVALUE( aSet2, XATTR_LINESTYLE, XLineStyleItem );
365 0 : const XFillStyle eFillStyle1 = ITEMVALUE( aSet1, XATTR_FILLSTYLE, XFillStyleItem );
366 0 : const XFillStyle eFillStyle2 = ITEMVALUE( aSet2, XATTR_FILLSTYLE, XFillStyleItem );
367 :
368 0 : if ( bAttributeFade )
369 : {
370 0 : if ( ( eLineStyle1 != XLINE_NONE ) && ( eLineStyle2 != XLINE_NONE ) )
371 : {
372 0 : bLineWidth = bLineColor = sal_True;
373 :
374 : aStartLineCol = static_cast< XLineColorItem const & >(
375 0 : aSet1.Get(XATTR_LINECOLOR)).GetColorValue();
376 : aEndLineCol = static_cast< XLineColorItem const & >(
377 0 : aSet2.Get(XATTR_LINECOLOR)).GetColorValue();
378 :
379 0 : nStartLineWidth = ITEMVALUE( aSet1, XATTR_LINEWIDTH, XLineWidthItem );
380 0 : nEndLineWidth = ITEMVALUE( aSet2, XATTR_LINEWIDTH, XLineWidthItem );
381 : }
382 0 : else if ( ( eLineStyle1 == XLINE_NONE ) && ( eLineStyle2 == XLINE_NONE ) )
383 0 : bIgnoreLine = sal_True;
384 :
385 0 : if ( ( eFillStyle1 == XFILL_SOLID ) && ( eFillStyle2 == XFILL_SOLID ) )
386 : {
387 0 : bFillColor = sal_True;
388 : aStartFillCol = static_cast< XFillColorItem const & >(
389 0 : aSet1.Get(XATTR_FILLCOLOR)).GetColorValue();
390 : aEndFillCol = static_cast< XFillColorItem const & >(
391 0 : aSet2.Get(XATTR_FILLCOLOR)).GetColorValue();
392 : }
393 0 : else if ( ( eFillStyle1 == XFILL_NONE ) && ( eFillStyle2 == XFILL_NONE ) )
394 0 : bIgnoreFill = sal_True;
395 : }
396 :
397 0 : if ( pPageView )
398 : {
399 0 : SfxItemSet aSet( aSet1 );
400 0 : SdrObjGroup* pObjGroup = new SdrObjGroup;
401 0 : SdrObjList* pObjList = pObjGroup->GetSubList();
402 0 : const size_t nCount = rPolyPolyList3D.size();
403 0 : const double fStep = 1. / ( nCount + 1 );
404 0 : const double fDelta = nEndLineWidth - nStartLineWidth;
405 0 : double fFactor = fStep;
406 :
407 0 : aSet.Put( XLineStyleItem( XLINE_SOLID ) );
408 0 : aSet.Put( XFillStyleItem( XFILL_SOLID ) );
409 :
410 0 : for ( size_t i = 0; i < nCount; i++, fFactor += fStep )
411 : {
412 0 : const ::basegfx::B2DPolyPolygon& rPolyPoly3D = *rPolyPolyList3D[ i ];
413 0 : SdrPathObj* pNewObj = new SdrPathObj(OBJ_POLY, rPolyPoly3D);
414 :
415 : // Linienfarbe
416 0 : if ( bLineColor )
417 : {
418 0 : const basegfx::BColor aLineColor(basegfx::interpolate(aStartLineCol.getBColor(), aEndLineCol.getBColor(), fFactor));
419 0 : aSet.Put( XLineColorItem( aEmptyStr, Color(aLineColor)));
420 : }
421 0 : else if ( bIgnoreLine )
422 0 : aSet.Put( XLineStyleItem( XLINE_NONE ) );
423 :
424 : // Fuellfarbe
425 0 : if ( bFillColor )
426 : {
427 0 : const basegfx::BColor aFillColor(basegfx::interpolate(aStartFillCol.getBColor(), aEndFillCol.getBColor(), fFactor));
428 0 : aSet.Put( XFillColorItem( aEmptyStr, Color(aFillColor)));
429 : }
430 0 : else if ( bIgnoreFill )
431 0 : aSet.Put( XFillStyleItem( XFILL_NONE ) );
432 :
433 : // Linienstaerke
434 0 : if ( bLineWidth )
435 0 : aSet.Put( XLineWidthItem( nStartLineWidth + (long) ( fFactor * fDelta + 0.5 ) ) );
436 :
437 0 : pNewObj->SetMergedItemSetAndBroadcast(aSet);
438 :
439 0 : pObjList->InsertObject( pNewObj, LIST_APPEND );
440 : }
441 :
442 0 : if ( nCount )
443 : {
444 0 : pObjList->InsertObject( pObj1->Clone(), 0 );
445 0 : pObjList->InsertObject( pObj2->Clone(), LIST_APPEND );
446 0 : mpView->DeleteMarked();
447 0 : mpView->InsertObjectAtView( pObjGroup, *pPageView, SDRINSERT_SETDEFLAYER );
448 0 : }
449 0 : }
450 0 : }
451 :
452 : //////////////////////////////////////////////////////////////////////////////
453 : // create single morphed PolyPolygon
454 : //
455 0 : ::basegfx::B2DPolyPolygon* FuMorph::ImpCreateMorphedPolygon(
456 : const ::basegfx::B2DPolyPolygon& rPolyPolyStart,
457 : const ::basegfx::B2DPolyPolygon& rPolyPolyEnd,
458 : double fMorphingFactor
459 : )
460 : {
461 0 : ::basegfx::B2DPolyPolygon* pNewPolyPolygon = new ::basegfx::B2DPolyPolygon();
462 0 : const double fFactor = 1.0 - fMorphingFactor;
463 :
464 0 : for(sal_uInt32 a(0L); a < rPolyPolyStart.count(); a++)
465 : {
466 0 : const ::basegfx::B2DPolygon aPolyStart(rPolyPolyStart.getB2DPolygon(a));
467 0 : const ::basegfx::B2DPolygon aPolyEnd(rPolyPolyEnd.getB2DPolygon(a));
468 0 : const sal_uInt32 nCount(aPolyStart.count());
469 0 : ::basegfx::B2DPolygon aNewPolygon;
470 :
471 0 : for(sal_uInt32 b(0L); b < nCount; b++)
472 : {
473 0 : const ::basegfx::B2DPoint& aPtStart(aPolyStart.getB2DPoint(b));
474 0 : const ::basegfx::B2DPoint& aPtEnd(aPolyEnd.getB2DPoint(b));
475 0 : aNewPolygon.append(aPtEnd + ((aPtStart - aPtEnd) * fFactor));
476 0 : }
477 :
478 0 : aNewPolygon.setClosed(aPolyStart.isClosed() && aPolyEnd.isClosed());
479 0 : pNewPolyPolygon->append(aNewPolygon);
480 0 : }
481 :
482 0 : return pNewPolyPolygon;
483 : }
484 :
485 : //////////////////////////////////////////////////////////////////////////////
486 : // create morphed PolyPolygons
487 : //
488 0 : sal_Bool FuMorph::ImpMorphPolygons(
489 : const ::basegfx::B2DPolyPolygon& rPolyPoly1,
490 : const ::basegfx::B2DPolyPolygon& rPolyPoly2,
491 : const sal_uInt16 nSteps,
492 : B2DPolyPolygonList_impl& rPolyPolyList3D
493 : )
494 : {
495 0 : if(nSteps)
496 : {
497 0 : const ::basegfx::B2DRange aStartPolySize(::basegfx::tools::getRange(rPolyPoly1));
498 0 : const ::basegfx::B2DPoint aStartCenter(aStartPolySize.getCenter());
499 0 : const ::basegfx::B2DRange aEndPolySize(::basegfx::tools::getRange(rPolyPoly2));
500 0 : const ::basegfx::B2DPoint aEndCenter(aEndPolySize.getCenter());
501 0 : const ::basegfx::B2DPoint aDelta(aEndCenter - aStartCenter);
502 0 : const double fFactor(1.0 / (nSteps + 1));
503 0 : double fValue(0.0);
504 :
505 0 : for(sal_uInt16 i(0); i < nSteps; i++)
506 : {
507 0 : fValue += fFactor;
508 0 : ::basegfx::B2DPolyPolygon* pNewPolyPoly2D = ImpCreateMorphedPolygon(rPolyPoly1, rPolyPoly2, fValue);
509 :
510 0 : const ::basegfx::B2DRange aNewPolySize(::basegfx::tools::getRange(*pNewPolyPoly2D));
511 0 : const ::basegfx::B2DPoint aNewS(aNewPolySize.getCenter());
512 0 : const ::basegfx::B2DPoint aRealS(aStartCenter + (aDelta * fValue));
513 0 : const ::basegfx::B2DPoint aDiff(aRealS - aNewS);
514 :
515 0 : pNewPolyPoly2D->transform(basegfx::tools::createTranslateB2DHomMatrix(aDiff));
516 0 : rPolyPolyList3D.push_back( pNewPolyPoly2D );
517 0 : }
518 : }
519 0 : return sal_True;
520 : }
521 :
522 9 : } // end of namespace sd
523 :
524 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|