7#ifndef MYGUI_RESOURCE_TRUE_TYPE_FONT_H_
8#define MYGUI_RESOURCE_TRUE_TYPE_FONT_H_
15#ifdef MYGUI_USE_FREETYPE
17using FT_UInt =
unsigned int;
18using FT_Int32 =
signed int;
20using FT_Face = FT_FaceRec_*;
22using FT_Library = FT_LibraryRec_*;
23struct FT_GlyphSlotRec_;
24using FT_GlyphSlot = FT_GlyphSlotRec_*;
26 #ifdef MYGUI_MSDF_FONTS
38#include <unordered_map>
43 class MYGUI_EXPORT ResourceTrueTypeFont :
public IFont,
public ITextureInvalidateListener
48 ~ResourceTrueTypeFont()
override;
50 void deserialization(xml::ElementPtr _node, Version _version)
override;
54 const GlyphInfo* getGlyphInfo(Char _id)
const override;
56 ITexture* getTextureFont()
const override;
59 int getDefaultHeight()
const override;
62 void textureInvalidate(ITexture* _texture)
override;
64 float getKerning(Char _left, Char _right)
const override;
68 std::vector<std::pair<Char, Char>> getCodePointRanges()
const;
72 Char getSubstituteCodePoint()
const;
76 void setSource(std::string_view _value);
77 void setShader(std::string_view _value);
78 void setSize(
float _value);
79 void setResolution(
unsigned int _value);
80 void setHinting(std::string_view _value);
81 void setAntialias(
bool _value);
82 void setTabWidth(
float _value);
83 void setOffsetHeight(
int _value);
84 void setSubstituteCode(
int _value);
85 void setDistance(
int _value);
86 void setMsdfMode(
bool _value);
87 void setMsdfRange(
int _value);
88 void setKerningEnabled(
bool _value);
89 void setDpiScale(
float _value);
90 void setAutoDpi(
bool _value);
92 void addCodePointRange(Char _first, Char _second);
93 void removeCodePointRange(Char _first, Char _second);
95#ifdef MYGUI_USE_FREETYPE
111 void addCodePoint(Char _codePoint);
117 unsigned int mResolution{96};
118 Hinting mHinting{HintingUseNative};
121 float mSpaceWidth{0.0f};
122 int mGlyphSpacing{-1};
123 float mTabWidth{0.0f};
126 Char mSubstituteCodePoint{
static_cast<Char>(
132 bool mKerningEnabled{
true};
133 float mDpiScale{1.0f};
137 int mDefaultHeight{0};
138 GlyphInfo* mSubstituteGlyphInfo{
140 MyGUI::ITexture* mTexture{
nullptr};
144 mDefaultGlyphSpacing;
145 static const float mDefaultTabWidth;
148 static const float mCursorWidth;
152 using CharMap = std::map<Char, FT_UInt>;
155 using GlyphMap = std::unordered_map<Char, GlyphInfo>;
158 using GlyphHeightMap = std::map<int, std::map<FT_UInt, GlyphInfo*>>;
160 template<
bool LAMode,
bool Antialias>
161 void initialiseFreeType();
167 FT_Face loadFace(
const FT_Library& _ftLibrary, std::vector<std::byte>& _fontBuffer);
170 void loadKerning(
const FT_Face& _ftFace);
174 void autoWrapGlyphPos(
int _glyphWidth,
int _texWidth,
int _lineHeight,
int& _texX,
int& _texY)
const;
177 GlyphInfo createFaceGlyphInfo(Char _codePoint,
int _fontAscent, FT_GlyphSlot _glyph)
const;
183 const GlyphInfo& _glyphInfo,
184 GlyphHeightMap& _glyphHeightMap,
185 float _scale = -1.0);
193 const FT_Face& _ftFace,
194 FT_Int32 _ftLoadFlags,
195 GlyphHeightMap& _glyphHeightMap);
198 template<
bool LAMode,
bool Antialias>
200 const GlyphHeightMap& _glyphHeightMap,
201 const FT_Library& _ftLibrary,
202 const FT_Face& _ftFace,
203 FT_Int32 _ftLoadFlags,
211 template<
bool LAMode,
bool UseBuffer,
bool Antialias>
225 uint8* _glyphBuffer =
nullptr);
231 #ifdef MYGUI_MSDF_FONTS
232 double mMsdfScale{1.0};
234 GlyphInfo createMsdfFaceGlyphInfo(
236 const msdfgen::Shape& _shape,
239 int createMsdfFaceGlyph(
243 msdfgen::FontHandle* _fontHandle,
244 GlyphHeightMap& _glyphHeightMap);
246 void renderMsdfGlyphs(
247 const GlyphHeightMap& _glyphHeightMap,
248 msdfgen::FontHandle* _fontHandle,
#define MYGUI_RTTI_DERIVED(DerivedType)
std::unordered_map< std::pair< Char, Char >, float, KerningPairHash > KerningMap