Kaydet (Commit) 68e756de authored tarafından Muthu Subramanian's avatar Muthu Subramanian

n#657896 - Gradient Transparencies and Muticolor Gradient fills.

- Assumes axial gradient fills when more than 3 colors are present.
- Implements importing of Transparency Gradients.
üst a54cb659
......@@ -59,6 +59,7 @@ enum ShapePropertyId
SHAPEPROP_FillStyle,
SHAPEPROP_FillColor,
SHAPEPROP_FillTransparency,
SHAPEPROP_GradientTransparency,
SHAPEPROP_FillGradient, /// Explicit fill gradient or name of a fill gradient stored in a global container.
SHAPEPROP_FillBitmapUrl, /// Explicit fill bitmap URL or name of a fill bitmap URL stored in a global container.
SHAPEPROP_FillBitmapMode,
......@@ -128,6 +129,8 @@ private:
bool setLineDash( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue );
/** Sets an explicit fill gradient, or creates a named fill gradient. */
bool setFillGradient( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue );
/** Creates a named transparency gradient. */
bool setGradientTrans( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue );
/** Sets an explicit fill bitmap URL, or creates a named fill bitmap URL. */
bool setFillBitmapUrl( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue );
......
......@@ -109,6 +109,8 @@ public:
an internal constant name with a new unused index appended. */
::rtl::OUString insertFillGradient( const ::com::sun::star::awt::Gradient& rGradient );
::rtl::OUString insertTransGrandient( const ::com::sun::star::awt::Gradient& rGradient );
/** Inserts a new named fill bitmap URL, returns the bitmap name, based on
an internal constant name with a new unused index appended. */
::rtl::OUString insertFillBitmapUrl( const ::rtl::OUString& rGraphicUrl );
......@@ -117,9 +119,11 @@ private:
ObjectContainer maMarkerContainer; /// Contains all named line markers (line end polygons).
ObjectContainer maDashContainer; /// Contains all named line dsahes.
ObjectContainer maGradientContainer; /// Contains all named fill gradients.
ObjectContainer maTransGradContainer; /// Contains all named transparency Gradients.
ObjectContainer maBitmapUrlContainer; /// Contains all named fill bitmap URLs.
const ::rtl::OUString maDashNameBase; /// Base name for all named line dashes.
const ::rtl::OUString maGradientNameBase; /// Base name for all named fill gradients.
const ::rtl::OUString maTransGradNameBase; /// Base name for all named fill gradients.
const ::rtl::OUString maBitmapUrlNameBase; /// Base name for all named fill bitmap URLs.
};
......
......@@ -217,6 +217,8 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap,
// do not create gradient struct if property is not supported...
if( rPropMap.supportsProperty( SHAPEPROP_FillGradient ) )
{
sal_Int32 nEndTrans = 0;
sal_Int32 nStartTrans = 0;
awt::Gradient aGradient;
aGradient.Angle = 900;
aGradient.StartIntensity = 100;
......@@ -227,6 +229,10 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap,
{
aGradient.StartColor = maGradientProps.maGradientStops.begin()->second.getColor( rGraphicHelper, nPhClr );
aGradient.EndColor = maGradientProps.maGradientStops.rbegin()->second.getColor( rGraphicHelper, nPhClr );
if( maGradientProps.maGradientStops.rbegin()->second.hasTransparency() )
nEndTrans = maGradientProps.maGradientStops.rbegin()->second.getTransparency()*255/100;
if( maGradientProps.maGradientStops.begin()->second.hasTransparency() )
nStartTrans = maGradientProps.maGradientStops.begin()->second.getTransparency()*255/100;
}
// "rotate with shape" not set, or set to false -> do not rotate
......@@ -244,29 +250,55 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap,
sal_Int32 nCenterY = (MAX_PERCENT + aFillToRect.Y1 - aFillToRect.Y2) / 2;
aGradient.YOffset = getLimitedValue< sal_Int16, sal_Int32 >( nCenterY / PER_PERCENT, 30, 70 );
::std::swap( aGradient.StartColor, aGradient.EndColor );
::std::swap( nStartTrans, nEndTrans );
nDmlAngle = nShapeRotation;
}
else
{
/* Try to detect a VML axial gradient. This type of
gradient is simulated by a 3-point linear gradient
with equal start and end color. */
bool bAxial = (nColorCount == 3) && (aGradient.StartColor == aGradient.EndColor);
gradient is simulated by a 3-point linear gradient.
Even if its a multi-color linear gradient, its probably better to assume
axial gradient, when there are 3 or more points.
*/
bool bAxial = (nColorCount >= 3);
aGradient.Style = bAxial ? awt::GradientStyle_AXIAL : awt::GradientStyle_LINEAR;
nDmlAngle = maGradientProps.moShadeAngle.get( 0 ) - nShapeRotation;
// convert DrawingML angle (in 1/60000 degrees) to API angle (in 1/10 degrees)
aGradient.Angle = static_cast< sal_Int16 >( (4500 - (nDmlAngle / (PER_DEGREE / 10))) % 3600 );
if( bAxial )
{
GradientFillProperties::GradientStopMap::const_iterator aIt = maGradientProps.maGradientStops.begin();
// Try to find the axial median
for(size_t i=0;i<nColorCount;i+=3)
aIt++;
// API StartColor is inner color in axial gradient
aGradient.StartColor = (++aIt)->second.getColor( rGraphicHelper, nPhClr );
// aIt->second.hasColor() kind would be better than Color != API_RGB_WHITE
if( aGradient.StartColor == aGradient.EndColor &&
( !aIt->second.hasTransparency() || aIt->second.getColor( rGraphicHelper, nPhClr ) != API_RGB_WHITE ) )
{
aGradient.StartColor = aIt->second.getColor( rGraphicHelper, nPhClr );
}
if( nStartTrans == nEndTrans && aIt->second.hasTransparency() )
nStartTrans = aIt->second.getTransparency()*255/100;
}
nDmlAngle = maGradientProps.moShadeAngle.get( 0 ) - nShapeRotation;
}
// convert DrawingML angle (in 1/60000 degrees) to API angle (in 1/10 degrees)
aGradient.Angle = static_cast< sal_Int16 >( (4500 - (nDmlAngle / (PER_DEGREE / 10))) % 3600 );
// push gradient or named gradient to property map
if( rPropMap.setProperty( SHAPEPROP_FillGradient, aGradient ) )
eFillStyle = FillStyle_GRADIENT;
// push gradient transparency to property map
if( nStartTrans != 0 || nEndTrans != 0 )
{
awt::Gradient aGrad(aGradient);
uno::Any aVal;
aGrad.EndColor = (sal_Int32)( nEndTrans | nEndTrans << 8 | nEndTrans << 16 );
aGrad.StartColor = (sal_Int32)( nStartTrans | nStartTrans << 8 | nStartTrans << 16 );
aVal <<= aGrad;
rPropMap.setProperty( SHAPEPROP_GradientTransparency, aGrad );
}
}
break;
......
......@@ -53,7 +53,7 @@ static const sal_Int32 spnDefaultShapeIds[ SHAPEPROP_END ] =
{
PROP_LineStyle, PROP_LineWidth, PROP_LineColor, PROP_LineTransparence, PROP_LineDash, PROP_LineJoint,
PROP_LineStartName, PROP_LineStartWidth, PROP_LineStartCenter, PROP_LineEndName, PROP_LineEndWidth, PROP_LineEndCenter,
PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_FillGradient,
PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_FillTransparenceGradientName, PROP_FillGradient,
PROP_FillBitmapURL, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY,
PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint
};
......@@ -110,6 +110,9 @@ bool ShapePropertyMap::setAnyProperty( ShapePropertyId ePropId, const Any& rValu
case SHAPEPROP_FillGradient:
return setFillGradient( nPropId, rValue );
case SHAPEPROP_GradientTransparency:
return setGradientTrans( nPropId, rValue );
case SHAPEPROP_FillBitmapUrl:
return setFillBitmapUrl( nPropId, rValue );
......@@ -172,6 +175,18 @@ bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId, const Any& rValue )
return false;
}
bool ShapePropertyMap::setGradientTrans( sal_Int32 nPropId, const Any& rValue )
{
// create named gradient and push its name
if( rValue.has< Gradient >() )
{
OUString aGradientName = mrModelObjHelper.insertTransGrandient( rValue.get< Gradient >() );
return ( aGradientName.getLength() > 0 ) && setProperty( nPropId, aGradientName );
}
return false;
}
bool ShapePropertyMap::setFillBitmapUrl( sal_Int32 nPropId, const Any& rValue )
{
// push bitmap URL explicitly
......
......@@ -26,6 +26,7 @@
*
************************************************************************/
#include <com/sun/star/container/XNameContainer.hpp>
#include "oox/helper/graphichelper.hxx"
#include <com/sun/star/awt/Point.hpp>
......
......@@ -112,9 +112,11 @@ ModelObjectHelper::ModelObjectHelper( const Reference< XMultiServiceFactory >& r
maMarkerContainer( rxModelFactory, CREATE_OUSTRING( "com.sun.star.drawing.MarkerTable" ) ),
maDashContainer( rxModelFactory, CREATE_OUSTRING( "com.sun.star.drawing.DashTable" ) ),
maGradientContainer( rxModelFactory, CREATE_OUSTRING( "com.sun.star.drawing.GradientTable" ) ),
maTransGradContainer( rxModelFactory, CREATE_OUSTRING( "com.sun.star.drawing.TransparencyGradientTable" ) ),
maBitmapUrlContainer( rxModelFactory, CREATE_OUSTRING( "com.sun.star.drawing.BitmapTable" ) ),
maDashNameBase( CREATE_OUSTRING( "msLineDash " ) ),
maGradientNameBase( CREATE_OUSTRING( "msFillGradient " ) ),
maTransGradNameBase( CREATE_OUSTRING( "msTransGradient " ) ),
maBitmapUrlNameBase( CREATE_OUSTRING( "msFillBitmap " ) )
{
}
......@@ -142,6 +144,11 @@ OUString ModelObjectHelper::insertFillGradient( const Gradient& rGradient )
return maGradientContainer.insertObject( maGradientNameBase, Any( rGradient ), true );
}
OUString ModelObjectHelper::insertTransGrandient( const Gradient& rGradient )
{
return maTransGradContainer.insertObject( maTransGradNameBase, Any( rGradient ), true );
}
OUString ModelObjectHelper::insertFillBitmapUrl( const OUString& rGraphicUrl )
{
if( rGraphicUrl.getLength() > 0 )
......
......@@ -156,6 +156,8 @@ FillGradient
FillGradientName
FillStyle
FillTransparence
FillTransparenceGradient
FillTransparenceGradientName
Filter
FilterCriteriaSource
FilterOptions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment