Flutter Engine
The Flutter Engine
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
16
17namespace 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///
32struct ScaledFont {
35};
36
37//------------------------------------------------------------------------------
38/// @brief A glyph and its subpixel position.
39///
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
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///
62 : scaled_font(sf), glyph(g) {}
65};
66
67} // namespace impeller
68
69template <>
70struct 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
76template <>
77struct 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
84template <>
85struct std::hash<impeller::SubpixelGlyph> {
86 constexpr std::size_t operator()(const impeller::SubpixelGlyph& sg) const {
87 return fml::HashCombine(
92 }
93};
94
95template <>
96struct 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_
static uint32_t hash(const SkShaderBase::GradientInfo &v)
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
constexpr std::size_t HashCombine()
Definition: hash_combine.h:25
Join
Definition: path.h:24
float Scalar
Definition: scalar.h:18
Cap
Definition: path.h:18
std::unordered_map< ScaledFont, std::unordered_set< SubpixelGlyph > > FontGlyphMap
constexpr uint32_t ToARGB() const
Convert to ARGB 32 bit color.
Definition: color.h:261
static constexpr Color Black()
Definition: color.h:268
A font along with a glyph in that font rendered at a particular scale and subpixel position.
const SubpixelGlyph & glyph
FontGlyphPair(const ScaledFont &sf, const SubpixelGlyph &g)
const ScaledFont & scaled_font
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
A font and a scale. Used as a key that represents a typeface within a glyph atlas.
A glyph and its subpixel position.
GlyphProperties properties
SubpixelGlyph(Glyph p_glyph, Point p_subpixel_offset, GlyphProperties p_properties)
constexpr bool operator()(const impeller::ScaledFont &lhs, const impeller::ScaledFont &rhs) const
constexpr bool operator()(const impeller::SubpixelGlyph &lhs, const impeller::SubpixelGlyph &rhs) const
constexpr std::size_t operator()(const impeller::ScaledFont &sf) const
constexpr std::size_t operator()(const impeller::SubpixelGlyph &sg) const