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