Add BLF_gettext(msgid) for C, and blf.gettext(msgid) for Python.

This commit is contained in:
Xiao Xiangquan 2011-05-30 11:03:16 +00:00
parent 682a5acd03
commit 0fc21dde4e
3 changed files with 33 additions and 0 deletions

@ -41,6 +41,8 @@ void BLF_exit(void);
void BLF_cache_clear(void);
char* BLF_gettext(const char *msgid);
int BLF_load(const char *name);
int BLF_load_mem(const char *name, unsigned char *mem, int mem_size);

@ -37,6 +37,7 @@
#include <math.h>
#include <ft2build.h>
#include <libintl.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
@ -120,6 +121,11 @@ void BLF_cache_clear(void)
}
}
char* BLF_gettext(const char *msgid)
{
return gettext( msgid );
}
static int blf_search(const char *name)
{
FontBLF *font;

@ -367,6 +367,30 @@ static PyObject *py_blf_load(PyObject *UNUSED(self), PyObject *args)
return PyLong_FromLong(BLF_load(filename));
}
PyDoc_STRVAR(py_blf_gettext_doc,
".. function:: gettext(msgid)\n"
"\n"
" Get a msg in local language.\n"
"\n"
" :arg msgid: the source string.\n"
" :type msgid: string\n"
" :return: the localized string.\n"
" :rtype: string\n"
);
static PyObject *py_blf_gettext(PyObject *UNUSED(self), PyObject *args)
{
char* msgid;
char* msgstr;
char* error_handle;
if (!PyArg_ParseTuple(args, "s:blf.gettext", &msgid))
return NULL;
msgstr = BLF_gettext( msgid );
return PyUnicode_DecodeUTF8( msgstr, strlen(msgstr), error_handle );
}
/*----------------------------MODULE INIT-------------------------*/
static PyMethodDef BLF_methods[] = {
{"aspect", (PyCFunction) py_blf_aspect, METH_VARARGS, py_blf_aspect_doc},
@ -382,6 +406,7 @@ static PyMethodDef BLF_methods[] = {
{"shadow_offset", (PyCFunction) py_blf_shadow_offset, METH_VARARGS, py_blf_shadow_offset_doc},
{"size", (PyCFunction) py_blf_size, METH_VARARGS, py_blf_size_doc},
{"load", (PyCFunction) py_blf_load, METH_VARARGS, py_blf_load_doc},
{"gettext", (PyCFunction) py_blf_gettext, METH_VARARGS, py_blf_gettext_doc},
{NULL, NULL, 0, NULL}
};