diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-01-30 17:42:39 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-06-18 13:03:22 +0200 |
commit | cc678cbe2e9f8d1bd9b571e0c3af0a38d0d2a4ad (patch) | |
tree | 0db38eb03943689a7e38b0d7541e3e3a82d6e67e /oox | |
parent | 8842b1938bba44315b3c88e1accbaadcc2a6df09 (diff) |
Related: tdf#94238 PPTX import: handle subset of radial gradient fill
Handle the case when the horizontal center is at 50%. Other cases are
still unhandled, those are more complex.
After fixing the style, center and border, the gradient fill looks
similar to how PowerPoint renders it.
Reviewed-on: https://gerrit.libreoffice.org/67168
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
(cherry picked from commit fa6d726a9369fd49ff2b6c00da682641a025ba50)
Conflicts:
sd/qa/unit/import-tests.cxx
Change-Id: I419da70482de37031aa2c7fc735692019d7665f5
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/drawingml/color.cxx | 8 | ||||
-rw-r--r-- | oox/source/drawingml/fillproperties.cxx | 48 |
2 files changed, 50 insertions, 6 deletions
diff --git a/oox/source/drawingml/color.cxx b/oox/source/drawingml/color.cxx index 7008328c47ca..a41c9398c268 100644 --- a/oox/source/drawingml/color.cxx +++ b/oox/source/drawingml/color.cxx @@ -431,6 +431,14 @@ sal_Int32 Color::getColorTransformationToken( const OUString& sName ) return XML_TOKEN_INVALID; } +bool Color::equals(const Color& rOther, const GraphicHelper& rGraphicHelper, ::Color nPhClr) const +{ + if (getColor(rGraphicHelper, nPhClr) != rOther.getColor(rGraphicHelper, nPhClr)) + return false; + + return getTransparency() == rOther.getTransparency(); +} + void Color::clearTransparence() { mnAlpha = MAX_PERCENT; diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx index be91daa81b92..9c5338ce8975 100644 --- a/oox/source/drawingml/fillproperties.cxx +++ b/oox/source/drawingml/fillproperties.cxx @@ -154,6 +154,30 @@ const awt::Size lclGetOriginalSize( const GraphicHelper& rGraphicHelper, const R return aSizeHmm; } +/** + * Looks for a last gradient transition and possibly sets a gradient border + * based on that. + */ +void extractGradientBorderFromStops(const GradientFillProperties& rGradientProps, + const GraphicHelper& rGraphicHelper, ::Color nPhClr, + awt::Gradient& rGradient) +{ + if (rGradientProps.maGradientStops.size() <= 1) + return; + + auto it = rGradientProps.maGradientStops.rbegin(); + double fLastPos = it->first; + Color aLastColor = it->second; + ++it; + double fLastButOnePos = it->first; + Color aLastButOneColor = it->second; + if (!aLastColor.equals(aLastButOneColor, rGraphicHelper, nPhClr)) + return; + + // Last transition has the same color, we can map that to a border. + rGradient.Border = rtl::math::round((fLastPos - fLastButOnePos) * 100); +} + } // namespace void GradientFillProperties::assignUsed( const GradientFillProperties& rSourceProps ) @@ -354,15 +378,28 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap, if( maGradientProps.moGradientPath.has() ) { - aGradient.Style = (maGradientProps.moGradientPath.get() == XML_circle) ? awt::GradientStyle_ELLIPTICAL : awt::GradientStyle_RECT; - // position of gradient center (limited to [30%;70%], otherwise gradient is too hidden) + // position of gradient center (limited to [30%;100%], otherwise gradient is too hidden) IntegerRectangle2D aFillToRect = maGradientProps.moFillToRect.get( IntegerRectangle2D( 0, 0, MAX_PERCENT, MAX_PERCENT ) ); sal_Int32 nCenterX = (MAX_PERCENT + aFillToRect.X1 - aFillToRect.X2) / 2; - aGradient.XOffset = getLimitedValue< sal_Int16, sal_Int32 >( nCenterX / PER_PERCENT, 30, 70 ); + aGradient.XOffset = getLimitedValue<sal_Int16, sal_Int32>( + nCenterX / PER_PERCENT, 30, 100); + + // Style should be radial at least when the horizontal center is at 50%. + awt::GradientStyle eCircle = aGradient.XOffset == 50 + ? awt::GradientStyle_RADIAL + : awt::GradientStyle_ELLIPTICAL; + aGradient.Style = (maGradientProps.moGradientPath.get() == XML_circle) + ? eCircle + : awt::GradientStyle_RECT; + sal_Int32 nCenterY = (MAX_PERCENT + aFillToRect.Y1 - aFillToRect.Y2) / 2; - aGradient.YOffset = getLimitedValue< sal_Int16, sal_Int32 >( nCenterY / PER_PERCENT, 30, 70 ); + aGradient.YOffset = getLimitedValue<sal_Int16, sal_Int32>( + nCenterY / PER_PERCENT, 30, 100); ::std::swap( aGradient.StartColor, aGradient.EndColor ); ::std::swap( nStartTrans, nEndTrans ); + + extractGradientBorderFromStops(maGradientProps, rGraphicHelper, nPhClr, + aGradient); } else if (!maGradientProps.maGradientStops.empty()) { @@ -394,8 +431,7 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap, GradientFillProperties::GradientStopMap::const_iterator aItZ(std::prev(aGradientStops.end())); while( bSymmetric && aItA->first < aItZ->first ) { - if( aItA->second.getColor( rGraphicHelper, nPhClr ) != aItZ->second.getColor( rGraphicHelper, nPhClr ) || - aItA->second.getTransparency() != aItZ->second.getTransparency() ) + if (!aItA->second.equals(aItZ->second, rGraphicHelper, nPhClr)) bSymmetric = false; else { |