Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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 <cstdint>
9#include <memory>
10
11#include "fml/hash_combine.h"
15
16namespace impeller {
17
18//------------------------------------------------------------------------------
19/// @brief Determines the axis along which there is subpixel positioning.
20///
21enum 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///
36class 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 ///
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
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
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
94template <>
95struct std::hash<impeller::Font::Metrics> {
96 constexpr std::size_t operator()(const impeller::Font::Metrics& m) const {
98 }
99};
100
101#endif // FLUTTER_IMPELLER_TYPOGRAPHER_FONT_H_
Describes a typeface along with any modifications to its intrinsic properties.
Definition font.h:36
bool IsEqual(const Font &other) const override
Definition font.cc:36
const std::shared_ptr< Typeface > & GetTypeface() const
The typeface whose intrinsic properties this font modifies.
Definition font.cc:27
AxisAlignment GetAxisAlignment() const
Definition font.cc:41
std::size_t GetHash() const override
Definition font.cc:31
const Metrics & GetMetrics() const
Definition font.cc:45
bool IsValid() const
Definition font.cc:23
constexpr std::size_t HashCombine()
float Scalar
Definition scalar.h:19
AxisAlignment
Determines the axis along which there is subpixel positioning.
Definition font.h:21
Describes the modifications made to the intrinsic properties of a typeface.
Definition font.h:45
constexpr bool operator==(const Metrics &o) const
Definition font.h:54
constexpr std::size_t operator()(const impeller::Font::Metrics &m) const
Definition font.h:96