diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2019-05-06 11:33:41 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2019-05-08 12:42:53 +0200 |
commit | d0119ff7f2c68aa05286bd303128f3a69c6bbd6a (patch) | |
tree | 80fc2e52ceb8446997348eda9186cbdfcd247298 /vcl | |
parent | 5218ca22b472a80969a715e38d7cb8d052be4b6a (diff) |
improve tools::Rectangle->basegfx::B2?Rectangle conversion
Improve the conversion method to do something reasonable with
empty Rectangle.
Use the conversion method in more places.
Change-Id: I48c13f3d6dae71f39f03f7939101e545c8125503
Reviewed-on: https://gerrit.libreoffice.org/71853
Tested-by: Jenkins
Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/gdi/gdimetafiletools.cxx | 17 | ||||
-rw-r--r-- | vcl/source/gdi/pdfextoutdevdata.cxx | 4 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 3 | ||||
-rw-r--r-- | vcl/source/gdi/region.cxx | 11 | ||||
-rw-r--r-- | vcl/source/helper/canvastools.cxx | 22 | ||||
-rw-r--r-- | vcl/source/outdev/bitmap.cxx | 15 |
6 files changed, 37 insertions, 35 deletions
diff --git a/vcl/source/gdi/gdimetafiletools.cxx b/vcl/source/gdi/gdimetafiletools.cxx index 14a5492e36c3..d545d2f9eba3 100644 --- a/vcl/source/gdi/gdimetafiletools.cxx +++ b/vcl/source/gdi/gdimetafiletools.cxx @@ -19,6 +19,7 @@ #include <vcl/gdimetafiletools.hxx> #include <vcl/metaact.hxx> +#include <vcl/canvastools.hxx> #include <basegfx/polygon/b2dpolygonclipper.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx> #include <basegfx/polygon/b2dpolypolygontools.hxx> @@ -319,9 +320,7 @@ void clipMetafileContentAgainstOwnRegions(GDIMetaFile& rSource) if(!rRect.IsEmpty() && !aClips.empty() && aClips.back().count()) { - const basegfx::B2DRange aClipRange( - rRect.Left(), rRect.Top(), - rRect.Right(), rRect.Bottom()); + const basegfx::B2DRange aClipRange(vcl::unotools::b2DRectangleFromRectangle(rRect)); aClips.back() = basegfx::utils::clipPolyPolygonOnRange( aClips.back(), @@ -516,9 +515,7 @@ void clipMetafileContentAgainstOwnRegions(GDIMetaFile& rSource) aClips.back(), basegfx::B2DPolyPolygon( basegfx::utils::createPolygonFromRect( - basegfx::B2DRange( - rRect.Left(), rRect.Top(), - rRect.Right(), rRect.Bottom()))), + vcl::unotools::b2DRectangleFromRectangle(rRect))), aTarget, false); // stroke } @@ -538,7 +535,7 @@ void clipMetafileContentAgainstOwnRegions(GDIMetaFile& rSource) { const sal_uInt32 nHor(pA->GetHorzRound()); const sal_uInt32 nVer(pA->GetVertRound()); - const basegfx::B2DRange aRange(rRect.Left(), rRect.Top(), rRect.Right(), rRect.Bottom()); + const basegfx::B2DRange aRange(vcl::unotools::b2DRectangleFromRectangle(rRect)); basegfx::B2DPolygon aOutline; if(nHor || nVer) @@ -575,7 +572,7 @@ void clipMetafileContentAgainstOwnRegions(GDIMetaFile& rSource) } else { - const basegfx::B2DRange aRange(rRect.Left(), rRect.Top(), rRect.Right(), rRect.Bottom()); + const basegfx::B2DRange aRange(vcl::unotools::b2DRectangleFromRectangle(rRect)); bDone = handleGeometricContent( aClips.back(), @@ -978,9 +975,7 @@ void clipMetafileContentAgainstOwnRegions(GDIMetaFile& rSource) aClips.back(), basegfx::B2DPolyPolygon( basegfx::utils::createPolygonFromRect( - basegfx::B2DRange( - rRect.Left(), rRect.Top(), - rRect.Right(), rRect.Bottom()))), + vcl::unotools::b2DRectangleFromRectangle(rRect))), pA->GetGradient(), aTarget); } diff --git a/vcl/source/gdi/pdfextoutdevdata.cxx b/vcl/source/gdi/pdfextoutdevdata.cxx index df90d4592c80..8696fd259a0e 100644 --- a/vcl/source/gdi/pdfextoutdevdata.cxx +++ b/vcl/source/gdi/pdfextoutdevdata.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <vcl/canvastools.hxx> #include <vcl/pdfextoutdevdata.hxx> #include <vcl/graph.hxx> #include <vcl/outdev.hxx> @@ -443,8 +444,7 @@ bool PageSyncData::PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAc { rWriter.Push(); basegfx::B2DPolyPolygon aRect( basegfx::utils::createPolygonFromRect( - basegfx::B2DRectangle( aVisibleOutputRect.Left(), aVisibleOutputRect.Top(), - aVisibleOutputRect.Right(), aVisibleOutputRect.Bottom() ) ) ); + vcl::unotools::b2DRectangleFromRectangle(aVisibleOutputRect) ) ); rWriter.SetClipRegion( aRect); } diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 218b65a908b9..79289ba8b39a 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -58,6 +58,7 @@ #include <svl/cryptosign.hxx> #include <vcl/bitmapex.hxx> #include <vcl/bitmapaccess.hxx> +#include <vcl/canvastools.hxx> #include <vcl/cvtgrf.hxx> #include <vcl/image.hxx> #include <vcl/lineinfo.hxx> @@ -10000,7 +10001,7 @@ void PDFWriterImpl::moveClipRegion( sal_Int32 nX, sal_Int32 nY ) void PDFWriterImpl::intersectClipRegion( const tools::Rectangle& rRect ) { basegfx::B2DPolyPolygon aRect( basegfx::utils::createPolygonFromRect( - basegfx::B2DRectangle( rRect.Left(), rRect.Top(), rRect.Right(), rRect.Bottom() ) ) ); + vcl::unotools::b2DRectangleFromRectangle(rRect) ) ); intersectClipRegion( aRect ); } diff --git a/vcl/source/gdi/region.cxx b/vcl/source/gdi/region.cxx index ff2fbfdf0580..083f89a15395 100644 --- a/vcl/source/gdi/region.cxx +++ b/vcl/source/gdi/region.cxx @@ -24,6 +24,7 @@ #include <tools/helpers.hxx> #include <osl/diagnose.h> #include <sal/log.hxx> +#include <vcl/canvastools.hxx> #include <vcl/region.hxx> #include <regionband.hxx> @@ -539,11 +540,7 @@ void vcl::Region::Union( const tools::Rectangle& rRect ) // get the other B2DPolyPolygon and use logical Or-Operation const basegfx::B2DPolygon aRectPoly( basegfx::utils::createPolygonFromRect( - basegfx::B2DRectangle( - rRect.Left(), - rRect.Top(), - rRect.Right(), - rRect.Bottom()))); + vcl::unotools::b2DRectangleFromRectangle(rRect))); const basegfx::B2DPolyPolygon aClip( basegfx::utils::solvePolygonOperationOr( aThisPolyPoly, @@ -716,7 +713,7 @@ void vcl::Region::Exclude( const tools::Rectangle& rRect ) // get the other B2DPolyPolygon const basegfx::B2DPolygon aRectPoly( basegfx::utils::createPolygonFromRect( - basegfx::B2DRectangle(rRect.Left(), rRect.Top(), rRect.Right(), rRect.Bottom()))); + vcl::unotools::b2DRectangleFromRectangle(rRect))); const basegfx::B2DPolyPolygon aOtherPolyPoly(aRectPoly); const basegfx::B2DPolyPolygon aClip = basegfx::utils::solvePolygonOperationDiff(aThisPolyPoly, aOtherPolyPoly); @@ -797,7 +794,7 @@ void vcl::Region::XOr( const tools::Rectangle& rRect ) // get the other B2DPolyPolygon const basegfx::B2DPolygon aRectPoly( basegfx::utils::createPolygonFromRect( - basegfx::B2DRectangle(rRect.Left(), rRect.Top(), rRect.Right(), rRect.Bottom()))); + vcl::unotools::b2DRectangleFromRectangle(rRect))); const basegfx::B2DPolyPolygon aOtherPolyPoly(aRectPoly); const basegfx::B2DPolyPolygon aClip = basegfx::utils::solvePolygonOperationXor(aThisPolyPoly, aOtherPolyPoly); diff --git a/vcl/source/helper/canvastools.cxx b/vcl/source/helper/canvastools.cxx index c53d800beb14..c3e15b3c697a 100644 --- a/vcl/source/helper/canvastools.cxx +++ b/vcl/source/helper/canvastools.cxx @@ -375,8 +375,14 @@ namespace vcl basegfx::B2IRectangle b2IRectangleFromRectangle(tools::Rectangle const& rRect) { - return basegfx::B2IRectangle(rRect.Left(), rRect.Top(), - rRect.Right(), rRect.Bottom()); + // although B2IRange internally has separate height/width emptiness, it doesn't + // expose any API to let us set them separately, so just do the best we can. + if (rRect.IsWidthEmpty() && rRect.IsHeightEmpty()) + return basegfx::B2IRange( basegfx::B2ITuple( rRect.Left(), rRect.Top() ) ); + return basegfx::B2IRange( rRect.Left(), + rRect.Top(), + rRect.IsWidthEmpty() ? rRect.Left() : rRect.Right(), + rRect.IsHeightEmpty() ? rRect.Top() : rRect.Bottom() ); } basegfx::B2DVector b2DSizeFromSize( const ::Size& rSize ) @@ -393,10 +399,14 @@ namespace vcl basegfx::B2DRange b2DRectangleFromRectangle( const ::tools::Rectangle& rRect ) { - return basegfx::B2DRange( rRect.Left(), - rRect.Top(), - rRect.Right(), - rRect.Bottom() ); + // although B2DRange internally has separate heigh/width emptiness, it doesn't + // expose any API to let us set them separately, so just do the best we can. + if (rRect.IsWidthEmpty() && rRect.IsHeightEmpty()) + return basegfx::B2DRange( basegfx::B2DTuple( rRect.Left(), rRect.Top() ) ); + return basegfx::B2DRectangle( rRect.Left(), + rRect.Top(), + rRect.IsWidthEmpty() ? rRect.Left() : rRect.Right(), + rRect.IsHeightEmpty() ? rRect.Top() : rRect.Bottom() ); } geometry::IntegerSize2D integerSize2DFromSize( const Size& rSize ) diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx index d4b99ea5da0f..0e57b2a9f203 100644 --- a/vcl/source/outdev/bitmap.cxx +++ b/vcl/source/outdev/bitmap.cxx @@ -22,6 +22,7 @@ #include <vcl/bitmap.hxx> #include <vcl/bitmapex.hxx> #include <vcl/bitmapaccess.hxx> +#include <vcl/canvastools.hxx> #include <vcl/gdimtf.hxx> #include <vcl/metaact.hxx> #include <config_features.h> @@ -1102,14 +1103,12 @@ bool OutputDevice::TransformAndReduceBitmapExToTargetRange( if(IsClipRegion()) { - const tools::Rectangle aRegionRectangle(GetActiveClipRegion().GetBoundRect()); - - aOutPixel.intersect( // caution! Range from rectangle, one too much (!) - basegfx::B2DRange( - aRegionRectangle.Left(), - aRegionRectangle.Top(), - aRegionRectangle.Right() + 1, - aRegionRectangle.Bottom() + 1)); + tools::Rectangle aRegionRectangle(GetActiveClipRegion().GetBoundRect()); + + // caution! Range from rectangle, one too much (!) + aRegionRectangle.AdjustRight(-1); + aRegionRectangle.AdjustBottom(-1); + aOutPixel.intersect( vcl::unotools::b2DRectangleFromRectangle(aRegionRectangle) ); } if(aOutPixel.isEmpty()) |