Flutter Impeller
glyph.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_IMPELLER_TYPOGRAPHER_GLYPH_H_
6 #define FLUTTER_IMPELLER_TYPOGRAPHER_GLYPH_H_
7 
8 #include <cstdint>
9 #include <functional>
10 
11 namespace impeller {
12 
13 //------------------------------------------------------------------------------
14 /// @brief The glyph index in the typeface.
15 ///
16 struct Glyph {
17  enum class Type : uint8_t {
18  kPath,
19  kBitmap,
20  };
21 
22  uint16_t index = 0;
23 
24  //------------------------------------------------------------------------------
25  /// @brief Whether the glyph is a path or a bitmap.
26  ///
28 
29  Glyph(uint16_t p_index, Type p_type) : index(p_index), type(p_type) {}
30 };
31 
32 // Many Glyph instances are instantiated, so care should be taken when
33 // increasing the size.
34 static_assert(sizeof(Glyph) == 4);
35 
36 } // namespace impeller
37 
38 template <>
39 struct std::hash<impeller::Glyph> {
40  constexpr std::size_t operator()(const impeller::Glyph& g) const {
41  static_assert(sizeof(g.index) == 2);
42  static_assert(sizeof(g.type) == 1);
43  return (static_cast<size_t>(g.type) << 16) | g.index;
44  }
45 };
46 
47 template <>
48 struct std::equal_to<impeller::Glyph> {
49  constexpr bool operator()(const impeller::Glyph& lhs,
50  const impeller::Glyph& rhs) const {
51  return lhs.index == rhs.index && lhs.type == rhs.type;
52  }
53 };
54 
55 template <>
56 struct std::less<impeller::Glyph> {
57  constexpr bool operator()(const impeller::Glyph& lhs,
58  const impeller::Glyph& rhs) const {
59  return lhs.index < rhs.index;
60  }
61 };
62 
63 #endif // FLUTTER_IMPELLER_TYPOGRAPHER_GLYPH_H_
The glyph index in the typeface.
Definition: glyph.h:16
uint16_t index
Definition: glyph.h:22
Glyph(uint16_t p_index, Type p_type)
Definition: glyph.h:29
Type type
Whether the glyph is a path or a bitmap.
Definition: glyph.h:27
constexpr bool operator()(const impeller::Glyph &lhs, const impeller::Glyph &rhs) const
Definition: glyph.h:49
constexpr std::size_t operator()(const impeller::Glyph &g) const
Definition: glyph.h:40
constexpr bool operator()(const impeller::Glyph &lhs, const impeller::Glyph &rhs) const
Definition: glyph.h:57