diff options
Diffstat (limited to 'svx/source/xoutdev/_xpoly.cxx')
-rw-r--r-- | svx/source/xoutdev/_xpoly.cxx | 212 |
1 files changed, 210 insertions, 2 deletions
diff --git a/svx/source/xoutdev/_xpoly.cxx b/svx/source/xoutdev/_xpoly.cxx index dd9d81378f93..16e4ed26ccc9 100644 --- a/svx/source/xoutdev/_xpoly.cxx +++ b/svx/source/xoutdev/_xpoly.cxx @@ -2,9 +2,9 @@ * * $RCSfile: _xpoly.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: vg $ $Date: 2004-01-06 15:47:36 $ + * last change: $Author: hr $ $Date: 2004-05-10 14:34:19 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,6 +71,26 @@ #include "xpoly.hxx" #include "xpolyimp.hxx" +#ifndef _BGFX_POLYGON_B2DPOLYGON_HXX +#include <basegfx/polygon/b2dpolygon.hxx> +#endif + +#ifndef _BGFX_POINT_B2DPOINT_HXX +#include <basegfx/point/b2dpoint.hxx> +#endif + +#ifndef _BGFX_VECTOR_B2DVECTOR_HXX +#include <basegfx/vector/b2dvector.hxx> +#endif + +#ifndef _BGFX_POLYGON_B2DPOLYGONTOOLS_HXX +#include <basegfx/polygon/b2dpolygontools.hxx> +#endif + +#ifndef _SV_SALBTYPE_HXX +#include <vcl/salbtype.hxx> // FRound +#endif + #define GLOBALOVERFLOW DBG_NAME(XPolygon); @@ -1745,6 +1765,166 @@ SvStream& operator<<( SvStream& rOStream, const XPolygon& rXPoly ) return rOStream; } +// #116512# convert to ::basegfx::B2DPolygon and return +::basegfx::B2DPolygon XPolygon::getB2DPolygon() const +{ + ::basegfx::B2DPolygon aRetval; + const sal_uInt16 nCount(GetPointCount()); + + for(sal_uInt16 a(0L); a < nCount;) + { + // get point + Point aPointA = (*this)[a++]; + + // test flags of next point if available, maybe it's a control point + if(a < nCount && XPOLY_CONTROL == GetFlags(a)) + { + // get two control points + Point aControlA = (*this)[a++]; + Point aControlB = (*this)[a++]; + + // add point A + ::basegfx::B2DPoint aPoA(aPointA.X(), aPointA.Y()); + aRetval.append(aPoA); + + // calculate Vectors and add them + const sal_uInt32 nDestIndex(aRetval.count() - 1L); + ::basegfx::B2DVector aVeA(aControlA.X() - aPointA.X(), aControlA.Y() - aPointA.Y()); + aRetval.setControlVectorA(nDestIndex, aVeA); + ::basegfx::B2DVector aVeB(aControlB.X() - aPointA.X(), aControlB.Y() - aPointA.Y()); + aRetval.setControlVectorB(nDestIndex, aVeB); + } + else + { + // add point A + ::basegfx::B2DPoint aPoA(aPointA.X(), aPointA.Y()); + aRetval.append(aPoA); + } + } + + // set closed flag + ::basegfx::tools::checkClosed(aRetval); + + return aRetval; +} + +// #116512# constructor to convert from ::basegfx::B2DPolygon +XPolygon::XPolygon(const ::basegfx::B2DPolygon& rPolygon) +{ + DBG_CTOR(XPolygon,NULL); + + const sal_Bool bCurve(rPolygon.areControlPointsUsed()); + const sal_Bool bClosed(rPolygon.isClosed()); + const sal_uInt32 nCount(rPolygon.count()); + + if(bCurve) + { + // curve creation + const sal_uInt32 nLoopCount(bClosed ? nCount : (nCount ? nCount - 1L : 0L )); + const sal_uInt32 nTargetCount(nLoopCount ? (nLoopCount * 3L) + 1L : 0L); + DBG_ASSERT(nTargetCount == sal_uInt32(sal_uInt16(nTargetCount)), + "XPolygon::XPolygon: Too many points in given ::basegfx::B2DPolygon (!)"); + pImpXPolygon = new ImpXPolygon( sal_uInt16(nTargetCount) , 1024 ); + + if(nLoopCount) + { + sal_uInt16 nIndex(0); + + for(sal_uInt32 a(0L); a < nLoopCount; a++) + { + // get and add start point + ::basegfx::B2DPoint aB2DPointA(rPolygon.getB2DPoint(a)); + Point aPointA(FRound(aB2DPointA.getX()), FRound(aB2DPointA.getY())); + sal_uInt16 nPointIndex(nIndex++); + Insert(nPointIndex, aPointA, XPOLY_NORMAL); + + // get and add first control point + ::basegfx::B2DVector aB2DVectorA(rPolygon.getControlVectorA(a)); + const sal_Bool bVectorAUsed(!aB2DVectorA.equalZero()); + Point aVecA(aPointA); + + if(bVectorAUsed) + { + aVecA = Point( + FRound(aB2DPointA.getX() + aB2DVectorA.getX()), + FRound(aB2DPointA.getY() + aB2DVectorA.getY())); + } + + Insert(nIndex++, aVecA, XPOLY_CONTROL); + + // get and add second control point + ::basegfx::B2DVector aB2DVectorB(rPolygon.getControlVectorB(a)); + const sal_Bool bVectorBUsed(!aB2DVectorB.equalZero()); + Point aVecB(aPointA); + + if(bVectorBUsed) + { + aVecB = Point( + FRound(aB2DPointA.getX() + aB2DVectorB.getX()), + FRound(aB2DPointA.getY() + aB2DVectorB.getY())); + } + + Insert(nIndex++, aVecB, XPOLY_CONTROL); + + // test continuity with previous control point + if(bVectorAUsed && (bClosed || a)) + { + const sal_uInt32 nPrevInd(a == 0L ? nCount - 1L : a - 1L); + ::basegfx::B2DVector aB2DVectorPrev(rPolygon.getControlPointB(nPrevInd) - aB2DPointA); + ::basegfx::B2VectorContinuity eCont = ::basegfx::getContinuity(aB2DVectorPrev, aB2DVectorA); + + if(::basegfx::CONTINUITY_C1 == eCont) + { + SetFlags(nPointIndex, XPOLY_SMOOTH); + } + else if(::basegfx::CONTINUITY_C2 == eCont) + { + SetFlags(nPointIndex, XPOLY_SYMMTR); + } + } + } + + if(rPolygon.isClosed()) + { + // add first point as closing point + Insert(nIndex, (*this)[0], XPOLY_NORMAL); + } + else + { + // add last point as closing point + ::basegfx::B2DPoint aClosingPoint(rPolygon.getB2DPoint(nCount - 1L)); + Point aEnd(FRound(aClosingPoint.getX()), FRound(aClosingPoint.getY())); + Insert(nIndex, aEnd, XPOLY_NORMAL); + } + } + } + else + { + // point list creation + const sal_uInt32 nTargetCount(nCount + (bClosed ? 1L : 0L)); + DBG_ASSERT(nTargetCount == sal_uInt32(sal_uInt16(nTargetCount)), + "XPolygon::XPolygon: Too many points in given ::basegfx::B2DPolygon (!)"); + pImpXPolygon = new ImpXPolygon( sal_uInt16(nTargetCount) , 1024 ); + + if(nCount) + { + sal_uInt16 nIndex(0); + + for(sal_uInt32 a(0L); a < nCount; a++) + { + ::basegfx::B2DPoint aB2DPoint(rPolygon.getB2DPoint(a)); + Point aPoint(FRound(aB2DPoint.getX()), FRound(aB2DPoint.getY())); + Insert(nIndex++, aPoint, XPOLY_NORMAL); + } + + if(rPolygon.isClosed()) + { + // add first point as closing point + Insert(nIndex, (*this)[0], XPOLY_NORMAL); + } + } + } +} //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+--------------- XPolyPolygon -----------------------------------------+ @@ -2441,4 +2621,32 @@ SvStream& operator<<( SvStream& rOStream, const XPolyPolygon& rXPolyPoly ) return rOStream; } +// #116512# convert to ::basegfx::B2DPolyPolygon and return +::basegfx::B2DPolyPolygon XPolyPolygon::getB2DPolyPolygon() const +{ + ::basegfx::B2DPolyPolygon aRetval; + + for(sal_uInt16 a(0L); a < Count(); a++) + { + const XPolygon& rPoly = (*this)[a]; + aRetval.append(rPoly.getB2DPolygon()); + } + + return aRetval; +} + +// #116512# constructor to convert from ::basegfx::B2DPolyPolygon +XPolyPolygon::XPolyPolygon(const ::basegfx::B2DPolyPolygon& rPolyPolygon) +{ + DBG_CTOR(XPolyPolygon,NULL); + pImpXPolyPolygon = new ImpXPolyPolygon( 16, 16 ); + + for(sal_uInt32 a(0L); a < rPolyPolygon.count(); a++) + { + ::basegfx::B2DPolygon aCandidate = rPolyPolygon.getB2DPolygon(a); + XPolygon aNewPoly(aCandidate); + Insert(aNewPoly); + } +} +// eof |