Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does it support unicode? #54

Closed
yzldw333 opened this issue Apr 20, 2017 · 4 comments
Closed

Does it support unicode? #54

yzldw333 opened this issue Apr 20, 2017 · 4 comments

Comments

@yzldw333
Copy link

I use it to make pictures of Chinese words, but it since that doesn't support.

@jiong3
Copy link
Contributor

jiong3 commented Apr 20, 2017

Rendering Chinese characters shouldn't be a problem, what exactly doesn't work?

@HinTak
Copy link
Collaborator

HinTak commented Apr 20, 2017 via email

@HinTak
Copy link
Collaborator

HinTak commented Apr 29, 2017

example_1-cairo

Here is example 1 quickly adapted to do Chinese. As I expected, just using a chinese-capable font and a chinese phrase would do, so the change is only two lines:

@@ -45,8 +45,8 @@ def main():
     matrix  = FT_Matrix()
     face    = FT_Face()
     pen     = FT_Vector()
-    filename= 'Vera.ttf'
-    text    = 'Hello World !'
+    filename= 'DroidSansFallbackFull.ttf'
+    text    = '你好嗎!'
     num_chars = len(text)

OTOH, as I mentioned above, python 2.x does strings and unicodes somewhat differently; so this change for example 1 only works on python 3.x. My fix ( #52 ) only fixes unicode processing for the emoji example. TODO.

@HinTak
Copy link
Collaborator

HinTak commented Apr 29, 2017

I tested both of these answers for python2, and both work. You can either put this line near the top:

from __future__ import unicode_literals

which enables python 2.x to process strings python 3.x style, or add a decode('utf8') manually like this:

@@ -45,8 +46,9 @@ def main():
     matrix  = FT_Matrix()
     face    = FT_Face()
     pen     = FT_Vector()
-    filename= 'Vera.ttf'
-    text    = 'Hello World !'
+    filename= 'DroidSansFallbackFull.ttf'
+    text    = '你好嗎!'
+    text = text.decode('utf8')
     num_chars = len(text)

Both of these work, you only need one of them. The first one is probably easiest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants