[Libreoffice-commits] .: oox/inc oox/source

Muthu Subramanian sumuthu at kemper.freedesktop.org
Tue Aug 23 00:02:48 PDT 2011


 oox/inc/oox/drawingml/shapepropertymap.hxx |    3 +
 oox/inc/oox/helper/modelobjecthelper.hxx   |    4 ++
 oox/source/drawingml/fillproperties.cxx    |   46 ++++++++++++++++++++++++-----
 oox/source/drawingml/shapepropertymap.cxx  |   17 ++++++++++
 oox/source/helper/graphichelper.cxx        |    1 
 oox/source/helper/modelobjecthelper.cxx    |    7 ++++
 oox/source/token/properties.txt            |    2 +
 7 files changed, 72 insertions(+), 8 deletions(-)

New commits:
commit 68e756de2ec7f9aeb1b6a6a28468745eca114715
Author: Muthu Subramanian <sumuthu at novell.com>
Date:   Tue Aug 23 12:44:51 2011 +0530

    n#657896 - Gradient Transparencies and Muticolor Gradient fills.
    
    - Assumes axial gradient fills when more than 3 colors are present.
    - Implements importing of Transparency Gradients.

diff --git a/oox/inc/oox/drawingml/shapepropertymap.hxx b/oox/inc/oox/drawingml/shapepropertymap.hxx
index e012d4b..e2326bd 100755
--- a/oox/inc/oox/drawingml/shapepropertymap.hxx
+++ b/oox/inc/oox/drawingml/shapepropertymap.hxx
@@ -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 );
 
diff --git a/oox/inc/oox/helper/modelobjecthelper.hxx b/oox/inc/oox/helper/modelobjecthelper.hxx
index e62c0ef..86459ec 100644
--- a/oox/inc/oox/helper/modelobjecthelper.hxx
+++ b/oox/inc/oox/helper/modelobjecthelper.hxx
@@ -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.
 };
 
diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx
index 04480d4..88e2949 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -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;
 
diff --git a/oox/source/drawingml/shapepropertymap.cxx b/oox/source/drawingml/shapepropertymap.cxx
index 521ed28..51736b7 100755
--- a/oox/source/drawingml/shapepropertymap.cxx
+++ b/oox/source/drawingml/shapepropertymap.cxx
@@ -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
diff --git a/oox/source/helper/graphichelper.cxx b/oox/source/helper/graphichelper.cxx
index e331ff9..941cc80 100644
--- a/oox/source/helper/graphichelper.cxx
+++ b/oox/source/helper/graphichelper.cxx
@@ -26,6 +26,7 @@
  *
  ************************************************************************/
 
+#include <com/sun/star/container/XNameContainer.hpp>
 #include "oox/helper/graphichelper.hxx"
 
 #include <com/sun/star/awt/Point.hpp>
diff --git a/oox/source/helper/modelobjecthelper.cxx b/oox/source/helper/modelobjecthelper.cxx
index 81a5447..2268bfa 100644
--- a/oox/source/helper/modelobjecthelper.cxx
+++ b/oox/source/helper/modelobjecthelper.cxx
@@ -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 )
diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt
index fa5b1ee..06f86cf 100644
--- a/oox/source/token/properties.txt
+++ b/oox/source/token/properties.txt
@@ -156,6 +156,8 @@ FillGradient
 FillGradientName
 FillStyle
 FillTransparence
+FillTransparenceGradient
+FillTransparenceGradientName
 Filter
 FilterCriteriaSource
 FilterOptions


More information about the Libreoffice-commits mailing list