sq_freetype.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. #ifdef SQ_USE_FREETYPE
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include "squirrel.h"
  5. #include "sqstdblobimpl.h"
  6. #include <ft2build.h>
  7. #include FT_FREETYPE_H
  8. #include "dynamic_library.h"
  9. /*SquiLu
  10. local library_functions = [
  11. ["FT_Error", "FT_Init_FreeType", "FT_Library *library"],
  12. ["FT_Error", "FT_New_Face", "FT_Library library, const char* filepathname, FT_Long face_index, FT_Face *aface"],
  13. ["FT_Error", "FT_New_Memory_Face", "FT_Library library, const FT_Byte* file_base, FT_Long file_size, FT_Long face_index, FT_Face *aface"],
  14. ["FT_Error", "FT_Done_Face", "FT_Face face"],
  15. ["FT_Error", "FT_Set_Char_Size", "FT_Face face, FT_F26Dot6 char_width, FT_F26Dot6 char_height, FT_UInt horz_resolution, FT_UInt vert_resolution"],
  16. ["FT_Error", "FT_Load_Glyph", "FT_Face face, FT_UInt glyph_index, FT_Int32 load_flags"],
  17. ["FT_Error", "FT_Load_Char", "FT_Face face, FT_ULong char_code, FT_Int32 load_flags"],
  18. ["FT_Error", "FT_Get_Glyph_Name", "FT_Face face, FT_UInt glyph_index, FT_Pointer buffer, FT_UInt buffer_max"],
  19. ["const char*", "FT_Get_Postscript_Name", "FT_Face face"],
  20. ["FT_Error", "FT_Select_Charmap", "FT_Face face, FT_Encoding encoding"],
  21. ["FT_Error", "FT_Set_Charmap", "FT_Face face, FT_CharMap charmap"],
  22. ["FT_Int", "FT_Get_Charmap_Index", "FT_CharMap charmap"],
  23. ["FT_UInt", "FT_Get_Char_Index", "FT_Face face, FT_ULong charcode"],
  24. ["FT_ULong", "FT_Get_First_Char", "FT_Face face, FT_UInt *agindex"],
  25. ["FT_ULong", "FT_Get_Next_Char", "FT_Face face, FT_ULong char_code, FT_UInt *agindex"],
  26. ["FT_UInt", "FT_Get_Name_Index", "FT_Face face, FT_String* glyph_name"],
  27. //next entry should be the last one
  28. //to make valid the test made on load_library function
  29. ["FT_Error", "FT_Done_FreeType", "FT_Library library"],
  30. ];
  31. function write_library_functions_declaration(){
  32. foreach(k,v in library_functions) {
  33. putsnl("typedef " + v[0] + " (*" + v[1] + "_t)(" + v[2] + ");");
  34. putsnl("static " + v[1] + "_t dl" + v[1] + " = 0;");
  35. }
  36. }
  37. function write_library_functions_load(){
  38. foreach(k,v in library_functions){
  39. putsnl("dl" + v[1] + " = (" + v[1] + "_t) libdyn.dlsym(\"" + v[1] + "\");");
  40. putsnl("if(!dl" + v[1] + ") return false;");
  41. }
  42. }
  43. function write_library_functions_static_defines(){
  44. foreach(k,v in library_functions){
  45. putsnl("#define dl" + v[1] + " " + v[1]);
  46. }
  47. }
  48. SquiLu*/
  49. static DynamicLibrary libdyn;
  50. //@write_library_functions_declaration();
  51. // generated-code:begin
  52. typedef FT_Error (*FT_Init_FreeType_t)(FT_Library *library);
  53. static FT_Init_FreeType_t dlFT_Init_FreeType = 0;
  54. typedef FT_Error (*FT_New_Face_t)(FT_Library library, const char* filepathname, FT_Long face_index, FT_Face *aface);
  55. static FT_New_Face_t dlFT_New_Face = 0;
  56. typedef FT_Error (*FT_New_Memory_Face_t)(FT_Library library, const FT_Byte* file_base, FT_Long file_size, FT_Long face_index, FT_Face *aface);
  57. static FT_New_Memory_Face_t dlFT_New_Memory_Face = 0;
  58. typedef FT_Error (*FT_Done_Face_t)(FT_Face face);
  59. static FT_Done_Face_t dlFT_Done_Face = 0;
  60. typedef FT_Error (*FT_Set_Char_Size_t)(FT_Face face, FT_F26Dot6 char_width, FT_F26Dot6 char_height, FT_UInt horz_resolution, FT_UInt vert_resolution);
  61. static FT_Set_Char_Size_t dlFT_Set_Char_Size = 0;
  62. typedef FT_Error (*FT_Load_Glyph_t)(FT_Face face, FT_UInt glyph_index, FT_Int32 load_flags);
  63. static FT_Load_Glyph_t dlFT_Load_Glyph = 0;
  64. typedef FT_Error (*FT_Load_Char_t)(FT_Face face, FT_ULong char_code, FT_Int32 load_flags);
  65. static FT_Load_Char_t dlFT_Load_Char = 0;
  66. typedef FT_Error (*FT_Get_Glyph_Name_t)(FT_Face face, FT_UInt glyph_index, FT_Pointer buffer, FT_UInt buffer_max);
  67. static FT_Get_Glyph_Name_t dlFT_Get_Glyph_Name = 0;
  68. typedef const char* (*FT_Get_Postscript_Name_t)(FT_Face face);
  69. static FT_Get_Postscript_Name_t dlFT_Get_Postscript_Name = 0;
  70. typedef FT_Error (*FT_Select_Charmap_t)(FT_Face face, FT_Encoding encoding);
  71. static FT_Select_Charmap_t dlFT_Select_Charmap = 0;
  72. typedef FT_Error (*FT_Set_Charmap_t)(FT_Face face, FT_CharMap charmap);
  73. static FT_Set_Charmap_t dlFT_Set_Charmap = 0;
  74. typedef FT_Int (*FT_Get_Charmap_Index_t)(FT_CharMap charmap);
  75. static FT_Get_Charmap_Index_t dlFT_Get_Charmap_Index = 0;
  76. typedef FT_UInt (*FT_Get_Char_Index_t)(FT_Face face, FT_ULong charcode);
  77. static FT_Get_Char_Index_t dlFT_Get_Char_Index = 0;
  78. typedef FT_ULong (*FT_Get_First_Char_t)(FT_Face face, FT_UInt *agindex);
  79. static FT_Get_First_Char_t dlFT_Get_First_Char = 0;
  80. typedef FT_ULong (*FT_Get_Next_Char_t)(FT_Face face, FT_ULong char_code, FT_UInt *agindex);
  81. static FT_Get_Next_Char_t dlFT_Get_Next_Char = 0;
  82. typedef FT_UInt (*FT_Get_Name_Index_t)(FT_Face face, FT_String* glyph_name);
  83. static FT_Get_Name_Index_t dlFT_Get_Name_Index = 0;
  84. typedef FT_Error (*FT_Done_FreeType_t)(FT_Library library);
  85. static FT_Done_FreeType_t dlFT_Done_FreeType = 0;
  86. // generated-code:end
  87. static const char *dynamicLibName = DYNLIB_FOR_OS(libfreetype);
  88. static bool load_library(const char *libname)
  89. {
  90. if(dlFT_Done_FreeType) return true;
  91. if(libdyn.open(libname))
  92. {
  93. //@write_library_functions_load();
  94. // generated-code:begin
  95. dlFT_Init_FreeType = (FT_Init_FreeType_t) libdyn.dlsym("FT_Init_FreeType");
  96. if(!dlFT_Init_FreeType) return false;
  97. dlFT_New_Face = (FT_New_Face_t) libdyn.dlsym("FT_New_Face");
  98. if(!dlFT_New_Face) return false;
  99. dlFT_New_Memory_Face = (FT_New_Memory_Face_t) libdyn.dlsym("FT_New_Memory_Face");
  100. if(!dlFT_New_Memory_Face) return false;
  101. dlFT_Done_Face = (FT_Done_Face_t) libdyn.dlsym("FT_Done_Face");
  102. if(!dlFT_Done_Face) return false;
  103. dlFT_Set_Char_Size = (FT_Set_Char_Size_t) libdyn.dlsym("FT_Set_Char_Size");
  104. if(!dlFT_Set_Char_Size) return false;
  105. dlFT_Load_Glyph = (FT_Load_Glyph_t) libdyn.dlsym("FT_Load_Glyph");
  106. if(!dlFT_Load_Glyph) return false;
  107. dlFT_Load_Char = (FT_Load_Char_t) libdyn.dlsym("FT_Load_Char");
  108. if(!dlFT_Load_Char) return false;
  109. dlFT_Get_Glyph_Name = (FT_Get_Glyph_Name_t) libdyn.dlsym("FT_Get_Glyph_Name");
  110. if(!dlFT_Get_Glyph_Name) return false;
  111. dlFT_Get_Postscript_Name = (FT_Get_Postscript_Name_t) libdyn.dlsym("FT_Get_Postscript_Name");
  112. if(!dlFT_Get_Postscript_Name) return false;
  113. dlFT_Select_Charmap = (FT_Select_Charmap_t) libdyn.dlsym("FT_Select_Charmap");
  114. if(!dlFT_Select_Charmap) return false;
  115. dlFT_Set_Charmap = (FT_Set_Charmap_t) libdyn.dlsym("FT_Set_Charmap");
  116. if(!dlFT_Set_Charmap) return false;
  117. dlFT_Get_Charmap_Index = (FT_Get_Charmap_Index_t) libdyn.dlsym("FT_Get_Charmap_Index");
  118. if(!dlFT_Get_Charmap_Index) return false;
  119. dlFT_Get_Char_Index = (FT_Get_Char_Index_t) libdyn.dlsym("FT_Get_Char_Index");
  120. if(!dlFT_Get_Char_Index) return false;
  121. dlFT_Get_First_Char = (FT_Get_First_Char_t) libdyn.dlsym("FT_Get_First_Char");
  122. if(!dlFT_Get_First_Char) return false;
  123. dlFT_Get_Next_Char = (FT_Get_Next_Char_t) libdyn.dlsym("FT_Get_Next_Char");
  124. if(!dlFT_Get_Next_Char) return false;
  125. dlFT_Get_Name_Index = (FT_Get_Name_Index_t) libdyn.dlsym("FT_Get_Name_Index");
  126. if(!dlFT_Get_Name_Index) return false;
  127. dlFT_Done_FreeType = (FT_Done_FreeType_t) libdyn.dlsym("FT_Done_FreeType");
  128. if(!dlFT_Done_FreeType) return false;
  129. // generated-code:end
  130. return true;
  131. }
  132. return false;
  133. }
  134. #undef KLASS_VAR
  135. #define KLASS_VAR(Klass, Var) Klass Var
  136. static const SQChar Freetype_Tag[] = _SC("sqFreetype");
  137. #define GET_freetype_INSTANCE_AT(idx, self) SQ_GET_INSTANCE2(v, idx, self, FT_Library, Freetype_Tag) \
  138. if(self == NULL) return sq_throwerror(v, _SC("sqfreetype object already closed"));
  139. #define GET_freetype_INSTANCE() GET_freetype_INSTANCE_AT(1, self)
  140. static SQRESULT sq_freetype_releasehook(SQUserPointer p, SQInteger /*size*/, void */*ep*/)
  141. {
  142. FT_Library self = ((FT_Library)p);
  143. if(self)
  144. {
  145. dlFT_Done_FreeType(self);
  146. }
  147. return 1;
  148. }
  149. static SQRESULT sq_freetype_constructor(HSQUIRRELVM v)
  150. {
  151. if(!load_library(dynamicLibName)) return sq_throwerror(v, _SC("Failed to load libfreetype !"));
  152. FT_Library library;
  153. FT_Error error = dlFT_Init_FreeType( &library );
  154. if(error)
  155. {
  156. return sq_throwerror(v,_SC("Failed to initialize FreeType library"));
  157. }
  158. sq_setinstanceup(v,1,library);
  159. sq_setreleasehook(v,1,sq_freetype_releasehook);
  160. return 0;
  161. }
  162. static SQRESULT sq_freetype_loadlib(HSQUIRRELVM v)
  163. {
  164. SQ_FUNC_VARS_NO_TOP(v);
  165. SQ_GET_STRING(v, 2, libname);
  166. sq_pushbool(v, load_library(libname));
  167. return 1;
  168. }
  169. #define _DECL_FUNC(name,nparams,tycheck) {_SC(#name),sq_freetype_##name,nparams,tycheck}
  170. static SQRegFunction sq_freetype_methods[] =
  171. {
  172. _DECL_FUNC(constructor,1,_SC(".")),
  173. _DECL_FUNC(loadlib,2,_SC(".s")),
  174. {0,0}
  175. };
  176. #undef _DECL_FUNC
  177. static const SQChar FreetypeFace_Tag[] = _SC("sqFreetypeFace");
  178. #define GET_freetype_face_INSTANCE_AT(idx, self) SQ_GET_INSTANCE2(v, idx, self, FT_Face, FreetypeFace_Tag) \
  179. if(self == NULL) return sq_throwerror(v, _SC("sqFreetypeFace object already closed"));
  180. #define GET_freetype_face_INSTANCE() GET_freetype_face_INSTANCE_AT(1, self)
  181. static SQRESULT sq_freetype_face_releasehook(SQUserPointer p, SQInteger /*size*/, void */*ep*/)
  182. {
  183. FT_Face self = ((FT_Face)p);
  184. if(self)
  185. {
  186. FT_Done_Face(self);
  187. }
  188. return 1;
  189. }
  190. static SQRESULT sq_freetype_face_constructor(HSQUIRRELVM v)
  191. {
  192. if(!load_library(dynamicLibName)) return sq_throwerror(v, _SC("Failed to load libpcre !"));
  193. SQ_FUNC_VARS(v);
  194. GET_freetype_INSTANCE_AT(2, library);
  195. SQ_GET_STRING(v, 3, fname);
  196. SQ_OPT_INTEGER(v, 4, face_index, 0);
  197. SQ_OPT_BOOL(v, 5, isMemory, SQFalse);
  198. FT_Face face;
  199. FT_Error error;
  200. if(isMemory) error = dlFT_New_Memory_Face(library, (const FT_Byte*)fname, fname_size, face_index, &face);
  201. else error = dlFT_New_Face(library, (const char*)fname, face_index, &face);
  202. if(error)
  203. {
  204. return sq_throwerror(v,_SC("Could not create freetype face"));
  205. }
  206. sq_setinstanceup(v,1,face);
  207. sq_setreleasehook(v,1,sq_freetype_face_releasehook);
  208. return 0;
  209. }
  210. static SQRESULT sq_freetype_face_set_char_size(HSQUIRRELVM v)
  211. {
  212. SQ_FUNC_VARS(v);
  213. GET_freetype_face_INSTANCE();
  214. SQ_GET_INTEGER(v, 2, char_width);
  215. SQ_GET_INTEGER(v, 3, char_height);
  216. SQ_OPT_INTEGER(v, 4, horz_resolution, 0);
  217. SQ_OPT_INTEGER(v, 5, vert_resolution, 0);
  218. sq_pushinteger(v, dlFT_Set_Char_Size(self, char_width, char_height, horz_resolution, vert_resolution));
  219. return 1;
  220. }
  221. static SQRESULT sq_freetype_face_load_char_or_glyph(HSQUIRRELVM v, bool onlyGlyph, bool asArray)
  222. {
  223. SQ_FUNC_VARS(v);
  224. GET_freetype_face_INSTANCE();
  225. SQ_GET_INTEGER(v, 2, char_idx);
  226. SQ_OPT_INTEGER(v, 3, load_flags, FT_LOAD_RENDER);
  227. FT_GlyphSlot slot = self->glyph;
  228. FT_Error error;
  229. if(onlyGlyph) error = dlFT_Load_Char(self, char_idx, load_flags);
  230. else error = dlFT_Load_Char(self, char_idx, load_flags);
  231. if(error) sq_pushinteger(v, error);
  232. else
  233. {
  234. if(asArray)
  235. {
  236. sq_newarray(v, 8);
  237. sq_pushstring(v, (const SQChar*)slot->bitmap.buffer,
  238. slot->bitmap.width * slot->bitmap.rows * sizeof (unsigned char));
  239. sq_arrayset(v, -2, 0);
  240. sq_pushinteger(v, slot->bitmap.width);
  241. sq_arrayset(v, -2, 1);
  242. sq_pushinteger(v, slot->bitmap.rows);
  243. sq_arrayset(v, -2, 2);
  244. sq_pushinteger(v, slot->metrics.horiBearingX);
  245. sq_arrayset(v, -2, 3);
  246. sq_pushinteger(v, slot->metrics.horiBearingY);
  247. sq_arrayset(v, -2, 4);
  248. sq_pushinteger(v, slot->metrics.horiAdvance);
  249. sq_arrayset(v, -2, 5);
  250. sq_pushinteger(v, slot->metrics.width);
  251. sq_arrayset(v, -2, 6);
  252. sq_pushinteger(v, slot->metrics.height);
  253. sq_arrayset(v, -2, 7);
  254. }
  255. else sq_pushstring(v, (const SQChar*)slot->bitmap.buffer,
  256. slot->bitmap.width * slot->bitmap.rows * sizeof (unsigned char));
  257. }
  258. return 1;
  259. }
  260. static SQRESULT sq_freetype_face_load_char(HSQUIRRELVM v)
  261. {
  262. return sq_freetype_face_load_char_or_glyph(v, false, false);
  263. }
  264. static SQRESULT sq_freetype_face_load_char2(HSQUIRRELVM v)
  265. {
  266. return sq_freetype_face_load_char_or_glyph(v, false, true);
  267. }
  268. static SQRESULT sq_freetype_face_load_glyph(HSQUIRRELVM v)
  269. {
  270. return sq_freetype_face_load_char_or_glyph(v, true, false);
  271. }
  272. static SQRESULT sq_freetype_face_load_glyph2(HSQUIRRELVM v)
  273. {
  274. return sq_freetype_face_load_char_or_glyph(v, true, true);
  275. }
  276. static SQRESULT sq_freetype_face_char_index(HSQUIRRELVM v)
  277. {
  278. SQ_FUNC_VARS_NO_TOP(v);
  279. GET_freetype_face_INSTANCE();
  280. SQ_GET_INTEGER(v, 2, glyph_idx);
  281. sq_pushinteger(v, dlFT_Get_Char_Index(self, glyph_idx));
  282. return 1;
  283. }
  284. static SQRESULT sq_freetype_face_first_char(HSQUIRRELVM v)
  285. {
  286. SQ_FUNC_VARS_NO_TOP(v);
  287. GET_freetype_face_INSTANCE();
  288. FT_UInt agindex;
  289. FT_ULong charcode = dlFT_Get_First_Char(self, &agindex);
  290. sq_newarray(v, 2);
  291. sq_pushinteger(v, charcode);
  292. sq_arrayset(v, -2, 0);
  293. sq_pushinteger(v, agindex);
  294. sq_arrayset(v, -2, 1);
  295. return 1;
  296. }
  297. static SQRESULT sq_freetype_face_next_char(HSQUIRRELVM v)
  298. {
  299. SQ_FUNC_VARS_NO_TOP(v);
  300. GET_freetype_face_INSTANCE();
  301. SQ_GET_INTEGER(v, 2, char_idx);
  302. FT_UInt agindex;
  303. FT_ULong charcode = dlFT_Get_Next_Char(self, char_idx, &agindex);
  304. sq_newarray(v, 2);
  305. sq_pushinteger(v, charcode);
  306. sq_arrayset(v, -2, 0);
  307. sq_pushinteger(v, agindex);
  308. sq_arrayset(v, -2, 1);
  309. return 1;
  310. }
  311. static SQRESULT sq_freetype_face_name_index(HSQUIRRELVM v)
  312. {
  313. SQ_FUNC_VARS_NO_TOP(v);
  314. GET_freetype_face_INSTANCE();
  315. SQ_GET_STRING(v, 2, char_name);
  316. FT_UInt gindex = dlFT_Get_Name_Index(self, (FT_String*)char_name);
  317. sq_pushinteger(v, gindex);
  318. return 1;
  319. }
  320. static SQRESULT sq_freetype_face_glyph_name(HSQUIRRELVM v)
  321. {
  322. SQ_FUNC_VARS_NO_TOP(v);
  323. GET_freetype_face_INSTANCE();
  324. if(FT_HAS_GLYPH_NAMES(self))
  325. {
  326. SQ_GET_INTEGER(v, 2, glyph_idx);
  327. SQInteger buf_size = 254;
  328. SQChar *buf = sq_getscratchpad(v, buf_size);
  329. FT_Error error = dlFT_Get_Glyph_Name(self, glyph_idx, buf, buf_size);
  330. if(error) sq_pushinteger(v, error);
  331. else sq_pushstring(v, buf, buf_size);
  332. }
  333. else sq_pushnull(v);
  334. return 1;
  335. }
  336. static SQRESULT sq_freetype_face_postscript_name(HSQUIRRELVM v)
  337. {
  338. SQ_FUNC_VARS_NO_TOP(v);
  339. GET_freetype_face_INSTANCE();
  340. const char *pname = dlFT_Get_Postscript_Name(self);
  341. if(pname) sq_pushstring(v, pname, -1);
  342. else sq_pushnull(v);
  343. return 1;
  344. }
  345. static SQRESULT sq_freetype_face_get_num_glyphs(HSQUIRRELVM v)
  346. {
  347. SQ_FUNC_VARS_NO_TOP(v);
  348. GET_freetype_face_INSTANCE();
  349. sq_pushinteger(v, self->num_glyphs);
  350. return 1;
  351. }
  352. static SQRESULT sq_freetype_face_metrics(HSQUIRRELVM v)
  353. {
  354. SQ_FUNC_VARS_NO_TOP(v);
  355. GET_freetype_face_INSTANCE();
  356. sq_newtableex(v, 3);
  357. sq_pushliteral(v, _SC("ascender"));
  358. sq_pushinteger(v, self->ascender);
  359. sq_rawset(v, -3);
  360. sq_pushliteral(v, _SC("descender"));
  361. sq_pushinteger(v, self->descender);
  362. sq_rawset(v, -3);
  363. sq_pushliteral(v, _SC("height"));
  364. sq_pushinteger(v, self->height);
  365. sq_rawset(v, -3);
  366. return 1;
  367. }
  368. #define _DECL_FUNC(name,nparams,tycheck) {_SC(#name),sq_freetype_face_##name,nparams,tycheck}
  369. static SQRegFunction sq_freetype_face_methods[] =
  370. {
  371. _DECL_FUNC(constructor,-3,_SC(".xsnb")),
  372. _DECL_FUNC(set_char_size,-3,_SC(".iiii")),
  373. _DECL_FUNC(get_num_glyphs,1,_SC("x")),
  374. _DECL_FUNC(load_char,-2,_SC("xi")),
  375. _DECL_FUNC(load_char2,-2,_SC("xi")),
  376. _DECL_FUNC(load_glyph,-2,_SC("xi")),
  377. _DECL_FUNC(load_glyph2,-2,_SC("xi")),
  378. _DECL_FUNC(first_char,1,_SC("x")),
  379. _DECL_FUNC(next_char,2,_SC("xi")),
  380. _DECL_FUNC(char_index,2,_SC("xi")),
  381. _DECL_FUNC(name_index,2,_SC("xs")),
  382. _DECL_FUNC(glyph_name,2,_SC("xi")),
  383. _DECL_FUNC(postscript_name,1,_SC("x")),
  384. _DECL_FUNC(metrics,1,_SC("x")),
  385. {0,0}
  386. };
  387. #undef _DECL_FUNC
  388. typedef struct {
  389. const SQChar *Str;
  390. SQInteger Val;
  391. } KeyIntType, * KeyIntPtrType;
  392. static KeyIntType sqfreetype_constants[] = {
  393. #define MK_CONST(c) {_SC(#c), c}
  394. #define MK_CONST2(c) {_SC(#c), (SQInteger)c}
  395. //MK_CONST(SSL_SESSION_ID_SIZE),
  396. MK_CONST(FT_LOAD_RENDER),
  397. MK_CONST(FT_LOAD_MONOCHROME),
  398. MK_CONST(FT_LOAD_TARGET_LIGHT),
  399. {0,0}
  400. };
  401. #ifdef __cplusplus
  402. extern "C" {
  403. #endif
  404. SQRESULT sqext_register_freetype(HSQUIRRELVM v)
  405. {
  406. sq_pushstring(v, Freetype_Tag,-1);
  407. sq_newclass(v,SQFalse);
  408. sq_settypetag(v,-1,(void*)Freetype_Tag);
  409. sq_insert_reg_funcs(v, sq_freetype_methods);
  410. /*
  411. //add constants
  412. KeyIntPtrType KeyIntPtr;
  413. for (KeyIntPtr = sqfreetype_constants; KeyIntPtr->Str; KeyIntPtr++) {
  414. sq_pushstring(v, KeyIntPtr->Str, -1); //first the key
  415. sq_pushinteger(v, KeyIntPtr->Val); //then the value
  416. sq_newslot(v, -3, SQFalse); //store then
  417. }
  418. */
  419. sq_newslot(v,-3,SQTrue);
  420. sq_pushstring(v, FreetypeFace_Tag,-1);
  421. sq_newclass(v,SQFalse);
  422. sq_settypetag(v,-1,(void*)FreetypeFace_Tag);
  423. sq_insert_reg_funcs(v, sq_freetype_face_methods);
  424. sq_newslot(v,-3,SQTrue);
  425. return 0;
  426. }
  427. #ifdef __cplusplus
  428. }
  429. #endif
  430. #endif // SQ_USE_FREETYPE