Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/editeng/borderline.hxx
Line
Count
Source
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
#ifndef INCLUDED_EDITENG_BORDERLINE_HXX
21
#define INCLUDED_EDITENG_BORDERLINE_HXX
22
23
#include <com/sun/star/table/BorderLineStyle.hpp>
24
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
32
class IntlWrapper;
33
34
// Line width defaults in twips
35
// Thin matches Excel's default values
36
// See tdf#48622 for the discussion leading to these defaults.
37
namespace SvxBorderLineWidth
38
{
39
constexpr inline sal_Int16 Hairline = 1; // 0.05pt
40
constexpr inline sal_Int16 VeryThin = 10; // 0.5pt
41
constexpr inline sal_Int16 Thin = 15; // 0.75pt
42
constexpr inline sal_Int16 Medium = 30; // 1.5pt
43
constexpr inline sal_Int16 Thick = 45; // 2.25pt
44
constexpr inline sal_Int16 ExtraThick = 90; // 4.5pt
45
};
46
47
// Abstracts over values from css::table::BorderLineStyle
48
enum class SvxBorderLineStyle : sal_Int16
49
{
50
    /** No border line
51
     */
52
    NONE = css::table::BorderLineStyle::NONE,
53
54
    /** Solid border line.
55
     */
56
    SOLID = css::table::BorderLineStyle::SOLID,
57
58
    /** Dotted border line.
59
     */
60
    DOTTED = css::table::BorderLineStyle::DOTTED,
61
62
    /** Dashed border line.
63
     */
64
    DASHED = css::table::BorderLineStyle::DASHED,
65
66
    /** Double border line. Widths of the lines and the gap are all equal,
67
        and vary equally with the total width.
68
     */
69
    DOUBLE = css::table::BorderLineStyle::DOUBLE,
70
71
    /** Double border line with a thin line outside and a thick line
72
        inside separated by a small gap.
73
     */
74
    THINTHICK_SMALLGAP = css::table::BorderLineStyle::THINTHICK_SMALLGAP,
75
76
    /** Double border line with a thin line outside and a thick line
77
        inside separated by a medium gap.
78
     */
79
    THINTHICK_MEDIUMGAP = css::table::BorderLineStyle::THINTHICK_MEDIUMGAP,
80
81
    /** Double border line with a thin line outside and a thick line
82
        inside separated by a large gap.
83
     */
84
    THINTHICK_LARGEGAP = css::table::BorderLineStyle::THINTHICK_LARGEGAP,
85
86
    /** Double border line with a thick line outside and a thin line
87
        inside separated by a small gap.
88
     */
89
    THICKTHIN_SMALLGAP = css::table::BorderLineStyle::THICKTHIN_SMALLGAP,
90
91
    /** Double border line with a thick line outside and a thin line
92
        inside separated by a medium gap.
93
     */
94
    THICKTHIN_MEDIUMGAP = css::table::BorderLineStyle::THICKTHIN_MEDIUMGAP,
95
96
    /** Double border line with a thick line outside and a thin line
97
        inside separated by a large gap.
98
     */
99
    THICKTHIN_LARGEGAP = css::table::BorderLineStyle::THICKTHIN_LARGEGAP,
100
101
    /** 3D embossed border line.
102
     */
103
    EMBOSSED = css::table::BorderLineStyle::EMBOSSED,
104
105
    /** 3D engraved border line.
106
     */
107
    ENGRAVED = css::table::BorderLineStyle::ENGRAVED,
108
109
    /** Outset border line.
110
     */
111
    OUTSET = css::table::BorderLineStyle::OUTSET,
112
113
    /** Inset border line.
114
     */
115
    INSET = css::table::BorderLineStyle::INSET,
116
117
    /** Finely dashed border line.
118
     */
119
    FINE_DASHED = css::table::BorderLineStyle::FINE_DASHED,
120
121
    /** Double border line consisting of two fixed thin lines separated by a
122
        variable gap.
123
     */
124
    DOUBLE_THIN = css::table::BorderLineStyle::DOUBLE_THIN,
125
126
    /** Line consisting of a repetition of one dash and one dot. */
127
    DASH_DOT = css::table::BorderLineStyle::DASH_DOT,
128
129
    /** Line consisting of a repetition of one dash and 2 dots. */
130
    DASH_DOT_DOT = css::table::BorderLineStyle::DASH_DOT_DOT,
131
132
    /** Maximum valid border line style value.
133
     */
134
    BORDER_LINE_STYLE_MAX = css::table::BorderLineStyle::BORDER_LINE_STYLE_MAX,
135
};
136
137
namespace editeng
138
{
139
140
// convert border style between Word formats and LO
141
SvxBorderLineStyle EDITENG_DLLPUBLIC ConvertBorderStyleFromWord(int);
142
/// convert border width in twips between Word formats and LO
143
double EDITENG_DLLPUBLIC ConvertBorderWidthToWord(SvxBorderLineStyle, double);
144
double EDITENG_DLLPUBLIC ConvertBorderWidthFromWord(SvxBorderLineStyle,
145
        double, int);
146
147
class EDITENG_DLLPUBLIC SvxBorderLine final
148
{
149
    tools::Long m_nWidth;
150
    tools::Long m_nMult;
151
    tools::Long m_nDiv;
152
    Color (*m_pColorOutFn)(Color);
153
    Color (*m_pColorInFn)(Color);
154
    Color (*m_pColorGapFn)(Color);
155
    BorderWidthImpl m_aWidthImpl;
156
    Color m_aColor;
157
    model::ComplexColor m_aComplexColor;
158
    SvxBorderLineStyle   m_nStyle;
159
    bool m_bMirrorWidths;
160
    bool m_bUseLeftTop;
161
162
public:
163
    SvxBorderLine( const Color *pCol = nullptr,
164
            tools::Long nWidth = 0,
165
            SvxBorderLineStyle nStyle = SvxBorderLineStyle::SOLID,
166
            Color (*pColorOutFn)( Color ) = &darkColor,
167
            Color (*pColorInFn)( Color ) = &darkColor );
168
169
17.1k
    const Color & GetColor() const { return m_aColor; }
170
1.04M
    void SetColor(const Color & rColor ) { m_aColor = rColor; }
171
172
    model::ComplexColor const& getComplexColor() const
173
0
    {
174
0
        auto pUnConst = const_cast<SvxBorderLine*>(this);
175
0
        pUnConst->m_aComplexColor.setFinalColor(GetColor());
176
0
        return m_aComplexColor;
177
0
    }
178
179
    void setComplexColor(model::ComplexColor const& rComplexColor)
180
45.2k
    {
181
45.2k
        m_aComplexColor = rComplexColor;
182
45.2k
    }
183
184
    bool setComplexColorFromAny(css::uno::Any const& rValue);
185
186
187
    Color           GetColorOut( bool bLeftOrTop = true ) const;
188
    Color           GetColorIn( bool bLeftOrTop = true ) const;
189
2.97k
    bool            HasGapColor() const { return m_pColorGapFn != nullptr; }
190
    Color           GetColorGap() const;
191
192
    void SetWidth( tools::Long nWidth );
193
    /** Guess the style and width from the three lines widths values.
194
195
        When the value of nStyle is SvxBorderLine::DOUBLE, the style set will be guessed
196
        using the three values to match the best possible style among the following:
197
            - SvxBorderLine::DOUBLE
198
            - SvxBorderLine::THINTHICK_SMALLGAP
199
            - SvxBorderLine::THINTHICK_MEDIUMGAP
200
            - SvxBorderLine::THINTHICK_LARGEGAP
201
            - SvxBorderLine::THICKTHIN_SMALLGAP
202
            - SvxBorderLine::THICKTHIN_MEDIUMGAP
203
            - SvxBorderLine::THICKTHIN_LARGEGAP
204
205
        If no styles matches the width, then the width is set to 0.
206
207
        There is one known case that could fit several styles: \a nIn = \a nDist = 0.75 pt,
208
        \a nOut = 1.5 pt. This case fits SvxBorderLine::THINTHICK_SMALLGAP and
209
        SvxBorderLine::THINTHICK_MEDIUMGAP with a 1.5 pt width and
210
        SvxBorderLine::THINTHICK_LARGEGAP with a 0.75 pt width. The same case happens
211
        also for thick-thin styles.
212
213
        \param nStyle the border style used to guess the width.
214
        \param nIn the width of the inner line in 1th pt
215
        \param nOut the width of the outer line in 1th pt
216
        \param nDist the width of the gap between the lines in 1th pt
217
     */
218
    void            GuessLinesWidths( SvxBorderLineStyle nStyle, sal_uInt16 nOut, sal_uInt16 nIn = 0, sal_uInt16 nDist = 0 );
219
220
    // TODO Hacky method to mirror lines in only a few cases
221
0
    void            SetMirrorWidths() { m_bMirrorWidths = true; }
222
117k
    tools::Long            GetWidth( ) const { return m_nWidth; }
223
    sal_uInt16      GetOutWidth() const;
224
    sal_uInt16      GetInWidth() const;
225
    sal_uInt16      GetDistance() const;
226
227
2.29M
    SvxBorderLineStyle  GetBorderLineStyle() const { return m_nStyle; }
228
229
    void            SetBorderLineStyle( SvxBorderLineStyle nNew );
230
    void            ScaleMetrics( tools::Long nMult, tools::Long nDiv );
231
232
    bool            operator==( const SvxBorderLine &rCmp ) const;
233
234
    OUString        GetValueString( MapUnit eSrcUnit, MapUnit eDestUnit,
235
                                    const IntlWrapper* pIntl,
236
                                    bool bMetricStr = false ) const;
237
238
    bool            HasPriority( const SvxBorderLine& rOtherLine ) const;
239
240
265k
    bool isEmpty() const {
241
265k
        return m_aWidthImpl.IsEmpty()
242
265k
            || m_nStyle == SvxBorderLineStyle::NONE
243
265k
            || m_nWidth == 0;
244
265k
    }
245
0
    bool isDouble() const { return m_aWidthImpl.IsDouble(); }
246
11.3k
    sal_uInt16 GetScaledWidth() const { return GetOutWidth() + GetInWidth() + GetDistance(); }
247
248
    static Color darkColor( Color aMain );
249
    static Color lightColor( Color aMain );
250
251
    static Color threeDLightColor( Color aMain );
252
    static Color threeDMediumColor( Color aMain );
253
    static Color threeDDarkColor( Color aMain );
254
255
    static BorderWidthImpl getWidthImpl( SvxBorderLineStyle nStyle );
256
};
257
258
EDITENG_DLLPUBLIC bool operator!=( const SvxBorderLine& rLeft, const SvxBorderLine& rRight );
259
260
} // namespace editeng
261
262
#endif