MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_font_resource.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10#ifndef INCGUARD_MGL_FONT_RESOURCE_H_1622008768
11#define INCGUARD_MGL_FONT_RESOURCE_H_1622008768
12
19
20namespace MGL::Render
21{
24{
25public:
26 /* ------------------------------------------------------------------------- */
30 /* ------------------------------------------------------------------------- */
31 constexpr FontResource(FontOrigin originType) noexcept
32 : _indexConverter(*this)
33 , _originType(originType)
34 {
35 }
36
37 virtual ~FontResource() noexcept = default;
38
39 /* ------------------------------------------------------------------------- */
49 /* ------------------------------------------------------------------------- */
50 virtual bool Print(FontWorkdata &workdata,
51 const FontOption &option,
52 const char *text,
53 const Text::FormatArgs &formatArgs) noexcept
54 {
55 (void)workdata;
56 (void)option;
57 (void)text;
58 (void)formatArgs;
59 return false;
60 }
61
62 /* ------------------------------------------------------------------------- */
72 /* ------------------------------------------------------------------------- */
73 virtual bool Print(FontWorkdata &workdata,
74 const FontOption &option,
75 const Text::IndexedCharacter *indexedString,
76 const Text::FormatArgs &formatArgs) noexcept
77 {
78 (void)workdata;
79 (void)option;
80 (void)indexedString;
81 (void)formatArgs;
82 return false;
83 }
84
85 /* ------------------------------------------------------------------------- */
92 /* ------------------------------------------------------------------------- */
93 [[nodiscard]] virtual Text::IndexedCharacter ToIndexedCharacter(char32_t character, FontFaceType faceType) const noexcept
94 {
95 (void)character;
96 (void)faceType;
97 return Text::kIndexedCharacterInvalid;
98 }
99
100 /* ------------------------------------------------------------------------- */
107 /* ------------------------------------------------------------------------- */
108 [[nodiscard]] virtual char32_t ToUTF32(Text::IndexedCharacter indexedCharacter, FontFaceType faceType) const noexcept
109 {
110 (void)indexedCharacter;
111 (void)faceType;
112 return 0;
113 }
114
115 /* ------------------------------------------------------------------------- */
123 /* ------------------------------------------------------------------------- */
124 [[nodiscard]] virtual const FontGlyph *GetGlyph(char32_t character, FontFaceType faceType, const FontOption &option) const noexcept
125 {
126 (void)character;
127 (void)faceType;
128 (void)option;
129 return nullptr;
130 }
131
132 /* ------------------------------------------------------------------------- */
140 /* ------------------------------------------------------------------------- */
141 [[nodiscard]] virtual const FontGlyph *GetGlyph(Text::IndexedCharacter character, FontFaceType faceType, const FontOption &option) const noexcept
142 {
143 (void)character;
144 (void)faceType;
145 (void)option;
146 return nullptr;
147 }
148
149 /* ------------------------------------------------------------------------- */
156 /* ------------------------------------------------------------------------- */
157 [[nodiscard]] virtual bool HasFontFace(FontFaceType faceType) const noexcept = 0;
158
159 /* ------------------------------------------------------------------------- */
165 /* ------------------------------------------------------------------------- */
166 [[nodiscard]] virtual bool IsValid() const noexcept = 0;
167
168 /* ------------------------------------------------------------------------- */
173 /* ------------------------------------------------------------------------- */
174 [[nodiscard]] constexpr const Text::IndexConverter &GetIndexConverter() const noexcept
175 {
176 return _indexConverter;
177 }
178
179 /* ------------------------------------------------------------------------- */
186 /* ------------------------------------------------------------------------- */
187 [[nodiscard]] constexpr bool IsEnabled(FontFeature feature) const noexcept
188 {
189 return (_featureFlags & static_cast<uint32_t>(feature)) != 0;
190 }
191
192 /* ------------------------------------------------------------------------- */
197 /* ------------------------------------------------------------------------- */
198 [[nodiscard]] constexpr FontOrigin GetOriginType() const noexcept
199 {
200 return _originType;
201 }
202
203protected:
204 /* ------------------------------------------------------------------------- */
210 /* ------------------------------------------------------------------------- */
211 constexpr void SetEnabled(FontFeature feature, bool isEnabled) noexcept
212 {
213 if (isEnabled)
214 {
215 _featureFlags |= static_cast<uint32_t>(feature);
216 }
217 else
218 {
219 _featureFlags &= ~(static_cast<uint32_t>(feature));
220 }
221 }
222
223private:
225 class IndexConverter : public Text::IndexConverter
226 {
227 public:
228 /* ------------------------------------------------------------------------- */
232 /* ------------------------------------------------------------------------- */
233 constexpr IndexConverter(const FontResource &fontResource) noexcept
234 : _resource(fontResource)
235 {
236 }
237
238 /* ------------------------------------------------------------------------- */
245 /* ------------------------------------------------------------------------- */
246 [[nodiscard]] Text::IndexedCharacter ToIndexedCharacter(char32_t character, FontFaceType faceType) const noexcept override
247 {
248 return _resource.ToIndexedCharacter(character, faceType);
249 }
250
251 /* ------------------------------------------------------------------------- */
258 /* ------------------------------------------------------------------------- */
259 [[nodiscard]] char32_t ToUTF32(Text::IndexedCharacter indexedCharacter, FontFaceType faceType) const noexcept override
260 {
261 return _resource.ToUTF32(indexedCharacter, faceType);
262 }
263
264 /* ------------------------------------------------------------------------- */
271 /* ------------------------------------------------------------------------- */
272 [[nodiscard]] bool HasFontFace(FontFaceType faceType) const noexcept override
273 {
274 return _resource.HasFontFace(faceType);
275 }
276
277 private:
278 const FontResource &_resource;
279 };
280
281 IndexConverter _indexConverter;
282 FontOrigin _originType;
283 uint32_t _featureFlags{0};
284};
285
287using SharedFontResource = std::shared_ptr<FontResource>;
288
289} // namespace MGL::Render
290
291#endif // INCGUARD_MGL_FONT_RESOURCE_H_1622008768
292
293// vim: et ts=4 sw=4 sts=4
フォントリソースクラス
Definition mgl_font_resource.h:24
constexpr const Text::IndexConverter & GetIndexConverter() const noexcept
インデックス文字列のコンバータを取得
Definition mgl_font_resource.h:174
constexpr bool IsEnabled(FontFeature feature) const noexcept
フォント機能の有効状態を取得
Definition mgl_font_resource.h:187
constexpr FontOrigin GetOriginType() const noexcept
フォントの原点タイプを取得
Definition mgl_font_resource.h:198
constexpr void SetEnabled(FontFeature feature, bool isEnabled) noexcept
フォント機能の有効状態を設定
Definition mgl_font_resource.h:211
virtual const FontGlyph * GetGlyph(Text::IndexedCharacter character, FontFaceType faceType, const FontOption &option) const noexcept
グリフの取得
Definition mgl_font_resource.h:141
virtual const FontGlyph * GetGlyph(char32_t character, FontFaceType faceType, const FontOption &option) const noexcept
グリフの取得
Definition mgl_font_resource.h:124
constexpr FontResource(FontOrigin originType) noexcept
コンストラクタ
Definition mgl_font_resource.h:31
virtual bool HasFontFace(FontFaceType faceType) const noexcept=0
指定したフェイスを保持しているかを取得
virtual bool Print(FontWorkdata &workdata, const FontOption &option, const char *text, const Text::FormatArgs &formatArgs) noexcept
文字の表示
Definition mgl_font_resource.h:50
virtual Text::IndexedCharacter ToIndexedCharacter(char32_t character, FontFaceType faceType) const noexcept
文字をインデックス文字に変換
Definition mgl_font_resource.h:93
virtual bool Print(FontWorkdata &workdata, const FontOption &option, const Text::IndexedCharacter *indexedString, const Text::FormatArgs &formatArgs) noexcept
インデックス化した文字を表示
Definition mgl_font_resource.h:73
virtual char32_t ToUTF32(Text::IndexedCharacter indexedCharacter, FontFaceType faceType) const noexcept
インデックス文字をUTF-32の文字に変換
Definition mgl_font_resource.h:108
virtual bool IsValid() const noexcept=0
このフォントリソースが有効かどうかを取得
インデックスコンバータクラス
Definition mgl_text_index_converter.h:24
フォント関連定義
FontOrigin
フォントの原点
Definition mgl_font_defs.h:52
FontFeature
フォントの機能
Definition mgl_font_defs.h:41
FontFaceType
フォントのフェイスタイプ
Definition mgl_font_defs.h:21
MGL フォントのグリフ情報
MGL フォント描画オプション
std::shared_ptr< FontResource > SharedFontResource
フォントリソースの共有ポインタ
Definition mgl_font_resource.h:287
uint16_t IndexedCharacter
インデックス化文字
Definition mgl_text_defs.h:30
MGL テキストフォーマット
STL::vector< FormatArgument > FormatArgs
テキストフォーマットの引数の配列
Definition mgl_text_format_argument.h:282
MGL テキストのインデックス化コンバータ
MGL 2Dベクトル
グリフ情報
Definition mgl_font_glyph.h:20
フォント描画オプション
Definition mgl_font_option.h:22
フォント描画のワークデータ
Definition mgl_font_defs.h:59