LibreOffice Module svx (master) 1
xtabgrdt.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <XPropertyTable.hxx>
21
22#include <vcl/virdev.hxx>
23#include <svx/strings.hrc>
24#include <svx/dialmgr.hxx>
25#include <svx/xtable.hxx>
26
27#include <rtl/ustrbuf.hxx>
28#include <vcl/svapp.hxx>
29#include <vcl/settings.hxx>
30#include <osl/diagnose.h>
31
39#include <memory>
40
41using namespace com::sun::star;
42
43XGradientList::XGradientList( const OUString& rPath, const OUString& rReferer )
44: XPropertyList( XPropertyListType::Gradient, rPath, rReferer )
45{
46}
47
49{
50}
51
52void XGradientList::Replace(std::unique_ptr<XGradientEntry> pEntry, tools::Long nIndex)
53{
54 XPropertyList::Replace(std::move(pEntry), nIndex);
55}
56
58{
59 return static_cast<XGradientEntry*>( XPropertyList::Get( nIndex ) );
60}
61
62uno::Reference< container::XNameContainer > XGradientList::createInstance()
63{
65}
66
68{
69 OUStringBuffer aStr(SvxResId(RID_SVXSTR_GRADIENT) + " 1");
70 sal_Int32 nLen = aStr.getLength() - 1;
71
72 // XGradient() default already creates [COL_BLACK, COL_WHITE] as defaults
73 Insert(std::make_unique<XGradientEntry>(XGradient(),aStr.toString()));
74
75 aStr[nLen] = '2';
76 Insert(std::make_unique<XGradientEntry>(XGradient(basegfx::utils::createColorStopsFromStartEndColor(COL_BLUE.getBColor(), COL_RED.getBColor()), css::awt::GradientStyle_AXIAL , 300_deg10,20,20,10,100,100),aStr.toString()));
77 aStr[nLen] = '3';
78 Insert(std::make_unique<XGradientEntry>(XGradient(basegfx::utils::createColorStopsFromStartEndColor(COL_RED.getBColor(), COL_YELLOW.getBColor()), css::awt::GradientStyle_RADIAL , 600_deg10,30,30,20,100,100),aStr.toString()));
79 aStr[nLen] = '4';
80 Insert(std::make_unique<XGradientEntry>(XGradient(basegfx::utils::createColorStopsFromStartEndColor(COL_YELLOW.getBColor(), COL_GREEN.getBColor()), css::awt::GradientStyle_ELLIPTICAL, 900_deg10,40,40,30,100,100),aStr.toString()));
81 aStr[nLen] = '5';
82 Insert(std::make_unique<XGradientEntry>(XGradient(basegfx::utils::createColorStopsFromStartEndColor(COL_GREEN.getBColor(), COL_MAGENTA.getBColor()), css::awt::GradientStyle_SQUARE , 1200_deg10,50,50,40,100,100),aStr.toString()));
83 aStr[nLen] = '6';
84 Insert(std::make_unique<XGradientEntry>(XGradient(basegfx::utils::createColorStopsFromStartEndColor(COL_MAGENTA.getBColor(), COL_YELLOW.getBColor()), css::awt::GradientStyle_RECT , 1900_deg10,60,60,50,100,100),aStr.toString()));
85
86 return true;
87}
88
90{
91 BitmapEx aRetval;
92
93 OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
94
95 if(nIndex < Count())
96 {
98 // prepare polygon geometry for rectangle
99 basegfx::B2DPolygon aRectangle(
101 basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height())));
102
103 const XGradient& rGradient = GetGradient(nIndex)->GetGradient();
104 const sal_uInt16 nStartIntens(rGradient.GetStartIntens());
105 basegfx::BColor aStart(rGradient.GetColorStops().front().getStopColor());
106
107 if(nStartIntens != 100)
108 {
109 const basegfx::BColor aBlack;
110 aStart = interpolate(aBlack, aStart, static_cast<double>(nStartIntens) * 0.01);
111 }
112
113 const sal_uInt16 nEndIntens(rGradient.GetEndIntens());
114 basegfx::BColor aEnd(rGradient.GetColorStops().back().getStopColor());
115
116 if(nEndIntens != 100)
117 {
118 const basegfx::BColor aBlack;
119 aEnd = interpolate(aBlack, aEnd, static_cast<double>(nEndIntens) * 0.01);
120 }
121
123
124 switch(rGradient.GetGradientStyle())
125 {
126 case css::awt::GradientStyle_LINEAR :
127 {
129 break;
130 }
131 case css::awt::GradientStyle_AXIAL :
132 {
134 break;
135 }
136 case css::awt::GradientStyle_RADIAL :
137 {
139 break;
140 }
141 case css::awt::GradientStyle_ELLIPTICAL :
142 {
144 break;
145 }
146 case css::awt::GradientStyle_SQUARE :
147 {
149 break;
150 }
151 default :
152 {
153 aGradientStyle = drawinglayer::attribute::GradientStyle::Rect; // css::awt::GradientStyle_RECT
154 break;
155 }
156 }
157
159 aGradientStyle,
160 static_cast<double>(rGradient.GetBorder()) * 0.01,
161 static_cast<double>(rGradient.GetXOffset()) * 0.01,
162 static_cast<double>(rGradient.GetYOffset()) * 0.01,
163 toRadians(rGradient.GetAngle()),
165
168 basegfx::B2DPolyPolygon(aRectangle),
169 std::move(aFillGradient)));
170
171 const basegfx::BColor aBlack(0.0, 0.0, 0.0);
172 const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
174 std::move(aRectangle),
175 aBlack));
176
177 // prepare VirtualDevice
179 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
180
181 pVirtualDevice->SetOutputSizePixel(rSize);
182 pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
183 ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
184 : DrawModeFlags::Default);
185
186 // create processor and draw primitives
187 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
188 *pVirtualDevice,
189 aNewViewInformation2D));
190
192
193 aSequence[0] = aGradientPrimitive;
194 aSequence[1] = aBlackRectanglePrimitive;
195
196 pProcessor2D->process(aSequence);
197 pProcessor2D.reset();
198
199 // get result bitmap and scale
200 aRetval = pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
201 }
202
203 return aRetval;
204}
205
207{
208 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
209 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
210 return CreateBitmap(nIndex, rSize);
211}
212
214{
215 return CreateBitmap(nIndex, rSize);
216}
217
218/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
uno::Reference< container::XNameContainer > SvxUnoXGradientTable_createInstance(XPropertyList &rTable) noexcept
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
basegfx::BColor getBColor() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
bool GetHighContrastMode() const
const Size & GetListBoxPreviewDefaultPixelSize() const
const XGradient & GetGradient() const
Definition: xtable.hxx:110
void Replace(std::unique_ptr< XGradientEntry > pEntry, tools::Long nIndex)
Definition: xtabgrdt.cxx:52
virtual ~XGradientList() override
Definition: xtabgrdt.cxx:48
XGradientList(const OUString &rPath, const OUString &rReferer)
Definition: xtabgrdt.cxx:43
virtual bool Create() override
Definition: xtabgrdt.cxx:67
BitmapEx GetBitmapForPreview(tools::Long nIndex, const Size &rSize)
Definition: xtabgrdt.cxx:213
BitmapEx CreateBitmap(tools::Long nIndex, const Size &rSize) const
Definition: xtabgrdt.cxx:89
XGradientEntry * GetGradient(tools::Long nIndex) const
Definition: xtabgrdt.cxx:57
virtual css::uno::Reference< css::container::XNameContainer > createInstance() override
Definition: xtabgrdt.cxx:62
virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override
Definition: xtabgrdt.cxx:206
sal_uInt16 GetYOffset() const
Definition: xgrad.hxx:73
sal_uInt16 GetStartIntens() const
Definition: xgrad.hxx:74
css::awt::GradientStyle GetGradientStyle() const
Definition: xgrad.hxx:68
sal_uInt16 GetBorder() const
Definition: xgrad.hxx:71
sal_uInt16 GetEndIntens() const
Definition: xgrad.hxx:75
Degree10 GetAngle() const
Definition: xgrad.hxx:70
sal_uInt16 GetXOffset() const
Definition: xgrad.hxx:72
const basegfx::ColorStops & GetColorStops() const
Definition: xgrad.hxx:69
tools::Long Count() const
Definition: xtable.cxx:122
void Insert(std::unique_ptr< XPropertyEntry > pEntry, tools::Long nIndex=std::numeric_limits< tools::Long >::max())
Definition: xtable.cxx:178
void Replace(std::unique_ptr< XPropertyEntry > pEntry, tools::Long nIndex)
Definition: xtable.cxx:193
XPropertyEntry * Get(tools::Long nIndex) const
Definition: xtable.cxx:132
constexpr ::Color COL_GREEN(0x00, 0x80, 0x00)
constexpr ::Color COL_MAGENTA(0x80, 0x00, 0x80)
constexpr ::Color COL_YELLOW(0xFF, 0xFF, 0x00)
constexpr ::Color COL_RED(0x80, 0x00, 0x00)
constexpr ::Color COL_BLUE(0x00, 0x00, 0x80)
double toRadians(D x)
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
sal_Int32 nIndex
aStr
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
ColorStops createColorStopsFromStartEndColor(const BColor &rStart, const BColor &rEnd)
std::unique_ptr< BaseProcessor2D > createPixelProcessor2DFromOutputDevice(OutputDevice &rTargetOutDev, const drawinglayer::geometry::ViewInformation2D &rViewInformation2D)
HSLColor interpolate(const HSLColor &rFrom, const HSLColor &rTo, double t, bool bCCW)
long Long
XPropertyListType
Definition: xtable.hxx:131