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 
13 
14 namespace impeller {
15 
22  bool stroke = false;
23 
24  struct Equal {
25  constexpr bool operator()(const impeller::GlyphProperties& lhs,
26  const impeller::GlyphProperties& rhs) const {
27  return lhs.color.ToARGB() == rhs.color.ToARGB() &&
28  lhs.stroke == rhs.stroke && lhs.stroke_cap == rhs.stroke_cap &&
29  lhs.stroke_join == rhs.stroke_join &&
30  lhs.stroke_miter == rhs.stroke_miter &&
31  lhs.stroke_width == rhs.stroke_width;
32  }
33  };
34 };
35 
36 //------------------------------------------------------------------------------
37 /// @brief A font and a scale. Used as a key that represents a typeface
38 /// within a glyph atlas.
39 ///
40 struct ScaledFont {
43 
44  template <typename H>
45  friend H AbslHashValue(H h, const ScaledFont& sf) {
46  return H::combine(std::move(h), sf.font.GetHash(), sf.scale);
47  }
48 
49  struct Equal {
50  constexpr bool operator()(const impeller::ScaledFont& lhs,
51  const impeller::ScaledFont& rhs) const {
52  return lhs.font.IsEqual(rhs.font) && lhs.scale == rhs.scale;
53  }
54  };
55 };
56 
57 //------------------------------------------------------------------------------
58 /// @brief A glyph and its subpixel position.
59 ///
60 struct SubpixelGlyph {
63  std::optional<GlyphProperties> properties;
64 
66  Point p_subpixel_offset,
67  std::optional<GlyphProperties> p_properties)
68  : glyph(p_glyph),
69  subpixel_offset(p_subpixel_offset),
70  properties(p_properties) {}
71 
72  template <typename H>
73  friend H AbslHashValue(H h, const SubpixelGlyph& sg) {
74  if (!sg.properties.has_value()) {
75  return H::combine(std::move(h), sg.glyph.index, sg.subpixel_offset.x,
76  sg.subpixel_offset.y);
77  }
78  return H::combine(std::move(h), sg.glyph.index, sg.subpixel_offset.x,
79  sg.subpixel_offset.y, sg.properties->color.ToARGB(),
80  sg.properties->stroke, sg.properties->stroke_cap,
81  sg.properties->stroke_join, sg.properties->stroke_miter,
82  sg.properties->stroke_width);
83  }
84 
85  struct Equal {
86  constexpr bool operator()(const impeller::SubpixelGlyph& lhs,
87  const impeller::SubpixelGlyph& rhs) const {
88  // Check simple non-optionals first.
89  if (lhs.glyph.index != rhs.glyph.index ||
90  lhs.glyph.type != rhs.glyph.type ||
91  lhs.subpixel_offset != rhs.subpixel_offset ||
92  // Mixmatch properties.
93  lhs.properties.has_value() != rhs.properties.has_value()) {
94  return false;
95  }
96  if (lhs.properties.has_value()) {
97  // Both have properties.
98  return GlyphProperties::Equal{}(lhs.properties.value(),
99  rhs.properties.value());
100  }
101  return true;
102  }
103  };
104 };
105 
106 //------------------------------------------------------------------------------
107 /// @brief A font along with a glyph in that font rendered at a particular
108 /// scale and subpixel position.
109 ///
112  : scaled_font(sf), glyph(g) {}
115 };
116 
117 } // namespace impeller
118 
119 #endif // FLUTTER_IMPELLER_TYPOGRAPHER_FONT_GLYPH_PAIR_H_
Describes a typeface along with any modifications to its intrinsic properties.
Definition: font.h:35
bool IsEqual(const Font &other) const override
Definition: font.cc:36
std::size_t GetHash() const override
Definition: font.cc:31
Join
Definition: path.h:25
float Scalar
Definition: scalar.h:18
Cap
Definition: path.h:19
constexpr uint32_t ToARGB() const
Convert to ARGB 32 bit color.
Definition: color.h:258
static constexpr Color Black()
Definition: color.h:265
A font along with a glyph in that font rendered at a particular scale and subpixel position.
FontGlyphPair(const ScaledFont &sf, const SubpixelGlyph &g)
The glyph index in the typeface.
Definition: glyph.h:16
uint16_t index
Definition: glyph.h:22
Type type
Whether the glyph is a path or a bitmap.
Definition: glyph.h:27
constexpr bool operator()(const impeller::GlyphProperties &lhs, const impeller::GlyphProperties &rhs) const
constexpr bool operator()(const impeller::ScaledFont &lhs, const impeller::ScaledFont &rhs) const
A font and a scale. Used as a key that represents a typeface within a glyph atlas.
friend H AbslHashValue(H h, const ScaledFont &sf)
constexpr bool operator()(const impeller::SubpixelGlyph &lhs, const impeller::SubpixelGlyph &rhs) const
A glyph and its subpixel position.
SubpixelGlyph(Glyph p_glyph, Point p_subpixel_offset, std::optional< GlyphProperties > p_properties)
std::optional< GlyphProperties > properties
friend H AbslHashValue(H h, const SubpixelGlyph &sg)