From 6c06c8a2be3d8cbbcb8ab1aaaeb04db95114dfcb Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Tue, 15 Aug 2023 14:42:20 +0300 Subject: 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 --- .../data/pptx/tdf153008-srcRect-smallNegBound.pptx | Bin 0 -> 23988 bytes sd/qa/unit/import-tests2.cxx | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 sd/qa/unit/data/pptx/tdf153008-srcRect-smallNegBound.pptx (limited to 'sd') 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 000000000000..9870e3f2e2e9 Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf153008-srcRect-smallNegBound.pptx differ diff --git a/sd/qa/unit/import-tests2.cxx b/sd/qa/unit/import-tests2.cxx index 4d197b364449..4e535c7749c7 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 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: */ -- cgit