1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <XPropertyTable.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/settings.hxx>
25 #include <vcl/virdev.hxx>
26 #include <svx/strings.hrc>
27 #include <svx/dialmgr.hxx>
28 #include <svx/xtable.hxx>
30 #include <comphelper/lok.hxx>
32 #include <drawinglayer/attribute/lineattribute.hxx>
33 #include <drawinglayer/attribute/strokeattribute.hxx>
34 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
35 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
36 #include <drawinglayer/processor2d/processor2dtools.hxx>
39 using namespace com::sun::star
;
41 XDashList::XDashList(const OUString
& rPath
, const OUString
& rReferer
)
42 : XPropertyList(XPropertyListType::Dash
, rPath
, rReferer
)
49 XDashList::~XDashList()
53 void XDashList::Replace(std::unique_ptr
<XDashEntry
> pEntry
, tools::Long nIndex
)
55 XPropertyList::Replace(std::move(pEntry
), nIndex
);
58 XDashEntry
* XDashList::GetDash(tools::Long nIndex
) const
60 return static_cast<XDashEntry
*>( XPropertyList::Get(nIndex
) );
63 uno::Reference
< container::XNameContainer
> XDashList::createInstance()
65 return uno::Reference
< container::XNameContainer
>(
66 SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY
);
69 bool XDashList::Create()
71 const OUString
aStr(SvxResId(RID_SVXSTR_LINESTYLE
));
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"));
80 BitmapEx
XDashList::ImpCreateBitmapForXDash(const XDash
* pDash
)
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
);
87 // prepare polygon geometry for line
88 basegfx::B2DPolygon aLine
;
90 aLine
.append(basegfx::B2DPoint(0.0, aSize
.Height() / 2.0));
91 aLine
.append(basegfx::B2DPoint(aSize
.Width(), aSize
.Height() / 2.0));
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(
100 // prepare StrokeAttribute
101 ::std::vector
< double > aDotDashArray
;
102 double fFullDotDashLen(0.0);
104 if(pDash
&& (pDash
->GetDots() || pDash
->GetDashes()))
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
);
111 fFullDotDashLen
= pDash
->CreateDotDashArray(aDotDashArray
, fLineWidthInUnits
);
113 if(!aDotDashArray
.empty())
115 for(double & a
: aDotDashArray
)
118 // ~zero length dash is a dot-like dot (with line width size round cap), so show it
123 fFullDotDashLen
*= fScaleValue
;
127 const drawinglayer::attribute::StrokeAttribute
aStrokeAttribute(
131 // create LinePrimitive
132 const drawinglayer::primitive2d::Primitive2DReference
aLinePrimitive(
133 new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
138 // prepare VirtualDevice
139 ScopedVclPtrInstance
< VirtualDevice
> pVirtualDevice
;
140 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D
;
142 pVirtualDevice
->SetOutputSizePixel(aSize
);
143 pVirtualDevice
->SetDrawMode(rStyleSettings
.GetHighContrastMode()
144 ? DrawModeFlags::SettingsLine
| DrawModeFlags::SettingsFill
| DrawModeFlags::SettingsText
| DrawModeFlags::SettingsGradient
145 : DrawModeFlags::Default
);
147 if(rStyleSettings
.GetPreviewUsesCheckeredBackground())
149 const Point
aNull(0, 0);
150 static const sal_uInt32
nLen(8 * nFactor
);
151 static const Color
aW(COL_WHITE
);
152 static const Color
aG(0xef, 0xef, 0xef);
154 pVirtualDevice
->DrawCheckered(aNull
, aSize
, nLen
, aW
, aG
);
158 pVirtualDevice
->SetBackground(rStyleSettings
.GetFieldColor());
159 pVirtualDevice
->Erase();
162 // create processor and draw primitives
163 std::unique_ptr
<drawinglayer::processor2d::BaseProcessor2D
> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
165 aNewViewInformation2D
));
167 const drawinglayer::primitive2d::Primitive2DContainer aSequence
{ aLinePrimitive
};
169 pProcessor2D
->process(aSequence
);
170 pProcessor2D
.reset();
172 // get result bitmap and scale
173 BitmapEx
aRetval(pVirtualDevice
->GetBitmapEx(Point(0, 0), pVirtualDevice
->GetOutputSizePixel()));
177 aRetval
.Scale(Size((rSize
.Width() * 5) / 2, rSize
.Height()));
183 BitmapEx
XDashList::CreateBitmapForUI( tools::Long nIndex
)
185 const XDash
& rDash
= GetDash(nIndex
)->GetDash();
187 return ImpCreateBitmapForXDash(&rDash
);
190 BitmapEx
const & XDashList::GetBitmapForUISolidLine() const
192 if(maBitmapSolidLine
.IsEmpty())
194 const_cast< XDashList
* >(this)->maBitmapSolidLine
= XDashList::ImpCreateBitmapForXDash(nullptr);
197 return maBitmapSolidLine
;
200 OUString
const & XDashList::GetStringForUiSolidLine() const
202 if(maStringSolidLine
.isEmpty())
204 const_cast< XDashList
* >(this)->maStringSolidLine
= SvxResId(RID_SVXSTR_SOLID
);
207 return maStringSolidLine
;
210 OUString
const & XDashList::GetStringForUiNoLine() const
212 if(maStringNoLine
.isEmpty())
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
);
220 return maStringNoLine
;
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */