oox/source/drawingml/fillproperties.cxx | 5 +++-- oox/source/export/drawingml.cxx | 26 ++++++++++++++++---------- sd/qa/unit/data/pptx/tdf152070.pptx |binary sd/qa/unit/import-tests.cxx | 20 ++++++++++++++++++++ 4 files changed, 39 insertions(+), 12 deletions(-)
New commits: commit b12e38c1ccb388e62e35d856d4a575e1724a10e9 Author: Tibor Nagy <nagy.tib...@nisz.hu> AuthorDate: Mon Dec 5 09:21:51 2022 +0100 Commit: László Németh <nem...@numbertext.org> CommitDate: Mon Dec 19 12:11:48 2022 +0000 tdf#152070 PPTX import: fix offset of tile background image by using bitmap image sizes instead of the original ones. Change-Id: Id6f2777bf6803bca7252878203a12ab796ac33dc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143766 Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx index c68568096fd8..2627a1861850 100644 --- a/oox/source/drawingml/fillproperties.cxx +++ b/oox/source/drawingml/fillproperties.cxx @@ -831,10 +831,11 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap, sal_Int32 nFillBmpSizeY = getLimitedValue< sal_Int32, double >( aOriginalSize.Height * fScaleY, 1, SAL_MAX_INT32 ); rPropMap.setProperty( ShapeProperty::FillBitmapSizeY, nFillBmpSizeY ); + awt::Size aBmpSize(nFillBmpSizeX, nFillBmpSizeY); // offset of the first bitmap tile (given as EMUs), convert to percent - sal_Int16 nTileOffsetX = getDoubleIntervalValue< sal_Int16 >(std::round(maBlipProps.moTileOffsetX.value_or( 0 ) / 3.6 / aOriginalSize.Width), 0, 100 ); + sal_Int16 nTileOffsetX = getDoubleIntervalValue< sal_Int16 >(std::round(maBlipProps.moTileOffsetX.value_or( 0 ) / 3.6 / aBmpSize.Width), 0, 100 ); rPropMap.setProperty( ShapeProperty::FillBitmapOffsetX, nTileOffsetX ); - sal_Int16 nTileOffsetY = getDoubleIntervalValue< sal_Int16 >(std::round(maBlipProps.moTileOffsetY.value_or( 0 ) / 3.6 / aOriginalSize.Height), 0, 100 ); + sal_Int16 nTileOffsetY = getDoubleIntervalValue< sal_Int16 >(std::round(maBlipProps.moTileOffsetY.value_or( 0 ) / 3.6 / aBmpSize.Height), 0, 100 ); rPropMap.setProperty( ShapeProperty::FillBitmapOffsetY, nTileOffsetY ); } } diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 3418a125fac5..86b9b5ac91dc 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -1887,19 +1887,18 @@ void DrawingML::WriteXGraphicTile(uno::Reference<beans::XPropertySet> const& rXP if (rMapMode.GetMapUnit() == MapUnit::MapPixel) aOriginalSize = Application::GetDefaultDevice()->PixelToLogic(aOriginalSize, MapMode(MapUnit::Map100thMM)); - sal_Int32 nOffsetX = 0; - if (GetProperty(rXPropSet, "FillBitmapPositionOffsetX")) - nOffsetX = (*o3tl::doAccess<sal_Int32>(mAny)) * aOriginalSize.Width() * 3.6; - - sal_Int32 nOffsetY = 0; - if (GetProperty(rXPropSet, "FillBitmapPositionOffsetY")) - nOffsetY = (*o3tl::doAccess<sal_Int32>(mAny)) * aOriginalSize.Height() * 3.6; - - // convert the X size of bitmap to a percentage sal_Int32 nSizeX = 0; + sal_Int32 nOffsetX = 0; if (GetProperty(rXPropSet, "FillBitmapSizeX")) { mAny >>= nSizeX; + if (GetProperty(rXPropSet, "FillBitmapPositionOffsetX")) + { + sal_Int32 nX = (nSizeX != 0) ? nSizeX : aOriginalSize.Width(); + nOffsetX = (*o3tl::doAccess<sal_Int32>(mAny)) * nX * 3.6; + } + + // convert the X size of bitmap to a percentage if (nSizeX > 0) nSizeX = double(nSizeX) / aOriginalSize.Width() * 100000; else if (nSizeX < 0) @@ -1908,11 +1907,18 @@ void DrawingML::WriteXGraphicTile(uno::Reference<beans::XPropertySet> const& rXP nSizeX = 100000; } - // convert the Y size of bitmap to a percentage sal_Int32 nSizeY = 0; + sal_Int32 nOffsetY = 0; if (GetProperty(rXPropSet, "FillBitmapSizeY")) { mAny >>= nSizeY; + if (GetProperty(rXPropSet, "FillBitmapPositionOffsetY")) + { + sal_Int32 nY = (nSizeY != 0) ? nSizeY : aOriginalSize.Height(); + nOffsetY = (*o3tl::doAccess<sal_Int32>(mAny)) * nY * 3.6; + } + + // convert the Y size of bitmap to a percentage if (nSizeY > 0) nSizeY = double(nSizeY) / aOriginalSize.Height() * 100000; else if (nSizeY < 0) diff --git a/sd/qa/unit/data/pptx/tdf152070.pptx b/sd/qa/unit/data/pptx/tdf152070.pptx new file mode 100644 index 000000000000..1fbc8016d149 Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf152070.pptx differ diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx index abd21782bf68..5a599ad9a43a 100644 --- a/sd/qa/unit/import-tests.cxx +++ b/sd/qa/unit/import-tests.cxx @@ -154,6 +154,7 @@ public: void testTdf89927(); void testTdf103800(); void testTdf151767(); + void testTdf152070(); CPPUNIT_TEST_SUITE(SdImportTest); @@ -229,6 +230,7 @@ public: CPPUNIT_TEST(testTdf89927); CPPUNIT_TEST(testTdf103800); CPPUNIT_TEST(testTdf151767); + CPPUNIT_TEST(testTdf152070); CPPUNIT_TEST_SUITE_END(); }; @@ -1928,6 +1930,24 @@ void SdImportTest::testTdf151767() CPPUNIT_ASSERT_EQUAL_MESSAGE("The bottom border is missing!", true, aBottom.LineWidth > 0); } +void SdImportTest::testTdf152070() +{ + createSdImpressDoc("pptx/tdf152070.pptx"); + + uno::Reference<drawing::XDrawPagesSupplier> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xPropSet(xPage, uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xBackgroundProps( + xPropSet->getPropertyValue("Background").get<uno::Reference<beans::XPropertySet>>()); + + CPPUNIT_ASSERT_EQUAL( + sal_Int32(50), // 50% + xBackgroundProps->getPropertyValue("FillBitmapPositionOffsetX").get<sal_Int32>()); + CPPUNIT_ASSERT_EQUAL( + sal_Int32(83), // 83% + xBackgroundProps->getPropertyValue("FillBitmapPositionOffsetY").get<sal_Int32>()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTest); CPPUNIT_PLUGIN_IMPLEMENT();