diff options
author | Armin Le Grand <alg@apache.org> | 2013-05-17 16:29:11 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-06-17 15:39:48 +0100 |
commit | 3a8dbb63197c5b9298015cbd5b15e607ec9a3705 (patch) | |
tree | d7edd0ed73a7d7ebafd449c924bd54ea0aad9065 /svtools | |
parent | 997cc4804d947fdd751e457fda47f95ecf3ac909 (diff) |
Resolves: #i74211# Correct crop of bitmap data when...
logical size and MapMode do not match real pixel size
(cherry picked from commit a24965371f7e881671182bc51432c08cbf667b56)
Conflicts:
svtools/inc/svtools/grfmgr.hxx
svtools/source/graphic/grfmgr.cxx
svx/inc/svx/svdhdl.hxx
svx/inc/svx/svdograf.hxx
svx/source/svdraw/svdhdl.cxx
Change-Id: Icfb9091b55e50081e8daf697c9f00f5b5a10531a
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/graphic/grfmgr.cxx | 107 |
1 files changed, 87 insertions, 20 deletions
diff --git a/svtools/source/graphic/grfmgr.cxx b/svtools/source/graphic/grfmgr.cxx index 136aa578e961..6577c0ef1d89 100644 --- a/svtools/source/graphic/grfmgr.cxx +++ b/svtools/source/graphic/grfmgr.cxx @@ -842,24 +842,53 @@ Graphic GraphicObject::GetTransformedGraphic( const Size& rDestSize, const MapMo } else if( GRAPHIC_BITMAP == eType ) { - BitmapEx aBitmapEx( aTransGraphic.GetBitmapEx() ); - - // convert crops to pixel - aCropLeftTop = Application::GetDefaultDevice()->LogicToPixel( Size( rAttr.GetLeftCrop(), - rAttr.GetTopCrop() ), - aMap100 ); - aCropRightBottom = Application::GetDefaultDevice()->LogicToPixel( Size( rAttr.GetRightCrop(), - rAttr.GetBottomCrop() ), - aMap100 ); + BitmapEx aBitmapEx( aTransGraphic.GetBitmapEx() ); + Rectangle aCropRect; - // convert from prefmapmode to pixel - const Size aSrcSizePixel( Application::GetDefaultDevice()->LogicToPixel( aSrcSize, - aMapGraph ) ); + // convert crops to pixel (crops are always in GraphicObject units) + if(rAttr.IsCropped()) + { + aCropLeftTop = Application::GetDefaultDevice()->LogicToPixel( + Size(rAttr.GetLeftCrop(), rAttr.GetTopCrop()), + aMapGraph); + aCropRightBottom = Application::GetDefaultDevice()->LogicToPixel( + Size(rAttr.GetRightCrop(), rAttr.GetBottomCrop()), + aMapGraph); + + // convert from prefmapmode to pixel + Size aSrcSizePixel( + Application::GetDefaultDevice()->LogicToPixel( + aSrcSize, + aMapGraph)); + + if(rAttr.IsCropped() + && (aSrcSizePixel.Width() != aBitmapEx.GetSizePixel().Width() || aSrcSizePixel.Height() != aBitmapEx.GetSizePixel().Height()) + && aSrcSizePixel.Width()) + { + // the size in pixels calculated from Graphic's internal MapMode (aTransGraphic.GetPrefMapMode()) + // and it's internal size (aTransGraphic.GetPrefSize()) is different from it's real pixel size. + // This can be interpreted as this values to be set wrong, but needs to be corrected since e.g. + // existing cropping is calculated based on this logic values already. + // aBitmapEx.Scale(aSrcSizePixel); + + // another possibility is to adapt the values created so far with a factor; this + // will keep the original Bitmap untouched and thus quality will not change + const double fFactorX(aBitmapEx.GetSizePixel().Width() / aSrcSizePixel.Width()); + const double fFactorY(aBitmapEx.GetSizePixel().Height() / aSrcSizePixel.Height()); + + aCropLeftTop.Width() = basegfx::fround(aCropLeftTop.Width() * fFactorX); + aCropLeftTop.Height() = basegfx::fround(aCropLeftTop.Height() * fFactorY); + aCropRightBottom.Width() = basegfx::fround(aCropRightBottom.Width() * fFactorX); + aCropRightBottom.Height() = basegfx::fround(aCropRightBottom.Height() * fFactorY); + + aSrcSizePixel = aBitmapEx.GetSizePixel(); + } - // setup crop rectangle in pixel - Rectangle aCropRect( aCropLeftTop.Width(), aCropLeftTop.Height(), - aSrcSizePixel.Width() - aCropRightBottom.Width(), - aSrcSizePixel.Height() - aCropRightBottom.Height() ); + // setup crop rectangle in pixel + aCropRect = Rectangle( aCropLeftTop.Width(), aCropLeftTop.Height(), + aSrcSizePixel.Width() - aCropRightBottom.Width(), + aSrcSizePixel.Height() - aCropRightBottom.Height() ); + } // #105641# Also crop animations if( aTransGraphic.IsAnimated() ) @@ -925,12 +954,10 @@ Graphic GraphicObject::GetTransformedGraphic( const Size& rDestSize, const MapMo } else { - BitmapEx aBmpEx( aTransGraphic.GetBitmapEx() ); - - ImplTransformBitmap( aBmpEx, rAttr, aCropLeftTop, aCropRightBottom, + ImplTransformBitmap( aBitmapEx, rAttr, aCropLeftTop, aCropRightBottom, aCropRect, rDestSize, sal_True ); - aTransGraphic = aBmpEx; + aTransGraphic = aBitmapEx; } aTransGraphic.SetPrefSize( rDestSize ); @@ -1175,4 +1202,44 @@ GraphicObject::InspectForGraphicObjectImageURL( const Reference< XInterface >& x } } +// calculate scalings between real image size and logic object size. This +// is necessary since the crop values are relative to original bitmap size +basegfx::B2DVector GraphicObject::calculateCropScaling( + double fWidth, + double fHeight, + double fLeftCrop, + double fTopCrop, + double fRightCrop, + double fBottomCrop) const +{ + const MapMode aMapMode100thmm(MAP_100TH_MM); + Size aBitmapSize(GetPrefSize()); + double fFactorX(1.0); + double fFactorY(1.0); + + if(MAP_PIXEL == GetPrefMapMode().GetMapUnit()) + { + aBitmapSize = Application::GetDefaultDevice()->PixelToLogic(aBitmapSize, aMapMode100thmm); + } + else + { + aBitmapSize = Application::GetDefaultDevice()->LogicToLogic(aBitmapSize, GetPrefMapMode(), aMapMode100thmm); + } + + const double fDivX(aBitmapSize.Width() - fLeftCrop - fRightCrop); + const double fDivY(aBitmapSize.Height() - fTopCrop - fBottomCrop); + + if(!basegfx::fTools::equalZero(fDivX)) + { + fFactorX = fabs(fWidth) / fDivX; + } + + if(!basegfx::fTools::equalZero(fDivY)) + { + fFactorY = fabs(fHeight) / fDivY; + } + + return basegfx::B2DVector(fFactorX,fFactorY); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |