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 <basegfx/matrix/b2dhommatrix.hxx>
33 #include <drawinglayer/attribute/lineattribute.hxx>
34 #include <drawinglayer/attribute/strokeattribute.hxx>
35 #include <drawinglayer/primitive2d/PolygonStrokePrimitive2D.hxx>
36 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
37 #include <drawinglayer/processor2d/processor2dtools.hxx>
40 using namespace com::sun::star
;
42 XDashList::XDashList(const OUString
& rPath
, const OUString
& rReferer
)
43 : XPropertyList(XPropertyListType::Dash
, rPath
, rReferer
)
47 XDashList::~XDashList()
51 void XDashList::Replace(std::unique_ptr
<XDashEntry
> pEntry
, tools::Long nIndex
)
53 XPropertyList::Replace(std::move(pEntry
), nIndex
);
56 XDashEntry
* XDashList::GetDash(tools::Long nIndex
) const
58 return static_cast<XDashEntry
*>( XPropertyList::Get(nIndex
) );
61 uno::Reference
< container::XNameContainer
> XDashList::createInstance()
63 return SvxUnoXDashTable_createInstance( *this );
66 bool XDashList::Create()
68 const OUString
aStr(SvxResId(RID_SVXSTR_LINESTYLE
));
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"));
77 double XDashList::ImpGetDefaultLineThickness()
79 return StyleSettings::GetListBoxPreviewDefaultLineWidth() * 1.1;
82 BitmapEx
XDashList::CreateBitmapForXDash(const XDash
* pDash
, double fLineThickness
)
84 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
85 const Size
& rSize
= rStyleSettings
.GetListBoxPreviewDefaultPixelSize();
86 const sal_uInt32
nFactor(2);
87 const Size
aSize((rSize
.Width() * 5 * 2) / 2, rSize
.Height() * nFactor
);
89 // prepare polygon geometry for line
90 basegfx::B2DPolygon aLine
;
92 aLine
.append(basegfx::B2DPoint(0.0, aSize
.Height() / 2.0));
93 aLine
.append(basegfx::B2DPoint(aSize
.Width(), aSize
.Height() / 2.0));
95 // prepare LineAttribute
96 const basegfx::BColor
aLineColor(rStyleSettings
.GetFieldTextColor().getBColor());
97 const double fLineWidth(fLineThickness
* nFactor
);
98 const drawinglayer::attribute::LineAttribute
aLineAttribute(
102 // prepare StrokeAttribute
103 ::std::vector
< double > aDotDashArray
;
104 double fFullDotDashLen(0.0);
106 if(pDash
&& (pDash
->GetDots() || pDash
->GetDashes()))
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
);
113 fFullDotDashLen
= pDash
->CreateDotDashArray(aDotDashArray
, fLineWidthInUnits
);
115 if(!aDotDashArray
.empty())
117 for(double & a
: aDotDashArray
)
120 // ~zero length dash is a dot-like dot (with line width size round cap), so show it
125 fFullDotDashLen
*= fScaleValue
;
129 drawinglayer::attribute::StrokeAttribute
aStrokeAttribute(
130 std::move(aDotDashArray
),
133 // create LinePrimitive
134 const drawinglayer::primitive2d::Primitive2DReference
aLinePrimitive(
135 new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
138 std::move(aStrokeAttribute
)));
140 // prepare VirtualDevice
141 ScopedVclPtrInstance
< VirtualDevice
> pVirtualDevice
;
142 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D
;
144 pVirtualDevice
->SetOutputSizePixel(aSize
);
145 pVirtualDevice
->SetDrawMode(rStyleSettings
.GetHighContrastMode()
146 ? DrawModeFlags::SettingsLine
| DrawModeFlags::SettingsFill
| DrawModeFlags::SettingsText
| DrawModeFlags::SettingsGradient
147 : DrawModeFlags::Default
);
149 if(rStyleSettings
.GetPreviewUsesCheckeredBackground())
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);
156 pVirtualDevice
->DrawCheckered(aNull
, aSize
, nLen
, aW
, aG
);
160 pVirtualDevice
->SetBackground(rStyleSettings
.GetFieldColor());
161 pVirtualDevice
->Erase();
164 // create processor and draw primitives
165 std::unique_ptr
<drawinglayer::processor2d::BaseProcessor2D
> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
167 aNewViewInformation2D
));
169 const drawinglayer::primitive2d::Primitive2DContainer aSequence
{ aLinePrimitive
};
171 pProcessor2D
->process(aSequence
);
172 pProcessor2D
.reset();
174 // get result bitmap and scale
175 BitmapEx
aRetval(pVirtualDevice
->GetBitmapEx(Point(0, 0), pVirtualDevice
->GetOutputSizePixel()));
179 aRetval
.Scale(Size((rSize
.Width() * 5) / 2, rSize
.Height()));
185 BitmapEx
XDashList::CreateBitmapForUI( tools::Long nIndex
)
187 const XDash
& rDash
= GetDash(nIndex
)->GetDash();
189 return CreateBitmapForXDash(&rDash
, ImpGetDefaultLineThickness());
192 BitmapEx
const & XDashList::GetBitmapForUISolidLine() const
194 if(maBitmapSolidLine
.IsEmpty())
196 const_cast< XDashList
* >(this)->maBitmapSolidLine
= XDashList::CreateBitmapForXDash(nullptr, ImpGetDefaultLineThickness());
199 return maBitmapSolidLine
;
202 OUString
const & XDashList::GetStringForUiSolidLine() const
204 if(maStringSolidLine
.isEmpty())
206 const_cast< XDashList
* >(this)->maStringSolidLine
= SvxResId(RID_SVXSTR_SOLID
);
209 return maStringSolidLine
;
212 OUString
const & XDashList::GetStringForUiNoLine() const
214 if(maStringNoLine
.isEmpty())
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
);
222 return maStringNoLine
;
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */