FTFont.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #pragma once
  2. #include "../Common.h"
  3. #include "../util/String.h"
  4. #include "../util/Dictionary.h"
  5. #include "../util/Array.h"
  6. #include <unordered_map>
  7. #include <vector>
  8. #include "third_party/freetype/include/ft2build.h"
  9. #include FT_FREETYPE_H
  10. NS_BF_BEGIN
  11. class Texture;
  12. class TextureSegment;
  13. class FTFontManager
  14. {
  15. public:
  16. class Face;
  17. class FaceSize
  18. {
  19. public:
  20. Face* mFace;
  21. FT_Size mFTSize;
  22. int mRefCount;
  23. float mPointSize;
  24. public:
  25. FaceSize()
  26. {
  27. mFace = NULL;
  28. mRefCount = 0;
  29. mFTSize = NULL;
  30. mPointSize = -1;
  31. }
  32. ~FaceSize();
  33. };
  34. class Face
  35. {
  36. public:
  37. String mFileName;
  38. FT_Face mFTFace;
  39. Dictionary<float, FaceSize*> mFaceSizes;
  40. public:
  41. Face()
  42. {
  43. mFTFace = NULL;
  44. }
  45. ~Face();
  46. };
  47. class Page
  48. {
  49. public:
  50. Texture* mTexture;
  51. int mCurX;
  52. int mCurY;
  53. int mMaxRowHeight;
  54. public:
  55. Page()
  56. {
  57. mTexture = NULL;
  58. mCurX = 0;
  59. mCurY = 0;
  60. mMaxRowHeight = 0;
  61. }
  62. ~Page();
  63. };
  64. class Glyph
  65. {
  66. public:
  67. Page* mPage;
  68. TextureSegment* mTextureSegment;
  69. int mX;
  70. int mY;
  71. int mWidth;
  72. int mHeight;
  73. int mXOffset;
  74. int mYOffset;
  75. int mXAdvance;
  76. public:
  77. Glyph()
  78. {
  79. mPage = NULL;
  80. mTextureSegment = NULL;
  81. }
  82. //~Glyph();
  83. };
  84. public:
  85. Dictionary<String, Face*> mFaces;
  86. Array<Page*> mPages;
  87. uint8 mWhiteTab[256];
  88. uint8 mBlackTab[256];
  89. void DoClearCache();
  90. public:
  91. FTFontManager();
  92. ~FTFontManager();
  93. static void ClearCache();
  94. };
  95. class FTFont
  96. {
  97. public:
  98. int mHeight;
  99. int mAscent;
  100. int mDescent;
  101. int mMaxAdvance;
  102. FTFontManager::Face* mFace;
  103. FTFontManager::FaceSize* mFaceSize;
  104. protected:
  105. void Dispose(bool cacheRetain);
  106. public:
  107. FTFont();
  108. ~FTFont();
  109. bool Load(const StringImpl& file, float pointSize);
  110. FTFontManager::Glyph* AllocGlyph(int charCode, bool allowDefault);
  111. int GetKerning(int charA, int charB);
  112. void Release(bool cacheRetain = false);
  113. };
  114. NS_BF_END