LibreOffice Module svx (master)  1
xtabdash.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/svapp.hxx>
23 #include <vcl/settings.hxx>
24 
25 #include <vcl/virdev.hxx>
26 #include <svx/strings.hrc>
27 #include <svx/dialmgr.hxx>
28 #include <svx/xtable.hxx>
29 
35 #include <memory>
36 
37 using namespace com::sun::star;
38 
39 XDashList::XDashList(const OUString& rPath, const OUString& rReferer)
40  : XPropertyList(XPropertyListType::Dash, rPath, rReferer)
41  , maBitmapSolidLine()
42  , maStringSolidLine()
43  , maStringNoLine()
44 {
45 }
46 
48 {
49 }
50 
51 void XDashList::Replace(std::unique_ptr<XDashEntry> pEntry, long nIndex)
52 {
53  XPropertyList::Replace(std::move(pEntry), nIndex);
54 }
55 
56 XDashEntry* XDashList::GetDash(long nIndex) const
57 {
58  return static_cast<XDashEntry*>( XPropertyList::Get(nIndex) );
59 }
60 
61 uno::Reference< container::XNameContainer > XDashList::createInstance()
62 {
63  return uno::Reference< container::XNameContainer >(
64  SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
65 }
66 
68 {
69  const OUString aStr(SvxResId(RID_SVXSTR_LINESTYLE));
70 
71  Insert(std::make_unique<XDashEntry>(XDash(css::drawing::DashStyle_RECT,1, 50,1, 50, 50),aStr + " 1"));
72  Insert(std::make_unique<XDashEntry>(XDash(css::drawing::DashStyle_RECT,1,500,1,500,500),aStr + " 2"));
73  Insert(std::make_unique<XDashEntry>(XDash(css::drawing::DashStyle_RECT,2, 50,3,250,120),aStr + " 3"));
74 
75  return true;
76 }
77 
79 {
80  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
81  const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
82  const sal_uInt32 nFactor(2);
83  const Size aSize((rSize.Width() * 5 * 2) / 2, rSize.Height() * nFactor);
84 
85  // prepare polygon geometry for line
86  basegfx::B2DPolygon aLine;
87 
88  aLine.append(basegfx::B2DPoint(0.0, aSize.Height() / 2.0));
89  aLine.append(basegfx::B2DPoint(aSize.Width(), aSize.Height() / 2.0));
90 
91  // prepare LineAttribute
92  const basegfx::BColor aLineColor(rStyleSettings.GetFieldTextColor().getBColor());
93  const double fLineWidth(StyleSettings::GetListBoxPreviewDefaultLineWidth() * (nFactor * 1.1));
94  const drawinglayer::attribute::LineAttribute aLineAttribute(
95  aLineColor,
96  fLineWidth);
97 
98  // prepare StrokeAttribute
99  ::std::vector< double > aDotDashArray;
100  double fFullDotDashLen(0.0);
101 
102  if(pDash && (pDash->GetDots() || pDash->GetDashes()))
103  {
104  const basegfx::B2DHomMatrix aScaleMatrix(OutputDevice::LogicToLogic(MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapPixel)));
105  const basegfx::B2DVector aScaleVector(aScaleMatrix * basegfx::B2DVector(1.0, 0.0));
106  const double fScaleValue(aScaleVector.getLength() * (nFactor * (1.4 / 2.0)));
107  const double fLineWidthInUnits(fLineWidth / fScaleValue);
108 
109  fFullDotDashLen = pDash->CreateDotDashArray(aDotDashArray, fLineWidthInUnits);
110 
111  if(!aDotDashArray.empty())
112  {
113  for(double & a : aDotDashArray)
114  {
115  a *= fScaleValue;
116  }
117 
118  fFullDotDashLen *= fScaleValue;
119  }
120  }
121 
122  const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(
123  aDotDashArray,
124  fFullDotDashLen);
125 
126  // create LinePrimitive
129  aLine,
130  aLineAttribute,
131  aStrokeAttribute));
132 
133  // prepare VirtualDevice
135  const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
136 
137  pVirtualDevice->SetOutputSizePixel(aSize);
138  pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
139  ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
140  : DrawModeFlags::Default);
141 
142  if(rStyleSettings.GetPreviewUsesCheckeredBackground())
143  {
144  const Point aNull(0, 0);
145  static const sal_uInt32 nLen(8 * nFactor);
146  static const Color aW(COL_WHITE);
147  static const Color aG(0xef, 0xef, 0xef);
148 
149  pVirtualDevice->DrawCheckered(aNull, aSize, nLen, aW, aG);
150  }
151  else
152  {
153  pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
154  pVirtualDevice->Erase();
155  }
156 
157  // create processor and draw primitives
158  std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
159  *pVirtualDevice,
160  aNewViewInformation2D));
161 
162  if(pProcessor2D)
163  {
164  const drawinglayer::primitive2d::Primitive2DContainer aSequence { aLinePrimitive };
165 
166  pProcessor2D->process(aSequence);
167  pProcessor2D.reset();
168  }
169 
170  // get result bitmap and scale
171  BitmapEx aRetval(pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel()));
172 
173  if(1 != nFactor)
174  {
175  aRetval.Scale(Size((rSize.Width() * 5) / 2, rSize.Height()));
176  }
177 
178  return aRetval;
179 }
180 
182 {
183  const XDash& rDash = GetDash(nIndex)->GetDash();
184 
185  return ImpCreateBitmapForXDash(&rDash);
186 }
187 
189 {
191  {
192  const_cast< XDashList* >(this)->maBitmapSolidLine = XDashList::ImpCreateBitmapForXDash(nullptr);
193  }
194 
195  return maBitmapSolidLine;
196 }
197 
198 OUString const & XDashList::GetStringForUiSolidLine() const
199 {
200  if(maStringSolidLine.isEmpty())
201  {
202  const_cast< XDashList* >(this)->maStringSolidLine = SvxResId(RID_SVXSTR_SOLID);
203  }
204 
205  return maStringSolidLine;
206 }
207 
208 OUString const & XDashList::GetStringForUiNoLine() const
209 {
210  if(maStringNoLine.isEmpty())
211  {
212  // formerly was RID_SVXSTR_INVISIBLE, but to make equal
213  // everywhere, use RID_SVXSTR_NONE
214  const_cast< XDashList* >(this)->maStringNoLine = SvxResId(RID_SVXSTR_NONE);
215  }
216 
217  return maStringNoLine;
218 }
219 
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
OUString maStringNoLine
Definition: xtable.hxx:276
XPropertyEntry * Get(long nIndex) const
Definition: xtable.cxx:135
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
BitmapEx const & GetBitmapForUISolidLine() const
Definition: xtabdash.cxx:188
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
long Height() const
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
bool GetPreviewUsesCheckeredBackground() const
virtual css::uno::Reference< css::container::XNameContainer > createInstance() override
Definition: xtabdash.cxx:61
BitmapEx maBitmapSolidLine
Definition: xtable.hxx:274
const Size & GetListBoxPreviewDefaultPixelSize() const
virtual ~XDashList() override
Definition: xtabdash.cxx:47
const Color & GetFieldTextColor() const
void Insert(std::unique_ptr< XPropertyEntry > pEntry, long nIndex=std::numeric_limits< long >::max())
Definition: xtable.cxx:181
void Replace(std::unique_ptr< XPropertyEntry > pEntry, long nIndex)
Definition: xtable.cxx:196
Definition: xdash.hxx:31
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
bool GetHighContrastMode() const
sal_uInt16 GetDots() const
Definition: xdash.hxx:55
const XDash & GetDash() const
Definition: xtable.hxx:80
virtual BitmapEx CreateBitmapForUI(long nIndex) override
Definition: xtabdash.cxx:181
std::unique_ptr< BaseProcessor2D > createPixelProcessor2DFromOutputDevice(OutputDevice &rTargetOutDev, const drawinglayer::geometry::ViewInformation2D &rViewInformation2D)
bool IsEmpty() const
uno::Reference< uno::XInterface > SvxUnoXDashTable_createInstance(XPropertyList *pTable)
OUString maStringSolidLine
Definition: xtable.hxx:275
XPropertyListType
Definition: xtable.hxx:131
uno_Any a
const Color & GetFieldColor() const
void Replace(std::unique_ptr< XDashEntry > pEntry, long nIndex)
Definition: xtabdash.cxx:51
double CreateDotDashArray(::std::vector< double > &rDotDashArray, double fLineWidth) const
Definition: xattr.cxx:437
XDashList(const OUString &rPath, const OUString &rReferer)
Definition: xtabdash.cxx:39
OUString const & GetStringForUiNoLine() const
Definition: xtabdash.cxx:208
OUString const & GetStringForUiSolidLine() const
Definition: xtabdash.cxx:198
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
constexpr::Color COL_WHITE(0xFF, 0xFF, 0xFF)
basegfx::BColor getBColor() const
double getLength() const
static sal_uInt16 GetListBoxPreviewDefaultLineWidth()
static BitmapEx ImpCreateBitmapForXDash(const XDash *pDash)
Definition: xtabdash.cxx:78
virtual bool Create() override
Definition: xtabdash.cxx:67
XDashEntry * GetDash(long nIndex) const
Definition: xtabdash.cxx:56
aStr
sal_uInt16 GetDashes() const
Definition: xdash.hxx:57