| 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
11 #include "impeller/geometry/color.h"
12 #include "impeller/geometry/path.h"
13 #include "impeller/geometry/point.h"
14 #include "impeller/typographer/font.h"
15 #include "impeller/typographer/glyph.h"
16
17 namespace impeller {
18
19 struct GlyphProperties {
20 Color color = Color::Black();
21 Scalar stroke_width = 0.0;
22 Cap stroke_cap = Cap::kButt;
23 Join stroke_join = Join::kMiter;
24 Scalar stroke_miter = 4.0;
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 {
33 Font font;
34 Scalar scale;
35 };
36
37 //------------------------------------------------------------------------------
38 /// @brief A glyph and its subpixel position.
39 ///
40 struct SubpixelGlyph {
41 Glyph glyph;
42 Point subpixel_offset;
43 GlyphProperties properties;
44
45 SubpixelGlyph(Glyph p_glyph,
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) {}
63 const ScaledFont& scaled_font;
64 const SubpixelGlyph& glyph;
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(
88 sg.glyph.index, sg.subpixel_offset.x, sg.subpixel_offset.y,
89 sg.properties.color.ToARGB(), sg.properties.stroke,
90 sg.properties.stroke_cap, sg.properties.stroke_join,
91 sg.properties.stroke_miter, sg.properties.stroke_width);
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 &&
104 lhs.properties.stroke_cap == rhs.properties.stroke_cap &&
105 lhs.properties.stroke_join == rhs.properties.stroke_join &&
106 lhs.properties.stroke_miter == rhs.properties.stroke_miter &&
107 lhs.properties.stroke_width == rhs.properties.stroke_width;
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