1 Fix the custom shape gradient behaviour, plus shaded fill colors
3 From: Thorsten Behrens <thb@openoffice.org>
8 svx/source/customshapes/EnhancedCustomShape2d.cxx | 248 +++++++++++++--------
9 svx/source/customshapes/EnhancedCustomShape2d.hxx | 5
10 svx/source/msfilter/msdffimp.cxx | 9 -
11 3 files changed, 160 insertions(+), 102 deletions(-)
14 diff --git svx/source/customshapes/EnhancedCustomShape2d.cxx svx/source/customshapes/EnhancedCustomShape2d.cxx
15 index 0361511..796cd40 100644
16 --- svx/source/customshapes/EnhancedCustomShape2d.cxx
17 +++ svx/source/customshapes/EnhancedCustomShape2d.cxx
19 #include <svx/xlnedwit.hxx>
20 #include <svx/xlnstcit.hxx>
21 #include <svx/xlnedcit.hxx>
22 +#include <svx/xflgrit.hxx>
23 +#include <svx/xflhtit.hxx>
24 +#include <svx/xbtmpit.hxx>
25 +#include <svx/xgrad.hxx>
26 +#include <svx/xbitmap.hxx>
27 +#include <svx/xhatch.hxx>
28 #include <com/sun/star/awt/Size.hpp>
29 #include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
30 #ifndef __COM_SUN_STAR_DRAWING_ENHANCEDCUSTOMSHAPESEGMENTCOMMAND_HPP__
32 #include <boost/shared_ptr.hpp>
34 #include <basegfx/numeric/ftools.hxx>
35 +#include <basegfx/color/bcolortools.hxx>
36 #include <basegfx/polygon/b2dpolygon.hxx>
39 @@ -724,23 +731,23 @@ EnhancedCustomShape2d::EnhancedCustomShape2d( SdrObject* pAObj ) :
40 /*const sal_Int32* pDefData =*/ ApplyShapeAttributes( rGeometryItem );
43 - case mso_sptCan : nColorData = 0x20200000; break;
44 - case mso_sptCube : nColorData = 0x302d0000; break;
45 - case mso_sptActionButtonBlank : nColorData = 0x502ad400; break;
46 - case mso_sptActionButtonHome : nColorData = 0x702ad4ad; break;
47 - case mso_sptActionButtonHelp : nColorData = 0x602ad4a0; break;
48 - case mso_sptActionButtonInformation : nColorData = 0x702ad4a5; break;
49 - case mso_sptActionButtonBackPrevious : nColorData = 0x602ad4a0; break;
50 - case mso_sptActionButtonForwardNext : nColorData = 0x602ad4a0; break;
51 - case mso_sptActionButtonBeginning : nColorData = 0x602ad4a0; break;
52 - case mso_sptActionButtonEnd : nColorData = 0x602ad4a0; break;
53 - case mso_sptActionButtonReturn : nColorData = 0x602ad4a0; break;
54 - case mso_sptActionButtonDocument : nColorData = 0x702ad4da; break;
55 - case mso_sptActionButtonSound : nColorData = 0x602ad4a0; break;
56 - case mso_sptActionButtonMovie : nColorData = 0x602ad4a0; break;
57 - case mso_sptBevel : nColorData = 0x502ad400; break;
58 - case mso_sptFoldedCorner : nColorData = 0x20d00000; break;
59 - case mso_sptSmileyFace : nColorData = 0x20d00000; break;
60 + case mso_sptCan : nColorData = 0x20400000; break;
61 + case mso_sptCube : nColorData = 0x302e0000; break;
62 + case mso_sptActionButtonBlank : nColorData = 0x502ce400; break;
63 + case mso_sptActionButtonHome : nColorData = 0x702ce4ce; break;
64 + case mso_sptActionButtonHelp : nColorData = 0x602ce4c0; break;
65 + case mso_sptActionButtonInformation : nColorData = 0x702ce4c5; break;
66 + case mso_sptActionButtonBackPrevious : nColorData = 0x602ce4c0; break;
67 + case mso_sptActionButtonForwardNext : nColorData = 0x602ce4c0; break;
68 + case mso_sptActionButtonBeginning : nColorData = 0x602ce4c0; break;
69 + case mso_sptActionButtonEnd : nColorData = 0x602ce4c0; break;
70 + case mso_sptActionButtonReturn : nColorData = 0x602ce4c0; break;
71 + case mso_sptActionButtonDocument : nColorData = 0x702ce4ec; break;
72 + case mso_sptActionButtonSound : nColorData = 0x602ce4c0; break;
73 + case mso_sptActionButtonMovie : nColorData = 0x602ce4c0; break;
74 + case mso_sptBevel : nColorData = 0x502ce400; break;
75 + case mso_sptFoldedCorner : nColorData = 0x20e00000; break;
76 + case mso_sptSmileyFace : nColorData = 0x20e00000; break;
79 if( sShapeType.getLength() > 4 &&
80 @@ -775,7 +782,7 @@ EnhancedCustomShape2d::EnhancedCustomShape2d( SdrObject* pAObj ) :
83 case mso_sptCurvedDownArrow : nFlags |= DFF_CUSTOMSHAPE_EXCH; break;
84 - case mso_sptRibbon2 : nColorData = 0x30dd0000; break;
85 + case mso_sptRibbon2 : nColorData = 0x30ee0000; break;
88 if ( ( seqAdjustmentValues.getLength() > 1 ) && ( seqAdjustmentValues[ 1 ].State == com::sun::star::beans::PropertyState_DIRECT_VALUE ) )
89 @@ -786,10 +793,10 @@ EnhancedCustomShape2d::EnhancedCustomShape2d( SdrObject* pAObj ) :
90 seqAdjustmentValues[ 1 ].Value <<= fValue;
92 nFlags |= DFF_CUSTOMSHAPE_FLIP_V;
93 - nColorData = 0x30dd0000;
94 + nColorData = 0x30ee0000;
97 - case mso_sptEllipseRibbon2 : nColorData = 0x30dd0000; break;
98 + case mso_sptEllipseRibbon2 : nColorData = 0x30ee0000; break;
99 case mso_sptEllipseRibbon : // !!!!!!!!!!
101 if ( ( seqAdjustmentValues.getLength() > 1 ) && ( seqAdjustmentValues[ 1 ].State == com::sun::star::beans::PropertyState_DIRECT_VALUE ) )
102 @@ -800,11 +807,11 @@ EnhancedCustomShape2d::EnhancedCustomShape2d( SdrObject* pAObj ) :
103 seqAdjustmentValues[ 1 ].Value <<= fValue;
105 nFlags |= DFF_CUSTOMSHAPE_FLIP_V;
106 - nColorData = 0x30dd0000;
107 + nColorData = 0x30ee0000;
110 - case mso_sptVerticalScroll : nColorData = 0x30dd0000; break;
111 - case mso_sptHorizontalScroll : nColorData = 0x30dd0000; break;
112 + case mso_sptVerticalScroll : nColorData = 0x30ee0000; break;
113 + case mso_sptHorizontalScroll : nColorData = 0x30ee0000; break;
117 @@ -1065,41 +1072,48 @@ sal_Bool EnhancedCustomShape2d::GetParameter( double& rRetValue, const EnhancedC
118 // nLumDat 27-24 = nLumDatEntry 0
119 // nLumDat 23-20 = nLumDatEntry 1 ...
120 // each 4bit entry is to be interpreted as a 10 percent signed luminance changing
121 -Color EnhancedCustomShape2d::GetColorData( const Color& rFillColor, sal_uInt32 nIndex )
122 +sal_Int32 EnhancedCustomShape2d::GetLuminanceChange( sal_uInt32 nIndex ) const
125 + const sal_uInt32 nCount = nColorData >> 28;
129 - sal_uInt32 i, nColor, nTmp, nCount = nColorData >> 28;
130 + if ( nIndex >= nCount )
131 + nIndex = nCount - 1;
135 - if ( nIndex >= nCount )
136 - nIndex = nCount - 1;
138 - sal_uInt32 nFillColor = (sal_uInt32)rFillColor.GetRed() |
139 - ((sal_uInt32)rFillColor.GetGreen() << 8 ) |
140 - ((sal_uInt32)rFillColor.GetBlue() << 16 );
142 - sal_Int32 nLumDat = nColorData << ( ( 1 + nIndex ) << 2 );
143 - sal_Int32 nLuminance = ( nLumDat >> 28 ) * 12;
147 - for ( i = 0; i < 3; i++ )
149 - sal_Int32 nC = (sal_uInt8)nTmp;
151 - nC += ( ( nLuminance * nC ) >> 8 );
154 - else if ( nC &~ 0xff )
157 - nColor |= nC << 16;
159 - aRetColor = Color( (sal_uInt8)nColor, (sal_uInt8)( nColor >> 8 ), (sal_uInt8)( nColor >> 16 ) );
162 + const sal_Int32 nLumDat = nColorData << ( ( 1 + nIndex ) << 2 );
163 + return ( nLumDat >> 28 ) * 10;
166 +Color EnhancedCustomShape2d::GetColorData( const Color& rFillColor, sal_uInt32 nIndex ) const
168 + const sal_Int32 nLuminance = GetLuminanceChange(nIndex);
172 + basegfx::BColor aHSVColor=
173 + basegfx::tools::rgb2hsv(
174 + basegfx::BColor(rFillColor.GetRed()/255.0,
175 + rFillColor.GetGreen()/255.0,
176 + rFillColor.GetBlue()/255.0));
177 + if( nLuminance > 0 )
179 + aHSVColor.setGreen(
180 + aHSVColor.getGreen() * (1.0-nLuminance/100.0));
183 + (1.0-nLuminance/100.0)*aHSVColor.getBlue());
185 + else if( nLuminance < 0 )
188 + (1.0+nLuminance/100.0)*aHSVColor.getBlue());
191 + aHSVColor = basegfx::tools::hsv2rgb(aHSVColor);
192 + return Color( (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(aHSVColor.getRed(),0.0,1.0) * 255.0 + 0.5 ),
193 + (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(aHSVColor.getGreen(),0.0,1.0) * 255.0 + 0.5 ),
194 + (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(aHSVColor.getBlue(),0.0,1.0) * 255.0 + 0.5 ) );
197 Rectangle EnhancedCustomShape2d::GetTextRect() const
198 @@ -1713,6 +1727,16 @@ void EnhancedCustomShape2d::CreateSubPath( sal_uInt16& rSrcPt, sal_uInt16& rSegm
200 if(aNewB2DPolyPolygon.count())
202 + // hack aNewB2DPolyPolygon to fill logic rect
203 + aNewB2DPolygon.clear();
204 + aNewB2DPolygon.append(basegfx::B2DPoint(0,0));
205 + aNewB2DPolyPolygon.append(aNewB2DPolygon);
207 + aNewB2DPolygon.clear();
208 + aNewB2DPolygon.append(basegfx::B2DPoint(aLogicRect.GetWidth(),
209 + aLogicRect.GetHeight()));
210 + aNewB2DPolyPolygon.append(aNewB2DPolygon);
213 bool bForceCreateTwoObjects(false);
215 @@ -1882,6 +1906,78 @@ void CorrectCalloutArrows( MSO_SPT eSpType, sal_uInt32 nLineObjectCount, std::ve
219 +void EnhancedCustomShape2d::AdaptObjColor(SdrPathObj& rObj, const SfxItemSet& rCustomShapeSet,
220 + sal_uInt32& nColorIndex, sal_uInt32 nColorCount)
222 + if ( !rObj.IsLine() )
224 + const XFillStyle eFillStyle = ((const XFillStyleItem&)rObj.GetMergedItem(XATTR_FILLSTYLE)).GetValue();
225 + switch( eFillStyle )
233 + aFillColor = GetColorData(
234 + ((XFillColorItem&)rCustomShapeSet.Get( XATTR_FILLCOLOR )).GetColorValue(),
235 + std::min(nColorIndex, nColorCount-1) );
236 + rObj.SetMergedItem( XFillColorItem( String(), aFillColor ) );
240 + case XFILL_GRADIENT:
242 + XGradient aXGradient(((const XFillGradientItem&)rObj.GetMergedItem(XATTR_FILLGRADIENT)).GetGradientValue());
245 + aXGradient.SetStartColor(
247 + aXGradient.GetStartColor(),
248 + std::min(nColorIndex, nColorCount-1) ));
249 + aXGradient.SetEndColor(
251 + aXGradient.GetEndColor(),
252 + std::min(nColorIndex, nColorCount-1) ));
255 + rObj.SetMergedItem( XFillGradientItem( String(), aXGradient ) );
260 + XHatch aXHatch(((const XFillHatchItem&)rObj.GetMergedItem(XATTR_FILLHATCH)).GetHatchValue());
265 + aXHatch.GetColor(),
266 + std::min(nColorIndex, nColorCount-1) ));
269 + rObj.SetMergedItem( XFillHatchItem( String(), aXHatch ) );
274 + Bitmap aBitmap(((const XFillBitmapItem&)rObj.GetMergedItem(XATTR_FILLBITMAP)).GetBitmapValue().GetBitmap());
278 + GetLuminanceChange(
279 + std::min(nColorIndex, nColorCount-1)));
282 + rObj.SetMergedItem( XFillBitmapItem( String(), aBitmap ) );
287 + if ( nColorIndex < nColorCount )
292 SdrObject* EnhancedCustomShape2d::CreatePathObj( sal_Bool bLineGeometryNeededOnly )
294 @@ -1906,18 +2002,10 @@ SdrObject* EnhancedCustomShape2d::CreatePathObj( sal_Bool bLineGeometryNeededOnl
295 if ( vObjectList.size() )
297 const SfxItemSet& rCustomShapeSet = pCustomShapeObj->GetMergedItemSet();
298 - // For primitive rendering, shadow handling is done completely based on the geometry, so i removed it here
299 - // const sal_Bool bShadow(((SdrShadowItem&)rCustomShapeSet.Get( SDRATTR_SHADOW )).GetValue());
300 - Color aBasicColor( COL_WHITE );
302 sal_uInt32 nColorCount = nColorData >> 28;
303 sal_uInt32 nColorIndex = 0;
307 - aBasicColor = ((XFillColorItem&)rCustomShapeSet.Get( XATTR_FILLCOLOR )).GetColorValue();
310 // #i37011# remove invisible objects
311 if(vObjectList.size())
313 @@ -1927,7 +2015,7 @@ SdrObject* EnhancedCustomShape2d::CreatePathObj( sal_Bool bLineGeometryNeededOnl
315 SdrPathObj* pObj(vObjectList[i]);
316 const XLineStyle eLineStyle = ((const XLineStyleItem&)pObj->GetMergedItem(XATTR_LINESTYLE)).GetValue();
317 - const XFillStyle eFillStyle = ((const XFillStyleItem&)pObj->GetMergedItem(XATTR_FILLSTYLE)).GetValue();
318 + const XFillStyle eFillStyle = ((const XFillStyleItem&)pObj->GetMergedItem(XATTR_FILLSTYLE)).GetValue();
320 //SJ: #i40600# if bLineGeometryNeededOnly is set linystyle does not matter
321 if( !bLineGeometryNeededOnly && ( XLINE_NONE == eLineStyle ) && ( XFILL_NONE == eFillStyle ) )
322 @@ -1942,26 +2030,7 @@ SdrObject* EnhancedCustomShape2d::CreatePathObj( sal_Bool bLineGeometryNeededOnl
323 if(1L == vObjectList.size())
325 // a single object, correct some values
326 - SdrPathObj* pObj(vObjectList[0L]);
328 -// For primitive rendering, shadow handling is done completely based on the geometry, so i removed it here
331 -// pObj->SetMergedItem(SdrShadowItem(sal_True));
334 - if(!pObj->IsLine())
336 - if ( nColorIndex < nColorCount )
338 - aFillColor = GetColorData( aBasicColor, nColorIndex++ );
343 - pObj->SetMergedItem( XFillColorItem( String(), aFillColor ) );
346 + AdaptObjColor(*vObjectList[0L],rCustomShapeSet,nColorIndex,nColorCount);
350 @@ -1980,16 +2049,7 @@ SdrObject* EnhancedCustomShape2d::CreatePathObj( sal_Bool bLineGeometryNeededOnl
355 - if ( nColorIndex < nColorCount )
357 - aFillColor = GetColorData( aBasicColor, nColorIndex++ );
362 - pObj->SetMergedItem( XFillColorItem( String(), aFillColor ) );
364 + AdaptObjColor(*pObj,rCustomShapeSet,nColorIndex,nColorCount);
368 diff --git svx/source/customshapes/EnhancedCustomShape2d.hxx svx/source/customshapes/EnhancedCustomShape2d.hxx
369 index 9d0f04b..fc28b3d 100644
370 --- svx/source/customshapes/EnhancedCustomShape2d.hxx
371 +++ svx/source/customshapes/EnhancedCustomShape2d.hxx
372 @@ -120,7 +120,10 @@ class EnhancedCustomShape2d : public SfxItemSet
373 sal_Int32 nRotateAngle;
375 sal_Bool SetAdjustValueAsDouble( const double& rValue, const sal_Int32 nIndex );
376 - Color GetColorData( const Color& rFillColor, sal_uInt32 nIndex );
377 + sal_Int32 GetLuminanceChange( sal_uInt32 nIndex ) const;
378 + Color GetColorData( const Color& rFillColor, sal_uInt32 nIndex ) const;
379 + void AdaptObjColor(SdrPathObj& rObj, const SfxItemSet& rCustomShapeSet,
380 + sal_uInt32& nColorIndex, sal_uInt32 nColorCount);
381 sal_Bool GetParameter( double& rParameterReturnValue, const com::sun::star::drawing::EnhancedCustomShapeParameter&,
382 const sal_Bool bReplaceGeoWidth, const sal_Bool bReplaceGeoHeight ) const;
383 Point GetPoint( const com::sun::star::drawing::EnhancedCustomShapeParameterPair&,
384 diff --git svx/source/msfilter/msdffimp.cxx svx/source/msfilter/msdffimp.cxx
385 index 05ae58c..cf4a5df 100644
386 --- svx/source/msfilter/msdffimp.cxx
387 +++ svx/source/msfilter/msdffimp.cxx
388 @@ -1668,12 +1668,7 @@ void DffPropertyReader::ApplyFillAttributes( SvStream& rIn, SfxItemSet& rSet, co
389 XGradientStyle eGrad = XGRAD_LINEAR;
390 sal_Int32 nChgColors = 0;
397 - else if ( nFocus < 0 ) // Bei negativem Focus sind die Farben zu tauschen
398 + if ( nFocus < 0 ) // Bei negativem Focus sind die Farben zu tauschen
402 @@ -1681,8 +1676,8 @@ void DffPropertyReader::ApplyFillAttributes( SvStream& rIn, SfxItemSet& rSet, co
403 if( nFocus > 40 && nFocus < 60 )
405 eGrad = XGRAD_AXIAL; // Besser gehts leider nicht
409 USHORT nFocusX = (USHORT)nFocus;
410 USHORT nFocusY = (USHORT)nFocus;