ldo / harfpy Goto Github PK
View Code? Open in Web Editor NEWPython wrapper for HarfBuzz
Python wrapper for HarfBuzz
This project is no longer being maintained on GitHub. Look for it at one of * gitlab: https://gitlab.com/ldo/harfpy * bitbucket: https://bitbucket.org/ldo17/harfpy
I saw the Github repo went down yesterday and noticed that there is an equivalent one at https://gitlab.com/ldo/harfpy
Which one is the mirror of the other, and where would you like pull request to be sent to?
Take for example glyph advance function, the documentation says:
def get_glyph_v_advance(self, font_data, glyph, user_data)
where self is the FontFuncs instance and font_data was what was passed to set_font_funcs for the Font, and return a float.
But in C the first argument in the font itself, which is needed here since the glyph advance (in font units) should be multiplied by the font scale.
Hi there!
I am using harfpy and python_freetype in the example code for a book I am writing. You can read it at https://ralsina.gitlab.io/boxes-book/ and I was wondering if you could upload them to PyPI? Makes explaining requirements.txt simpler.
Thanks in advance!
Are the following Blob declarations equivalent?
table = b'..' # the font table in bytes
blob = hb.Blob.create(
table, len(table), HB.MEMORY_MODE_READONLY, None, None)
import array
table = b'..' # the font table in bytes
a = array.array('B')
a.frombytes(table)
value = hb.Blob.create_for_array(a, HB.MEMORY_MODE_READONLY)
The second example works, but the first one produces bad access. Am I missing something?
Hi,
I have a very important project to render Devnagiri text using Arduino Uno/Mega or ESP32.
I was looking for solutions and came across this. As you have clearly mentioned this library is for linux environment.
But the code is in python. ESP32 supports micro python.
Is there any way to port this to ESP32/Arduino environment with MicroPython?
If not, do you have any ideas how to achieve this? Thanks!
See: OpenType/opentype-layout#4
(Apologies for "spamming".)
So I did port the hb_ot python example from the harfbuzz repo:
import array
import os
from harfbuzz import HARFBUZZ as HB
import harfbuzz as hb
def shape_dat(path, text):
a = array.array('B')
size = os.path.getsize(path)
with open(path, 'rb') as f:
a.fromfile(f, size)
blob = hb.Blob.create_for_array(a, HB.MEMORY_MODE_READONLY)
face = hb.Face.create(blob, 0)
del blob
font = hb.Font.create(face)
upem = face.upem
del face
font.scale = (upem, upem)
font.ot_set_funcs()
buf = hb.Buffer.create()
class Debugger(object):
def message(self, buf, font, msg, data):
print(msg)
return True
debugger = Debugger()
#buf.set_message_func(debugger, None, None)
buf.add_str(text)
buf.guess_segment_properties()
hb.shape(font, buf)
for info, pos in zip(buf.glyph_infos, buf.glyph_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))
if __name__ == "__main__":
import sys
assert len(sys.argv) == 3
shape_dat(*sys.argv[1:])
Yet the x_advance values that I get back seem very small, e.g. with Bitstream Vera:
PS C:\Users\Admin\Documents> python harfbuzz__.py C:\Vera.ttf "Hello World!"
gid43=0@24,0+0
gid72=1@19,0+0
gid79=2@8,0+0
gid79=3@8,0+0
gid82=4@19,0+0
gid3=5@10,0+0
gid58=6@31,0+0
gid82=7@19,0+0
gid85=8@13,0+0
gid79=9@8,0+0
gid71=10@20,0+0
gid4=11@12,0+0
Is this expected?
cc @khaledhosny
I store a hb.Font and reuse it to redo shaping on new inputs, and it seems I randomly get bad access or garbage results after a few times reusing the hb.Font.
Traceback (most recent call last):
File "c:\users\admin\downloads\trufont\lib\trufont\controls\glyphCanvasView.py", line 342, in keyPressEvent
self._redirectEvent(event, self._currentTool.keyPressEvent)
File "c:\users\admin\downloads\trufont\lib\trufont\controls\glyphCanvasView.py", line 465, in _redirectEvent
callback(event)
File "c:\users\admin\downloads\trufont\lib\trufont\drawingTools\textTool.py", line 119, in keyPressEvent
self.layoutLine.insert(text)
File "c:\users\admin\downloads\trufont\lib\trufont\objects\layoutLine.py", line 99, in insert
self.updateView()
File "c:\users\admin\downloads\trufont\lib\trufont\objects\layoutLine.py", line 164, in updateView
self._shapeAndSetText()
File "c:\users\admin\downloads\trufont\lib\trufont\objects\layoutLine.py", line 142, in _shapeAndSetText
records = self.engine.process(self._inputString.tounicode())
File "c:\users\admin\downloads\trufont\lib\trufont\objects\layoutEngine.py", line 165, in process
hb.shape(self._hbFont, buf)
File "c:\users\admin\downloads\harfpy\harfbuzz.py", line 4009, in shape
hb.hb_shape(font._hbobj, buffer._hbobj, c_features, nr_features)
OSError: exception: access violation reading 0x130945F6
Making this binding work in OSX requires a tiny change. When dynamically loading the library
on OSX the name is different:
hb = ct.cdll.LoadLibrary("libharfbuzz.0.dylib")
Other than that, it works. If you are interested in this working I can provide a PR.
There is a similar issue in the freetype binding.
Take this simple helloworld.py snippet:
import freetype2
import harfbuzz as hb
ft = freetype2.Library()
text_line = "abc"
buf = hb.Buffer.create()
buf.add_str(text_line, 0, len(text_line))
buf.guess_segment_properties()
ft_face = ft.new_face("/Users/cosimolupo/Desktop/test.ttf")
ft_face.set_char_size(size=1, resolution=72)
hb_font = hb.Font.ft_create(ft_face)
hb.shape(hb_font, buf)
print(
"buf.glyph_infos = %s\n\n"
"glyph_positions = %s" % (
buf.glyph_infos, buf.glyph_positions
)
)
# if I don't delete hb_font, I get "Segmentation fault: 11"
del hb_font
I noticed that, if I don't manually delete the hb_font
instance myself, python will abort with a Segmentation fault 11
immediately before exit, while it's destroying the __main__
module.
When run I am receiving function not found error.
I got this error message while trying to set up a debugger function on the Buffer object:
Traceback (most recent call last):
File "harfbuzz__.py", line 47, in <module>
shape_dat(*sys.argv[1:])
File "harfbuzz__.py", line 28, in shape_dat
buf.set_message_func(debugger, None, None)
File "c:\users\admin\downloads\harfpy\harfbuzz.py", line 772, in set_callback
wrap_callback_func = def_wrap_callback_func(self, callback_func, user_data)
File "c:\users\admin\downloads\harfpy\harfbuzz.py", line 2484, in def_wrap_message_func
@HB.message_func_t
AttributeError: type object 'HARFBUZZ' has no attribute 'message_func_t'
Maybe I'm misusing the API, but thought I would post this.
File "/home/frappe/frappe-bench/apps/asterisk_erp/asterisk_erp/codimd/codimd_pdf.py", line 4, in <module>
import harfbuzz as hb
File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/harfbuzz.py", line 1535, in <module>
hb.hb_face_count.restype = ct.c_uint
File "/usr/lib/python3.6/ctypes/__init__.py", line 361, in __getattr__
func = self.__getitem__(name)
File "/usr/lib/python3.6/ctypes/__init__.py", line 366, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: /usr/lib/x86_64-linux-gnu/libharfbuzz.so.0: undefined symbol: hb_face_count
Line 1535( hb.hb_face_count.restype = ct.c_uint
) of the script throws error.
OS: Ubuntu 18.04.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.