diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx index 75da3836b6f5..329d5d3bb4b1 100644 --- a/oox/source/drawingml/fillproperties.cxx +++ b/oox/source/drawingml/fillproperties.cxx @@ -853,7 +853,6 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap, aGraphCrop.Right = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * aFillRect.X2 ) / 100000 ); if ( aFillRect.Y2 ) aGraphCrop.Bottom = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y2 ) / 100000 ); - rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop); bool bHasCropValues = aGraphCrop.Left != 0 || aGraphCrop.Right !=0 || aGraphCrop.Top != 0 || aGraphCrop.Bottom != 0; // Negative GraphicCrop values means "crop" here. @@ -861,12 +860,17 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap, if(bIsCustomShape && bHasCropValues && bNeedCrop) { + // Physically crop the image + // In this case, don't set the PROP_GraphicCrop because that + // would lead to applying the crop twice after roundtrip xGraphic = lclCropGraphic(xGraphic, CropQuotientsFromFillRect(aFillRect)); if (rPropMap.supportsProperty(ShapeProperty::FillBitmapName)) rPropMap.setProperty(ShapeProperty::FillBitmapName, xGraphic); else rPropMap.setProperty(ShapeProperty::FillBitmap, xGraphic); } + else + rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop); } } } diff --git a/sw/qa/extras/ooxmlexport/data/crop-roundtrip.docx b/sw/qa/extras/ooxmlexport/data/crop-roundtrip.docx new file mode 100644 index 000000000000..6db60d0e8c60 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/crop-roundtrip.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx index 71d28b313d2a..04c775fa8fcb 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -172,6 +173,20 @@ CPPUNIT_TEST_FIXTURE(Test, testSdtDuplicatedId) assertXPath(pXmlDoc, "//w:sdt", 2); } +CPPUNIT_TEST_FIXTURE(Test, testImageCropping) +{ + loadAndReload("crop-roundtrip.docx"); + + // the image has no cropping after roundtrip, because it has been physically cropped + // NB: this test should be fixed when the core feature to show image cropped when it + // has the "GraphicCrop" is set is implemented + auto aGraphicCropStruct = getProperty(getShape(1), "GraphicCrop"); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aGraphicCropStruct.Left); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aGraphicCropStruct.Right); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aGraphicCropStruct.Top); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aGraphicCropStruct.Bottom); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */