[subset] Fail if source face has no glyphs

Also return nullptr if any of the input pointers are nullptr.
Before we were returning the empty face.

Fixes https://github.com/harfbuzz/harfbuzz/issues/4824
This commit is contained in:
Behdad Esfahbod committed 2024-08-06 06:50:54 -06:00
1 parent 31f1d25e2a
commit e0c3cbf16c
2 files changed
+10 -5

No files matched your search

+8 -2
View File
@@ -594,14 +594,20 @@ static void _attach_accelerator_data (hb_subset_plan_t* plan,
* @input: input to use for the subsetting.
*
* Subsets a font according to provided input. Returns nullptr
* if the subset operation fails.
* if the subset operation fails or the face has no glyphs.
*
* Since: 2.9.0
**/
hb_face_t *
hb_subset_or_fail (hb_face_t *source, const hb_subset_input_t *input)
{
if (unlikely (!input || !source)) return hb_face_get_empty ();
if (unlikely (!input || !source)) return nullptr;
if (unlikely (!source->get_num_glyphs ()))
{
DEBUG_MSG (SUBSET, nullptr, "No glyphs in source font.");
return nullptr;
}
hb_subset_plan_t *plan = hb_subset_plan_create_or_fail (source, input);
if (unlikely (!plan)) {
+2 -3
View File
@@ -43,8 +43,7 @@ test_subset_32_tables (void)
hb_set_add (codepoints, 'c');
subset = hb_subset_or_fail (face, input);
g_assert (subset);
g_assert (subset != hb_face_get_empty ());
g_assert (!subset);
hb_subset_input_destroy (input);
hb_face_destroy (subset);
@@ -194,7 +193,7 @@ test_subset_plan (void)
}
static hb_blob_t*
_ref_table (hb_face_t *face, hb_tag_t tag, void *user_data)
_ref_table (hb_face_t *, hb_tag_t tag, void *user_data)
{
return hb_face_reference_table ((hb_face_t*) user_data, tag);
}