diff options
author | Bartosz Kosiorek <gang65@poczta.onet.pl> | 2019-01-15 15:11:28 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-03-13 08:44:40 +0100 |
commit | ff2223ca4f0cf201e4b0067a5b66340dbfca5929 (patch) | |
tree | 41f471274925fdf923e0b652f76e2ddf5c3f9194 | |
parent | ff248538cbe5a74dbe31049097a0d569b829efa9 (diff) |
tdf#122557 EMF+ Implement proper rotation support of DrawImage
(cherry picked from commit e3ccc09417731e61d3d35ed4cc1a7436e05f5325)
Conflicts:
drawinglayer/source/tools/emfpbrush.hxx
drawinglayer/source/tools/emfphelperdata.cxx
drawinglayer/source/tools/emfphelperdata.hxx
drawinglayer/source/tools/emfpregion.cxx
Change-Id: I2c32a47fac06b2026d61a0f369e6d569c9f57502
-rw-r--r-- | cppcanvas/source/mtfrenderer/bitmapaction.cxx | 50 | ||||
-rw-r--r-- | cppcanvas/source/mtfrenderer/bitmapaction.hxx | 4 | ||||
-rw-r--r-- | cppcanvas/source/mtfrenderer/emfplus.cxx | 17 |
3 files changed, 65 insertions, 6 deletions
diff --git a/cppcanvas/source/mtfrenderer/bitmapaction.cxx b/cppcanvas/source/mtfrenderer/bitmapaction.cxx index 2777abb7e24c..53fc44992a88 100644 --- a/cppcanvas/source/mtfrenderer/bitmapaction.cxx +++ b/cppcanvas/source/mtfrenderer/bitmapaction.cxx @@ -58,6 +58,10 @@ namespace cppcanvas const ::basegfx::B2DVector& rDstSize, const CanvasSharedPtr&, const OutDevState& ); + BitmapAction( const ::BitmapEx&, + const ::basegfx::B2DHomMatrix& rTransform, + const CanvasSharedPtr&, + const OutDevState& ); virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation, const Subset& rSubset ) const override; @@ -139,6 +143,41 @@ namespace cppcanvas nullptr ); } + BitmapAction::BitmapAction( const ::BitmapEx& rBmpEx, + const ::basegfx::B2DHomMatrix& rDstTransform, + const CanvasSharedPtr& rCanvas, + const OutDevState& rState ) : + CachedPrimitiveBase( rCanvas, true ), + mxBitmap( vcl::unotools::xBitmapFromBitmapEx( rCanvas->getUNOCanvas()->getDevice(), + rBmpEx ) ), + mpCanvas( rCanvas ), + maState() + { + tools::initRenderState(maState,rState); + + // Setup transformation such that the next render call is + // moved rPoint away, and scaled according to the ratio + // given by src and dst size. + const ::Size aBmpSize( rBmpEx.GetSizePixel() ); + + basegfx::B2DVector aDstScale, aDstTranslate; + double fDstRotate, fDstShearX; + rDstTransform.decompose(aDstScale, aDstTranslate, fDstRotate, fDstShearX); + const ::basegfx::B2DVector aScale( aDstScale.getX() / aBmpSize.Width(), + aDstScale.getY() / aBmpSize.Height() ); + const basegfx::B2DHomMatrix aLocalTransformation(basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix( + aScale, fDstShearX, -fDstRotate, aDstTranslate)); + ::canvas::tools::appendToRenderState( maState, aLocalTransformation ); + + // correct clip (which is relative to original transform) + tools::modifyClip( maState, + rState, + rCanvas, + aDstTranslate, + &aScale, + nullptr ); + } + bool BitmapAction::renderPrimitive( uno::Reference< rendering::XCachedPrimitive >& rCachedPrimitive, const ::basegfx::B2DHomMatrix& rTransformation ) const { @@ -222,6 +261,17 @@ namespace cppcanvas rCanvas, rState ) ); } + + ActionSharedPtr BitmapActionFactory::createBitmapAction( const ::BitmapEx& rBmpEx, + const ::basegfx::B2DHomMatrix& rTransform, + const CanvasSharedPtr& rCanvas, + const OutDevState& rState ) + { + return ActionSharedPtr( new BitmapAction(rBmpEx, + rTransform, + rCanvas, + rState ) ); + } } } diff --git a/cppcanvas/source/mtfrenderer/bitmapaction.hxx b/cppcanvas/source/mtfrenderer/bitmapaction.hxx index d028828c32fe..a3f8db1d1f12 100644 --- a/cppcanvas/source/mtfrenderer/bitmapaction.hxx +++ b/cppcanvas/source/mtfrenderer/bitmapaction.hxx @@ -58,6 +58,10 @@ namespace cppcanvas const ::basegfx::B2DVector& rDstSize, const CanvasSharedPtr&, const OutDevState& ); + ActionSharedPtr createBitmapAction( const ::BitmapEx&, + const ::basegfx::B2DHomMatrix& rDstTransform, + const CanvasSharedPtr&, + const OutDevState& ); } } } diff --git a/cppcanvas/source/mtfrenderer/emfplus.cxx b/cppcanvas/source/mtfrenderer/emfplus.cxx index 736e181dcbfe..00ca97a2d10c 100644 --- a/cppcanvas/source/mtfrenderer/emfplus.cxx +++ b/cppcanvas/source/mtfrenderer/emfplus.cxx @@ -57,6 +57,7 @@ #include <emfppen.hxx> #include <emfpregion.hxx> #include <emfpstringformat.hxx> +#include <basegfx/matrix/b2dhommatrixtools.hxx> namespace { @@ -1216,8 +1217,8 @@ namespace cppcanvas SAL_INFO("cppcanvas.emf", "EMF+ destination points: " << x1 << "," << y1 << " " << x2 << "," << y2 << " " << x3 << "," << y3); SAL_INFO("cppcanvas.emf", "EMF+ destination rectangle: " << x1 << "," << y1 << " " << x2 - x1 << "x" << y3 - y1); - aDstPoint = Map (x1, y1); - aDstSize = MapSize(x2 - x1, y3 - y1); + aDstPoint = basegfx::B2DVector(x1, y1); + aDstSize = basegfx::B2DVector(x2 - x1, y3 - y1); bValid = true; } @@ -1228,8 +1229,8 @@ namespace cppcanvas SAL_INFO("cppcanvas.emf", "EMF+ destination rectangle: " << dx << "," << dy << " " << dw << "x" << dh); - aDstPoint = Map (dx, dy); - aDstSize = MapSize(dw, dh); + aDstPoint = basegfx::B2DVector(dx, dy); + aDstSize = basegfx::B2DVector(dw, dh); bValid = true; } @@ -1241,11 +1242,15 @@ namespace cppcanvas Size aSize( aBmp.GetSizePixel() ); SAL_INFO("cppcanvas.emf", "EMF+ bitmap size: " << aSize.Width() << "x" << aSize.Height()); if( aSize.Width() > 0 && aSize.Height() > 0 ) { + basegfx::B2DHomMatrix aTransform(aWorldTransform.eM11, aWorldTransform.eM12, aWorldTransform.eDx, aWorldTransform.eM21, aWorldTransform.eM22, aWorldTransform.eDy); + aTransform.scale(100.0 * nMmX / nPixX, 100.0 * nMmY / nPixY); + aTransform.translate(-nFrameLeft, -nFrameTop); + aTransform *= basegfx::B2DHomMatrix(aBaseTransform.eM11, aBaseTransform.eM12, aBaseTransform.eDx, aBaseTransform.eM21, aBaseTransform.eM22, aBaseTransform.eDy); + aTransform = aTransform * basegfx::tools::createScaleTranslateB2DHomMatrix(aDstSize, aDstPoint); ActionSharedPtr pBmpAction ( internal::BitmapActionFactory::createBitmapAction ( aBmp, - rState.mapModeTransform * aDstPoint, - rState.mapModeTransform * aDstSize, + rState.mapModeTransform * aTransform, rCanvas, rState)); |