My Project
GLFontAtlas.h
1 #pragma once
2 #include <string>
3 #include <unordered_map>
4 
5 #include "GLType.h"
6 
7 namespace ParaEngine
8 {
9 
10  class Font;
11  class Texture2D;
12  class FontFreeType;
13 
14  class FontAtlas : public CRefCountedOne
15  {
16  public:
17  static const int CacheTextureWidth;
18  static const int CacheTextureHeight;
19  static const char* CMD_PURGE_FONTATLAS;
20  static const char* CMD_RESET_FONTATLAS;
21 
22  FontAtlas(Font &theFont);
23  virtual ~FontAtlas();
24 
25  void addLetterDefinition(char16_t utf16Char, const FontLetterDefinition &letterDefinition);
26  bool getLetterDefinitionForChar(char16_t utf16Char, FontLetterDefinition &letterDefinition);
27 
28  bool prepareLetterDefinitions(const std::u16string& utf16String);
29 
30  inline const std::unordered_map<size_t, Texture2D*>& getTextures() const { return _atlasTextures; }
31  void addTexture(Texture2D *texture, int slot);
32  float getLineHeight() const { return _lineHeight; }
33  void setLineHeight(float newHeight);
34 
35 
36 
37  Texture2D* getTexture(int slot);
38  const Font* getFont() const { return _font; }
39 
40 
41  float getCommonLineHeight() const
42  {
43  return _lineHeight;
44  }
45 
49  void purgeTexturesAtlas();
50 
56 
61  void setAliasTexParameters();
62 
63  protected:
64  void reset();
65 
66  void releaseTextures();
67 
68  void findNewCharacters(const std::u16string& u16Text, std::unordered_map<unsigned short, unsigned short>& charCodeMap);
69 
70  void conversionU16TOGB2312(const std::u16string& u16Text, std::unordered_map<unsigned short, unsigned short>& charCodeMap);
71 
77  void scaleFontLetterDefinition(float scaleFactor);
78 
79  std::unordered_map<size_t, Texture2D*> _atlasTextures;
80  std::unordered_map<char16_t, FontLetterDefinition> _letterDefinitions;
81  float _lineHeight;
82  Font* _font;
83  FontFreeType* _fontFreeType;
84  void* _iconv;
85 
86  // Dynamic GlyphCollection related stuff
87  int _currentPage;
88  unsigned char *_currentPageData;
89  int _currentPageDataSize;
90  float _currentPageOrigX;
91  float _currentPageOrigY;
92  int _letterPadding;
93  int _letterEdgeExtend;
94 
95  int _fontAscender;
96 
97  bool _antialiasEnabled;
98  int _currLineHeight;
99 
100  friend class Label;
101  };
102 }
Definition: GLFontAtlas.h:14
Base class for a reference counted asset.
Definition: PERef.h:55
void setAliasTexParameters()
sets font texture parameters:
Definition: GLFontAtlas.cpp:427
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: GLFont.h:10
Definition: GLTexture2D.h:12
void scaleFontLetterDefinition(float scaleFactor)
Scale each font letter by scaleFactor.
Definition: GLFontAtlas.cpp:129
Definition: GLLabel.h:34
void setAntiAliasTexParameters()
sets font texture parameters:
Definition: GLFontAtlas.cpp:439
Definition: GLFontFreeType.h:17
Definition: GLType.h:68
void purgeTexturesAtlas()
Removes textures atlas.
Definition: GLFontAtlas.cpp:115