1 /* 2 * Copyright (C) 2018 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_VARIATION_H 18 #define MINIKIN_FONT_VARIATION_H 19 20 #include <cstdint> 21 #include <iostream> 22 23 #include "minikin/SortedPackedVector.h" 24 25 namespace minikin { 26 27 typedef uint32_t AxisTag; 28 29 struct FontVariation { 30 FontVariation() = default; FontVariationFontVariation31 FontVariation(AxisTag axisTag, float value) : axisTag(axisTag), value(value) {} 32 AxisTag axisTag; 33 float value; 34 }; 35 36 constexpr bool operator==(const FontVariation& l, const FontVariation& r) { 37 return l.axisTag == r.axisTag && l.value == r.value; 38 } 39 40 constexpr bool operator!=(const FontVariation& l, const FontVariation& r) { 41 return !(l == r); 42 } 43 44 constexpr bool operator<(const FontVariation& l, const FontVariation& r) { 45 return l.axisTag < r.axisTag; 46 } 47 48 constexpr bool operator>(const FontVariation& l, const FontVariation& r) { 49 return l.axisTag > r.axisTag; 50 } 51 52 constexpr bool operator<=(const FontVariation& l, const FontVariation& r) { 53 return l.axisTag <= r.axisTag; 54 } 55 56 constexpr bool operator>=(const FontVariation& l, const FontVariation& r) { 57 return l.axisTag >= r.axisTag; 58 } 59 60 // Immutable variation settings 61 using VariationSettings = SortedPackedVector<FontVariation, 2, uint16_t>; 62 63 inline std::ostream& operator<<(std::ostream& os, const FontVariation& variation) { 64 return os << "'" << static_cast<char>(variation.axisTag >> 24) 65 << static_cast<char>(variation.axisTag >> 16) 66 << static_cast<char>(variation.axisTag >> 8) << static_cast<char>(variation.axisTag) 67 << "' " << variation.value; 68 } 69 70 inline std::ostream& operator<<(std::ostream& os, const VariationSettings& varSettings) { 71 for (size_t i = 0; i < varSettings.size(); ++i) { 72 if (i != 0) { 73 os << ", "; 74 } 75 os << varSettings[i]; 76 } 77 return os; 78 } 79 80 } // namespace minikin 81 82 #endif // MINIKIN_FONT_VARIATION_H 83