Giter Club home page Giter Club logo

Comments (4)

jiong3 avatar jiong3 commented on May 26, 2024

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

from freetype-py.

HinTak avatar HinTak commented on May 26, 2024

from freetype-py.

HinTak avatar HinTak commented on May 26, 2024

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.

from freetype-py.

HinTak avatar HinTak commented on May 26, 2024

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.

from freetype-py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.