From 69e443b254fceb29f26f6a0c0129fe3c93c19cfb Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Tue, 20 Feb 2018 14:29:21 -0800 Subject: [PATCH] [subset] Switch to hb_blob_copy_writable_or_fail in glyf subsetting. --- src/hb-ot-glyf-table.hh | 29 +++++++++++------------------ src/hb-ot-maxp-table.hh | 3 +-- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 454b4e68..50a71115 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -104,25 +104,18 @@ struct glyf _add_head_and_set_loca_version (hb_face_t *source, bool use_short_loca, hb_face_t *dest) { hb_blob_t *head_blob = OT::Sanitizer().sanitize (hb_face_reference_table (source, HB_OT_TAG_head)); - const OT::head *head = OT::Sanitizer::lock_instance (head_blob); - hb_bool_t has_head = (head != nullptr); - - if (has_head) { - OT::head *head_prime = (OT::head *) malloc (OT::head::static_size); - memcpy (head_prime, head, OT::head::static_size); - head_prime->indexToLocFormat.set (use_short_loca ? 0 : 1); - - hb_blob_t *head_prime_blob = hb_blob_create ((const char*) head_prime, - OT::head::static_size, - HB_MEMORY_MODE_READONLY, - head_prime, - free); - has_head = hb_subset_face_add_table (dest, HB_OT_TAG_head, head_prime_blob); - hb_blob_destroy (head_prime_blob); - } - + hb_blob_t *head_prime_blob = hb_blob_copy_writable_or_fail (head_blob); hb_blob_destroy (head_blob); - return has_head; + + if (unlikely (!head_prime_blob)) + return false; + + OT::head *head_prime = (OT::head *) hb_blob_get_data_writable (head_prime_blob, nullptr); + head_prime->indexToLocFormat.set (use_short_loca ? 0 : 1); + bool success = hb_subset_face_add_table (dest, HB_OT_TAG_head, head_prime_blob); + + hb_blob_destroy (head_prime_blob); + return success; } struct GlyphHeader diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh index 3ffa57b1..12929229 100644 --- a/src/hb-ot-maxp-table.hh +++ b/src/hb-ot-maxp-table.hh @@ -70,8 +70,7 @@ struct maxp if (unlikely (!maxp_prime_blob)) { return false; } - unsigned int length; - OT::maxp *maxp_prime = (OT::maxp *) hb_blob_get_data (maxp_prime_blob, &length); + OT::maxp *maxp_prime = (OT::maxp *) hb_blob_get_data (maxp_prime_blob, nullptr); maxp_prime->set_num_glyphs (plan->gids_to_retain_sorted.len); -- GitLab