[HarfBuzz] How to get hb_face_t and hb_font_t without Freetype?
eliz at gnu.org
Fri May 24 13:39:30 UTC 2019
> From: Ebrahim Byagowi <ebraminio at gmail.com>
> Date: Fri, 24 May 2019 20:13:43 +0430
> Cc: Harfbuzz <harfbuzz at lists.freedesktop.org>
> Pardon me for the may inaccurate following answer I have to write quickly,
Thanks for your help.
> > Also, does HarfBuzz support TrueType Collection (TTC) files, and if so, does it want the data only for the
> currently selected font or all
> of the data?
> It does, if you want harfbuzz handles it for you, you should give it the full blob and set the index you like in
> second argument of hb_face_create, otherwise you should handle it yourself.
OK, this brings me to another question: what should I in general pass
as the 2nd argument of hb_face_create? Suppose I'm using a TTF or OTF
font file, should I always pass zero as the 2nd argument? What is the
semantics of that argument?
> > I'm now working on the HarfBuzz font driver for Emacs on Windows using GetFontData with the dwTable
> argument zero, to get the entire data of the font.
> Is it DirectWrite? Have you seen the helper we have the in hb-directwrite.h and hb-uniscribe.h? They can be
> very useful.
I'm not using DirectWrite, nor am I using Uniscribe. My HarfBuzz is
built without these two, as I understand building with these back-ends
is only needed for comparison. I want to use the HarfBuzz shaper, and
only it (Emacs already has support for Uniscribe).
But yes, I do consult these files to figure out answers to my
> > does their memory need to be freed in some manner after I have the hb_font_t object, or do I have to keep
> them as long as hb_font_t is in use?
> Don't free it yourself specially if in use, you can use harfbuzz destroy callback so harfbuzz can handle it for
Sorry, I don't think I understand: what do you mean by "harfbuzz
destroy callback"? If you mean the 'destroy" argument of
hb_blob_create, then AFAIU this is called only to destroy user_data,
and I don't have user_data, I pass NULL as the 4th argument of
hb_blob_create. And hb_face_create doesn't have any callback argument
I see in the few programs in util/ that both the blob and the face are
destroyed as soon as hb_font_t object is created, which is why I
thought I could do the same. But now you seem to say I shouldn't?
For that matter, what should I use as the 'mode' argument of
shows an example of calling hb_blob_create with 'free' (in my case,
'xfree') as the 'destroy' callback, so I guess my interpretation of
that argument as being pertinent to user_data was incorrect? Still,
the questions about memory management for hb_face_t and about the
semantics of the hb_memory_mode_t enum values are left unanswered.
> > I see that hb_blob_create, hb_face_create etc. return empty objects when they fail. But I see no "is-empty"
> function or macro in the docs, did I miss something?
> Some of the objects may work with empty comparison but it is not broken face
> https://github.com/harfbuzz/harfbuzz/issues/1572 but something does it very accurately is
AFAIU, you are saying that if hb_face_get_glyph_count returns zero,
the face is empty and shouldn't be used, is that right?
> > Where do those 64.0 factors come from?
> Subpixel accuracy, harfbuzz works with integers but as subpixel accuracy needed you have to we need to do
> some scaling. Scaling is not the pixels but _set_ppem and _set_ptem is (this is very inaccurate, but I hope
> would be useful)
Does this mean I should use the factor of 64 in my code as well? Or
does that value depend on some properties of the font?
> > Or point me to the documentation where that is described, if I missed it?
> https://harfbuzz.github.io/ may address some of your issues
Thanks again for your help.
More information about the HarfBuzz