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