summaryrefslogtreecommitdiff
path: root/emfio
diff options
context:
space:
mode:
authorHossein <hossein@libreoffice.org>2021-11-08 22:24:51 +0100
committerMike Kaganski <mike.kaganski@collabora.com>2021-11-09 07:14:30 +0100
commit2f590d0b66eddc53abe775ab344a195489d0a031 (patch)
treead2ffabaab6f3fcc89679fb3cafc34e1489089fc /emfio
parent83b529d88388c7c8e0563242a030063bd95c4bed (diff)
Simplify conditions for EMR_STRETCHDIBITS (EMF)
The variables xSrc, ySrc (x/y positions) and cxSrc, cySrc (x/y size) come from [MS-EMF] documentation, "EMR_STRETCHDIBITS Record" section. By calculating the difference between Bitmap x size and cxSrc (called nWidthDiff), and also Bitmap y size and cySrc (called nHeightDiff), the conditions used to test if it is OK to crop are simplified, and are better readable. Redundant checks (nWidthDiff >= 0) and (nHeightDiff >= 0) are removed because it is now obvious that when they are bigger than non-negative xSrc and ySrc, thus they themselves can not be negative. Change-Id: I8e82c3d469377f21d34b57f3d50f977cf71004ce Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124096 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'emfio')
-rw-r--r--emfio/source/reader/emfreader.cxx8
1 files changed, 4 insertions, 4 deletions
diff --git a/emfio/source/reader/emfreader.cxx b/emfio/source/reader/emfreader.cxx
index 7a29571d4773..a75c0a49e57f 100644
--- a/emfio/source/reader/emfreader.cxx
+++ b/emfio/source/reader/emfreader.cxx
@@ -1794,13 +1794,13 @@ namespace emfio
aTmp.Seek( 0 );
ReadDIB(aBitmap, aTmp, true);
+ const tools::Long nWidthDiff = aBitmap.GetSizePixel().Width() - cxSrc;
+ const tools::Long nHeightDiff = aBitmap.GetSizePixel().Height() - cySrc;
+
// test if it is sensible to crop
if ( (cxSrc > 0) && (cySrc > 0) &&
(xSrc >= 0) && (ySrc >= 0) &&
- (aBitmap.GetSizePixel().Width() >= cxSrc) &&
- (xSrc <= aBitmap.GetSizePixel().Width() - cxSrc) &&
- (aBitmap.GetSizePixel().Height() >= cySrc) &&
- (ySrc <= aBitmap.GetSizePixel().Height() - cySrc) )
+ (xSrc <= nWidthDiff) && (ySrc <= nHeightDiff) )
{
tools::Rectangle aCropRect( Point( xSrc, ySrc ), Size( cxSrc, cySrc ) );
aBitmap.Crop( aCropRect );