Skip to content

Commit

Permalink
Auto-detect python 2 utf8 inputs, and allow example/emoji-color.py to…
Browse files Browse the repository at this point in the history
… work under python 2

Support python 2 with or without python 3 __future__ compatibility mode,
and bare integer as input to face.load_char
  • Loading branch information
HinTak committed Apr 15, 2017
1 parent e9721e6 commit a4e35f7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion freetype/__init__.py
Expand Up @@ -1291,8 +1291,16 @@ def load_char( self, char, flags = FT_LOAD_RENDER ):
This function simply calls FT_Get_Char_Index and FT_Load_Glyph.
'''

if len(char) == 1:
# python 2 with ascii input
if ( isinstance(char, str) and ( len(char) == 1 ) ):
char = ord(char)
# python 2 with utf8 string input
if ( isinstance(char, str) and ( len(char) != 1 ) ):
char = ord(char.decode('utf8'))
# python 3 or python 2 with __future__.unicode_literals
if ( isinstance(char, unicode) and ( len(char) == 1 ) ):
char = ord(char)
# allow bare integer to pass through
error = FT_Load_Char( self._FT_Face, char, flags )
if error: raise FT_Exception( error )

Expand Down

0 comments on commit a4e35f7

Please sign in to comment.