From 03348ce0051cfae7172ac0d09b83ed5f82fa842a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 12:59:32 -0500 Subject: [PATCH 01/37] Minor --- src/hb-aat-layout.cc | 12 ++++++------ src/hb-ot-color.cc | 10 +++++----- src/hb-ot-font.cc | 18 +++++++++--------- src/hb-ot-layout.cc | 2 +- src/hb-ot-math.cc | 2 +- src/hb-ot-name.cc | 2 +- src/hb-ot-var.cc | 6 ++---- 7 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index 80bf2d766..9e0eb92fa 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -181,7 +181,7 @@ _get_mort (hb_face_t *face, hb_blob_t **blob = nullptr) *blob = hb_blob_get_empty (); return Null(AAT::mort); } - const AAT::mort& mort = *(hb_ot_face_data (face)->mort.get ()); + const AAT::mort& mort = *(hb_ot_face_data (face)->mort); if (blob) *blob = hb_ot_face_data (face)->mort.get_blob (); return mort; @@ -195,7 +195,7 @@ _get_morx (hb_face_t *face, hb_blob_t **blob = nullptr) *blob = hb_blob_get_empty (); return Null(AAT::morx); } - const AAT::morx& morx = *(hb_ot_face_data (face)->morx.get ()); + const AAT::morx& morx = *(hb_ot_face_data (face)->morx); if (blob) *blob = hb_ot_face_data (face)->morx.get_blob (); return morx; @@ -209,7 +209,7 @@ _get_kerx (hb_face_t *face, hb_blob_t **blob = nullptr) *blob = hb_blob_get_empty (); return Null(AAT::kerx); } - const AAT::kerx& kerx = *(hb_ot_face_data (face)->kerx.get ()); + const AAT::kerx& kerx = *(hb_ot_face_data (face)->kerx); if (blob) *blob = hb_ot_face_data (face)->kerx.get_blob (); return kerx; @@ -223,7 +223,7 @@ _get_ankr (hb_face_t *face, hb_blob_t **blob = nullptr) *blob = hb_blob_get_empty (); return Null(AAT::ankr); } - const AAT::ankr& ankr = *(hb_ot_face_data (face)->ankr.get ()); + const AAT::ankr& ankr = *(hb_ot_face_data (face)->ankr); if (blob) *blob = hb_ot_face_data (face)->ankr.get_blob (); return ankr; @@ -232,13 +232,13 @@ static inline const AAT::trak& _get_trak (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(AAT::trak); - return *(hb_ot_face_data (face)->trak.get ()); + return *(hb_ot_face_data (face)->trak); } static inline const AAT::ltag& _get_ltag (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(AAT::ltag); - return *(hb_ot_face_data (face)->ltag.get ()); + return *(hb_ot_face_data (face)->ltag); } diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc index b87ed56fa..853f65dcf 100644 --- a/src/hb-ot-color.cc +++ b/src/hb-ot-color.cc @@ -54,35 +54,35 @@ static inline const OT::COLR& _get_colr (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::COLR); - return *(hb_ot_face_data (face)->COLR.get ()); + return *(hb_ot_face_data (face)->COLR); } static inline const OT::CBDT_accelerator_t& _get_cbdt (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::CBDT_accelerator_t); - return *(hb_ot_face_data (face)->CBDT.get ()); + return *(hb_ot_face_data (face)->CBDT); } static inline const OT::CPAL& _get_cpal (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::CPAL); - return *(hb_ot_face_data (face)->CPAL.get ()); + return *(hb_ot_face_data (face)->CPAL); } static inline const OT::sbix_accelerator_t& _get_sbix (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::sbix_accelerator_t); - return *(hb_ot_face_data (face)->sbix.get ()); + return *(hb_ot_face_data (face)->sbix); } static inline const OT::SVG_accelerator_t& _get_svg (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::SVG_accelerator_t); - return *(hb_ot_face_data (face)->SVG.get ()); + return *(hb_ot_face_data (face)->SVG); } diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 33a4388ce..41bea1405 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -62,7 +62,7 @@ hb_ot_get_nominal_glyph (hb_font_t *font HB_UNUSED, void *user_data HB_UNUSED) { const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; - return ot_face->cmap.get ()->get_nominal_glyph (unicode, glyph); + return ot_face->cmap->get_nominal_glyph (unicode, glyph); } static unsigned int @@ -76,7 +76,7 @@ hb_ot_get_nominal_glyphs (hb_font_t *font HB_UNUSED, void *user_data HB_UNUSED) { const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; - const OT::cmap_accelerator_t &cmap = *ot_face->cmap.get (); + const OT::cmap_accelerator_t &cmap = *ot_face->cmap; unsigned int done; for (done = 0; done < count && cmap.get_nominal_glyph (*first_unicode, first_glyph); @@ -97,7 +97,7 @@ hb_ot_get_variation_glyph (hb_font_t *font HB_UNUSED, void *user_data HB_UNUSED) { const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; - return ot_face->cmap.get ()->get_variation_glyph (unicode, variation_selector, glyph); + return ot_face->cmap->get_variation_glyph (unicode, variation_selector, glyph); } static void @@ -110,7 +110,7 @@ hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data, void *user_data HB_UNUSED) { const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; - const OT::hmtx_accelerator_t &hmtx = *ot_face->hmtx.get (); + const OT::hmtx_accelerator_t &hmtx = *ot_face->hmtx; for (unsigned int i = 0; i < count; i++) { @@ -130,7 +130,7 @@ hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data, void *user_data HB_UNUSED) { const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; - const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx.get (); + const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx; for (unsigned int i = 0; i < count; i++) { @@ -152,7 +152,7 @@ hb_ot_get_glyph_v_origin (hb_font_t *font, *x = font->get_glyph_h_advance (glyph) / 2; - const OT::VORG &VORG = *ot_face->VORG.get (); + const OT::VORG &VORG = *ot_face->VORG; if (VORG.has_data ()) { *y = font->em_scale_y (VORG.get_y_origin (glyph)); @@ -162,7 +162,7 @@ hb_ot_get_glyph_v_origin (hb_font_t *font, hb_glyph_extents_t extents = {0}; if (ot_face->glyf->get_extents (glyph, &extents)) { - const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx.get (); + const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx; hb_position_t tsb = vmtx.get_side_bearing (glyph); *y = font->em_scale_y (extents.y_bearing + tsb); return true; @@ -225,7 +225,7 @@ hb_ot_get_font_h_extents (hb_font_t *font, void *user_data HB_UNUSED) { const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; - const OT::hmtx_accelerator_t &hmtx = *ot_face->hmtx.get (); + const OT::hmtx_accelerator_t &hmtx = *ot_face->hmtx; metrics->ascender = font->em_scale_y (hmtx.ascender); metrics->descender = font->em_scale_y (hmtx.descender); metrics->line_gap = font->em_scale_y (hmtx.line_gap); @@ -240,7 +240,7 @@ hb_ot_get_font_v_extents (hb_font_t *font, void *user_data HB_UNUSED) { const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; - const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx.get (); + const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx; metrics->ascender = font->em_scale_x (vmtx.ascender); metrics->descender = font->em_scale_x (vmtx.descender); metrics->line_gap = font->em_scale_x (vmtx.line_gap); diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index f1f09c76d..fcdc79ee9 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -62,7 +62,7 @@ _get_kern (hb_face_t *face, hb_blob_t **blob = nullptr) *blob = hb_blob_get_empty (); return Null(OT::kern); } - const OT::kern& kern = *(hb_ot_face_data (face)->kern.get ()); + const OT::kern& kern = *(hb_ot_face_data (face)->kern); if (blob) *blob = hb_ot_face_data (face)->kern.get_blob (); return kern; diff --git a/src/hb-ot-math.cc b/src/hb-ot-math.cc index 92c29480d..3fb720b20 100644 --- a/src/hb-ot-math.cc +++ b/src/hb-ot-math.cc @@ -45,7 +45,7 @@ _get_math (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::MATH); hb_ot_face_data_t * data = hb_ot_face_data (face); - return *(data->MATH.get ()); + return *(data->MATH); } /* diff --git a/src/hb-ot-name.cc b/src/hb-ot-name.cc index f5ac18d79..f2d1f0c2f 100644 --- a/src/hb-ot-name.cc +++ b/src/hb-ot-name.cc @@ -46,7 +46,7 @@ static inline const OT::name_accelerator_t& _get_name (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::name_accelerator_t); - return *(hb_ot_face_data (face)->name.get ()); + return *(hb_ot_face_data (face)->name); } /** diff --git a/src/hb-ot-var.cc b/src/hb-ot-var.cc index 64087be81..4363f85ee 100644 --- a/src/hb-ot-var.cc +++ b/src/hb-ot-var.cc @@ -51,15 +51,13 @@ static inline const OT::fvar& _get_fvar (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::fvar); - hb_ot_face_data_t *layout = hb_ot_face_data (face); - return *(layout->fvar.get ()); + return *(hb_ot_face_data (face)->fvar); } static inline const OT::avar& _get_avar (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::avar); - hb_ot_face_data_t *layout = hb_ot_face_data (face); - return *(layout->avar.get ()); + return *(hb_ot_face_data (face)->avar); } /** From 0da22fb0ada8a54fc59739057f281a406a993212 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 13:13:39 -0500 Subject: [PATCH 02/37] [null] Tweak hb_nonnull_ptr_t some more --- src/hb-null.hh | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/hb-null.hh b/src/hb-null.hh index c91af1636..25a24f05c 100644 --- a/src/hb-null.hh +++ b/src/hb-null.hh @@ -114,20 +114,14 @@ struct hb_nonnull_ptr_t inline hb_nonnull_ptr_t (T *v_ = nullptr) : v (v_) {} inline T * operator = (T *v_) { return v = v_; } - inline T * operator -> (void) { return get (); } - inline const T * operator -> (void) const { return get (); } - inline T & operator * (void) { return *get (); } - inline const T & operator * (void) const { return *get (); } - inline T ** operator & (void) { return &v; } - inline const T ** operator & (void) const { return &v; } - template inline operator C * (void) { return get (); } + inline T * operator -> (void) const { return get (); } + inline T & operator * (void) const { return *get (); } + inline T ** operator & (void) const { return &v; } + /* Only auto-cast to const types. */ template inline operator const C * (void) const { return get (); } - inline operator char * (void) { return (char *) get (); } inline operator const char * (void) const { return (const char *) get (); } - inline T * get (void) { return v ? v : const_cast (&Null(T)); } - inline const T * get (void) const { return v ? v : const_cast (&Null(T)); } - inline T * get_raw (void) { return v; } - inline const T * get_raw (void) const { return v; } + inline T * get (void) const { return v ? v : const_cast (&Null(T)); } + inline T * get_raw (void) const { return v; } T *v; }; From f6e7cb51b13aabb447dc97a59602d65eb42edc4b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 13:23:07 -0500 Subject: [PATCH 03/37] Fix const-confusion in hb_array_t as well --- src/hb-dsalgs.hh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index f2bff063d..9ccd7f255 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -553,11 +553,9 @@ struct hb_array_t inline unsigned int get_size (void) const { return len * sizeof (Type); } - template inline operator T * (void) { return arrayZ; } - template inline operator const T * (void) const { return arrayZ; } + template inline operator T * (void) const { return arrayZ; } - inline Type * operator & (void) { return arrayZ; } - inline const Type * operator & (void) const { return arrayZ; } + inline Type * operator & (void) const { return arrayZ; } inline hb_array_t sub_array (unsigned int start_offset, unsigned int seg_count) const { From f6fc5574d3dae177a54b10195e0d1f368a74f768 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 13:23:54 -0500 Subject: [PATCH 04/37] Add pointer magic operators to hb_atomic_ptr_t --- src/hb-atomic.hh | 3 +++ src/hb-common.cc | 6 +++--- src/hb-face.cc | 2 +- src/hb-graphite2.cc | 8 ++++---- src/hb-machinery.hh | 1 + src/hb-ot-shape-complex-arabic.cc | 4 ++-- src/hb-shape-plan.cc | 2 +- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/hb-atomic.hh b/src/hb-atomic.hh index 697de19c5..49c2809e2 100644 --- a/src/hb-atomic.hh +++ b/src/hb-atomic.hh @@ -290,6 +290,9 @@ struct hb_atomic_ptr_t inline T *get (void) const { return (T *) hb_atomic_ptr_impl_get ((void **) &v); } inline bool cmpexch (const T *old, T *new_) const { return hb_atomic_ptr_impl_cmpexch ((void **) &v, (void *) old, (void *) new_); } + inline T * operator -> (void) const { return get (); } + template inline operator C * (void) const { return get (); } + mutable T *v; }; diff --git a/src/hb-common.cc b/src/hb-common.cc index d7c1921f3..37be8a34e 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -281,7 +281,7 @@ static void free_langs (void) { retry: - hb_language_item_t *first_lang = langs.get (); + hb_language_item_t *first_lang = langs; if (unlikely (!langs.cmpexch (first_lang, nullptr))) goto retry; @@ -298,7 +298,7 @@ static hb_language_item_t * lang_find_or_insert (const char *key) { retry: - hb_language_item_t *first_lang = langs.get (); + hb_language_item_t *first_lang = langs; for (hb_language_item_t *lang = first_lang; lang; lang = lang->next) if (*lang == key) @@ -408,7 +408,7 @@ hb_language_get_default (void) { static hb_atomic_ptr_t default_language; - hb_language_t language = default_language.get (); + hb_language_t language = default_language; if (unlikely (language == HB_LANGUAGE_INVALID)) { language = hb_language_from_string (setlocale (LC_CTYPE, nullptr), -1); diff --git a/src/hb-face.cc b/src/hb-face.cc index 50ab10e38..a0f8047f3 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -263,7 +263,7 @@ hb_face_destroy (hb_face_t *face) { if (!hb_object_destroy (face)) return; - for (hb_face_t::plan_node_t *node = face->shape_plans.get (); node; ) + for (hb_face_t::plan_node_t *node = face->shape_plans; node; ) { hb_face_t::plan_node_t *next = node->next; hb_shape_plan_destroy (node->shape_plan); diff --git a/src/hb-graphite2.cc b/src/hb-graphite2.cc index 971241f92..24ee3d507 100644 --- a/src/hb-graphite2.cc +++ b/src/hb-graphite2.cc @@ -71,7 +71,7 @@ struct hb_graphite2_face_data_t static const void *hb_graphite2_get_table (const void *data, unsigned int tag, size_t *len) { hb_graphite2_face_data_t *face_data = (hb_graphite2_face_data_t *) data; - hb_graphite2_tablelist_t *tlist = face_data->tlist.get (); + hb_graphite2_tablelist_t *tlist = face_data->tlist; hb_blob_t *blob = nullptr; @@ -94,7 +94,7 @@ static const void *hb_graphite2_get_table (const void *data, unsigned int tag, s p->tag = tag; retry: - hb_graphite2_tablelist_t *tlist = face_data->tlist.get (); + hb_graphite2_tablelist_t *tlist = face_data->tlist; p->next = tlist; if (unlikely (!face_data->tlist.cmpexch (tlist, p))) @@ -110,7 +110,7 @@ retry: static void hb_graphite2_release_table(const void *data, const void *table_buffer) { hb_graphite2_face_data_t *face_data = (hb_graphite2_face_data_t *) data; - hb_graphite2_tablelist_t *tlist = face_data->tlist.get(); + hb_graphite2_tablelist_t *tlist = face_data->tlist; hb_graphite2_tablelist_t *prev = nullptr; hb_graphite2_tablelist_t *curr = tlist; @@ -164,7 +164,7 @@ _hb_graphite2_shaper_face_data_create (hb_face_t *face) void _hb_graphite2_shaper_face_data_destroy (hb_graphite2_face_data_t *data) { - hb_graphite2_tablelist_t *tlist = data->tlist.get (); + hb_graphite2_tablelist_t *tlist = data->tlist; while (tlist) { diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index 465bbb14f..f58050da0 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -795,6 +795,7 @@ struct hb_lazy_loader_t : hb_data_wrapper_t inline const Returned * operator -> (void) const { return get (); } inline const Returned & operator * (void) const { return *get (); } + template inline operator const C * (void) const { return get (); } inline Data * get_data (void) const { diff --git a/src/hb-ot-shape-complex-arabic.cc b/src/hb-ot-shape-complex-arabic.cc index 8e56dde3d..50a52136b 100644 --- a/src/hb-ot-shape-complex-arabic.cc +++ b/src/hb-ot-shape-complex-arabic.cc @@ -279,7 +279,7 @@ data_destroy_arabic (void *data) { arabic_shape_plan_t *arabic_plan = (arabic_shape_plan_t *) data; - arabic_fallback_plan_destroy (arabic_plan->fallback_plan.get ()); + arabic_fallback_plan_destroy (arabic_plan->fallback_plan); free (data); } @@ -389,7 +389,7 @@ arabic_fallback_shape (const hb_ot_shape_plan_t *plan, return; retry: - arabic_fallback_plan_t *fallback_plan = arabic_plan->fallback_plan.get (); + arabic_fallback_plan_t *fallback_plan = arabic_plan->fallback_plan; if (unlikely (!fallback_plan)) { /* This sucks. We need a font to build the fallback plan... */ diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index 8d002f8a7..f2f210196 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc @@ -532,7 +532,7 @@ hb_shape_plan_create_cached2 (hb_face_t *face, retry: - hb_face_t::plan_node_t *cached_plan_nodes = face->shape_plans.get (); + hb_face_t::plan_node_t *cached_plan_nodes = face->shape_plans; /* Don't look for plan in the cache if there were variation coordinates XXX Fix me. */ if (!hb_coords_present (coords, num_coords)) From bb380ec18394b2c581b672ecbf98991e14897f2e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 13:45:12 -0500 Subject: [PATCH 05/37] [cmap] Make null accelerator safe Fixes https://github.com/harfbuzz/harfbuzz/issues/1146 --- src/hb-ot-cmap-table.hh | 50 ++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index a1c5a9747..bcb50790e 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -1016,40 +1016,35 @@ struct cmap { this->blob = hb_sanitize_context_t().reference_table (face); const cmap *table = this->blob->as (); - const CmapSubtableFormat14 *subtable_uvs = nullptr; bool symbol; - subtable = table->find_best_subtable (&symbol); + subtableZ = table->find_best_subtable (&symbol); /* UVS subtable. */ - if (!subtable_uvs) + subtable_uvsZ = &Null(CmapSubtableFormat14); { const CmapSubtable *st = table->find_subtable (0, 5); if (st && st->u.format == 14) - subtable_uvs = &st->u.format14; + subtable_uvsZ = &st->u.format14; } - /* Meh. */ - if (!subtable_uvs) subtable_uvs = &Null(CmapSubtableFormat14); - this->subtable_uvs = subtable_uvs; - - this->get_glyph_data = subtable; + this->get_glyph_data = subtableZ; if (unlikely (symbol)) { - this->get_glyph_func = get_glyph_from_symbol; + this->get_glyph_funcZ = get_glyph_from_symbol; } else { - switch (subtable->u.format) { + switch (subtableZ->u.format) { /* Accelerate format 4 and format 12. */ default: - this->get_glyph_func = get_glyph_from; + this->get_glyph_funcZ = get_glyph_from; break; case 12: - this->get_glyph_func = get_glyph_from; + this->get_glyph_funcZ = get_glyph_from; break; case 4: { - this->format4_accel.init (&subtable->u.format4); + this->format4_accel.init (&subtableZ->u.format4); this->get_glyph_data = &this->format4_accel; - this->get_glyph_func = this->format4_accel.get_glyph_func; + this->get_glyph_funcZ = this->format4_accel.get_glyph_func; } break; } @@ -1064,16 +1059,18 @@ struct cmap inline bool get_nominal_glyph (hb_codepoint_t unicode, hb_codepoint_t *glyph) const { - return this->get_glyph_func (this->get_glyph_data, unicode, glyph); + if (unlikely (!this->get_glyph_funcZ)) return false; + return this->get_glyph_funcZ (this->get_glyph_data, unicode, glyph); } inline bool get_variation_glyph (hb_codepoint_t unicode, hb_codepoint_t variation_selector, hb_codepoint_t *glyph) const { - switch (this->subtable_uvs->get_glyph_variant (unicode, - variation_selector, - glyph)) + if (unlikely (!this->subtable_uvsZ)) return false; + switch (this->subtable_uvsZ->get_glyph_variant (unicode, + variation_selector, + glyph)) { case GLYPH_VARIANT_NOT_FOUND: return false; case GLYPH_VARIANT_FOUND: return true; @@ -1085,16 +1082,19 @@ struct cmap inline void collect_unicodes (hb_set_t *out) const { - subtable->collect_unicodes (out); + if (unlikely (!this->subtableZ)) return; + subtableZ->collect_unicodes (out); } inline void collect_variation_selectors (hb_set_t *out) const { - subtable_uvs->collect_variation_selectors (out); + if (unlikely (!this->subtable_uvsZ)) return; + subtable_uvsZ->collect_variation_selectors (out); } inline void collect_variation_unicodes (hb_codepoint_t variation_selector, hb_set_t *out) const { - subtable_uvs->collect_variation_unicodes (variation_selector, out); + if (unlikely (!this->subtable_uvsZ)) return; + subtable_uvsZ->collect_variation_unicodes (variation_selector, out); } protected: @@ -1134,10 +1134,10 @@ struct cmap } private: - const CmapSubtable *subtable; - const CmapSubtableFormat14 *subtable_uvs; + const CmapSubtable *subtableZ; + const CmapSubtableFormat14 *subtable_uvsZ; - hb_cmap_get_glyph_func_t get_glyph_func; + hb_cmap_get_glyph_func_t get_glyph_funcZ; const void *get_glyph_data; CmapSubtableFormat4::accelerator_t format4_accel; From 252632c477b963f305116d69fcafacd8bf7b97bf Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 14:33:41 -0500 Subject: [PATCH 06/37] [uniscribe] Fix use of deprecated API --- src/hb-uniscribe.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index 26b99ed15..e77825b34 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -853,7 +853,13 @@ retry: #undef MAX_ITEMS - OPENTYPE_TAG language_tag = hb_uint32_swap (hb_ot_tag_from_language (buffer->props.language)); + hb_tag_t lang_tag; + unsigned int lang_count = 1; + hb_ot_tags_from_script_and_language (buffer->props.script, + buffer->props.language, + nullptr, nullptr, + &lang_count, &lang_tag); + OPENTYPE_TAG language_tag = hb_uint32_swap (lang_count ? lang_tag : HB_TAG_NONE); hb_vector_t range_properties; hb_vector_t range_char_counts; From 6482fda519ca7d173e3bcb3717aa30e237f04b25 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 15:03:18 -0500 Subject: [PATCH 07/37] [fuzzing] Fuzz glyph-id etc in test-ot-face --- test/api/test-ot-face.c | 57 +++++++++++++++++---------------- test/fuzzing/hb-shape-fuzzer.cc | 19 +---------- 2 files changed, 30 insertions(+), 46 deletions(-) diff --git a/test/api/test-ot-face.c b/test/api/test-ot-face.c index da23fe593..d6eefbaaf 100644 --- a/test/api/test-ot-face.c +++ b/test/api/test-ot-face.c @@ -33,7 +33,8 @@ static void -test_face (hb_face_t *face) +test_face (hb_face_t *face, + hb_codepoint_t cp) { hb_font_t *font = hb_font_create (face); hb_ot_font_set_funcs (font); @@ -41,35 +42,35 @@ test_face (hb_face_t *face) hb_set_t *set = hb_set_create (); hb_face_collect_unicodes (face, set); hb_face_collect_variation_selectors (face, set); - hb_face_collect_variation_unicodes (face, 0, set); + hb_face_collect_variation_unicodes (face, cp, set); hb_codepoint_t g; hb_position_t x, y; hb_glyph_extents_t extents; char buf[5] = {0}; - hb_font_get_nominal_glyph (font, 0, &g); - hb_font_get_variation_glyph (font, 0, 0, &g); - hb_font_get_glyph_h_advance (font, g); - hb_font_get_glyph_v_advance (font, g); - hb_font_get_glyph_h_origin (font, g, &x, &y); - hb_font_get_glyph_v_origin (font, g, &x, &y); - hb_font_get_glyph_extents (font, g, &extents); - hb_font_get_glyph_contour_point (font, g, 0, &x, &y); - hb_font_get_glyph_name (font, g, buf, sizeof (buf)); + hb_font_get_nominal_glyph (font, cp, &g); + hb_font_get_variation_glyph (font, cp, cp, &g); + hb_font_get_glyph_h_advance (font, cp); + hb_font_get_glyph_v_advance (font, cp); + hb_font_get_glyph_h_origin (font, cp, &x, &y); + hb_font_get_glyph_v_origin (font, cp, &x, &y); + hb_font_get_glyph_extents (font, cp, &extents); + hb_font_get_glyph_contour_point (font, cp, 0, &x, &y); + hb_font_get_glyph_name (font, cp, buf, sizeof (buf)); hb_font_get_glyph_from_name (font, buf, strlen (buf), &g); hb_ot_color_has_palettes (face); hb_ot_color_palette_get_count (face); - hb_ot_color_palette_get_name_id (face, 0); - hb_ot_color_palette_color_get_name_id (face, 0); - hb_ot_color_palette_get_flags (face, 0); - hb_ot_color_palette_get_colors (face, 0, 0, NULL, NULL); + hb_ot_color_palette_get_name_id (face, cp); + hb_ot_color_palette_color_get_name_id (face, cp); + hb_ot_color_palette_get_flags (face, cp); + hb_ot_color_palette_get_colors (face, cp, 0, NULL, NULL); hb_ot_color_has_layers (face); - hb_ot_color_glyph_get_layers (face, 0, 0, NULL, NULL); + hb_ot_color_glyph_get_layers (face, cp, 0, NULL, NULL); hb_ot_color_has_svg (face); - hb_blob_destroy (hb_ot_color_glyph_reference_svg (face, 0)); + hb_blob_destroy (hb_ot_color_glyph_reference_svg (face, cp)); hb_ot_color_has_png (face); - hb_blob_destroy (hb_ot_color_glyph_reference_png (font, 0)); + hb_blob_destroy (hb_ot_color_glyph_reference_png (font, cp)); hb_ot_layout_has_glyph_classes (face); hb_ot_layout_has_substitution (face); @@ -77,19 +78,19 @@ test_face (hb_face_t *face) hb_ot_math_has_data (face); hb_ot_math_get_constant (font, HB_OT_MATH_CONSTANT_MATH_LEADING); - hb_ot_math_get_glyph_italics_correction (font, 0); - hb_ot_math_get_glyph_top_accent_attachment (font, 0); - hb_ot_math_is_glyph_extended_shape (face, 0); - hb_ot_math_get_glyph_kerning (font, 0, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0); - hb_ot_math_get_glyph_variants (font, 0, HB_DIRECTION_TTB, 0, NULL, NULL); + hb_ot_math_get_glyph_italics_correction (font, cp); + hb_ot_math_get_glyph_top_accent_attachment (font, cp); + hb_ot_math_is_glyph_extended_shape (face, cp); + hb_ot_math_get_glyph_kerning (font, cp, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0); + hb_ot_math_get_glyph_variants (font, cp, HB_DIRECTION_TTB, 0, NULL, NULL); hb_ot_math_get_min_connector_overlap (font, HB_DIRECTION_RTL); - hb_ot_math_get_glyph_assembly (font, 0, HB_DIRECTION_BTT, 0, NULL, NULL, NULL); + hb_ot_math_get_glyph_assembly (font, cp, HB_DIRECTION_BTT, 0, NULL, NULL, NULL); unsigned int len = sizeof (buf); hb_ot_name_list_names (face, NULL); - hb_ot_name_get_utf8 (face, 0, NULL, &len, buf); - hb_ot_name_get_utf16 (face, 0, NULL, NULL, NULL); - hb_ot_name_get_utf32 (face, 0, NULL, NULL, NULL); + hb_ot_name_get_utf8 (face, cp, NULL, &len, buf); + hb_ot_name_get_utf16 (face, cp, NULL, NULL, NULL); + hb_ot_name_get_utf32 (face, cp, NULL, NULL, NULL); hb_ot_var_get_axis_count (face); hb_ot_var_get_axes (face, 0, NULL, NULL); @@ -104,7 +105,7 @@ test_face (hb_face_t *face) static void test_ot_face_empty (void) { - test_face (hb_face_get_empty ()); + test_face (hb_face_get_empty (), 0); } int diff --git a/test/fuzzing/hb-shape-fuzzer.cc b/test/fuzzing/hb-shape-fuzzer.cc index fedf56e20..ec69d514d 100644 --- a/test/fuzzing/hb-shape-fuzzer.cc +++ b/test/fuzzing/hb-shape-fuzzer.cc @@ -32,28 +32,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) hb_buffer_add_utf32 (buffer, text32, sizeof (text32) / sizeof (text32[0]), 0, -1); hb_buffer_guess_segment_properties (buffer); hb_shape (font, buffer, NULL, 0); - - unsigned int len = hb_buffer_get_length (buffer); - hb_glyph_info_t *infos = hb_buffer_get_glyph_infos (buffer, NULL); - //hb_glyph_position_t *positions = hb_buffer_get_glyph_positions (buffer, NULL); - for (unsigned int i = 0; i < len; i++) - { - hb_glyph_info_t info = infos[i]; - //hb_glyph_position_t pos = positions[i]; - - hb_glyph_extents_t extents; - hb_font_get_glyph_extents (font, info.codepoint, &extents); - - hb_ot_color_glyph_get_layers (face, info.codepoint, 0, nullptr, nullptr); - hb_blob_destroy (hb_ot_color_glyph_reference_svg (face, info.codepoint)); - hb_blob_destroy (hb_ot_color_glyph_reference_png (font, info.codepoint)); - } - hb_buffer_destroy (buffer); } /* Misc calls on face. */ - test_face (face); + test_face (face, text32[15]); hb_font_destroy (font); hb_face_destroy (face); From 8be74d85534534dbdd39a0a6f496e26e9f3e661d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 18:47:22 -0500 Subject: [PATCH 08/37] 2.1.1 --- NEWS | 8 ++++++++ configure.ac | 2 +- src/hb-version.h | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index cb8a28ff0..04579d685 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +Overview of changes leading to 2.1.1 +Monday, November 5, 2018 +==================================== +- AAT improvements: + o Implement 'mort' table. + o Implement 'kern' subtables Format 1 and Format 3. + + Overview of changes leading to 2.1.0 Tuesday, October 30, 2018 ==================================== diff --git a/configure.ac b/configure.ac index 21d48f39a..48ee9ce94 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ([2.64]) AC_INIT([HarfBuzz], - [2.1.0], + [2.1.1], [https://github.com/harfbuzz/harfbuzz/issues/new], [harfbuzz], [http://harfbuzz.org/]) diff --git a/src/hb-version.h b/src/hb-version.h index 68af8f864..ec150d5dd 100644 --- a/src/hb-version.h +++ b/src/hb-version.h @@ -38,9 +38,9 @@ HB_BEGIN_DECLS #define HB_VERSION_MAJOR 2 #define HB_VERSION_MINOR 1 -#define HB_VERSION_MICRO 0 +#define HB_VERSION_MICRO 1 -#define HB_VERSION_STRING "2.1.0" +#define HB_VERSION_STRING "2.1.1" #define HB_VERSION_ATLEAST(major,minor,micro) \ ((major)*10000+(minor)*100+(micro) <= \ From 36d85dce25abd079252d973f804220bf7b97e987 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 19:46:29 -0500 Subject: [PATCH 09/37] [cmap] Use hb_nonnullptr_t --- src/hb-ot-cmap-table.hh | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index bcb50790e..2013ae987 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -1017,22 +1017,20 @@ struct cmap this->blob = hb_sanitize_context_t().reference_table (face); const cmap *table = this->blob->as (); bool symbol; - subtableZ = table->find_best_subtable (&symbol); - - /* UVS subtable. */ - subtable_uvsZ = &Null(CmapSubtableFormat14); + this->subtable = table->find_best_subtable (&symbol); + this->subtable_uvs = &Null(CmapSubtableFormat14); { const CmapSubtable *st = table->find_subtable (0, 5); if (st && st->u.format == 14) - subtable_uvsZ = &st->u.format14; + subtable_uvs = &st->u.format14; } - this->get_glyph_data = subtableZ; + this->get_glyph_data = subtable; if (unlikely (symbol)) { this->get_glyph_funcZ = get_glyph_from_symbol; } else { - switch (subtableZ->u.format) { + switch (subtable->u.format) { /* Accelerate format 4 and format 12. */ default: this->get_glyph_funcZ = get_glyph_from; @@ -1042,7 +1040,7 @@ struct cmap break; case 4: { - this->format4_accel.init (&subtableZ->u.format4); + this->format4_accel.init (&subtable->u.format4); this->get_glyph_data = &this->format4_accel; this->get_glyph_funcZ = this->format4_accel.get_glyph_func; } @@ -1067,10 +1065,9 @@ struct cmap hb_codepoint_t variation_selector, hb_codepoint_t *glyph) const { - if (unlikely (!this->subtable_uvsZ)) return false; - switch (this->subtable_uvsZ->get_glyph_variant (unicode, - variation_selector, - glyph)) + switch (this->subtable_uvs->get_glyph_variant (unicode, + variation_selector, + glyph)) { case GLYPH_VARIANT_NOT_FOUND: return false; case GLYPH_VARIANT_FOUND: return true; @@ -1082,19 +1079,16 @@ struct cmap inline void collect_unicodes (hb_set_t *out) const { - if (unlikely (!this->subtableZ)) return; - subtableZ->collect_unicodes (out); + subtable->collect_unicodes (out); } inline void collect_variation_selectors (hb_set_t *out) const { - if (unlikely (!this->subtable_uvsZ)) return; - subtable_uvsZ->collect_variation_selectors (out); + subtable_uvs->collect_variation_selectors (out); } inline void collect_variation_unicodes (hb_codepoint_t variation_selector, hb_set_t *out) const { - if (unlikely (!this->subtable_uvsZ)) return; - subtable_uvsZ->collect_variation_unicodes (variation_selector, out); + subtable_uvs->collect_variation_unicodes (variation_selector, out); } protected: @@ -1134,8 +1128,8 @@ struct cmap } private: - const CmapSubtable *subtableZ; - const CmapSubtableFormat14 *subtable_uvsZ; + hb_nonnull_ptr_t subtable; + hb_nonnull_ptr_t subtable_uvs; hb_cmap_get_glyph_func_t get_glyph_funcZ; const void *get_glyph_data; From 56ba998cddbb2ba5d24fb0b02d2bf77a46c0f23f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 19:49:54 -0500 Subject: [PATCH 10/37] [cmap] Push get_nominal_glyphs down into cmap accelerator --- src/hb-ot-cmap-table.hh | 21 +++++++++++++++++++++ src/hb-ot-font.cc | 13 +++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 2013ae987..399c46bfc 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -1060,6 +1060,27 @@ struct cmap if (unlikely (!this->get_glyph_funcZ)) return false; return this->get_glyph_funcZ (this->get_glyph_data, unicode, glyph); } + inline unsigned int get_nominal_glyphs (unsigned int count, + const hb_codepoint_t *first_unicode, + unsigned int unicode_stride, + hb_codepoint_t *first_glyph, + unsigned int glyph_stride) const + { + if (unlikely (!this->get_glyph_funcZ)) return 0; + + hb_cmap_get_glyph_func_t get_glyph_funcZ = this->get_glyph_funcZ; + const void *get_glyph_data = this->get_glyph_data; + + unsigned int done; + for (done = 0; + done < count && get_glyph_funcZ (get_glyph_data, *first_unicode, first_glyph); + done++) + { + first_unicode = &StructAtOffset (first_unicode, unicode_stride); + first_glyph = &StructAtOffset (first_glyph, glyph_stride); + } + return done; + } inline bool get_variation_glyph (hb_codepoint_t unicode, hb_codepoint_t variation_selector, diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 41bea1405..3e2f1f656 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -76,16 +76,9 @@ hb_ot_get_nominal_glyphs (hb_font_t *font HB_UNUSED, void *user_data HB_UNUSED) { const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; - const OT::cmap_accelerator_t &cmap = *ot_face->cmap; - unsigned int done; - for (done = 0; - done < count && cmap.get_nominal_glyph (*first_unicode, first_glyph); - done++) - { - first_unicode = &StructAtOffset (first_unicode, unicode_stride); - first_glyph = &StructAtOffset (first_glyph, glyph_stride); - } - return done; + return ot_face->cmap->get_nominal_glyphs (count, + first_unicode, unicode_stride, + first_glyph, glyph_stride); } static hb_bool_t From 914b595f2598d5bdb2c750832d567a57d45db84e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 22:39:50 -0500 Subject: [PATCH 11/37] [ot-face] Include hb-ot-face directly in hb_face_t Simplifying access coming next. --- src/hb-face.cc | 4 ++++ src/hb-face.hh | 3 +++ src/hb-ot-face.cc | 24 ++-------------------- src/hb-ot-face.hh | 51 +++++++++++++++++++--------------------------- src/hb-ot-font.cc | 24 +++++++++++----------- src/hb-ot-math.cc | 3 +-- src/hb-ot-shape.cc | 5 +++-- 7 files changed, 46 insertions(+), 68 deletions(-) diff --git a/src/hb-face.cc b/src/hb-face.cc index a0f8047f3..921eed285 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -132,6 +132,8 @@ hb_face_create_for_tables (hb_reference_table_func_t reference_table_func, face->upem = 0; face->num_glyphs = (unsigned int) -1; + face->table.init0 (face); + return face; } @@ -275,6 +277,8 @@ hb_face_destroy (hb_face_t *face) #include "hb-shaper-list.hh" #undef HB_SHAPER_IMPLEMENT + face->table.fini (); + if (face->destroy) face->destroy (face->user_data); diff --git a/src/hb-face.hh b/src/hb-face.hh index 520bdfdf8..726f68837 100644 --- a/src/hb-face.hh +++ b/src/hb-face.hh @@ -33,6 +33,7 @@ #include "hb-shaper.hh" #include "hb-shape-plan.hh" +#include "hb-ot-face.hh" /* @@ -53,6 +54,8 @@ struct hb_face_t struct hb_shaper_data_t shaper_data; /* Various shaper data. */ + hb_ot_face_t table; + /* Cache */ struct plan_node_t { diff --git a/src/hb-ot-face.cc b/src/hb-ot-face.cc index cbceea9b1..c7dafdd4a 100644 --- a/src/hb-ot-face.cc +++ b/src/hb-ot-face.cc @@ -40,7 +40,7 @@ #include "hb-ot-layout-gpos-table.hh" -void hb_ot_face_data_t::init0 (hb_face_t *face) +void hb_ot_face_t::init0 (hb_face_t *face) { this->face = face; #define HB_OT_TABLE(Namespace, Type) Type.init0 (); @@ -49,7 +49,7 @@ void hb_ot_face_data_t::init0 (hb_face_t *face) #undef HB_OT_ACCELERATOR #undef HB_OT_TABLE } -void hb_ot_face_data_t::fini (void) +void hb_ot_face_t::fini (void) { #define HB_OT_TABLE(Namespace, Type) Type.fini (); #define HB_OT_ACCELERATOR(Namespace, Type) HB_OT_TABLE (Namespace, Type) @@ -57,23 +57,3 @@ void hb_ot_face_data_t::fini (void) #undef HB_OT_ACCELERATOR #undef HB_OT_TABLE } - -hb_ot_face_data_t * -_hb_ot_face_data_create (hb_face_t *face) -{ - hb_ot_face_data_t *data = (hb_ot_face_data_t *) calloc (1, sizeof (hb_ot_face_data_t)); - if (unlikely (!data)) - return nullptr; - - data->init0 (face); - - return data; -} - -void -_hb_ot_face_data_destroy (hb_ot_face_data_t *data) -{ - data->fini (); - free (data); -} - diff --git a/src/hb-ot-face.hh b/src/hb-ot-face.hh index caa1d97ef..46d5db759 100644 --- a/src/hb-ot-face.hh +++ b/src/hb-ot-face.hh @@ -34,34 +34,14 @@ #include "hb-machinery.hh" -#define hb_ot_face_data(face) ((hb_ot_face_data_t *) face->shaper_data.ot.get_relaxed ()) +#define hb_ot_face_data(face) (&face->table) /* - * hb_ot_face_data_t + * hb_ot_face_t */ -/* Most of these tables are NOT needed for shaping. But we need to hook them *somewhere*. - * This is as good as any place. */ #define HB_OT_TABLES \ - /* OpenType shaping. */ \ - HB_OT_ACCELERATOR(OT, GDEF) \ - HB_OT_ACCELERATOR(OT, GSUB) \ - HB_OT_ACCELERATOR(OT, GPOS) \ - HB_OT_TABLE(OT, JSTF) \ - HB_OT_TABLE(OT, BASE) \ - /* AAT shaping. */ \ - HB_OT_TABLE(AAT, morx) \ - HB_OT_TABLE(AAT, mort) \ - HB_OT_TABLE(AAT, kerx) \ - HB_OT_TABLE(AAT, ankr) \ - HB_OT_TABLE(AAT, trak) \ - /* OpenType variations. */ \ - HB_OT_TABLE(OT, fvar) \ - HB_OT_TABLE(OT, avar) \ - HB_OT_TABLE(OT, MVAR) \ - /* OpenType math. */ \ - HB_OT_TABLE(OT, MATH) \ /* OpenType fundamentals. */ \ HB_OT_ACCELERATOR(OT, cmap) \ HB_OT_ACCELERATOR(OT, hmtx) \ @@ -71,7 +51,25 @@ HB_OT_ACCELERATOR(OT, glyf) \ HB_OT_TABLE(OT, VORG) \ HB_OT_ACCELERATOR(OT, name) \ + /* OpenType shaping. */ \ + HB_OT_ACCELERATOR(OT, GDEF) \ + HB_OT_ACCELERATOR(OT, GSUB) \ + HB_OT_ACCELERATOR(OT, GPOS) \ + HB_OT_TABLE(OT, BASE) \ + HB_OT_TABLE(OT, JSTF) \ + /* AAT shaping. */ \ + HB_OT_TABLE(AAT, mort) \ + HB_OT_TABLE(AAT, morx) \ + HB_OT_TABLE(AAT, kerx) \ + HB_OT_TABLE(AAT, ankr) \ + HB_OT_TABLE(AAT, trak) \ HB_OT_TABLE(AAT, ltag) \ + /* OpenType variations. */ \ + HB_OT_TABLE(OT, fvar) \ + HB_OT_TABLE(OT, avar) \ + HB_OT_TABLE(OT, MVAR) \ + /* OpenType math. */ \ + HB_OT_TABLE(OT, MATH) \ /* OpenType color fonts. */ \ HB_OT_TABLE(OT, COLR) \ HB_OT_TABLE(OT, CPAL) \ @@ -87,7 +85,7 @@ HB_OT_TABLES #undef HB_OT_ACCELERATOR #undef HB_OT_TABLE -struct hb_ot_face_data_t +struct hb_ot_face_t { HB_INTERNAL void init0 (hb_face_t *face); HB_INTERNAL void fini (void); @@ -115,11 +113,4 @@ struct hb_ot_face_data_t }; -HB_INTERNAL hb_ot_face_data_t * -_hb_ot_face_data_create (hb_face_t *face); - -HB_INTERNAL void -_hb_ot_face_data_destroy (hb_ot_face_data_t *data); - - #endif /* HB_OT_FACE_HH */ diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 3e2f1f656..54095c170 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -61,7 +61,7 @@ hb_ot_get_nominal_glyph (hb_font_t *font HB_UNUSED, hb_codepoint_t *glyph, void *user_data HB_UNUSED) { - const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; + const hb_ot_face_t *ot_face = (const hb_ot_face_t *) font_data; return ot_face->cmap->get_nominal_glyph (unicode, glyph); } @@ -75,7 +75,7 @@ hb_ot_get_nominal_glyphs (hb_font_t *font HB_UNUSED, unsigned int glyph_stride, void *user_data HB_UNUSED) { - const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; + const hb_ot_face_t *ot_face = (const hb_ot_face_t *) font_data; return ot_face->cmap->get_nominal_glyphs (count, first_unicode, unicode_stride, first_glyph, glyph_stride); @@ -89,7 +89,7 @@ hb_ot_get_variation_glyph (hb_font_t *font HB_UNUSED, hb_codepoint_t *glyph, void *user_data HB_UNUSED) { - const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; + const hb_ot_face_t *ot_face = (const hb_ot_face_t *) font_data; return ot_face->cmap->get_variation_glyph (unicode, variation_selector, glyph); } @@ -102,7 +102,7 @@ hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data, unsigned advance_stride, void *user_data HB_UNUSED) { - const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; + const hb_ot_face_t *ot_face = (const hb_ot_face_t *) font_data; const OT::hmtx_accelerator_t &hmtx = *ot_face->hmtx; for (unsigned int i = 0; i < count; i++) @@ -122,7 +122,7 @@ hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data, unsigned advance_stride, void *user_data HB_UNUSED) { - const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; + const hb_ot_face_t *ot_face = (const hb_ot_face_t *) font_data; const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx; for (unsigned int i = 0; i < count; i++) @@ -141,7 +141,7 @@ hb_ot_get_glyph_v_origin (hb_font_t *font, hb_position_t *y, void *user_data HB_UNUSED) { - const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; + const hb_ot_face_t *ot_face = (const hb_ot_face_t *) font_data; *x = font->get_glyph_h_advance (glyph) / 2; @@ -175,7 +175,7 @@ hb_ot_get_glyph_extents (hb_font_t *font, hb_glyph_extents_t *extents, void *user_data HB_UNUSED) { - const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; + const hb_ot_face_t *ot_face = (const hb_ot_face_t *) font_data; bool ret = ot_face->sbix->get_extents (font, glyph, extents); if (!ret) ret = ot_face->glyf->get_extents (glyph, extents); @@ -196,7 +196,7 @@ hb_ot_get_glyph_name (hb_font_t *font HB_UNUSED, char *name, unsigned int size, void *user_data HB_UNUSED) { - const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; + const hb_ot_face_t *ot_face = (const hb_ot_face_t *) font_data; return ot_face->post->get_glyph_name (glyph, name, size); } @@ -207,7 +207,7 @@ hb_ot_get_glyph_from_name (hb_font_t *font HB_UNUSED, hb_codepoint_t *glyph, void *user_data HB_UNUSED) { - const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; + const hb_ot_face_t *ot_face = (const hb_ot_face_t *) font_data; return ot_face->post->get_glyph_from_name (name, len, glyph); } @@ -217,7 +217,7 @@ hb_ot_get_font_h_extents (hb_font_t *font, hb_font_extents_t *metrics, void *user_data HB_UNUSED) { - const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; + const hb_ot_face_t *ot_face = (const hb_ot_face_t *) font_data; const OT::hmtx_accelerator_t &hmtx = *ot_face->hmtx; metrics->ascender = font->em_scale_y (hmtx.ascender); metrics->descender = font->em_scale_y (hmtx.descender); @@ -232,7 +232,7 @@ hb_ot_get_font_v_extents (hb_font_t *font, hb_font_extents_t *metrics, void *user_data HB_UNUSED) { - const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; + const hb_ot_face_t *ot_face = (const hb_ot_face_t *) font_data; const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx; metrics->ascender = font->em_scale_x (vmtx.ascender); metrics->descender = font->em_scale_x (vmtx.descender); @@ -299,7 +299,7 @@ void hb_ot_font_set_funcs (hb_font_t *font) { if (unlikely (!hb_ot_shaper_face_data_ensure (font->face))) return; - hb_ot_face_data_t *ot_face = hb_ot_face_data (font->face); + hb_ot_face_t *ot_face = hb_ot_face_data (font->face); hb_font_set_funcs (font, _hb_ot_get_font_funcs (), diff --git a/src/hb-ot-math.cc b/src/hb-ot-math.cc index 3fb720b20..594f63cad 100644 --- a/src/hb-ot-math.cc +++ b/src/hb-ot-math.cc @@ -44,8 +44,7 @@ static inline const OT::MATH& _get_math (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::MATH); - hb_ot_face_data_t * data = hb_ot_face_data (face); - return *(data->MATH); + return *(hb_ot_face_data (face)->MATH); } /* diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 8c5e38e06..98c29a483 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -258,16 +258,17 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner, HB_SHAPER_DATA_ENSURE_DEFINE(ot, face) +struct hb_ot_face_data_t {}; + hb_ot_face_data_t * _hb_ot_shaper_face_data_create (hb_face_t *face) { - return _hb_ot_face_data_create (face); + return (hb_ot_face_data_t *) HB_SHAPER_DATA_SUCCEEDED; } void _hb_ot_shaper_face_data_destroy (hb_ot_face_data_t *data) { - _hb_ot_face_data_destroy (data); } From a35c92cbe771a75df40412fd248ad06f6a0cfebf Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 22:58:43 -0500 Subject: [PATCH 12/37] [ot-face] Simplify table access Yoohoo! --- src/hb-aat-layout.cc | 107 ++++++++----------------------------------- src/hb-ot-color.cc | 66 ++++++-------------------- src/hb-ot-layout.cc | 20 ++------ src/hb-ot-math.cc | 47 +++++++------------ src/hb-ot-name.cc | 11 +---- src/hb-ot-var.cc | 33 ++++--------- 6 files changed, 64 insertions(+), 220 deletions(-) diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index 9e0eb92fa..4c4e29456 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -172,88 +172,19 @@ AAT::hb_aat_apply_context_t::set_ankr_table (const AAT::ankr *ankr_table_, * mort/morx/kerx/trak */ -static inline const AAT::mort& -_get_mort (hb_face_t *face, hb_blob_t **blob = nullptr) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) - { - if (blob) - *blob = hb_blob_get_empty (); - return Null(AAT::mort); - } - const AAT::mort& mort = *(hb_ot_face_data (face)->mort); - if (blob) - *blob = hb_ot_face_data (face)->mort.get_blob (); - return mort; -} -static inline const AAT::morx& -_get_morx (hb_face_t *face, hb_blob_t **blob = nullptr) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) - { - if (blob) - *blob = hb_blob_get_empty (); - return Null(AAT::morx); - } - const AAT::morx& morx = *(hb_ot_face_data (face)->morx); - if (blob) - *blob = hb_ot_face_data (face)->morx.get_blob (); - return morx; -} -static inline const AAT::kerx& -_get_kerx (hb_face_t *face, hb_blob_t **blob = nullptr) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) - { - if (blob) - *blob = hb_blob_get_empty (); - return Null(AAT::kerx); - } - const AAT::kerx& kerx = *(hb_ot_face_data (face)->kerx); - if (blob) - *blob = hb_ot_face_data (face)->kerx.get_blob (); - return kerx; -} -static inline const AAT::ankr& -_get_ankr (hb_face_t *face, hb_blob_t **blob = nullptr) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) - { - if (blob) - *blob = hb_blob_get_empty (); - return Null(AAT::ankr); - } - const AAT::ankr& ankr = *(hb_ot_face_data (face)->ankr); - if (blob) - *blob = hb_ot_face_data (face)->ankr.get_blob (); - return ankr; -} -static inline const AAT::trak& -_get_trak (hb_face_t *face) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(AAT::trak); - return *(hb_ot_face_data (face)->trak); -} -static inline const AAT::ltag& -_get_ltag (hb_face_t *face) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(AAT::ltag); - return *(hb_ot_face_data (face)->ltag); -} - void hb_aat_layout_compile_map (const hb_aat_map_builder_t *mapper, hb_aat_map_t *map) { - const AAT::morx& morx = _get_morx (mapper->face, nullptr); + const AAT::morx& morx = *mapper->face->table.morx; if (morx.has_data ()) { morx.compile_flags (mapper, map); return; } - const AAT::mort& mort = _get_mort (mapper->face, nullptr); + const AAT::mort& mort = *mapper->face->table.mort; if (mort.has_data ()) { mort.compile_flags (mapper, map); @@ -265,8 +196,8 @@ hb_aat_layout_compile_map (const hb_aat_map_builder_t *mapper, hb_bool_t hb_aat_layout_has_substitution (hb_face_t *face) { - return _get_morx (face).has_data () || - _get_mort (face).has_data (); + return face->table.morx->has_data (); + face->table.mort->has_data (); } void @@ -274,20 +205,20 @@ hb_aat_layout_substitute (hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) { - hb_blob_t *blob; - - const AAT::morx& morx = _get_morx (font->face, &blob); + hb_blob_t *morx_blob = font->face->table.morx.get_blob (); + const AAT::morx& morx = *font->face->table.morx; if (morx.has_data ()) { - AAT::hb_aat_apply_context_t c (plan, font, buffer, blob); + AAT::hb_aat_apply_context_t c (plan, font, buffer, morx_blob); morx.apply (&c); return; } - const AAT::mort& mort = _get_mort (font->face, &blob); + hb_blob_t *mort_blob = font->face->table.morx.get_blob (); + const AAT::mort& mort = *font->face->table.mort; if (mort.has_data ()) { - AAT::hb_aat_apply_context_t c (plan, font, buffer, blob); + AAT::hb_aat_apply_context_t c (plan, font, buffer, mort_blob); mort.apply (&c); return; } @@ -297,7 +228,7 @@ hb_aat_layout_substitute (hb_ot_shape_plan_t *plan, hb_bool_t hb_aat_layout_has_positioning (hb_face_t *face) { - return _get_kerx (face).has_data (); + return face->table.kerx->has_data (); } void @@ -305,21 +236,22 @@ hb_aat_layout_position (hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) { - hb_blob_t *blob; - const AAT::kerx& kerx = _get_kerx (font->face, &blob); + hb_blob_t *blob = font->face->table.kerx.get_blob (); + const AAT::kerx& kerx = *font->face->table.kerx; - hb_blob_t *ankr_blob; - const AAT::ankr& ankr = _get_ankr (font->face, &ankr_blob); + hb_blob_t *ankr_blob = font->face->table.ankr.get_blob ();; + const AAT::ankr& ankr = *font->face->table.ankr; AAT::hb_aat_apply_context_t c (plan, font, buffer, blob); c.set_ankr_table (&ankr, ankr_blob->data + ankr_blob->length); kerx.apply (&c); } + hb_bool_t hb_aat_layout_has_tracking (hb_face_t *face) { - return _get_trak (face).has_data (); + return face->table.trak->has_data (); } void @@ -327,15 +259,16 @@ hb_aat_layout_track (hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) { - const AAT::trak& trak = _get_trak (font->face); + const AAT::trak& trak = *font->face->table.trak; AAT::hb_aat_apply_context_t c (plan, font, buffer); trak.apply (&c); } + hb_language_t _hb_aat_language_get (hb_face_t *face, unsigned int i) { - return _get_ltag (face).get_language (i); + return face->table.ltag->get_language (i); } diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc index 853f65dcf..cac289b27 100644 --- a/src/hb-ot-color.cc +++ b/src/hb-ot-color.cc @@ -50,42 +50,6 @@ **/ -static inline const OT::COLR& -_get_colr (hb_face_t *face) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::COLR); - return *(hb_ot_face_data (face)->COLR); -} - -static inline const OT::CBDT_accelerator_t& -_get_cbdt (hb_face_t *face) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::CBDT_accelerator_t); - return *(hb_ot_face_data (face)->CBDT); -} - -static inline const OT::CPAL& -_get_cpal (hb_face_t *face) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::CPAL); - return *(hb_ot_face_data (face)->CPAL); -} - -static inline const OT::sbix_accelerator_t& -_get_sbix (hb_face_t *face) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::sbix_accelerator_t); - return *(hb_ot_face_data (face)->sbix); -} - -static inline const OT::SVG_accelerator_t& -_get_svg (hb_face_t *face) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::SVG_accelerator_t); - return *(hb_ot_face_data (face)->SVG); -} - - /* * CPAL */ @@ -102,7 +66,7 @@ _get_svg (hb_face_t *face) hb_bool_t hb_ot_color_has_palettes (hb_face_t *face) { - return _get_cpal (face).has_data (); + return face->table.CPAL->has_data (); } /** @@ -117,7 +81,7 @@ hb_ot_color_has_palettes (hb_face_t *face) unsigned int hb_ot_color_palette_get_count (hb_face_t *face) { - return _get_cpal (face).get_palette_count (); + return face->table.CPAL->get_palette_count (); } /** @@ -137,7 +101,7 @@ hb_ot_name_id_t hb_ot_color_palette_get_name_id (hb_face_t *face, unsigned int palette_index) { - return _get_cpal (face).get_palette_name_id (palette_index); + return face->table.CPAL->get_palette_name_id (palette_index); } /** @@ -153,7 +117,7 @@ hb_ot_name_id_t hb_ot_color_palette_color_get_name_id (hb_face_t *face, unsigned int color_index) { - return _get_cpal (face).get_color_name_id (color_index); + return face->table.CPAL->get_color_name_id (color_index); } /** @@ -169,7 +133,7 @@ hb_ot_color_palette_flags_t hb_ot_color_palette_get_flags (hb_face_t *face, unsigned int palette_index) { - return _get_cpal(face).get_palette_flags (palette_index); + return face->table.CPAL->get_palette_flags (palette_index); } /** @@ -203,7 +167,7 @@ hb_ot_color_palette_get_colors (hb_face_t *face, unsigned int *colors_count /* IN/OUT. May be NULL. */, hb_color_t *colors /* OUT. May be NULL. */) { - return _get_cpal (face).get_palette_colors (palette_index, start_offset, colors_count, colors); + return face->table.CPAL->get_palette_colors (palette_index, start_offset, colors_count, colors); } @@ -222,7 +186,7 @@ hb_ot_color_palette_get_colors (hb_face_t *face, hb_bool_t hb_ot_color_has_layers (hb_face_t *face) { - return _get_colr (face).has_data (); + return face->table.COLR->has_data (); } /** @@ -245,7 +209,7 @@ hb_ot_color_glyph_get_layers (hb_face_t *face, unsigned int *count, /* IN/OUT. May be NULL. */ hb_ot_color_layer_t *layers /* OUT. May be NULL. */) { - return _get_colr (face).get_glyph_layers (glyph, start_offset, count, layers); + return face->table.COLR->get_glyph_layers (glyph, start_offset, count, layers); } @@ -266,7 +230,7 @@ hb_ot_color_glyph_get_layers (hb_face_t *face, hb_bool_t hb_ot_color_has_svg (hb_face_t *face) { - return _get_svg (face).has_data (); + return face->table.SVG->has_data (); } /** @@ -283,7 +247,7 @@ hb_ot_color_has_svg (hb_face_t *face) hb_blob_t * hb_ot_color_glyph_reference_svg (hb_face_t *face, hb_codepoint_t glyph) { - return _get_svg (face).reference_blob_for_glyph (glyph); + return face->table.SVG->reference_blob_for_glyph (glyph); } @@ -304,7 +268,7 @@ hb_ot_color_glyph_reference_svg (hb_face_t *face, hb_codepoint_t glyph) hb_bool_t hb_ot_color_has_png (hb_face_t *face) { - return _get_cbdt (face).has_data () || _get_sbix (face).has_data (); + return face->table.CBDT->has_data () || face->table.sbix->has_data (); } /** @@ -325,11 +289,11 @@ hb_ot_color_glyph_reference_png (hb_font_t *font, hb_codepoint_t glyph) { hb_blob_t *blob = hb_blob_get_empty (); - if (_get_sbix (font->face).has_data ()) - blob = _get_sbix (font->face).reference_png (font, glyph, nullptr, nullptr, nullptr); + if (font->face->table.sbix->has_data ()) + blob = font->face->table.sbix->reference_png (font, glyph, nullptr, nullptr, nullptr); - if (!blob->length && _get_cbdt (font->face).has_data ()) - blob = _get_cbdt (font->face).reference_png (font, glyph); + if (!blob->length && font->face->table.CBDT->has_data ()) + blob = font->face->table.CBDT->reference_png (font, glyph); return blob; } diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index fcdc79ee9..b3c635380 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -53,20 +53,6 @@ **/ -static inline const OT::kern& -_get_kern (hb_face_t *face, hb_blob_t **blob = nullptr) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) - { - if (blob) - *blob = hb_blob_get_empty (); - return Null(OT::kern); - } - const OT::kern& kern = *(hb_ot_face_data (face)->kern); - if (blob) - *blob = hb_ot_face_data (face)->kern.get_blob (); - return kern; -} const OT::GDEF& _get_gdef (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GDEF); @@ -109,7 +95,7 @@ const OT::GPOS& _get_gpos_relaxed (hb_face_t *face) hb_bool_t hb_ot_layout_has_kerning (hb_face_t *face) { - return _get_kern (face).has_data (); + return face->table.kern->has_data (); } void @@ -117,8 +103,8 @@ hb_ot_layout_kern (hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) { - hb_blob_t *blob; - const AAT::kern& kern = _get_kern (font->face, &blob); + hb_blob_t *blob = font->face->table.kern.get_blob (); + const AAT::kern& kern = *font->face->table.kern; AAT::hb_aat_apply_context_t c (plan, font, buffer, blob); diff --git a/src/hb-ot-math.cc b/src/hb-ot-math.cc index 594f63cad..e1d26d301 100644 --- a/src/hb-ot-math.cc +++ b/src/hb-ot-math.cc @@ -40,13 +40,6 @@ **/ -static inline const OT::MATH& -_get_math (hb_face_t *face) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::MATH); - return *(hb_ot_face_data (face)->MATH); -} - /* * OT::MATH */ @@ -65,7 +58,7 @@ _get_math (hb_face_t *face) hb_bool_t hb_ot_math_has_data (hb_face_t *face) { - return _get_math (face).has_data (); + return face->table.MATH->has_data (); } /** @@ -87,8 +80,7 @@ hb_position_t hb_ot_math_get_constant (hb_font_t *font, hb_ot_math_constant_t constant) { - const OT::MATH &math = _get_math (font->face); - return math.get_constant(constant, font); + return font->face->table.MATH->get_constant(constant, font); } /** @@ -104,8 +96,7 @@ hb_position_t hb_ot_math_get_glyph_italics_correction (hb_font_t *font, hb_codepoint_t glyph) { - const OT::MATH &math = _get_math (font->face); - return math.get_math_glyph_info().get_italics_correction (glyph, font); + return font->face->table.MATH->get_math_glyph_info().get_italics_correction (glyph, font); } /** @@ -121,8 +112,7 @@ hb_position_t hb_ot_math_get_glyph_top_accent_attachment (hb_font_t *font, hb_codepoint_t glyph) { - const OT::MATH &math = _get_math (font->face); - return math.get_math_glyph_info().get_top_accent_attachment (glyph, font); + return font->face->table.MATH->get_math_glyph_info().get_top_accent_attachment (glyph, font); } /** @@ -138,8 +128,7 @@ hb_bool_t hb_ot_math_is_glyph_extended_shape (hb_face_t *face, hb_codepoint_t glyph) { - const OT::MATH &math = _get_math (face); - return math.get_math_glyph_info().is_extended_shape (glyph); + return face->table.MATH->get_math_glyph_info().is_extended_shape (glyph); } /** @@ -165,8 +154,7 @@ hb_ot_math_get_glyph_kerning (hb_font_t *font, hb_ot_math_kern_t kern, hb_position_t correction_height) { - const OT::MATH &math = _get_math (font->face); - return math.get_math_glyph_info().get_kerning (glyph, kern, correction_height, font); + return font->face->table.MATH->get_math_glyph_info().get_kerning (glyph, kern, correction_height, font); } /** @@ -196,11 +184,10 @@ hb_ot_math_get_glyph_variants (hb_font_t *font, unsigned int *variants_count, /* IN/OUT */ hb_ot_math_glyph_variant_t *variants /* OUT */) { - const OT::MATH &math = _get_math (font->face); - return math.get_math_variants().get_glyph_variants (glyph, direction, font, - start_offset, - variants_count, - variants); + return font->face->table.MATH->get_math_variants().get_glyph_variants (glyph, direction, font, + start_offset, + variants_count, + variants); } /** @@ -221,8 +208,7 @@ hb_position_t hb_ot_math_get_min_connector_overlap (hb_font_t *font, hb_direction_t direction) { - const OT::MATH &math = _get_math (font->face); - return math.get_math_variants().get_min_connector_overlap (direction, font); + return font->face->table.MATH->get_math_variants().get_min_connector_overlap (direction, font); } /** @@ -254,10 +240,9 @@ hb_ot_math_get_glyph_assembly (hb_font_t *font, hb_ot_math_glyph_part_t *parts, /* OUT */ hb_position_t *italics_correction /* OUT */) { - const OT::MATH &math = _get_math (font->face); - return math.get_math_variants().get_glyph_parts (glyph, direction, font, - start_offset, - parts_count, - parts, - italics_correction); + return font->face->table.MATH->get_math_variants().get_glyph_parts (glyph, direction, font, + start_offset, + parts_count, + parts, + italics_correction); } diff --git a/src/hb-ot-name.cc b/src/hb-ot-name.cc index f2d1f0c2f..4c8866096 100644 --- a/src/hb-ot-name.cc +++ b/src/hb-ot-name.cc @@ -42,13 +42,6 @@ **/ -static inline const OT::name_accelerator_t& -_get_name (hb_face_t *face) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::name_accelerator_t); - return *(hb_ot_face_data (face)->name); -} - /** * hb_ot_name_list_names: * @face: font face. @@ -65,7 +58,7 @@ const hb_ot_name_entry_t * hb_ot_name_list_names (hb_face_t *face, unsigned int *num_entries /* OUT */) { - const OT::name_accelerator_t &name = _get_name (face); + const OT::name_accelerator_t &name = *face->table.name; if (num_entries) *num_entries = name.names.len; return name.names.arrayZ(); } @@ -124,7 +117,7 @@ hb_ot_name_get_utf (hb_face_t *face, unsigned int *text_size /* IN/OUT */, typename utf_t::codepoint_t *text /* OUT */) { - const OT::name_accelerator_t &name = _get_name (face); + const OT::name_accelerator_t &name = *face->table.name; if (!language) language = hb_language_from_string ("en", 2); diff --git a/src/hb-ot-var.cc b/src/hb-ot-var.cc index 4363f85ee..c97e9c494 100644 --- a/src/hb-ot-var.cc +++ b/src/hb-ot-var.cc @@ -47,18 +47,6 @@ * fvar/avar */ -static inline const OT::fvar& -_get_fvar (hb_face_t *face) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::fvar); - return *(hb_ot_face_data (face)->fvar); -} -static inline const OT::avar& -_get_avar (hb_face_t *face) -{ - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::avar); - return *(hb_ot_face_data (face)->avar); -} /** * hb_ot_var_has_data: @@ -74,7 +62,7 @@ _get_avar (hb_face_t *face) hb_bool_t hb_ot_var_has_data (hb_face_t *face) { - return _get_fvar (face).has_data (); + return face->table.fvar->has_data (); } /** @@ -85,8 +73,7 @@ hb_ot_var_has_data (hb_face_t *face) unsigned int hb_ot_var_get_axis_count (hb_face_t *face) { - const OT::fvar &fvar = _get_fvar (face); - return fvar.get_axis_count (); + return face->table.fvar->get_axis_count (); } /** @@ -100,8 +87,7 @@ hb_ot_var_get_axes (hb_face_t *face, unsigned int *axes_count /* IN/OUT */, hb_ot_var_axis_t *axes_array /* OUT */) { - const OT::fvar &fvar = _get_fvar (face); - return fvar.get_axis_infos (start_offset, axes_count, axes_array); + return face->table.fvar->get_axis_infos (start_offset, axes_count, axes_array); } /** @@ -115,8 +101,7 @@ hb_ot_var_find_axis (hb_face_t *face, unsigned int *axis_index, hb_ot_var_axis_t *axis_info) { - const OT::fvar &fvar = _get_fvar (face); - return fvar.find_axis (axis_tag, axis_index, axis_info); + return face->table.fvar->find_axis (axis_tag, axis_index, axis_info); } @@ -135,7 +120,7 @@ hb_ot_var_normalize_variations (hb_face_t *face, for (unsigned int i = 0; i < coords_length; i++) coords[i] = 0; - const OT::fvar &fvar = _get_fvar (face); + const OT::fvar &fvar = *face->table.fvar; for (unsigned int i = 0; i < variations_length; i++) { unsigned int axis_index; @@ -144,8 +129,7 @@ hb_ot_var_normalize_variations (hb_face_t *face, coords[axis_index] = fvar.normalize_axis_value (axis_index, variations[i].value); } - const OT::avar &avar = _get_avar (face); - avar.map_coords (coords, coords_length); + face->table.avar->map_coords (coords, coords_length); } /** @@ -159,10 +143,9 @@ hb_ot_var_normalize_coords (hb_face_t *face, const float *design_coords, /* IN */ int *normalized_coords /* OUT */) { - const OT::fvar &fvar = _get_fvar (face); + const OT::fvar &fvar = *face->table.fvar; for (unsigned int i = 0; i < coords_length; i++) normalized_coords[i] = fvar.normalize_axis_value (i, design_coords[i]); - const OT::avar &avar = _get_avar (face); - avar.map_coords (normalized_coords, coords_length); + face->table.avar->map_coords (normalized_coords, coords_length); } From 0fe7a745c9a323a3fc76beb011b6ab8919cf905b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 23:08:33 -0500 Subject: [PATCH 13/37] [ot-face] Simplify more table access --- src/hb-face.cc | 6 +++--- src/hb-ot-face.hh | 3 --- src/hb-ot-font.cc | 4 +--- src/hb-ot-layout.cc | 34 +++++++++++++++++----------------- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/hb-face.cc b/src/hb-face.cc index 921eed285..b3ded6f78 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -552,7 +552,7 @@ hb_face_collect_unicodes (hb_face_t *face, hb_set_t *out) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return; - hb_ot_face_data (face)->cmap->collect_unicodes (out); + face->table.cmap->collect_unicodes (out); } /** @@ -569,7 +569,7 @@ hb_face_collect_variation_selectors (hb_face_t *face, hb_set_t *out) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return; - hb_ot_face_data (face)->cmap->collect_variation_selectors (out); + face->table.cmap->collect_variation_selectors (out); } /** @@ -587,7 +587,7 @@ hb_face_collect_variation_unicodes (hb_face_t *face, hb_set_t *out) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return; - hb_ot_face_data (face)->cmap->collect_variation_unicodes (variation_selector, out); + face->table.cmap->collect_variation_unicodes (variation_selector, out); } diff --git a/src/hb-ot-face.hh b/src/hb-ot-face.hh index 46d5db759..f393d4b1b 100644 --- a/src/hb-ot-face.hh +++ b/src/hb-ot-face.hh @@ -34,9 +34,6 @@ #include "hb-machinery.hh" -#define hb_ot_face_data(face) (&face->table) - - /* * hb_ot_face_t */ diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 54095c170..2f88f3ad2 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -299,10 +299,8 @@ void hb_ot_font_set_funcs (hb_font_t *font) { if (unlikely (!hb_ot_shaper_face_data_ensure (font->face))) return; - hb_ot_face_t *ot_face = hb_ot_face_data (font->face); - hb_font_set_funcs (font, _hb_ot_get_font_funcs (), - ot_face, + &font->face->table, nullptr); } diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index b3c635380..1a6cf148d 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -56,35 +56,35 @@ const OT::GDEF& _get_gdef (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GDEF); - return *hb_ot_face_data (face)->GDEF->table; + return *face->table.GDEF->table; } static hb_blob_t * _get_gsub_blob (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return hb_blob_get_empty (); - return hb_ot_face_data (face)->GSUB->blob; + return face->table.GSUB->blob; } static inline const OT::GSUB& _get_gsub (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GSUB); - return *hb_ot_face_data (face)->GSUB->table; + return *face->table.GSUB->table; } const OT::GSUB& _get_gsub_relaxed (hb_face_t *face) { - return *hb_ot_face_data (face)->GSUB.get_relaxed ()->table; + return *face->table.GSUB.get_relaxed ()->table; } static hb_blob_t * _get_gpos_blob (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return hb_blob_get_empty (); - return hb_ot_face_data (face)->GPOS->blob; + return face->table.GPOS->blob; } static inline const OT::GPOS& _get_gpos (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GPOS); - return *hb_ot_face_data (face)->GPOS->table; + return *face->table.GPOS->table; } const OT::GPOS& _get_gpos_relaxed (hb_face_t *face) { - return *hb_ot_face_data (face)->GPOS.get_relaxed ()->table; + return *face->table.GPOS.get_relaxed ()->table; } @@ -877,13 +877,13 @@ hb_ot_layout_lookup_collect_glyphs (hb_face_t *face, { case HB_OT_TAG_GSUB: { - const OT::SubstLookup& l = hb_ot_face_data (face)->GSUB->table->get_lookup (lookup_index); + const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index); l.collect_glyphs (&c); return; } case HB_OT_TAG_GPOS: { - const OT::PosLookup& l = hb_ot_face_data (face)->GPOS->table->get_lookup (lookup_index); + const OT::PosLookup& l = face->table.GPOS->table->get_lookup (lookup_index); l.collect_glyphs (&c); return; } @@ -956,12 +956,12 @@ hb_ot_layout_lookup_would_substitute_fast (hb_face_t *face, unsigned int glyphs_length, hb_bool_t zero_context) { - if (unlikely (lookup_index >= hb_ot_face_data (face)->GSUB->lookup_count)) return false; + if (unlikely (lookup_index >= face->table.GSUB->lookup_count)) return false; OT::hb_would_apply_context_t c (face, glyphs, glyphs_length, (bool) zero_context); - const OT::SubstLookup& l = hb_ot_face_data (face)->GSUB->table->get_lookup (lookup_index); + const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index); - return l.would_apply (&c, &hb_ot_face_data (face)->GSUB->accels[lookup_index]); + return l.would_apply (&c, &face->table.GSUB->accels[lookup_index]); } void @@ -1240,8 +1240,8 @@ struct GSUBProxy typedef OT::SubstLookup Lookup; GSUBProxy (hb_face_t *face) : - table (*hb_ot_face_data (face)->GSUB->table), - accels (hb_ot_face_data (face)->GSUB->accels) {} + table (*face->table.GSUB->table), + accels (face->table.GSUB->accels) {} const OT::GSUB &table; const OT::hb_ot_layout_lookup_accelerator_t *accels; @@ -1254,8 +1254,8 @@ struct GPOSProxy typedef OT::PosLookup Lookup; GPOSProxy (hb_face_t *face) : - table (*hb_ot_face_data (face)->GPOS->table), - accels (hb_ot_face_data (face)->GPOS->accels) {} + table (*face->table.GPOS->table), + accels (face->table.GPOS->accels) {} const OT::GPOS &table; const OT::hb_ot_layout_lookup_accelerator_t *accels; @@ -1414,7 +1414,7 @@ hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c, static const OT::BASE& _get_base (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::BASE); - return *hb_ot_face_data (face)->BASE; + return *face->table.BASE; } hb_bool_t From ea6d9b661fc3cf6bc4366feeb7694c0b712abfae Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 23:09:29 -0500 Subject: [PATCH 14/37] [ot-face] Remove a few ensures --- src/hb-face.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/hb-face.cc b/src/hb-face.cc index b3ded6f78..8e731052c 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -551,7 +551,6 @@ void hb_face_collect_unicodes (hb_face_t *face, hb_set_t *out) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return; face->table.cmap->collect_unicodes (out); } @@ -568,7 +567,6 @@ void hb_face_collect_variation_selectors (hb_face_t *face, hb_set_t *out) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return; face->table.cmap->collect_variation_selectors (out); } @@ -586,7 +584,6 @@ hb_face_collect_variation_unicodes (hb_face_t *face, hb_codepoint_t variation_selector, hb_set_t *out) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return; face->table.cmap->collect_variation_unicodes (variation_selector, out); } From 9198de7b9b6020c1e3d6a48783e36db7e1f7e99a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 23:10:37 -0500 Subject: [PATCH 15/37] [ot-font] Remove ensure --- src/hb-ot-font.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 2f88f3ad2..cf8cbd35d 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -298,7 +298,6 @@ _hb_ot_get_font_funcs (void) void hb_ot_font_set_funcs (hb_font_t *font) { - if (unlikely (!hb_ot_shaper_face_data_ensure (font->face))) return; hb_font_set_funcs (font, _hb_ot_get_font_funcs (), &font->face->table, From db35409f0db9faf91a10defc81e4d6d60dc7822a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 23:11:46 -0500 Subject: [PATCH 16/37] [ot-layout] Remove ensures --- src/hb-ot-layout.cc | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 1a6cf148d..5768cd7f6 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -55,17 +55,14 @@ const OT::GDEF& _get_gdef (hb_face_t *face) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GDEF); return *face->table.GDEF->table; } static hb_blob_t * _get_gsub_blob (hb_face_t *face) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return hb_blob_get_empty (); return face->table.GSUB->blob; } static inline const OT::GSUB& _get_gsub (hb_face_t *face) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GSUB); return *face->table.GSUB->table; } const OT::GSUB& _get_gsub_relaxed (hb_face_t *face) @@ -74,12 +71,10 @@ const OT::GSUB& _get_gsub_relaxed (hb_face_t *face) } static hb_blob_t * _get_gpos_blob (hb_face_t *face) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return hb_blob_get_empty (); return face->table.GPOS->blob; } static inline const OT::GPOS& _get_gpos (hb_face_t *face) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GPOS); return *face->table.GPOS->table; } const OT::GPOS& _get_gpos_relaxed (hb_face_t *face) @@ -865,8 +860,6 @@ hb_ot_layout_lookup_collect_glyphs (hb_face_t *face, hb_set_t *glyphs_after, /* OUT. May be NULL */ hb_set_t *glyphs_output /* OUT. May be NULL */) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return; - OT::hb_collect_glyphs_context_t c (face, glyphs_before, glyphs_input, @@ -945,8 +938,10 @@ hb_ot_layout_lookup_would_substitute (hb_face_t *face, unsigned int glyphs_length, hb_bool_t zero_context) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return false; - return hb_ot_layout_lookup_would_substitute_fast (face, lookup_index, glyphs, glyphs_length, zero_context); + return hb_ot_layout_lookup_would_substitute_fast (face, + lookup_index, + glyphs, glyphs_length, + zero_context); } hb_bool_t @@ -1413,7 +1408,6 @@ hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c, #if 0 static const OT::BASE& _get_base (hb_face_t *face) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::BASE); return *face->table.BASE; } From 33b006cc51b0d27cbe1d8ed498bbf2b548cb6554 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 23:19:04 -0500 Subject: [PATCH 17/37] [ot-layout] Simplify some access --- src/hb-ot-layout-gdef-table.hh | 2 +- src/hb-ot-layout-gpos-table.hh | 9 +++++---- src/hb-ot-layout-gsub-table.hh | 9 +++++---- src/hb-ot-layout-gsubgpos.hh | 2 +- src/hb-ot-layout.hh | 12 +----------- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/hb-ot-layout-gdef-table.hh b/src/hb-ot-layout-gdef-table.hh index 5847953d3..ea5f1c07d 100644 --- a/src/hb-ot-layout-gdef-table.hh +++ b/src/hb-ot-layout-gdef-table.hh @@ -410,7 +410,7 @@ struct GDEF struct accelerator_t { - HB_INTERNAL inline void init (hb_face_t *face); + HB_INTERNAL void init (hb_face_t *face); inline void fini (void) { diff --git a/src/hb-ot-layout-gpos-table.hh b/src/hb-ot-layout-gpos-table.hh index 399ede434..743a97931 100644 --- a/src/hb-ot-layout-gpos-table.hh +++ b/src/hb-ot-layout-gpos-table.hh @@ -1736,18 +1736,21 @@ GPOS::position_finish_offsets (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer) } +struct GPOS_accelerator_t : GPOS::accelerator_t {}; + + /* Out-of-class implementation for methods recursing */ template /*static*/ inline typename context_t::return_t PosLookup::dispatch_recurse_func (context_t *c, unsigned int lookup_index) { - const PosLookup &l = _get_gpos_relaxed (c->face)->get_lookup (lookup_index); + const PosLookup &l = c->face->table.GPOS.get_relaxed ()->table->get_lookup (lookup_index); return l.dispatch (c); } /*static*/ inline bool PosLookup::apply_recurse_func (hb_ot_apply_context_t *c, unsigned int lookup_index) { - const PosLookup &l = _get_gpos_relaxed (c->face).get_lookup (lookup_index); + const PosLookup &l = c->face->table.GPOS.get_relaxed ()->table->get_lookup (lookup_index); unsigned int saved_lookup_props = c->lookup_props; unsigned int saved_lookup_index = c->lookup_index; c->set_lookup_index (lookup_index); @@ -1758,8 +1761,6 @@ template return ret; } -struct GPOS_accelerator_t : GPOS::accelerator_t {}; - } /* namespace OT */ diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index d24ea59af..cef642180 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -1487,6 +1487,9 @@ struct GSUB : GSUBGPOS }; +struct GSUB_accelerator_t : GSUB::accelerator_t {}; + + /* Out-of-class implementation for methods recursing */ /*static*/ inline bool ExtensionSubst::is_reverse (void) const @@ -1500,13 +1503,13 @@ struct GSUB : GSUBGPOS template /*static*/ inline typename context_t::return_t SubstLookup::dispatch_recurse_func (context_t *c, unsigned int lookup_index) { - const SubstLookup &l = _get_gsub_relaxed (c->face).get_lookup (lookup_index); + const SubstLookup &l = c->face->table.GSUB.get_relaxed ()->table->get_lookup (lookup_index); return l.dispatch (c); } /*static*/ inline bool SubstLookup::apply_recurse_func (hb_ot_apply_context_t *c, unsigned int lookup_index) { - const SubstLookup &l = _get_gsub_relaxed (c->face).get_lookup (lookup_index); + const SubstLookup &l = c->face->table.GSUB.get_relaxed ()->table->get_lookup (lookup_index); unsigned int saved_lookup_props = c->lookup_props; unsigned int saved_lookup_index = c->lookup_index; c->set_lookup_index (lookup_index); @@ -1517,8 +1520,6 @@ template return ret; } -struct GSUB_accelerator_t : GSUB::accelerator_t {}; - } /* namespace OT */ diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 0d9eeae58..eccbcf420 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -491,7 +491,7 @@ struct hb_ot_apply_context_t : iter_input (), iter_context (), font (font_), face (font->face), buffer (buffer_), recurse_func (nullptr), - gdef (_get_gdef (face)), + gdef (*face->table.GDEF->table), var_store (gdef.get_var_store ()), direction (buffer_->props.direction), lookup_mask (1), diff --git a/src/hb-ot-layout.hh b/src/hb-ot-layout.hh index b29f87c5a..437ae4776 100644 --- a/src/hb-ot-layout.hh +++ b/src/hb-ot-layout.hh @@ -38,19 +38,9 @@ #include "hb-set-digest.hh" -namespace OT -{ - struct GDEF; - struct GSUB; - struct GPOS; -} - -HB_INTERNAL const OT::GDEF& _get_gdef (hb_face_t *face); -HB_INTERNAL const OT::GSUB& _get_gsub_relaxed (hb_face_t *face); -HB_INTERNAL const OT::GPOS& _get_gpos_relaxed (hb_face_t *face); - struct hb_ot_shape_plan_t; + /* * kern */ From 5e68cec17913e9f6e98e5017a56c78a5614e4030 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 23:23:57 -0500 Subject: [PATCH 18/37] [ot-layout] Simplify GDEF access --- src/hb-ot-layout.cc | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 5768cd7f6..33c8c1135 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -53,34 +53,14 @@ **/ -const OT::GDEF& _get_gdef (hb_face_t *face) -{ - return *face->table.GDEF->table; -} -static hb_blob_t * _get_gsub_blob (hb_face_t *face) -{ - return face->table.GSUB->blob; -} static inline const OT::GSUB& _get_gsub (hb_face_t *face) { return *face->table.GSUB->table; } -const OT::GSUB& _get_gsub_relaxed (hb_face_t *face) -{ - return *face->table.GSUB.get_relaxed ()->table; -} -static hb_blob_t * _get_gpos_blob (hb_face_t *face) -{ - return face->table.GPOS->blob; -} static inline const OT::GPOS& _get_gpos (hb_face_t *face) { return *face->table.GPOS->table; } -const OT::GPOS& _get_gpos_relaxed (hb_face_t *face) -{ - return *face->table.GPOS.get_relaxed ()->table; -} /* @@ -219,8 +199,8 @@ OT::GDEF::accelerator_t::init (hb_face_t *face) this->blob = hb_sanitize_context_t().reference_table (face); if (unlikely (_hb_ot_blacklist_gdef (this->blob->length, - _get_gsub_blob (face)->length, - _get_gpos_blob (face)->length))) + face->table.GSUB->blob->length, + face->table.GPOS->blob->length))) { hb_blob_destroy (this->blob); this->blob = hb_blob_get_empty (); @@ -235,7 +215,7 @@ _hb_ot_layout_set_glyph_props (hb_font_t *font, { _hb_buffer_assert_gsubgpos_vars (buffer); - const OT::GDEF &gdef = _get_gdef (font->face); + const OT::GDEF &gdef = *font->face->table.GDEF->table; unsigned int count = buffer->len; for (unsigned int i = 0; i < count; i++) { @@ -250,7 +230,7 @@ _hb_ot_layout_set_glyph_props (hb_font_t *font, hb_bool_t hb_ot_layout_has_glyph_classes (hb_face_t *face) { - return _get_gdef (face).has_glyph_classes (); + return face->table.GDEF->table->has_glyph_classes (); } /** @@ -262,7 +242,7 @@ hb_ot_layout_glyph_class_t hb_ot_layout_get_glyph_class (hb_face_t *face, hb_codepoint_t glyph) { - return (hb_ot_layout_glyph_class_t) _get_gdef (face).get_glyph_class (glyph); + return (hb_ot_layout_glyph_class_t) face->table.GDEF->table->get_glyph_class (glyph); } /** @@ -275,7 +255,7 @@ hb_ot_layout_get_glyphs_in_class (hb_face_t *face, hb_ot_layout_glyph_class_t klass, hb_set_t *glyphs /* OUT */) { - return _get_gdef (face).get_glyphs_in_class (klass, glyphs); + return face->table.GDEF->table->get_glyphs_in_class (klass, glyphs); } unsigned int @@ -285,7 +265,10 @@ hb_ot_layout_get_attach_points (hb_face_t *face, unsigned int *point_count /* IN/OUT */, unsigned int *point_array /* OUT */) { - return _get_gdef (face).get_attach_points (glyph, start_offset, point_count, point_array); + return face->table.GDEF->table->get_attach_points (glyph, + start_offset, + point_count, + point_array); } unsigned int @@ -296,7 +279,12 @@ hb_ot_layout_get_ligature_carets (hb_font_t *font, unsigned int *caret_count /* IN/OUT */, hb_position_t *caret_array /* OUT */) { - return _get_gdef (font->face).get_lig_carets (font, direction, glyph, start_offset, caret_count, caret_array); + return font->face->table.GDEF->table->get_lig_carets (font, + direction, + glyph, + start_offset, + caret_count, + caret_array); } From 737efbe65583a71d7df9ae7b423d9fb1d68599b7 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 23:26:29 -0500 Subject: [PATCH 19/37] [ot-layout] Simplify GSUB/GPOS access This concludes simplifying table access to face->table.XXXX. --- src/hb-ot-layout.cc | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 33c8c1135..7b0c5a6a4 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -53,16 +53,6 @@ **/ -static inline const OT::GSUB& _get_gsub (hb_face_t *face) -{ - return *face->table.GSUB->table; -} -static inline const OT::GPOS& _get_gpos (hb_face_t *face) -{ - return *face->table.GPOS->table; -} - - /* * kern */ @@ -297,8 +287,8 @@ get_gsubgpos_table (hb_face_t *face, hb_tag_t table_tag) { switch (table_tag) { - case HB_OT_TAG_GSUB: return _get_gsub (face); - case HB_OT_TAG_GPOS: return _get_gpos (face); + case HB_OT_TAG_GSUB: return *face->table.GSUB->table; + case HB_OT_TAG_GPOS: return *face->table.GPOS->table; default: return Null(OT::GSUBGPOS); } } @@ -470,7 +460,12 @@ hb_ot_layout_script_find_language (hb_face_t *face, hb_tag_t language_tag, unsigned int *language_index) { - return hb_ot_layout_script_select_language (face, table_tag, script_index, 1, &language_tag, language_index); + return hb_ot_layout_script_select_language (face, + table_tag, + script_index, + 1, + &language_tag, + language_index); } /** @@ -911,7 +906,7 @@ hb_ot_layout_feature_with_variations_get_lookups (hb_face_t *face, hb_bool_t hb_ot_layout_has_substitution (hb_face_t *face) { - return _get_gsub (face).has_data (); + return face->table.GSUB->table->has_data (); } /** @@ -967,7 +962,7 @@ hb_ot_layout_lookup_substitute_closure (hb_face_t *face, hb_map_t done_lookups; OT::hb_closure_context_t c (face, glyphs, &done_lookups); - const OT::SubstLookup& l = _get_gsub (face).get_lookup (lookup_index); + const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index); l.closure (&c, lookup_index); } @@ -987,7 +982,7 @@ hb_ot_layout_lookups_substitute_closure (hb_face_t *face, { hb_map_t done_lookups; OT::hb_closure_context_t c (face, glyphs, &done_lookups); - const OT::GSUB& gsub = _get_gsub (face); + const OT::GSUB& gsub = *face->table.GSUB->table; unsigned int iteration_count = 0; unsigned int glyphs_length; @@ -1016,7 +1011,7 @@ hb_ot_layout_lookups_substitute_closure (hb_face_t *face, hb_bool_t hb_ot_layout_has_positioning (hb_face_t *face) { - return _get_gpos (face).has_data (); + return face->table.GPOS->table->has_data (); } void @@ -1050,7 +1045,7 @@ hb_ot_layout_get_size_params (hb_face_t *face, unsigned int *range_start, /* OUT. May be NULL */ unsigned int *range_end /* OUT. May be NULL */) { - const OT::GPOS &gpos = _get_gpos (face); + const OT::GPOS &gpos = *face->table.GPOS->table; const hb_tag_t tag = HB_TAG ('s','i','z','e'); unsigned int num_features = gpos.get_feature_count (); From 61f52231f430c72e1b66b76dabb018cfe45a01d5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 23:28:52 -0500 Subject: [PATCH 20/37] [math] Shorten names a bit --- src/hb-ot-math-table.hh | 4 ++-- src/hb-ot-math.cc | 33 +++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/hb-ot-math-table.hh b/src/hb-ot-math-table.hh index e20935972..54c4e7fca 100644 --- a/src/hb-ot-math-table.hh +++ b/src/hb-ot-math-table.hh @@ -700,10 +700,10 @@ struct MATH hb_font_t *font) const { return (this+mathConstants).get_value (constant, font); } - inline const MathGlyphInfo &get_math_glyph_info (void) const + inline const MathGlyphInfo &get_glyph_info (void) const { return this+mathGlyphInfo; } - inline const MathVariants &get_math_variants (void) const + inline const MathVariants &get_variants (void) const { return this+mathVariants; } protected: diff --git a/src/hb-ot-math.cc b/src/hb-ot-math.cc index e1d26d301..bd31bf565 100644 --- a/src/hb-ot-math.cc +++ b/src/hb-ot-math.cc @@ -96,7 +96,7 @@ hb_position_t hb_ot_math_get_glyph_italics_correction (hb_font_t *font, hb_codepoint_t glyph) { - return font->face->table.MATH->get_math_glyph_info().get_italics_correction (glyph, font); + return font->face->table.MATH->get_glyph_info().get_italics_correction (glyph, font); } /** @@ -112,7 +112,7 @@ hb_position_t hb_ot_math_get_glyph_top_accent_attachment (hb_font_t *font, hb_codepoint_t glyph) { - return font->face->table.MATH->get_math_glyph_info().get_top_accent_attachment (glyph, font); + return font->face->table.MATH->get_glyph_info().get_top_accent_attachment (glyph, font); } /** @@ -128,7 +128,7 @@ hb_bool_t hb_ot_math_is_glyph_extended_shape (hb_face_t *face, hb_codepoint_t glyph) { - return face->table.MATH->get_math_glyph_info().is_extended_shape (glyph); + return face->table.MATH->get_glyph_info().is_extended_shape (glyph); } /** @@ -154,7 +154,10 @@ hb_ot_math_get_glyph_kerning (hb_font_t *font, hb_ot_math_kern_t kern, hb_position_t correction_height) { - return font->face->table.MATH->get_math_glyph_info().get_kerning (glyph, kern, correction_height, font); + return font->face->table.MATH->get_glyph_info().get_kerning (glyph, + kern, + correction_height, + font); } /** @@ -184,10 +187,10 @@ hb_ot_math_get_glyph_variants (hb_font_t *font, unsigned int *variants_count, /* IN/OUT */ hb_ot_math_glyph_variant_t *variants /* OUT */) { - return font->face->table.MATH->get_math_variants().get_glyph_variants (glyph, direction, font, - start_offset, - variants_count, - variants); + return font->face->table.MATH->get_variants().get_glyph_variants (glyph, direction, font, + start_offset, + variants_count, + variants); } /** @@ -208,7 +211,7 @@ hb_position_t hb_ot_math_get_min_connector_overlap (hb_font_t *font, hb_direction_t direction) { - return font->face->table.MATH->get_math_variants().get_min_connector_overlap (direction, font); + return font->face->table.MATH->get_variants().get_min_connector_overlap (direction, font); } /** @@ -240,9 +243,11 @@ hb_ot_math_get_glyph_assembly (hb_font_t *font, hb_ot_math_glyph_part_t *parts, /* OUT */ hb_position_t *italics_correction /* OUT */) { - return font->face->table.MATH->get_math_variants().get_glyph_parts (glyph, direction, font, - start_offset, - parts_count, - parts, - italics_correction); + return font->face->table.MATH->get_variants().get_glyph_parts (glyph, + direction, + font, + start_offset, + parts_count, + parts, + italics_correction); } From fa3ebf845fcffa827600fc4ca9fdde3aaa99f4c5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 5 Nov 2018 23:34:07 -0500 Subject: [PATCH 21/37] Simplify some more --- src/hb-aat-layout.cc | 10 +++++----- src/hb-ot-layout.cc | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index 4c4e29456..1912de0db 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -206,7 +206,7 @@ hb_aat_layout_substitute (hb_ot_shape_plan_t *plan, hb_buffer_t *buffer) { hb_blob_t *morx_blob = font->face->table.morx.get_blob (); - const AAT::morx& morx = *font->face->table.morx; + const AAT::morx& morx = *morx_blob->as (); if (morx.has_data ()) { AAT::hb_aat_apply_context_t c (plan, font, buffer, morx_blob); @@ -215,7 +215,7 @@ hb_aat_layout_substitute (hb_ot_shape_plan_t *plan, } hb_blob_t *mort_blob = font->face->table.morx.get_blob (); - const AAT::mort& mort = *font->face->table.mort; + const AAT::mort& mort = *mort_blob->as (); if (mort.has_data ()) { AAT::hb_aat_apply_context_t c (plan, font, buffer, mort_blob); @@ -236,13 +236,13 @@ hb_aat_layout_position (hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) { - hb_blob_t *blob = font->face->table.kerx.get_blob (); - const AAT::kerx& kerx = *font->face->table.kerx; + hb_blob_t *kerx_blob = font->face->table.kerx.get_blob (); + const AAT::kerx& kerx = *kerx_blob->as (); hb_blob_t *ankr_blob = font->face->table.ankr.get_blob ();; const AAT::ankr& ankr = *font->face->table.ankr; - AAT::hb_aat_apply_context_t c (plan, font, buffer, blob); + AAT::hb_aat_apply_context_t c (plan, font, buffer, kerx_blob); c.set_ankr_table (&ankr, ankr_blob->data + ankr_blob->length); kerx.apply (&c); } diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 7b0c5a6a4..1b366eb7b 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -69,7 +69,7 @@ hb_ot_layout_kern (hb_ot_shape_plan_t *plan, hb_buffer_t *buffer) { hb_blob_t *blob = font->face->table.kern.get_blob (); - const AAT::kern& kern = *font->face->table.kern; + const AAT::kern& kern = *blob->as (); AAT::hb_aat_apply_context_t c (plan, font, buffer, blob); From 98b37f0c109d0f7454e91c9563c56d1903d6d496 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Tue, 6 Nov 2018 09:16:28 +0330 Subject: [PATCH 22/37] [mort] Fix table detection logic mort really needs some initial tests at least. --- src/hb-aat-layout.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index 1912de0db..5a4e227ca 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -196,7 +196,7 @@ hb_aat_layout_compile_map (const hb_aat_map_builder_t *mapper, hb_bool_t hb_aat_layout_has_substitution (hb_face_t *face) { - return face->table.morx->has_data (); + return face->table.morx->has_data () || face->table.mort->has_data (); } From 9139cc23ea9fb339be9426860e0c72038d32a2ab Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Tue, 6 Nov 2018 11:17:14 +0330 Subject: [PATCH 23/37] Fix link issue of some of the bots e.g. https://circleci.com/gh/harfbuzz/harfbuzz/52410 --- src/hb-ot-layout.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 1b366eb7b..34d5729ca 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -183,7 +183,7 @@ _hb_ot_blacklist_gdef (unsigned int gdef_len, return false; } -inline void +HB_INTERNAL void OT::GDEF::accelerator_t::init (hb_face_t *face) { this->blob = hb_sanitize_context_t().reference_table (face); From a49df419f04b4065fc7f70a77c5cbc453e6ba906 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Tue, 6 Nov 2018 11:26:30 +0330 Subject: [PATCH 24/37] [test] Test hb_ot_name_{list_names,get_utf8} on test-ot-name --- test/api/test-ot-name.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/test/api/test-ot-name.c b/test/api/test-ot-name.c index 431ee3a20..c844f48ec 100644 --- a/test/api/test-ot-name.c +++ b/test/api/test-ot-name.c @@ -27,10 +27,11 @@ #include +hb_face_t *face; + static void test_ot_layout_feature_get_name_ids_and_characters (void) { - hb_face_t *face = hb_test_open_font_file ("fonts/cv01.otf"); hb_tag_t cv01 = HB_TAG ('c','v','0','1'); unsigned int feature_index; if (!hb_ot_layout_language_find_feature (face, @@ -68,8 +69,24 @@ test_ot_layout_feature_get_name_ids_and_characters (void) g_assert_cmpint (char_count, ==, 2); g_assert_cmpint (characters[0], ==, 10); g_assert_cmpint (characters[1], ==, 24030); +} - hb_face_destroy (face); +static void +test_ot_name (void) +{ + unsigned int num_entries; + const hb_ot_name_entry_t *entries; + entries = hb_ot_name_list_names (face, &num_entries); + g_assert_cmpuint (12, ==, num_entries); + hb_ot_name_id_t name_id = entries[3].name_id; + g_assert_cmpuint (3, ==, name_id); + hb_language_t lang = entries[3].language; + g_assert_cmpstr ("en", ==, hb_language_to_string (lang)); + char text[10]; + unsigned int text_size = 10; + g_assert_cmpuint (27, ==, hb_ot_name_get_utf8 (face, name_id, lang, &text_size, text)); + g_assert_cmpuint (9, ==, text_size); + g_assert_cmpstr (text, ==, "FontForge"); } int @@ -78,6 +95,10 @@ main (int argc, char **argv) g_test_init (&argc, &argv, NULL); hb_test_add (test_ot_layout_feature_get_name_ids_and_characters); + hb_test_add (test_ot_name); - return hb_test_run (); + face = hb_test_open_font_file ("fonts/cv01.otf"); + unsigned int status = hb_test_run (); + hb_face_destroy (face); + return status; } From b6112e5ea4d08fcbfa8f7cb4ef3903514a6e99f3 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Tue, 6 Nov 2018 11:42:47 +0330 Subject: [PATCH 25/37] [test] Fix -Weverything bot complain --- test/api/test-ot-name.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/api/test-ot-name.c b/test/api/test-ot-name.c index c844f48ec..71a8727b5 100644 --- a/test/api/test-ot-name.c +++ b/test/api/test-ot-name.c @@ -27,7 +27,7 @@ #include -hb_face_t *face; +static hb_face_t *face; static void test_ot_layout_feature_get_name_ids_and_characters (void) From 37f421c951c853dff165df6731d0ab9c46350790 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 6 Nov 2018 10:03:38 -0500 Subject: [PATCH 26/37] Minor --- src/hb-ot-layout.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 34d5729ca..6da1d3fdc 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -183,7 +183,7 @@ _hb_ot_blacklist_gdef (unsigned int gdef_len, return false; } -HB_INTERNAL void +void OT::GDEF::accelerator_t::init (hb_face_t *face) { this->blob = hb_sanitize_context_t().reference_table (face); From b062378ce640eb418cb413b595b79cc81a193209 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 6 Nov 2018 10:20:36 -0500 Subject: [PATCH 27/37] [test] Minor --- test/api/.valgrind-suppressions | 0 test/api/Makefile.am | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 test/api/.valgrind-suppressions diff --git a/test/api/.valgrind-suppressions b/test/api/.valgrind-suppressions deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/api/Makefile.am b/test/api/Makefile.am index b307cd123..e6e08a252 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -148,7 +148,7 @@ check-gtester: # Check tests under valgrind. Saves log to log-valgrind.txt VALGRIND_FLAGS = \ - --tool=memcheck --suppressions=$(srcdir)/.valgrind-suppressions \ + --tool=memcheck --track-origins=yes \ --leak-check=yes $(EXTRA_VALGRIND_FLAGS) From 3af0a7edd0c99aaef846ae787056d7664bc69d35 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 6 Nov 2018 10:20:57 -0500 Subject: [PATCH 28/37] [fuzzing] Add make check-valgrind --- test/fuzzing/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/fuzzing/Makefile.am b/test/fuzzing/Makefile.am index 250608861..54178ff43 100644 --- a/test/fuzzing/Makefile.am +++ b/test/fuzzing/Makefile.am @@ -68,5 +68,7 @@ hb_subset_fuzzer_DEPENDENCIES = \ check: EXEEXT="$(EXEEXT)" srcdir="$(srcdir)" builddir="$(builddir)" $(srcdir)/run-shape-fuzzer-tests.py EXEEXT="$(EXEEXT)" srcdir="$(srcdir)" builddir="$(builddir)" $(srcdir)/run-subset-fuzzer-tests.py +check-valgrind: + $(AM_V_at)RUN_VALGRIND=1 $(MAKE) $(AM_MAKEFLGS) check -include $(top_srcdir)/git.mk From 8790b2740a334f1789fb0cf329f2b8ac9733793c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 6 Nov 2018 10:24:54 -0500 Subject: [PATCH 29/37] [fuzzing] Fix test --- test/fuzzing/hb-shape-fuzzer.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/fuzzing/hb-shape-fuzzer.cc b/test/fuzzing/hb-shape-fuzzer.cc index ec69d514d..70ad08b45 100644 --- a/test/fuzzing/hb-shape-fuzzer.cc +++ b/test/fuzzing/hb-shape-fuzzer.cc @@ -33,10 +33,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) hb_buffer_guess_segment_properties (buffer); hb_shape (font, buffer, NULL, 0); hb_buffer_destroy (buffer); - } - /* Misc calls on face. */ - test_face (face, text32[15]); + /* Misc calls on face. */ + test_face (face, text32[15]); + } hb_font_destroy (font); hb_face_destroy (face); From 3ec2e4fa7bec07ec181a0390e5f5fd695abee611 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 6 Nov 2018 10:49:19 -0500 Subject: [PATCH 30/37] [util] Don't terminate string after a a 0 in -u Fixes https://github.com/harfbuzz/harfbuzz/issues/1361 --- util/options.cc | 4 +++- util/options.hh | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/util/options.cc b/util/options.cc index 5661cd059..3b22ca723 100644 --- a/util/options.cc +++ b/util/options.cc @@ -325,6 +325,7 @@ parse_text (const char *name G_GNUC_UNUSED, return false; } + text_opts->text_len = -1; text_opts->text = g_strdup (arg); return true; } @@ -370,6 +371,7 @@ parse_unicodes (const char *name G_GNUC_UNUSED, s = p; } + text_opts->text_len = gs->len; text_opts->text = g_string_free (gs, FALSE); return true; } @@ -729,7 +731,7 @@ text_options_t::get_line (unsigned int *len) if (text) { if (!line) line = text; if (line_len == (unsigned int) -1) - line_len = strlen (line); + line_len = text_len; if (!line_len) { *len = 0; diff --git a/util/options.hh b/util/options.hh index 6d57d7d61..0137484ce 100644 --- a/util/options.hh +++ b/util/options.hh @@ -506,6 +506,7 @@ struct text_options_t : option_group_t text_before = nullptr; text_after = nullptr; + text_len = -1; text = nullptr; text_file = nullptr; @@ -542,6 +543,7 @@ struct text_options_t : option_group_t char *text_before; char *text_after; + int text_len; char *text; char *text_file; From 9bddfde25dc8c302c765a1e9a8a2c38c4a836e2e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 6 Nov 2018 11:03:34 -0500 Subject: [PATCH 31/37] [util] Fix up previous commit --- util/options.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/util/options.cc b/util/options.cc index 3b22ca723..3f8fa3d04 100644 --- a/util/options.cc +++ b/util/options.cc @@ -729,9 +729,13 @@ const char * text_options_t::get_line (unsigned int *len) { if (text) { - if (!line) line = text; - if (line_len == (unsigned int) -1) + if (!line) + { + line = text; line_len = text_len; + } + if (line_len == (unsigned int) -1) + line_len = strlen (line); if (!line_len) { *len = 0; From d29602b962c13836f4c0d46796bc693f66f9b9fe Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Tue, 6 Nov 2018 18:07:47 +0200 Subject: [PATCH 32/37] Add missing backslash --- test/api/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/api/Makefile.am b/test/api/Makefile.am index e6e08a252..67044489e 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -148,7 +148,7 @@ check-gtester: # Check tests under valgrind. Saves log to log-valgrind.txt VALGRIND_FLAGS = \ - --tool=memcheck + --tool=memcheck \ --track-origins=yes \ --leak-check=yes $(EXTRA_VALGRIND_FLAGS) From 5c3ccbc634158ba9f84d365c9a31a596f6d8825b Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Tue, 6 Nov 2018 18:10:56 +0200 Subject: [PATCH 33/37] Another missing backlash Did this ever work? --- test/api/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 67044489e..947832b81 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -150,7 +150,7 @@ check-gtester: VALGRIND_FLAGS = \ --tool=memcheck \ --track-origins=yes \ - --leak-check=yes + --leak-check=yes \ $(EXTRA_VALGRIND_FLAGS) # Can't do for now: --show-reachable=yes CLEANFILES += log-valgrind.txt From 75b00b51c8fca5d605c479333eb3abd608623613 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 6 Nov 2018 11:13:40 -0500 Subject: [PATCH 34/37] [kern] Renames --- src/hb-ot-kern-table.hh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh index 5bc9e436c..2f27dcf40 100644 --- a/src/hb-ot-kern-table.hh +++ b/src/hb-ot-kern-table.hh @@ -524,11 +524,11 @@ struct KernSubTableWrapper /* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */ inline const T* thiz (void) const { return static_cast (this); } - inline bool is_supported (void) const - { return !(thiz()->coverage & T::CheckFlags); } + inline bool is_simple (void) const + { return !(thiz()->coverage & (T::CrossStream | T::Variation)); } inline bool is_horizontal (void) const - { return (thiz()->coverage & T::Direction) == T::CheckHorizontal; } + { return (thiz()->coverage & T::Direction) == T::DirectionHorizontal; } inline bool is_override (void) const { return bool (thiz()->coverage & T::Override); } @@ -537,7 +537,7 @@ struct KernSubTableWrapper { return thiz()->subtable.get_kerning (left, right, thiz()->format); } inline int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right) const - { return is_supported () && is_horizontal () ? get_kerning (left, right) : 0; } + { return is_simple () && is_horizontal () ? get_kerning (left, right) : 0; } inline void apply (AAT::hb_aat_apply_context_t *c) const { thiz()->subtable.apply (c, thiz()->format); } @@ -567,7 +567,7 @@ struct KernTable unsigned int count = thiz()->nTables; for (unsigned int i = 0; i < count; i++) { - if (st->is_supported () && st->is_override ()) + if (st->is_simple () && st->is_override ()) v = 0; v += st->get_h_kerning (left, right); st = &StructAfter (*st); @@ -584,14 +584,14 @@ struct KernTable unsigned int last_override = 0; for (unsigned int i = 0; i < count; i++) { - if (st->is_supported () && st->is_override ()) + if (st->is_simple () && st->is_override ()) last_override = i; st = &StructAfter (*st); } st = CastP (&thiz()->dataZ); for (unsigned int i = 0; i < count; i++) { - if (!st->is_supported ()) + if (!st->is_simple ()) goto skip; if (HB_DIRECTION_IS_HORIZONTAL (c->buffer->props.direction) != st->is_horizontal ()) @@ -654,8 +654,7 @@ struct KernOT : KernTable Variation = 0x00u, /* Not supported. */ - CheckFlags = 0x06u, - CheckHorizontal = 0x01u + DirectionHorizontal= 0x01u }; protected: @@ -695,8 +694,7 @@ struct KernAAT : KernTable Override = 0x00u, /* Not supported. */ - CheckFlags = 0x60u, - CheckHorizontal = 0x00u + DirectionHorizontal= 0x00u }; protected: From b0da2cd0b9c1346b7cda5997fb799e895e34aace Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 6 Nov 2018 11:16:45 -0500 Subject: [PATCH 35/37] [kern] Some more --- src/hb-ot-kern-table.hh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh index 2f27dcf40..e9d7e3018 100644 --- a/src/hb-ot-kern-table.hh +++ b/src/hb-ot-kern-table.hh @@ -536,9 +536,6 @@ struct KernSubTableWrapper inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const { return thiz()->subtable.get_kerning (left, right, thiz()->format); } - inline int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right) const - { return is_simple () && is_horizontal () ? get_kerning (left, right) : 0; } - inline void apply (AAT::hb_aat_apply_context_t *c) const { thiz()->subtable.apply (c, thiz()->format); } @@ -567,9 +564,11 @@ struct KernTable unsigned int count = thiz()->nTables; for (unsigned int i = 0; i < count; i++) { - if (st->is_simple () && st->is_override ()) + if (!st->is_simple () || !st->is_horizontal ()) + continue; + if (st->is_override ()) v = 0; - v += st->get_h_kerning (left, right); + v += st->get_kerning (left, right); st = &StructAfter (*st); } return v; From 213fa3bf711dae5028e3d041e305cdd35223de77 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 6 Nov 2018 12:07:15 -0500 Subject: [PATCH 36/37] [kern] Refactor to include header in each subtable type --- src/hb-ot-kern-table.hh | 189 +++++++++++++++++++--------------------- 1 file changed, 91 insertions(+), 98 deletions(-) diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh index e9d7e3018..1073530d6 100644 --- a/src/hb-ot-kern-table.hh +++ b/src/hb-ot-kern-table.hh @@ -155,6 +155,7 @@ struct KernPair DEFINE_SIZE_STATIC (6); }; +template struct KernSubTableFormat0 { inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const @@ -186,11 +187,13 @@ struct KernSubTableFormat0 } protected: - BinSearchArrayOf pairs; /* Array of kerning pairs. */ + KernSubTableHeader header; + BinSearchArrayOf pairs; /* Array of kerning pairs. */ public: - DEFINE_SIZE_ARRAY (8, pairs); + DEFINE_SIZE_ARRAY (KernSubTableHeader::static_size + 8, pairs); }; +template struct KernSubTableFormat1 { typedef void EntryData; @@ -309,10 +312,11 @@ struct KernSubTableFormat1 } protected: + KernSubTableHeader header; AAT::StateTable machine; OffsetTo, HBUINT16, false> kernAction; public: - DEFINE_SIZE_STATIC (10); + DEFINE_SIZE_STATIC (KernSubTableHeader::static_size + 10); }; struct KernClassTable @@ -333,6 +337,7 @@ struct KernClassTable DEFINE_SIZE_ARRAY (4, classes); }; +template struct KernSubTableFormat2 { inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right, @@ -393,20 +398,19 @@ struct KernSubTableFormat2 } protected: - HBUINT16 rowWidth; /* The width, in bytes, of a row in the table. */ - OffsetTo - leftClassTable; /* Offset from beginning of this subtable to - * left-hand class table. */ - OffsetTo - rightClassTable;/* Offset from beginning of this subtable to - * right-hand class table. */ - OffsetTo - array; /* Offset from beginning of this subtable to - * the start of the kerning array. */ + KernSubTableHeader header; + HBUINT16 rowWidth; /* The width, in bytes, of a row in the table. */ + OffsetTo leftClassTable; /* Offset from beginning of this subtable to + * left-hand class table. */ + OffsetTo rightClassTable;/* Offset from beginning of this subtable to + * right-hand class table. */ + OffsetTo array; /* Offset from beginning of this subtable to + * the start of the kerning array. */ public: - DEFINE_SIZE_MIN (8); + DEFINE_SIZE_MIN (KernSubTableHeader::static_size + 8); }; +template struct KernSubTableFormat3 { inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const @@ -448,44 +452,52 @@ struct KernSubTableFormat3 } protected: - HBUINT16 glyphCount; /* The number of glyphs in this font. */ - HBUINT8 kernValueCount; /* The number of kerning values. */ - HBUINT8 leftClassCount; /* The number of left-hand classes. */ - HBUINT8 rightClassCount;/* The number of right-hand classes. */ - HBUINT8 flags; /* Set to zero (reserved for future use). */ - UnsizedArrayOf - kernValueZ; /* The kerning values. - * Length kernValueCount. */ + KernSubTableHeader header; + HBUINT16 glyphCount; /* The number of glyphs in this font. */ + HBUINT8 kernValueCount; /* The number of kerning values. */ + HBUINT8 leftClassCount; /* The number of left-hand classes. */ + HBUINT8 rightClassCount;/* The number of right-hand classes. */ + HBUINT8 flags; /* Set to zero (reserved for future use). */ + UnsizedArrayOf kernValueZ; /* The kerning values. + * Length kernValueCount. */ #if 0 - UnsizedArrayOf - leftClass; /* The left-hand classes. - * Length glyphCount. */ - UnsizedArrayOf - RightClass; /* The right-hand classes. - * Length glyphCount. */ - UnsizedArrayOf - kernIndex; /* The indices into the kernValue array. - * Length leftClassCount * rightClassCount */ + UnsizedArrayOfleftClass; /* The left-hand classes. + * Length glyphCount. */ + UnsizedArrayOfrightClass; /* The right-hand classes. + * Length glyphCount. */ + UnsizedArrayOfkernIndex; /* The indices into the kernValue array. + * Length leftClassCount * rightClassCount */ #endif public: - DEFINE_SIZE_ARRAY (6, kernValueZ); + DEFINE_SIZE_ARRAY (KernSubTableHeader::static_size + 6, kernValueZ); }; +template struct KernSubTable { - inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right, unsigned int format) const + inline unsigned int get_size (void) const { return u.header.length; } + + inline bool is_simple (void) const + { return !(u.header.coverage & (u.header.CrossStream | u.header.Variation)); } + + inline bool is_horizontal (void) const + { return (u.header.coverage & u.header.Direction) == u.header.DirectionHorizontal; } + + inline bool is_override (void) const + { return bool (u.header.coverage & u.header.Override); } + + inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const { - switch (format) { + switch (u.header.format) { /* This method hooks up to hb_font_t's get_h_kerning. Only support Format0. */ case 0: return u.format0.get_kerning (left, right); default:return 0; } } - inline void apply (AAT::hb_aat_apply_context_t *c, unsigned int format) const + inline void apply (AAT::hb_aat_apply_context_t *c) const { - /* TODO Switch to dispatch(). */ - switch (format) { + switch (u.header.format) { case 0: u.format0.apply (c); return; case 1: u.format1.apply (c); return; case 2: u.format2.apply (c); return; @@ -494,10 +506,13 @@ struct KernSubTable } } - inline bool sanitize (hb_sanitize_context_t *c, unsigned int format) const + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - switch (format) { + if (unlikely (!u.header.sanitize (c) || + u.header.length < u.header.min_size || + !c->check_range (this, u.header.length))) return_trace (false); + switch (u.header.format) { case 0: return_trace (u.format0.sanitize (c)); case 1: return_trace (u.format1.sanitize (c)); case 2: return_trace (u.format2.sanitize (c)); @@ -508,49 +523,17 @@ struct KernSubTable protected: union { - KernSubTableFormat0 format0; - KernSubTableFormat1 format1; - KernSubTableFormat2 format2; - KernSubTableFormat3 format3; + KernSubTableHeader header; + KernSubTableFormat0 format0; + KernSubTableFormat1 format1; + KernSubTableFormat2 format2; + KernSubTableFormat3 format3; } u; public: DEFINE_SIZE_MIN (0); }; -template -struct KernSubTableWrapper -{ - /* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */ - inline const T* thiz (void) const { return static_cast (this); } - - inline bool is_simple (void) const - { return !(thiz()->coverage & (T::CrossStream | T::Variation)); } - - inline bool is_horizontal (void) const - { return (thiz()->coverage & T::Direction) == T::DirectionHorizontal; } - - inline bool is_override (void) const - { return bool (thiz()->coverage & T::Override); } - - inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const - { return thiz()->subtable.get_kerning (left, right, thiz()->format); } - - inline void apply (AAT::hb_aat_apply_context_t *c) const - { thiz()->subtable.apply (c, thiz()->format); } - - inline unsigned int get_size (void) const { return thiz()->length; } - - inline bool sanitize (hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - return_trace (c->check_struct (thiz()) && - thiz()->length >= T::min_size && - c->check_range (thiz(), thiz()->length) && - thiz()->subtable.sanitize (c, thiz()->format)); - } -}; - template struct KernTable { @@ -559,8 +542,10 @@ struct KernTable inline int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right) const { + typedef KernSubTable SubTable; + int v = 0; - const typename T::SubTableWrapper *st = CastP (&thiz()->dataZ); + const SubTable *st = CastP (&thiz()->dataZ); unsigned int count = thiz()->nTables; for (unsigned int i = 0; i < count; i++) { @@ -569,15 +554,17 @@ struct KernTable if (st->is_override ()) v = 0; v += st->get_kerning (left, right); - st = &StructAfter (*st); + st = &StructAfter (*st); } return v; } inline void apply (AAT::hb_aat_apply_context_t *c) const { + typedef KernSubTable SubTable; + c->set_lookup_index (0); - const typename T::SubTableWrapper *st = CastP (&thiz()->dataZ); + const SubTable *st = CastP (&thiz()->dataZ); unsigned int count = thiz()->nTables; /* If there's an override subtable, skip subtables before that. */ unsigned int last_override = 0; @@ -585,9 +572,9 @@ struct KernTable { if (st->is_simple () && st->is_override ()) last_override = i; - st = &StructAfter (*st); + st = &StructAfter (*st); } - st = CastP (&thiz()->dataZ); + st = CastP (&thiz()->dataZ); for (unsigned int i = 0; i < count; i++) { if (!st->is_simple ()) @@ -609,7 +596,7 @@ struct KernTable (void) c->buffer->message (c->font, "end kern subtable %d", c->lookup_index); skip: - st = &StructAfter (*st); + st = &StructAfter (*st); } } @@ -620,13 +607,15 @@ struct KernTable thiz()->version != T::VERSION)) return_trace (false); - const typename T::SubTableWrapper *st = CastP (&thiz()->dataZ); + typedef KernSubTable SubTable; + + const SubTable *st = CastP (&thiz()->dataZ); unsigned int count = thiz()->nTables; for (unsigned int i = 0; i < count; i++) { if (unlikely (!st->sanitize (c))) return_trace (false); - st = &StructAfter (*st); + st = &StructAfter (*st); } return_trace (true); @@ -639,11 +628,8 @@ struct KernOT : KernTable static const uint16_t VERSION = 0x0000u; - struct SubTableWrapper : KernSubTableWrapper + struct SubTableHeader { - friend struct KernTable; - friend struct KernSubTableWrapper; - enum Coverage { Direction = 0x01u, @@ -656,14 +642,19 @@ struct KernOT : KernTable DirectionHorizontal= 0x01u }; - protected: + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this)); + } + + public: HBUINT16 versionZ; /* Unused. */ HBUINT16 length; /* Length of the subtable (including this header). */ HBUINT8 format; /* Subtable format. */ HBUINT8 coverage; /* Coverage bits. */ - KernSubTable subtable; /* Subtable data. */ public: - DEFINE_SIZE_MIN (6); + DEFINE_SIZE_STATIC (6); }; protected: @@ -680,11 +671,8 @@ struct KernAAT : KernTable static const uint32_t VERSION = 0x00010000u; - struct SubTableWrapper : KernSubTableWrapper + struct SubTableHeader { - friend struct KernTable; - friend struct KernSubTableWrapper; - enum Coverage { Direction = 0x80u, @@ -696,15 +684,20 @@ struct KernAAT : KernTable DirectionHorizontal= 0x00u }; - protected: + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this)); + } + + public: HBUINT32 length; /* Length of the subtable (including this header). */ HBUINT8 coverage; /* Coverage bits. */ HBUINT8 format; /* Subtable format. */ HBUINT16 tupleIndex; /* The tuple index (used for variations fonts). * This value specifies which tuple this subtable covers. */ - KernSubTable subtable; /* Subtable data. */ public: - DEFINE_SIZE_MIN (8); + DEFINE_SIZE_STATIC (8); }; protected: From bfafe208da11817b5ebf3751f02af2dcdf57bd19 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 6 Nov 2018 12:11:45 -0500 Subject: [PATCH 37/37] [kern] Switch to dispatch --- src/hb-aat-layout-kerx-table.hh | 12 ++++++------ src/hb-ot-kern-table.hh | 31 +++++++++++++++---------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh index d2242c549..ca2fdb493 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh @@ -637,12 +637,12 @@ struct KerxTable unsigned int subtable_type = get_type (); TRACE_DISPATCH (this, subtable_type); switch (subtable_type) { - case 0 : return_trace (c->dispatch (u.format0)); - case 1 : return_trace (c->dispatch (u.format1)); - case 2 : return_trace (c->dispatch (u.format2)); - case 4 : return_trace (c->dispatch (u.format4)); - case 6 : return_trace (c->dispatch (u.format6)); - default: return_trace (c->default_return_value ()); + case 0: return_trace (c->dispatch (u.format0)); + case 1: return_trace (c->dispatch (u.format1)); + case 2: return_trace (c->dispatch (u.format2)); + case 4: return_trace (c->dispatch (u.format4)); + case 6: return_trace (c->dispatch (u.format6)); + default: return_trace (c->default_return_value ()); } } diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh index 1073530d6..66e827d17 100644 --- a/src/hb-ot-kern-table.hh +++ b/src/hb-ot-kern-table.hh @@ -476,6 +476,7 @@ template struct KernSubTable { inline unsigned int get_size (void) const { return u.header.length; } + inline unsigned int get_type (void) const { return u.header.format; } inline bool is_simple (void) const { return !(u.header.coverage & (u.header.CrossStream | u.header.Variation)); } @@ -488,21 +489,24 @@ struct KernSubTable inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const { - switch (u.header.format) { + switch (get_type ()) { /* This method hooks up to hb_font_t's get_h_kerning. Only support Format0. */ case 0: return u.format0.get_kerning (left, right); default:return 0; } } - inline void apply (AAT::hb_aat_apply_context_t *c) const + template + inline typename context_t::return_t dispatch (context_t *c) const { - switch (u.header.format) { - case 0: u.format0.apply (c); return; - case 1: u.format1.apply (c); return; - case 2: u.format2.apply (c); return; - case 3: u.format3.apply (c); return; - default: return; + unsigned int subtable_type = get_type (); + TRACE_DISPATCH (this, subtable_type); + switch (subtable_type) { + case 0: return_trace (c->dispatch (u.format0)); + case 1: return_trace (c->dispatch (u.format1)); + case 2: return_trace (c->dispatch (u.format2)); + case 3: return_trace (c->dispatch (u.format3)); + default: return_trace (c->default_return_value ()); } } @@ -512,13 +516,8 @@ struct KernSubTable if (unlikely (!u.header.sanitize (c) || u.header.length < u.header.min_size || !c->check_range (this, u.header.length))) return_trace (false); - switch (u.header.format) { - case 0: return_trace (u.format0.sanitize (c)); - case 1: return_trace (u.format1.sanitize (c)); - case 2: return_trace (u.format2.sanitize (c)); - case 3: return_trace (u.format3.sanitize (c)); - default:return_trace (true); - } + + return_trace (dispatch (c)); } protected: @@ -591,7 +590,7 @@ struct KernTable c->sanitizer.set_object (*st); - st->apply (c); + st->dispatch (c); (void) c->buffer->message (c->font, "end kern subtable %d", c->lookup_index);