12 #include "utils/ColorUtils.h" 13 #include "utils/Geometry.h" 21 #include FT_FREETYPE_H 22 #include <harfbuzz/hb.h> 25 #include <DirectXMath.h> 26 #include <DirectXPackedVector.h> 37 struct FT_LibraryRec_;
38 struct FT_GlyphSlotRec_;
39 struct FT_BitmapGlyphRec_;
40 struct FT_StrokerRec_;
42 typedef struct FT_FaceRec_* FT_Face;
43 typedef struct FT_LibraryRec_* FT_Library;
44 typedef struct FT_GlyphSlotRec_* FT_GlyphSlot;
45 typedef struct FT_BitmapGlyphRec_* FT_BitmapGlyph;
46 typedef struct FT_StrokerRec_* FT_Stroker;
48 typedef uint32_t character_t;
49 typedef std::vector<character_t> vecText;
68 unsigned char r, g, b, a;
80 static constexpr
int MAX_GLYPH_IDX = 4096;
81 static constexpr
size_t LOOKUPTABLE_SIZE = MAX_GLYPH_IDX * FONT_STYLES_COUNT;
88 static CGUIFontTTF* CreateGUIFontTTF(
const std::string& fontIdent);
92 bool Load(
const std::string& strFilename,
95 float lineSpacing = 1.0f,
101 virtual CVertexBuffer CreateVertexBuffer(
const std::vector<SVertex>& vertices)
const 106 virtual void DestroyVertexBuffer(
CVertexBuffer& bufferHandle)
const {}
108 const std::string& GetFontIdent()
const {
return m_fontIdent; }
111 explicit CGUIFontTTF(
const std::string& fontIdent);
115 hb_glyph_info_t m_glyphInfo{};
116 hb_glyph_position_t m_glyphPosition{};
118 Glyph(
const hb_glyph_info_t& glyphInfo,
const hb_glyph_position_t& glyphPosition)
119 : m_glyphInfo(glyphInfo), m_glyphPosition(glyphPosition)
133 FT_UInt m_glyphIndex;
134 character_t m_glyphAndStyle;
139 unsigned int m_startOffset;
140 unsigned int m_endOffset;
141 hb_buffer_t* m_buffer;
142 hb_script_t m_script;
143 hb_glyph_info_t* m_glyphInfos;
144 hb_glyph_position_t* m_glyphPositions;
148 void RemoveReference();
150 std::vector<Glyph> GetHarfBuzzShapedGlyphs(
const vecText& text);
152 float GetTextWidthInternal(
const vecText& text);
153 float GetTextWidthInternal(
const vecText& text,
const std::vector<Glyph>& glyph);
154 float GetCharWidthInternal(character_t ch);
155 float GetTextHeight(
float lineSpacing,
int numLines)
const;
156 float GetTextBaseLine()
const {
return static_cast<float>(m_cellBaseLine); }
157 float GetLineHeight(
float lineSpacing)
const;
158 float GetFontHeight()
const {
return m_height; }
163 const std::vector<UTILS::COLOR::Color>& colors,
169 float m_height{0.0f};
172 Character* GetCharacter(character_t letter, FT_UInt glyphIndex);
173 bool CacheCharacter(FT_UInt glyphIndex, uint32_t style,
Character* ch);
178 UTILS::COLOR::Color color,
180 std::vector<SVertex>& vertices);
181 void ClearCharacterCache();
183 virtual std::unique_ptr<CTexture> ReallocTexture(
unsigned int& newHeight) = 0;
184 virtual bool CopyCharToTexture(FT_BitmapGlyph bitGlyph,
188 unsigned int y2) = 0;
189 virtual void DeleteHardwareTexture() = 0;
192 void SetGlyphStrength(FT_GlyphSlot slot,
int glyphStrength);
193 static void ObliqueGlyph(FT_GlyphSlot slot);
195 std::unique_ptr<CTexture>
198 unsigned int m_textureWidth{0};
199 unsigned int m_textureHeight{0};
206 unsigned int GetTextureLineHeight()
const;
207 unsigned int GetMaxFontHeight()
const;
209 UTILS::COLOR::Color m_color{UTILS::COLOR::NONE};
211 std::vector<Character> m_char;
214 Character* m_charquick[LOOKUPTABLE_SIZE]{
nullptr};
216 bool m_ellipseCached{
false};
217 float m_ellipsesWidth{0.0f};
219 unsigned int m_cellBaseLine{0};
220 unsigned int m_cellHeight{0};
221 unsigned int m_maxFontHeight{0};
223 unsigned int m_nestedBeginCount{0};
226 FT_Face m_face{
nullptr};
227 FT_Stroker m_stroker{
nullptr};
229 hb_font_t* m_hbFont{
nullptr};
231 float m_originX{0.0f};
232 float m_originY{0.0f};
234 unsigned int m_nTexture{0};
248 : m_translateX(translateX),
249 m_translateY(translateY),
250 m_translateZ(translateZ),
251 m_vertexBuffer(vertexBuffer),
256 std::vector<CTranslatedVertices> m_vertexTrans;
257 std::vector<SVertex> m_vertex;
259 float m_textureScaleX{0.0f};
260 float m_textureScaleY{0.0f};
262 const std::string m_fontIdent;
272 float GetTabSpaceLength();
274 virtual bool FirstBegin() = 0;
275 virtual void LastEnd() = 0;
278 int m_referenceCount{0};
Definition: GUIFontTTF.h:65
Definition: GUIFontTTF.h:113
Definition: GUIFontTTF.h:236
Definition: GUIFontTTF.h:76
Definition: RenderSystem.h:27
Definition: GUIFontTTF.h:137
Base texture class, subclasses of which depend on the render spec (DX, GL etc.)
Definition: Texture.h:34
Definition: GUIFontCache.h:220
Definition: GUIFontTTF.h:124
Definition: GUIFont.h:107
Definition: GraphicContext.h:60