summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2023-08-15 21:09:27 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2023-08-15 21:41:24 +0200
commitd2c7cbc7d724d608f6d37bbb0233ad2b39eb938e (patch)
tree23d07e3ec86715e276f5e69ea17244ee82715c29 /oox
parent7712221f5340b8eb875d391967b2726e93285ab4 (diff)
Simplify and improve conversion
Using o3tl::convert makes sure that rounding is correct, which shows in the improved unit test, that now doesn't need different values before and after roundtrip. Change-Id: If46e27300bc199e89c0abf0ea4d0cd825024aeb2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155728 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r--oox/source/drawingml/fillproperties.cxx24
1 files changed, 12 insertions, 12 deletions
diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx
index a11aeb6236ee..8cc400257155 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -105,9 +105,9 @@ std::optional<Quotients> CropQuotientsFromSrcRect(geometry::IntegerRectangle2D a
aSrcRect.X2 = std::max(aSrcRect.X2, sal_Int32(0));
aSrcRect.Y1 = std::max(aSrcRect.Y1, sal_Int32(0));
aSrcRect.Y2 = std::max(aSrcRect.Y2, sal_Int32(0));
- if (aSrcRect.X1 + aSrcRect.X2 >= 100'000 || aSrcRect.Y1 + aSrcRect.Y2 >= 100'000)
+ if (aSrcRect.X1 + aSrcRect.X2 >= MAX_PERCENT || aSrcRect.Y1 + aSrcRect.Y2 >= MAX_PERCENT)
return {}; // Cropped everything
- return getQuotients(aSrcRect, 100'000.0, 100'000.0);
+ return getQuotients(aSrcRect, MAX_PERCENT, MAX_PERCENT);
}
// ECMA-376 Part 1 20.1.8.30 fillRect (Fill Rectangle)
@@ -118,8 +118,8 @@ std::optional<Quotients> CropQuotientsFromFillRect(geometry::IntegerRectangle2D
aFillRect.Y1 = std::min(aFillRect.Y1, sal_Int32(0));
aFillRect.Y2 = std::min(aFillRect.Y2, sal_Int32(0));
// Negative divisor and negative relative offset give positive value wanted in lclCropGraphic
- return getQuotients(aFillRect, -100'000.0 + aFillRect.X1 + aFillRect.X2,
- -100'000.0 + aFillRect.Y1 + aFillRect.Y2);
+ return getQuotients(aFillRect, -MAX_PERCENT + aFillRect.X1 + aFillRect.X2,
+ -MAX_PERCENT + aFillRect.Y1 + aFillRect.Y2);
}
// Crops a piece of the bitmap. lclCropGraphic doesn't handle growing.
@@ -624,13 +624,13 @@ void FillProperties::pushToPropMap(ShapePropertyMap& rPropMap, const GraphicHelp
{
text::GraphicCrop aGraphCrop( 0, 0, 0, 0 );
if ( aFillRect.X1 )
- aGraphCrop.Left = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * aFillRect.X1 ) / 100000 );
+ aGraphCrop.Left = o3tl::convert(aFillRect.X1, aOriginalSize.Width, MAX_PERCENT);
if ( aFillRect.Y1 )
- aGraphCrop.Top = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y1 ) / 100000 );
+ aGraphCrop.Top = o3tl::convert(aFillRect.Y1, aOriginalSize.Height, MAX_PERCENT);
if ( aFillRect.X2 )
- aGraphCrop.Right = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * aFillRect.X2 ) / 100000 );
+ aGraphCrop.Right = o3tl::convert(aFillRect.X2, aOriginalSize.Width, MAX_PERCENT);
if ( aFillRect.Y2 )
- aGraphCrop.Bottom = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y2 ) / 100000 );
+ aGraphCrop.Bottom = o3tl::convert(aFillRect.Y2, aOriginalSize.Height, MAX_PERCENT);
bool bHasCropValues = aGraphCrop.Left != 0 || aGraphCrop.Right !=0 || aGraphCrop.Top != 0 || aGraphCrop.Bottom != 0;
// Negative GraphicCrop values means "crop" here.
@@ -817,13 +817,13 @@ void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelpe
{
text::GraphicCrop aGraphCrop( 0, 0, 0, 0 );
if ( oClipRect.X1 )
- aGraphCrop.Left = rtl::math::round( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X1 ) / 100000 );
+ aGraphCrop.Left = o3tl::convert(oClipRect.X1, aOriginalSize.Width, MAX_PERCENT);
if ( oClipRect.Y1 )
- aGraphCrop.Top = rtl::math::round( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y1 ) / 100000 );
+ aGraphCrop.Top = o3tl::convert(oClipRect.Y1, aOriginalSize.Height, MAX_PERCENT);
if ( oClipRect.X2 )
- aGraphCrop.Right = rtl::math::round( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X2 ) / 100000 );
+ aGraphCrop.Right = o3tl::convert(oClipRect.X2, aOriginalSize.Width, MAX_PERCENT);
if ( oClipRect.Y2 )
- aGraphCrop.Bottom = rtl::math::round( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y2 ) / 100000 );
+ aGraphCrop.Bottom = o3tl::convert(oClipRect.Y2, aOriginalSize.Height, MAX_PERCENT);
rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop);
if(mbIsCustomShape)