88#include < unordered_map>
99#include < unordered_set>
1010
11+ #include " fml/hash_combine.h"
1112#include " impeller/geometry/color.h"
1213#include " impeller/geometry/path.h"
1314#include " impeller/geometry/point.h"
@@ -32,6 +33,19 @@ struct GlyphProperties {
3233struct ScaledFont {
3334 Font font;
3435 Scalar scale;
36+
37+ struct Hash {
38+ constexpr std::size_t operator ()(const impeller::ScaledFont& sf) const {
39+ return fml::HashCombine (sf.font .GetHash (), sf.scale );
40+ }
41+ };
42+
43+ struct Equal {
44+ constexpr bool operator ()(const impeller::ScaledFont& lhs,
45+ const impeller::ScaledFont& rhs) const {
46+ return lhs.font .IsEqual (rhs.font ) && lhs.scale == rhs.scale ;
47+ }
48+ };
3549};
3650
3751// ------------------------------------------------------------------------------
@@ -40,18 +54,58 @@ struct ScaledFont {
4054struct SubpixelGlyph {
4155 Glyph glyph;
4256 Point subpixel_offset;
43- GlyphProperties properties;
57+ std::optional< GlyphProperties> properties;
4458
4559 SubpixelGlyph (Glyph p_glyph,
4660 Point p_subpixel_offset,
47- GlyphProperties p_properties)
61+ std::optional< GlyphProperties> p_properties)
4862 : glyph(p_glyph),
4963 subpixel_offset (p_subpixel_offset),
5064 properties(p_properties) {}
65+
66+ struct Hash {
67+ constexpr std::size_t operator ()(const impeller::SubpixelGlyph& sg) const {
68+ if (!sg.properties .has_value ()) {
69+ return fml::HashCombine (sg.glyph .index , sg.subpixel_offset .x ,
70+ sg.subpixel_offset .y );
71+ }
72+ return fml::HashCombine (
73+ sg.glyph .index , sg.subpixel_offset .x , sg.subpixel_offset .y ,
74+ sg.properties ->color .ToARGB (), sg.properties ->stroke ,
75+ sg.properties ->stroke_cap , sg.properties ->stroke_join ,
76+ sg.properties ->stroke_miter , sg.properties ->stroke_width );
77+ }
78+ };
79+
80+ struct Equal {
81+ constexpr bool operator ()(const impeller::SubpixelGlyph& lhs,
82+ const impeller::SubpixelGlyph& rhs) const {
83+ if (!lhs.properties .has_value () && !rhs.properties .has_value ()) {
84+ return lhs.glyph .index == rhs.glyph .index &&
85+ lhs.glyph .type == rhs.glyph .type &&
86+ lhs.subpixel_offset == rhs.subpixel_offset ;
87+ }
88+ return lhs.glyph .index == rhs.glyph .index &&
89+ lhs.glyph .type == rhs.glyph .type &&
90+ lhs.subpixel_offset == rhs.subpixel_offset &&
91+ lhs.properties .has_value () && rhs.properties .has_value () &&
92+ lhs.properties ->color .ToARGB () == rhs.properties ->color .ToARGB () &&
93+ lhs.properties ->stroke == rhs.properties ->stroke &&
94+ lhs.properties ->stroke_cap == rhs.properties ->stroke_cap &&
95+ lhs.properties ->stroke_join == rhs.properties ->stroke_join &&
96+ lhs.properties ->stroke_miter == rhs.properties ->stroke_miter &&
97+ lhs.properties ->stroke_width == rhs.properties ->stroke_width ;
98+ }
99+ };
51100};
52101
53102using FontGlyphMap =
54- std::unordered_map<ScaledFont, std::unordered_set<SubpixelGlyph>>;
103+ std::unordered_map<ScaledFont,
104+ std::unordered_set<SubpixelGlyph,
105+ SubpixelGlyph::Hash,
106+ SubpixelGlyph::Equal>,
107+ ScaledFont::Hash,
108+ ScaledFont::Equal>;
55109
56110// ------------------------------------------------------------------------------
57111// / @brief A font along with a glyph in that font rendered at a particular
@@ -66,46 +120,4 @@ struct FontGlyphPair {
66120
67121} // namespace impeller
68122
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-
111123#endif // FLUTTER_IMPELLER_TYPOGRAPHER_FONT_GLYPH_PAIR_H_
0 commit comments