diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-09-20 06:25:57 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-09-20 06:25:57 +0400 |
commit | 0e421f429ab9c6a6d041c7feb52e84826abe6c65 (patch) | |
tree | 2f65b2d5e848e59e9052d25e889b990e4444a0a4 | |
parent | 8dbc7a3ba321ce545c5ebfaa306c62314a38ff48 (diff) |
modify the python gettext function to pass through the original string when no translation is done, this means the cached info such as byte representation and hash will be kept.
-rw-r--r-- | source/blender/blenkernel/intern/font.c | 2 | ||||
-rw-r--r-- | source/blender/python/generic/blf_py_api.c | 41 |
2 files changed, 23 insertions, 20 deletions
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 0a94b4e3fd1..b5770d6a57c 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -289,8 +289,10 @@ void free_ttfont(void) } BLI_freelistN(&ttfdata); +#ifdef INTERNATIONAL if(unifont_ttf) MEM_freeN(unifont_ttf); +#endif } struct TmpFont *vfont_find_tmpfont(VFont *vfont) diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c index 9a4bcf22ed8..4b14ddc303c 100644 --- a/source/blender/python/generic/blf_py_api.c +++ b/source/blender/python/generic/blf_py_api.c @@ -381,20 +381,20 @@ PyDoc_STRVAR(py_blf_gettext_doc, " :return: the localized string.\n" " :rtype: string\n" ); -static PyObject *py_blf_gettext(PyObject *UNUSED(self), PyObject *args) +static PyObject *py_blf_gettext(PyObject *UNUSED(self), PyObject *value) { - char* msgid; - const char *text; - - if (!PyArg_ParseTuple(args, "s:blf.gettext", &msgid)) - return NULL; - - if((U.transopts&USER_DOTRANSLATE) && (U.transopts&USER_TR_IFACE)) - text = BLF_gettext( msgid ); - else - text = msgid; - - return PyUnicode_FromString( text ); + if ((U.transopts & USER_DOTRANSLATE) && (U.transopts & USER_TR_IFACE)) { + const char *msgid= _PyUnicode_AsString(value); + if(msgid == NULL) { + PyErr_SetString(PyExc_TypeError, "blf.gettext expects a single string argument"); + return NULL; + } + + return PyUnicode_FromString(BLF_gettext(msgid)); + } + else { + return Py_INCREF(value), value; + } } PyDoc_STRVAR(py_blf_fake_gettext_doc, @@ -407,15 +407,16 @@ PyDoc_STRVAR(py_blf_fake_gettext_doc, " :return: the source string.\n" " :rtype: string\n" ); -static PyObject *py_blf_fake_gettext(PyObject *UNUSED(self), PyObject *args) +static PyObject *py_blf_fake_gettext(PyObject *UNUSED(self), PyObject *value) { - const char* msgid; - if (!PyArg_ParseTuple(args, "s:blf.fake_gettext", &msgid)) + if (!PyUnicode_Check(value)) { + PyErr_SetString(PyExc_TypeError, "blf.fake_gettext expects a single string argument"); return NULL; + } - return PyUnicode_FromString( msgid ); + return Py_INCREF(value), value; } -#endif +#endif /* INTERNATIONAL */ /*----------------------------MODULE INIT-------------------------*/ static PyMethodDef BLF_methods[] = { @@ -433,8 +434,8 @@ static PyMethodDef BLF_methods[] = { {"size", (PyCFunction) py_blf_size, METH_VARARGS, py_blf_size_doc}, {"load", (PyCFunction) py_blf_load, METH_VARARGS, py_blf_load_doc}, #ifdef INTERNATIONAL - {"gettext", (PyCFunction) py_blf_gettext, METH_VARARGS, py_blf_gettext_doc}, - {"fake_gettext", (PyCFunction) py_blf_fake_gettext, METH_VARARGS, py_blf_fake_gettext_doc}, + {"gettext", (PyCFunction) py_blf_gettext, METH_O, py_blf_gettext_doc}, + {"fake_gettext", (PyCFunction) py_blf_fake_gettext, METH_O, py_blf_fake_gettext_doc}, #endif {NULL, NULL, 0, NULL} }; |