From 28bdc7916e1875e6827cae3b70977ad6c8c42824 Mon Sep 17 00:00:00 2001 From: Gülşah Köse Date: Wed, 20 Jan 2021 00:52:56 +0300 Subject: tdf#134210 Import support for custom stretch values. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I33ced8d667e37b7fb79f4c87b689f45966ac0097 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109658 Tested-by: Jenkins Reviewed-by: Gülşah Köse (cherry picked from commit 2c96bd26ec488d865370fe9d394e7c4e228e05ab) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109806 Reviewed-by: Miklos Vajna --- oox/source/drawingml/fillproperties.cxx | 34 ++++++++++++++++++++++++++++++++- oox/source/drawingml/shape.cxx | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) (limited to 'oox/source') diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx index 3efd64878326..837578ebc807 100644 --- a/oox/source/drawingml/fillproperties.cxx +++ b/oox/source/drawingml/fillproperties.cxx @@ -87,6 +87,32 @@ Reference< XGraphic > lclRotateGraphic(uno::Reference const & return aReturnGraphic.GetXGraphic(); } +Reference< XGraphic > lclCropGraphic(uno::Reference const & xGraphic, geometry::IntegerRectangle2D aFillRect) +{ + ::Graphic aGraphic(xGraphic); + ::Graphic aReturnGraphic; + + assert (aGraphic.GetType() == GraphicType::Bitmap); + + BitmapEx aBitmapEx(aGraphic.GetBitmapEx()); + + sal_Int32 nOrigHeight = aBitmapEx.GetSizePixel().Height(); + sal_Int32 nHeight = nOrigHeight; + sal_Int32 nTopCorr = nOrigHeight * -1 * static_cast(aFillRect.Y1) / 100000; + nHeight += nTopCorr; + sal_Int32 nBottomCorr = nOrigHeight * -1 * static_cast(aFillRect.Y2) / 100000; + nHeight += nBottomCorr; + + aBitmapEx.Scale(Size(aBitmapEx.GetSizePixel().Width(), nHeight)); + aBitmapEx.Crop(tools::Rectangle(Point(0, nTopCorr), Size(aBitmapEx.GetSizePixel().Width(), nOrigHeight))); + + aReturnGraphic = ::Graphic(aBitmapEx); + aReturnGraphic.setOriginURL(aGraphic.getOriginURL()); + + return aReturnGraphic.GetXGraphic(); +} + + Reference< XGraphic > lclCheckAndApplyChangeColorTransform(const BlipFillProperties &aBlipProps, uno::Reference const & xGraphic, const GraphicHelper& rGraphicHelper, const ::Color nPhClr) { @@ -272,7 +298,7 @@ Color FillProperties::getBestSolidColor() const void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap, const GraphicHelper& rGraphicHelper, sal_Int32 nShapeRotation, ::Color nPhClr, - bool bFlipH, bool bFlipV ) const + bool bFlipH, bool bFlipV, bool bIsCustomShape) const { if( !moFillType.has() ) return; @@ -675,6 +701,12 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap, if ( aFillRect.Y2 ) aGraphCrop.Bottom = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y2 ) / 100000 ); rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop); + + if(bIsCustomShape) + { + xGraphic = lclCropGraphic(xGraphic, aFillRect); + rPropMap.setProperty(ShapeProperty::FillBitmap, xGraphic); + } } } } diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index a7ffe9655f1c..4ec4c425c9ce 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -1058,7 +1058,7 @@ Reference< XShape > const & Shape::createAndInsert( if (getFillProperties().moFillType.has() && getFillProperties().moFillType.get() == XML_grpFill) getFillProperties().assignUsed(aFillProperties); if(!bIsCroppedGraphic) - aFillProperties.pushToPropMap( aShapeProps, rGraphicHelper, mnRotation, nFillPhClr, mbFlipH, mbFlipV ); + aFillProperties.pushToPropMap( aShapeProps, rGraphicHelper, mnRotation, nFillPhClr, mbFlipH, mbFlipV, bIsCustomShape ); LineProperties aLineProperties = getActualLineProperties(pTheme); aLineProperties.pushToPropMap( aShapeProps, rGraphicHelper, nLinePhClr ); EffectProperties aEffectProperties = getActualEffectProperties(pTheme); -- cgit