From df482562d2532956c197468740e2a02499a89f55 Mon Sep 17 00:00:00 2001 From: Tibor Nagy Date: Mon, 23 Jan 2023 09:33:13 +0100 Subject: tdf#153107 OOXML export: fix scale of tile of shape background MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Relative scale values were exported as absolute values, resulting broken shape background. Change-Id: Ia38e125862e7f8ceff5d41754340723c3a9eb028 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145996 Tested-by: László Németh Reviewed-by: László Németh Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153576 Reviewed-by: Jaume Pujantell Tested-by: Jenkins CollaboraOffice Reviewed-by: Caolán McNamara --- oox/source/export/drawingml.cxx | 55 +++++++++++++++++++++++------------------ oox/source/export/shapes.cxx | 6 ++--- 2 files changed, 34 insertions(+), 27 deletions(-) (limited to 'oox') diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 6599f6cb1959..f7f67595c025 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -1703,7 +1703,8 @@ OUString DrawingML::WriteXGraphicBlip(uno::Reference const } void DrawingML::WriteXGraphicBlipMode(uno::Reference const & rXPropSet, - uno::Reference const & rxGraphic) + uno::Reference const & rxGraphic, + css::awt::Size const& rSize) { BitmapMode eBitmapMode(BitmapMode_NO_REPEAT); if (GetProperty(rXPropSet, "FillBitmapMode")) @@ -1714,7 +1715,7 @@ void DrawingML::WriteXGraphicBlipMode(uno::Reference const switch (eBitmapMode) { case BitmapMode_REPEAT: - WriteXGraphicTile(rXPropSet, rxGraphic); + WriteXGraphicTile(rXPropSet, rxGraphic, rSize); break; case BitmapMode_STRETCH: WriteXGraphicStretch(rXPropSet, rxGraphic); @@ -1724,7 +1725,8 @@ void DrawingML::WriteXGraphicBlipMode(uno::Reference const } } -void DrawingML::WriteBlipOrNormalFill( const Reference< XPropertySet >& xPropSet, const OUString& rURLPropName ) +void DrawingML::WriteBlipOrNormalFill(const Reference& xPropSet, + const OUString& rURLPropName, const awt::Size& rSize) { // check for blip and otherwise fall back to normal fill // we always store normal fill properties but OOXML @@ -1732,15 +1734,17 @@ void DrawingML::WriteBlipOrNormalFill( const Reference< XPropertySet >& xPropSet if (GetProperty ( xPropSet, rURLPropName )) WriteBlipFill( xPropSet, rURLPropName ); else - WriteFill(xPropSet); + WriteFill(xPropSet, rSize); } -void DrawingML::WriteBlipFill( const Reference< XPropertySet >& rXPropSet, const OUString& sURLPropName ) +void DrawingML::WriteBlipFill(const Reference& rXPropSet, + const OUString& sURLPropName, const awt::Size& rSize) { - WriteBlipFill( rXPropSet, sURLPropName, XML_a ); + WriteBlipFill( rXPropSet, rSize, sURLPropName, XML_a ); } -void DrawingML::WriteBlipFill( const Reference< XPropertySet >& rXPropSet, const OUString& sURLPropName, sal_Int32 nXmlNamespace ) +void DrawingML::WriteBlipFill(const Reference& rXPropSet, const awt::Size& rSize, + const OUString& sURLPropName, sal_Int32 nXmlNamespace) { if ( !GetProperty( rXPropSet, sURLPropName ) ) return; @@ -1762,13 +1766,14 @@ void DrawingML::WriteBlipFill( const Reference< XPropertySet >& rXPropSet, const bool bWriteMode = false; if (sURLPropName == "FillBitmap" || sURLPropName == "BackGraphic") bWriteMode = true; - WriteXGraphicBlipFill(rXPropSet, xGraphic, nXmlNamespace, bWriteMode); + WriteXGraphicBlipFill(rXPropSet, xGraphic, nXmlNamespace, bWriteMode, false, rSize); } } void DrawingML::WriteXGraphicBlipFill(uno::Reference const & rXPropSet, uno::Reference const & rxGraphic, - sal_Int32 nXmlNamespace, bool bWriteMode, bool bRelPathToMedia) + sal_Int32 nXmlNamespace, bool bWriteMode, + bool bRelPathToMedia, css::awt::Size const& rSize) { if (!rxGraphic.is() ) return; @@ -1785,7 +1790,7 @@ void DrawingML::WriteXGraphicBlipFill(uno::Reference const if (bWriteMode) { - WriteXGraphicBlipMode(rXPropSet, rxGraphic); + WriteXGraphicBlipMode(rXPropSet, rxGraphic, rSize); } else if(GetProperty(rXPropSet, "FillBitmapStretch")) { @@ -1976,7 +1981,8 @@ static OUString lclConvertRectanglePointToToken(RectanglePoint eRectanglePoint) } void DrawingML::WriteXGraphicTile(uno::Reference const& rXPropSet, - uno::Reference const& rxGraphic) + uno::Reference const& rxGraphic, + css::awt::Size const& rSize) { Graphic aGraphic(rxGraphic); Size aOriginalSize(aGraphic.GetPrefSize()); @@ -1993,6 +1999,8 @@ void DrawingML::WriteXGraphicTile(uno::Reference const& rXP if (GetProperty(rXPropSet, "FillBitmapPositionOffsetX")) { sal_Int32 nX = (nSizeX != 0) ? nSizeX : aOriginalSize.Width(); + if (nX < 0 && rSize.Width > 0) + nX = rSize.Width * std::abs(nX) / 100; nOffsetX = (*o3tl::doAccess(mAny)) * nX * 3.6; } @@ -2013,6 +2021,8 @@ void DrawingML::WriteXGraphicTile(uno::Reference const& rXP if (GetProperty(rXPropSet, "FillBitmapPositionOffsetY")) { sal_Int32 nY = (nSizeY != 0) ? nSizeY : aOriginalSize.Height(); + if (nY < 0 && rSize.Height > 0) + nY = rSize.Height * std::abs(nY) / 100; nOffsetY = (*o3tl::doAccess(mAny)) * nY * 3.6; } @@ -2028,18 +2038,15 @@ void DrawingML::WriteXGraphicTile(uno::Reference const& rXP // if the "Scale" setting is checked in the images settings dialog. if (nSizeX < 0 && nSizeY < 0) { - Reference xDPS(GetFB()->getModel(), UNO_QUERY_THROW); - Reference xDrawPages(xDPS->getDrawPages(), UNO_SET_THROW); - // in this case, the size of the first slide is enough, because all slides are the same size - Reference xDrawPage(xDrawPages->getByIndex(0), UNO_QUERY); - css::uno::Reference xPagePropSet(xDrawPage, UNO_QUERY); - if (xPagePropSet) + if (rSize.Width != 0 && rSize.Height != 0) + { + nSizeX = rSize.Width / double(aOriginalSize.Width()) * std::abs(nSizeX); + nSizeY = rSize.Height / double(aOriginalSize.Height()) * std::abs(nSizeY); + } + else { - double nPageWidth(0.0), nPageHeight(0.0); - xPagePropSet->getPropertyValue("Width") >>= nPageWidth; - xPagePropSet->getPropertyValue("Height") >>= nPageHeight; - nSizeX = nPageWidth / aOriginalSize.Width() * std::abs(nSizeX); - nSizeY = nPageHeight / aOriginalSize.Height() * std::abs(nSizeY); + nSizeX = std::abs(nSizeX); + nSizeY = std::abs(nSizeY); } } @@ -5145,7 +5152,7 @@ sax_fastparser::FSHelperPtr DrawingML::CreateOutputStream ( return p; } -void DrawingML::WriteFill( const Reference< XPropertySet >& xPropSet ) +void DrawingML::WriteFill(const Reference& xPropSet, const awt::Size& rSize) { if ( !GetProperty( xPropSet, "FillStyle" ) ) return; @@ -5197,7 +5204,7 @@ void DrawingML::WriteFill( const Reference< XPropertySet >& xPropSet ) WriteGradientFill( xPropSet ); break; case FillStyle_BITMAP : - WriteBlipFill( xPropSet, "FillBitmap" ); + WriteBlipFill( xPropSet, "FillBitmap", rSize ); break; case FillStyle_HATCH : WritePattFill( xPropSet ); diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx index 801d4ad9e318..2bf1fe11a6e9 100644 --- a/oox/source/export/shapes.cxx +++ b/oox/source/export/shapes.cxx @@ -441,7 +441,7 @@ ShapeExport& ShapeExport::WritePolyPolygonShape( const Reference< XShape >& xSha Reference< XPropertySet > xProps( xShape, UNO_QUERY ); if( xProps.is() ) { if( bClosed ) - WriteFill( xProps ); + WriteFill(xProps, aSize); WriteOutline( xProps ); } @@ -1111,7 +1111,7 @@ ShapeExport& ShapeExport::WriteCustomShape( const Reference< XShape >& xShape ) } if( rXPropSet.is() ) { - WriteFill( rXPropSet ); + WriteFill(rXPropSet, xShape->getSize()); WriteOutline( rXPropSet ); WriteShapeEffects( rXPropSet ); @@ -2482,7 +2482,7 @@ ShapeExport& ShapeExport::WriteTextShape( const Reference< XShape >& xShape ) uno::Reference xPropertySet(xShape, UNO_QUERY); if (!IsFontworkShape(xShapeProps)) // Fontwork needs fill and outline in run properties instead. { - WriteBlipOrNormalFill(xPropertySet, "Graphic"); + WriteBlipOrNormalFill(xPropertySet, "Graphic", xShape->getSize()); WriteOutline(xPropertySet); WriteShapeEffects(xPropertySet); } -- cgit