aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics/font.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules/graphics/font.cpp')
-rw-r--r--src/lua/modules/graphics/font.cpp42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/lua/modules/graphics/font.cpp b/src/lua/modules/graphics/font.cpp
index 042eb19..15aa04e 100644
--- a/src/lua/modules/graphics/font.cpp
+++ b/src/lua/modules/graphics/font.cpp
@@ -19,25 +19,37 @@ namespace lua
return 0;
}
- static int l_box(lua_State* L)
+ static int l_typeset(lua_State* L)
{
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_FONT, sizeof(Proxy));
- FontRef ref = proxy->getRef<Font>();
- const char* text = luax_checkstring(L, 2);
- int fheight = luax_checknumber(L, 3);
- int spacing = luax_checknumber(L, 4);
- int lheight = luax_checknumber(L, 5);
- int w, h;
- ref->box(text, fheight, lheight, spacing, &w, &h);
- luax_pushnumber(L, w);
- luax_pushnumber(L, h);
- return 2;
+ Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_FONT);
+ const char* text = luax_checkstring(L, 2);
+ int lineheight = luax_checkinteger(L, 3);
+ int spacing = luax_checkinteger(L, 4);
+ Ref<Font>& refFont = p->getRef<Font>();
+ Font* font = refFont.getObject();
+ Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_PAGE, sizeof(Proxy));
+ Page* page = font->typeset(text, lineheight, spacing);
+ proxy->bind(new Ref<Page>(page, JIN_GRAPHICS_PAGE));
+ return 1;
+ }
+
+ static int l_print(lua_State* L)
+ {
+ 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);
+ return 0;
}
static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "box", l_box },
- { 0, 0 }
+ { "__gc", l_gc },
+ { "typeset", l_typeset },
+ { "print", l_print },
+ { 0, 0 }
};
int luaopen_Font(lua_State* L)