提交 81a31f3e 编写于 作者: B Behdad Esfahbod

[bindings] Make sample Python 2/3 compatible

上级 b632e799
...@@ -5,6 +5,19 @@ from __future__ import print_function ...@@ -5,6 +5,19 @@ from __future__ import print_function
import sys import sys
from gi.repository import HarfBuzz as hb from gi.repository import HarfBuzz as hb
# Python 2/3 compatibility
try:
unicode
except NameError:
unicode = str
def tounicode(s, encoding='utf-8'):
if not isinstance(s, unicode):
return s.decode(encoding)
else:
return s
def nothing(data): def nothing(data):
print(data) print(data)
...@@ -12,7 +25,7 @@ fontdata = open (sys.argv[1], 'rb').read () ...@@ -12,7 +25,7 @@ fontdata = open (sys.argv[1], 'rb').read ()
blob = hb.blob_create (fontdata, hb.memory_mode_t.DUPLICATE, 1234, None) blob = hb.blob_create (fontdata, hb.memory_mode_t.DUPLICATE, 1234, None)
buf = hb.buffer_create () buf = hb.buffer_create ()
hb.buffer_add_utf8 (buf, "Hello بهداد", 0, -1) hb.buffer_add_utf8 (buf, tounicode("Hello بهداد").encode('utf-8'), 0, -1)
hb.buffer_guess_segment_properties (buf) hb.buffer_guess_segment_properties (buf)
face = hb.face_create (blob, 0) face = hb.face_create (blob, 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册