Flutter Impeller
font_glyph_pair.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_FONT_GLYPH_PAIR_H_
6 #define FLUTTER_IMPELLER_TYPOGRAPHER_FONT_GLYPH_PAIR_H_
7 
8 #include <optional>
9 #include <unordered_map>
10 #include <unordered_set>
11 #include <vector>
12 
13 #include "flutter/fml/macros.h"
14 #include "impeller/geometry/size.h"
17 
18 namespace impeller {
19 
20 //------------------------------------------------------------------------------
21 /// @brief A font and a scale. Used as a key that represents a typeface
22 /// within a glyph atlas.
23 ///
24 struct ScaledFont {
27 };
28 
29 using FontGlyphMap = std::unordered_map<ScaledFont, std::unordered_set<Glyph>>;
30 
31 //------------------------------------------------------------------------------
32 /// @brief A font along with a glyph in that font rendered at a particular
33 /// scale.
34 ///
35 struct FontGlyphPair {
36  FontGlyphPair(const ScaledFont& sf, const Glyph& g)
37  : scaled_font(sf), glyph(g) {}
39  const Glyph& glyph;
40 };
41 
42 } // namespace impeller
43 
44 template <>
45 struct std::hash<impeller::ScaledFont> {
46  constexpr std::size_t operator()(const impeller::ScaledFont& sf) const {
47  return fml::HashCombine(sf.font.GetHash(), sf.scale);
48  }
49 };
50 
51 template <>
52 struct std::equal_to<impeller::ScaledFont> {
53  constexpr bool operator()(const impeller::ScaledFont& lhs,
54  const impeller::ScaledFont& rhs) const {
55  return lhs.font.IsEqual(rhs.font) && lhs.scale == rhs.scale;
56  }
57 };
58 
59 #endif // FLUTTER_IMPELLER_TYPOGRAPHER_FONT_GLYPH_PAIR_H_
impeller::Font::GetHash
std::size_t GetHash() const override
Definition: font.cc:27
impeller::Scalar
float Scalar
Definition: scalar.h:18
std::hash< impeller::ScaledFont >::operator()
constexpr std::size_t operator()(const impeller::ScaledFont &sf) const
Definition: font_glyph_pair.h:46
impeller::Font
Describes a typeface along with any modifications to its intrinsic properties.
Definition: font.h:22
impeller::FontGlyphPair::FontGlyphPair
FontGlyphPair(const ScaledFont &sf, const Glyph &g)
Definition: font_glyph_pair.h:36
impeller::ScaledFont::font
Font font
Definition: font_glyph_pair.h:25
impeller::FontGlyphMap
std::unordered_map< ScaledFont, std::unordered_set< Glyph > > FontGlyphMap
Definition: font_glyph_pair.h:29
impeller::Glyph
The glyph index in the typeface.
Definition: glyph.h:20
impeller::FontGlyphPair::glyph
const Glyph & glyph
Definition: font_glyph_pair.h:39
glyph.h
impeller::FontGlyphPair::scaled_font
const ScaledFont & scaled_font
Definition: font_glyph_pair.h:38
font.h
impeller::FontGlyphPair
A font along with a glyph in that font rendered at a particular scale.
Definition: font_glyph_pair.h:35
impeller::ScaledFont::scale
Scalar scale
Definition: font_glyph_pair.h:26
impeller::Font::IsEqual
bool IsEqual(const Font &other) const override
Definition: font.cc:32
std::equal_to< impeller::ScaledFont >::operator()
constexpr bool operator()(const impeller::ScaledFont &lhs, const impeller::ScaledFont &rhs) const
Definition: font_glyph_pair.h:53
impeller
Definition: aiks_blur_unittests.cc:20
impeller::ScaledFont
A font and a scale. Used as a key that represents a typeface within a glyph atlas.
Definition: font_glyph_pair.h:24
size.h