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 #include "flutter/fml/hash_combine.h"
12 #include "flutter/fml/macros.h"
13 #include "impeller/geometry/rect.h"
14 
15 namespace impeller {
16 
17 //------------------------------------------------------------------------------
18 /// @brief The glyph index in the typeface.
19 ///
20 struct Glyph {
21  enum class Type : uint8_t {
22  kPath,
23  kBitmap,
24  };
25 
26  uint16_t index = 0;
27 
28  //------------------------------------------------------------------------------
29  /// @brief Whether the glyph is a path or a bitmap.
30  ///
32 
33  //------------------------------------------------------------------------------
34  /// @brief Visibility coverage of the glyph in text run space (relative to
35  /// the baseline, no scaling applied).
36  ///
38 
39  Glyph(uint16_t p_index, Type p_type, Rect p_bounds)
40  : index(p_index), type(p_type), bounds(p_bounds) {}
41 };
42 
43 // Many Glyph instances are instantiated, so care should be taken when
44 // increasing the size.
45 static_assert(sizeof(Glyph) == 20);
46 
47 } // namespace impeller
48 
49 template <>
50 struct std::hash<impeller::Glyph> {
51  constexpr std::size_t operator()(const impeller::Glyph& g) const {
52  static_assert(sizeof(g.index) == 2);
53  static_assert(sizeof(g.type) == 1);
54  return (static_cast<size_t>(g.type) << 16) | g.index;
55  }
56 };
57 
58 template <>
59 struct std::equal_to<impeller::Glyph> {
60  constexpr bool operator()(const impeller::Glyph& lhs,
61  const impeller::Glyph& rhs) const {
62  return lhs.index == rhs.index && lhs.type == rhs.type;
63  }
64 };
65 
66 template <>
67 struct std::less<impeller::Glyph> {
68  constexpr bool operator()(const impeller::Glyph& lhs,
69  const impeller::Glyph& rhs) const {
70  return lhs.index < rhs.index;
71  }
72 };
73 
74 #endif // FLUTTER_IMPELLER_TYPOGRAPHER_GLYPH_H_
impeller::Glyph::Type
Type
Definition: glyph.h:21
impeller::Glyph::Type::kBitmap
@ kBitmap
std::hash< impeller::Glyph >::operator()
constexpr std::size_t operator()(const impeller::Glyph &g) const
Definition: glyph.h:51
impeller::Glyph::Glyph
Glyph(uint16_t p_index, Type p_type, Rect p_bounds)
Definition: glyph.h:39
impeller::Glyph
The glyph index in the typeface.
Definition: glyph.h:20
std::equal_to< impeller::Glyph >::operator()
constexpr bool operator()(const impeller::Glyph &lhs, const impeller::Glyph &rhs) const
Definition: glyph.h:60
std::less< impeller::Glyph >::operator()
constexpr bool operator()(const impeller::Glyph &lhs, const impeller::Glyph &rhs) const
Definition: glyph.h:68
impeller::Glyph::index
uint16_t index
Definition: glyph.h:26
impeller::Glyph::type
Type type
Whether the glyph is a path or a bitmap.
Definition: glyph.h:31
rect.h
impeller::Glyph::Type::kPath
@ kPath
impeller
Definition: aiks_blur_unittests.cc:20
impeller::Glyph::bounds
Rect bounds
Visibility coverage of the glyph in text run space (relative to the baseline, no scaling applied).
Definition: glyph.h:37
impeller::TRect< Scalar >