harfbuzz
Opened this issue · 6 comments
I'd like to implement harfbuzz node binding. At the same time I need to use FT2 font rendering. Harfbuzz code looks like this:
FT_Face ft_face;
FT_New_Face(ft_library, "amiri-regular.ttf", 0, &ft_face);
int ptSize = 50*64;
int device_hdpi = 72;
int device_vdpi = 72;
FT_Set_Char_Size(ft_face, 0, ptSize, device_hdpi, device_vdpi );
hb_buffer_t *buf = hb_buffer_create();
hb_font_t *hb_ft_font = hb_ft_font_create(ft_face, NULL);
hb_buffer_set_direction(buf, HB_DIRECTION_LTR);
int len = strlen(*input);
hb_buffer_add_utf8(buf, *input, len, 0, len);
hb_shape(hb_ft_font, buf, NULL, 0);
unsigned int glyph_count;
hb_glyph_info_t *glyph_info = hb_buffer_get_glyph_infos(buf, &glyph_count);
hb_glyph_position_t *glyph_pos = hb_buffer_get_glyph_positions(buf, &glyph_count);
What do you think re adding raw FT_Face handle accessor?
I'm not sure how that would work.
You're talking about adding a javascript accessor to FontFace that returns its ftFace
pointer?
yes. I'm currently serializing it to JS as hex string and de-serialising back from string in harfbuzz binding:
https://github.com/sidorares/node-freetype2/blob/face-handle/src/FontFace.cc#L67-L74
https://github.com/sidorares/node-harfbuzz/blob/master/src/addon.cc#L36-L40
That seems a little wonky. How about this?
Yeah, I like your approach more. Can you think of some way of having freetype2 as peer dependency? They going to be used alongside
That seems a little wonky
It does. It kind of worked for me but only partially, hb_shape returns correct list of glyph infos but all glyph positions are garbage. I'll try your way, thanks a lot!
hmm, still the same problem. Maybe FT needs to be initialised in the same dynamic library to work properly? xAdvance is completely irrelevant
node index.js /Library/Fonts/Arial.ttf "test 123"
[ { xOffset: 0,
yOffset: 0,
xAdvance: 2492,
yAdvance: 0,
codepoint: 22,
cluster: 7,
mask: 1 },
{ xOffset: 0,
yOffset: 0,
xAdvance: 2492,
yAdvance: 0,
codepoint: 21,
cluster: 6,
mask: 1 },
{ xOffset: 0,
yOffset: 0,
xAdvance: 2492,
yAdvance: 0,
codepoint: 20,
cluster: 5,
mask: 1 },
{ xOffset: 0,
yOffset: 0,
xAdvance: 1245,
yAdvance: 0,
codepoint: 3,
cluster: 4,
mask: 1 },
{ xOffset: 0,
yOffset: 0,
xAdvance: 1245,
yAdvance: 0,
codepoint: 87,
cluster: 3,
mask: 1 },
{ xOffset: 0,
yOffset: 0,
xAdvance: 2240,
yAdvance: 0,
codepoint: 86,
cluster: 2,
mask: 1 },
{ xOffset: 0,
yOffset: 0,
xAdvance: 2492,
yAdvance: 0,
codepoint: 72,
cluster: 1,
mask: 1 },
{ xOffset: 0,
yOffset: 0,
xAdvance: 1245,
yAdvance: 0,
codepoint: 87,
cluster: 0,
mask: 1 } ]
There is the way I like from architecture point of view, but it's hard to implement ( and not very performant ). Instead of using hb_ft helpers that access all tables in the face directly, provide callbacks to hb module and implement all glyphs-measuring code on top