Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / svx / source / xoutdev / xtabgrdt.cxx
blobfbb69a0ddd77f8d0a73f982c1bd85c2fcbd1efea
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <XPropertyTable.hxx>
22 #include <vcl/virdev.hxx>
23 #include <svx/strings.hrc>
24 #include <svx/dialmgr.hxx>
25 #include <svx/xtable.hxx>
27 #include <rtl/ustrbuf.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/settings.hxx>
31 #include <drawinglayer/attribute/fillgradientattribute.hxx>
32 #include <drawinglayer/primitive2d/PolyPolygonGradientPrimitive2D.hxx>
33 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
34 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
35 #include <drawinglayer/processor2d/processor2dtools.hxx>
36 #include <basegfx/polygon/b2dpolygontools.hxx>
37 #include <memory>
39 using namespace com::sun::star;
41 XGradientList::XGradientList( const OUString& rPath, const OUString& rReferer )
42 : XPropertyList( XPropertyListType::Gradient, rPath, rReferer )
46 XGradientList::~XGradientList()
50 void XGradientList::Replace(std::unique_ptr<XGradientEntry> pEntry, tools::Long nIndex)
52 XPropertyList::Replace(std::move(pEntry), nIndex);
55 XGradientEntry* XGradientList::GetGradient(tools::Long nIndex) const
57 return static_cast<XGradientEntry*>( XPropertyList::Get( nIndex ) );
60 uno::Reference< container::XNameContainer > XGradientList::createInstance()
62 return uno::Reference< container::XNameContainer >(
63 SvxUnoXGradientTable_createInstance( this ),
64 uno::UNO_QUERY );
67 bool XGradientList::Create()
69 OUStringBuffer aStr(SvxResId(RID_SVXSTR_GRADIENT));
70 aStr.append(" 1");
71 sal_Int32 nLen = aStr.getLength() - 1;
72 Insert(std::make_unique<XGradientEntry>(XGradient(COL_BLACK, COL_WHITE, css::awt::GradientStyle_LINEAR , Degree10(0),10,10, 0,100,100),aStr.toString()));
73 aStr[nLen] = '2';
74 Insert(std::make_unique<XGradientEntry>(XGradient(COL_BLUE, COL_RED, css::awt::GradientStyle_AXIAL , Degree10(300),20,20,10,100,100),aStr.toString()));
75 aStr[nLen] = '3';
76 Insert(std::make_unique<XGradientEntry>(XGradient(COL_RED, COL_YELLOW,css::awt::GradientStyle_RADIAL , Degree10(600),30,30,20,100,100),aStr.toString()));
77 aStr[nLen] = '4';
78 Insert(std::make_unique<XGradientEntry>(XGradient(COL_YELLOW , COL_GREEN, css::awt::GradientStyle_ELLIPTICAL, Degree10(900),40,40,30,100,100),aStr.toString()));
79 aStr[nLen] = '5';
80 Insert(std::make_unique<XGradientEntry>(XGradient(COL_GREEN , COL_MAGENTA,css::awt::GradientStyle_SQUARE , Degree10(1200),50,50,40,100,100),aStr.toString()));
81 aStr[nLen] = '6';
82 Insert(std::make_unique<XGradientEntry>(XGradient(COL_MAGENTA, COL_YELLOW ,css::awt::GradientStyle_RECT , Degree10(1900),60,60,50,100,100),aStr.toString()));
84 return true;
87 BitmapEx XGradientList::CreateBitmap( tools::Long nIndex, const Size& rSize ) const
89 BitmapEx aRetval;
91 OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
93 if(nIndex < Count())
95 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
96 // prepare polygon geometry for rectangle
97 const basegfx::B2DPolygon aRectangle(
98 basegfx::utils::createPolygonFromRect(
99 basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height())));
101 const XGradient& rGradient = GetGradient(nIndex)->GetGradient();
102 const sal_uInt16 nStartIntens(rGradient.GetStartIntens());
103 basegfx::BColor aStart(rGradient.GetStartColor().getBColor());
105 if(nStartIntens != 100)
107 const basegfx::BColor aBlack;
108 aStart = interpolate(aBlack, aStart, static_cast<double>(nStartIntens) * 0.01);
111 const sal_uInt16 nEndIntens(rGradient.GetEndIntens());
112 basegfx::BColor aEnd(rGradient.GetEndColor().getBColor());
114 if(nEndIntens != 100)
116 const basegfx::BColor aBlack;
117 aEnd = interpolate(aBlack, aEnd, static_cast<double>(nEndIntens) * 0.01);
120 drawinglayer::attribute::GradientStyle aGradientStyle(drawinglayer::attribute::GradientStyle::Rect);
122 switch(rGradient.GetGradientStyle())
124 case css::awt::GradientStyle_LINEAR :
126 aGradientStyle = drawinglayer::attribute::GradientStyle::Linear;
127 break;
129 case css::awt::GradientStyle_AXIAL :
131 aGradientStyle = drawinglayer::attribute::GradientStyle::Axial;
132 break;
134 case css::awt::GradientStyle_RADIAL :
136 aGradientStyle = drawinglayer::attribute::GradientStyle::Radial;
137 break;
139 case css::awt::GradientStyle_ELLIPTICAL :
141 aGradientStyle = drawinglayer::attribute::GradientStyle::Elliptical;
142 break;
144 case css::awt::GradientStyle_SQUARE :
146 aGradientStyle = drawinglayer::attribute::GradientStyle::Square;
147 break;
149 default :
151 aGradientStyle = drawinglayer::attribute::GradientStyle::Rect; // css::awt::GradientStyle_RECT
152 break;
156 const sal_uInt16 nSteps((rSize.Width() + rSize.Height()) / 3);
157 const drawinglayer::attribute::FillGradientAttribute aFillGradient(
158 aGradientStyle,
159 static_cast<double>(rGradient.GetBorder()) * 0.01,
160 static_cast<double>(rGradient.GetXOffset()) * 0.01,
161 static_cast<double>(rGradient.GetYOffset()) * 0.01,
162 static_cast<double>(rGradient.GetAngle().get()) * F_PI1800,
163 aStart,
164 aEnd,
165 nSteps);
167 const drawinglayer::primitive2d::Primitive2DReference aGradientPrimitive(
168 new drawinglayer::primitive2d::PolyPolygonGradientPrimitive2D(
169 basegfx::B2DPolyPolygon(aRectangle),
170 aFillGradient));
172 const basegfx::BColor aBlack(0.0, 0.0, 0.0);
173 const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
174 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
175 aRectangle,
176 aBlack));
178 // prepare VirtualDevice
179 ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
180 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
182 pVirtualDevice->SetOutputSizePixel(rSize);
183 pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
184 ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
185 : DrawModeFlags::Default);
187 // create processor and draw primitives
188 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
189 *pVirtualDevice,
190 aNewViewInformation2D));
192 if(pProcessor2D)
194 drawinglayer::primitive2d::Primitive2DContainer aSequence(2);
196 aSequence[0] = aGradientPrimitive;
197 aSequence[1] = aBlackRectanglePrimitive;
199 pProcessor2D->process(aSequence);
200 pProcessor2D.reset();
203 // get result bitmap and scale
204 aRetval = pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
207 return aRetval;
210 BitmapEx XGradientList::CreateBitmapForUI(tools::Long nIndex)
212 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
213 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
214 return CreateBitmap(nIndex, rSize);
217 BitmapEx XGradientList::GetBitmapForPreview(tools::Long nIndex, const Size& rSize)
219 return CreateBitmap(nIndex, rSize);
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */