[ooo-build-commit] patches/dev300

Thorsten Behrens thorsten at kemper.freedesktop.org
Fri Jun 12 08:03:06 PDT 2009


 patches/dev300/apply                            |    3 
 patches/dev300/ppt-customshape-shading-fix.diff |  358 ++++++++++++++++++++++++
 2 files changed, 361 insertions(+)

New commits:
commit 8c1124fbab6d84ff9987cd8c234b1ddaeda1e43a
Author: Thorsten Behrens <tbehrens at novell.com>
Date:   Fri Jun 12 16:55:16 2009 +0200

    Better shading algo for customshapes, better gradients
    
    Some custom shapes can have shaded parts, like for example 3d can,
    the bevelled buttons etc. Those shaded colors are calculated
    internally, and have been way off at times. Now using HSV color
    space & the originally documented luminance modifications in steps
    of 10 percent. Compared to MSO, still no 100 percent match, but
    that seems due to gamma correction there.
    Additionally, starting with MSO12, gradients on those shaded surfaces
    look much better; adapted code to display gradients equally nice.
    
    Note that most of this patch also applies to ooxml import; note as
    well that customshapes from *all* kind of input files (including ODF
    docs) now look different than before; no real way of changing this
    in a backward-compatible way, since behaviour of custom shapes is
    mandated (mostly) by internal tables, and not stored in a file.
    
    * patches/dev300/apply: added the patch
    * patches/dev300/ppt-customshape-shading-fix.diff: changed
      EnhancedCustomShape2d and escher import according to the
      text above

diff --git a/patches/dev300/apply b/patches/dev300/apply
index 9b23eda..1c1aa26 100644
--- a/patches/dev300/apply
+++ b/patches/dev300/apply
@@ -3167,6 +3167,9 @@ svx-fix-fit-to-frame-crash.diff, n#508621, rodo
 # adds various color conversion functions to basegfx's BColor
 basegfx-color-tools.diff, thorsten
 
+# much improved surface shades, gradient color for customshapes
+ppt-customshape-shading-fix.diff, n#485637, thorsten
+
 [ OOXML ]
 oox-pptx-import-fix-placeholder-text-style.diff, n#479834, rodo
 oox-pptx-import-fix-text-body-properties-priority.diff, n#403402, rodo
diff --git a/patches/dev300/ppt-customshape-shading-fix.diff b/patches/dev300/ppt-customshape-shading-fix.diff
new file mode 100644
index 0000000..2f79937
--- /dev/null
+++ b/patches/dev300/ppt-customshape-shading-fix.diff
@@ -0,0 +1,358 @@
+Fix the custom shape gradient behaviour, plus shaded fill colors
+
+From: Thorsten Behrens <thb at openoffice.org>
+
+
+---
+
+ svx/source/customshapes/EnhancedCustomShape2d.cxx |  195 ++++++++++++---------
+ svx/source/customshapes/EnhancedCustomShape2d.hxx |    2 
+ svx/source/msfilter/msdffimp.cxx                  |    9 -
+ 3 files changed, 114 insertions(+), 92 deletions(-)
+
+
+diff --git svx/source/customshapes/EnhancedCustomShape2d.cxx svx/source/customshapes/EnhancedCustomShape2d.cxx
+index 0361511..a235e8c 100644
+--- svx/source/customshapes/EnhancedCustomShape2d.cxx
++++ svx/source/customshapes/EnhancedCustomShape2d.cxx
+@@ -55,6 +55,8 @@
+ #include <svx/xlnedwit.hxx>
+ #include <svx/xlnstcit.hxx>
+ #include <svx/xlnedcit.hxx>
++#include <svx/xflgrit.hxx>
++#include <svx/xgrad.hxx>
+ #include <com/sun/star/awt/Size.hpp>
+ #include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
+ #ifndef __COM_SUN_STAR_DRAWING_ENHANCEDCUSTOMSHAPESEGMENTCOMMAND_HPP__
+@@ -64,6 +66,7 @@
+ #include <boost/shared_ptr.hpp>
+ #endif
+ #include <basegfx/numeric/ftools.hxx>
++#include <basegfx/color/bcolortools.hxx>
+ #include <basegfx/polygon/b2dpolygon.hxx>
+ 
+ // #i76201#
+@@ -724,23 +727,23 @@ EnhancedCustomShape2d::EnhancedCustomShape2d( SdrObject* pAObj ) :
+ 	/*const sal_Int32* pDefData =*/ ApplyShapeAttributes( rGeometryItem );
+ 	switch( eSpType )
+ 	{
+-		case mso_sptCan :						nColorData = 0x20200000; break;
+-		case mso_sptCube :						nColorData = 0x302d0000; break;
+-		case mso_sptActionButtonBlank :			nColorData = 0x502ad400; break;
+-		case mso_sptActionButtonHome :			nColorData = 0x702ad4ad; break;
+-		case mso_sptActionButtonHelp :			nColorData = 0x602ad4a0; break;
+-		case mso_sptActionButtonInformation :	nColorData = 0x702ad4a5; break;
+-		case mso_sptActionButtonBackPrevious :	nColorData = 0x602ad4a0; break;
+-		case mso_sptActionButtonForwardNext :	nColorData = 0x602ad4a0; break;
+-		case mso_sptActionButtonBeginning :		nColorData = 0x602ad4a0; break;
+-		case mso_sptActionButtonEnd :			nColorData = 0x602ad4a0; break;
+-		case mso_sptActionButtonReturn :		nColorData = 0x602ad4a0; break;
+-		case mso_sptActionButtonDocument :		nColorData = 0x702ad4da; break;
+-		case mso_sptActionButtonSound :			nColorData = 0x602ad4a0; break;
+-		case mso_sptActionButtonMovie :			nColorData = 0x602ad4a0; break;
+-		case mso_sptBevel :						nColorData = 0x502ad400; break;
+-		case mso_sptFoldedCorner :				nColorData = 0x20d00000; break;
+-		case mso_sptSmileyFace :				nColorData = 0x20d00000; break;
++		case mso_sptCan :						nColorData = 0x20400000; break;
++		case mso_sptCube :						nColorData = 0x302e0000; break;
++		case mso_sptActionButtonBlank :			nColorData = 0x502ce400; break;
++		case mso_sptActionButtonHome :			nColorData = 0x702ce4ce; break;
++		case mso_sptActionButtonHelp :			nColorData = 0x602ce4c0; break;
++		case mso_sptActionButtonInformation :	nColorData = 0x702ce4c5; break;
++		case mso_sptActionButtonBackPrevious :	nColorData = 0x602ce4c0; break;
++		case mso_sptActionButtonForwardNext :	nColorData = 0x602ce4c0; break;
++		case mso_sptActionButtonBeginning :		nColorData = 0x602ce4c0; break;
++		case mso_sptActionButtonEnd :			nColorData = 0x602ce4c0; break;
++		case mso_sptActionButtonReturn :		nColorData = 0x602ce4c0; break;
++		case mso_sptActionButtonDocument :		nColorData = 0x702ce4ec; break;
++		case mso_sptActionButtonSound :			nColorData = 0x602ce4c0; break;
++		case mso_sptActionButtonMovie :			nColorData = 0x602ce4c0; break;
++		case mso_sptBevel :						nColorData = 0x502ce400; break;
++		case mso_sptFoldedCorner :				nColorData = 0x20e00000; break;
++		case mso_sptSmileyFace :				nColorData = 0x20e00000; break;
+         case mso_sptNil :
+         {
+             if( sShapeType.getLength() > 4 &&
+@@ -775,7 +778,7 @@ EnhancedCustomShape2d::EnhancedCustomShape2d( SdrObject* pAObj ) :
+ 		}
+ 		break;
+ 		case mso_sptCurvedDownArrow :			nFlags |= DFF_CUSTOMSHAPE_EXCH; break;
+-		case mso_sptRibbon2 :					nColorData = 0x30dd0000; break;
++		case mso_sptRibbon2 :					nColorData = 0x30ee0000; break;
+ 		case mso_sptRibbon :
+ 		{
+ 			if ( ( seqAdjustmentValues.getLength() > 1 ) && ( seqAdjustmentValues[ 1 ].State == com::sun::star::beans::PropertyState_DIRECT_VALUE ) )
+@@ -786,10 +789,10 @@ EnhancedCustomShape2d::EnhancedCustomShape2d( SdrObject* pAObj ) :
+ 				seqAdjustmentValues[ 1 ].Value <<= fValue;
+ 			}
+ 			nFlags |= DFF_CUSTOMSHAPE_FLIP_V;
+-			nColorData = 0x30dd0000;
++			nColorData = 0x30ee0000;
+ 		}
+ 		break;
+-		case mso_sptEllipseRibbon2 :			nColorData = 0x30dd0000; break;
++		case mso_sptEllipseRibbon2 :			nColorData = 0x30ee0000; break;
+ 		case mso_sptEllipseRibbon :				// !!!!!!!!!!
+ 		{
+ 			if ( ( seqAdjustmentValues.getLength() > 1 ) && ( seqAdjustmentValues[ 1 ].State == com::sun::star::beans::PropertyState_DIRECT_VALUE ) )
+@@ -800,11 +803,11 @@ EnhancedCustomShape2d::EnhancedCustomShape2d( SdrObject* pAObj ) :
+ 				seqAdjustmentValues[ 1 ].Value <<= fValue;
+ 			}
+ 			nFlags |= DFF_CUSTOMSHAPE_FLIP_V;
+-			nColorData = 0x30dd0000;
++			nColorData = 0x30ee0000;
+ 		}
+ 		break;
+-		case mso_sptVerticalScroll :			nColorData = 0x30dd0000; break;
+-		case mso_sptHorizontalScroll :			nColorData = 0x30dd0000; break;
++		case mso_sptVerticalScroll :			nColorData = 0x30ee0000; break;
++		case mso_sptHorizontalScroll :			nColorData = 0x30ee0000; break;
+ 		default:
+ 			break;
+ 	}
+@@ -1069,35 +1072,38 @@ Color EnhancedCustomShape2d::GetColorData( const Color& rFillColor, sal_uInt32 n
+ {
+ 	Color aRetColor;
+ 
+-	sal_uInt32 i, nColor, nTmp, nCount = nColorData >> 28;
+-
++	const sal_uInt32 nCount = nColorData >> 28;
+ 	if ( nCount )
+ 	{
+ 		if ( nIndex >= nCount )
+ 			nIndex = nCount - 1;
+ 
+-		sal_uInt32 nFillColor = (sal_uInt32)rFillColor.GetRed() |
+-									((sal_uInt32)rFillColor.GetGreen() << 8 ) |
+-										((sal_uInt32)rFillColor.GetBlue() << 16 );
+-
+ 		sal_Int32 nLumDat = nColorData << ( ( 1 + nIndex ) << 2 );
+-		sal_Int32 nLuminance = ( nLumDat >> 28 ) * 12;
+-
+-		nTmp = nFillColor;
+-		nColor = 0;
+-		for ( i = 0; i < 3; i++ )
+-		{
+-			sal_Int32 nC = (sal_uInt8)nTmp;
+-			nTmp >>= 8;
+-			nC += ( ( nLuminance * nC ) >> 8 );
+-			if ( nC < 0 )
+-				nC = 0;
+-			else if ( nC &~ 0xff )
+-				nC = 0xff;
+-			nColor >>= 8;
+-			nColor |= nC << 16;
+-		}
+-		aRetColor = Color( (sal_uInt8)nColor, (sal_uInt8)( nColor >> 8 ), (sal_uInt8)( nColor >> 16 ) );
++		sal_Int32 nLuminance = ( nLumDat >> 28 ) * 10;
++
++        basegfx::BColor aHSVColor=
++            basegfx::tools::rgb2hsv(
++                basegfx::BColor(rFillColor.GetRed()/255.0,
++                                rFillColor.GetGreen()/255.0,
++                                rFillColor.GetBlue()/255.0));
++        if( nLuminance > 0 )
++        {
++            aHSVColor.setGreen(
++                aHSVColor.getGreen() * (1.0-nLuminance/100.0));
++            aHSVColor.setBlue(
++                nLuminance/100.0 + 
++                (1.0-nLuminance/100.0)*aHSVColor.getBlue());
++        }
++        else if( nLuminance < 0 )
++        {
++            aHSVColor.setBlue(
++                (1.0+nLuminance/100.0)*aHSVColor.getBlue());
++        }
++
++        aHSVColor = basegfx::tools::hsv2rgb(aHSVColor);
++		aRetColor = Color( (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(aHSVColor.getRed(),0.0,1.0) * 255.0 + 0.5 ), 
++                           (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(aHSVColor.getGreen(),0.0,1.0) * 255.0 + 0.5 ),
++                           (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(aHSVColor.getBlue(),0.0,1.0) * 255.0 + 0.5 ) );
+ 	}
+ 	return aRetColor;
+ }
+@@ -1713,6 +1719,16 @@ void EnhancedCustomShape2d::CreateSubPath( sal_uInt16& rSrcPt, sal_uInt16& rSegm
+ 
+ 	if(aNewB2DPolyPolygon.count())
+ 	{
++        // hack aNewB2DPolyPolygon to fill logic rect
++        aNewB2DPolygon.clear();
++        aNewB2DPolygon.append(basegfx::B2DPoint(0,0));
++        aNewB2DPolyPolygon.append(aNewB2DPolygon);
++
++        aNewB2DPolygon.clear();
++        aNewB2DPolygon.append(basegfx::B2DPoint(aLogicRect.GetWidth(),
++                                                aLogicRect.GetHeight()));
++        aNewB2DPolyPolygon.append(aNewB2DPolygon);
++
+ 		// #i37011#
+ 		bool bForceCreateTwoObjects(false);
+ 
+@@ -1882,6 +1898,51 @@ void CorrectCalloutArrows( MSO_SPT eSpType, sal_uInt32 nLineObjectCount, std::ve
+ 	}
+ }
+ 
++void EnhancedCustomShape2d::AdaptObjColor(SdrPathObj& rObj, const SfxItemSet& rCustomShapeSet, 
++                                          sal_uInt32& nColorIndex, sal_uInt32 nColorCount)
++{
++    if ( !rObj.IsLine() )
++    {
++        const XFillStyle eFillStyle = ((const XFillStyleItem&)rObj.GetMergedItem(XATTR_FILLSTYLE)).GetValue();
++        switch( eFillStyle )
++        {
++            default:
++            case XFILL_SOLID:
++            {
++                Color aFillColor;
++                if ( nColorCount )
++                {
++                    aFillColor = GetColorData( 
++                        ((XFillColorItem&)rCustomShapeSet.Get( XATTR_FILLCOLOR )).GetColorValue(), 
++                        std::min(nColorIndex, nColorCount-1) );
++                    rObj.SetMergedItem( XFillColorItem( String(), aFillColor ) );
++                }
++                break;
++            }
++            case XFILL_GRADIENT:
++            {
++                XGradient aXGradient(((const XFillGradientItem&)rObj.GetMergedItem(XATTR_FILLGRADIENT)).GetGradientValue());
++                if ( nColorCount )
++                {
++                    aXGradient.SetStartColor(
++                        GetColorData(
++                            aXGradient.GetStartColor(), 
++                            std::min(nColorIndex, nColorCount-1) ));
++                    aXGradient.SetEndColor(
++                        GetColorData(
++                            aXGradient.GetEndColor(), 
++                            std::min(nColorIndex, nColorCount-1) ));
++                }
++
++                rObj.SetMergedItem( XFillGradientItem( String(), aXGradient ) );
++                break;
++            }
++        }
++
++        if ( nColorIndex < nColorCount )
++            nColorIndex++;
++    }
++}
+ 
+ SdrObject* EnhancedCustomShape2d::CreatePathObj( sal_Bool bLineGeometryNeededOnly )
+ {
+@@ -1906,18 +1967,10 @@ SdrObject* EnhancedCustomShape2d::CreatePathObj( sal_Bool bLineGeometryNeededOnl
+ 	if ( vObjectList.size() )
+ 	{
+ 		const SfxItemSet& rCustomShapeSet = pCustomShapeObj->GetMergedItemSet();
+-		// For primitive rendering, shadow handling is done completely based on the geometry, so i removed it here
+-		// const sal_Bool	bShadow(((SdrShadowItem&)rCustomShapeSet.Get( SDRATTR_SHADOW )).GetValue());
+-		Color			aBasicColor( COL_WHITE );
+ 		Color			aFillColor;
+ 		sal_uInt32		nColorCount = nColorData >> 28;
+ 		sal_uInt32		nColorIndex	= 0;
+ 
+-		if ( nColorCount )
+-		{
+-			aBasicColor = ((XFillColorItem&)rCustomShapeSet.Get( XATTR_FILLCOLOR )).GetColorValue();
+-		}
+-
+ 		// #i37011# remove invisible objects
+ 		if(vObjectList.size())
+ 		{
+@@ -1927,7 +1980,7 @@ SdrObject* EnhancedCustomShape2d::CreatePathObj( sal_Bool bLineGeometryNeededOnl
+ 			{
+ 				SdrPathObj* pObj(vObjectList[i]);
+ 				const XLineStyle eLineStyle = ((const XLineStyleItem&)pObj->GetMergedItem(XATTR_LINESTYLE)).GetValue();
+-				const XFillStyle eFillStyle = ((const XFillStyleItem&)pObj->GetMergedItem(XATTR_FILLSTYLE)).GetValue();
++                const XFillStyle eFillStyle = ((const XFillStyleItem&)pObj->GetMergedItem(XATTR_FILLSTYLE)).GetValue();
+ 
+ 				//SJ: #i40600# if bLineGeometryNeededOnly is set linystyle does not matter
+ 				if( !bLineGeometryNeededOnly && ( XLINE_NONE == eLineStyle ) && ( XFILL_NONE == eFillStyle ) )
+@@ -1942,26 +1995,7 @@ SdrObject* EnhancedCustomShape2d::CreatePathObj( sal_Bool bLineGeometryNeededOnl
+ 		if(1L == vObjectList.size())
+ 		{
+ 			// a single object, correct some values
+-			SdrPathObj* pObj(vObjectList[0L]);
+-
+-// For primitive rendering, shadow handling is done completely based on the geometry, so i removed it here
+-//			if(bShadow)
+-//			{
+-//				pObj->SetMergedItem(SdrShadowItem(sal_True));
+-//			}
+-
+-			if(!pObj->IsLine())
+-			{
+-				if ( nColorIndex < nColorCount )
+-				{
+-					aFillColor = GetColorData( aBasicColor, nColorIndex++ );
+-				}
+-
+-				if ( nColorCount )
+-				{
+-					pObj->SetMergedItem( XFillColorItem( String(), aFillColor ) );
+-				}
+-			}
++            AdaptObjColor(*vObjectList[0L],rCustomShapeSet,nColorIndex,nColorCount);
+ 		}
+ 		else
+ 		{
+@@ -1980,16 +2014,7 @@ SdrObject* EnhancedCustomShape2d::CreatePathObj( sal_Bool bLineGeometryNeededOnl
+ 				else
+ 				{
+ 					nAreaObjectCount++;
+-
+-					if ( nColorIndex < nColorCount )
+-					{
+-						aFillColor = GetColorData( aBasicColor, nColorIndex++ );
+-					}
+-
+-					if ( nColorCount )
+-					{
+-						pObj->SetMergedItem( XFillColorItem( String(), aFillColor ) );
+-					}
++                    AdaptObjColor(*pObj,rCustomShapeSet,nColorIndex,nColorCount);
+ 				}
+ 			}
+ 
+diff --git svx/source/customshapes/EnhancedCustomShape2d.hxx svx/source/customshapes/EnhancedCustomShape2d.hxx
+index 9d0f04b..077bce0 100644
+--- svx/source/customshapes/EnhancedCustomShape2d.hxx
++++ svx/source/customshapes/EnhancedCustomShape2d.hxx
+@@ -121,6 +121,8 @@ class EnhancedCustomShape2d : public SfxItemSet
+ 
+ 		sal_Bool					SetAdjustValueAsDouble( const double& rValue, const sal_Int32 nIndex );
+ 		Color						GetColorData( const Color& rFillColor, sal_uInt32 nIndex );
++        void                        AdaptObjColor(SdrPathObj& rObj, const SfxItemSet& rCustomShapeSet, 
++                                                  sal_uInt32& nColorIndex, sal_uInt32 nColorCount);
+ 		sal_Bool					GetParameter( double& rParameterReturnValue,  const com::sun::star::drawing::EnhancedCustomShapeParameter&,
+ 													const sal_Bool bReplaceGeoWidth, const sal_Bool bReplaceGeoHeight ) const;
+ 		Point						GetPoint( const com::sun::star::drawing::EnhancedCustomShapeParameterPair&,
+diff --git svx/source/msfilter/msdffimp.cxx svx/source/msfilter/msdffimp.cxx
+index 05ae58c..cf4a5df 100644
+--- svx/source/msfilter/msdffimp.cxx
++++ svx/source/msfilter/msdffimp.cxx
+@@ -1668,12 +1668,7 @@ void DffPropertyReader::ApplyFillAttributes( SvStream& rIn, SfxItemSet& rSet, co
+ 			XGradientStyle eGrad = XGRAD_LINEAR;
+ 			sal_Int32 nChgColors = 0;
+ 
+-			if ( !nAngle )
+-				nChgColors ^= 1;
+-
+-			if ( !nFocus )
+-				nChgColors ^= 1;
+-			else if ( nFocus < 0 )		// Bei negativem Focus sind die Farben zu tauschen
++			if ( nFocus < 0 )		// Bei negativem Focus sind die Farben zu tauschen
+ 			{
+ 				nFocus =- nFocus;
+ 				nChgColors ^= 1;
+@@ -1681,8 +1676,8 @@ void DffPropertyReader::ApplyFillAttributes( SvStream& rIn, SfxItemSet& rSet, co
+ 			if( nFocus > 40 && nFocus < 60 )
+ 			{
+ 				eGrad = XGRAD_AXIAL;	// Besser gehts leider nicht
+-				nChgColors ^= 1;
+ 			}
++
+ 			USHORT nFocusX = (USHORT)nFocus;
+ 			USHORT nFocusY = (USHORT)nFocus;
+ 


More information about the ooo-build-commit mailing list