summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-08-05 20:31:06 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-08-06 08:39:29 +0200
commit987c96d8a976338dcb8b5b8c4d1258b8fddb0093 (patch)
treed893ab08e5ce2d926f9d841b411d70e5d76d6175
parent1616b53292cdc22c04d07bb21e71bf43dcd22299 (diff)
loplugin:flatten in tools
Change-Id: I6e5c07f4e63b949afb8c259d623a0711a86db021 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100188 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--tools/source/generic/config.cxx140
-rw-r--r--tools/source/generic/poly.cxx182
-rw-r--r--tools/source/generic/poly2.cxx74
-rw-r--r--tools/source/stream/vcompat.cxx28
4 files changed, 212 insertions, 212 deletions
diff --git a/tools/source/generic/config.cxx b/tools/source/generic/config.cxx
index 6808bc4a132a..0f2e13acea21 100644
--- a/tools/source/generic/config.cxx
+++ b/tools/source/generic/config.cxx
@@ -667,31 +667,31 @@ void Config::DeleteGroup(const OString& rGroup)
pGroup = pGroup->mpNext;
}
- if ( pGroup )
+ if ( !pGroup )
+ return;
+
+ // Remove all keys
+ ImplKeyData* pTempKey;
+ ImplKeyData* pKey = pGroup->mpFirstKey;
+ while ( pKey )
{
- // Remove all keys
- ImplKeyData* pTempKey;
- ImplKeyData* pKey = pGroup->mpFirstKey;
- while ( pKey )
- {
- pTempKey = pKey->mpNext;
- delete pKey;
- pKey = pTempKey;
- }
+ pTempKey = pKey->mpNext;
+ delete pKey;
+ pKey = pTempKey;
+ }
- // Rewire pointers and remove group
- if ( pPrevGroup )
- pPrevGroup->mpNext = pGroup->mpNext;
- else
- mpData->mpFirstGroup = pGroup->mpNext;
- delete pGroup;
+ // Rewire pointers and remove group
+ if ( pPrevGroup )
+ pPrevGroup->mpNext = pGroup->mpNext;
+ else
+ mpData->mpFirstGroup = pGroup->mpNext;
+ delete pGroup;
- // Rewrite config data
- mpData->mbModified = true;
+ // Rewrite config data
+ mpData->mbModified = true;
- mnDataUpdateId = mpData->mnDataUpdateId;
- mpData->mnDataUpdateId++;
- }
+ mnDataUpdateId = mpData->mnDataUpdateId;
+ mpData->mnDataUpdateId++;
}
OString Config::GetGroupName(sal_uInt16 nGroup) const
@@ -787,41 +787,41 @@ void Config::WriteKey(const OString& rKey, const OString& rStr)
// Search key and update value if found
ImplGroupData* pGroup = ImplGetGroup();
- if ( pGroup )
+ if ( !pGroup )
+ return;
+
+ ImplKeyData* pPrevKey = nullptr;
+ ImplKeyData* pKey = pGroup->mpFirstKey;
+ while ( pKey )
{
- ImplKeyData* pPrevKey = nullptr;
- ImplKeyData* pKey = pGroup->mpFirstKey;
- while ( pKey )
- {
- if ( !pKey->mbIsComment && pKey->maKey.equalsIgnoreAsciiCase(rKey) )
- break;
+ if ( !pKey->mbIsComment && pKey->maKey.equalsIgnoreAsciiCase(rKey) )
+ break;
- pPrevKey = pKey;
- pKey = pKey->mpNext;
- }
+ pPrevKey = pKey;
+ pKey = pKey->mpNext;
+ }
- bool bNewValue;
- if ( !pKey )
- {
- pKey = new ImplKeyData;
- pKey->mpNext = nullptr;
- pKey->maKey = rKey;
- pKey->mbIsComment = false;
- if ( pPrevKey )
- pPrevKey->mpNext = pKey;
- else
- pGroup->mpFirstKey = pKey;
- bNewValue = true;
- }
+ bool bNewValue;
+ if ( !pKey )
+ {
+ pKey = new ImplKeyData;
+ pKey->mpNext = nullptr;
+ pKey->maKey = rKey;
+ pKey->mbIsComment = false;
+ if ( pPrevKey )
+ pPrevKey->mpNext = pKey;
else
- bNewValue = pKey->maValue != rStr;
+ pGroup->mpFirstKey = pKey;
+ bNewValue = true;
+ }
+ else
+ bNewValue = pKey->maValue != rStr;
- if ( bNewValue )
- {
- pKey->maValue = rStr;
+ if ( bNewValue )
+ {
+ pKey->maValue = rStr;
- mpData->mbModified = true;
- }
+ mpData->mbModified = true;
}
}
@@ -836,30 +836,30 @@ void Config::DeleteKey(const OString& rKey)
// Search key and update value
ImplGroupData* pGroup = ImplGetGroup();
- if ( pGroup )
+ if ( !pGroup )
+ return;
+
+ ImplKeyData* pPrevKey = nullptr;
+ ImplKeyData* pKey = pGroup->mpFirstKey;
+ while ( pKey )
{
- ImplKeyData* pPrevKey = nullptr;
- ImplKeyData* pKey = pGroup->mpFirstKey;
- while ( pKey )
- {
- if ( !pKey->mbIsComment && pKey->maKey.equalsIgnoreAsciiCase(rKey) )
- break;
+ if ( !pKey->mbIsComment && pKey->maKey.equalsIgnoreAsciiCase(rKey) )
+ break;
- pPrevKey = pKey;
- pKey = pKey->mpNext;
- }
+ pPrevKey = pKey;
+ pKey = pKey->mpNext;
+ }
- if ( pKey )
- {
- // Rewire group pointers and delete
- if ( pPrevKey )
- pPrevKey->mpNext = pKey->mpNext;
- else
- pGroup->mpFirstKey = pKey->mpNext;
- delete pKey;
+ if ( pKey )
+ {
+ // Rewire group pointers and delete
+ if ( pPrevKey )
+ pPrevKey->mpNext = pKey->mpNext;
+ else
+ pGroup->mpFirstKey = pKey->mpNext;
+ delete pKey;
- mpData->mbModified = true;
- }
+ mpData->mbModified = true;
}
}
diff --git a/tools/source/generic/poly.cxx b/tools/source/generic/poly.cxx
index 08d6a3eeee84..eab7a81acc39 100644
--- a/tools/source/generic/poly.cxx
+++ b/tools/source/generic/poly.cxx
@@ -1029,60 +1029,60 @@ void Polygon::Optimize( PolyOptimizeFlags nOptimizeFlags )
sal_uInt16 nSize = mpImplPolygon->mnPoints;
- if( bool(nOptimizeFlags) && nSize )
+ if( !(bool(nOptimizeFlags) && nSize) )
+ return;
+
+ if( nOptimizeFlags & PolyOptimizeFlags::EDGES )
{
- if( nOptimizeFlags & PolyOptimizeFlags::EDGES )
- {
- const tools::Rectangle aBound( GetBoundRect() );
- const double fArea = ( aBound.GetWidth() + aBound.GetHeight() ) * 0.5;
- const sal_uInt16 nPercent = 50;
+ const tools::Rectangle aBound( GetBoundRect() );
+ const double fArea = ( aBound.GetWidth() + aBound.GetHeight() ) * 0.5;
+ const sal_uInt16 nPercent = 50;
- Optimize( PolyOptimizeFlags::NO_SAME );
- ImplReduceEdges( *this, fArea, nPercent );
- }
- else if( nOptimizeFlags & PolyOptimizeFlags::NO_SAME )
- {
- tools::Polygon aNewPoly;
- const Point& rFirst = mpImplPolygon->mxPointAry[ 0 ];
+ Optimize( PolyOptimizeFlags::NO_SAME );
+ ImplReduceEdges( *this, fArea, nPercent );
+ }
+ else if( nOptimizeFlags & PolyOptimizeFlags::NO_SAME )
+ {
+ tools::Polygon aNewPoly;
+ const Point& rFirst = mpImplPolygon->mxPointAry[ 0 ];
- while( nSize && ( mpImplPolygon->mxPointAry[ nSize - 1 ] == rFirst ) )
- nSize--;
+ while( nSize && ( mpImplPolygon->mxPointAry[ nSize - 1 ] == rFirst ) )
+ nSize--;
- if( nSize > 1 )
- {
- sal_uInt16 nLast = 0, nNewCount = 1;
+ if( nSize > 1 )
+ {
+ sal_uInt16 nLast = 0, nNewCount = 1;
- aNewPoly.SetSize( nSize );
- aNewPoly[ 0 ] = rFirst;
+ aNewPoly.SetSize( nSize );
+ aNewPoly[ 0 ] = rFirst;
- for( sal_uInt16 i = 1; i < nSize; i++ )
+ for( sal_uInt16 i = 1; i < nSize; i++ )
+ {
+ if( mpImplPolygon->mxPointAry[ i ] != mpImplPolygon->mxPointAry[ nLast ])
{
- if( mpImplPolygon->mxPointAry[ i ] != mpImplPolygon->mxPointAry[ nLast ])
- {
- nLast = i;
- aNewPoly[ nNewCount++ ] = mpImplPolygon->mxPointAry[ i ];
- }
+ nLast = i;
+ aNewPoly[ nNewCount++ ] = mpImplPolygon->mxPointAry[ i ];
}
-
- if( nNewCount == 1 )
- aNewPoly.Clear();
- else
- aNewPoly.SetSize( nNewCount );
}
- *this = aNewPoly;
+ if( nNewCount == 1 )
+ aNewPoly.Clear();
+ else
+ aNewPoly.SetSize( nNewCount );
}
- nSize = mpImplPolygon->mnPoints;
+ *this = aNewPoly;
+ }
+
+ nSize = mpImplPolygon->mnPoints;
- if( nSize > 1 )
+ if( nSize > 1 )
+ {
+ if( ( nOptimizeFlags & PolyOptimizeFlags::CLOSE ) &&
+ ( mpImplPolygon->mxPointAry[ 0 ] != mpImplPolygon->mxPointAry[ nSize - 1 ] ) )
{
- if( ( nOptimizeFlags & PolyOptimizeFlags::CLOSE ) &&
- ( mpImplPolygon->mxPointAry[ 0 ] != mpImplPolygon->mxPointAry[ nSize - 1 ] ) )
- {
- SetSize( mpImplPolygon->mnPoints + 1 );
- mpImplPolygon->mxPointAry[ mpImplPolygon->mnPoints - 1 ] = mpImplPolygon->mxPointAry[ 0 ];
- }
+ SetSize( mpImplPolygon->mnPoints + 1 );
+ mpImplPolygon->mxPointAry[ mpImplPolygon->mnPoints - 1 ] = mpImplPolygon->mxPointAry[ 0 ];
}
}
}
@@ -1719,58 +1719,58 @@ static void impCorrectContinuity(basegfx::B2DPolygon& roPolygon, sal_uInt32 nInd
const sal_uInt32 nPointCount(roPolygon.count());
OSL_ENSURE(nIndex < nPointCount, "impCorrectContinuity: index access out of range (!)");
- if(nIndex < nPointCount && (PolyFlags::Smooth == nCFlag || PolyFlags::Symmetric == nCFlag))
- {
- if(roPolygon.isPrevControlPointUsed(nIndex) && roPolygon.isNextControlPointUsed(nIndex))
- {
- // #i115917# Patch from osnola (modified, thanks for showing the problem)
-
- // The correction is needed because an integer polygon with control points
- // is converted to double precision. When C1 or C2 is used the involved vectors
- // may not have the same directions/lengths since these come from integer coordinates
- // and may have been snapped to different nearest integer coordinates. The snap error
- // is in the range of +-1 in y and y, thus 0.0 <= error <= sqrt(2.0). Nonetheless,
- // it needs to be corrected to be able to detect the continuity in this points
- // correctly.
-
- // We only have the integer data here (already in double precision form, but no mantissa
- // used), so the best correction is to use:
-
- // for C1: The longest vector since it potentially has best preserved the original vector.
- // Even better the sum of the vectors, weighted by their length. This gives the
- // normal vector addition to get the vector itself, lengths need to be preserved.
- // for C2: The mediated vector(s) since both should be the same, but mirrored
-
- // extract the point and vectors
- const basegfx::B2DPoint aPoint(roPolygon.getB2DPoint(nIndex));
- const basegfx::B2DVector aNext(roPolygon.getNextControlPoint(nIndex) - aPoint);
- const basegfx::B2DVector aPrev(aPoint - roPolygon.getPrevControlPoint(nIndex));
-
- // calculate common direction vector, normalize
- const basegfx::B2DVector aDirection(aNext + aPrev);
- const double fDirectionLen = aDirection.getLength();
- if (fDirectionLen == 0.0)
- return;
+ if(nIndex >= nPointCount || (PolyFlags::Smooth != nCFlag && PolyFlags::Symmetric != nCFlag))
+ return;
- if (PolyFlags::Smooth == nCFlag)
- {
- // C1: apply common direction vector, preserve individual lengths
- const double fInvDirectionLen(1.0 / fDirectionLen);
- roPolygon.setNextControlPoint(nIndex, basegfx::B2DPoint(aPoint + (aDirection * (aNext.getLength() * fInvDirectionLen))));
- roPolygon.setPrevControlPoint(nIndex, basegfx::B2DPoint(aPoint - (aDirection * (aPrev.getLength() * fInvDirectionLen))));
- }
- else // PolyFlags::Symmetric
- {
- // C2: get mediated length. Taking half of the unnormalized direction would be
- // an approximation, but not correct.
- const double fMedLength((aNext.getLength() + aPrev.getLength()) * (0.5 / fDirectionLen));
- const basegfx::B2DVector aScaledDirection(aDirection * fMedLength);
-
- // Bring Direction to correct length and apply
- roPolygon.setNextControlPoint(nIndex, basegfx::B2DPoint(aPoint + aScaledDirection));
- roPolygon.setPrevControlPoint(nIndex, basegfx::B2DPoint(aPoint - aScaledDirection));
- }
- }
+ if(!roPolygon.isPrevControlPointUsed(nIndex) || !roPolygon.isNextControlPointUsed(nIndex))
+ return;
+
+ // #i115917# Patch from osnola (modified, thanks for showing the problem)
+
+ // The correction is needed because an integer polygon with control points
+ // is converted to double precision. When C1 or C2 is used the involved vectors
+ // may not have the same directions/lengths since these come from integer coordinates
+ // and may have been snapped to different nearest integer coordinates. The snap error
+ // is in the range of +-1 in y and y, thus 0.0 <= error <= sqrt(2.0). Nonetheless,
+ // it needs to be corrected to be able to detect the continuity in this points
+ // correctly.
+
+ // We only have the integer data here (already in double precision form, but no mantissa
+ // used), so the best correction is to use:
+
+ // for C1: The longest vector since it potentially has best preserved the original vector.
+ // Even better the sum of the vectors, weighted by their length. This gives the
+ // normal vector addition to get the vector itself, lengths need to be preserved.
+ // for C2: The mediated vector(s) since both should be the same, but mirrored
+
+ // extract the point and vectors
+ const basegfx::B2DPoint aPoint(roPolygon.getB2DPoint(nIndex));
+ const basegfx::B2DVector aNext(roPolygon.getNextControlPoint(nIndex) - aPoint);
+ const basegfx::B2DVector aPrev(aPoint - roPolygon.getPrevControlPoint(nIndex));
+
+ // calculate common direction vector, normalize
+ const basegfx::B2DVector aDirection(aNext + aPrev);
+ const double fDirectionLen = aDirection.getLength();
+ if (fDirectionLen == 0.0)
+ return;
+
+ if (PolyFlags::Smooth == nCFlag)
+ {
+ // C1: apply common direction vector, preserve individual lengths
+ const double fInvDirectionLen(1.0 / fDirectionLen);
+ roPolygon.setNextControlPoint(nIndex, basegfx::B2DPoint(aPoint + (aDirection * (aNext.getLength() * fInvDirectionLen))));
+ roPolygon.setPrevControlPoint(nIndex, basegfx::B2DPoint(aPoint - (aDirection * (aPrev.getLength() * fInvDirectionLen))));
+ }
+ else // PolyFlags::Symmetric
+ {
+ // C2: get mediated length. Taking half of the unnormalized direction would be
+ // an approximation, but not correct.
+ const double fMedLength((aNext.getLength() + aPrev.getLength()) * (0.5 / fDirectionLen));
+ const basegfx::B2DVector aScaledDirection(aDirection * fMedLength);
+
+ // Bring Direction to correct length and apply
+ roPolygon.setNextControlPoint(nIndex, basegfx::B2DPoint(aPoint + aScaledDirection));
+ roPolygon.setPrevControlPoint(nIndex, basegfx::B2DPoint(aPoint - aScaledDirection));
}
}
diff --git a/tools/source/generic/poly2.cxx b/tools/source/generic/poly2.cxx
index d37ba809f2fb..5591ea4e6d83 100644
--- a/tools/source/generic/poly2.cxx
+++ b/tools/source/generic/poly2.cxx
@@ -100,55 +100,55 @@ void PolyPolygon::Clear()
void PolyPolygon::Optimize( PolyOptimizeFlags nOptimizeFlags )
{
- if(bool(nOptimizeFlags) && Count())
- {
- // #115630# ImplDrawHatch does not work with beziers included in the polypolygon, take care of that
- bool bIsCurve(false);
+ if(!(bool(nOptimizeFlags) && Count()))
+ return;
+
+ // #115630# ImplDrawHatch does not work with beziers included in the polypolygon, take care of that
+ bool bIsCurve(false);
- for(sal_uInt16 a(0); !bIsCurve && a < Count(); a++)
+ for(sal_uInt16 a(0); !bIsCurve && a < Count(); a++)
+ {
+ if((*this)[a].HasFlags())
{
- if((*this)[a].HasFlags())
- {
- bIsCurve = true;
- }
+ bIsCurve = true;
}
+ }
+
+ if(bIsCurve)
+ {
+ OSL_ENSURE(false, "Optimize does *not* support curves, falling back to AdaptiveSubdivide()...");
+ tools::PolyPolygon aPolyPoly;
- if(bIsCurve)
+ AdaptiveSubdivide(aPolyPoly);
+ aPolyPoly.Optimize(nOptimizeFlags);
+ *this = aPolyPoly;
+ }
+ else
+ {
+ double fArea;
+ const bool bEdges = ( nOptimizeFlags & PolyOptimizeFlags::EDGES ) == PolyOptimizeFlags::EDGES;
+ sal_uInt16 nPercent = 0;
+
+ if( bEdges )
{
- OSL_ENSURE(false, "Optimize does *not* support curves, falling back to AdaptiveSubdivide()...");
- tools::PolyPolygon aPolyPoly;
+ const tools::Rectangle aBound( GetBoundRect() );
- AdaptiveSubdivide(aPolyPoly);
- aPolyPoly.Optimize(nOptimizeFlags);
- *this = aPolyPoly;
+ fArea = ( aBound.GetWidth() + aBound.GetHeight() ) * 0.5;
+ nPercent = 50;
+ nOptimizeFlags &= ~PolyOptimizeFlags::EDGES;
}
- else
- {
- double fArea;
- const bool bEdges = ( nOptimizeFlags & PolyOptimizeFlags::EDGES ) == PolyOptimizeFlags::EDGES;
- sal_uInt16 nPercent = 0;
+ // Optimize polygons
+ for( sal_uInt16 i = 0, nPolyCount = mpImplPolyPolygon->mvPolyAry.size(); i < nPolyCount; i++ )
+ {
if( bEdges )
{
- const tools::Rectangle aBound( GetBoundRect() );
-
- fArea = ( aBound.GetWidth() + aBound.GetHeight() ) * 0.5;
- nPercent = 50;
- nOptimizeFlags &= ~PolyOptimizeFlags::EDGES;
+ mpImplPolyPolygon->mvPolyAry[ i ].Optimize( PolyOptimizeFlags::NO_SAME );
+ tools::Polygon::ImplReduceEdges( mpImplPolyPolygon->mvPolyAry[ i ], fArea, nPercent );
}
- // Optimize polygons
- for( sal_uInt16 i = 0, nPolyCount = mpImplPolyPolygon->mvPolyAry.size(); i < nPolyCount; i++ )
- {
- if( bEdges )
- {
- mpImplPolyPolygon->mvPolyAry[ i ].Optimize( PolyOptimizeFlags::NO_SAME );
- tools::Polygon::ImplReduceEdges( mpImplPolyPolygon->mvPolyAry[ i ], fArea, nPercent );
- }
-
- if( bool(nOptimizeFlags) )
- mpImplPolyPolygon->mvPolyAry[ i ].Optimize( nOptimizeFlags );
- }
+ if( bool(nOptimizeFlags) )
+ mpImplPolyPolygon->mvPolyAry[ i ].Optimize( nOptimizeFlags );
}
}
}
diff --git a/tools/source/stream/vcompat.cxx b/tools/source/stream/vcompat.cxx
index d77f866e06af..a63440701360 100644
--- a/tools/source/stream/vcompat.cxx
+++ b/tools/source/stream/vcompat.cxx
@@ -27,21 +27,21 @@ VersionCompat::VersionCompat( SvStream& rStm, StreamMode nStreamMode, sal_uInt16
mnStmMode ( nStreamMode ),
mnVersion ( nVersion )
{
- if( !mpRWStm->GetError() )
+ if( mpRWStm->GetError() )
+ return;
+
+ if( StreamMode::WRITE == mnStmMode )
+ {
+ mpRWStm->WriteUInt16( mnVersion );
+ mnCompatPos = mpRWStm->Tell();
+ mnTotalSize = mnCompatPos + 4;
+ mpRWStm->SeekRel( 4 );
+ }
+ else
{
- if( StreamMode::WRITE == mnStmMode )
- {
- mpRWStm->WriteUInt16( mnVersion );
- mnCompatPos = mpRWStm->Tell();
- mnTotalSize = mnCompatPos + 4;
- mpRWStm->SeekRel( 4 );
- }
- else
- {
- mpRWStm->ReadUInt16( mnVersion );
- mpRWStm->ReadUInt32( mnTotalSize );
- mnCompatPos = mpRWStm->Tell();
- }
+ mpRWStm->ReadUInt16( mnVersion );
+ mpRWStm->ReadUInt32( mnTotalSize );
+ mnCompatPos = mpRWStm->Tell();
}
}