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  , maBitmapSolidLine()
44  , maStringSolidLine()
45  , maStringNoLine()
46 {
47 }
48 
50 {
51 }
52 
53 void XDashList::Replace(std::unique_ptr<XDashEntry> pEntry, long nIndex)
54 {
55  XPropertyList::Replace(std::move(pEntry), nIndex);
56 }
57 
58 XDashEntry* XDashList::GetDash(long nIndex) const
59 {
60  return static_cast<XDashEntry*>( XPropertyList::Get(nIndex) );
61 }
62 
63 uno::Reference< container::XNameContainer > XDashList::createInstance()
64 {
65  return uno::Reference< container::XNameContainer >(
66  SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
67 }
68 
70 {
71  const OUString aStr(SvxResId(RID_SVXSTR_LINESTYLE));
72 
73  Insert(std::make_unique<XDashEntry>(XDash(css::drawing::DashStyle_RECT,1, 50,1, 50, 50),aStr + " 1"));
74  Insert(std::make_unique<XDashEntry>(XDash(css::drawing::DashStyle_RECT,1,500,1,500,500),aStr + " 2"));
75  Insert(std::make_unique<XDashEntry>(XDash(css::drawing::DashStyle_RECT,2, 50,3,250,120),aStr + " 3"));
76 
77  return true;
78 }
79 
81 {
82  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
83  const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
84  const sal_uInt32 nFactor(2);
85  const Size aSize((rSize.Width() * 5 * 2) / 2, rSize.Height() * nFactor);
86 
87  // prepare polygon geometry for line
88  basegfx::B2DPolygon aLine;
89 
90  aLine.append(basegfx::B2DPoint(0.0, aSize.Height() / 2.0));
91  aLine.append(basegfx::B2DPoint(aSize.Width(), aSize.Height() / 2.0));
92 
93  // prepare LineAttribute
94  const basegfx::BColor aLineColor(rStyleSettings.GetFieldTextColor().getBColor());
95  const double fLineWidth(StyleSettings::GetListBoxPreviewDefaultLineWidth() * (nFactor * 1.1));
96  const drawinglayer::attribute::LineAttribute aLineAttribute(
97  aLineColor,
98  fLineWidth);
99 
100  // prepare StrokeAttribute
101  ::std::vector< double > aDotDashArray;
102  double fFullDotDashLen(0.0);
103 
104  if(pDash && (pDash->GetDots() || pDash->GetDashes()))
105  {
106  const basegfx::B2DHomMatrix aScaleMatrix(OutputDevice::LogicToLogic(MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapPixel)));
107  const basegfx::B2DVector aScaleVector(aScaleMatrix * basegfx::B2DVector(1.0, 0.0));
108  const double fScaleValue(aScaleVector.getLength() * (nFactor * (1.4 / 2.0)));
109  const double fLineWidthInUnits(fLineWidth / fScaleValue);
110 
111  fFullDotDashLen = pDash->CreateDotDashArray(aDotDashArray, fLineWidthInUnits);
112 
113  if(!aDotDashArray.empty())
114  {
115  for(double & a : aDotDashArray)
116  {
117  a *= fScaleValue;
118  }
119 
120  fFullDotDashLen *= fScaleValue;
121  }
122  }
123 
124  const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(
125  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  if(pProcessor2D)
165  {
166  const drawinglayer::primitive2d::Primitive2DContainer aSequence { aLinePrimitive };
167 
168  pProcessor2D->process(aSequence);
169  pProcessor2D.reset();
170  }
171 
172  // get result bitmap and scale
173  BitmapEx aRetval(pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel()));
174 
175  if(1 != nFactor)
176  {
177  aRetval.Scale(Size((rSize.Width() * 5) / 2, rSize.Height()));
178  }
179 
180  return aRetval;
181 }
182 
184 {
185  const XDash& rDash = GetDash(nIndex)->GetDash();
186 
187  return ImpCreateBitmapForXDash(&rDash);
188 }
189 
191 {
193  {
194  const_cast< XDashList* >(this)->maBitmapSolidLine = XDashList::ImpCreateBitmapForXDash(nullptr);
195  }
196 
197  return maBitmapSolidLine;
198 }
199 
200 OUString const & XDashList::GetStringForUiSolidLine() const
201 {
202  if(maStringSolidLine.isEmpty())
203  {
204  const_cast< XDashList* >(this)->maStringSolidLine = SvxResId(RID_SVXSTR_SOLID);
205  }
206 
207  return maStringSolidLine;
208 }
209 
210 OUString const & XDashList::GetStringForUiNoLine() const
211 {
212  if(maStringNoLine.isEmpty())
213  {
214  // formerly was RID_SVXSTR_INVISIBLE, but to make equal
215  // everywhere, use RID_SVXSTR_NONE
216  const_cast< XDashList* >(this)->maStringNoLine = comphelper::LibreOfficeKit::isActive() ? SvxResId(RID_SVXSTR_INVISIBLE) :
217  SvxResId(RID_SVXSTR_NONE);
218  }
219 
220  return maStringNoLine;
221 }
222 
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
OUString maStringNoLine
Definition: xtable.hxx:276
XPropertyEntry * Get(long nIndex) const
Definition: xtable.cxx:131
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
BitmapEx const & GetBitmapForUISolidLine() const
Definition: xtabdash.cxx:190
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:63
BitmapEx maBitmapSolidLine
Definition: xtable.hxx:274
const Size & GetListBoxPreviewDefaultPixelSize() const
virtual ~XDashList() override
Definition: xtabdash.cxx:49
const Color & GetFieldTextColor() const
void Insert(std::unique_ptr< XPropertyEntry > pEntry, long nIndex=std::numeric_limits< long >::max())
Definition: xtable.cxx:177
void Replace(std::unique_ptr< XPropertyEntry > pEntry, long nIndex)
Definition: xtable.cxx:192
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:183
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:53
double CreateDotDashArray(::std::vector< double > &rDotDashArray, double fLineWidth) const
Definition: xattr.cxx:429
XDashList(const OUString &rPath, const OUString &rReferer)
Definition: xtabdash.cxx:41
OUString const & GetStringForUiNoLine() const
Definition: xtabdash.cxx:210
OUString const & GetStringForUiSolidLine() const
Definition: xtabdash.cxx:200
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
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:80
virtual bool Create() override
Definition: xtabdash.cxx:69
XDashEntry * GetDash(long nIndex) const
Definition: xtabdash.cxx:58
aStr
sal_uInt16 GetDashes() const
Definition: xdash.hxx:57