bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / editeng / borderline.hxx
blob64d7f2c5c3cb397c08d62b9ba99d27866f4674db
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/mapunit.hxx>
27 #include <editeng/editengdllapi.h>
28 #include <svtools/borderline.hxx>
30 class IntlWrapper;
32 // Line defaults in twips (former Writer defaults):
34 #define DEF_LINE_WIDTH_0 1
35 #define DEF_LINE_WIDTH_1 20
36 #define DEF_LINE_WIDTH_2 50
37 #define DEF_LINE_WIDTH_3 80
38 #define DEF_LINE_WIDTH_4 100
39 #define DEF_LINE_WIDTH_5 10
40 #define DEF_LINE_WIDTH_6 5 // 0.25pt
43 // Abstracts over values from css::table::BorderLineStyle
44 enum class SvxBorderLineStyle : sal_Int16
46 /** No border line
48 NONE = css::table::BorderLineStyle::NONE,
50 /** Solid border line.
52 SOLID = css::table::BorderLineStyle::SOLID,
54 /** Dotted border line.
56 DOTTED = css::table::BorderLineStyle::DOTTED,
58 /** Dashed border line.
60 DASHED = css::table::BorderLineStyle::DASHED,
62 /** Double border line. Widths of the lines and the gap are all equal,
63 and vary equally with the total width.
65 DOUBLE = css::table::BorderLineStyle::DOUBLE,
67 /** Double border line with a thin line outside and a thick line
68 inside separated by a small gap.
70 THINTHICK_SMALLGAP = css::table::BorderLineStyle::THINTHICK_SMALLGAP,
72 /** Double border line with a thin line outside and a thick line
73 inside separated by a medium gap.
75 THINTHICK_MEDIUMGAP = css::table::BorderLineStyle::THINTHICK_MEDIUMGAP,
77 /** Double border line with a thin line outside and a thick line
78 inside separated by a large gap.
80 THINTHICK_LARGEGAP = css::table::BorderLineStyle::THINTHICK_LARGEGAP,
82 /** Double border line with a thick line outside and a thin line
83 inside separated by a small gap.
85 THICKTHIN_SMALLGAP = css::table::BorderLineStyle::THICKTHIN_SMALLGAP,
87 /** Double border line with a thick line outside and a thin line
88 inside separated by a medium gap.
90 THICKTHIN_MEDIUMGAP = css::table::BorderLineStyle::THICKTHIN_MEDIUMGAP,
92 /** Double border line with a thick line outside and a thin line
93 inside separated by a large gap.
95 THICKTHIN_LARGEGAP = css::table::BorderLineStyle::THICKTHIN_LARGEGAP,
97 /** 3D embossed border line.
99 EMBOSSED = css::table::BorderLineStyle::EMBOSSED,
101 /** 3D engraved border line.
103 ENGRAVED = css::table::BorderLineStyle::ENGRAVED,
105 /** Outset border line.
107 OUTSET = css::table::BorderLineStyle::OUTSET,
109 /** Inset border line.
111 INSET = css::table::BorderLineStyle::INSET,
113 /** Finely dashed border line.
115 FINE_DASHED = css::table::BorderLineStyle::FINE_DASHED,
117 /** Double border line consisting of two fixed thin lines separated by a
118 variable gap.
120 DOUBLE_THIN = css::table::BorderLineStyle::DOUBLE_THIN,
122 /** Line consisting of a repetition of one dash and one dot. */
123 DASH_DOT = css::table::BorderLineStyle::DASH_DOT,
125 /** Line consisting of a repetition of one dash and 2 dots. */
126 DASH_DOT_DOT = css::table::BorderLineStyle::DASH_DOT_DOT,
128 /** Maximum valid border line style value.
130 BORDER_LINE_STYLE_MAX = css::table::BorderLineStyle::BORDER_LINE_STYLE_MAX,
133 namespace editeng
136 // convert border style between Word formats and LO
137 SvxBorderLineStyle EDITENG_DLLPUBLIC ConvertBorderStyleFromWord(int);
138 /// convert border width in twips between Word formats and LO
139 double EDITENG_DLLPUBLIC ConvertBorderWidthToWord(SvxBorderLineStyle, double);
140 double EDITENG_DLLPUBLIC ConvertBorderWidthFromWord(SvxBorderLineStyle,
141 double, int);
143 class EDITENG_DLLPUBLIC SvxBorderLine final
145 Color aColor;
147 long m_nWidth;
148 bool m_bMirrorWidths;
149 BorderWidthImpl m_aWidthImpl;
150 long m_nMult;
151 long m_nDiv;
153 SvxBorderLineStyle m_nStyle;
155 bool m_bUseLeftTop;
156 Color (*m_pColorOutFn)( Color );
157 Color (*m_pColorInFn)( Color );
158 Color (*m_pColorGapFn)( Color );
160 public:
161 SvxBorderLine( const Color *pCol = nullptr,
162 long nWidth = 0,
163 SvxBorderLineStyle nStyle = SvxBorderLineStyle::SOLID,
164 Color (*pColorOutFn)( Color ) = &darkColor,
165 Color (*pColorInFn)( Color ) = &darkColor );
167 const Color& GetColor() const { return aColor; }
168 Color GetColorOut( bool bLeftOrTop = true ) const;
169 Color GetColorIn( bool bLeftOrTop = true ) const;
170 bool HasGapColor() const { return m_pColorGapFn != nullptr; }
171 Color GetColorGap() const;
173 void SetWidth( long nWidth );
174 /** Guess the style and width from the three lines widths values.
176 When the value of nStyle is SvxBorderLine::DOUBLE, the style set will be guessed
177 using the three values to match the best possible style among the following:
178 - SvxBorderLine::DOUBLE
179 - SvxBorderLine::THINTHICK_SMALLGAP
180 - SvxBorderLine::THINTHICK_MEDIUMGAP
181 - SvxBorderLine::THINTHICK_LARGEGAP
182 - SvxBorderLine::THICKTHIN_SMALLGAP
183 - SvxBorderLine::THICKTHIN_MEDIUMGAP
184 - SvxBorderLine::THICKTHIN_LARGEGAP
186 If no styles matches the width, then the width is set to 0.
188 There is one known case that could fit several styles: \a nIn = \a nDist = 0.75 pt,
189 \a nOut = 1.5 pt. This case fits SvxBorderLine::THINTHICK_SMALLGAP and
190 SvxBorderLine::THINTHICK_MEDIUMGAP with a 1.5 pt width and
191 SvxBorderLine::THINTHICK_LARGEGAP with a 0.75 pt width. The same case happens
192 also for thick-thin styles.
194 \param nStyle the border style used to guess the width.
195 \param nIn the width of the inner line in 1th pt
196 \param nOut the width of the outer line in 1th pt
197 \param nDist the width of the gap between the lines in 1th pt
199 void GuessLinesWidths( SvxBorderLineStyle nStyle, sal_uInt16 nOut, sal_uInt16 nIn = 0, sal_uInt16 nDist = 0 );
201 // TODO Hacky method to mirror lines in only a few cases
202 void SetMirrorWidths() { m_bMirrorWidths = true; }
203 long GetWidth( ) const { return m_nWidth; }
204 sal_uInt16 GetOutWidth() const;
205 sal_uInt16 GetInWidth() const;
206 sal_uInt16 GetDistance() const;
208 SvxBorderLineStyle GetBorderLineStyle() const { return m_nStyle; }
210 void SetColor( const Color &rColor ) { aColor = rColor; }
211 void SetBorderLineStyle( SvxBorderLineStyle nNew );
212 void ScaleMetrics( long nMult, long nDiv );
214 bool operator==( const SvxBorderLine &rCmp ) const;
216 OUString GetValueString( MapUnit eSrcUnit, MapUnit eDestUnit,
217 const IntlWrapper* pIntl,
218 bool bMetricStr = false ) const;
220 bool HasPriority( const SvxBorderLine& rOtherLine ) const;
222 bool isEmpty() const {
223 return m_aWidthImpl.IsEmpty()
224 || m_nStyle == SvxBorderLineStyle::NONE
225 || m_nWidth == 0;
227 bool isDouble() const { return m_aWidthImpl.IsDouble(); }
228 sal_uInt16 GetScaledWidth() const { return GetOutWidth() + GetInWidth() + GetDistance(); }
230 static Color darkColor( Color aMain );
231 static Color lightColor( Color aMain );
233 static Color threeDLightColor( Color aMain );
234 static Color threeDMediumColor( Color aMain );
235 static Color threeDDarkColor( Color aMain );
237 static BorderWidthImpl getWidthImpl( SvxBorderLineStyle nStyle );
240 EDITENG_DLLPUBLIC bool operator!=( const SvxBorderLine& rLeft, const SvxBorderLine& rRight );
242 } // namespace editeng
244 #endif