[directwrite] Add hb_directwrite_face_create_from_file_or_fail()

Just loads the blob from file and creates a face from it.

New API:
+hb_directwrite_face_create_from_file_or_fail()
This commit is contained in:
Behdad Esfahbod 2025-03-14 02:13:32 -06:00
parent c73b54bcca
commit 1e9d101ed7
4 changed files with 33 additions and 1 deletions

View file

@ -361,6 +361,7 @@ hb_coretext_font_set_funcs
<SECTION>
<FILE>hb-directwrite</FILE>
hb_directwrite_face_create
hb_directwrite_face_create_from_file_or_fail
hb_directwrite_face_create_from_blob_or_fail
hb_directwrite_face_get_dw_font_face
hb_directwrite_font_create

View file

@ -1026,6 +1026,33 @@ hb_directwrite_face_create (IDWriteFontFace *dw_face)
_hb_directwrite_face_release);
}
/**
* hb_directwrite_face_create_from_file_or_fail:
* @file_name: A font filename
* @index: The index of the face within the file
*
* Creates an #hb_face_t face object from the specified
* font file and face index.
*
* This is similar in functionality to hb_face_create_from_file_or_fail(),
* but uses the DirectWrite library for loading the font file.
*
* Return value: (transfer full): The new face object, or `NULL` if
* no face is found at the specified index or the file cannot be read.
*
* XSince: REPLACEME
*/
hb_face_t *
hb_directwrite_face_create_from_file_or_fail (const char *file_name,
unsigned int index)
{
auto *blob = hb_blob_create_from_file_or_fail (file_name);
if (unlikely (!blob))
return nullptr;
return hb_directwrite_face_create_from_blob_or_fail (blob, index);
}
/**
* hb_directwrite_face_create_from_blob_or_fail:
* @blob: A blob containing the font data

View file

@ -34,6 +34,10 @@ HB_BEGIN_DECLS
HB_EXTERN hb_face_t *
hb_directwrite_face_create (IDWriteFontFace *dw_face);
HB_EXTERN hb_face_t *
hb_directwrite_face_create_from_file_or_fail (const char *file_name,
unsigned int index);
HB_EXTERN hb_face_t *
hb_directwrite_face_create_from_blob_or_fail (hb_blob_t *blob,
unsigned int index);

View file

@ -357,7 +357,7 @@ static struct supported_face_loaders_t {
#endif
#ifdef HAVE_DIRECTWRITE
{"directwrite",
nullptr, //hb_directwrite_face_create_from_file_or_fail,
hb_directwrite_face_create_from_file_or_fail,
hb_directwrite_face_create_from_blob_or_fail
},
#endif