summaryrefslogtreecommitdiffstats
path: root/gfx/harfbuzz/src/sample.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /gfx/harfbuzz/src/sample.py
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/harfbuzz/src/sample.py')
-rwxr-xr-xgfx/harfbuzz/src/sample.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/gfx/harfbuzz/src/sample.py b/gfx/harfbuzz/src/sample.py
new file mode 100755
index 0000000000..5d04e803f2
--- /dev/null
+++ b/gfx/harfbuzz/src/sample.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python3
+
+import sys
+import array
+import gi
+gi.require_version('HarfBuzz', '0.0')
+from gi.repository import HarfBuzz as hb
+from gi.repository import GLib
+
+fontdata = open (sys.argv[1], 'rb').read ()
+text = 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)
+#hb.ft_font_set_funcs (font)
+hb.ot_font_set_funcs (font)
+
+buf = hb.buffer_create ()
+class Debugger (object):
+ def message (self, buf, font, msg, data, _x_what_is_this):
+ print (msg)
+ return True
+debugger = Debugger ()
+hb.buffer_set_message_func (buf, debugger.message, 1, 0)
+
+##
+## Add text to buffer
+##
+#
+# See https://github.com/harfbuzz/harfbuzz/pull/271
+#
+# 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 (the first item in the array is BOM, so we skip it):
+if sys.maxunicode == 0x10FFFF:
+ hb.buffer_add_utf32 (buf, array.array ('I', text.encode ('utf-32'))[1:], 0, -1)
+else:
+ hb.buffer_add_utf16 (buf, array.array ('H', text.encode ('utf-16'))[1:], 0, -1)
+
+
+hb.buffer_guess_segment_properties (buf)
+
+hb.shape (font, buf, [])
+del font
+
+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
+ x_advance = pos.x_advance
+ x_offset = pos.x_offset
+ y_offset = pos.y_offset
+
+ print ("gid%d=%d@%d,%d+%d" % (gid, cluster, x_advance, x_offset, y_offset))