1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_svx.hxx" 24 25 // include --------------------------------------------------------------- 26 #include <com/sun/star/container/XNameContainer.hpp> 27 #include "svx/XPropertyTable.hxx" 28 #include <unotools/ucbstreamhelper.hxx> 29 #include "xmlxtexp.hxx" 30 #include "xmlxtimp.hxx" 31 #include <tools/urlobj.hxx> 32 #include <vcl/virdev.hxx> 33 #include <svx/dialogs.hrc> 34 #include <svx/dialmgr.hxx> 35 #include <svx/xtable.hxx> 36 #include <vcl/svapp.hxx> 37 #include <drawinglayer/attribute/fillgradientattribute.hxx> 38 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> 39 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 40 #include <drawinglayer/processor2d/processor2dtools.hxx> 41 #include <basegfx/polygon/b2dpolygontools.hxx> 42 43 #define GLOBALOVERFLOW 44 45 using namespace com::sun::star; 46 using namespace rtl; 47 48 sal_Unicode const pszExtGradient[] = {'s','o','g'}; 49 //char const aChckGradient[] = { 0x04, 0x00, 'S','O','G','L'}; // < 5.2 50 //char const aChckGradient0[] = { 0x04, 0x00, 'S','O','G','0'}; // = 5.2 51 //char const aChckXML[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0 52 53 // -------------------- 54 // class XGradientList 55 // -------------------- 56 57 XGradientList::XGradientList( const String& rPath ) 58 : XPropertyList(rPath ) 59 { 60 } 61 62 XGradientList::~XGradientList() 63 { 64 } 65 66 XGradientEntry* XGradientList::Replace(XGradientEntry* pEntry, long nIndex ) 67 { 68 return( (XGradientEntry*) XPropertyList::Replace( pEntry, nIndex ) ); 69 } 70 71 XGradientEntry* XGradientList::Remove(long nIndex) 72 { 73 return( (XGradientEntry*) XPropertyList::Remove( nIndex ) ); 74 } 75 76 XGradientEntry* XGradientList::GetGradient(long nIndex) const 77 { 78 return( (XGradientEntry*) XPropertyList::Get( nIndex ) ); 79 } 80 81 sal_Bool XGradientList::Load() 82 { 83 if( mbListDirty ) 84 { 85 mbListDirty = false; 86 87 INetURLObject aURL( maPath ); 88 89 if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 90 { 91 DBG_ASSERT( !maPath.Len(), "invalid URL" ); 92 return sal_False; 93 } 94 95 aURL.Append( maName ); 96 97 if( !aURL.getExtension().getLength() ) 98 aURL.setExtension( rtl::OUString( pszExtGradient, 3 ) ); 99 100 uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY ); 101 return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 102 103 } 104 return( sal_False ); 105 } 106 107 sal_Bool XGradientList::Save() 108 { 109 INetURLObject aURL( maPath ); 110 111 if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 112 { 113 DBG_ASSERT( !maPath.Len(), "invalid URL" ); 114 return sal_False; 115 } 116 117 aURL.Append( maName ); 118 119 if( !aURL.getExtension().getLength() ) 120 aURL.setExtension( rtl::OUString( pszExtGradient, 3 ) ); 121 122 uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY ); 123 return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 124 } 125 126 sal_Bool XGradientList::Create() 127 { 128 XubString aStr( SVX_RES( RID_SVXSTR_GRADIENT ) ); 129 xub_StrLen nLen; 130 131 aStr.AppendAscii(" 1"); 132 nLen = aStr.Len() - 1; 133 Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLACK ),RGB_Color(COL_WHITE ),XGRAD_LINEAR , 0,10,10, 0,100,100),aStr)); 134 aStr.SetChar(nLen, sal_Unicode('2')); 135 Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLUE ),RGB_Color(COL_RED ),XGRAD_AXIAL , 300,20,20,10,100,100),aStr)); 136 aStr.SetChar(nLen, sal_Unicode('3')); 137 Insert(new XGradientEntry(XGradient(RGB_Color(COL_RED ),RGB_Color(COL_YELLOW ),XGRAD_RADIAL , 600,30,30,20,100,100),aStr)); 138 aStr.SetChar(nLen, sal_Unicode('4')); 139 Insert(new XGradientEntry(XGradient(RGB_Color(COL_YELLOW ),RGB_Color(COL_GREEN ),XGRAD_ELLIPTICAL, 900,40,40,30,100,100),aStr)); 140 aStr.SetChar(nLen, sal_Unicode('5')); 141 Insert(new XGradientEntry(XGradient(RGB_Color(COL_GREEN ),RGB_Color(COL_MAGENTA),XGRAD_SQUARE , 1200,50,50,40,100,100),aStr)); 142 aStr.SetChar(nLen, sal_Unicode('6')); 143 Insert(new XGradientEntry(XGradient(RGB_Color(COL_MAGENTA),RGB_Color(COL_YELLOW ),XGRAD_RECT , 1900,60,60,50,100,100),aStr)); 144 145 return( sal_True ); 146 } 147 148 Bitmap XGradientList::CreateBitmapForUI(long nIndex) 149 { 150 Bitmap aRetval; 151 OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)"); 152 153 if(nIndex < Count()) 154 { 155 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 156 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize(); 157 158 // prepare polygon geometry for rectangle 159 const basegfx::B2DPolygon aRectangle( 160 basegfx::tools::createPolygonFromRect( 161 basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height()))); 162 163 const XGradient& rGradient = GetGradient(nIndex)->GetGradient(); 164 const sal_uInt16 nStartIntens(rGradient.GetStartIntens()); 165 basegfx::BColor aStart(rGradient.GetStartColor().getBColor()); 166 167 if(nStartIntens != 100) 168 { 169 const basegfx::BColor aBlack; 170 aStart = interpolate(aBlack, aStart, (double)nStartIntens * 0.01); 171 } 172 173 const sal_uInt16 nEndIntens(rGradient.GetEndIntens()); 174 basegfx::BColor aEnd(rGradient.GetEndColor().getBColor()); 175 176 if(nEndIntens != 100) 177 { 178 const basegfx::BColor aBlack; 179 aEnd = interpolate(aBlack, aEnd, (double)nEndIntens * 0.01); 180 } 181 182 drawinglayer::attribute::GradientStyle aGradientStyle(drawinglayer::attribute::GRADIENTSTYLE_RECT); 183 184 switch(rGradient.GetGradientStyle()) 185 { 186 case XGRAD_LINEAR : 187 { 188 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_LINEAR; 189 break; 190 } 191 case XGRAD_AXIAL : 192 { 193 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_AXIAL; 194 break; 195 } 196 case XGRAD_RADIAL : 197 { 198 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_RADIAL; 199 break; 200 } 201 case XGRAD_ELLIPTICAL : 202 { 203 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_ELLIPTICAL; 204 break; 205 } 206 case XGRAD_SQUARE : 207 { 208 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_SQUARE; 209 break; 210 } 211 default : 212 { 213 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_RECT; // XGRAD_RECT 214 break; 215 } 216 } 217 218 const sal_uInt16 nSteps((rSize.Width() + rSize.Height()) / 3); 219 const drawinglayer::attribute::FillGradientAttribute aFillGradient( 220 aGradientStyle, 221 (double)rGradient.GetBorder() * 0.01, 222 (double)rGradient.GetXOffset() * 0.01, 223 (double)rGradient.GetYOffset() * 0.01, 224 (double)rGradient.GetAngle() * F_PI1800, 225 aStart, 226 aEnd, 227 nSteps); 228 229 const drawinglayer::primitive2d::Primitive2DReference aGradientPrimitive( 230 new drawinglayer::primitive2d::PolyPolygonGradientPrimitive2D( 231 basegfx::B2DPolyPolygon(aRectangle), 232 aFillGradient)); 233 234 const basegfx::BColor aBlack(0.0, 0.0, 0.0); 235 const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive( 236 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D( 237 aRectangle, 238 aBlack)); 239 240 // prepare VirtualDevice 241 VirtualDevice aVirtualDevice; 242 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D; 243 244 aVirtualDevice.SetOutputSizePixel(rSize); 245 aVirtualDevice.SetDrawMode(rStyleSettings.GetHighContrastMode() 246 ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT 247 : DRAWMODE_DEFAULT); 248 249 // create processor and draw primitives 250 drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice( 251 aVirtualDevice, 252 aNewViewInformation2D); 253 254 if(pProcessor2D) 255 { 256 drawinglayer::primitive2d::Primitive2DSequence aSequence(2); 257 258 aSequence[0] = aGradientPrimitive; 259 aSequence[1] = aBlackRectanglePrimitive; 260 261 pProcessor2D->process(aSequence); 262 delete pProcessor2D; 263 } 264 265 // get result bitmap and scale 266 aRetval = aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel()); 267 } 268 269 return aRetval; 270 } 271 272 ////////////////////////////////////////////////////////////////////////////// 273 // eof 274