diff --git a/src/hb-blob.hh b/src/hb-blob.hh index 1f7499fbf..08afd5622 100644 --- a/src/hb-blob.hh +++ b/src/hb-blob.hh @@ -80,4 +80,27 @@ struct hb_blob_t DECLARE_NULL_INSTANCE (hb_blob_t); +/* + * hb_blob_ptr_t + */ + +template +struct hb_blob_ptr_t +{ + typedef typename hb_remove_pointer

::value T; + + inline hb_blob_ptr_t (hb_blob_t *b_ = nullptr) : b (b_) {} + inline hb_blob_t * operator = (hb_blob_t *b_) { return b = b_; } + inline const T * operator -> (void) const { return get (); } + inline const T & operator * (void) const { return *get (); } + template inline operator const C * (void) const { return get (); } + inline operator const char * (void) const { return (const char *) get (); } + inline const T * get (void) const { return b->as (); } + inline hb_blob_t * get_blob (void) const { return b.get_raw (); } + inline unsigned int get_length (void) const { return get_blob ()->length; } + + hb_nonnull_ptr_t b; +}; + + #endif /* HB_BLOB_HH */ diff --git a/src/hb-ot-layout-gdef-table.hh b/src/hb-ot-layout-gdef-table.hh index af7e5a833..aa6ffc884 100644 --- a/src/hb-ot-layout-gdef-table.hh +++ b/src/hb-ot-layout-gdef-table.hh @@ -412,11 +412,10 @@ struct GDEF inline void fini (void) { - hb_blob_destroy (this->blob); + hb_blob_destroy (this->table.get_blob ()); } - hb_blob_t *blob; - hb_nonnull_ptr_t table; + hb_blob_ptr_t table; }; inline unsigned int get_size (void) const diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index eccbcf420..2a89d495e 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -2752,8 +2752,7 @@ struct GSUBGPOS { inline void init (hb_face_t *face) { - this->blob = hb_sanitize_context_t().reference_table (face); - table = this->blob->template as (); + this->table = hb_sanitize_context_t().reference_table (face); this->lookup_count = table->get_lookup_count (); @@ -2770,11 +2769,10 @@ struct GSUBGPOS for (unsigned int i = 0; i < this->lookup_count; i++) this->accels[i].fini (); free (this->accels); - hb_blob_destroy (this->blob); + hb_blob_destroy (this->table.get_blob ()); } - hb_blob_t *blob; - hb_nonnull_ptr_t table; + hb_blob_ptr_t table; unsigned int lookup_count; hb_ot_layout_lookup_accelerator_t *accels; }; diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 0353c1c50..ec2421e3f 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -194,17 +194,15 @@ _hb_ot_blacklist_gdef (unsigned int gdef_len, void OT::GDEF::accelerator_t::init (hb_face_t *face) { - this->blob = hb_sanitize_context_t().reference_table (face); + this->table = hb_sanitize_context_t().reference_table (face); - if (unlikely (_hb_ot_blacklist_gdef (this->blob->length, - face->table.GSUB->blob->length, - face->table.GPOS->blob->length))) + if (unlikely (_hb_ot_blacklist_gdef (this->table.get_length (), + face->table.GSUB->table.get_length (), + face->table.GPOS->table.get_length ()))) { - hb_blob_destroy (this->blob); - this->blob = hb_blob_get_empty (); + hb_blob_destroy (this->table.get_blob ()); + this->table = hb_blob_get_empty (); } - - table = this->blob->as (); } static void diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh index f1e785f19..5aa068136 100644 --- a/src/hb-ot-name-table.hh +++ b/src/hb-ot-name-table.hh @@ -179,11 +179,10 @@ struct name { inline void init (hb_face_t *face) { - this->blob = hb_sanitize_context_t().reference_table (face); - this->table = this->blob->as (); - assert (this->blob->length >= this->table->stringOffset); + this->table = hb_sanitize_context_t().reference_table (face); + assert (this->table.get_length () >= this->table->stringOffset); this->pool = (this->table+this->table->stringOffset).arrayZ; - this->pool_len = this->blob->length - this->table->stringOffset; + this->pool_len = this->table.get_length () - this->table->stringOffset; const hb_array_t all_names (this->table->nameRecordZ.arrayZ, this->table->count); @@ -221,7 +220,7 @@ struct name inline void fini (void) { this->names.fini (); - hb_blob_destroy (this->blob); + hb_blob_destroy (this->table.get_blob ()); } inline int get_index (hb_ot_name_id_t name_id, @@ -253,11 +252,10 @@ struct name } private: - hb_blob_t *blob; const void *pool; unsigned int pool_len; public: - hb_nonnull_ptr_t table; + hb_blob_ptr_t table; hb_vector_t names; };