MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_ResourceTrueTypeFont.h
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #ifndef __MYGUI_RESOURCE_TRUE_TYPE_FONT_H__
23 #define __MYGUI_RESOURCE_TRUE_TYPE_FONT_H__
24
25 #include "MyGUI_Prerequest.h"
26 #include "MyGUI_ITexture.h"
27 #include "MyGUI_IFont.h"
28
29 #ifdef MYGUI_USE_FREETYPE
30 #include <ft2build.h>
31 #include FT_FREETYPE_H
32 #endif // MYGUI_USE_FREETYPE
33
34 namespace MyGUI
35 {
36
37 class MYGUI_EXPORT ResourceTrueTypeFont :
38 public IFont
39 {
40 MYGUI_RTTI_DERIVED( ResourceTrueTypeFont )
41
42 public:
43 ResourceTrueTypeFont();
44 virtual ~ResourceTrueTypeFont();
45
46 virtual void deserialization(xml::ElementPtr _node, Version _version);
47
48 // Returns the glyph info for the specified code point, or the glyph info for a substitute glyph if the code point does not
49 // exist in this font. Returns nullptr if there is a problem with the font.
50 virtual GlyphInfo* getGlyphInfo(Char _id);
51
52 virtual ITexture* getTextureFont();
53
54 // получившаяся высота при генерации в пикселях
55 virtual int getDefaultHeight();
56
57 // Returns a collection of code-point ranges that are supported by this font. Each range is specified as [first, second];
58 // for example, a range containing a single code point will have the same value for both first and second.
59 std::vector<std::pair<Char, Char> > getCodePointRanges() const;
60
61 // Returns the code point that is used as a substitute for code points that don't exist in the font. The default substitute
62 // code point is FontCodeType::NotDefined, but it can be customized in the font definition file.
63 Char getSubstituteCodePoint() const;
64
65 private:
66 void addCodePoint(Char _codePoint);
67 void removeCodePoint(Char _codePoint);
68
69 void addCodePointRange(Char _first, Char _second);
70 void removeCodePointRange(Char _first, Char _second);
71
72 void clearCodePoints();
73
74 void initialise();
75
76 // The following variables are set directly from values specified by the user.
77 std::string mSource; // Source (filename) of the font.
78 float mSize; // Size of the font, in points (there are 72 points per inch).
79 uint mResolution; // Resolution of the font, in pixels per inch.
80 bool mAntialias; // Whether or not to anti-alias the font by copying its alpha channel to its luminance channel.
81 float mSpaceWidth; // The width of a "Space" character, in pixels. If zero, the default width is used.
82 float mTabWidth; // The width of the "Tab" special character, in pixels.
83 int mOffsetHeight; // How far up to nudge text rendered in this font, in pixels. May be negative to nudge text down.
84 Char mSubstituteCodePoint; // The code point to use as a substitute for code points that don't exist in the font.
85
86 // The following variables are calculated automatically.
87 int mDefaultHeight; // The nominal height of the font in pixels.
88 GlyphInfo* mSubstituteGlyphInfo; // The glyph info to use as a substitute for code points that don't exist in the font.
89 MyGUI::ITexture* mTexture; // The texture that contains all of the rendered glyphs in the font.
90
91 // The following constants used to be mutable, but they no longer need to be. Do not modify their values!
92 static const int mGlyphSpacing; // How far apart the glyphs are placed from each other in the font texture, in pixels.
93 static const float mSelectedWidth; // The width of the "Selected" and "SelectedBack" special characters, in pixels.
94 static const float mCursorWidth; // The width of the "Cursor" special character, in pixels.
95
96 #ifdef MYGUI_USE_FREETYPE
97
98 private:
99 // A map of code points to glyph indices.
100 typedef std::map<Char, FT_UInt> CharMap;
101
102 // A map of glyph indices to glyph info objects.
103 typedef std::map<FT_UInt, GlyphInfo> GlyphMap;
104
105 // A map of glyph heights to the set of paired glyph indices and glyph info objects that are of that height.
106 typedef std::map<FT_Pos, std::map<FT_UInt, GlyphInfo*> > GlyphHeightMap;
107
108 template<bool LAMode, bool Antialias>
109 void initialiseFreeType();
110
111 // Loads the font face as specified by mSource, mSize, and mResolution. Automatically adjusts code-point ranges according
112 // to the capabilities of the font face.
113 // Returns a handle to the FreeType face object for the face, or nullptr if the face could not be loaded.
114 // Keeps the font file loaded in memory and stores its location in _fontBuffer. The caller is responsible for freeing this
115 // buffer when it is done using the face by calling delete[] on the buffer after calling FT_Done_Face() on the face itself.
116 FT_Face loadFace(const FT_Library& _ftLibrary, uint8*& _fontBuffer);
117
118 // Wraps the current texture coordinates _texX and _texY to the beginning of the next line if the specified glyph width
119 // doesn't fit at the end of the current line. Automatically takes the glyph spacing into account.
120 void autoWrapGlyphPos(int _glyphWidth, int _texWidth, int _lineHeight, int& _texX, int& _texY);
121
122 // Creates a GlyphInfo object using the specified information.
123 GlyphInfo createFaceGlyphInfo(Char _codePoint, int _fontAscent, FT_GlyphSlot _glyph);
124
125 // Creates a glyph with the specified glyph index and assigns it to the specified code point.
126 // Automatically updates _glyphHeightMap, mCharMap, and mGlyphMap with data from the new glyph..
127 int createGlyph(FT_UInt _glyphIndex, const GlyphInfo& _glyphInfo, GlyphHeightMap& _glyphHeightMap);
128
129 // Creates a glyph with the specified index from the specified font face and assigns it to the specified code point.
130 // Automatically updates _glyphHeightMap with data from the newly created glyph.
131 int createFaceGlyph(FT_UInt _glyphIndex, Char _codePoint, int _fontAscent, const FT_Face& _face, GlyphHeightMap& _glyphHeightMap);
132
133 // Renders all of the glyphs in _glyphHeightMap into the specified texture buffer using data from the specified font face.
134 template<bool LAMode, bool Antialias>
135 void renderGlyphs(const GlyphHeightMap& _glyphHeightMap, const FT_Library& _ftLibrary, const FT_Face& _face, uint8* _texBuffer, int _texWidth, int _texHeight);
136
137 // Renders the glyph described by the specified glyph info according to the specified parameters.
138 // Supports two types of rendering, depending on the value of UseBuffer: Texture block transfer and rectangular color fill.
139 // The _luminance0 value is used for even-numbered columns (from zero), while _luminance1 is used for odd-numbered ones.
140 template<bool LAMode, bool UseBuffer, bool Antialias>
141 void renderGlyph(GlyphInfo& _info, uint8 _luminance0, uint8 _luminance1, uint8 _alpha, int _lineHeight, uint8* _texBuffer, int _texWidth, int _texHeight, int& _texX, int& _texY, uint8* _glyphBuffer = nullptr);
142
143 CharMap mCharMap; // A map of code points to glyph indices.
144 GlyphMap mGlyphMap; // A map of glyph indices to glyph info objects.
145
146 #endif // MYGUI_USE_FREETYPE
147
148 };
149
150 } // namespace MyGUI
151
152 #endif // __MYGUI_RESOURCE_TRUE_TYPE_FONT_H__
MyGUI_Prerequest.h
MyGUI::xml::ElementPtr
Element * ElementPtr
Definition: MyGUI_XmlDocument.h:114
MyGUI_IFont.h
MyGUI::IFont
Definition: MyGUI_IFont.h:35
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition: MyGUI_RTTI.h:88
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:120
MyGUI::uint
unsigned int uint
Definition: MyGUI_Types.h:64
MyGUI_ITexture.h
MyGUI::ResourceTrueTypeFont
Definition: MyGUI_ResourceTrueTypeFont.h:37
MyGUI::ITexture
Definition: MyGUI_ITexture.h:41
MyGUI::Char
unsigned int Char
Definition: MyGUI_Types.h:66
MyGUI::Version
Definition: MyGUI_Version.h:32
MyGUI::GlyphInfo
Definition: MyGUI_FontData.h:53
MyGUI::uint8
unsigned char uint8
Definition: MyGUI_Types.h:61