summaryrefslogtreecommitdiff
path: root/lib/LuaFTGL.cc
blob: f9be9d533273b2188b79d3412d73c6a1226252e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#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_UBBOX,
    FTFONT_ADVANCE,
    FTFONT_UADVANCE,
    FTFONT_RENDER,
    FTFONT_URENDER,
    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, { BLUA_NUMBER } },
    { FTFONT_CHARMAPCOUNT,   "CharMapCount",   0, 0, { } },
    { FTFONT_CHARMAPLIST,    "CharMapList",    0, 0, { } },
    { FTFONT_FACESIZE,       "FaceSize",       0, 2, { BLUA_NUMBER, BLUA_NUMBER } },
    { FTFONT_DEPTH,          "Depth",          1, 1, { BLUA_NUMBER } },
    { FTFONT_USEDISPLAYLIST, "UseDisplayList", 1, 1, { BLUA_BOOLEAN } },
    { FTFONT_ASCENDER,       "Ascender",       0, 0, { } },
    { FTFONT_DESCENDER,      "Descender",      0, 0, { } },
    { FTFONT_LINEHEIGHT,     "LineHeight",     0, 0, { } },
    { FTFONT_BBOX,           "BBox",           1, 1, { BLUA_STRING } },
    { FTFONT_UBBOX,          "UBBox",          1, 1, { BLUA_STRING } },
    { FTFONT_ADVANCE,        "Advance",        1, 1, { BLUA_STRING } },
    { FTFONT_UADVANCE,       "UAdvance",       1, 1, { BLUA_STRING } },
    { FTFONT_RENDER,         "Render",         1, 1, { BLUA_STRING } },
    { FTFONT_URENDER,        "URender",        1, 1, { BLUA_STRING } },
    { FTFONT_ERROR,          "Error",          0, 0, { } },
    { -1, 0, 0, 0, 0 }
};

struct lua_functypes_t EncapFTFont_functions[] = {
    { FTFONT_NEWEXTRD,       "NewExtrdFont",   1, 1, { BLUA_OBJECT | BLUA_STRING } },
    { FTFONT_NEWOUTLINE,     "NewOutlineFont", 1, 1, { BLUA_OBJECT | BLUA_STRING } },
    { FTFONT_NEWPOLYGON,     "NewPolygonFont", 1, 1, { BLUA_OBJECT | BLUA_STRING } },
    { FTFONT_NEWTEXTURE,     "NewTextureFont", 1, 1, { BLUA_OBJECT | BLUA_STRING } },
    { FTFONT_NEWPIXMAP,      "NewPixmapFont",  1, 1, { BLUA_OBJECT | BLUA_STRING } },
    { FTFONT_NEWBITMAP,      "NewBitmapFont",  1, 1, { BLUA_OBJECT | BLUA_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_UBBOX);
    DECLARE_METHOD(EncapFTFont, FTFONT_ADVANCE);
    DECLARE_METHOD(EncapFTFont, FTFONT_UADVANCE);
    DECLARE_METHOD(EncapFTFont, FTFONT_RENDER);
    DECLARE_METHOD(EncapFTFont, FTFONT_URENDER);
    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_UBBOX);
    PUSH_METHOD(EncapFTFont, FTFONT_ADVANCE);
    PUSH_METHOD(EncapFTFont, FTFONT_UADVANCE);
    PUSH_METHOD(EncapFTFont, FTFONT_RENDER);
    PUSH_METHOD(EncapFTFont, FTFONT_URENDER);
    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;
    String x;

    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_UBBOX:
        r = 6;
        x = L->tostring(2);
        x.iconv("utf-8", "utf-32");
        f->BBox(((wchar_t *) x.to_charp()) + 1, 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_UADVANCE:
        r = 1;
        x = L->tostring(2);
        x.iconv("utf-8", "utf-32");
        L->push(f->Advance(((wchar_t *) x.to_charp()) + 1));
        break;
    case FTFONT_RENDER:
        f->Render(L->tostring(2).to_charp());
        break;
    case FTFONT_URENDER:
        x = L->tostring(2);
        x.iconv("utf-8", "utf-32");
        f->Render(((wchar_t *) x.to_charp()) + 1);
        break;
    case FTFONT_ERROR:
        r = 1;
        L->push((lua_Number) f->Error());
        break;
    }
    
    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;
}