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 <unordered_map>
9 #include <unordered_set>
10 
12 #include "impeller/geometry/path.h"
16 
17 namespace impeller {
18 
25  bool stroke = false;
26 };
27 
28 //------------------------------------------------------------------------------
29 /// @brief A font and a scale. Used as a key that represents a typeface
30 /// within a glyph atlas.
31 ///
32 struct ScaledFont {
35 };
36 
37 //------------------------------------------------------------------------------
38 /// @brief A glyph and its subpixel position.
39 ///
40 struct SubpixelGlyph {
44 
46  Point p_subpixel_offset,
47  GlyphProperties p_properties)
48  : glyph(p_glyph),
49  subpixel_offset(p_subpixel_offset),
50  properties(p_properties) {}
51 };
52 
53 using FontGlyphMap =
54  std::unordered_map<ScaledFont, std::unordered_set<SubpixelGlyph>>;
55 
56 //------------------------------------------------------------------------------
57 /// @brief A font along with a glyph in that font rendered at a particular
58 /// scale and subpixel position.
59 ///
60 struct FontGlyphPair {
61  FontGlyphPair(const ScaledFont& sf, const SubpixelGlyph& g)
62  : scaled_font(sf), glyph(g) {}
65 };
66 
67 } // namespace impeller
68 
69 template <>
70 struct std::hash<impeller::ScaledFont> {
71  constexpr std::size_t operator()(const impeller::ScaledFont& sf) const {
72  return fml::HashCombine(sf.font.GetHash(), sf.scale);
73  }
74 };
75 
76 template <>
77 struct std::equal_to<impeller::ScaledFont> {
78  constexpr bool operator()(const impeller::ScaledFont& lhs,
79  const impeller::ScaledFont& rhs) const {
80  return lhs.font.IsEqual(rhs.font) && lhs.scale == rhs.scale;
81  }
82 };
83 
84 template <>
85 struct std::hash<impeller::SubpixelGlyph> {
86  constexpr std::size_t operator()(const impeller::SubpixelGlyph& sg) const {
87  return fml::HashCombine(
92  }
93 };
94 
95 template <>
96 struct std::equal_to<impeller::SubpixelGlyph> {
97  constexpr bool operator()(const impeller::SubpixelGlyph& lhs,
98  const impeller::SubpixelGlyph& rhs) const {
99  return lhs.glyph.index == rhs.glyph.index &&
100  lhs.glyph.type == rhs.glyph.type &&
101  lhs.subpixel_offset == rhs.subpixel_offset &&
102  lhs.properties.color.ToARGB() == rhs.properties.color.ToARGB() &&
103  lhs.properties.stroke == rhs.properties.stroke &&
108  }
109 };
110 
111 #endif // FLUTTER_IMPELLER_TYPOGRAPHER_FONT_GLYPH_PAIR_H_
path.h
impeller::Font::GetHash
std::size_t GetHash() const override
Definition: font.cc:31
point.h
impeller::TPoint::y
Type y
Definition: point.h:31
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:71
impeller::Font
Describes a typeface along with any modifications to its intrinsic properties.
Definition: font.h:35
impeller::GlyphProperties
Definition: font_glyph_pair.h:19
impeller::Color
Definition: color.h:124
impeller::SubpixelGlyph::subpixel_offset
Point subpixel_offset
Definition: font_glyph_pair.h:42
impeller::ScaledFont::font
Font font
Definition: font_glyph_pair.h:33
std::equal_to< impeller::SubpixelGlyph >::operator()
constexpr bool operator()(const impeller::SubpixelGlyph &lhs, const impeller::SubpixelGlyph &rhs) const
Definition: font_glyph_pair.h:97
impeller::SubpixelGlyph
A glyph and its subpixel position.
Definition: font_glyph_pair.h:40
impeller::Color::ToARGB
constexpr uint32_t ToARGB() const
Convert to ARGB 32 bit color.
Definition: color.h:261
impeller::GlyphProperties::stroke_miter
Scalar stroke_miter
Definition: font_glyph_pair.h:24
impeller::SubpixelGlyph::SubpixelGlyph
SubpixelGlyph(Glyph p_glyph, Point p_subpixel_offset, GlyphProperties p_properties)
Definition: font_glyph_pair.h:45
impeller::Cap::kButt
@ kButt
impeller::GlyphProperties::color
Color color
Definition: font_glyph_pair.h:20
impeller::Join::kMiter
@ kMiter
impeller::Glyph
The glyph index in the typeface.
Definition: glyph.h:16
impeller::FontGlyphPair::glyph
const SubpixelGlyph & glyph
Definition: font_glyph_pair.h:64
glyph.h
impeller::FontGlyphPair::scaled_font
const ScaledFont & scaled_font
Definition: font_glyph_pair.h:63
font.h
impeller::FontGlyphMap
std::unordered_map< ScaledFont, std::unordered_set< SubpixelGlyph > > FontGlyphMap
Definition: font_glyph_pair.h:54
impeller::SubpixelGlyph::glyph
Glyph glyph
Definition: font_glyph_pair.h:41
impeller::SubpixelGlyph::properties
GlyphProperties properties
Definition: font_glyph_pair.h:43
impeller::GlyphProperties::stroke_join
Join stroke_join
Definition: font_glyph_pair.h:23
impeller::Glyph::index
uint16_t index
Definition: glyph.h:22
impeller::GlyphProperties::stroke
bool stroke
Definition: font_glyph_pair.h:25
impeller::FontGlyphPair
A font along with a glyph in that font rendered at a particular scale and subpixel position.
Definition: font_glyph_pair.h:60
impeller::TPoint::x
Type x
Definition: point.h:30
impeller::GlyphProperties::stroke_width
Scalar stroke_width
Definition: font_glyph_pair.h:21
impeller::Glyph::type
Type type
Whether the glyph is a path or a bitmap.
Definition: glyph.h:27
impeller::ScaledFont::scale
Scalar scale
Definition: font_glyph_pair.h:34
impeller::FontGlyphPair::FontGlyphPair
FontGlyphPair(const ScaledFont &sf, const SubpixelGlyph &g)
Definition: font_glyph_pair.h:61
impeller::GlyphProperties::stroke_cap
Cap stroke_cap
Definition: font_glyph_pair.h:22
impeller::Join
Join
Definition: path.h:24
impeller::TPoint< Scalar >
impeller::Font::IsEqual
bool IsEqual(const Font &other) const override
Definition: font.cc:36
impeller::Color::Black
static constexpr Color Black()
Definition: color.h:268
std::equal_to< impeller::ScaledFont >::operator()
constexpr bool operator()(const impeller::ScaledFont &lhs, const impeller::ScaledFont &rhs) const
Definition: font_glyph_pair.h:78
color.h
std::hash< impeller::SubpixelGlyph >::operator()
constexpr std::size_t operator()(const impeller::SubpixelGlyph &sg) const
Definition: font_glyph_pair.h:86
impeller
Definition: aiks_blend_unittests.cc:18
impeller::ScaledFont
A font and a scale. Used as a key that represents a typeface within a glyph atlas.
Definition: font_glyph_pair.h:32
impeller::Cap
Cap
Definition: path.h:18