Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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"
14
15namespace impeller {
16
17//------------------------------------------------------------------------------
18/// @brief The glyph index in the typeface.
19///
20struct 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.
45static_assert(sizeof(Glyph) == 20);
46
47} // namespace impeller
48
49template <>
50struct 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
58template <>
59struct 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
66template <>
67struct 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_
The glyph index in the typeface.
Definition glyph.h:20
uint16_t index
Definition glyph.h:26
Type type
Whether the glyph is a path or a bitmap.
Definition glyph.h:31
Glyph(uint16_t p_index, Type p_type, Rect p_bounds)
Definition glyph.h:39
Rect bounds
Visibility coverage of the glyph in text run space (relative to the baseline, no scaling applied).
Definition glyph.h:37
constexpr bool operator()(const impeller::Glyph &lhs, const impeller::Glyph &rhs) const
Definition glyph.h:60
constexpr std::size_t operator()(const impeller::Glyph &g) const
Definition glyph.h:51
constexpr bool operator()(const impeller::Glyph &lhs, const impeller::Glyph &rhs) const
Definition glyph.h:68