• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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_FEATURE_H
18 #define MINIKIN_FONT_FEATURE_H
19 
20 #include <hb.h>
21 
22 #include <ostream>
23 #include <string_view>
24 #include <vector>
25 
26 namespace minikin {
27 
28 struct MinikinPaint;
29 
30 // Subset of the hb_feature_t since we don't allow setting features on ranges.
31 struct FontFeature {
32     hb_tag_t tag;
33     uint32_t value;
34 
35     static std::vector<FontFeature> parse(std::string_view fontFeatureString);
36 };
37 
38 /**
39  * Returns the final set of font features based on the features requested by this paint object and
40  * extra defaults or implied font features.
41  *
42  * Features are included from the paint object if they are:
43  *   1) in a supported range
44  *
45  * Default features are added based if they are:
46  *   1) implied due to Paint settings such as letterSpacing
47  *   2) default features that do not conflict with requested features
48  */
49 std::vector<hb_feature_t> cleanAndAddDefaultFontFeatures(const MinikinPaint& features);
50 
51 // For gtest output
52 inline std::ostream& operator<<(std::ostream& os, const FontFeature& feature) {
53     return os << static_cast<char>(feature.tag >> 24) << static_cast<char>(feature.tag >> 16)
54               << static_cast<char>(feature.tag >> 8) << static_cast<char>(feature.tag) << " "
55               << feature.value;
56 }
57 
58 inline std::ostream& operator<<(std::ostream& os, const std::vector<FontFeature>& features) {
59     for (size_t i = 0; i < features.size(); ++i) {
60         if (i != 0) {
61             os << ", ";
62         }
63         os << features;
64     }
65     return os;
66 }
67 
68 constexpr bool operator==(const FontFeature& l, const FontFeature& r) {
69     return l.tag == r.tag && l.value == r.value;
70 }
71 
72 constexpr bool operator!=(const FontFeature& l, const FontFeature& r) {
73     return !(l == r);
74 }
75 
76 }  // namespace minikin
77 #endif  // MINIKIN_LAYOUT_H
78