[bindings] Use hb_glib_blob_create() in sample
hb_blob_create() is considered C-only API.
This commit is contained in:
parent
0ef179e2dc
commit
2cd5323531
|
@ -78,12 +78,12 @@ _hb_blob_destroy_user_data (hb_blob_t *blob)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hb_blob_create: (Xconstructor)
|
* hb_blob_create: (skip)
|
||||||
* @data: (array length=length) (element-type uint8_t) (closure user_data) (destroy destroy) (scope notified) (transfer none): Pointer to blob data.
|
* @data: Pointer to blob data.
|
||||||
* @length: Length of @data in bytes.
|
* @length: Length of @data in bytes.
|
||||||
* @mode: Memory mode for @data.
|
* @mode: Memory mode for @data.
|
||||||
* @user_data: (nullable): Data parameter to pass to @destroy.
|
* @user_data: Data parameter to pass to @destroy.
|
||||||
* @destroy: (nullable): Callback to call when @data is not needed anymore.
|
* @destroy: Callback to call when @data is not needed anymore.
|
||||||
*
|
*
|
||||||
* Creates a new "blob" object wrapping @data. The @mode parameter is used
|
* Creates a new "blob" object wrapping @data. The @mode parameter is used
|
||||||
* to negotiate ownership and lifecycle of @data.
|
* to negotiate ownership and lifecycle of @data.
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys
|
import sys
|
||||||
from gi.repository import HarfBuzz as hb
|
from gi.repository import HarfBuzz as hb
|
||||||
|
from gi.repository import GLib
|
||||||
|
|
||||||
# Python 2/3 compatibility
|
# Python 2/3 compatibility
|
||||||
try:
|
try:
|
||||||
|
@ -17,25 +18,23 @@ def tounicode(s, encoding='utf-8'):
|
||||||
else:
|
else:
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
def nothing(data):
|
|
||||||
print(data)
|
|
||||||
|
|
||||||
fontdata = open (sys.argv[1], 'rb').read ()
|
fontdata = open (sys.argv[1], 'rb').read ()
|
||||||
|
blob = hb.glib_blob_create (GLib.Bytes.new (fontdata))
|
||||||
blob = hb.blob_create (fontdata, hb.memory_mode_t.DUPLICATE, 1234, None)
|
|
||||||
buf = hb.buffer_create ()
|
|
||||||
hb.buffer_add_utf8 (buf, tounicode("Hello بهداد").encode('utf-8'), 0, -1)
|
|
||||||
hb.buffer_guess_segment_properties (buf)
|
|
||||||
|
|
||||||
face = hb.face_create (blob, 0)
|
face = hb.face_create (blob, 0)
|
||||||
|
del blob
|
||||||
font = hb.font_create (face)
|
font = hb.font_create (face)
|
||||||
upem = hb.face_get_upem (face)
|
upem = hb.face_get_upem (face)
|
||||||
|
del face
|
||||||
hb.font_set_scale (font, upem, upem)
|
hb.font_set_scale (font, upem, upem)
|
||||||
#hb.ft_font_set_funcs (font)
|
#hb.ft_font_set_funcs (font)
|
||||||
hb.ot_font_set_funcs (font)
|
hb.ot_font_set_funcs (font)
|
||||||
|
|
||||||
|
buf = hb.buffer_create ()
|
||||||
|
hb.buffer_add_utf8 (buf, tounicode("Hello بهداد").encode('utf-8'), 0, -1)
|
||||||
|
hb.buffer_guess_segment_properties (buf)
|
||||||
|
|
||||||
hb.shape (font, buf, [])
|
hb.shape (font, buf, [])
|
||||||
|
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)
|
||||||
|
|
Loading…
Reference in New Issue