summaryrefslogtreecommitdiff
path: root/Runtime/Scripting/GUI/Font.bind.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Scripting/GUI/Font.bind.cpp')
-rw-r--r--Runtime/Scripting/GUI/Font.bind.cpp53
1 files changed, 48 insertions, 5 deletions
diff --git a/Runtime/Scripting/GUI/Font.bind.cpp b/Runtime/Scripting/GUI/Font.bind.cpp
index 73fb7e6..8259a60 100644
--- a/Runtime/Scripting/GUI/Font.bind.cpp
+++ b/Runtime/Scripting/GUI/Font.bind.cpp
@@ -3,12 +3,21 @@
#include "Runtime/Debug/Log.h"
#include "Runtime/Graphics/GfxDevice.h"
#include "Runtime/Common/DataBuffer.h"
+#include "Runtime/GUI/utf8.h"
+#include "Runtime/Utilities/StaticInitiator.h"
+
+static std::vector<character::Codepoint>* s_Codepoints;
+
+InitializeStaticVariables([](){
+ s_Codepoints = new std::vector<character::Codepoint>();
+});
LUA_BIND_REGISTRY(Font)
{
LUA_BIND_REGISTER_METHODS(state,
{ "New", _New },
{ "GetCharacter", _GetCharacter },
+ { "GetCharacters", _GetCharacters },
{ "GetGlyphAtlas", _GetGlyphAtlas }
);
}
@@ -33,7 +42,7 @@ LUA_BIND_IMPL_METHOD(Font, _New)
setting.margin = state.GetValue<int>(3, 0);
setting.padding = state.GetValue<int>(4, 0);
try {
- font = new Font(path, setting);
+ font = new Font(state.GetVM(), path, setting);
}
catch (FontException& e)
{
@@ -56,7 +65,7 @@ LUA_BIND_IMPL_METHOD(Font, _New)
setting.margin = state.GetValue<int>(3, 0);
setting.padding = state.GetValue<int>(4, 0);
try {
- font = new Font(buffer, setting);
+ font = new Font(state.GetVM(), buffer, setting);
}
catch (FontException& e)
{
@@ -75,7 +84,6 @@ LUA_BIND_IMPL_METHOD(Font, _New)
LUA_BIND_IMPL_METHOD(Font, _GetCharacter)
{
LUA_BIND_PREPARE(L, Font);
-// Character character = self->GetCharacter(character);
return 1;
}
@@ -83,8 +91,43 @@ LUA_BIND_IMPL_METHOD(Font, _GetCharacter)
LUA_BIND_IMPL_METHOD(Font, _GetCharacters)
{
LUA_BIND_PREPARE(L, Font);
-// Character character = self->GetCharacter(character);
- return 1;
+ LUA_BIND_CHECK(L, "USN*");
+
+ char* buf = (char*)state.GetValue<const char*>(2, "");
+ int size = state.GetValue<int>(3, 12);
+ int encoding = state.GetValue<int>(4, EEncoding::Encoding_UTF8);
+
+ s_Codepoints->clear();
+ if (encoding == EEncoding::Encoding_UTF8)
+ {
+ while (*buf != 0) {
+ int err;
+ s_Codepoints->push_back(utf8::getu8c(&buf, &err));
+ if (err != 0)
+ {
+ log_warning("Illegal utf8 bytes %d", err);
+ }
+ }
+ }
+ else if (encoding == EEncoding::Encoding_UTF16)
+ {
+ while (*buf != 0) {
+ unsigned short* s = (unsigned short*)(buf);
+ s_Codepoints->push_back(*s);
+ buf += 2;
+ }
+ }
+ else if (encoding == EEncoding::Encoding_ASCII)
+ {
+ while (*buf != 0) {
+ s_Codepoints->push_back(*buf);
+ buf += 1;
+ }
+ }
+
+ self->RenderCharacters(*s_Codepoints, size);
+
+ return 0;
}
// font:GetAtlas(i)