oox/source/drawingml/fillproperties.cxx                   |   10 ++-----
 sd/qa/unit/data/pptx/tdf153008-srcRect-smallNegBound.pptx |binary
 sd/qa/unit/import-tests2.cxx                              |   19 ++++++++++++++
 3 files changed, 23 insertions(+), 6 deletions(-)

New commits:
commit dd1f530bf7ab50f7b45bea5413c2328c7ecc5ed6
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Aug 15 14:42:20 2023 +0300
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Wed Aug 16 11:17:07 2023 +0200

    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.kagan...@collabora.com>
    (cherry picked from commit 6c06c8a2be3d8cbbcb8ab1aaaeb04db95114dfcb)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155700
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/oox/source/drawingml/fillproperties.cxx 
b/oox/source/drawingml/fillproperties.cxx
index 7e2f5185b7f6..5edc71b8bc12 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 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<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: */

Reply via email to