summaryrefslogtreecommitdiff
path: root/Runtime/GUI/Font.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-01 16:53:51 +0800
committerchai <chaifix@163.com>2021-11-01 16:53:51 +0800
commitb7310c9cce95bfc9bfe135063ee0e97fbc654928 (patch)
tree459d37f0acd9b9dd6719b71d1ecc8620dc1f5fef /Runtime/GUI/Font.cpp
parent4dead522e513ffd326101b790b2129595f72ff42 (diff)
*misc
Diffstat (limited to 'Runtime/GUI/Font.cpp')
-rw-r--r--Runtime/GUI/Font.cpp89
1 files changed, 77 insertions, 12 deletions
diff --git a/Runtime/GUI/Font.cpp b/Runtime/GUI/Font.cpp
index f00f33d..67a2e3b 100644
--- a/Runtime/GUI/Font.cpp
+++ b/Runtime/GUI/Font.cpp
@@ -13,21 +13,86 @@ using namespace character;
//https://baike.baidu.com/item/%E5%9F%BA%E6%9C%AC%E5%A4%9A%E6%96%87%E7%A7%8D%E5%B9%B3%E9%9D%A2/10788078
//https://stackoverflow.com/questions/27331819/whats-the-difference-between-a-character-a-code-point-a-glyph-and-a-grapheme
-void Font::Setup(TextGeneratingSettings settings)
+static std::string s_FontError;
+
+Font::Font(std::string path, TextGeneratingSettings settings)
+ : LuaBind::NativeClass<Font>()
{
- m_AtlasMargin = settings.margin;
- m_GlyphPadding = settings.padding;
- m_AtlasSize = settings.atlasSize;
+ m_AtlasMargin = settings.margin;
+ m_GlyphPadding = settings.padding;
+ m_AtlasSize = settings.atlasSize;
- if (FT_Init_FreeType(&m_FTLibrary))
- {
- return;
- }
+ if (FT_Init_FreeType(&m_FTLibrary))
+ {
+ s_FontError = "Init freetype error. Font path " + path;
+ throw FontException(s_FontError.c_str());
+ }
- if (FT_New_Face(m_FTLibrary, "Resources/Font/Deng.ttf", 0, &m_FTFace))
- {
- return;
- }
+ if (FT_New_Face(m_FTLibrary, path.c_str(), 0, &m_FTFace))
+ {
+ s_FontError = "Create freetype face error. Font path " + path;
+ throw FontException(s_FontError.c_str());
+ }
+}
+
+Font::Font(LuaBind::VM* vm, std::string path, TextGeneratingSettings settings)
+ : LuaBind::NativeClass<Font>(vm)
+{
+ m_AtlasMargin = settings.margin;
+ m_GlyphPadding = settings.padding;
+ m_AtlasSize = settings.atlasSize;
+
+ if (FT_Init_FreeType(&m_FTLibrary))
+ {
+ s_FontError = "Init freetype error. Font path " + path;
+ throw FontException(s_FontError.c_str());
+ }
+
+ if (FT_New_Face(m_FTLibrary, path.c_str(), 0, &m_FTFace))
+ {
+ s_FontError = "Create freetype face error. Font path " + path;
+ throw FontException(s_FontError.c_str());
+ }
+}
+
+Font::Font(DataBuffer* db, TextGeneratingSettings settings)
+ : LuaBind::NativeClass<Font>()
+{
+ m_AtlasMargin = settings.margin;
+ m_GlyphPadding = settings.padding;
+ m_AtlasSize = settings.atlasSize;
+
+ if (FT_Init_FreeType(&m_FTLibrary))
+ {
+ s_FontError = "Init freetype error.";
+ throw FontException(s_FontError.c_str());
+ }
+
+ if (FT_New_Memory_Face(m_FTLibrary, db->udata, db->length, 0, &m_FTFace))
+ {
+ s_FontError = "Create freetype face error.";
+ throw FontException(s_FontError.c_str());
+ }
+}
+
+Font::Font(DataBuffer* db, LuaBind::VM* vm, std::string path, TextGeneratingSettings settings)
+ : LuaBind::NativeClass<Font>(vm)
+{
+ m_AtlasMargin = settings.margin;
+ m_GlyphPadding = settings.padding;
+ m_AtlasSize = settings.atlasSize;
+
+ if (FT_Init_FreeType(&m_FTLibrary))
+ {
+ s_FontError = "Init freetype error.";
+ throw FontException(s_FontError.c_str());
+ }
+
+ if (FT_New_Memory_Face(m_FTLibrary, db->udata, db->length, 0, &m_FTFace))
+ {
+ s_FontError = "Create freetype face error.";
+ throw FontException(s_FontError.c_str());
+ }
}
character::Hash Font::GetHash(Codepoint codepoint, int pixelSize)