[py] minor, comment buffer_add_utf8 call

mainly to apply lgtm suggestion, looks better also however,
some minor spacing is also applied.
This commit is contained in:
Ebrahim Byagowi 2020-07-13 20:41:13 +04:30 committed by GitHub
parent 2c1d699409
commit 2a182128b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 15 deletions

View File

@ -20,11 +20,11 @@ hb.font_set_scale (font, upem, upem)
hb.ot_font_set_funcs (font) hb.ot_font_set_funcs (font)
buf = hb.buffer_create () buf = hb.buffer_create ()
class Debugger(object): class Debugger (object):
def message (self, buf, font, msg, data, _x_what_is_this): def message (self, buf, font, msg, data, _x_what_is_this):
print(msg) print (msg)
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)
## ##
@ -33,17 +33,16 @@ hb.buffer_set_message_func (buf, debugger.message, 1, 0)
# #
# See https://github.com/harfbuzz/harfbuzz/pull/271 # See https://github.com/harfbuzz/harfbuzz/pull/271
# #
if False: # If you do not care about cluster values reflecting Python
# If you do not care about cluster values reflecting Python # string indices, then this is quickest way to add text to
# string indices, then this is quickest way to add text to # buffer:
# buffer: # hb.buffer_add_utf8 (buf, text.encode('utf-8'), 0, -1)
hb.buffer_add_utf8 (buf, text.encode('utf-8'), 0, -1) # Otherwise, then following handles both narrow and wide
# Otherwise, then following handles both narrow and wide # Python builds (the first item in the array is BOM, so we skip it):
# Python builds (the first item in the array is BOM, so we skip it): if sys.maxunicode == 0x10FFFF:
elif sys.maxunicode == 0x10FFFF: hb.buffer_add_utf32 (buf, array.array ('I', text.encode ('utf-32'))[1:], 0, -1)
hb.buffer_add_utf32 (buf, array.array('I', text.encode('utf-32'))[1:], 0, -1)
else: else:
hb.buffer_add_utf16 (buf, array.array('H', text.encode('utf-16'))[1:], 0, -1) hb.buffer_add_utf16 (buf, array.array ('H', text.encode ('utf-16'))[1:], 0, -1)
hb.buffer_guess_segment_properties (buf) hb.buffer_guess_segment_properties (buf)
@ -54,11 +53,11 @@ del font
infos = hb.buffer_get_glyph_infos (buf) infos = hb.buffer_get_glyph_infos (buf)
positions = hb.buffer_get_glyph_positions (buf) positions = hb.buffer_get_glyph_positions (buf)
for info,pos in zip(infos, positions): for info, pos in zip (infos, positions):
gid = info.codepoint gid = info.codepoint
cluster = info.cluster cluster = info.cluster
x_advance = pos.x_advance x_advance = pos.x_advance
x_offset = pos.x_offset x_offset = pos.x_offset
y_offset = pos.y_offset y_offset = pos.y_offset
print("gid%d=%d@%d,%d+%d" % (gid, cluster, x_advance, x_offset, y_offset)) print ("gid%d=%d@%d,%d+%d" % (gid, cluster, x_advance, x_offset, y_offset))