1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINIKIN_FONT_STYLE_H
18 #define MINIKIN_FONT_STYLE_H
19 
20 namespace minikin {
21 
22 // FontStyle represents style information.
23 class FontStyle {
24 public:
25     enum class Weight : uint16_t {
26         THIN = 100,
27         EXTRA_LIGHT = 200,
28         LIGHT = 300,
29         NORMAL = 400,
30         MEDIUM = 500,
31         SEMI_BOLD = 600,
32         BOLD = 700,
33         EXTRA_BOLD = 800,
34         BLACK = 900,
35         EXTRA_BLACK = 1000,
36     };
37 
38     enum class Slant : bool {
39         ITALIC = true,
40         UPRIGHT = false,
41     };
42 
FontStyle()43     constexpr FontStyle() : FontStyle(Weight::NORMAL, Slant::UPRIGHT) {}
FontStyle(Weight weight)44     constexpr explicit FontStyle(Weight weight) : FontStyle(weight, Slant::UPRIGHT) {}
FontStyle(Slant slant)45     constexpr explicit FontStyle(Slant slant) : FontStyle(Weight::NORMAL, slant) {}
FontStyle(Weight weight,Slant slant)46     constexpr FontStyle(Weight weight, Slant slant)
47             : FontStyle(static_cast<uint16_t>(weight), slant) {}
FontStyle(uint16_t weight,Slant slant)48     constexpr FontStyle(uint16_t weight, Slant slant) : mWeight(weight), mSlant(slant) {}
49 
weight()50     constexpr uint16_t weight() const { return mWeight; }
slant()51     constexpr Slant slant() const { return mSlant; }
52 
53     constexpr bool operator==(const FontStyle& other) const {
54         return weight() == other.weight() && slant() == other.slant();
55     }
56 
identifier()57     constexpr uint32_t identifier() const {
58         return (static_cast<uint32_t>(weight()) << 16) | static_cast<uint32_t>(slant());
59     }
60 
61 private:
62     uint16_t mWeight;
63     Slant mSlant;
64 };
65 
66 }  // namespace minikin
67 
68 #endif  // MINIKIN_FONT_STYLE_H
69