aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-08 20:10:35 +0800
committerchai <chaifix@163.com>2018-10-08 20:10:35 +0800
commit1e9bdd854c89c32fa09016871d9693976fc9a08b (patch)
tree89f2824c37a6a46aaceebdceb3452a94f76f1f86
parent5c776ff6676ea2ca418bb5ec709ca729ef3bc435 (diff)
*增加直接打印文字
-rw-r--r--src/libjin/Graphics/Font.cpp6
-rw-r--r--src/libjin/Graphics/Font.h1
-rw-r--r--src/lua/modules/graphics/font.cpp26
3 files changed, 21 insertions, 12 deletions
diff --git a/src/libjin/Graphics/Font.cpp b/src/libjin/Graphics/Font.cpp
index 77d48f7..3e18359 100644
--- a/src/libjin/Graphics/Font.cpp
+++ b/src/libjin/Graphics/Font.cpp
@@ -65,12 +65,6 @@ namespace graphics
return font;
}
- void Font::destroyFont(Font* font)
- {
- if (font != nullptr)
- delete font;
- }
-
Font::Font(FontData* f, unsigned int fontSize)
: cursor(0, 0)
, font(f)
diff --git a/src/libjin/Graphics/Font.h b/src/libjin/Graphics/Font.h
index 2bd51a5..0cb07de 100644
--- a/src/libjin/Graphics/Font.h
+++ b/src/libjin/Graphics/Font.h
@@ -53,7 +53,6 @@ namespace graphics
typedef unsigned int Codepoint;
static Font* createFont(FontData* fontData, unsigned int fontSzie);
- static void destroyFont(Font* font);
Page* typeset(const char* text, int lineheight, int spacing);
void print(const char* text, int x, int y, int lineheight, int spacing = 0);
diff --git a/src/lua/modules/graphics/font.cpp b/src/lua/modules/graphics/font.cpp
index 15aa04e..0b0e1a0 100644
--- a/src/lua/modules/graphics/font.cpp
+++ b/src/lua/modules/graphics/font.cpp
@@ -37,11 +37,27 @@ namespace lua
{
Proxy* pFont = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_FONT);
Font* font = pFont->getObject<Font>();
- Proxy* p = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_PAGE);
- Page* page = p->getObject<Page>();
- int x = luax_checkinteger(L, 3);
- int y = luax_checkinteger(L, 4);
- font->print(page, x, y);
+ if (luax_istype(L, 2, JIN_GRAPHICS_PAGE))
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_PAGE);
+ Page* page = p->getObject<Page>();
+ int x = luax_checkinteger(L, 3);
+ int y = luax_checkinteger(L, 4);
+ font->print(page, x, y);
+ }
+ else if (luax_isstring(L, 2))
+ {
+ const char* text = luax_checkstring(L, 2);
+ int x = luax_checkinteger(L, 3);
+ int y = luax_checkinteger(L, 4);
+ int lh = luax_checkinteger(L, 5);
+ int sp = luax_checkinteger(L, 6);
+ font->print(text, x, y, lh, sp);
+ }
+ else
+ {
+ luax_typerror(L, 2, "font or string");
+ }
return 0;
}