From b12acba4943420ecf0392660382c3d39b31ac987 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 12 Oct 2024 19:29:02 -0600 Subject: [PATCH] [face] Add hb_face_create_from_file_or_fail() New API: + hb_face_create_from_file_or_fail() --- docs/harfbuzz-sections.txt | 1 + src/hb-blob.cc | 5 ++--- src/hb-face.cc | 29 ++++++++++++++++++++++++++++- src/hb-face.h | 4 ++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 49cae7fbc..fff7730f6 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -358,6 +358,7 @@ hb_face_count hb_face_t hb_face_create hb_face_create_or_fail +hb_face_create_from_file_or_fail hb_reference_table_func_t hb_face_create_for_tables hb_face_get_empty diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 873d9b257..c363636d6 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -617,10 +617,9 @@ hb_blob_create_from_file (const char *file_name) /** * hb_blob_create_from_file_or_fail: - * @file_name: A font filename + * @file_name: A filename * - * Creates a new blob containing the data from the - * specified binary font file. + * Creates a new blob containing the data from the specified file. * * The filename is passed directly to the system on all platforms, * except on Windows, where the filename is interpreted as UTF-8. diff --git a/src/hb-face.cc b/src/hb-face.cc index 8d429c688..6e743a36f 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -272,7 +272,7 @@ hb_face_create (hb_blob_t *blob, * 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 + * no face is found at the specified index. * * XSince: REPLACEME **/ @@ -291,6 +291,33 @@ hb_face_create_or_fail (hb_blob_t *blob, return face; } +/** + * hb_face_create_from_file_or_fail: + * @file_name: A font filename + * @index: The index of the face within the file + * + * A thin wrapper around hb_blob_create_from_file_or_fail() + * followed by hb_face_create_or_fail(). + * + * 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_EXTERN hb_face_t * +hb_face_create_from_file_or_fail (const char *file_name, + unsigned int index) +{ + hb_blob_t *blob = hb_blob_create_from_file_or_fail (file_name); + if (unlikely (!blob)) + return nullptr; + + hb_face_t *face = hb_face_create_or_fail (blob, index); + hb_blob_destroy (blob); + + return face; +} + /** * hb_face_get_empty: * diff --git a/src/hb-face.h b/src/hb-face.h index f37bd3ce5..8aec681cf 100644 --- a/src/hb-face.h +++ b/src/hb-face.h @@ -63,6 +63,10 @@ HB_EXTERN hb_face_t * hb_face_create_or_fail (hb_blob_t *blob, unsigned int index); +HB_EXTERN hb_face_t * +hb_face_create_from_file_or_fail (const char *file_name, + unsigned int index); + /** * hb_reference_table_func_t: * @face: an #hb_face_t to reference table for