Kiwano Engine v1.3.x
Font.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/core/Resource.h>
23#include <kiwano/platform/NativeObject.hpp>
24
25namespace kiwano
26{
27
28class Renderer;
29
40{
41 enum Value : uint32_t
42 {
43 Thin = 100U,
44 ExtraLight = 200U,
45 Light = 300U,
46 Normal = 400U,
47 Medium = 500U,
48 Bold = 700U,
49 ExtraBold = 800U,
50 Black = 900U,
51 ExtraBlack = 950U
52 };
53};
54
59enum class FontPosture
60{
61 Normal,
62 Oblique,
63 Italic,
64};
65
70enum class FontStretch
71{
72 Unknown,
73 UltraCondensed,
74 ExtraCondensed,
75 Condensed,
76 SemiCondensed,
77 Normal,
78 SemiExpanded,
79 Expanded,
80 ExtraExpanded,
81 UltraExpanded,
82};
83
88class KGE_API FontCollection : public NativeObject
89{
90public:
94 static RefPtr<FontCollection> Preload(const Vector<String>& files);
95
99 static RefPtr<FontCollection> Preload(const Vector<Resource>& resources);
100
101 const Vector<String>& GetFamilyNames() const;
102
103protected:
104 Vector<String> family_names_;
105};
106
111class KGE_API Font
112{
113public:
114 float size;
115 uint32_t weight;
116 FontPosture posture;
117 FontStretch stretch;
118 String family_name;
119 RefPtr<FontCollection> collection;
120
127 Font(StringView family_name, float size, uint32_t weight = FontWeight::Normal,
129
136 Font(RefPtr<FontCollection> collection, float size, uint32_t weight = FontWeight::Normal,
138};
139
144class KGE_API FontCache final : public Singleton<FontCache>
145{
147
148public:
151 void AddFontCollection(RefPtr<FontCollection> collection);
152
155 void AddFontCollection(StringView font_family, RefPtr<FontCollection> collection);
156
159 RefPtr<FontCollection> GetFontCollection(StringView font_family) const;
160
163 void RemoveFontCollection(StringView font_family);
164
167 void Clear();
168
169 ~FontCache();
170
171private:
172 FontCache();
173
174 String TransformFamily(String family) const;
175
176private:
177 UnorderedMap<String, RefPtr<FontCollection>> collection_cache_;
178};
179
182inline const Vector<String>& FontCollection::GetFamilyNames() const
183{
184 return family_names_;
185}
186
187} // namespace kiwano
字体缓存
Definition: Font.h:145
字体集合
Definition: Font.h:89
字体
Definition: Font.h:112
含有本地指针的对象
Definition: NativeObject.hpp:32
引用计数智能指针
Definition: RefBasePtr.hpp:35
Definition: Singleton.h:28
FontPosture
字体形态
Definition: Font.h:60
FontStretch
字体拉伸
Definition: Font.h:71
字体粗细值
Definition: Font.h:40
Value
Definition: Font.h:42
@ Bold
加粗
Definition: Font.h:48
@ Normal
正常
Definition: Font.h:46