2013-09-13 02:53:07 +02:00
|
|
|
#!/usr/bin/python
|
2015-01-06 23:05:26 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-09-13 02:53:07 +02:00
|
|
|
|
2015-01-06 23:05:26 +01:00
|
|
|
from __future__ import print_function
|
2013-09-13 02:53:07 +02:00
|
|
|
import sys
|
|
|
|
from gi.repository import HarfBuzz as hb
|
|
|
|
|
2015-01-07 00:37:31 +01:00
|
|
|
# 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
|
|
|
|
|
|
|
|
|
2015-01-06 23:05:26 +01:00
|
|
|
def nothing(data):
|
|
|
|
print(data)
|
2013-09-13 02:53:07 +02:00
|
|
|
|
2015-01-06 23:05:26 +01:00
|
|
|
fontdata = open (sys.argv[1], 'rb').read ()
|
2013-09-13 02:53:07 +02:00
|
|
|
|
2015-01-06 23:05:26 +01:00
|
|
|
blob = hb.blob_create (fontdata, hb.memory_mode_t.DUPLICATE, 1234, None)
|
|
|
|
buf = hb.buffer_create ()
|
2015-01-07 00:37:31 +01:00
|
|
|
hb.buffer_add_utf8 (buf, tounicode("Hello بهداد").encode('utf-8'), 0, -1)
|
2015-01-06 23:05:26 +01:00
|
|
|
hb.buffer_guess_segment_properties (buf)
|
|
|
|
|
|
|
|
face = hb.face_create (blob, 0)
|
|
|
|
font = hb.font_create (face)
|
|
|
|
upem = hb.face_get_upem (face)
|
|
|
|
hb.font_set_scale (font, upem, upem)
|
|
|
|
#hb.ft_font_set_funcs (font)
|
|
|
|
hb.ot_font_set_funcs (font)
|
|
|
|
|
|
|
|
hb.shape (font, buf, [])
|
|
|
|
|
|
|
|
infos = hb.buffer_get_glyph_infos (buf)
|
|
|
|
positions = hb.buffer_get_glyph_positions (buf)
|
|
|
|
|
|
|
|
for info,pos in zip(infos, positions):
|
|
|
|
gid = info.codepoint
|
|
|
|
cluster = info.cluster
|
|
|
|
advance = pos.x_advance
|
|
|
|
|
|
|
|
print(gid, cluster, advance)
|