MyGUI 3.5.3
MyGUI_ResourceManualFont.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_RESOURCE_MANUAL_FONT_H_
8#define MYGUI_RESOURCE_MANUAL_FONT_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_ITexture.h"
12#include "MyGUI_IFont.h"
13
14namespace MyGUI
15{
16
17 class MYGUI_EXPORT ResourceManualFont : public IFont
18 {
19 MYGUI_RTTI_DERIVED(ResourceManualFont)
20
21 public:
22 void deserialization(xml::ElementPtr _node, Version _version) override;
23
24 // Returns the glyph info for the specified code point, or the glyph info for a substitute glyph if the code point does not
25 // exist in this font. Returns nullptr if the code point does not exist and there is no substitute glyph available.
26 const GlyphInfo* getGlyphInfo(Char _id) const override;
27
28 ITexture* getTextureFont() const override;
29
30 // Default height from font settings
31 int getDefaultHeight() const override;
32
33 float getKerning(Char _left, Char _right) const override;
34
35 // Manual loading methods, not needed when loading from XML
36 // Set the source texture by name
37 void setSource(std::string_view value);
38 // Set the shader by name
39 void setShader(std::string_view value);
40 // Set the source texture directly
41 // Note: the user is responsible for deallocation of the texture.
42 void setTexture(MyGUI::ITexture* texture);
43 // Set the default height of the font
44 void setDefaultHeight(int value);
45 // Add a glyph for character 'id'
46 void addGlyphInfo(Char id, const GlyphInfo& info);
47 // Add a kerning pair
48 void addKerningInfo(Char _left, Char _right, float _value);
49
50 private:
51 // Loads the texture specified by mSource.
52 void loadTexture();
53
54 // A map of code points to glyph info objects.
55 using CharMap = std::unordered_map<Char, GlyphInfo>;
56
57 // The following variables are set directly from values specified by the user.
58 std::string mSource; // Source (filename) of the font.
59 std::string mShader; // Optional shader, applied to the font.
60
61 // The following variables are calculated automatically.
62 int mDefaultHeight{0}; // The nominal height of the font in pixels.
63 GlyphInfo* mSubstituteGlyphInfo{
64 nullptr}; // The glyph info to use as a substitute for code points that don't exist in the font.
65 MyGUI::ITexture* mTexture{nullptr}; // The texture that contains all of the rendered glyphs in the font.
66
67 CharMap mCharMap; // A map of code points to glyph info objects.
68
69 KerningMap mKerningMap;
70 };
71
72} // namespace MyGUI
73
74#endif // MYGUI_RESOURCE_MANUAL_FONT_H_
#define MYGUI_EXPORT
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition MyGUI_RTTI.h:67
std::unordered_map< std::pair< Char, Char >, float, KerningPairHash > KerningMap