Fix dxcanvas gradient glitches
* moved common gradient step size code out to canvastools to share * reverted back to manual polygon rendering for anisotrophic rect and ellipse gradients * fixed tilemode==none case for bitmap fills
This commit is contained in:
13
canvas/inc/canvas/canvastools.hxx
Normal file → Executable file
13
canvas/inc/canvas/canvastools.hxx
Normal file → Executable file
@@ -69,6 +69,7 @@ namespace com { namespace sun { namespace star { namespace rendering
|
|||||||
struct ViewState;
|
struct ViewState;
|
||||||
struct IntegerBitmapLayout;
|
struct IntegerBitmapLayout;
|
||||||
class XCanvas;
|
class XCanvas;
|
||||||
|
struct Texture;
|
||||||
class XIntegerBitmapColorSpace;
|
class XIntegerBitmapColorSpace;
|
||||||
class XPolyPolygon2D;
|
class XPolyPolygon2D;
|
||||||
|
|
||||||
@@ -499,6 +500,18 @@ namespace canvas
|
|||||||
*/
|
*/
|
||||||
::basegfx::B2DPolyPolygon getBoundMarksPolyPolygon( const ::basegfx::B2DRange& rRange );
|
::basegfx::B2DPolyPolygon getBoundMarksPolyPolygon( const ::basegfx::B2DRange& rRange );
|
||||||
|
|
||||||
|
/** Calculate number of gradient "strips" to generate (takes
|
||||||
|
into account device resolution)
|
||||||
|
|
||||||
|
@param nColorSteps
|
||||||
|
Maximal integer difference between all color stops, needed
|
||||||
|
for smooth gradient color differences
|
||||||
|
*/
|
||||||
|
int calcGradientStepCount( ::basegfx::B2DHomMatrix& rTotalTransform,
|
||||||
|
const ::com::sun::star::rendering::ViewState& viewState,
|
||||||
|
const ::com::sun::star::rendering::RenderState& renderState,
|
||||||
|
const ::com::sun::star::rendering::Texture& texture,
|
||||||
|
int nColorSteps );
|
||||||
|
|
||||||
/** A very simplistic map for ASCII strings and arbitrary value
|
/** A very simplistic map for ASCII strings and arbitrary value
|
||||||
types.
|
types.
|
||||||
|
@@ -41,6 +41,7 @@
|
|||||||
#include <basegfx/point/b2dpoint.hxx>
|
#include <basegfx/point/b2dpoint.hxx>
|
||||||
#include <basegfx/range/b2drectangle.hxx>
|
#include <basegfx/range/b2drectangle.hxx>
|
||||||
#include <basegfx/numeric/ftools.hxx>
|
#include <basegfx/numeric/ftools.hxx>
|
||||||
|
#include <basegfx/polygon/b2dpolygontools.hxx>
|
||||||
#include <basegfx/tools/tools.hxx>
|
#include <basegfx/tools/tools.hxx>
|
||||||
#include <basegfx/tools/lerp.hxx>
|
#include <basegfx/tools/lerp.hxx>
|
||||||
#include <basegfx/tools/keystoplerp.hxx>
|
#include <basegfx/tools/keystoplerp.hxx>
|
||||||
@@ -67,7 +68,7 @@ namespace dxcanvas
|
|||||||
typedef ::boost::shared_ptr< Gdiplus::PathGradientBrush > PathGradientBrushSharedPtr;
|
typedef ::boost::shared_ptr< Gdiplus::PathGradientBrush > PathGradientBrushSharedPtr;
|
||||||
|
|
||||||
bool fillLinearGradient( GraphicsSharedPtr& rGraphics,
|
bool fillLinearGradient( GraphicsSharedPtr& rGraphics,
|
||||||
const ::canvas::ParametricPolyPolygon::Values& rValues,
|
const ::canvas::ParametricPolyPolygon::Values& /*rValues*/,
|
||||||
const std::vector< Gdiplus::Color >& rColors,
|
const std::vector< Gdiplus::Color >& rColors,
|
||||||
const std::vector< Gdiplus::REAL >& rStops,
|
const std::vector< Gdiplus::REAL >& rStops,
|
||||||
const GraphicsPathSharedPtr& rFillPath,
|
const GraphicsPathSharedPtr& rFillPath,
|
||||||
@@ -214,23 +215,14 @@ namespace dxcanvas
|
|||||||
const std::vector< Gdiplus::REAL >& rStops,
|
const std::vector< Gdiplus::REAL >& rStops,
|
||||||
GraphicsSharedPtr& rGraphics,
|
GraphicsSharedPtr& rGraphics,
|
||||||
const GraphicsPathSharedPtr& rPath,
|
const GraphicsPathSharedPtr& rPath,
|
||||||
|
const rendering::ViewState& viewState,
|
||||||
|
const rendering::RenderState& renderState,
|
||||||
const rendering::Texture& texture )
|
const rendering::Texture& texture )
|
||||||
{
|
{
|
||||||
Gdiplus::Matrix aMatrix;
|
|
||||||
tools::gdiPlusMatrixFromAffineMatrix2D( aMatrix,
|
|
||||||
texture.AffineTransform );
|
|
||||||
|
|
||||||
// copy original fill path object, might have to change it
|
// copy original fill path object, might have to change it
|
||||||
// below
|
// below
|
||||||
GraphicsPathSharedPtr pFillPath( rPath );
|
GraphicsPathSharedPtr pFillPath( rPath );
|
||||||
|
const ::basegfx::B2DPolygon& rGradientPoly( rValues.maGradientPoly );
|
||||||
// clone original gradient path object, we need to change it
|
|
||||||
// below
|
|
||||||
GraphicsPathSharedPtr pGradientPath(
|
|
||||||
tools::graphicsPathFromB2DPolygon( rValues.maGradientPoly ) );
|
|
||||||
|
|
||||||
ENSURE_OR_RETURN( pGradientPath.get(),
|
|
||||||
"ParametricPolyPolygon::fillPolygonalGradient(): Could not clone path" );
|
|
||||||
|
|
||||||
PathGradientBrushSharedPtr pGradientBrush;
|
PathGradientBrushSharedPtr pGradientBrush;
|
||||||
|
|
||||||
@@ -264,8 +256,6 @@ namespace dxcanvas
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
rGraphics->MultiplyTransform( &aMatrix );
|
|
||||||
|
|
||||||
// disable anti-aliasing, if any
|
// disable anti-aliasing, if any
|
||||||
const Gdiplus::SmoothingMode eOldAAMode( rGraphics->GetSmoothingMode() );
|
const Gdiplus::SmoothingMode eOldAAMode( rGraphics->GetSmoothingMode() );
|
||||||
rGraphics->SetSmoothingMode( Gdiplus::SmoothingModeHighSpeed );
|
rGraphics->SetSmoothingMode( Gdiplus::SmoothingModeHighSpeed );
|
||||||
@@ -278,50 +268,80 @@ namespace dxcanvas
|
|||||||
int nColorSteps = 0;
|
int nColorSteps = 0;
|
||||||
for( size_t i=0; i<rColors.size()-1; ++i )
|
for( size_t i=0; i<rColors.size()-1; ++i )
|
||||||
nColorSteps += numColorSteps(rColors[i],rColors[i+1]);
|
nColorSteps += numColorSteps(rColors[i],rColors[i+1]);
|
||||||
|
::basegfx::B2DHomMatrix aTotalTransform;
|
||||||
|
const int nStepCount=
|
||||||
|
::canvas::tools::calcGradientStepCount(aTotalTransform,
|
||||||
|
viewState,
|
||||||
|
renderState,
|
||||||
|
texture,
|
||||||
|
nColorSteps);
|
||||||
|
|
||||||
Gdiplus::Matrix aWorldTransformMatrix;
|
::basegfx::B2DHomMatrix aTextureTransform;
|
||||||
rGraphics->GetTransform( &aWorldTransformMatrix );
|
::basegfx::unotools::homMatrixFromAffineMatrix( aTextureTransform,
|
||||||
|
texture.AffineTransform );
|
||||||
|
// determine overall transformation for inner polygon (might
|
||||||
|
// have to be prefixed by anisotrophic scaling)
|
||||||
|
::basegfx::B2DHomMatrix aInnerPolygonTransformMatrix;
|
||||||
|
|
||||||
Gdiplus::RectF aBounds;
|
// For performance reasons, we create a temporary VCL polygon
|
||||||
pGradientPath->GetBounds( &aBounds, &aWorldTransformMatrix, NULL );
|
// here, keep it all the way and only change the vertex values
|
||||||
|
// in the loop below (as ::Polygon is a pimpl class, creating
|
||||||
|
// one every loop turn would really stress the mem allocator)
|
||||||
|
::basegfx::B2DPolygon aOuterPoly( rGradientPoly );
|
||||||
|
::basegfx::B2DPolygon aInnerPoly;
|
||||||
|
|
||||||
// longest line in gradient bound rect
|
// subdivide polygon _before_ rendering, would otherwise have
|
||||||
const int nGradientSize(
|
// to be performed on every loop turn.
|
||||||
static_cast<int>( hypot( aBounds.Width, aBounds.Height ) + 1.0 ) );
|
if( aOuterPoly.areControlPointsUsed() )
|
||||||
|
aOuterPoly = ::basegfx::tools::adaptiveSubdivideByAngle(aOuterPoly);
|
||||||
|
|
||||||
// typical number for pixel of the same color (strip size)
|
aInnerPoly = aOuterPoly;
|
||||||
const int nStripSize( nGradientSize < 50 ? 2 : 4 );
|
aOuterPoly.transform(aTextureTransform);
|
||||||
|
|
||||||
// use at least three steps, and at utmost the number of color
|
|
||||||
// steps
|
|
||||||
const int nStepCount(
|
|
||||||
::std::max(
|
|
||||||
3,
|
|
||||||
::std::min(
|
|
||||||
nGradientSize / nStripSize,
|
|
||||||
nColorSteps ) ) );
|
|
||||||
|
|
||||||
Gdiplus::SolidBrush aFillBrush( rColors[0] );
|
// apply scaling (possibly anisotrophic) to inner polygon
|
||||||
Gdiplus::Matrix aGDIScaleMatrix;
|
// ------------------------------------------------------
|
||||||
::basegfx::B2DHomMatrix aScaleMatrix;
|
|
||||||
|
|
||||||
// calc relative size for anisotrophic polygon scaling:
|
// scale inner polygon according to aspect ratio: for
|
||||||
// when the aspect ratio is e.g. 2.0, that denotes a
|
// wider-than-tall bounds (nAspectRatio > 1.0), the inner
|
||||||
// gradient which is twice as wide as high. Then, to
|
// polygon, representing the gradient focus, must have
|
||||||
// generate a symmetric gradient, the x direction is only
|
// non-zero width. Specifically, a bound rect twice as wide as
|
||||||
// scaled to 0.5 times the gradient width. Similarly, when
|
// tall has a focus polygon of half it's width.
|
||||||
// the aspect ratio is 4.0, the focus has 3/4 the width of
|
const double nAspectRatio( rValues.mnAspectRatio );
|
||||||
// the overall gradient.
|
if( nAspectRatio > 1.0 )
|
||||||
const double nRelativeFocusSize( rValues.mnAspectRatio > 1.0 ?
|
{
|
||||||
1.0 - 1.0/rValues.mnAspectRatio :
|
// width > height case
|
||||||
1.0 - rValues.mnAspectRatio );
|
aInnerPolygonTransformMatrix.scale( 1.0 - 1.0/nAspectRatio,
|
||||||
|
0.0 );
|
||||||
|
}
|
||||||
|
else if( nAspectRatio < 1.0 )
|
||||||
|
{
|
||||||
|
// width < height case
|
||||||
|
aInnerPolygonTransformMatrix.scale( 0.0,
|
||||||
|
1.0 - nAspectRatio );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// isotrophic case
|
||||||
|
aInnerPolygonTransformMatrix.scale( 0.0, 0.0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// and finally, add texture transform to it.
|
||||||
|
aInnerPolygonTransformMatrix *= aTextureTransform;
|
||||||
|
|
||||||
|
// apply final matrix to polygon
|
||||||
|
aInnerPoly.transform( aInnerPolygonTransformMatrix );
|
||||||
|
|
||||||
|
Gdiplus::GraphicsPath aCurrPath;
|
||||||
|
Gdiplus::SolidBrush aFillBrush( rColors[0] );
|
||||||
|
const sal_uInt32 nNumPoints( aOuterPoly.count() );
|
||||||
basegfx::tools::KeyStopLerp aLerper(rValues.maStops);
|
basegfx::tools::KeyStopLerp aLerper(rValues.maStops);
|
||||||
for( int i=1; i<nStepCount; ++i )
|
for( int i=1; i<nStepCount; ++i )
|
||||||
{
|
{
|
||||||
std::ptrdiff_t nIndex;
|
std::ptrdiff_t nIndex;
|
||||||
double fAlpha;
|
double fAlpha;
|
||||||
boost::tuples::tie(nIndex,fAlpha)=aLerper.lerp(double(i)/nStepCount);
|
const double fT( i/double(nStepCount) );
|
||||||
|
boost::tuples::tie(nIndex,fAlpha)=aLerper.lerp(fT);
|
||||||
|
|
||||||
const Gdiplus::Color aFillColor(
|
const Gdiplus::Color aFillColor(
|
||||||
static_cast<BYTE>( basegfx::tools::lerp(rColors[nIndex].GetRed(),rColors[nIndex+1].GetRed(),fAlpha) ),
|
static_cast<BYTE>( basegfx::tools::lerp(rColors[nIndex].GetRed(),rColors[nIndex+1].GetRed(),fAlpha) ),
|
||||||
@@ -329,45 +349,23 @@ namespace dxcanvas
|
|||||||
static_cast<BYTE>( basegfx::tools::lerp(rColors[nIndex].GetBlue(),rColors[nIndex+1].GetBlue(),fAlpha) ) );
|
static_cast<BYTE>( basegfx::tools::lerp(rColors[nIndex].GetBlue(),rColors[nIndex+1].GetBlue(),fAlpha) ) );
|
||||||
|
|
||||||
aFillBrush.SetColor( aFillColor );
|
aFillBrush.SetColor( aFillColor );
|
||||||
|
aCurrPath.Reset(); aCurrPath.StartFigure();
|
||||||
const double nCurrScale( (nStepCount-i)/(double)nStepCount );
|
for( unsigned int p=1; p<nNumPoints; ++p )
|
||||||
aScaleMatrix = basegfx::tools::createTranslateB2DHomMatrix(-0.5, -0.5);
|
|
||||||
|
|
||||||
// handle anisotrophic polygon scaling
|
|
||||||
if( rValues.mnAspectRatio < 1.0 )
|
|
||||||
{
|
{
|
||||||
// height > width case
|
const ::basegfx::B2DPoint& rOuterPoint1( aOuterPoly.getB2DPoint(p-1) );
|
||||||
aScaleMatrix.scale( nCurrScale,
|
const ::basegfx::B2DPoint& rInnerPoint1( aInnerPoly.getB2DPoint(p-1) );
|
||||||
// lerp with nCurrScale
|
const ::basegfx::B2DPoint& rOuterPoint2( aOuterPoly.getB2DPoint(p) );
|
||||||
// between 1.0 and
|
const ::basegfx::B2DPoint& rInnerPoint2( aInnerPoly.getB2DPoint(p) );
|
||||||
// relative focus height
|
|
||||||
nCurrScale + (1.0-nCurrScale)*nRelativeFocusSize );
|
aCurrPath.AddLine(
|
||||||
}
|
Gdiplus::REAL(fT*rInnerPoint1.getX() + (1-fT)*rOuterPoint1.getX()),
|
||||||
else if( rValues.mnAspectRatio > 1.0 )
|
Gdiplus::REAL(fT*rInnerPoint1.getY() + (1-fT)*rOuterPoint1.getY()),
|
||||||
{
|
Gdiplus::REAL(fT*rInnerPoint2.getX() + (1-fT)*rOuterPoint2.getX()),
|
||||||
// width > height case
|
Gdiplus::REAL(fT*rInnerPoint2.getY() + (1-fT)*rOuterPoint2.getY()));
|
||||||
aScaleMatrix.scale( nCurrScale + (1.0-nCurrScale)*nRelativeFocusSize,
|
|
||||||
// lerp with nCurrScale
|
|
||||||
// between 1.0 and
|
|
||||||
// relative focus width
|
|
||||||
nCurrScale );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
aScaleMatrix.scale( nCurrScale,
|
|
||||||
nCurrScale );
|
|
||||||
}
|
}
|
||||||
|
aCurrPath.CloseFigure();
|
||||||
|
|
||||||
aScaleMatrix.translate( 0.5, 0.5 );
|
rGraphics->FillPath( &aFillBrush, &aCurrPath );
|
||||||
|
|
||||||
tools::gdiPlusMatrixFromB2DHomMatrix( aGDIScaleMatrix,
|
|
||||||
aScaleMatrix );
|
|
||||||
|
|
||||||
GraphicsPathSharedPtr pScaledGradientPath(
|
|
||||||
tools::graphicsPathFromB2DPolygon( rValues.maGradientPoly ) );
|
|
||||||
pScaledGradientPath->Transform( &aGDIScaleMatrix );
|
|
||||||
|
|
||||||
rGraphics->FillPath( &aFillBrush, pScaledGradientPath.get() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset to old anti-alias mode
|
// reset to old anti-alias mode
|
||||||
@@ -388,6 +386,11 @@ namespace dxcanvas
|
|||||||
// one sets both, only the translational components of the
|
// one sets both, only the translational components of the
|
||||||
// texture is respected.
|
// texture is respected.
|
||||||
|
|
||||||
|
Gdiplus::Matrix aMatrix;
|
||||||
|
tools::gdiPlusMatrixFromAffineMatrix2D( aMatrix,
|
||||||
|
texture.AffineTransform );
|
||||||
|
GraphicsPathSharedPtr pGradientPath(
|
||||||
|
tools::graphicsPathFromB2DPolygon( rValues.maGradientPoly ));
|
||||||
pGradientPath->Transform( &aMatrix );
|
pGradientPath->Transform( &aMatrix );
|
||||||
|
|
||||||
pGradientBrush.reset(
|
pGradientBrush.reset(
|
||||||
@@ -400,7 +403,7 @@ namespace dxcanvas
|
|||||||
// gradients are by default the _centroid_ of the path
|
// gradients are by default the _centroid_ of the path
|
||||||
// (i.e. the weighted sum of edge points), it will not
|
// (i.e. the weighted sum of edge points), it will not
|
||||||
// necessarily coincide with our notion of center.
|
// necessarily coincide with our notion of center.
|
||||||
Gdiplus::PointF aCenterPoint(0.5, 0.5);
|
Gdiplus::PointF aCenterPoint(0, 0);
|
||||||
aMatrix.TransformPoints( &aCenterPoint );
|
aMatrix.TransformPoints( &aCenterPoint );
|
||||||
pGradientBrush->SetCenterPoint( aCenterPoint );
|
pGradientBrush->SetCenterPoint( aCenterPoint );
|
||||||
|
|
||||||
@@ -440,6 +443,8 @@ namespace dxcanvas
|
|||||||
const std::vector< Gdiplus::REAL >& rStops,
|
const std::vector< Gdiplus::REAL >& rStops,
|
||||||
GraphicsSharedPtr& rGraphics,
|
GraphicsSharedPtr& rGraphics,
|
||||||
const GraphicsPathSharedPtr& rPath,
|
const GraphicsPathSharedPtr& rPath,
|
||||||
|
const rendering::ViewState& viewState,
|
||||||
|
const rendering::RenderState& renderState,
|
||||||
const rendering::Texture& texture )
|
const rendering::Texture& texture )
|
||||||
{
|
{
|
||||||
switch( rValues.meType )
|
switch( rValues.meType )
|
||||||
@@ -461,6 +466,8 @@ namespace dxcanvas
|
|||||||
rStops,
|
rStops,
|
||||||
rGraphics,
|
rGraphics,
|
||||||
rPath,
|
rPath,
|
||||||
|
viewState,
|
||||||
|
renderState,
|
||||||
texture );
|
texture );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -486,8 +493,8 @@ namespace dxcanvas
|
|||||||
|
|
||||||
const geometry::IntegerSize2D aBmpSize( xBitmap->getSize() );
|
const geometry::IntegerSize2D aBmpSize( xBitmap->getSize() );
|
||||||
ENSURE_ARG_OR_THROW( aBmpSize.Width != 0 &&
|
ENSURE_ARG_OR_THROW( aBmpSize.Width != 0 &&
|
||||||
aBmpSize.Height != 0,
|
aBmpSize.Height != 0,
|
||||||
"CanvasHelper::fillBitmap(): zero-sized texture bitmap" );
|
"CanvasHelper::fillBitmap(): zero-sized texture bitmap" );
|
||||||
|
|
||||||
// TODO(P3): Detect case that path is rectangle and
|
// TODO(P3): Detect case that path is rectangle and
|
||||||
// bitmap is just scaled into that. Then, we can
|
// bitmap is just scaled into that. Then, we can
|
||||||
@@ -499,7 +506,6 @@ namespace dxcanvas
|
|||||||
tools::bitmapFromXBitmap( xBitmap ) );
|
tools::bitmapFromXBitmap( xBitmap ) );
|
||||||
|
|
||||||
TextureBrushSharedPtr pBrush;
|
TextureBrushSharedPtr pBrush;
|
||||||
|
|
||||||
if( ::rtl::math::approxEqual( rTexture.Alpha,
|
if( ::rtl::math::approxEqual( rTexture.Alpha,
|
||||||
1.0 ) )
|
1.0 ) )
|
||||||
{
|
{
|
||||||
@@ -537,9 +543,9 @@ namespace dxcanvas
|
|||||||
|
|
||||||
// scale down bitmap to [0,1]x[0,1] rect, as required
|
// scale down bitmap to [0,1]x[0,1] rect, as required
|
||||||
// from the XCanvas interface.
|
// from the XCanvas interface.
|
||||||
|
pBrush->MultiplyTransform( &aTextureTransform );
|
||||||
pBrush->ScaleTransform( static_cast< Gdiplus::REAL >(1.0/aBmpSize.Width),
|
pBrush->ScaleTransform( static_cast< Gdiplus::REAL >(1.0/aBmpSize.Width),
|
||||||
static_cast< Gdiplus::REAL >(1.0/aBmpSize.Height) );
|
static_cast< Gdiplus::REAL >(1.0/aBmpSize.Height) );
|
||||||
pBrush->MultiplyTransform( &aTextureTransform );
|
|
||||||
|
|
||||||
// TODO(F1): FillRule
|
// TODO(F1): FillRule
|
||||||
ENSURE_OR_THROW(
|
ENSURE_OR_THROW(
|
||||||
@@ -602,6 +608,8 @@ namespace dxcanvas
|
|||||||
aStops,
|
aStops,
|
||||||
pGraphics,
|
pGraphics,
|
||||||
tools::graphicsPathFromXPolyPolygon2D( xPolyPolygon ),
|
tools::graphicsPathFromXPolyPolygon2D( xPolyPolygon ),
|
||||||
|
viewState,
|
||||||
|
renderState,
|
||||||
textures[0] );
|
textures[0] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -199,7 +199,7 @@ namespace dxcanvas
|
|||||||
{
|
{
|
||||||
const sal_uInt32 nPoints( rPoly.count() );
|
const sal_uInt32 nPoints( rPoly.count() );
|
||||||
|
|
||||||
if( !nPoints )
|
if( nPoints < 2 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rOutput->StartFigure();
|
rOutput->StartFigure();
|
||||||
|
48
canvas/source/tools/canvastools.cxx
Normal file → Executable file
48
canvas/source/tools/canvastools.cxx
Normal file → Executable file
@@ -994,6 +994,54 @@ namespace canvas
|
|||||||
return aPolyPoly;
|
return aPolyPoly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int calcGradientStepCount( ::basegfx::B2DHomMatrix& rTotalTransform,
|
||||||
|
const rendering::ViewState& viewState,
|
||||||
|
const rendering::RenderState& renderState,
|
||||||
|
const rendering::Texture& texture,
|
||||||
|
int nColorSteps )
|
||||||
|
{
|
||||||
|
// calculate overall texture transformation (directly from
|
||||||
|
// texture to device space).
|
||||||
|
::basegfx::B2DHomMatrix aMatrix;
|
||||||
|
|
||||||
|
rTotalTransform.identity();
|
||||||
|
::basegfx::unotools::homMatrixFromAffineMatrix( rTotalTransform,
|
||||||
|
texture.AffineTransform );
|
||||||
|
::canvas::tools::mergeViewAndRenderTransform(aMatrix,
|
||||||
|
viewState,
|
||||||
|
renderState);
|
||||||
|
rTotalTransform *= aMatrix; // prepend total view/render transformation
|
||||||
|
|
||||||
|
// determine size of gradient in device coordinate system
|
||||||
|
// (to e.g. determine sensible number of gradient steps)
|
||||||
|
::basegfx::B2DPoint aLeftTop( 0.0, 0.0 );
|
||||||
|
::basegfx::B2DPoint aLeftBottom( 0.0, 1.0 );
|
||||||
|
::basegfx::B2DPoint aRightTop( 1.0, 0.0 );
|
||||||
|
::basegfx::B2DPoint aRightBottom( 1.0, 1.0 );
|
||||||
|
|
||||||
|
aLeftTop *= rTotalTransform;
|
||||||
|
aLeftBottom *= rTotalTransform;
|
||||||
|
aRightTop *= rTotalTransform;
|
||||||
|
aRightBottom*= rTotalTransform;
|
||||||
|
|
||||||
|
// longest line in gradient bound rect
|
||||||
|
const int nGradientSize(
|
||||||
|
static_cast<int>(
|
||||||
|
::std::max(
|
||||||
|
::basegfx::B2DVector(aRightBottom-aLeftTop).getLength(),
|
||||||
|
::basegfx::B2DVector(aRightTop-aLeftBottom).getLength() ) + 1.0 ) );
|
||||||
|
|
||||||
|
// typical number for pixel of the same color (strip size)
|
||||||
|
const int nStripSize( nGradientSize < 50 ? 2 : 4 );
|
||||||
|
|
||||||
|
// use at least three steps, and at utmost the number of color
|
||||||
|
// steps
|
||||||
|
return ::std::max( 3,
|
||||||
|
::std::min(
|
||||||
|
nGradientSize / nStripSize,
|
||||||
|
nColorSteps ) );
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace tools
|
} // namespace tools
|
||||||
|
|
||||||
} // namespace canvas
|
} // namespace canvas
|
||||||
|
75
canvas/source/vcl/canvashelper_texturefill.cxx
Normal file → Executable file
75
canvas/source/vcl/canvashelper_texturefill.cxx
Normal file → Executable file
@@ -562,62 +562,27 @@ namespace vclcanvas
|
|||||||
// deadlocks, canvashelper calls this method with locked own
|
// deadlocks, canvashelper calls this method with locked own
|
||||||
// mutex.
|
// mutex.
|
||||||
|
|
||||||
// calculate overall texture transformation (directly from
|
|
||||||
// texture to device space).
|
|
||||||
::basegfx::B2DHomMatrix aMatrix;
|
|
||||||
::basegfx::B2DHomMatrix aTextureTransform;
|
|
||||||
|
|
||||||
::basegfx::unotools::homMatrixFromAffineMatrix( aTextureTransform,
|
|
||||||
texture.AffineTransform );
|
|
||||||
::canvas::tools::mergeViewAndRenderTransform(aMatrix,
|
|
||||||
viewState,
|
|
||||||
renderState);
|
|
||||||
aTextureTransform *= aMatrix; // prepend total view/render transformation
|
|
||||||
|
|
||||||
// determine maximal bound rect of gradient-filled polygon
|
|
||||||
const ::Rectangle aPolygonDeviceRectOrig(
|
|
||||||
rPoly.GetBoundRect() );
|
|
||||||
|
|
||||||
// determine size of gradient in device coordinate system
|
|
||||||
// (to e.g. determine sensible number of gradient steps)
|
|
||||||
::basegfx::B2DPoint aLeftTop( 0.0, 0.0 );
|
|
||||||
::basegfx::B2DPoint aLeftBottom( 0.0, 1.0 );
|
|
||||||
::basegfx::B2DPoint aRightTop( 1.0, 0.0 );
|
|
||||||
::basegfx::B2DPoint aRightBottom( 1.0, 1.0 );
|
|
||||||
|
|
||||||
aLeftTop *= aTextureTransform;
|
|
||||||
aLeftBottom *= aTextureTransform;
|
|
||||||
aRightTop *= aTextureTransform;
|
|
||||||
aRightBottom*= aTextureTransform;
|
|
||||||
|
|
||||||
|
|
||||||
// calc step size
|
// calc step size
|
||||||
// --------------
|
// --------------
|
||||||
int nColorSteps = 0;
|
int nColorSteps = 0;
|
||||||
for( size_t i=0; i<rColors.size()-1; ++i )
|
for( size_t i=0; i<rColors.size()-1; ++i )
|
||||||
nColorSteps += numColorSteps(rColors[i],rColors[i+1]);
|
nColorSteps += numColorSteps(rColors[i],rColors[i+1]);
|
||||||
|
|
||||||
// longest line in gradient bound rect
|
::basegfx::B2DHomMatrix aTotalTransform;
|
||||||
const int nGradientSize(
|
const int nStepCount=
|
||||||
static_cast<int>(
|
::canvas::tools::calcGradientStepCount(aTotalTransform,
|
||||||
::std::max(
|
viewState,
|
||||||
::basegfx::B2DVector(aRightBottom-aLeftTop).getLength(),
|
renderState,
|
||||||
::basegfx::B2DVector(aRightTop-aLeftBottom).getLength() ) + 1.0 ) );
|
texture,
|
||||||
|
nColorSteps);
|
||||||
// typical number for pixel of the same color (strip size)
|
|
||||||
const int nStripSize( nGradientSize < 50 ? 2 : 4 );
|
|
||||||
|
|
||||||
// use at least three steps, and at utmost the number of color
|
|
||||||
// steps
|
|
||||||
const int nStepCount(
|
|
||||||
::std::max(
|
|
||||||
3,
|
|
||||||
::std::min(
|
|
||||||
nGradientSize / nStripSize,
|
|
||||||
nColorSteps ) ) );
|
|
||||||
|
|
||||||
rOutDev.SetLineColor();
|
rOutDev.SetLineColor();
|
||||||
|
|
||||||
|
// determine maximal bound rect of texture-filled
|
||||||
|
// polygon
|
||||||
|
const ::Rectangle aPolygonDeviceRectOrig(
|
||||||
|
rPoly.GetBoundRect() );
|
||||||
|
|
||||||
if( tools::isRectangle( rPoly ) )
|
if( tools::isRectangle( rPoly ) )
|
||||||
{
|
{
|
||||||
// use optimized output path
|
// use optimized output path
|
||||||
@@ -635,7 +600,7 @@ namespace vclcanvas
|
|||||||
doGradientFill( rOutDev,
|
doGradientFill( rOutDev,
|
||||||
rValues,
|
rValues,
|
||||||
rColors,
|
rColors,
|
||||||
aTextureTransform,
|
aTotalTransform,
|
||||||
aPolygonDeviceRectOrig,
|
aPolygonDeviceRectOrig,
|
||||||
nStepCount,
|
nStepCount,
|
||||||
false );
|
false );
|
||||||
@@ -648,7 +613,7 @@ namespace vclcanvas
|
|||||||
doGradientFill( *p2ndOutDev,
|
doGradientFill( *p2ndOutDev,
|
||||||
rValues,
|
rValues,
|
||||||
rColors,
|
rColors,
|
||||||
aTextureTransform,
|
aTotalTransform,
|
||||||
aPolygonDeviceRectOrig,
|
aPolygonDeviceRectOrig,
|
||||||
nStepCount,
|
nStepCount,
|
||||||
false );
|
false );
|
||||||
@@ -666,7 +631,7 @@ namespace vclcanvas
|
|||||||
doGradientFill( rOutDev,
|
doGradientFill( rOutDev,
|
||||||
rValues,
|
rValues,
|
||||||
rColors,
|
rColors,
|
||||||
aTextureTransform,
|
aTotalTransform,
|
||||||
aPolygonDeviceRectOrig,
|
aPolygonDeviceRectOrig,
|
||||||
nStepCount,
|
nStepCount,
|
||||||
false );
|
false );
|
||||||
@@ -679,7 +644,7 @@ namespace vclcanvas
|
|||||||
doGradientFill( *p2ndOutDev,
|
doGradientFill( *p2ndOutDev,
|
||||||
rValues,
|
rValues,
|
||||||
rColors,
|
rColors,
|
||||||
aTextureTransform,
|
aTotalTransform,
|
||||||
aPolygonDeviceRectOrig,
|
aPolygonDeviceRectOrig,
|
||||||
nStepCount,
|
nStepCount,
|
||||||
false );
|
false );
|
||||||
@@ -694,7 +659,7 @@ namespace vclcanvas
|
|||||||
doGradientFill( rOutDev,
|
doGradientFill( rOutDev,
|
||||||
rValues,
|
rValues,
|
||||||
rColors,
|
rColors,
|
||||||
aTextureTransform,
|
aTotalTransform,
|
||||||
aPolygonDeviceRectOrig,
|
aPolygonDeviceRectOrig,
|
||||||
nStepCount,
|
nStepCount,
|
||||||
true );
|
true );
|
||||||
@@ -705,7 +670,7 @@ namespace vclcanvas
|
|||||||
doGradientFill( rOutDev,
|
doGradientFill( rOutDev,
|
||||||
rValues,
|
rValues,
|
||||||
rColors,
|
rColors,
|
||||||
aTextureTransform,
|
aTotalTransform,
|
||||||
aPolygonDeviceRectOrig,
|
aPolygonDeviceRectOrig,
|
||||||
nStepCount,
|
nStepCount,
|
||||||
true );
|
true );
|
||||||
@@ -718,7 +683,7 @@ namespace vclcanvas
|
|||||||
doGradientFill( *p2ndOutDev,
|
doGradientFill( *p2ndOutDev,
|
||||||
rValues,
|
rValues,
|
||||||
rColors,
|
rColors,
|
||||||
aTextureTransform,
|
aTotalTransform,
|
||||||
aPolygonDeviceRectOrig,
|
aPolygonDeviceRectOrig,
|
||||||
nStepCount,
|
nStepCount,
|
||||||
true );
|
true );
|
||||||
@@ -729,7 +694,7 @@ namespace vclcanvas
|
|||||||
doGradientFill( *p2ndOutDev,
|
doGradientFill( *p2ndOutDev,
|
||||||
rValues,
|
rValues,
|
||||||
rColors,
|
rColors,
|
||||||
aTextureTransform,
|
aTotalTransform,
|
||||||
aPolygonDeviceRectOrig,
|
aPolygonDeviceRectOrig,
|
||||||
nStepCount,
|
nStepCount,
|
||||||
true );
|
true );
|
||||||
|
Reference in New Issue
Block a user