CoriEngine
Loading...
Searching...
No Matches
Font.hpp
Go to the documentation of this file.
1#pragma once
4
5namespace Cori {
6 class AssetManager;
7 namespace Graphics {
8 namespace Internal {
9 struct FontData;
10 }
11
15 class Font : public Profiling::Trackable<Font>, public std::enable_shared_from_this<Font> {
16 public:
20 struct CharsetRange {
21 uint32_t m_Start;
22 uint32_t m_End;
23 };
24
30 static constexpr CharsetRange Latin = { 0x0020, 0x00FF };
31 static constexpr CharsetRange LatinExtendedA = { 0x0100, 0x017F };
32 static constexpr CharsetRange LatinExtendedB = { 0x0180, 0x024F };
33
34 static constexpr CharsetRange Cyrillic = { 0x0400, 0x04FF };
35 static constexpr CharsetRange CyrillicExtendedA = { 0x2DE0, 0x2DFF };
36 static constexpr CharsetRange CyrillicExtendedB = { 0xA640, 0xA69F };
37 };
38
42 class Descriptor {
43 public:
52 constexpr Descriptor(std::string name, std::filesystem::path fontPath, std::vector<CharsetRange> charsetRanges, const float minimalScale = 48.0f, const float miterLimit = 1.0f)
53 : m_Name(std::move(name)),
54 m_FontPath(std::move(fontPath)),
55 m_CharsetRanges(std::move(charsetRanges)),
56 m_MinimalScale(minimalScale),
57 m_MiterLimit(miterLimit),
58 m_RuntimeID(s_NextRuntimeID.fetch_add(1, std::memory_order_relaxed))
59 { }
60
61 using AssetType = Font;
62
63 [[nodiscard]] uint32_t GetRuntimeID() const { return m_RuntimeID; }
64
65 constexpr bool operator==(const Descriptor& other) const {
66 return m_RuntimeID == other.m_RuntimeID;
67 }
68
69 struct Hasher {
70 std::size_t operator()(const Descriptor& descriptor) const {
71 return std::hash<uint32_t>{}(descriptor.m_RuntimeID);
72 }
73 };
74
75 const std::string m_Name;
76 const std::filesystem::path m_FontPath;
77 const std::vector<CharsetRange> m_CharsetRanges;
78 const float m_MinimalScale;
79 const float m_MiterLimit;
80
81 private:
82 const uint32_t m_RuntimeID{ 0 };
83 inline static std::atomic<uint32_t> s_NextRuntimeID{ 1 };
84 };
85
94 [[nodiscard]] static std::shared_ptr<Font> Create(const std::filesystem::path& path, const std::vector<CharsetRange>& charsets, const float minimalScale = 48.0f, const float miterLimit = 1.0f);
95
96 Font();
97 ~Font();
98
99 AssetStatus GetStatus() const;
100
101 private:
102 friend AssetManager;
103 friend class Renderer2D;
104 [[nodiscard]] static std::shared_ptr<Font> Create(const Descriptor& descriptor);
105 Internal::FontData* GetData();
106 AssetStatus m_Status;
107
108 void Load(void* font, const std::vector<CharsetRange>& charsets, const std::filesystem::path& fontPath, const float minimalScale, const float miterLimit);
109 Internal::FontData* m_Data{ nullptr };
110 };
111 }
112}
Used when you want to manually control the asset lifetime, loading, preloading, unloading.
Font Descriptor meant to be used with AssetManager only.
Definition Font.hpp:42
const std::string m_Name
Definition Font.hpp:75
const std::vector< CharsetRange > m_CharsetRanges
Definition Font.hpp:77
constexpr Descriptor(std::string name, std::filesystem::path fontPath, std::vector< CharsetRange > charsetRanges, const float minimalScale=48.0f, const float miterLimit=1.0f)
Constructs a descriptor.
Definition Font.hpp:52
uint32_t GetRuntimeID() const
Definition Font.hpp:63
const std::filesystem::path m_FontPath
Definition Font.hpp:76
constexpr bool operator==(const Descriptor &other) const
Definition Font.hpp:65
friend class Renderer2D
Definition Font.hpp:103
AssetStatus GetStatus() const
Definition Font.cpp:266
static std::shared_ptr< Font > Create(const std::filesystem::path &path, const std::vector< CharsetRange > &charsets, const float minimalScale=48.0f, const float miterLimit=1.0f)
Creates a Font object.
Definition Font.cpp:9
For InstanceMetrics to work with a type it should derive from this.
Definition Trackable.hpp:29
Almost everything connected to graphics is in this namespace.
Definition Window.hpp:7
Global engine namespace.
A UTF-32 charset range.
Definition Font.hpp:20
These are predefined UTF-32 charset ranges to be used when creating a Font.
Definition Font.hpp:29
static constexpr CharsetRange CyrillicExtendedB
Definition Font.hpp:36
static constexpr CharsetRange Cyrillic
Definition Font.hpp:34
static constexpr CharsetRange Latin
Definition Font.hpp:30
static constexpr CharsetRange LatinExtendedA
Definition Font.hpp:31
static constexpr CharsetRange LatinExtendedB
Definition Font.hpp:32
static constexpr CharsetRange CyrillicExtendedA
Definition Font.hpp:35
std::size_t operator()(const Descriptor &descriptor) const
Definition Font.hpp:70