static int cdfont(cdCtxCanvas *ctxcanvas, const char *type_face, int style, int size) { char filename[10240]; /* try the pre-defined names and pre-defined style suffix */ if (!cdGetFontFileNameDefault(type_face, style, filename)) { /* try to find the file in the native system */ if (!cdGetFontFileNameSystem(type_face, style, filename)) { /* try the type_face as file name, here assume type_face is a full path */ strcpy(filename, type_face); } } ctxcanvas->font = ftglCreateTextureFont(filename); if (!ctxcanvas->font) return 0; if (size < 0) size = cdGetFontSizePoints(ctxcanvas->canvas, size); /* FTGL: One point in pixel space maps to 1 unit in opengl space, so a glyph that is 18 points high should be 18.0 units high. */ /* CD: that means 1 point is actually being mapped to 1 pixel */ size = cdGetFontSizePixels(ctxcanvas->canvas, size); ftglSetFontFaceSize(ctxcanvas->font, size, (int)(ctxcanvas->canvas->xres*25.4)); ftglSetFontCharMap(ctxcanvas->font, ft_encoding_unicode); return 1; }
int font_new(lua_State *L, const char *path, const char *name) { FTGLfont *ftgl_font = ftglCreateTextureFont(path); if (!ftgl_font) return luaL_error(L, "cannot load font file %s", path); ftglSetFontDisplayList(ftgl_font, 1); ftglSetFontFaceSize(ftgl_font, SCALE, SCALE); ftglSetFontCharMap(ftgl_font, ft_encoding_unicode); font_t *font = push_font(L); font->font = ftgl_font; return 1; }