tdf#153008: srcRect may have some members negative
The overly strict check (implying that all members must be non-negative,
to perform the crop) excluded valid cases where some of the members were
negative, and some positive.
Change-Id: I629689bdccedf9e37632a9fe14654778c0f14a6f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155717
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx
index 7e2f518..5edc71b 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -826,13 +826,11 @@ void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelpe
aGraphCrop.Bottom = rtl::math::round( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y2 ) / 100000 );
rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop);
bool bHasCropValues = aGraphCrop.Left != 0 || aGraphCrop.Right !=0 || aGraphCrop.Top != 0 || aGraphCrop.Bottom != 0;
// Positive GraphicCrop values means "crop" here.
bool bNeedCrop = aGraphCrop.Left >= 0 && aGraphCrop.Right >= 0 && aGraphCrop.Top >= 0 && aGraphCrop.Bottom >= 0;
if(mbIsCustomShape && bHasCropValues && bNeedCrop)
if(mbIsCustomShape)
{
xGraphic = lclCropGraphic(xGraphic, CropQuotientsFromSrcRect(oClipRect));
// Positive GraphicCrop values means "crop" here.
if (aGraphCrop.Left > 0 || aGraphCrop.Right > 0 || aGraphCrop.Top > 0 || aGraphCrop.Bottom > 0)
xGraphic = lclCropGraphic(xGraphic, CropQuotientsFromSrcRect(oClipRect));
}
}
}
diff --git a/sd/qa/unit/data/pptx/tdf153008-srcRect-smallNegBound.pptx b/sd/qa/unit/data/pptx/tdf153008-srcRect-smallNegBound.pptx
new file mode 100644
index 0000000..9870e3f
--- /dev/null
+++ b/sd/qa/unit/data/pptx/tdf153008-srcRect-smallNegBound.pptx
Binary files differ
diff --git a/sd/qa/unit/import-tests2.cxx b/sd/qa/unit/import-tests2.cxx
index 4d197b3..4e535c7 100644
--- a/sd/qa/unit/import-tests2.cxx
+++ b/sd/qa/unit/import-tests2.cxx
@@ -1918,6 +1918,25 @@ CPPUNIT_TEST_FIXTURE(SdImportTest2, testIndentDuplication)
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nIndent2);
}
CPPUNIT_TEST_FIXTURE(SdImportTest2, test_srcRect_smallNegBound)
{
// Given a cropped custom shape, with a srcRect having a small negative value in one of bounds
createSdImpressDoc("pptx/tdf153008-srcRect-smallNegBound.pptx");
uno::Reference<graphic::XGraphic> xGraphic(
getShapeFromPage(0, 0)->getPropertyValue("FillBitmap"), uno::UNO_QUERY_THROW);
BitmapEx aBitmap(Graphic(xGraphic).GetBitmapEx());
// Properly cropped bitmap should have black pixels close to left edge, near vertical center.
// Before the fix, the gear was distorted, and this area was white.
auto yMiddle = aBitmap.GetSizePixel().Height() / 2;
auto x5Percent = aBitmap.GetSizePixel().Width() / 20;
CPPUNIT_ASSERT(aBitmap.GetPixelColor(x5Percent, yMiddle).IsDark());
// Just in case, check that the corner is bright (it is in fact yellow)
CPPUNIT_ASSERT(aBitmap.GetPixelColor(0, 0).IsBright());
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */