oox/source/drawingml/fillproperties.cxx |   13 +++++++++++++
 sd/qa/unit/data/pptx/tdf163852.pptx     |binary
 sd/qa/unit/import-tests2.cxx            |   18 ++++++++++++++++++
 3 files changed, 31 insertions(+)

New commits:
commit f0f813ab5e7dc48924e9d42889912c3fb79208eb
Author:     Balazs Varga <balazs.varga.ext...@allotropia.de>
AuthorDate: Thu Jan 2 16:45:10 2025 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Jan 7 09:53:45 2025 +0100

    tdf#163852 ooxml: fix import of cropped vector graphic objects
    
    We need to store the vector graphic objects size, so later
    we can calculate with that for the cropping.
    
    follow-up commit of: 1db193c6c744289139b1df2af0b8defcf974b238
    (tdf#126084 import svg image from ooxml document that use svgBlip elem)
    
    Change-Id: Iffa98cc6a03063544bdf2b8ec3012415868e7c65
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179626
    Tested-by: Jenkins
    Reviewed-by: Balazs Varga <balazs.varga.ext...@allotropia.de>
    Tested-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
    (cherry picked from commit 63753117640dde3e8e0b0e677afe26b7f57c626b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179838
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/oox/source/drawingml/fillproperties.cxx 
b/oox/source/drawingml/fillproperties.cxx
index eaeb0029c415..b75dfed5aac8 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -832,6 +832,19 @@ void GraphicProperties::pushToPropMap( PropertyMap& 
rPropMap, const GraphicHelpe
         {
             geometry::IntegerRectangle2D oClipRect( 
maBlipProps.moClipRect.value() );
             awt::Size aOriginalSize( rGraphicHelper.getOriginalSize( xGraphic 
) );
+
+            if (aOriginalSize.Width <= 0 || aOriginalSize.Height <= 0)
+            {
+                // VectorGraphic Objects need the correct object size for 
cropping
+                Graphic aGraphic(xGraphic);
+                if (aGraphic.getVectorGraphicData())
+                {
+                    Size aPrefSize = aGraphic.GetPrefSize();
+                    aOriginalSize.Height = 
static_cast<sal_Int32>(aPrefSize.getHeight());
+                    aOriginalSize.Width = 
static_cast<sal_Int32>(aPrefSize.getWidth());
+                }
+            }
+
             if (aOriginalSize.Width > 0 && aOriginalSize.Height > 0)
             {
                 text::GraphicCrop aGraphCrop( 0, 0, 0, 0 );
diff --git a/sd/qa/unit/data/pptx/tdf163852.pptx 
b/sd/qa/unit/data/pptx/tdf163852.pptx
new file mode 100644
index 000000000000..542a8268f6f8
Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf163852.pptx differ
diff --git a/sd/qa/unit/import-tests2.cxx b/sd/qa/unit/import-tests2.cxx
index 8e9b7f5f72b9..13a86cf25d77 100644
--- a/sd/qa/unit/import-tests2.cxx
+++ b/sd/qa/unit/import-tests2.cxx
@@ -1370,6 +1370,24 @@ CPPUNIT_TEST_FIXTURE(SdImportTest2, testTdf149206)
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aCrop.Right);
 }
 
+CPPUNIT_TEST_FIXTURE(SdImportTest2, testtdf163852)
+{
+    // Check that the svg image is cropped
+    createSdImpressDoc("pptx/tdf163852.pptx");
+
+    uno::Reference<beans::XPropertySet> 
xPropertySet(getShapeFromPage(/*nShape=*/1, /*nPage=*/0));
+    text::GraphicCrop aCrop;
+    xPropertySet->getPropertyValue(u"GraphicCrop"_ustr) >>= aCrop;
+
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aCrop.Top);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aCrop.Left);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aCrop.Right);
+    // Without the fix in place, this test would have failed with
+    // - Expected: 702
+    // - Actual  : 0
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(702), aCrop.Bottom);
+}
+
 CPPUNIT_TEST_FIXTURE(SdImportTest2, testTdf149785)
 {
     // Without the fix in place, this test would have failed to load the file

Reply via email to