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