[face] Add hb_face_create_or_fail()

New API:
+ hb_face_create_or_fail()
This commit is contained in:
Behdad Esfahbod 2024-10-12 19:24:42 -06:00
parent 2166a46ad3
commit 2437fd883a
3 changed files with 33 additions and 0 deletions

View file

@ -357,6 +357,7 @@ hb_directwrite_face_get_font_face
hb_face_count
hb_face_t
hb_face_create
hb_face_create_or_fail
hb_reference_table_func_t
hb_face_create_for_tables
hb_face_get_empty

View file

@ -263,6 +263,34 @@ hb_face_create (hb_blob_t *blob,
return face;
}
/**
* hb_face_create_or_fail:
* @blob: #hb_blob_t to work upon
* @index: The index of the face within @blob
*
* Like hb_face_create(), but returns `NULL` if the blob data
* contains no usable font face at the specified index.
*
* Return value: (transfer full): The new face object, or `NULL` if
* no face is found at the specified index
*
* XSince: REPLACEME
**/
hb_face_t *
hb_face_create_or_fail (hb_blob_t *blob,
unsigned int index)
{
unsigned num_faces = hb_face_count (blob);
if (index >= num_faces)
return nullptr;
hb_face_t *face = hb_face_create (blob, index);
if (hb_object_is_immutable (face))
return nullptr;
return face;
}
/**
* hb_face_get_empty:
*

View file

@ -59,6 +59,10 @@ HB_EXTERN hb_face_t *
hb_face_create (hb_blob_t *blob,
unsigned int index);
HB_EXTERN hb_face_t *
hb_face_create_or_fail (hb_blob_t *blob,
unsigned int index);
/**
* hb_reference_table_func_t:
* @face: an #hb_face_t to reference table for