Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/vcl/font.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_VCL_FONT_HXX
21
#define INCLUDED_VCL_FONT_HXX
22
23
#include <rtl/ustring.hxx>
24
#include <sal/types.h>
25
#include <vcl/dllapi.h>
26
#include <vcl/font/Variation.hxx>
27
#include <tools/fontenum.hxx>
28
#include <tools/long.hxx>
29
#include <tools/degree.hxx>
30
#include <i18nlangtag/lang.h>
31
#include <o3tl/cow_wrapper.hxx>
32
33
class Color;
34
class Size;
35
class LanguageTag;
36
class SvStream;
37
38
class ImplFont;
39
class FontAttributes;
40
namespace vcl { class Font; }
41
enum class FontKerning;
42
enum class FontRelief;
43
44
// need to first declare these outside the vcl namespace, or the friend declarations won't work right
45
VCL_DLLPUBLIC SvStream&  ReadFont( SvStream& rIStm, vcl::Font& );
46
VCL_DLLPUBLIC SvStream&  WriteFont( SvStream& rOStm, const vcl::Font& );
47
48
namespace vcl {
49
50
class SAL_WARN_UNUSED VCL_DLLPUBLIC Font
51
{
52
public:
53
    explicit            Font();
54
                        Font( const Font& ); // TODO make me explicit
55
                        Font( Font&& ) noexcept;
56
    explicit            Font( const OUString& rFamilyName, const Size& );
57
    explicit            Font( const OUString& rFamilyName, const OUString& rStyleName, const Size& );
58
    explicit            Font( FontFamily eFamily, const Size& );
59
    virtual             ~Font();
60
61
    const OUString&     GetFamilyName() const;
62
    FontFamily          GetFamilyTypeMaybeAskConfig();
63
    FontFamily          GetFamilyType() const;
64
    const OUString&     GetStyleName() const;
65
66
    FontWeight          GetWeightMaybeAskConfig();
67
    FontWeight          GetWeight() const;
68
    FontItalic          GetItalicMaybeAskConfig();
69
    FontItalic          GetItalic() const;
70
    FontPitch           GetPitchMaybeAskConfig();
71
    FontPitch           GetPitch() const;
72
    FontWidth           GetWidthTypeMaybeAskConfig();
73
    FontWidth           GetWidthType() const;
74
    TextAlign           GetAlignment() const;
75
    rtl_TextEncoding    GetCharSet() const;
76
    FontEmphasisMark    GetEmphasisMarkStyle() const;
77
78
    void                SetFamilyName( const OUString& rFamilyName );
79
    void                SetStyleName( const OUString& rStyleName );
80
    void                SetFamily( FontFamily );
81
82
    void                SetPitch( FontPitch ePitch );
83
    void                SetItalic( FontItalic );
84
    void                SetWeight( FontWeight );
85
    void                SetWidthType( FontWidth );
86
    void                SetAlignment( TextAlign );
87
    void                SetCharSet( rtl_TextEncoding );
88
89
    // Device dependent functions
90
    int                 GetQuality() const;
91
92
    void                SetQuality(int);
93
    void                IncreaseQualityBy(int);
94
    void                DecreaseQualityBy(int);
95
96
    // setting the color on the font is obsolete, the only remaining
97
    // valid use is for keeping backward compatibility with old MetaFiles
98
    const Color&        GetColor() const;
99
    const Color&        GetFillColor() const;
100
101
    bool                IsTransparent() const;
102
103
    void                SetColor( const Color& );
104
    void                SetFillColor( const Color& );
105
106
    void                SetTransparent( bool bTransparent );
107
108
    void                SetFontSize( const Size& );
109
    const Size&         GetFontSize() const;
110
    void                SetFontHeight( tools::Long nHeight );
111
    tools::Long                GetFontHeight() const;
112
    void                SetFontWidth( tools::Long nWidth );
113
    tools::Long                GetFontWidth() const;
114
    SAL_DLLPRIVATE const FontFamily& GetFontFamily() const;
115
116
    // tdf#127471 for corrections on EMF/WMF we need the AvgFontWidth in Windows-specific notation
117
    tools::Long         GetOrCalculateAverageFontWidth() const;
118
119
    // Prefer LanguageTag over LanguageType
120
    SAL_DLLPRIVATE void SetLanguageTag( const LanguageTag & );
121
    SAL_DLLPRIVATE const LanguageTag& GetLanguageTag() const;
122
    SAL_DLLPRIVATE void SetCJKContextLanguageTag( const LanguageTag& );
123
    SAL_DLLPRIVATE const LanguageTag& GetCJKContextLanguageTag() const;
124
    void                SetLanguage( LanguageType );
125
    LanguageType        GetLanguage() const;
126
    void                SetCJKContextLanguage( LanguageType );
127
    LanguageType        GetCJKContextLanguage() const;
128
129
    void                SetOrientation( Degree10 nLineOrientation );
130
    Degree10            GetOrientation() const;
131
    void                SetVertical( bool bVertical );
132
    bool                IsVertical() const;
133
    void                SetKerning( FontKerning nKerning );
134
    FontKerning         GetKerning() const;
135
    bool                IsKerning() const;
136
    void                SetFixKerning(const short nSpacing);
137
    short               GetFixKerning() const;
138
    bool                IsFixKerning() const;
139
140
    void                SetOpticalSizing( bool bOpticalSizing );
141
    bool                GetOpticalSizing() const;
142
143
    void                SetVariations( const std::vector<vcl::font::Variation>& rVariations );
144
    const std::vector<vcl::font::Variation>& GetVariations() const;
145
146
    void                SetOutline( bool bOutline );
147
    bool                IsOutline() const;
148
    void                SetShadow( bool bShadow );
149
    bool                IsShadow() const;
150
    void                SetRelief( FontRelief );
151
    FontRelief          GetRelief() const;
152
    void                SetUnderline( FontLineStyle );
153
    FontLineStyle       GetUnderline() const;
154
    void                SetOverline( FontLineStyle );
155
    FontLineStyle       GetOverline() const;
156
    void                SetStrikeout( FontStrikeout );
157
    FontStrikeout       GetStrikeout() const;
158
    void                SetEmphasisMark( FontEmphasisMark );
159
    FontEmphasisMark    GetEmphasisMark() const;
160
    void                SetWordLineMode( bool bWordLine );
161
    bool                IsWordLineMode() const;
162
163
    void                Merge( const Font& rFont );
164
    SAL_DLLPRIVATE void GetFontAttributes( FontAttributes& rAttrs ) const;
165
166
    Font&               operator=( const Font& );
167
    Font&               operator=( Font&& ) noexcept;
168
    bool                operator==( const Font& ) const;
169
    bool                operator!=( const Font& rFont ) const
170
4.63M
                            { return !(Font::operator==( rFont )); }
171
    bool                IsSameInstance( const Font& ) const;
172
    SAL_DLLPRIVATE bool EqualIgnoreColor( const Font& ) const;
173
174
    // Compute value usable as hash.
175
    SAL_DLLPRIVATE size_t GetHashValueIgnoreColor() const;
176
177
    friend VCL_DLLPUBLIC SvStream&  ::ReadFont( SvStream& rIStm, vcl::Font& );
178
    friend VCL_DLLPUBLIC SvStream&  ::WriteFont( SvStream& rOStm, const vcl::Font& );
179
180
    static Font identifyFont( const void* pBuffer, sal_uInt32 nLen );
181
182
    typedef o3tl::cow_wrapper< ImplFont > ImplType;
183
184
    inline bool IsUnderlineAbove() const;
185
186
private:
187
    ImplType mpImplFont;
188
};
189
190
inline bool Font::IsUnderlineAbove() const
191
3.34k
{
192
3.34k
    if (!IsVertical())
193
3.34k
        return false;
194
    // the underline is right for Japanese only
195
0
    return (LANGUAGE_JAPANESE == GetLanguage()) ||
196
0
           (LANGUAGE_JAPANESE == GetCJKContextLanguage());
197
3.34k
}
198
199
}
200
201
#endif  // _VCL_FONT_HXX
202
203
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */