Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/include/vcl/txtattr.hxx
Line
Count
Source (jump to first uncovered line)
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_VCL_TXTATTR_HXX
21
#define INCLUDED_VCL_TXTATTR_HXX
22
23
#include <config_options.h>
24
#include <tools/color.hxx>
25
#include <tools/debug.hxx>
26
#include <tools/fontenum.hxx>
27
#include <vcl/dllapi.h>
28
#include <memory>
29
30
namespace vcl { class Font; }
31
32
0
#define TEXTATTR_FONTCOLOR  1
33
0
#define TEXTATTR_FONTWEIGHT 3
34
35
#define TEXTATTR_USER_START 1000 //start id for user defined text attributes
36
37
38
class VCL_DLLPUBLIC TextAttrib
39
{
40
private:
41
    sal_uInt16 const        mnWhich;
42
43
protected:
44
0
                            TextAttrib( sal_uInt16 nWhich ) : mnWhich(nWhich) {}
45
0
                            TextAttrib( const TextAttrib& ) = default;
46
47
public:
48
49
    virtual                 ~TextAttrib();
50
51
0
    sal_uInt16              Which() const   { return mnWhich; }
52
    virtual void            SetFont( vcl::Font& rFont ) const = 0;
53
    virtual std::unique_ptr<TextAttrib> Clone() const = 0;
54
55
    virtual bool            operator==( const TextAttrib& rAttr ) const = 0;
56
    bool                    operator!=( const TextAttrib& rAttr ) const
57
0
                                { return !(*this == rAttr ); }
58
};
59
60
61
class VCL_DLLPUBLIC TextAttribFontColor final : public TextAttrib
62
{
63
private:
64
    Color   maColor;
65
66
public:
67
                            TextAttribFontColor( const Color& rColor );
68
69
0
    const Color&            GetColor() const { return maColor; }
70
71
    virtual void            SetFont( vcl::Font& rFont ) const override;
72
    virtual std::unique_ptr<TextAttrib> Clone() const override;
73
    virtual bool            operator==( const TextAttrib& rAttr ) const override;
74
75
};
76
77
class UNLESS_MERGELIBS_MORE(VCL_DLLPUBLIC) TextAttribFontWeight final : public TextAttrib
78
{
79
private:
80
    FontWeight  meWeight;
81
82
public:
83
                            TextAttribFontWeight( FontWeight eWeight );
84
85
    virtual void            SetFont( vcl::Font& rFont ) const override;
86
    virtual std::unique_ptr<TextAttrib> Clone() const override;
87
    virtual bool            operator==( const TextAttrib& rAttr ) const override;
88
89
0
    FontWeight getFontWeight() const { return meWeight; }
90
};
91
92
class TextCharAttrib
93
{
94
private:
95
    std::unique_ptr<TextAttrib>
96
                    mpAttr;
97
    sal_Int32       mnStart;
98
    sal_Int32       mnEnd;
99
100
public:
101
                    TextCharAttrib( const TextAttrib& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
102
                    TextCharAttrib( const TextCharAttrib& rTextCharAttrib );
103
104
0
    const TextAttrib&   GetAttr() const         { return *mpAttr; }
105
106
0
    sal_uInt16          Which() const               { return mpAttr->Which(); }
107
108
0
    sal_Int32           GetStart() const            { return mnStart; }
109
0
    void                SetStart(sal_Int32 n)       { mnStart = n; }
110
111
0
    sal_Int32           GetEnd() const              { return mnEnd; }
112
0
    void                SetEnd(sal_Int32 n)         { mnEnd = n; }
113
114
    inline sal_Int32    GetLen() const;
115
116
    inline void     MoveForward( sal_Int32 nDiff );
117
    inline void     MoveBackward( sal_Int32 nDiff );
118
119
    inline void     Expand( sal_Int32 nDiff );
120
    inline void     Collaps( sal_Int32 nDiff );
121
122
    inline bool     IsIn( sal_Int32 nIndex ) const;
123
    inline bool     IsInside( sal_Int32 nIndex ) const;
124
    inline bool     IsEmpty() const;
125
126
};
127
128
inline sal_Int32 TextCharAttrib::GetLen() const
129
0
{
130
0
    DBG_ASSERT( mnEnd >= mnStart, "TextCharAttrib: nEnd < nStart!" );
131
0
    return mnEnd-mnStart;
132
0
}
133
134
inline void TextCharAttrib::MoveForward( sal_Int32 nDiff )
135
0
{
136
0
    DBG_ASSERT( nDiff <= SAL_MAX_INT32-mnEnd, "TextCharAttrib: MoveForward?!" );
137
0
    mnStart = mnStart + nDiff;
138
0
    mnEnd = mnEnd + nDiff;
139
0
}
140
141
inline void TextCharAttrib::MoveBackward( sal_Int32 nDiff )
142
0
{
143
0
    DBG_ASSERT( mnStart >= nDiff, "TextCharAttrib: MoveBackward?!" );
144
0
    mnStart = mnStart - nDiff;
145
0
    mnEnd = mnEnd - nDiff;
146
0
}
147
148
inline void TextCharAttrib::Expand( sal_Int32 nDiff )
149
0
{
150
0
    DBG_ASSERT( nDiff <= SAL_MAX_INT32-mnEnd, "TextCharAttrib: Expand?!" );
151
0
    mnEnd = mnEnd + nDiff;
152
0
}
153
154
inline void TextCharAttrib::Collaps( sal_Int32 nDiff )
155
0
{
156
0
    DBG_ASSERT( mnEnd-mnStart >= nDiff, "TextCharAttrib: Collaps?!" );
157
0
    mnEnd = mnEnd - nDiff;
158
0
}
159
160
inline bool TextCharAttrib::IsIn( sal_Int32 nIndex ) const
161
0
{
162
0
    return ( ( mnStart <= nIndex ) && ( mnEnd >= nIndex ) );
163
0
}
164
165
inline bool TextCharAttrib::IsInside( sal_Int32 nIndex ) const
166
0
{
167
0
    return ( ( mnStart < nIndex ) && ( mnEnd > nIndex ) );
168
0
}
169
170
inline bool TextCharAttrib::IsEmpty() const
171
0
{
172
0
    return mnStart == mnEnd;
173
0
}
174
175
#endif // INCLUDED_VCL_TXTATTR_HXX
176
177
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */