[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] rendering wide unicode characters?
On Thursday 08 December 2005 21:23, Anthony Baxter wrote:
> As far as I understand (and from the docs) I can just pass unicode
> strings to Font.render, and it will work. This example shows that
> for some characters, it doesn't. Should I log a bug in a tracker
> somewhere? I tried (in the example code) to pass the string encoded
> as utf-16 and utf-8 as well, also with no luck.
A quick look at src/font.c doesn't show any _obvious_ bugs, although I
prefer the following patch (removes the PyEval_CallMethod, so it
should be a little faster). It doesn't fix this particular issue,
though. :-(
It also changes the ordering of the includes so that Python.h is
included first. This is a necessary change, and it looks like there's
a bunch of other files that need this change made as well.
(see the boxed Warning text at
http://docs.python.org/ext/simpleExample.html)
--- src/font.c.dist 2005-12-08 22:14:30.000000000 +1100
+++ src/font.c 2005-12-08 22:24:20.000000000 +1100
@@ -25,10 +25,10 @@
* font module for pygame
*/
#define PYGAMEAPI_FONT_INTERNAL
+#include "font.h"
#include <stdio.h>
#include <string.h>
#include "pygame.h"
-#include "font.h"
#include "structmember.h"
@@ -455,7 +455,7 @@
}
else if(PyUnicode_Check(text))
{
- PyObject* strob = PyEval_CallMethod(text, "encode",
"(s)", "utf-8");
+ PyObject* strob = PyUnicode_AsEncodedObject(text,
"utf-8", "replace");
char *string = PyString_AsString(strob);
if(aa)
@@ -525,7 +525,7 @@
if(PyUnicode_Check(text))
{
- PyObject* strob = PyEval_CallMethod(text, "encode",
"(s)", "utf-8");
+ PyObject* strob = PyUnicode_AsEncodedObject(text,
"utf-8", "replace");
char *string = PyString_AsString(strob);
TTF_SizeUTF8(font, string, &w, &h);
--
Anthony Baxter <anthony@xxxxxxxxxxxxxxxx>
It's never too late to have a happy childhood.