[subset] Add hb_subset_or_fail () to public subset api.

This commit is contained in:
Garret Rieger 2021-06-09 16:33:50 -07:00
parent aba2e13141
commit 668f2bd93e
3 changed files with 29 additions and 6 deletions

View File

@ -304,13 +304,31 @@ _subset_table (hb_subset_plan_t *plan, hb_tag_t tag)
**/ **/
hb_face_t * hb_face_t *
hb_subset (hb_face_t *source, const hb_subset_input_t *input) hb_subset (hb_face_t *source, const hb_subset_input_t *input)
{
hb_face_t* result = hb_subset_or_fail (source, input);
if (unlikely (!result)) return hb_face_get_empty ();
return result;
}
/**
* hb_subset_or_fail:
* @source: font face data to be subset.
* @input: input to use for the subsetting.
*
* Subsets a font according to provided input. Returns nullptr
* if the subset operation fails.
*
* Since: REPLACE
**/
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 hb_face_get_empty ();
hb_subset_plan_t *plan = hb_subset_plan_create (source, input); hb_subset_plan_t *plan = hb_subset_plan_create (source, input);
if (unlikely (plan->in_error ())) { if (unlikely (plan->in_error ())) {
hb_subset_plan_destroy (plan); hb_subset_plan_destroy (plan);
return hb_face_get_empty (); return nullptr;
} }
hb_set_t tags_set; hb_set_t tags_set;
@ -331,7 +349,7 @@ hb_subset (hb_face_t *source, const hb_subset_input_t *input)
} }
end: end:
hb_face_t *result = success ? hb_face_reference (plan->dest) : hb_face_get_empty (); hb_face_t *result = success ? hb_face_reference (plan->dest) : nullptr;
hb_subset_plan_destroy (plan); hb_subset_plan_destroy (plan);
return result; return result;

View File

@ -118,6 +118,9 @@ hb_subset_input_get_no_prune_unicode_ranges (hb_subset_input_t *subset_input);
HB_EXTERN hb_face_t * HB_EXTERN hb_face_t *
hb_subset (hb_face_t *source, const hb_subset_input_t *input); hb_subset (hb_face_t *source, const hb_subset_input_t *input);
HB_EXTERN hb_face_t *
hb_subset_or_fail (hb_face_t *source, const hb_subset_input_t *input);
HB_EXTERN hb_bool_t HB_EXTERN hb_bool_t
hb_subset_input_set_user_data (hb_subset_input_t *input, hb_subset_input_set_user_data (hb_subset_input_t *input,
hb_user_data_key_t *key, hb_user_data_key_t *key,

View File

@ -101,16 +101,18 @@ struct subset_consumer_t
hb_face_t *new_face = nullptr; hb_face_t *new_face = nullptr;
for (unsigned i = 0; i < subset_options.num_iterations; i++) { for (unsigned i = 0; i < subset_options.num_iterations; i++) {
hb_face_destroy (new_face); hb_face_destroy (new_face);
new_face = hb_subset (face, input); new_face = hb_subset_or_fail (face, input);
} }
hb_blob_t *result = hb_face_reference_blob (new_face);
failed = !hb_blob_get_length (result); failed = !new_face;
if (!failed) if (!failed)
{
hb_blob_t *result = hb_face_reference_blob (new_face);
write_file (options.output_file, result); write_file (options.output_file, result);
hb_blob_destroy (result);
}
hb_subset_input_destroy (input); hb_subset_input_destroy (input);
hb_blob_destroy (result);
hb_face_destroy (new_face); hb_face_destroy (new_face);
hb_font_destroy (font); hb_font_destroy (font);
} }