| 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 #include <optional>
10
11 #include "flutter/fml/macros.h"
12 #include "impeller/base/comparable.h"
13 #include "impeller/typographer/glyph.h"
14 #include "impeller/typographer/typeface.h"
15
16 namespace impeller {
17
18 //------------------------------------------------------------------------------
19 /// @brief Describes a typeface along with any modifications to its
20 /// intrinsic properties.
21 ///
22 class Font : public Comparable<Font> {
23 public:
24 //----------------------------------------------------------------------------
25 /// @brief Describes the modifications made to the intrinsic properties
26 /// of a typeface.
27 ///
28 /// The coordinate system of a font has its origin at (0, 0) on
29 /// the baseline with an upper-left-origin coordinate system.
30 ///
31 struct Metrics {
32 //--------------------------------------------------------------------------
33 /// The point size of the font.
34 ///
35 Scalar point_size = 12.0f;
36 bool embolden = false;
37 Scalar skewX = 0.0f;
38 Scalar scaleX = 1.0f;
39
40 constexpr bool operator==(const Metrics& o) const {
41 return point_size == o.point_size && embolden == o.embolden &&
42 skewX == o.skewX && scaleX == o.scaleX;
43 }
44 };
45
46 Font(std::shared_ptr<Typeface> typeface, Metrics metrics);
47
48 ~Font();
49
50 bool IsValid() const;
51
52 //----------------------------------------------------------------------------
53 /// @brief The typeface whose intrinsic properties this font modifies.
54 ///
55 /// @return The typeface.
56 ///
57 const std::shared_ptr<Typeface>& GetTypeface() const;
58
59 const Metrics& GetMetrics() const;
60
61 // |Comparable<Font>|
62 std::size_t GetHash() const override;
63
64 // |Comparable<Font>|
65 bool IsEqual(const Font& other) const override;
66
67 private:
68 std::shared_ptr<Typeface> typeface_;
69 Metrics metrics_ = {};
70 bool is_valid_ = false;
71 };
72
73 } // namespace impeller
74
75 template <>
76 struct std::hash<impeller::Font::Metrics> {
77 constexpr std::size_t operator()(const impeller::Font::Metrics& m) const {
78 return fml::HashCombine(m.point_size, m.skewX, m.scaleX);
79 }
80 };
81
82 #endif // FLUTTER_IMPELLER_TYPOGRAPHER_FONT_H_
impeller::Font::GetHash
std::size_t GetHash() const override
Definition: font.cc:27
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::Font
Describes a typeface along with any modifications to its intrinsic properties.
Definition: font.h:22
impeller::Font::~Font
~Font()
impeller::Font::Metrics::embolden
bool embolden
Definition: font.h:36
impeller::Font::Font
Font(std::shared_ptr< Typeface > typeface, Metrics metrics)
Definition: font.cc:9
impeller::Font::IsValid
bool IsValid() const
Definition: font.cc:19
impeller::Font::GetTypeface
const std::shared_ptr< Typeface > & GetTypeface() const
The typeface whose intrinsic properties this font modifies.
Definition: font.cc:23
impeller::Font::Metrics::skewX
Scalar skewX
Definition: font.h:37
glyph.h
impeller::Font::Metrics::operator==
constexpr bool operator==(const Metrics &o) const
Definition: font.h:40
impeller::Font::Metrics::point_size
Scalar point_size
Definition: font.h:35
impeller::Font::GetMetrics
const Metrics & GetMetrics() const
Definition: font.cc:37
typeface.h
impeller::Comparable
Definition: comparable.h:29
comparable.h
impeller::Font::IsEqual
bool IsEqual(const Font &other) const override
Definition: font.cc:32
impeller::Font::Metrics::scaleX
Scalar scaleX
Definition: font.h:38
std::hash< impeller::Font::Metrics >::operator()
constexpr std::size_t operator()(const impeller::Font::Metrics &m) const
Definition: font.h:77
impeller
Definition: aiks_context.cc:10
impeller::Font::Metrics
Describes the modifications made to the intrinsic properties of a typeface.
Definition: font.h:31