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 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 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 105 return false; 106 } 107 108 bool XGradientList::Save() 109 { 110 INetURLObject aURL( maPath ); 111 112 if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 113 { 114 DBG_ASSERT( !maPath.Len(), "invalid URL" ); 115 return false; 116 } 117 118 aURL.Append( maName ); 119 120 if( !aURL.getExtension().getLength() ) 121 aURL.setExtension( rtl::OUString( pszExtGradient, 3 ) ); 122 123 uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY ); 124 return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 125 } 126 127 bool XGradientList::Create() 128 { 129 XubString aStr( SVX_RES( RID_SVXSTR_GRADIENT ) ); 130 xub_StrLen nLen; 131 132 aStr.AppendAscii(" 1"); 133 nLen = aStr.Len() - 1; 134 Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLACK ),RGB_Color(COL_WHITE ),XGRAD_LINEAR , 0,10,10, 0,100,100),aStr)); 135 aStr.SetChar(nLen, sal_Unicode('2')); 136 Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLUE ),RGB_Color(COL_RED ),XGRAD_AXIAL , 300,20,20,10,100,100),aStr)); 137 aStr.SetChar(nLen, sal_Unicode('3')); 138 Insert(new XGradientEntry(XGradient(RGB_Color(COL_RED ),RGB_Color(COL_YELLOW ),XGRAD_RADIAL , 600,30,30,20,100,100),aStr)); 139 aStr.SetChar(nLen, sal_Unicode('4')); 140 Insert(new XGradientEntry(XGradient(RGB_Color(COL_YELLOW ),RGB_Color(COL_GREEN ),XGRAD_ELLIPTICAL, 900,40,40,30,100,100),aStr)); 141 aStr.SetChar(nLen, sal_Unicode('5')); 142 Insert(new XGradientEntry(XGradient(RGB_Color(COL_GREEN ),RGB_Color(COL_MAGENTA),XGRAD_SQUARE , 1200,50,50,40,100,100),aStr)); 143 aStr.SetChar(nLen, sal_Unicode('6')); 144 Insert(new XGradientEntry(XGradient(RGB_Color(COL_MAGENTA),RGB_Color(COL_YELLOW ),XGRAD_RECT , 1900,60,60,50,100,100),aStr)); 145 146 return true; 147 } 148 149 Bitmap XGradientList::CreateBitmapForUI(long nIndex) 150 { 151 Bitmap aRetval; 152 OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)"); 153 154 if(nIndex < Count()) 155 { 156 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 157 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize(); 158 159 // prepare polygon geometry for rectangle 160 const basegfx::B2DPolygon aRectangle( 161 basegfx::tools::createPolygonFromRect( 162 basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height()))); 163 164 const XGradient& rGradient = GetGradient(nIndex)->GetGradient(); 165 const sal_uInt16 nStartIntens(rGradient.GetStartIntens()); 166 basegfx::BColor aStart(rGradient.GetStartColor().getBColor()); 167 168 if(nStartIntens != 100) 169 { 170 const basegfx::BColor aBlack; 171 aStart = interpolate(aBlack, aStart, (double)nStartIntens * 0.01); 172 } 173 174 const sal_uInt16 nEndIntens(rGradient.GetEndIntens()); 175 basegfx::BColor aEnd(rGradient.GetEndColor().getBColor()); 176 177 if(nEndIntens != 100) 178 { 179 const basegfx::BColor aBlack; 180 aEnd = interpolate(aBlack, aEnd, (double)nEndIntens * 0.01); 181 } 182 183 drawinglayer::attribute::GradientStyle aGradientStyle(drawinglayer::attribute::GRADIENTSTYLE_RECT); 184 185 switch(rGradient.GetGradientStyle()) 186 { 187 case XGRAD_LINEAR : 188 { 189 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_LINEAR; 190 break; 191 } 192 case XGRAD_AXIAL : 193 { 194 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_AXIAL; 195 break; 196 } 197 case XGRAD_RADIAL : 198 { 199 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_RADIAL; 200 break; 201 } 202 case XGRAD_ELLIPTICAL : 203 { 204 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_ELLIPTICAL; 205 break; 206 } 207 case XGRAD_SQUARE : 208 { 209 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_SQUARE; 210 break; 211 } 212 default : 213 { 214 aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_RECT; // XGRAD_RECT 215 break; 216 } 217 } 218 219 const sal_uInt16 nSteps((rSize.Width() + rSize.Height()) / 3); 220 const drawinglayer::attribute::FillGradientAttribute aFillGradient( 221 aGradientStyle, 222 (double)rGradient.GetBorder() * 0.01, 223 (double)rGradient.GetXOffset() * 0.01, 224 (double)rGradient.GetYOffset() * 0.01, 225 (double)rGradient.GetAngle() * F_PI1800, 226 aStart, 227 aEnd, 228 nSteps); 229 230 const drawinglayer::primitive2d::Primitive2DReference aGradientPrimitive( 231 new drawinglayer::primitive2d::PolyPolygonGradientPrimitive2D( 232 basegfx::B2DPolyPolygon(aRectangle), 233 aFillGradient)); 234 235 const basegfx::BColor aBlack(0.0, 0.0, 0.0); 236 const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive( 237 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D( 238 aRectangle, 239 aBlack)); 240 241 // prepare VirtualDevice 242 VirtualDevice aVirtualDevice; 243 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D; 244 245 aVirtualDevice.SetOutputSizePixel(rSize); 246 aVirtualDevice.SetDrawMode(rStyleSettings.GetHighContrastMode() 247 ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT 248 : DRAWMODE_DEFAULT); 249 250 // create processor and draw primitives 251 drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice( 252 aVirtualDevice, 253 aNewViewInformation2D); 254 255 if(pProcessor2D) 256 { 257 drawinglayer::primitive2d::Primitive2DSequence aSequence(2); 258 259 aSequence[0] = aGradientPrimitive; 260 aSequence[1] = aBlackRectanglePrimitive; 261 262 pProcessor2D->process(aSequence); 263 delete pProcessor2D; 264 } 265 266 // get result bitmap and scale 267 aRetval = aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel()); 268 } 269 270 return aRetval; 271 } 272 273 ////////////////////////////////////////////////////////////////////////////// 274 // eof 275