[Libreoffice-commits] core.git: Branch 'libreoffice-7-4' - oox/source sw/qa

2022-11-25 Thread Jan Holesovsky (via logerrit)
 oox/source/drawingml/fillproperties.cxx   |6 +-
 sw/qa/extras/ooxmlexport/data/crop-roundtrip.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport18.cxx|   15 +++
 3 files changed, 20 insertions(+), 1 deletion(-)

New commits:
commit 96accaabebc2685a55323f939c432ce8e8c60f34
Author: Jan Holesovsky 
AuthorDate: Thu Nov 24 11:22:49 2022 +0100
Commit: Xisco Fauli 
CommitDate: Fri Nov 25 10:48:11 2022 +0100

tdf#152199: Don't crop twice

We have a "GraphicCrop" property that is supposed to roundtrip the
cropping in OOXML, but there is no core feature backing it (ie. the
image is not shown cropped when this is imported and set).

Instead, to show the image "cropped", we crop the image physically on
import (throw away pixels that are 'outside' of the cropped area).

But - the "GraphicCrop" is then saved on export, together with the image
already physically cropped, which leads to garbled DOCX on re-import.

Given that the core feature to show image cropped when the "GraphicCrop"
is set, let's avoid setting it when we physically crop the image.

Change-Id: Ia1090ea9c6d22e60c77d52bf65281f6588d07d4e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143216
Tested-by: Jenkins
Reviewed-by: Jan Holesovsky 
Signed-off-by: Xisco Fauli 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143251

diff --git a/oox/source/drawingml/fillproperties.cxx 
b/oox/source/drawingml/fillproperties.cxx
index 3b540ba1de29..144c67fa5caf 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 ) / 10 );
 if ( aFillRect.Y2 )
 aGraphCrop.Bottom = static_cast< sal_Int32 >( 
( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y2 ) / 10 );
-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 ..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 e1e515f99e57..dc9429c20cbe 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 
@@ -101,6 +102,20 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf150966_regularInset)
 assertXPathAttrs(pXmlDoc, "//wps:bodyPr", { { "tIns", "179640" }, { 
"bIns", "36" } });
 }
 
+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();
 
 /*

[Libreoffice-commits] core.git: Branch 'libreoffice-7-4' - oox/source sw/qa

2022-07-29 Thread Justin Luth (via logerrit)
 dev/null  |binary
 oox/source/drawingml/fillproperties.cxx   |5 -
 sw/qa/extras/ooxmlexport/ooxmlexport6.cxx |   10 --
 3 files changed, 4 insertions(+), 11 deletions(-)

New commits:
commit a0f38b84a0156b0e00ccf3067d65f495c1780c95
Author: Justin Luth 
AuthorDate: Thu Jul 28 16:45:41 2022 -0400
Commit: Xisco Fauli 
CommitDate: Fri Jul 29 10:24:57 2022 +0200

Revert "tdf#141652 partial revert "Reset ShapeProperty priority..."

This reverts 7.4 commit 18cc1240565e697859dd7d17058f91d5e01df929.

Someone backported it to 7.3 as well.

Reverting fixes regression report tdf#150061.


Change-Id: Ie04595e11dd9d2e15fa940b8ada71714bd434f6a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137581
Tested-by: Jenkins
Reviewed-by: Justin Luth 
(cherry picked from commit 84b719e41c3a5f1e3dba112508721d69c1b3185e)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137530
Reviewed-by: Xisco Fauli 

diff --git a/oox/source/drawingml/fillproperties.cxx 
b/oox/source/drawingml/fillproperties.cxx
index a5dbc84fb377..c2f4eaad4e03 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -811,7 +811,10 @@ void FillProperties::pushToPropMap( ShapePropertyMap& 
rPropMap,
 if(bIsCustomShape && bHasCropValues && bNeedCrop)
 {
 xGraphic = lclCropGraphic(xGraphic, 
CropQuotientsFromFillRect(aFillRect));
-
rPropMap.setProperty(ShapeProperty::FillBitmap, xGraphic);
+if 
(rPropMap.supportsProperty(ShapeProperty::FillBitmapName))
+
rPropMap.setProperty(ShapeProperty::FillBitmapName, xGraphic);
+else
+
rPropMap.setProperty(ShapeProperty::FillBitmap, xGraphic);
 }
 }
 }
diff --git a/sw/qa/extras/ooxmlexport/data/tdf141652_fillBitmapName.docx 
b/sw/qa/extras/ooxmlexport/data/tdf141652_fillBitmapName.docx
deleted file mode 100644
index 4a47a544d6bb..
Binary files a/sw/qa/extras/ooxmlexport/data/tdf141652_fillBitmapName.docx and 
/dev/null differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx
index 6c35215f584a..c54580ee766a 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx
@@ -274,16 +274,6 @@ DECLARE_OOXMLEXPORT_TEST(testDMLShapeFillBitmapCrop, 
"dml-shape-fillbitmapcrop.d
 
 }
 
-DECLARE_OOXMLEXPORT_TEST(test141652_fillBitmapName, 
"tdf141652_fillBitmapName.docx")
-{
-text::GraphicCrop aGraphicCropStruct = 
getProperty(getShape(1), "GraphicCrop");
-CPPUNIT_ASSERT_DOUBLES_EQUAL( sal_Int32(-769), aGraphicCropStruct.Right, 
10);
-
-CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Left );
-CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Top );
-CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Bottom );
-}
-
 DECLARE_OOXMLEXPORT_TEST(testDMLShapeFillPattern, "dml-shape-fillpattern.docx")
 {
 // Hatching was ignored by the export.