From 0b0fad3ea8888d57d1e077077f5897d1901c5371 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 00:26:55 -0500 Subject: [PATCH] [color] Port to hb_blob_ptr_t Fix hb_blob_ptr_t::get_length () as well. --- src/hb-blob.hh | 2 +- src/hb-ot-color-cbdt-table.hh | 38 ++++++++++++----------------------- src/hb-ot-color-sbix-table.hh | 10 ++++----- src/hb-ot-color-svg-table.hh | 11 +++++----- src/hb-ot-glyf-table.hh | 22 ++++++++------------ 5 files changed, 31 insertions(+), 52 deletions(-) diff --git a/src/hb-blob.hh b/src/hb-blob.hh index 7007540c3..1b7d4bed9 100644 --- a/src/hb-blob.hh +++ b/src/hb-blob.hh @@ -96,7 +96,7 @@ struct hb_blob_ptr_t 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; } + inline unsigned int get_length (void) const { return b.get ()->length; } hb_nonnull_ptr_t b; }; diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh index 580dc3769..0a8f4e1ab 100644 --- a/src/hb-ot-color-cbdt-table.hh +++ b/src/hb-ot-color-cbdt-table.hh @@ -384,26 +384,16 @@ struct CBDT { inline void init (hb_face_t *face) { + cblc = hb_sanitize_context_t().reference_table (face); + cbdt = hb_sanitize_context_t().reference_table (face); + upem = hb_face_get_upem (face); - - cblc_blob = hb_sanitize_context_t().reference_table (face); - cbdt_blob = hb_sanitize_context_t().reference_table (face); - cbdt_len = hb_blob_get_length (cbdt_blob); - - if (hb_blob_get_length (cblc_blob) == 0) { - cblc = nullptr; - cbdt = nullptr; - return; /* Not a bitmap font. */ - } - cblc = cblc_blob->as (); - cbdt = cbdt_blob->as (); - } inline void fini (void) { - hb_blob_destroy (this->cblc_blob); - hb_blob_destroy (this->cbdt_blob); + hb_blob_destroy (this->cblc.get_blob ()); + hb_blob_destroy (this->cbdt.get_blob ()); } inline bool get_extents (hb_font_t *font, hb_codepoint_t glyph, @@ -423,6 +413,7 @@ struct CBDT return false; { + unsigned int cbdt_len = cbdt.get_length (); if (unlikely (image_offset > cbdt_len || cbdt_len - image_offset < image_length)) return false; @@ -475,6 +466,7 @@ struct CBDT return hb_blob_get_empty (); { + unsigned int cbdt_len = cbdt.get_length (); if (unlikely (image_offset > cbdt_len || cbdt_len - image_offset < image_length)) return hb_blob_get_empty (); @@ -485,7 +477,7 @@ struct CBDT return hb_blob_get_empty (); const GlyphBitmapDataFormat17& glyphFormat17 = StructAtOffset (this->cbdt, image_offset); - return hb_blob_create_sub_blob (cbdt_blob, + return hb_blob_create_sub_blob (cbdt.get_blob (), image_offset + GlyphBitmapDataFormat17::min_size, glyphFormat17.data.len); } @@ -494,7 +486,7 @@ struct CBDT return hb_blob_get_empty (); const GlyphBitmapDataFormat18& glyphFormat18 = StructAtOffset (this->cbdt, image_offset); - return hb_blob_create_sub_blob (cbdt_blob, + return hb_blob_create_sub_blob (cbdt.get_blob (), image_offset + GlyphBitmapDataFormat18::min_size, glyphFormat18.data.len); } @@ -503,7 +495,7 @@ struct CBDT return hb_blob_get_empty (); const GlyphBitmapDataFormat19& glyphFormat19 = StructAtOffset (this->cbdt, image_offset); - return hb_blob_create_sub_blob (cbdt_blob, + return hb_blob_create_sub_blob (cbdt.get_blob (), image_offset + GlyphBitmapDataFormat19::min_size, glyphFormat19.data.len); } @@ -513,16 +505,12 @@ struct CBDT return hb_blob_get_empty (); } - inline bool has_data () const - { return cbdt_len; } + inline bool has_data () const { return cbdt.get_length (); } private: - hb_blob_t *cblc_blob; - hb_blob_t *cbdt_blob; - hb_nonnull_ptr_t cblc; - hb_nonnull_ptr_t cbdt; + hb_blob_ptr_t cblc; + hb_blob_ptr_t cbdt; - unsigned int cbdt_len; unsigned int upem; }; diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index 7a01d14ae..64ebb63e9 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -140,14 +140,13 @@ struct sbix { inline void init (hb_face_t *face) { - sbix_blob = hb_sanitize_context_t().reference_table (face); - table = sbix_blob->as (); + table = hb_sanitize_context_t().reference_table (face); num_glyphs = face->get_num_glyphs (); } inline void fini (void) { - hb_blob_destroy (sbix_blob); + hb_blob_destroy (table.get_blob ()); } inline bool has_data () const @@ -169,7 +168,7 @@ struct sbix int *y_offset, unsigned int *available_ppem) const { - return choose_strike (font).get_glyph_blob (glyph_id, sbix_blob, + return choose_strike (font).get_glyph_blob (glyph_id, table.get_blob (), HB_TAG ('p','n','g',' '), x_offset, y_offset, num_glyphs, available_ppem); @@ -263,8 +262,7 @@ struct sbix } private: - hb_blob_t *sbix_blob; - hb_nonnull_ptr_t table; + hb_blob_ptr_t table; unsigned int num_glyphs; }; diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh index 069c54788..37b28ea68 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh @@ -81,25 +81,24 @@ struct SVG { inline void init (hb_face_t *face) { - svg_blob = hb_sanitize_context_t().reference_table (face); - table = svg_blob->as (); + table = hb_sanitize_context_t().reference_table (face); } inline void fini (void) { - hb_blob_destroy (svg_blob); + hb_blob_destroy (table.get_blob ()); } inline hb_blob_t *reference_blob_for_glyph (hb_codepoint_t glyph_id) const { - return table->get_glyph_entry (glyph_id).reference_blob (svg_blob, table->svgDocEntries); + return table->get_glyph_entry (glyph_id).reference_blob (table.get_blob (), + table->svgDocEntries); } inline bool has_data () const { return table->has_data (); } private: - hb_blob_t *svg_blob; - hb_nonnull_ptr_t table; + hb_blob_ptr_t table; }; inline const SVGDocumentIndexEntry &get_glyph_entry (hb_codepoint_t glyph_id) const diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 0623be892..43b921e2c 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -246,19 +246,16 @@ struct glyf short_offset = 0 == head_table->indexToLocFormat; hb_blob_destroy (head_blob); - loca_blob = hb_sanitize_context_t().reference_table (face); - loca_table = loca_blob->as (); - glyf_blob = hb_sanitize_context_t().reference_table (face); - glyf_table = glyf_blob->as (); + loca_table = hb_sanitize_context_t().reference_table (face); + glyf_table = hb_sanitize_context_t().reference_table (face); - num_glyphs = MAX (1u, hb_blob_get_length (loca_blob) / (short_offset ? 2 : 4)) - 1; - glyf_len = hb_blob_get_length (glyf_blob); + num_glyphs = MAX (1u, loca_table.get_length () / (short_offset ? 2 : 4)) - 1; } inline void fini (void) { - hb_blob_destroy (loca_blob); - hb_blob_destroy (glyf_blob); + hb_blob_destroy (loca_table.get_blob ()); + hb_blob_destroy (glyf_table.get_blob ()); } /* @@ -388,7 +385,7 @@ struct glyf *end_offset = offsets[glyph + 1]; } - if (*start_offset > *end_offset || *end_offset > glyf_len) + if (*start_offset > *end_offset || *end_offset > glyf_table.get_length ()) return false; return true; @@ -476,11 +473,8 @@ struct glyf private: bool short_offset; unsigned int num_glyphs; - hb_nonnull_ptr_t loca_table; - hb_nonnull_ptr_t glyf_table; - hb_blob_t *loca_blob; - hb_blob_t *glyf_blob; - unsigned int glyf_len; + hb_blob_ptr_t loca_table; + hb_blob_ptr_t glyf_table; }; protected: