diff options
author | Oliver Bolte <obo@openoffice.org> | 2005-04-18 08:15:55 +0000 |
---|---|---|
committer | Oliver Bolte <obo@openoffice.org> | 2005-04-18 08:15:55 +0000 |
commit | 5c22a3f129b5596c0ecb8fd8c211ab11d5f3c22e (patch) | |
tree | d1ece185011e4209d84c2a0962a4c0897e076d4b /basegfx/source/tools | |
parent | c6aa4fae82a0ce5647d3aeadca2298a224cbd746 (diff) |
INTEGRATION: CWS presfixes03 (1.3.6); FILE MERGED
2005/04/01 15:08:31 thb 1.3.6.1: #i37793#, #i39245# Overhauled polygon conversion code, to now fully support beziers and transport the polygon's open/close state correctly across the API
Diffstat (limited to 'basegfx/source/tools')
-rwxr-xr-x | basegfx/source/tools/canvastools.cxx | 104 |
1 files changed, 68 insertions, 36 deletions
diff --git a/basegfx/source/tools/canvastools.cxx b/basegfx/source/tools/canvastools.cxx index 594c53f8e1c8..54e80a331a48 100755 --- a/basegfx/source/tools/canvastools.cxx +++ b/basegfx/source/tools/canvastools.cxx @@ -2,9 +2,9 @@ * * $RCSfile: canvastools.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: vg $ $Date: 2005-03-10 13:39:00 $ + * last change: $Author: obo $ $Date: 2005-04-18 09:15:55 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -129,33 +129,38 @@ namespace basegfx const sal_uInt32 nNumPoints( rPoly.count() ); uno::Sequence< geometry::RealBezierSegment2D > outputSequence( nNumPoints ); + geometry::RealBezierSegment2D* pOutput = outputSequence.getArray(); // fill sequence from polygon sal_uInt32 i; for( i=0; i<nNumPoints; ++i ) { const ::basegfx::B2DPoint aStartPoint( rPoly.getB2DPoint(i) ); - const ::basegfx::B2DVector aCtrl1( rPoly.getControlVectorA(i) ); - const ::basegfx::B2DVector aCtrl2( rPoly.getControlVectorB(i) ); + const ::basegfx::B2DPoint aEndPoint( i+1<nNumPoints ? rPoly.getB2DPoint(i+1) : aStartPoint ); + const ::basegfx::B2DPoint aCtrl1( rPoly.getControlPointA(i) ); + const ::basegfx::B2DPoint aCtrl2( rPoly.getControlPointB(i) ); - if( aCtrl1.equalZero() && - aCtrl2.equalZero() ) + if( aStartPoint.equal( aCtrl1 ) && + aStartPoint.equal( aCtrl2 ) ) { - outputSequence[i] = geometry::RealBezierSegment2D( aStartPoint.getX(), - aStartPoint.getY(), - aStartPoint.getX(), - aStartPoint.getY(), - aStartPoint.getX(), - aStartPoint.getY() ); + const double nX( aStartPoint.getX() ); + const double nY( aStartPoint.getY() ); + + // ATTN: The following line should match the + // comparison below in + // polygonFromBezier2DSequence()! + pOutput[i] = geometry::RealBezierSegment2D( nX, nY, + nX, nY, + nX, nY ); } else { - outputSequence[i] = geometry::RealBezierSegment2D( aStartPoint.getX(), - aStartPoint.getY(), - aCtrl1.getX(), - aCtrl1.getY(), - aCtrl2.getX(), - aCtrl2.getY() ); + pOutput[i] = geometry::RealBezierSegment2D( aStartPoint.getX(), + aStartPoint.getY(), + aCtrl1.getX(), + aCtrl1.getY(), + aCtrl2.getX(), + aCtrl2.getY() ); } } @@ -167,6 +172,7 @@ namespace basegfx const sal_uInt32 nNumPoints( rPoly.count() ); uno::Sequence< geometry::RealPoint2D > outputSequence( nNumPoints ); + geometry::RealPoint2D* pOutput = outputSequence.getArray(); // fill sequence from polygon sal_uInt32 i; @@ -174,8 +180,8 @@ namespace basegfx { const ::basegfx::B2DPoint aPoint( rPoly.getB2DPoint(i) ); - outputSequence[i] = geometry::RealPoint2D( aPoint.getX(), - aPoint.getY() ); + pOutput[i] = geometry::RealPoint2D( aPoint.getX(), + aPoint.getY() ); } return outputSequence; @@ -184,6 +190,42 @@ namespace basegfx //--------------------------------------------------------------------------------------- + uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > bezierSequenceSequenceFromB2DPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly ) + { + const sal_uInt32 nNumPolies( rPolyPoly.count() ); + sal_uInt32 i; + + uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > outputSequence( nNumPolies ); + uno::Sequence< geometry::RealBezierSegment2D >* pOutput = outputSequence.getArray(); + + for( i=0; i<nNumPolies; ++i ) + { + pOutput[i] = bezierSequenceFromB2DPolygon( rPolyPoly.getB2DPolygon(i) ); + } + + return outputSequence; + } + + //--------------------------------------------------------------------------------------- + + uno::Sequence< uno::Sequence< geometry::RealPoint2D > > pointSequenceSequenceFromB2DPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly ) + { + const sal_uInt32 nNumPolies( rPolyPoly.count() ); + sal_uInt32 i; + + uno::Sequence< uno::Sequence< geometry::RealPoint2D > > outputSequence( nNumPolies ); + uno::Sequence< geometry::RealPoint2D >* pOutput = outputSequence.getArray(); + + for( i=0; i<nNumPolies; ++i ) + { + pOutput[i] = pointSequenceFromB2DPolygon( rPolyPoly.getB2DPolygon(i) ); + } + + return outputSequence; + } + + //--------------------------------------------------------------------------------------- + uno::Reference< rendering::XPolyPolygon2D > xPolyPolygonFromB2DPolygon( const uno::Reference< rendering::XGraphicDevice >& xGraphicDevice, const ::basegfx::B2DPolygon& rPoly ) { @@ -230,26 +272,14 @@ namespace basegfx if( rPolyPoly.areControlPointsUsed() ) { - uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > outputSequence( nNumPolies ); - - for( i=0; i<nNumPolies; ++i ) - { - outputSequence[i] = bezierSequenceFromB2DPolygon( rPolyPoly.getB2DPolygon(i) ); - } - - xRes.set( xGraphicDevice->createCompatibleBezierPolyPolygon( outputSequence ), + xRes.set( xGraphicDevice->createCompatibleBezierPolyPolygon( + bezierSequenceSequenceFromB2DPolyPolygon( rPolyPoly ) ), uno::UNO_QUERY ); } else { - uno::Sequence< uno::Sequence< geometry::RealPoint2D > > outputSequence( nNumPolies ); - - for( i=0; i<nNumPolies; ++i ) - { - outputSequence[i] = pointSequenceFromB2DPolygon( rPolyPoly.getB2DPolygon(i) ); - } - - xRes.set( xGraphicDevice->createCompatibleLinePolyPolygon( outputSequence ), + xRes.set( xGraphicDevice->createCompatibleLinePolyPolygon( + pointSequenceSequenceFromB2DPolyPolygon( rPolyPoly ) ), uno::UNO_QUERY ); } @@ -302,6 +332,8 @@ namespace basegfx { const geometry::RealBezierSegment2D aCurrSegment( curves[nCurrPoint] ); + // ATTN: This line should match the setup in + // bezierSequenceFromB2DPolygon()! if( aCurrSegment.Px == aCurrSegment.C1x && aCurrSegment.Px == aCurrSegment.C2x && aCurrSegment.Py == aCurrSegment.C1y && |