Coverage Report

Created: 2021-08-22 09:07

/src/skia/include/core/SkFontStyle.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2013 Google Inc.
3
 *
4
 * Use of this source code is governed by a BSD-style license that can be
5
 * found in the LICENSE file.
6
 */
7
8
#ifndef SkFontStyle_DEFINED
9
#define SkFontStyle_DEFINED
10
11
#include "include/core/SkTypes.h"
12
#include "include/private/SkTPin.h"
13
14
class SK_API SkFontStyle {
15
public:
16
    enum Weight {
17
        kInvisible_Weight   =    0,
18
        kThin_Weight        =  100,
19
        kExtraLight_Weight  =  200,
20
        kLight_Weight       =  300,
21
        kNormal_Weight      =  400,
22
        kMedium_Weight      =  500,
23
        kSemiBold_Weight    =  600,
24
        kBold_Weight        =  700,
25
        kExtraBold_Weight   =  800,
26
        kBlack_Weight       =  900,
27
        kExtraBlack_Weight  = 1000,
28
    };
29
30
    enum Width {
31
        kUltraCondensed_Width   = 1,
32
        kExtraCondensed_Width   = 2,
33
        kCondensed_Width        = 3,
34
        kSemiCondensed_Width    = 4,
35
        kNormal_Width           = 5,
36
        kSemiExpanded_Width     = 6,
37
        kExpanded_Width         = 7,
38
        kExtraExpanded_Width    = 8,
39
        kUltraExpanded_Width    = 9,
40
    };
41
42
    enum Slant {
43
        kUpright_Slant,
44
        kItalic_Slant,
45
        kOblique_Slant,
46
    };
47
48
    constexpr SkFontStyle(int weight, int width, Slant slant) : fValue(
49
        (SkTPin<int>(weight, kInvisible_Weight, kExtraBlack_Weight)) +
50
        (SkTPin<int>(width, kUltraCondensed_Width, kUltraExpanded_Width) << 16) +
51
        (SkTPin<int>(slant, kUpright_Slant, kOblique_Slant) << 24)
52
484M
     ) { }
53
54
483M
    constexpr SkFontStyle() : SkFontStyle{kNormal_Weight, kNormal_Width, kUpright_Slant} { }
55
56
81.2k
    bool operator==(const SkFontStyle& rhs) const {
57
81.2k
        return fValue == rhs.fValue;
58
81.2k
    }
59
60
257k
    int weight() const { return fValue & 0xFFFF; }
61
253k
    int width() const { return (fValue >> 16) & 0xFF; }
62
175k
    Slant slant() const { return (Slant)((fValue >> 24) & 0xFF); }
63
64
12.0k
    static constexpr SkFontStyle Normal() {
65
12.0k
        return SkFontStyle(kNormal_Weight, kNormal_Width, kUpright_Slant);
66
12.0k
    }
67
0
    static constexpr SkFontStyle Bold() {
68
0
        return SkFontStyle(kBold_Weight,   kNormal_Width, kUpright_Slant);
69
0
    }
70
0
    static constexpr SkFontStyle Italic() {
71
0
        return SkFontStyle(kNormal_Weight, kNormal_Width, kItalic_Slant );
72
0
    }
73
0
    static constexpr SkFontStyle BoldItalic() {
74
0
        return SkFontStyle(kBold_Weight,   kNormal_Width, kItalic_Slant );
75
0
    }
76
77
private:
78
    int32_t fValue;
79
};
80
81
#endif