[python] Use utf-32 / utf-16 based on build of Python
Fixes https://github.com/behdad/harfbuzz/pull/271
This commit is contained in:
parent
fc9de44a03
commit
d3e2a06b0f
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys
|
import sys
|
||||||
|
import array
|
||||||
from gi.repository import HarfBuzz as hb
|
from gi.repository import HarfBuzz as hb
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
|
|
||||||
@ -39,7 +40,26 @@ class Debugger(object):
|
|||||||
return True
|
return True
|
||||||
debugger = Debugger()
|
debugger = Debugger()
|
||||||
hb.buffer_set_message_func (buf, debugger.message, 1, 0)
|
hb.buffer_set_message_func (buf, debugger.message, 1, 0)
|
||||||
hb.buffer_add_utf8 (buf, text.encode('utf-8'), 0, -1)
|
|
||||||
|
##
|
||||||
|
## Add text to buffer
|
||||||
|
##
|
||||||
|
#
|
||||||
|
# See https://github.com/behdad/harfbuzz/pull/271
|
||||||
|
#
|
||||||
|
if False:
|
||||||
|
# If you do not care about cluster values reflecting Python
|
||||||
|
# string indices, then this is quickest way to add text to
|
||||||
|
# buffer:
|
||||||
|
hb.buffer_add_utf8 (buf, text.encode('utf-8'), 0, -1)
|
||||||
|
# Otherwise, then following handles both narrow and wide
|
||||||
|
# Python builds:
|
||||||
|
elif sys.maxunicode == 0x10FFFF:
|
||||||
|
hb.buffer_add_utf32 (buf, array.array('I', text.encode('utf-32')), 0, -1)
|
||||||
|
else:
|
||||||
|
hb.buffer_add_utf16 (buf, array.array('H', text.encode('utf-16')), 0, -1)
|
||||||
|
|
||||||
|
|
||||||
hb.buffer_guess_segment_properties (buf)
|
hb.buffer_guess_segment_properties (buf)
|
||||||
|
|
||||||
hb.shape (font, buf, [])
|
hb.shape (font, buf, [])
|
||||||
|
Loading…
Reference in New Issue
Block a user