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 
38 #include <memory>
39 
40 using namespace com::sun::star;
41 
42 XGradientList::XGradientList( const OUString& rPath, const OUString& rReferer )
43 : XPropertyList( XPropertyListType::Gradient, rPath, rReferer )
44 {
45 }
46 
48 {
49 }
50 
51 void XGradientList::Replace(std::unique_ptr<XGradientEntry> pEntry, tools::Long nIndex)
52 {
53  XPropertyList::Replace(std::move(pEntry), nIndex);
54 }
55 
57 {
58  return static_cast<XGradientEntry*>( XPropertyList::Get( nIndex ) );
59 }
60 
61 uno::Reference< container::XNameContainer > XGradientList::createInstance()
62 {
64 }
65 
67 {
68  OUStringBuffer aStr(SvxResId(RID_SVXSTR_GRADIENT));
69  aStr.append(" 1");
70  sal_Int32 nLen = aStr.getLength() - 1;
71  Insert(std::make_unique<XGradientEntry>(XGradient(COL_BLACK, COL_WHITE, css::awt::GradientStyle_LINEAR , 0_deg10,10,10, 0,100,100),aStr.toString()));
72  aStr[nLen] = '2';
73  Insert(std::make_unique<XGradientEntry>(XGradient(COL_BLUE, COL_RED, css::awt::GradientStyle_AXIAL , 300_deg10,20,20,10,100,100),aStr.toString()));
74  aStr[nLen] = '3';
75  Insert(std::make_unique<XGradientEntry>(XGradient(COL_RED, COL_YELLOW,css::awt::GradientStyle_RADIAL , 600_deg10,30,30,20,100,100),aStr.toString()));
76  aStr[nLen] = '4';
77  Insert(std::make_unique<XGradientEntry>(XGradient(COL_YELLOW , COL_GREEN, css::awt::GradientStyle_ELLIPTICAL, 900_deg10,40,40,30,100,100),aStr.toString()));
78  aStr[nLen] = '5';
79  Insert(std::make_unique<XGradientEntry>(XGradient(COL_GREEN , COL_MAGENTA,css::awt::GradientStyle_SQUARE , 1200_deg10,50,50,40,100,100),aStr.toString()));
80  aStr[nLen] = '6';
81  Insert(std::make_unique<XGradientEntry>(XGradient(COL_MAGENTA, COL_YELLOW ,css::awt::GradientStyle_RECT , 1900_deg10,60,60,50,100,100),aStr.toString()));
82 
83  return true;
84 }
85 
87 {
88  BitmapEx aRetval;
89 
90  OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
91 
92  if(nIndex < Count())
93  {
94  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
95  // prepare polygon geometry for rectangle
96  basegfx::B2DPolygon aRectangle(
98  basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height())));
99 
100  const XGradient& rGradient = GetGradient(nIndex)->GetGradient();
101  const sal_uInt16 nStartIntens(rGradient.GetStartIntens());
102  basegfx::BColor aStart(rGradient.GetStartColor().getBColor());
103 
104  if(nStartIntens != 100)
105  {
106  const basegfx::BColor aBlack;
107  aStart = interpolate(aBlack, aStart, static_cast<double>(nStartIntens) * 0.01);
108  }
109 
110  const sal_uInt16 nEndIntens(rGradient.GetEndIntens());
111  basegfx::BColor aEnd(rGradient.GetEndColor().getBColor());
112 
113  if(nEndIntens != 100)
114  {
115  const basegfx::BColor aBlack;
116  aEnd = interpolate(aBlack, aEnd, static_cast<double>(nEndIntens) * 0.01);
117  }
118 
120 
121  switch(rGradient.GetGradientStyle())
122  {
123  case css::awt::GradientStyle_LINEAR :
124  {
126  break;
127  }
128  case css::awt::GradientStyle_AXIAL :
129  {
131  break;
132  }
133  case css::awt::GradientStyle_RADIAL :
134  {
136  break;
137  }
138  case css::awt::GradientStyle_ELLIPTICAL :
139  {
141  break;
142  }
143  case css::awt::GradientStyle_SQUARE :
144  {
146  break;
147  }
148  default :
149  {
150  aGradientStyle = drawinglayer::attribute::GradientStyle::Rect; // css::awt::GradientStyle_RECT
151  break;
152  }
153  }
154 
156  aGradientStyle,
157  static_cast<double>(rGradient.GetBorder()) * 0.01,
158  static_cast<double>(rGradient.GetXOffset()) * 0.01,
159  static_cast<double>(rGradient.GetYOffset()) * 0.01,
160  toRadians(rGradient.GetAngle()),
161  aStart,
162  aEnd);
163 
164  const drawinglayer::primitive2d::Primitive2DReference aGradientPrimitive(
166  basegfx::B2DPolyPolygon(aRectangle),
167  std::move(aFillGradient)));
168 
169  const basegfx::BColor aBlack(0.0, 0.0, 0.0);
170  const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
172  std::move(aRectangle),
173  aBlack));
174 
175  // prepare VirtualDevice
177  const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
178 
179  pVirtualDevice->SetOutputSizePixel(rSize);
180  pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
181  ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
182  : DrawModeFlags::Default);
183 
184  // create processor and draw primitives
185  std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
186  *pVirtualDevice,
187  aNewViewInformation2D));
188 
190 
191  aSequence[0] = aGradientPrimitive;
192  aSequence[1] = aBlackRectanglePrimitive;
193 
194  pProcessor2D->process(aSequence);
195  pProcessor2D.reset();
196 
197  // get result bitmap and scale
198  aRetval = pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
199  }
200 
201  return aRetval;
202 }
203 
205 {
206  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
207  const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
208  return CreateBitmap(nIndex, rSize);
209 }
210 
212 {
213  return CreateBitmap(nIndex, rSize);
214 }
215 
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr::Color COL_RED(0x80, 0x00, 0x00)
long Long
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
const Size & GetListBoxPreviewDefaultPixelSize() const
constexpr::Color COL_MAGENTA(0x80, 0x00, 0x80)
HSLColor interpolate(const HSLColor &rFrom, const HSLColor &rTo, double t, bool bCCW)
constexpr tools::Long Width() const
const XGradient & GetGradient() const
Definition: xtable.hxx:110
void Replace(std::unique_ptr< XGradientEntry > pEntry, tools::Long nIndex)
Definition: xtabgrdt.cxx:51
uno::Reference< container::XNameContainer > SvxUnoXGradientTable_createInstance(XPropertyList &rTable) noexcept
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
bool GetHighContrastMode() const
BitmapEx CreateBitmap(tools::Long nIndex, const Size &rSize) const
Definition: xtabgrdt.cxx:86
void Replace(std::unique_ptr< XPropertyEntry > pEntry, tools::Long nIndex)
Definition: xtable.cxx:192
virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override
Definition: xtabgrdt.cxx:204
std::unique_ptr< BaseProcessor2D > createPixelProcessor2DFromOutputDevice(OutputDevice &rTargetOutDev, const drawinglayer::geometry::ViewInformation2D &rViewInformation2D)
XGradientEntry * GetGradient(tools::Long nIndex) const
Definition: xtabgrdt.cxx:56
XPropertyListType
Definition: xtable.hxx:131
void Insert(std::unique_ptr< XPropertyEntry > pEntry, tools::Long nIndex=std::numeric_limits< tools::Long >::max())
Definition: xtable.cxx:177
BitmapEx GetBitmapForPreview(tools::Long nIndex, const Size &rSize)
Definition: xtabgrdt.cxx:211
virtual bool Create() override
Definition: xtabgrdt.cxx:66
virtual ~XGradientList() override
Definition: xtabgrdt.cxx:47
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
XPropertyEntry * Get(tools::Long nIndex) const
Definition: xtable.cxx:131
double toRadians(D x)
tools::Long Count() const
Definition: xtable.cxx:121
constexpr tools::Long Height() const
constexpr::Color COL_GREEN(0x00, 0x80, 0x00)
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_YELLOW
constexpr::Color COL_BLUE(0x00, 0x00, 0x80)
XGradientList(const OUString &rPath, const OUString &rReferer)
Definition: xtabgrdt.cxx:42
aStr
virtual css::uno::Reference< css::container::XNameContainer > createInstance() override
Definition: xtabgrdt.cxx:61