summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2007-06-23 14:28:18 +0000
committerpixel <pixel>2007-06-23 14:28:18 +0000
commitf105764b8c77364608cb5a60c81aab7af414b60a (patch)
treed8eedf4b6ac6f04b70af44a657a9eefa47543505
parentcda8e426f609530062524bb43f103612d25cacc7 (diff)
Adding FTGL support.
-rw-r--r--include/LuaFTGL.h69
-rw-r--r--lib/LuaFTGL.cc285
2 files changed, 354 insertions, 0 deletions
diff --git a/include/LuaFTGL.h b/include/LuaFTGL.h
new file mode 100644
index 0000000..48a3016
--- /dev/null
+++ b/include/LuaFTGL.h
@@ -0,0 +1,69 @@
+#ifndef __LUAFTGL_H__
+#define __LUAFTGL_H__
+
+#include <FTGLExtrdFont.h>
+#include <FTGLOutlineFont.h>
+#include <FTGLPolygonFont.h>
+#include <FTGLTextureFont.h>
+#include <FTGLPixmapFont.h>
+#include <FTGLBitmapFont.h>
+
+#include <Exceptions.h>
+#include <BLua.h>
+
+class EncapFTFont : public Base {
+ public:
+ EncapFTFont(FTFont * _f) : f(_f) { }
+ ~EncapFTFont() { delete f; }
+ FTFont * Get() { return f; }
+ private:
+ FTFont * f;
+};
+
+class EncapFTGLExtrdFont : public EncapFTFont {
+ public:
+ EncapFTGLExtrdFont(const char * path) : EncapFTFont(new FTGLExtrdFont(path)) { }
+ EncapFTGLExtrdFont(const unsigned char * buff, size_t siz) : EncapFTFont(new FTGLExtrdFont(buff, siz)) { }
+};
+
+class EncapFTGLOutlineFont : public EncapFTFont {
+ public:
+ EncapFTGLOutlineFont(const char * path) : EncapFTFont(new FTGLOutlineFont(path)) { }
+ EncapFTGLOutlineFont(const unsigned char * buff, size_t siz) : EncapFTFont(new FTGLOutlineFont(buff, siz)) { }
+};
+
+class EncapFTGLPolygonFont : public EncapFTFont {
+ public:
+ EncapFTGLPolygonFont(const char * path) : EncapFTFont(new FTGLPolygonFont(path)) { }
+ EncapFTGLPolygonFont(const unsigned char * buff, size_t siz) : EncapFTFont(new FTGLPolygonFont(buff, siz)) { }
+};
+
+class EncapFTGLTextureFont : public EncapFTFont {
+ public:
+ EncapFTGLTextureFont(const char * path) : EncapFTFont(new FTGLTextureFont(path)) { }
+ EncapFTGLTextureFont(const unsigned char * buff, size_t siz) : EncapFTFont(new FTGLTextureFont(buff, siz)) { }
+};
+
+class EncapFTGLPixmapFont : public EncapFTFont {
+ public:
+ EncapFTGLPixmapFont(const char * path) : EncapFTFont(new FTGLPixmapFont(path)) { }
+ EncapFTGLPixmapFont(const unsigned char * buff, size_t siz) : EncapFTFont(new FTGLPixmapFont(buff, siz)) { }
+};
+
+class EncapFTGLBitmapFont : public EncapFTFont {
+ public:
+ EncapFTGLBitmapFont(const char * path) : EncapFTFont(new FTGLBitmapFont(path)) { }
+ EncapFTGLBitmapFont(const unsigned char * buff, size_t siz) : EncapFTFont(new FTGLBitmapFont(buff, siz)) { }
+};
+
+class LuaFTFont : public LuaObject {
+ public:
+ static void pushstatics(Lua *) throw (GeneralException);
+ LuaFTFont(EncapFTFont * _f) : f(_f) { }
+ ~LuaFTFont() { }
+ private:
+ virtual void pushmembers(Lua *);
+ EncapFTFont * f;
+};
+
+#endif
diff --git a/lib/LuaFTGL.cc b/lib/LuaFTGL.cc
new file mode 100644
index 0000000..851ccb3
--- /dev/null
+++ b/lib/LuaFTGL.cc
@@ -0,0 +1,285 @@
+#include "LuaFTGL.h"
+
+#include <Handle.h>
+#include <Buffer.h>
+
+#define export_enum(L, n) \
+ L->push(#n); \
+ L->push((lua_Number) n); \
+ L->settable(LUA_GLOBALSINDEX);
+
+enum EncapFTFont_methods_t {
+ FTFONT_CHARMAP = 0,
+ FTFONT_CHARMAPCOUNT,
+ FTFONT_CHARMAPLIST,
+ FTFONT_FACESIZE,
+ FTFONT_DEPTH,
+ FTFONT_USEDISPLAYLIST,
+ FTFONT_ASCENDER,
+ FTFONT_DESCENDER,
+ FTFONT_LINEHEIGHT,
+ FTFONT_BBOX,
+ FTFONT_ADVANCE,
+ FTFONT_RENDER,
+ FTFONT_ERROR,
+};
+
+enum EncapFTFont_functions_t {
+ FTFONT_NEWEXTRD = 0,
+ FTFONT_NEWOUTLINE,
+ FTFONT_NEWPOLYGON,
+ FTFONT_NEWTEXTURE,
+ FTFONT_NEWPIXMAP,
+ FTFONT_NEWBITMAP,
+};
+
+struct lua_functypes_t EncapFTFont_methods[] = {
+ { FTFONT_CHARMAP, "CharMap", 1, 1, { LUA_NUMBER } },
+ { FTFONT_CHARMAPCOUNT, "CharMapCount", 0, 0, { } },
+ { FTFONT_CHARMAPLIST, "CharMapList", 0, 0, { } },
+ { FTFONT_FACESIZE, "FaceSize", 0, 2, { LUA_NUMBER, LUA_NUMBER } },
+ { FTFONT_DEPTH, "Depth", 1, 1, { LUA_NUMBER } },
+ { FTFONT_USEDISPLAYLIST, "UseDisplayList", 1, 1, { LUA_BOOLEAN } },
+ { FTFONT_ASCENDER, "Ascender", 0, 0, { } },
+ { FTFONT_DESCENDER, "Descender", 0, 0, { } },
+ { FTFONT_LINEHEIGHT, "LineHeight", 0, 0, { } },
+ { FTFONT_BBOX, "BBox", 1, 1, { LUA_STRING } },
+ { FTFONT_ADVANCE, "Advance", 1, 1, { LUA_STRING } },
+ { FTFONT_RENDER, "Render", 1, 1, { LUA_STRING } },
+ { FTFONT_ERROR, "Error", 0, 0, { } },
+ { -1, 0, 0, 0, 0 }
+};
+
+struct lua_functypes_t EncapFTFont_functions[] = {
+ { FTFONT_NEWEXTRD, "NewExtrdFont", 1, 1, { LUA_OBJECT | LUA_STRING } },
+ { FTFONT_NEWOUTLINE, "NewOutlineFont", 1, 1, { LUA_OBJECT | LUA_STRING } },
+ { FTFONT_NEWPOLYGON, "NewPolygonFont", 1, 1, { LUA_OBJECT | LUA_STRING } },
+ { FTFONT_NEWTEXTURE, "NewTextureFont", 1, 1, { LUA_OBJECT | LUA_STRING } },
+ { FTFONT_NEWPIXMAP, "NewPixmapFont", 1, 1, { LUA_OBJECT | LUA_STRING } },
+ { FTFONT_NEWBITMAP, "NewBitmapFont", 1, 1, { LUA_OBJECT | LUA_STRING } },
+ { -1, 0, 0, 0, 0 }
+};
+
+class sLua_EncapFTFont : public Base {
+ public:
+ DECLARE_METHOD(EncapFTFont, FTFONT_CHARMAP);
+ DECLARE_METHOD(EncapFTFont, FTFONT_CHARMAPCOUNT);
+ DECLARE_METHOD(EncapFTFont, FTFONT_CHARMAPLIST);
+ DECLARE_METHOD(EncapFTFont, FTFONT_FACESIZE);
+ DECLARE_METHOD(EncapFTFont, FTFONT_DEPTH);
+ DECLARE_METHOD(EncapFTFont, FTFONT_USEDISPLAYLIST);
+ DECLARE_METHOD(EncapFTFont, FTFONT_ASCENDER);
+ DECLARE_METHOD(EncapFTFont, FTFONT_DESCENDER);
+ DECLARE_METHOD(EncapFTFont, FTFONT_LINEHEIGHT);
+ DECLARE_METHOD(EncapFTFont, FTFONT_BBOX);
+ DECLARE_METHOD(EncapFTFont, FTFONT_ADVANCE);
+ DECLARE_METHOD(EncapFTFont, FTFONT_RENDER);
+ DECLARE_METHOD(EncapFTFont, FTFONT_ERROR);
+
+ DECLARE_FUNCTION(EncapFTFont, FTFONT_NEWEXTRD);
+ DECLARE_FUNCTION(EncapFTFont, FTFONT_NEWOUTLINE);
+ DECLARE_FUNCTION(EncapFTFont, FTFONT_NEWPOLYGON);
+ DECLARE_FUNCTION(EncapFTFont, FTFONT_NEWTEXTURE);
+ DECLARE_FUNCTION(EncapFTFont, FTFONT_NEWPIXMAP);
+ DECLARE_FUNCTION(EncapFTFont, FTFONT_NEWBITMAP);
+ private:
+ static int EncapFTFont_proceed(Lua * L, int n, EncapFTFont * obj, int caller);
+ static int EncapFTFont_proceed_statics(Lua * L, int n, int caller);
+};
+
+void LuaFTFont::pushmembers(Lua * L) {
+ pushme(L, f, "FTFont");
+
+ PUSH_METHOD(EncapFTFont, FTFONT_CHARMAP);
+ PUSH_METHOD(EncapFTFont, FTFONT_CHARMAPCOUNT);
+ PUSH_METHOD(EncapFTFont, FTFONT_CHARMAPLIST);
+ PUSH_METHOD(EncapFTFont, FTFONT_FACESIZE);
+ PUSH_METHOD(EncapFTFont, FTFONT_DEPTH);
+ PUSH_METHOD(EncapFTFont, FTFONT_USEDISPLAYLIST);
+ PUSH_METHOD(EncapFTFont, FTFONT_ASCENDER);
+ PUSH_METHOD(EncapFTFont, FTFONT_DESCENDER);
+ PUSH_METHOD(EncapFTFont, FTFONT_LINEHEIGHT);
+ PUSH_METHOD(EncapFTFont, FTFONT_BBOX);
+ PUSH_METHOD(EncapFTFont, FTFONT_ADVANCE);
+ PUSH_METHOD(EncapFTFont, FTFONT_RENDER);
+ PUSH_METHOD(EncapFTFont, FTFONT_ERROR);
+}
+
+void LuaFTFont::pushstatics(Lua * L) throw (GeneralException) {
+ CHECK_METHODS(EncapFTFont);
+ CHECK_FUNCTIONS(EncapFTFont);
+
+ PUSH_FUNCTION(EncapFTFont, FTFONT_NEWEXTRD);
+ PUSH_FUNCTION(EncapFTFont, FTFONT_NEWOUTLINE);
+ PUSH_FUNCTION(EncapFTFont, FTFONT_NEWPOLYGON);
+ PUSH_FUNCTION(EncapFTFont, FTFONT_NEWTEXTURE);
+ PUSH_FUNCTION(EncapFTFont, FTFONT_NEWPIXMAP);
+ PUSH_FUNCTION(EncapFTFont, FTFONT_NEWBITMAP);
+
+ export_enum(L, FT_ENCODING_NONE);
+ export_enum(L, FT_ENCODING_MS_SYMBOL);
+ export_enum(L, FT_ENCODING_UNICODE);
+ export_enum(L, FT_ENCODING_SJIS);
+ export_enum(L, FT_ENCODING_GB2312);
+ export_enum(L, FT_ENCODING_BIG5);
+ export_enum(L, FT_ENCODING_WANSUNG);
+ export_enum(L, FT_ENCODING_JOHAB);
+ export_enum(L, FT_ENCODING_MS_SJIS);
+ export_enum(L, FT_ENCODING_MS_GB2312);
+ export_enum(L, FT_ENCODING_MS_BIG5);
+ export_enum(L, FT_ENCODING_MS_WANSUNG);
+ export_enum(L, FT_ENCODING_MS_JOHAB);
+ export_enum(L, FT_ENCODING_ADOBE_STANDARD);
+ export_enum(L, FT_ENCODING_ADOBE_EXPERT);
+ export_enum(L, FT_ENCODING_ADOBE_CUSTOM);
+ export_enum(L, FT_ENCODING_ADOBE_LATIN_1);
+ export_enum(L, FT_ENCODING_OLD_LATIN_2);
+ export_enum(L, FT_ENCODING_APPLE_ROMAN);
+}
+
+int sLua_EncapFTFont::EncapFTFont_proceed(Lua * L, int n, EncapFTFont * obj, int caller) {
+ int r = 0;
+ int i;
+ FTFont * f = obj->Get();
+ FT_Encoding * l;
+ float llx, lly, llz, urx, ury, urz;
+
+ switch (caller) {
+ case FTFONT_CHARMAP:
+ L->push(f->CharMap(FT_Encoding(L->tonumber(2))));
+ r = 1;
+ break;
+ case FTFONT_CHARMAPCOUNT:
+ L->push((lua_Number) f->CharMapCount());
+ r = 1;
+ break;
+ case FTFONT_CHARMAPLIST:
+ L->newtable();
+ r = 1;
+ l = f->CharMapList();
+ for (i = 0; i < f->CharMapCount(); i++) {
+ L->push((lua_Number) i + 1);
+ L->push((lua_Number) l[i]);
+ L->settable();
+ }
+ break;
+ case FTFONT_FACESIZE:
+ r = 1;
+ if (n == 0) {
+ L->push((lua_Number) f->FaceSize());
+ } else {
+ unsigned int size = L->tonumber(2);
+ if (n == 1) {
+ L->push(f->FaceSize(size));
+ } else {
+ unsigned int res = L->tonumber(3);
+ L->push(f->FaceSize(size, res));
+ }
+ }
+ break;
+ case FTFONT_DEPTH:
+ f->Depth(L->tonumber(2));
+ break;
+ case FTFONT_USEDISPLAYLIST:
+ f->UseDisplayList(L->toboolean(2));
+ break;
+ case FTFONT_ASCENDER:
+ r = 1;
+ L->push(f->Ascender());
+ break;
+ case FTFONT_DESCENDER:
+ r = 1;
+ L->push(f->Descender());
+ break;
+ case FTFONT_LINEHEIGHT:
+ r = 1;
+ L->push(f->LineHeight());
+ break;
+ case FTFONT_BBOX:
+ r = 6;
+ f->BBox(L->tostring(2).to_charp(), llx, lly, llz, urx, ury, urz);
+ L->push(llx);
+ L->push(lly);
+ L->push(llz);
+ L->push(urx);
+ L->push(ury);
+ L->push(urz);
+ break;
+ case FTFONT_ADVANCE:
+ r = 1;
+ L->push(f->Advance(L->tostring(2).to_charp()));
+ break;
+ case FTFONT_RENDER:
+ f->Render(L->tostring(2).to_charp());
+ break;
+ case FTFONT_ERROR:
+ r = 0;
+ }
+
+ return r;
+}
+
+int sLua_EncapFTFont::EncapFTFont_proceed_statics(Lua * L, int n, int caller) {
+ Handle * h = 0;
+ Buffer * b = 0;
+ bool has_to_delete = false;
+ EncapFTFont * f;
+
+ if (L->isobject(1)) {
+ h = (Handle *) LuaObject::getme(L);
+ b = dynamic_cast<Buffer *>(h);
+ if (!b) {
+ b = new Buffer();
+ b->copyfrom(h);
+ has_to_delete = true;
+ }
+ switch (caller) {
+ case FTFONT_NEWEXTRD:
+ f = new EncapFTGLExtrdFont(b->GetBuffer(), b->GetSize());
+ break;
+ case FTFONT_NEWOUTLINE:
+ f = new EncapFTGLOutlineFont(b->GetBuffer(), b->GetSize());
+ break;
+ case FTFONT_NEWPOLYGON:
+ f = new EncapFTGLPolygonFont(b->GetBuffer(), b->GetSize());
+ break;
+ case FTFONT_NEWTEXTURE:
+ f = new EncapFTGLTextureFont(b->GetBuffer(), b->GetSize());
+ break;
+ case FTFONT_NEWPIXMAP:
+ f = new EncapFTGLPixmapFont(b->GetBuffer(), b->GetSize());
+ break;
+ case FTFONT_NEWBITMAP:
+ f = new EncapFTGLBitmapFont(b->GetBuffer(), b->GetSize());
+ break;
+ }
+ if (has_to_delete)
+ delete b;
+ } else {
+ switch (caller) {
+ case FTFONT_NEWEXTRD:
+ f = new EncapFTGLExtrdFont(L->tostring(1).to_charp());
+ break;
+ case FTFONT_NEWOUTLINE:
+ f = new EncapFTGLOutlineFont(L->tostring(1).to_charp());
+ break;
+ case FTFONT_NEWPOLYGON:
+ f = new EncapFTGLPolygonFont(L->tostring(1).to_charp());
+ break;
+ case FTFONT_NEWTEXTURE:
+ f = new EncapFTGLTextureFont(L->tostring(1).to_charp());
+ break;
+ case FTFONT_NEWPIXMAP:
+ f = new EncapFTGLPixmapFont(L->tostring(1).to_charp());
+ break;
+ case FTFONT_NEWBITMAP:
+ f = new EncapFTGLBitmapFont(L->tostring(1).to_charp());
+ break;
+ }
+ }
+
+ LuaFTFont lf(f);
+ lf.pushdestruct(L);
+
+ return 1;
+}