diff options
Diffstat (limited to 'basegfx/source/polygon/b2dsvgpolypolygon.cxx')
-rw-r--r-- | basegfx/source/polygon/b2dsvgpolypolygon.cxx | 168 |
1 files changed, 84 insertions, 84 deletions
diff --git a/basegfx/source/polygon/b2dsvgpolypolygon.cxx b/basegfx/source/polygon/b2dsvgpolypolygon.cxx index d2815337edaf..cff043d0378e 100644 --- a/basegfx/source/polygon/b2dsvgpolypolygon.cxx +++ b/basegfx/source/polygon/b2dsvgpolypolygon.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -43,9 +43,9 @@ namespace basegfx { namespace { - void lcl_skipSpaces(sal_Int32& io_rPos, - const ::rtl::OUString& rStr, - const sal_Int32 nLen) + void lcl_skipSpaces(sal_Int32& io_rPos, + const ::rtl::OUString& rStr, + const sal_Int32 nLen) { while( io_rPos < nLen && sal_Unicode(' ') == rStr[io_rPos] ) @@ -54,11 +54,11 @@ namespace basegfx } } - void lcl_skipSpacesAndCommas(sal_Int32& io_rPos, - const ::rtl::OUString& rStr, - const sal_Int32 nLen) + void lcl_skipSpacesAndCommas(sal_Int32& io_rPos, + const ::rtl::OUString& rStr, + const sal_Int32 nLen) { - while(io_rPos < nLen + while(io_rPos < nLen && (sal_Unicode(' ') == rStr[io_rPos] || sal_Unicode(',') == rStr[io_rPos])) { ++io_rPos; @@ -80,10 +80,10 @@ namespace basegfx bSignAllowed); } - bool lcl_getDoubleChar(double& o_fRetval, - sal_Int32& io_rPos, - const ::rtl::OUString& rStr, - const sal_Int32 /*nLen*/) + bool lcl_getDoubleChar(double& o_fRetval, + sal_Int32& io_rPos, + const ::rtl::OUString& rStr, + const sal_Int32 /*nLen*/) { sal_Unicode aChar( rStr[io_rPos] ); ::rtl::OUStringBuffer sNumberString; @@ -105,7 +105,7 @@ namespace basegfx { sNumberString.append(rStr[io_rPos]); aChar = rStr[++io_rPos]; - + if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar) { sNumberString.append(rStr[io_rPos]); @@ -122,10 +122,10 @@ namespace basegfx if(sNumberString.getLength()) { rtl_math_ConversionStatus eStatus; - o_fRetval = ::rtl::math::stringToDouble( sNumberString.makeStringAndClear(), - (sal_Unicode)('.'), - (sal_Unicode)(','), - &eStatus, + o_fRetval = ::rtl::math::stringToDouble( sNumberString.makeStringAndClear(), + (sal_Unicode)('.'), + (sal_Unicode)(','), + &eStatus, NULL ); return ( eStatus == rtl_math_ConversionStatus_Ok ); } @@ -133,10 +133,10 @@ namespace basegfx return false; } - bool lcl_importDoubleAndSpaces( double& o_fRetval, - sal_Int32& io_rPos, - const ::rtl::OUString& rStr, - const sal_Int32 nLen ) + bool lcl_importDoubleAndSpaces( double& o_fRetval, + sal_Int32& io_rPos, + const ::rtl::OUString& rStr, + const sal_Int32 nLen ) { if( !lcl_getDoubleChar(o_fRetval, io_rPos, rStr, nLen) ) return false; @@ -147,9 +147,9 @@ namespace basegfx } bool lcl_importNumberAndSpaces(sal_Int32& o_nRetval, - sal_Int32& io_rPos, - const ::rtl::OUString& rStr, - const sal_Int32 nLen) + sal_Int32& io_rPos, + const ::rtl::OUString& rStr, + const sal_Int32 nLen) { sal_Unicode aChar( rStr[io_rPos] ); ::rtl::OUStringBuffer sNumberString; @@ -177,9 +177,9 @@ namespace basegfx return false; } - void lcl_skipNumber(sal_Int32& io_rPos, - const ::rtl::OUString& rStr, - const sal_Int32 nLen) + void lcl_skipNumber(sal_Int32& io_rPos, + const ::rtl::OUString& rStr, + const sal_Int32 nLen) { bool bSignAllowed(true); @@ -190,9 +190,9 @@ namespace basegfx } } - void lcl_skipDouble(sal_Int32& io_rPos, - const ::rtl::OUString& rStr, - const sal_Int32 /*nLen*/) + void lcl_skipDouble(sal_Int32& io_rPos, + const ::rtl::OUString& rStr, + const sal_Int32 /*nLen*/) { sal_Unicode aChar( rStr[io_rPos] ); @@ -208,7 +208,7 @@ namespace basegfx if(sal_Unicode('e') == aChar || sal_Unicode('E') == aChar) { aChar = rStr[++io_rPos]; - + if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar) aChar = rStr[++io_rPos]; @@ -218,33 +218,33 @@ namespace basegfx } } } - void lcl_skipNumberAndSpacesAndCommas(sal_Int32& io_rPos, - const ::rtl::OUString& rStr, - const sal_Int32 nLen) + void lcl_skipNumberAndSpacesAndCommas(sal_Int32& io_rPos, + const ::rtl::OUString& rStr, + const sal_Int32 nLen) { lcl_skipNumber(io_rPos, rStr, nLen); lcl_skipSpacesAndCommas(io_rPos, rStr, nLen); } // #100617# Allow to skip doubles, too. - void lcl_skipDoubleAndSpacesAndCommas(sal_Int32& io_rPos, - const ::rtl::OUString& rStr, - const sal_Int32 nLen) + void lcl_skipDoubleAndSpacesAndCommas(sal_Int32& io_rPos, + const ::rtl::OUString& rStr, + const sal_Int32 nLen) { lcl_skipDouble(io_rPos, rStr, nLen); lcl_skipSpacesAndCommas(io_rPos, rStr, nLen); } - void lcl_putNumberChar( ::rtl::OUStringBuffer& rStr, - double fValue ) + void lcl_putNumberChar( ::rtl::OUStringBuffer& rStr, + double fValue ) { rStr.append( fValue ); } - void lcl_putNumberCharWithSpace( ::rtl::OUStringBuffer& rStr, - double fValue, - double fOldValue, - bool bUseRelativeCoordinates ) + void lcl_putNumberCharWithSpace( ::rtl::OUStringBuffer& rStr, + double fValue, + double fOldValue, + bool bUseRelativeCoordinates ) { if( bUseRelativeCoordinates ) fValue -= fOldValue; @@ -252,7 +252,7 @@ namespace basegfx const sal_Int32 aLen( rStr.getLength() ); if(aLen) { - if( lcl_isOnNumberChar(rStr.charAt(aLen - 1), false) && + if( lcl_isOnNumberChar(rStr.charAt(aLen - 1), false) && fValue >= 0.0 ) { rStr.append( sal_Unicode(' ') ); @@ -264,13 +264,13 @@ namespace basegfx inline sal_Unicode lcl_getCommand( sal_Char cUpperCaseCommand, sal_Char cLowerCaseCommand, - bool bUseRelativeCoordinates ) + bool bUseRelativeCoordinates ) { return bUseRelativeCoordinates ? cLowerCaseCommand : cUpperCaseCommand; } } - bool importFromSvgD(B2DPolyPolygon& o_rPolyPolygon, const ::rtl::OUString& rSvgDStatement) + bool importFromSvgD(B2DPolyPolygon& o_rPolyPolygon, const ::rtl::OUString& rSvgDStatement) { o_rPolyPolygon.clear(); const sal_Int32 nLen(rSvgDStatement.getLength()); @@ -301,7 +301,7 @@ namespace basegfx bIsClosed = true; break; } - + case 'm' : case 'M' : { @@ -326,9 +326,9 @@ namespace basegfx { closeWithGeometryChange(aCurrPoly); } - + o_rPolyPolygon.append(aCurrPoly); - + // reset import values bIsClosed = false; aCurrPoly.clear(); @@ -354,7 +354,7 @@ namespace basegfx // set last position nLastX = nX; nLastY = nY; - + // add point aCurrPoly.append(B2DPoint(nX, nY)); } @@ -384,13 +384,13 @@ namespace basegfx // set last position nLastX = nX; - + // add point aCurrPoly.append(B2DPoint(nX, nY)); } break; } - + case 'v' : { bRelative = true; @@ -414,13 +414,13 @@ namespace basegfx // set last position nLastY = nY; - + // add point aCurrPoly.append(B2DPoint(nX, nY)); } break; } - + case 's' : { bRelative = true; @@ -479,7 +479,7 @@ namespace basegfx } break; } - + case 'c' : { bRelative = true; @@ -528,7 +528,7 @@ namespace basegfx } break; } - + // #100617# quadratic beziers are imported as cubic ones case 'q' : { @@ -579,7 +579,7 @@ namespace basegfx } break; } - + // #100617# relative quadratic beziers are imported as cubic case 't' : { @@ -633,11 +633,11 @@ namespace basegfx const B2DPoint aQuadControlPoint( ((3.0 * aPrevControl.getX()) - aPrevPoint.getX()) / 2.0, ((3.0 * aPrevControl.getY()) - aPrevPoint.getY()) / 2.0); - + // calculate the cubic bezier coefficients from the quadratic ones. const double nX2Prime((aQuadControlPoint.getX() * 2.0 + nX) / 3.0); const double nY2Prime((aQuadControlPoint.getY() * 2.0 + nY) / 3.0); - + // append curved edge, use mirrored cubic control point directly aCurrPoly.appendBezierSegment(aPrevControl, B2DPoint(nX2Prime, nY2Prime), B2DPoint(nX, nY)); } @@ -699,7 +699,7 @@ namespace basegfx { // normalize according to SVG spec fRX=fabs(fRX); fRY=fabs(fRY); - + // from the SVG spec, appendix F.6.4 // |x1'| |cos phi sin phi| |(x1 - x2)/2| @@ -707,12 +707,12 @@ namespace basegfx const B2DPoint p1(nLastX, nLastY); const B2DPoint p2(nX, nY); B2DHomMatrix aTransform(basegfx::tools::createRotateB2DHomMatrix(-fPhi*M_PI/180)); - + const B2DPoint p1_prime( aTransform * B2DPoint(((p1-p2)/2.0)) ); // ______________________________________ rx y1' // |cx'| + / rx^2 ry^2 - rx^2 y1'^2 - ry^2 x1^2 ry - // |cy'| =-/ rx^2y1'^2 + ry^2 x1'^2 - ry x1' + // |cy'| =-/ rx^2y1'^2 + ry^2 x1'^2 - ry x1' // rx // chose + if f_A != f_S // chose - if f_A = f_S @@ -741,7 +741,7 @@ namespace basegfx aCurrPoly.append(B2DPoint(nX, nY)); continue; } - + fRY=sqrt(fRadicant2); fRX=fRatio*fRY; @@ -759,7 +759,7 @@ namespace basegfx -fFactor*fRY*p1_prime.getX()/fRX); } - // + u - v + // + u - v // angle(u,v) = arccos( ------------ ) (take the sign of (ux vy - uy vx)) // - ||u|| ||v|| @@ -767,14 +767,14 @@ namespace basegfx // theta1 = angle(( ), | | ) // 0 | (y1' - cy')/ry | const B2DPoint aRadii(fRX,fRY); - double fTheta1( + double fTheta1( B2DVector(1.0,0.0).angle( (p1_prime-aCenter_prime)/aRadii)); // |1| | (-x1' - cx')/rx | // theta2 = angle( | | , | | ) // |0| | (-y1' - cy')/ry | - double fTheta2( + double fTheta2( B2DVector(1.0,0.0).angle( (-p1_prime-aCenter_prime)/aRadii)); @@ -786,7 +786,7 @@ namespace basegfx // (since // createPolygonFromEllipseSegment() // normalizes to e.g. cw arc) - const bool bFlipSegment( (bLargeArcFlag!=0) == + const bool bFlipSegment( (bLargeArcFlag!=0) == (fmod(fTheta2+2*M_PI-fTheta1, 2*M_PI)<M_PI) ); if( bFlipSegment ) @@ -794,11 +794,11 @@ namespace basegfx // finally, create bezier polygon from this B2DPolygon aSegment( - tools::createPolygonFromUnitEllipseSegment( + tools::createPolygonFromUnitEllipseSegment( fTheta1, fTheta2 )); // transform ellipse by rotation & move to final center - aTransform = basegfx::tools::createScaleB2DHomMatrix(fRX, fRY); + aTransform = basegfx::tools::createScaleB2DHomMatrix(fRX, fRY); aTransform.translate(aCenter_prime.getX(), aCenter_prime.getY()); aTransform.rotate(fPhi*M_PI/180); @@ -806,7 +806,7 @@ namespace basegfx aTransform.translate(aOffset.getX(), aOffset.getY()); aSegment.transform(aTransform); - + // createPolygonFromEllipseSegment() // always creates arcs that are // positively oriented - flip polygon @@ -862,8 +862,8 @@ namespace basegfx { if(!lcl_importDoubleAndSpaces(nX, nPos, rSvgPointsAttribute, nLen)) return false; if(!lcl_importDoubleAndSpaces(nY, nPos, rSvgPointsAttribute, nLen)) return false; - - // add point + + // add point o_rPoly.append(B2DPoint(nX, nY)); // skip to next number, or finish @@ -875,7 +875,7 @@ namespace basegfx ::rtl::OUString exportToSvgD( const B2DPolyPolygon& rPolyPolygon, - bool bUseRelativeCoordinates, + bool bUseRelativeCoordinates, bool bDetectQuadraticBeziers) { const sal_uInt32 nCount(rPolyPolygon.count()); @@ -909,7 +909,7 @@ namespace basegfx const B2DPoint aEdgeEnd(aPolygon.getB2DPoint(nNextIndex)); // handle edge from (aEdgeStart, aEdgeEnd) using indices (nIndex, nNextIndex) - const bool bEdgeIsBezier(bPolyUsesControlPoints + const bool bEdgeIsBezier(bPolyUsesControlPoints && (aPolygon.isNextControlPointUsed(nIndex) || aPolygon.isPrevControlPointUsed(nNextIndex))); if(bEdgeIsBezier) @@ -920,18 +920,18 @@ namespace basegfx bool bIsQuadraticBezier(false); // check continuity at current edge's start point. For SVG, do NOT use an - // existing continuity since no 'S' or 's' statement should be written. At - // import, that 'previous' control vector is not available. SVG documentation + // existing continuity since no 'S' or 's' statement should be written. At + // import, that 'previous' control vector is not available. SVG documentation // says for interpretation: // - // "(If there is no previous command or if the previous command was - // not an C, c, S or s, assume the first control point is coincident + // "(If there is no previous command or if the previous command was + // not an C, c, S or s, assume the first control point is coincident // with the current point.)" // // That's what is done from our import, so avoid exporting it as first statement // is necessary. const bool bSymmetricAtEdgeStart( - 0 != nIndex + 0 != nIndex && CONTINUITY_C2 == aPolygon.getContinuityInPoint(nIndex)); if(bDetectQuadraticBeziers) @@ -941,7 +941,7 @@ namespace basegfx // the same place when they are prolonged // to the common quadratic control point // - // Left: P = (3P1 - P0) / 2 + // Left: P = (3P1 - P0) / 2 // Right: P = (3P2 - P3) / 2 aLeft = B2DPoint((3.0 * aControlEdgeStart - aEdgeStart) / 2.0); aRight= B2DPoint((3.0 * aControlEdgeEnd - aEdgeEnd) / 2.0); @@ -960,7 +960,7 @@ namespace basegfx aResult.append(aCommand); aLastSVGCommand = aCommand; } - + lcl_putNumberCharWithSpace(aResult, aEdgeEnd.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates); lcl_putNumberCharWithSpace(aResult, aEdgeEnd.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinates); aLastSVGCommand = aCommand; @@ -975,7 +975,7 @@ namespace basegfx aResult.append(aCommand); aLastSVGCommand = aCommand; } - + lcl_putNumberCharWithSpace(aResult, aLeft.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates); lcl_putNumberCharWithSpace(aResult, aLeft.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinates); lcl_putNumberCharWithSpace(aResult, aEdgeEnd.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates); @@ -996,7 +996,7 @@ namespace basegfx aResult.append(aCommand); aLastSVGCommand = aCommand; } - + lcl_putNumberCharWithSpace(aResult, aControlEdgeEnd.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates); lcl_putNumberCharWithSpace(aResult, aControlEdgeEnd.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinates); lcl_putNumberCharWithSpace(aResult, aEdgeEnd.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates); @@ -1013,7 +1013,7 @@ namespace basegfx aResult.append(aCommand); aLastSVGCommand = aCommand; } - + lcl_putNumberCharWithSpace(aResult, aControlEdgeStart.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates); lcl_putNumberCharWithSpace(aResult, aControlEdgeStart.getY(), aCurrentSVGPosition.getY(), bUseRelativeCoordinates); lcl_putNumberCharWithSpace(aResult, aControlEdgeEnd.getX(), aCurrentSVGPosition.getX(), bUseRelativeCoordinates); |