Resolves: #i115630# secured OutputDevice::ImplDrawHatch in vcl

and PolyPolygon::Optimize in tools to useful fallbacks when working on
PolyPolygons (what they do *not* support)

(cherry picked from commit dbe489ab9766d96c5cafb079bc4778103bded783)

Conflicts:
	vcl/source/gdi/outdev4.cxx

Change-Id: I5d2374ec95702cb0cab29d2e82710d4aa29fa823
This commit is contained in:
Armin Le Grand
2012-09-27 12:07:14 +00:00
committed by Caolán McNamara
parent 59cc160f34
commit c1acf1d72e
2 changed files with 99 additions and 51 deletions

View File

@@ -241,39 +241,62 @@ void PolyPolygon::Optimize( sal_uIntPtr nOptimizeFlags, const PolyOptimizeData*
{ {
DBG_CHKTHIS( PolyPolygon, NULL ); DBG_CHKTHIS( PolyPolygon, NULL );
if( nOptimizeFlags ) if(nOptimizeFlags && Count())
{ {
double fArea; // #115630# ImplDrawHatch does not work with beziers included in the polypolygon, take care of that
const sal_Bool bEdges = ( nOptimizeFlags & POLY_OPTIMIZE_EDGES ) == POLY_OPTIMIZE_EDGES; bool bIsCurve(false);
sal_uInt16 nPercent = 0;
if( bEdges ) for(sal_uInt16 a(0); !bIsCurve && a < Count(); a++)
{ {
const Rectangle aBound( GetBoundRect() ); if((*this)[a].HasFlags())
{
fArea = ( aBound.GetWidth() + aBound.GetHeight() ) * 0.5; bIsCurve = true;
nPercent = pData ? pData->GetPercentValue() : 50; }
nOptimizeFlags &= ~POLY_OPTIMIZE_EDGES;
} }
// watch for ref counter if(bIsCurve)
if( mpImplPolyPolygon->mnRefCount > 1 )
{ {
mpImplPolyPolygon->mnRefCount--; OSL_ENSURE(false, "Optimize does *not* support curves, falling back to AdaptiveSubdivide()...");
mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon ); PolyPolygon aPolyPoly;
}
// Optimize polygons AdaptiveSubdivide(aPolyPoly);
for( sal_uInt16 i = 0, nPolyCount = mpImplPolyPolygon->mnCount; i < nPolyCount; i++ ) aPolyPoly.Optimize(nOptimizeFlags, pData);
*this = aPolyPoly;
}
else
{ {
double fArea;
const sal_Bool bEdges = ( nOptimizeFlags & POLY_OPTIMIZE_EDGES ) == POLY_OPTIMIZE_EDGES;
sal_uInt16 nPercent = 0;
if( bEdges ) if( bEdges )
{ {
mpImplPolyPolygon->mpPolyAry[ i ]->Optimize( POLY_OPTIMIZE_NO_SAME ); const Rectangle aBound( GetBoundRect() );
Polygon::ImplReduceEdges( *( mpImplPolyPolygon->mpPolyAry[ i ] ), fArea, nPercent );
fArea = ( aBound.GetWidth() + aBound.GetHeight() ) * 0.5;
nPercent = pData ? pData->GetPercentValue() : 50;
nOptimizeFlags &= ~POLY_OPTIMIZE_EDGES;
} }
if( nOptimizeFlags ) // watch for ref counter
mpImplPolyPolygon->mpPolyAry[ i ]->Optimize( nOptimizeFlags, pData ); if( mpImplPolyPolygon->mnRefCount > 1 )
{
mpImplPolyPolygon->mnRefCount--;
mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon );
}
// Optimize polygons
for( sal_uInt16 i = 0, nPolyCount = mpImplPolyPolygon->mnCount; i < nPolyCount; i++ )
{
if( bEdges )
{
mpImplPolyPolygon->mpPolyAry[ i ]->Optimize( POLY_OPTIMIZE_NO_SAME );
Polygon::ImplReduceEdges( *( mpImplPolyPolygon->mpPolyAry[ i ] ), fArea, nPercent );
}
if( nOptimizeFlags )
mpImplPolyPolygon->mpPolyAry[ i ]->Optimize( nOptimizeFlags, pData );
}
} }
} }
} }

View File

@@ -1077,40 +1077,39 @@ void OutputDevice::AddHatchActions( const PolyPolygon& rPolyPoly, const Hatch& r
void OutputDevice::ImplDrawHatch( const PolyPolygon& rPolyPoly, const Hatch& rHatch, sal_Bool bMtf ) void OutputDevice::ImplDrawHatch( const PolyPolygon& rPolyPoly, const Hatch& rHatch, sal_Bool bMtf )
{ {
Rectangle aRect( rPolyPoly.GetBoundRect() ); if(rPolyPoly.Count())
const long nLogPixelWidth = ImplDevicePixelToLogicWidth( 1 );
const long nWidth = ImplDevicePixelToLogicWidth( std::max( ImplLogicWidthToDevicePixel( rHatch.GetDistance() ), 3L ) );
Point* pPtBuffer = new Point[ HATCH_MAXPOINTS ];
Point aPt1, aPt2, aEndPt1;
Size aInc;
// Single hatch
aRect.Left() -= nLogPixelWidth; aRect.Top() -= nLogPixelWidth; aRect.Right() += nLogPixelWidth; aRect.Bottom() += nLogPixelWidth;
ImplCalcHatchValues( aRect, nWidth, rHatch.GetAngle(), aPt1, aPt2, aInc, aEndPt1 );
do
{ {
ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer, bMtf ); // #i115630# ImplDrawHatch does not work with beziers included in the polypolygon, take care of that
aPt1.X() += aInc.Width(); aPt1.Y() += aInc.Height(); bool bIsCurve(false);
aPt2.X() += aInc.Width(); aPt2.Y() += aInc.Height();
}
while( ( aPt1.X() <= aEndPt1.X() ) && ( aPt1.Y() <= aEndPt1.Y() ) );
if( ( rHatch.GetStyle() == HATCH_DOUBLE ) || ( rHatch.GetStyle() == HATCH_TRIPLE ) ) for(sal_uInt16 a(0); !bIsCurve && a < rPolyPoly.Count(); a++)
{
// Double hatch
ImplCalcHatchValues( aRect, nWidth, rHatch.GetAngle() + 900, aPt1, aPt2, aInc, aEndPt1 );
do
{ {
ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer, bMtf ); if(rPolyPoly[a].HasFlags())
aPt1.X() += aInc.Width(); aPt1.Y() += aInc.Height(); {
aPt2.X() += aInc.Width(); aPt2.Y() += aInc.Height(); bIsCurve = true;
}
} }
while( ( aPt1.X() <= aEndPt1.X() ) && ( aPt1.Y() <= aEndPt1.Y() ) );
if( rHatch.GetStyle() == HATCH_TRIPLE ) if(bIsCurve)
{ {
// Triple hatch OSL_ENSURE(false, "ImplDrawHatch does *not* support curves, falling back to AdaptiveSubdivide()...");
ImplCalcHatchValues( aRect, nWidth, rHatch.GetAngle() + 450, aPt1, aPt2, aInc, aEndPt1 ); PolyPolygon aPolyPoly;
rPolyPoly.AdaptiveSubdivide(aPolyPoly);
ImplDrawHatch(aPolyPoly, rHatch, bMtf);
}
else
{
Rectangle aRect( rPolyPoly.GetBoundRect() );
const long nLogPixelWidth = ImplDevicePixelToLogicWidth( 1 );
const long nWidth = ImplDevicePixelToLogicWidth( std::max( ImplLogicWidthToDevicePixel( rHatch.GetDistance() ), 3L ) );
Point* pPtBuffer = new Point[ HATCH_MAXPOINTS ];
Point aPt1, aPt2, aEndPt1;
Size aInc;
// Single hatch
aRect.Left() -= nLogPixelWidth; aRect.Top() -= nLogPixelWidth; aRect.Right() += nLogPixelWidth; aRect.Bottom() += nLogPixelWidth;
ImplCalcHatchValues( aRect, nWidth, rHatch.GetAngle(), aPt1, aPt2, aInc, aEndPt1 );
do do
{ {
ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer, bMtf ); ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer, bMtf );
@@ -1118,10 +1117,36 @@ void OutputDevice::ImplDrawHatch( const PolyPolygon& rPolyPoly, const Hatch& rHa
aPt2.X() += aInc.Width(); aPt2.Y() += aInc.Height(); aPt2.X() += aInc.Width(); aPt2.Y() += aInc.Height();
} }
while( ( aPt1.X() <= aEndPt1.X() ) && ( aPt1.Y() <= aEndPt1.Y() ) ); while( ( aPt1.X() <= aEndPt1.X() ) && ( aPt1.Y() <= aEndPt1.Y() ) );
if( ( rHatch.GetStyle() == HATCH_DOUBLE ) || ( rHatch.GetStyle() == HATCH_TRIPLE ) )
{
// Double hatch
ImplCalcHatchValues( aRect, nWidth, rHatch.GetAngle() + 900, aPt1, aPt2, aInc, aEndPt1 );
do
{
ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer, bMtf );
aPt1.X() += aInc.Width(); aPt1.Y() += aInc.Height();
aPt2.X() += aInc.Width(); aPt2.Y() += aInc.Height();
}
while( ( aPt1.X() <= aEndPt1.X() ) && ( aPt1.Y() <= aEndPt1.Y() ) );
if( rHatch.GetStyle() == HATCH_TRIPLE )
{
// Triple hatch
ImplCalcHatchValues( aRect, nWidth, rHatch.GetAngle() + 450, aPt1, aPt2, aInc, aEndPt1 );
do
{
ImplDrawHatchLine( Line( aPt1, aPt2 ), rPolyPoly, pPtBuffer, bMtf );
aPt1.X() += aInc.Width(); aPt1.Y() += aInc.Height();
aPt2.X() += aInc.Width(); aPt2.Y() += aInc.Height();
}
while( ( aPt1.X() <= aEndPt1.X() ) && ( aPt1.Y() <= aEndPt1.Y() ) );
}
}
delete[] pPtBuffer;
} }
} }
delete[] pPtBuffer;
} }
void OutputDevice::ImplCalcHatchValues( const Rectangle& rRect, long nDist, sal_uInt16 nAngle10, void OutputDevice::ImplCalcHatchValues( const Rectangle& rRect, long nDist, sal_uInt16 nAngle10,