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