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