summaryrefslogtreecommitdiff
path: root/Runtime/GUI/Font.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-01 19:30:44 +0800
committerchai <chaifix@163.com>2021-11-01 19:30:44 +0800
commit4b652abe1d76f1bcbe5d7583a8986256f50c483d (patch)
treedaf81888f8e37c40483fcd309201bc33471b97fa /Runtime/GUI/Font.h
parentb7310c9cce95bfc9bfe135063ee0e97fbc654928 (diff)
-LuaBindClass::RegisterNativeClass
Diffstat (limited to 'Runtime/GUI/Font.h')
-rw-r--r--Runtime/GUI/Font.h34
1 files changed, 19 insertions, 15 deletions
diff --git a/Runtime/GUI/Font.h b/Runtime/GUI/Font.h
index 242bd19..344cc00 100644
--- a/Runtime/GUI/Font.h
+++ b/Runtime/GUI/Font.h
@@ -5,24 +5,29 @@
#include "freetype.h"
#include "Runtime/Lua/LuaHelper.h"
#include "Runtime/Common/DataBuffer.h"
+#include "Runtime/Math/Math.h"
#include <string>
#include <unordered_map>
#include <exception>
#include <vector>
-//https://learnopengl.com/In-Practice/Text-Rendering
+//https://github.com/kaienfr/Font
struct Character {
unsigned int atlas; // atlas索引
- Internal::Rect position; // 在altas里的位置
- Internal::Vector2 bearing; // 左上角相对于原点的偏移
+ Rect position; // 在altas里的位置
+ Vector2 bearing; // 左上角相对于原点的偏移
unsigned int advance; // 总宽,算上了间隔
};
namespace character
{
+#if GAMELAB_WIN
typedef unsigned short Codepoint; // unicode Codepoint(BMP,U+0000至U+FFFF)
+#else
+ typedef unsigned int Codepoint; // unicode Codepoint(BMP,U+0000至U+FFFF)
+#endif
union Hash {
unsigned int hashCode;
@@ -55,13 +60,13 @@ struct GlyphAtals
Texture* altas; // 贴图
int width, height; // 尺寸
- Internal::Vector2 cursor; // 游标,从左上角(0,0)开始
+ Vector2 cursor; // 游标,从左上角(0,0)开始
int rowHeight; // 当前行的高度
};
struct TextGeneratingSettings
{
- Internal::Vector2 atlasSize; // atlas的尺寸
+ Vector2 atlasSize; // atlas的尺寸
int margin; // atlas的边界
int padding; // glyph相互之间的间距,防止采样的时候越界
};
@@ -89,20 +94,21 @@ public:
Font(std::string path, TextGeneratingSettings setting)/*throw FontException*/;
Font(LuaBind::VM* vm, std::string path, TextGeneratingSettings setting)/*throw FontException*/;
Font(DataBuffer* db, TextGeneratingSettings setting)/*throw FontException*/;
- Font(DataBuffer* db, LuaBind::VM* vm, std::string path, TextGeneratingSettings setting)/*throw FontException*/;
+ Font(LuaBind::VM* vm, DataBuffer* db, TextGeneratingSettings setting)/*throw FontException*/;
const Character* GetCharacter(character::Codepoint codepoint, int pixelSize);
const GlyphAtals* GetGlyphAtlas(int index);
// pre-bake
void RenderCharacter(character::Codepoint codepoint, int pixelSize);
- void RenderCharacters(character::Codepoint* codepoint, int n, int pixelSize);
+ void RenderCharacters(character::Codepoint* codepoint, int n, int pixelSize);
+ void RenderCharacters(std::vector<character::Codepoint>& codepoint, int pixelSize);
private:
Texture* CreateAtlas();
- GlyphAtals* RequestAtlas(int pixelSize, Internal::Vector2 preferSize);
- Internal::Rect GetRenderChartAndMove(GlyphAtals* atlas, Internal::Vector2 preferSize);
- bool HasEnoughSpace(GlyphAtals* atlas, Internal::Vector2 preferSize);
+ GlyphAtals* RequestAtlas(int pixelSize, Vector2 preferSize);
+ Rect GetRenderChartAndMove(GlyphAtals* atlas, Vector2 preferSize);
+ bool HasEnoughSpace(GlyphAtals* atlas, Vector2 preferSize);
character::Hash GetHash(character::Codepoint Codepoint, int pixelSize);
//-------------------------------------------------------------------------
@@ -114,9 +120,9 @@ private:
bool m_IsEnabled;
- Internal::Vector2 m_AtlasSize;
- int m_AtlasMargin;
- int m_GlyphPadding;
+ Vector2 m_AtlasSize;
+ int m_AtlasMargin;
+ int m_GlyphPadding;
FT_Library m_FTLibrary;
FT_Face m_FTFace;
@@ -132,8 +138,6 @@ private:
};
-//#define g_TextGenerator (*Font::Instance())
-
namespace TextHelper
{