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 #ifndef INCLUDED_EDITENG_BORDERLINE_HXX
21 #define INCLUDED_EDITENG_BORDERLINE_HXX
23 #include <com/sun/star/table/BorderLineStyle.hpp>
25 #include <tools/color.hxx>
26 #include <tools/long.hxx>
27 #include <tools/mapunit.hxx>
28 #include <editeng/editengdllapi.h>
29 #include <svtools/borderline.hxx>
30 #include <docmodel/color/ComplexColor.hxx>
31 #include <o3tl/hash_combine.hxx>
35 // Line width defaults in twips
36 // Thin matches Excel's default values
37 // See tdf#48622 for the discussion leading to these defaults.
38 namespace SvxBorderLineWidth
40 constexpr inline sal_Int16 Hairline
= 1; // 0.05pt
41 constexpr inline sal_Int16 VeryThin
= 10; // 0.5pt
42 constexpr inline sal_Int16 Thin
= 15; // 0.75pt
43 constexpr inline sal_Int16 Medium
= 30; // 1.5pt
44 constexpr inline sal_Int16 Thick
= 45; // 2.25pt
45 constexpr inline sal_Int16 ExtraThick
= 90; // 4.5pt
48 // Abstracts over values from css::table::BorderLineStyle
49 enum class SvxBorderLineStyle
: sal_Int16
53 NONE
= css::table::BorderLineStyle::NONE
,
55 /** Solid border line.
57 SOLID
= css::table::BorderLineStyle::SOLID
,
59 /** Dotted border line.
61 DOTTED
= css::table::BorderLineStyle::DOTTED
,
63 /** Dashed border line.
65 DASHED
= css::table::BorderLineStyle::DASHED
,
67 /** Double border line. Widths of the lines and the gap are all equal,
68 and vary equally with the total width.
70 DOUBLE
= css::table::BorderLineStyle::DOUBLE
,
72 /** Double border line with a thin line outside and a thick line
73 inside separated by a small gap.
75 THINTHICK_SMALLGAP
= css::table::BorderLineStyle::THINTHICK_SMALLGAP
,
77 /** Double border line with a thin line outside and a thick line
78 inside separated by a medium gap.
80 THINTHICK_MEDIUMGAP
= css::table::BorderLineStyle::THINTHICK_MEDIUMGAP
,
82 /** Double border line with a thin line outside and a thick line
83 inside separated by a large gap.
85 THINTHICK_LARGEGAP
= css::table::BorderLineStyle::THINTHICK_LARGEGAP
,
87 /** Double border line with a thick line outside and a thin line
88 inside separated by a small gap.
90 THICKTHIN_SMALLGAP
= css::table::BorderLineStyle::THICKTHIN_SMALLGAP
,
92 /** Double border line with a thick line outside and a thin line
93 inside separated by a medium gap.
95 THICKTHIN_MEDIUMGAP
= css::table::BorderLineStyle::THICKTHIN_MEDIUMGAP
,
97 /** Double border line with a thick line outside and a thin line
98 inside separated by a large gap.
100 THICKTHIN_LARGEGAP
= css::table::BorderLineStyle::THICKTHIN_LARGEGAP
,
102 /** 3D embossed border line.
104 EMBOSSED
= css::table::BorderLineStyle::EMBOSSED
,
106 /** 3D engraved border line.
108 ENGRAVED
= css::table::BorderLineStyle::ENGRAVED
,
110 /** Outset border line.
112 OUTSET
= css::table::BorderLineStyle::OUTSET
,
114 /** Inset border line.
116 INSET
= css::table::BorderLineStyle::INSET
,
118 /** Finely dashed border line.
120 FINE_DASHED
= css::table::BorderLineStyle::FINE_DASHED
,
122 /** Double border line consisting of two fixed thin lines separated by a
125 DOUBLE_THIN
= css::table::BorderLineStyle::DOUBLE_THIN
,
127 /** Line consisting of a repetition of one dash and one dot. */
128 DASH_DOT
= css::table::BorderLineStyle::DASH_DOT
,
130 /** Line consisting of a repetition of one dash and 2 dots. */
131 DASH_DOT_DOT
= css::table::BorderLineStyle::DASH_DOT_DOT
,
133 /** Maximum valid border line style value.
135 BORDER_LINE_STYLE_MAX
= css::table::BorderLineStyle::BORDER_LINE_STYLE_MAX
,
141 // convert border style between Word formats and LO
142 SvxBorderLineStyle EDITENG_DLLPUBLIC
ConvertBorderStyleFromWord(int);
143 /// convert border width in twips between Word formats and LO
144 double EDITENG_DLLPUBLIC
ConvertBorderWidthToWord(SvxBorderLineStyle
, double);
145 double EDITENG_DLLPUBLIC
ConvertBorderWidthFromWord(SvxBorderLineStyle
,
148 class EDITENG_DLLPUBLIC SvxBorderLine final
150 tools::Long m_nWidth
;
153 Color (*m_pColorOutFn
)(Color
);
154 Color (*m_pColorInFn
)(Color
);
155 Color (*m_pColorGapFn
)(Color
);
156 BorderWidthImpl m_aWidthImpl
;
158 model::ComplexColor m_aComplexColor
;
159 SvxBorderLineStyle m_nStyle
;
160 bool m_bMirrorWidths
;
164 SvxBorderLine( const Color
*pCol
= nullptr,
165 tools::Long nWidth
= 0,
166 SvxBorderLineStyle nStyle
= SvxBorderLineStyle::SOLID
,
167 Color (*pColorOutFn
)( Color
) = &darkColor
,
168 Color (*pColorInFn
)( Color
) = &darkColor
);
170 const Color
& GetColor() const { return m_aColor
; }
171 void SetColor(const Color
& rColor
) { m_aColor
= rColor
; }
173 model::ComplexColor
const& getComplexColor() const
175 auto pUnConst
= const_cast<SvxBorderLine
*>(this);
176 pUnConst
->m_aComplexColor
.setFinalColor(GetColor());
177 return m_aComplexColor
;
180 void setComplexColor(model::ComplexColor
const& rComplexColor
)
182 m_aComplexColor
= rComplexColor
;
185 bool setComplexColorFromAny(css::uno::Any
const& rValue
);
188 Color
GetColorOut( bool bLeftOrTop
= true ) const;
189 Color
GetColorIn( bool bLeftOrTop
= true ) const;
190 bool HasGapColor() const { return m_pColorGapFn
!= nullptr; }
191 Color
GetColorGap() const;
193 void SetWidth( tools::Long nWidth
);
194 /** Guess the style and width from the three lines widths values.
196 When the value of nStyle is SvxBorderLine::DOUBLE, the style set will be guessed
197 using the three values to match the best possible style among the following:
198 - SvxBorderLine::DOUBLE
199 - SvxBorderLine::THINTHICK_SMALLGAP
200 - SvxBorderLine::THINTHICK_MEDIUMGAP
201 - SvxBorderLine::THINTHICK_LARGEGAP
202 - SvxBorderLine::THICKTHIN_SMALLGAP
203 - SvxBorderLine::THICKTHIN_MEDIUMGAP
204 - SvxBorderLine::THICKTHIN_LARGEGAP
206 If no styles matches the width, then the width is set to 0.
208 There is one known case that could fit several styles: \a nIn = \a nDist = 0.75 pt,
209 \a nOut = 1.5 pt. This case fits SvxBorderLine::THINTHICK_SMALLGAP and
210 SvxBorderLine::THINTHICK_MEDIUMGAP with a 1.5 pt width and
211 SvxBorderLine::THINTHICK_LARGEGAP with a 0.75 pt width. The same case happens
212 also for thick-thin styles.
214 \param nStyle the border style used to guess the width.
215 \param nIn the width of the inner line in 1th pt
216 \param nOut the width of the outer line in 1th pt
217 \param nDist the width of the gap between the lines in 1th pt
219 void GuessLinesWidths( SvxBorderLineStyle nStyle
, sal_uInt16 nOut
, sal_uInt16 nIn
= 0, sal_uInt16 nDist
= 0 );
221 // TODO Hacky method to mirror lines in only a few cases
222 void SetMirrorWidths() { m_bMirrorWidths
= true; }
223 tools::Long
GetWidth( ) const { return m_nWidth
; }
224 sal_uInt16
GetOutWidth() const;
225 sal_uInt16
GetInWidth() const;
226 sal_uInt16
GetDistance() const;
228 SvxBorderLineStyle
GetBorderLineStyle() const { return m_nStyle
; }
230 void SetBorderLineStyle( SvxBorderLineStyle nNew
);
231 void ScaleMetrics( tools::Long nMult
, tools::Long nDiv
);
233 bool operator==( const SvxBorderLine
&rCmp
) const;
235 OUString
GetValueString( MapUnit eSrcUnit
, MapUnit eDestUnit
,
236 const IntlWrapper
* pIntl
,
237 bool bMetricStr
= false ) const;
239 bool HasPriority( const SvxBorderLine
& rOtherLine
) const;
241 bool isEmpty() const {
242 return m_aWidthImpl
.IsEmpty()
243 || m_nStyle
== SvxBorderLineStyle::NONE
246 bool isDouble() const { return m_aWidthImpl
.IsDouble(); }
247 sal_uInt16
GetScaledWidth() const { return GetOutWidth() + GetInWidth() + GetDistance(); }
249 static Color
darkColor( Color aMain
);
250 static Color
lightColor( Color aMain
);
252 static Color
threeDLightColor( Color aMain
);
253 static Color
threeDMediumColor( Color aMain
);
254 static Color
threeDDarkColor( Color aMain
);
256 static BorderWidthImpl
getWidthImpl( SvxBorderLineStyle nStyle
);
259 EDITENG_DLLPUBLIC
bool operator!=( const SvxBorderLine
& rLeft
, const SvxBorderLine
& rRight
);
261 } // namespace editeng