| Flutter Impeller |

font.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_H_
6 #define FLUTTER_IMPELLER_TYPOGRAPHER_FONT_H_
7
8 #include <cstdint>
9 #include <memory>
10
11 #include "fml/hash_combine.h"
12 #include "impeller/base/comparable.h"
13 #include "impeller/geometry/scalar.h"
14 #include "impeller/typographer/typeface.h"
15
16 namespace impeller {
17
18 //------------------------------------------------------------------------------
19 /// @brief Determines the axis along which there is subpixel positioning.
20 ///
21 enum class AxisAlignment : uint8_t {
22 // No subpixel positioning.
23 kNone,
24 // Subpixel positioning in the X axis only.
25 kX,
26 // Subpixel positioning in the Y axis only.
27 kY,
28 // No specific axis, subpixel positioning in each direction.
29 kAll,
30 };
31
32 //------------------------------------------------------------------------------
33 /// @brief Describes a typeface along with any modifications to its
34 /// intrinsic properties.
35 ///
36 class Font : public Comparable<Font> {
37 public:
38 //----------------------------------------------------------------------------
39 /// @brief Describes the modifications made to the intrinsic properties
40 /// of a typeface.
41 ///
42 /// The coordinate system of a font has its origin at (0, 0) on
43 /// the baseline with an upper-left-origin coordinate system.
44 ///
45 struct Metrics {
46 //--------------------------------------------------------------------------
47 /// The point size of the font.
48 ///
49 Scalar point_size = 12.0f;
50 bool embolden = false;
51 Scalar skewX = 0.0f;
52 Scalar scaleX = 1.0f;
53
54 constexpr bool operator==(const Metrics& o) const {
55 return point_size == o.point_size && embolden == o.embolden &&
56 skewX == o.skewX && scaleX == o.scaleX;
57 }
58 };
59
60 Font(std::shared_ptr<Typeface> typeface,
61 Metrics metrics,
62 AxisAlignment axis_alignment);
63
64 ~Font();
65
66 bool IsValid() const;
67
68 //----------------------------------------------------------------------------
69 /// @brief The typeface whose intrinsic properties this font modifies.
70 ///
71 /// @return The typeface.
72 ///
73 const std::shared_ptr<Typeface>& GetTypeface() const;
74
75 const Metrics& GetMetrics() const;
76
77 // |Comparable<Font>|
78 std::size_t GetHash() const override;
79
80 // |Comparable<Font>|
81 bool IsEqual(const Font& other) const override;
82
83 AxisAlignment GetAxisAlignment() const;
84
85 private:
86 std::shared_ptr<Typeface> typeface_;
87 Metrics metrics_ = {};
88 AxisAlignment axis_alignment_;
89 bool is_valid_ = false;
90 };
91
92 } // namespace impeller
93
94 template <>
95 struct std::hash<impeller::Font::Metrics> {
96 constexpr std::size_t operator()(const impeller::Font::Metrics& m) const {
97 return fml::HashCombine(m.point_size, m.skewX, m.scaleX);
98 }
99 };
100
101 #endif // FLUTTER_IMPELLER_TYPOGRAPHER_FONT_H_
impeller::Comparable
Definition: comparable.h:29
impeller::Font
Describes a typeface along with any modifications to its intrinsic properties.
Definition: font.h:36
impeller::Font::IsEqual
bool IsEqual(const Font &other) const override
Definition: font.cc:36
impeller::Font::GetTypeface
const std::shared_ptr< Typeface > & GetTypeface() const
The typeface whose intrinsic properties this font modifies.
Definition: font.cc:27
impeller::Font::GetAxisAlignment
AxisAlignment GetAxisAlignment() const
Definition: font.cc:41
impeller::Font::GetHash
std::size_t GetHash() const override
Definition: font.cc:31
impeller::Font::~Font
~Font()
impeller::Font::GetMetrics
const Metrics & GetMetrics() const
Definition: font.cc:45
impeller::Font::Font
Font(std::shared_ptr< Typeface > typeface, Metrics metrics, AxisAlignment axis_alignment)
Definition: font.cc:9
impeller::Font::IsValid
bool IsValid() const
Definition: font.cc:23
comparable.h
impeller
Definition: allocation.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:19
impeller::AxisAlignment
AxisAlignment
Determines the axis along which there is subpixel positioning.
Definition: font.h:21
impeller::AxisAlignment::kX
@ kX
impeller::AxisAlignment::kAll
@ kAll
impeller::AxisAlignment::kNone
@ kNone
impeller::AxisAlignment::kY
@ kY
scalar.h
impeller::Font::Metrics
Describes the modifications made to the intrinsic properties of a typeface.
Definition: font.h:45
impeller::Font::Metrics::embolden
bool embolden
Definition: font.h:50
impeller::Font::Metrics::skewX
Scalar skewX
Definition: font.h:51
impeller::Font::Metrics::scaleX
Scalar scaleX
Definition: font.h:52
impeller::Font::Metrics::operator==
constexpr bool operator==(const Metrics &o) const
Definition: font.h:54
impeller::Font::Metrics::point_size
Scalar point_size
Definition: font.h:49
std::hash< impeller::Font::Metrics >::operator()
constexpr std::size_t operator()(const impeller::Font::Metrics &m) const
Definition: font.h:96
typeface.h