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 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
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
125 std::move(aDotDashArray),
126 fFullDotDashLen);
127
128 // create LinePrimitive
131 std::move(aLine),
132 aLineAttribute,
133 std::move(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
198{
199 if(maStringSolidLine.isEmpty())
200 {
201 const_cast< XDashList* >(this)->maStringSolidLine = SvxResId(RID_SVXSTR_SOLID);
202 }
203
204 return maStringSolidLine;
205}
206
207OUString 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: */
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
XDashEntry * GetDash(tools::Long nIndex) const
Definition: xtabdash.cxx:56
virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override
Definition: xtabdash.cxx:180
static BitmapEx ImpCreateBitmapForXDash(const XDash *pDash)
Definition: xtabdash.cxx:77
OUString const & GetStringForUiSolidLine() const
Definition: xtabdash.cxx:197
virtual bool Create() override
Definition: xtabdash.cxx:66
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:187
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:207
Definition: xdash.hxx:32
double CreateDotDashArray(::std::vector< double > &rDotDashArray, double fLineWidth) const
Definition: xattr.cxx:440
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