diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 23b4a5af3..4a5c06cd6 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -517,6 +517,7 @@ hb_glyph_extents_t hb_ft_face_create hb_ft_face_create_cached hb_ft_face_create_referenced +hb_ft_face_create_from_file_or_fail hb_ft_font_create hb_ft_font_create_referenced hb_ft_font_changed diff --git a/src/hb-coretext-shape.cc b/src/hb-coretext-shape.cc index b0b86c5b5..e417f288e 100644 --- a/src/hb-coretext-shape.cc +++ b/src/hb-coretext-shape.cc @@ -361,7 +361,7 @@ hb_coretext_face_create (CGFontRef cg_font) * 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. * - * Since: 0.9.10 + * XSince: REPLACEME */ hb_face_t * hb_coretext_face_create_from_file_or_fail (const char *file_name, diff --git a/src/hb-ft.cc b/src/hb-ft.cc index f6d8bf413..c84946595 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -1469,6 +1469,43 @@ get_ft_library () return static_ft_library.get_unconst (); } +/** + * hb_ft_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_for_from_file_or_fail(), + * but uses the FreeType 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_ft_face_create_from_file_or_fail (const char *file_name, + unsigned int index) +{ + FT_Face ft_face; + FT_Error error = FT_New_Face (get_ft_library (), + file_name, + index, + &ft_face); + if (error) + return nullptr; + + hb_face_t *face = hb_ft_face_create_referenced (ft_face); + FT_Done_Face (ft_face); + + if (hb_face_is_immutable (face)) + return nullptr; + + return face; +} + static void _release_blob (void *arg) { diff --git a/src/hb-ft.h b/src/hb-ft.h index 6a8a7abe8..8cf14dc39 100644 --- a/src/hb-ft.h +++ b/src/hb-ft.h @@ -84,6 +84,9 @@ hb_ft_face_create_cached (FT_Face ft_face); HB_EXTERN hb_face_t * hb_ft_face_create_referenced (FT_Face ft_face); +HB_EXTERN hb_face_t * +hb_ft_face_create_from_file_or_fail (const char *file_name, + unsigned int index); /* * hb-font from ft-face.