Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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"
15
16namespace impeller {
17
18//------------------------------------------------------------------------------
19/// @brief Describes a typeface along with any modifications to its
20/// intrinsic properties.
21///
22class 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 ///
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
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
75template <>
76struct 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_
Describes a typeface along with any modifications to its intrinsic properties.
Definition font.h:22
bool IsEqual(const Font &other) const override
Definition font.cc:32
const std::shared_ptr< Typeface > & GetTypeface() const
The typeface whose intrinsic properties this font modifies.
Definition font.cc:23
std::size_t GetHash() const override
Definition font.cc:27
const Metrics & GetMetrics() const
Definition font.cc:37
bool IsValid() const
Definition font.cc:19
constexpr std::size_t HashCombine()
float Scalar
Definition scalar.h:18
Describes the modifications made to the intrinsic properties of a typeface.
Definition font.h:31
constexpr bool operator==(const Metrics &o) const
Definition font.h:40
constexpr std::size_t operator()(const impeller::Font::Metrics &m) const
Definition font.h:77