Coverage Report

Created: 2024-05-20 07:14

/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/base/SkTPin.h"
13
14
#include <cstdint>
15
16
class SK_API SkFontStyle {
17
public:
18
    enum Weight {
19
        kInvisible_Weight   =    0,
20
        kThin_Weight        =  100,
21
        kExtraLight_Weight  =  200,
22
        kLight_Weight       =  300,
23
        kNormal_Weight      =  400,
24
        kMedium_Weight      =  500,
25
        kSemiBold_Weight    =  600,
26
        kBold_Weight        =  700,
27
        kExtraBold_Weight   =  800,
28
        kBlack_Weight       =  900,
29
        kExtraBlack_Weight  = 1000,
30
    };
31
32
    enum Width {
33
        kUltraCondensed_Width   = 1,
34
        kExtraCondensed_Width   = 2,
35
        kCondensed_Width        = 3,
36
        kSemiCondensed_Width    = 4,
37
        kNormal_Width           = 5,
38
        kSemiExpanded_Width     = 6,
39
        kExpanded_Width         = 7,
40
        kExtraExpanded_Width    = 8,
41
        kUltraExpanded_Width    = 9,
42
    };
43
44
    enum Slant {
45
        kUpright_Slant,
46
        kItalic_Slant,
47
        kOblique_Slant,
48
    };
49
50
    constexpr SkFontStyle(int weight, int width, Slant slant) : fValue(
51
        (SkTPin<int>(weight, kInvisible_Weight, kExtraBlack_Weight)) +
52
        (SkTPin<int>(width, kUltraCondensed_Width, kUltraExpanded_Width) << 16) +
53
        (SkTPin<int>(slant, kUpright_Slant, kOblique_Slant) << 24)
54
48.1M
     ) { }
55
56
47.3M
    constexpr SkFontStyle() : SkFontStyle{kNormal_Weight, kNormal_Width, kUpright_Slant} { }
57
58
4.57k
    bool operator==(const SkFontStyle& rhs) const {
59
4.57k
        return fValue == rhs.fValue;
60
4.57k
    }
61
62
8.43M
    int weight() const { return fValue & 0xFFFF; }
63
7.03M
    int width() const { return (fValue >> 16) & 0xFF; }
64
2.84M
    Slant slant() const { return (Slant)((fValue >> 24) & 0xFF); }
65
66
1.36k
    static constexpr SkFontStyle Normal() {
67
1.36k
        return SkFontStyle(kNormal_Weight, kNormal_Width, kUpright_Slant);
68
1.36k
    }
69
0
    static constexpr SkFontStyle Bold() {
70
0
        return SkFontStyle(kBold_Weight,   kNormal_Width, kUpright_Slant);
71
0
    }
72
0
    static constexpr SkFontStyle Italic() {
73
0
        return SkFontStyle(kNormal_Weight, kNormal_Width, kItalic_Slant );
74
0
    }
75
0
    static constexpr SkFontStyle BoldItalic() {
76
0
        return SkFontStyle(kBold_Weight,   kNormal_Width, kItalic_Slant );
77
0
    }
78
79
private:
80
    friend class SkTypefaceProxyPrototype;  // To serialize fValue
81
    int32_t fValue;
82
};
83
84
#endif