[HarfBuzz] How to get hb_face_t and hb_font_t without Freetype?

Eli Zaretskii eliz at gnu.org
Sat May 18 11:33:45 UTC 2019


> Cc: behdad at behdad.org, harfbuzz at lists.freedesktop.org
> From: Jonathan Kew <jfkthame at gmail.com>
> Date: Sat, 11 May 2019 22:15:46 +0100
> 
> >> If you've got access to the font as a file or as a single buffer in
> >> memory, then wrapping the entire thing as a blob and handing it to
> >> hb_face_create will be simplest.
> > 
> > Would wrapping in a blob the buffer returned by GetFontData be enough?
> 
> If you use GetFontData to get the complete font as a single buffer (i.e. 
> pass zero for the dwTable parameter), yes.

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.  The question for which I cannot find an answer is regarding
the memory management of the font data I get from GetFontData.  The
buffer into which I get the font data is malloc'ed.  Then I create a
blob from that buffer using hb_blob_create, use that blob to create a
face with hb_face_create, and finally use the face to create a font
with hb_font_create.  The result of hb_font_create I cache and use
thereafter each time I need to call hb_shape_full.  But what about the
hb_blob_t and the hb_face_t objects created in the process -- 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?  The question about the blob also directly affects whether I need
to keep around the buffer allocated for the GetFontData call, or can
it be freed once I have the hb_font_t object.

Another question is about error handling.  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?  If
not, how does one test for errors in a C program?  I assumed that any
errors cause subsequent calls to fail, and so only checked the last
call to hb_font_create for errors -- is that correct?

Thanks in advance for any help.


More information about the HarfBuzz mailing list