from gi.repository import HarfBuzz as hb from gi.repository import GLib # 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 if (hb.version_atleast(2,1,2)): pass else: raise RuntimeError('HarfBuzz too old') ##################################################################### ### Derived from harfbuzz:src/sample.py fontdata = open (sys.argv[1], 'rb').read () text = tounicode(sys.argv[2]) # Need to create GLib.Bytes explicitly until this bug is fixed: # https://bugzilla.gnome.org/show_bug.cgi?id=729541 blob = hb.glib_blob_create (GLib.Bytes.new (fontdata)) face = hb.face_create (blob, 0) del blob font = hb.font_create (face)
# 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 if (hb.version_atleast(1, 9, 0)): pass else: raise RuntimeError('HarfBuzz too old') fontdata = open(sys.argv[1], 'rb').read() text = tounicode(sys.argv[2]) # Need to create GLib.Bytes explicitly until this bug is fixed: # https://bugzilla.gnome.org/show_bug.cgi?id=729541 blob = hb.glib_blob_create(GLib.Bytes.new(fontdata)) face = hb.face_create(blob, 0) del blob font = hb.font_create(face) upem = hb.face_get_upem(face) del face hb.font_set_scale(font, upem, upem)