aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkFontStyle.h
blob: f42d7dd4701824b6f15666bf875c839b41216092 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 * Copyright 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkFontStyle_DEFINED
#define SkFontStyle_DEFINED

#include "SkTypes.h"

class SK_API SkFontStyle {
public:
    enum Weight {
        kThin_Weight        = 100,
        kExtraLight_Weight  = 200,
        kLight_Weight       = 300,
        kNormal_Weight      = 400,
        kMedium_Weight      = 500,
        kSemiBold_Weight    = 600,
        kBold_Weight        = 700,
        kExtraBold_Weight   = 800,
        kBlack_Weight       = 900
    };

    enum Width {
        kUltraCondensed_Width   = 1,
        kExtraCondensed_Width   = 2,
        kCondensed_Width        = 3,
        kSemiCondensed_Width    = 4,
        kNormal_Width           = 5,
        kSemiExpanded_Width     = 6,
        kExpanded_Width         = 7,
        kExtraExpanded_Width    = 8,
        kUltaExpanded_Width     = 9
    };

    enum Slant {
        kUpright_Slant,
        kItalic_Slant,
    };

    SkFontStyle();
    SkFontStyle(int weight, int width, Slant);
    /** oldStyle means the style-bits in SkTypeface::Style: bold=1, italic=2 */
    explicit SkFontStyle(unsigned oldStyle);

    bool operator==(const SkFontStyle& rhs) const {
        return fUnion.fU32 == rhs.fUnion.fU32;
    }

    int weight() const { return fUnion.fR.fWeight; }
    int width() const { return fUnion.fR.fWidth; }
    Slant slant() const { return (Slant)fUnion.fR.fSlant; }

    bool isItalic() const {
        return kItalic_Slant == fUnion.fR.fSlant;
    }

private:
    union {
        struct {
            uint16_t fWeight;   // 100 .. 900
            uint8_t  fWidth;    // 1 .. 9
            uint8_t  fSlant;    // 0 .. 2
        } fR;
        uint32_t    fU32;
    } fUnion;
};

#endif