From 1d66cdcf770e45d995a318592352e4349faecb71 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 19:54:08 -0500 Subject: [PATCH 01/29] Better fix for MSVC 2008 Follow up on b4c61130324455bfd42095b01fa14ac901e441f1 Fixes https://github.com/harfbuzz/harfbuzz/issues/1374 --- src/hb-machinery.hh | 8 ++++---- src/hb-open-type.hh | 8 ++++++++ src/hb-ot-cmap-table.hh | 4 ++-- src/hb-ot-layout-gpos-table.hh | 4 ++-- src/hb-ot-var-avar-table.hh | 9 ++++----- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index f58050da0..f8f1a5b57 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -110,17 +110,17 @@ static inline Type& StructAfter(TObject &X) static const unsigned int min_size = (size) #define DEFINE_SIZE_ARRAY(size, array) \ - DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + VAR * sizeof (array[0])); \ - DEFINE_COMPILES_ASSERTION ((void) array[0].static_size) \ + DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + VAR * (array).item_size); \ + DEFINE_COMPILES_ASSERTION ((void) (array)[0].static_size) \ enum { min_size = (size) } #define DEFINE_SIZE_ARRAY_SIZED(size, array) \ - inline unsigned int get_size (void) const { return (size - array.min_size + array.get_size ()); } \ + inline unsigned int get_size (void) const { return (size - (array).min_size + (array).get_size ()); } \ DEFINE_SIZE_ARRAY(size, array) #define DEFINE_SIZE_ARRAY2(size, array1, array2) \ DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + sizeof (this->array1[0]) + sizeof (this->array2[0])); \ - DEFINE_COMPILES_ASSERTION ((void) array1[0].static_size; (void) array2[0].static_size) \ + DEFINE_COMPILES_ASSERTION ((void) (array1)[0].static_size; (void) (array2)[0].static_size) \ static const unsigned int min_size = (size) diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 56fa43345..14506180f 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -335,6 +335,8 @@ static inline Type& operator + (Base &base, OffsetTo template struct UnsizedArrayOf { + enum { item_size = Type::static_size }; + HB_NO_CREATE_COPY_ASSIGN_TEMPLATE (UnsizedArrayOf, Type); /* Unlikely other places, use "int i" instead of "unsigned int i" for our @@ -435,6 +437,8 @@ struct UnsizedOffsetListOf : UnsizedOffsetArrayOf template struct ArrayOf { + enum { item_size = Type::static_size }; + HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (ArrayOf, Type, LenType); inline const Type *sub_array (unsigned int start_offset, unsigned int *pcount /* IN/OUT */) const @@ -603,6 +607,8 @@ struct OffsetListOf : OffsetArrayOf template struct HeadlessArrayOf { + enum { item_size = Type::static_size }; + HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (HeadlessArrayOf, Type, LenType); inline const Type& operator [] (unsigned int i) const @@ -801,6 +807,8 @@ struct VarSizedBinSearchHeader template struct VarSizedBinSearchArrayOf { + enum { item_size = Type::static_size }; + HB_NO_CREATE_COPY_ASSIGN_TEMPLATE (VarSizedBinSearchArrayOf, Type); inline const Type& operator [] (unsigned int i) const diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 399c46bfc..c0e08666a 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -636,7 +636,7 @@ struct DefaultUVS : SortedArrayOf } public: - DEFINE_SIZE_ARRAY (4, arrayZ); + DEFINE_SIZE_ARRAY (4, *this); }; struct UVSMapping @@ -668,7 +668,7 @@ struct NonDefaultUVS : SortedArrayOf } public: - DEFINE_SIZE_ARRAY (4, arrayZ); + DEFINE_SIZE_ARRAY (4, *this); }; struct VariationSelectorRecord diff --git a/src/hb-ot-layout-gpos-table.hh b/src/hb-ot-layout-gpos-table.hh index fc74af47a..cf735c301 100644 --- a/src/hb-ot-layout-gpos-table.hh +++ b/src/hb-ot-layout-gpos-table.hh @@ -53,7 +53,7 @@ enum attach_type_t { typedef HBUINT16 Value; -typedef Value ValueRecord[VAR]; +typedef UnsizedArrayOf ValueRecord; struct ValueFormat : HBUINT16 { @@ -879,7 +879,7 @@ struct PairPosFormat2 unsigned int stride = len1 + len2; unsigned int record_size = valueFormat1.get_size () + valueFormat2.get_size (); unsigned int count = (unsigned int) class1Count * (unsigned int) class2Count; - return_trace (c->check_array (values, count, record_size) && + return_trace (c->check_array ((const void *) values, count, record_size) && valueFormat1.sanitize_values_stride_unsafe (c, this, &values[0], count, stride) && valueFormat2.sanitize_values_stride_unsafe (c, this, &values[len1], count, stride)); } diff --git a/src/hb-ot-var-avar-table.hh b/src/hb-ot-var-avar-table.hh index d100ca21e..c2b110a21 100644 --- a/src/hb-ot-var-avar-table.hh +++ b/src/hb-ot-var-avar-table.hh @@ -94,7 +94,7 @@ struct SegmentMaps : ArrayOf } public: - DEFINE_SIZE_ARRAY (2, arrayZ); + DEFINE_SIZE_ARRAY (2, *this); }; struct avar @@ -109,7 +109,7 @@ struct avar c->check_struct (this)))) return_trace (false); - const SegmentMaps *map = axisSegmentMapsZ.arrayZ; + const SegmentMaps *map = &firstAxisSegmentMaps; unsigned int count = axisCount; for (unsigned int i = 0; i < count; i++) { @@ -125,7 +125,7 @@ struct avar { unsigned int count = MIN (coords_length, axisCount); - const SegmentMaps *map = axisSegmentMapsZ.arrayZ; + const SegmentMaps *map = &firstAxisSegmentMaps; for (unsigned int i = 0; i < count; i++) { coords[i] = map->map (coords[i]); @@ -140,8 +140,7 @@ struct avar HBUINT16 axisCount; /* The number of variation axes in the font. This * must be the same number as axisCount in the * 'fvar' table. */ - UnsizedArrayOf - axisSegmentMapsZ; + SegmentMaps firstAxisSegmentMaps; public: DEFINE_SIZE_MIN (8); From a953b647507fe2ae8f5187fbfb04e69d2a2952e4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 20:10:03 -0500 Subject: [PATCH 02/29] Revert parts of previous commit that made clang unhappy --- src/hb-machinery.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index f8f1a5b57..d0e1271c7 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -110,7 +110,7 @@ static inline Type& StructAfter(TObject &X) static const unsigned int min_size = (size) #define DEFINE_SIZE_ARRAY(size, array) \ - DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + VAR * (array).item_size); \ + DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + VAR * sizeof ((array)[0])); \ DEFINE_COMPILES_ASSERTION ((void) (array)[0].static_size) \ enum { min_size = (size) } From 4674655841bb810e7b68f03431d7b5a7c34c6f20 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 20:11:10 -0500 Subject: [PATCH 03/29] Minor --- src/hb-ot-shape-complex-arabic-fallback.hh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/hb-ot-shape-complex-arabic-fallback.hh b/src/hb-ot-shape-complex-arabic-fallback.hh index eeb2da85f..0fb3793e2 100644 --- a/src/hb-ot-shape-complex-arabic-fallback.hh +++ b/src/hb-ot-shape-complex-arabic-fallback.hh @@ -212,8 +212,11 @@ struct arabic_fallback_plan_t struct ManifestLookup { + public: OT::Tag tag; OT::OffsetTo lookupOffset; + public: + DEFINE_SIZE_STATIC (6); }; typedef OT::ArrayOf Manifest; From f9e0552debc45afedd86c848484bcd169af62dc2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 21:01:49 -0500 Subject: [PATCH 04/29] [fuzzing] Make "make lib" faster and more usable --- src/Makefile.am | 2 +- test/fuzzing/Makefile.am | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index fbd8f6023..9632b4df6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -195,7 +195,7 @@ libharfbuzz_subset_fuzzing_la_LINK = $(chosen_linker) $(libharfbuzz_subset_fuzzi libharfbuzz_subset_fuzzing_la_SOURCES = $(libharfbuzz_subset_la_SOURCES) libharfbuzz_subset_fuzzing_la_CPPFLAGS = $(HBCFLAGS) $(FUZZING_CPPFLAGS) libharfbuzz_subset_fuzzing_la_LDFLAGS = $(AM_LDFLAGS) -libharfbuzz_subset_fuzzing_la_LIBADD = $(libharfbuzz_subset_la_LIBADD) +libharfbuzz_subset_fuzzing_la_LIBADD = libharfbuzz-fuzzing.la EXTRA_libharfbuzz_subset_fuzzing_la_DEPENDENCIES = $(EXTRA_libharfbuzz_subset_la_DEPENDENCIES) CLEANFILES += libharfbuzz-subset-fuzzing.la diff --git a/test/fuzzing/Makefile.am b/test/fuzzing/Makefile.am index 54178ff43..ed67eee8c 100644 --- a/test/fuzzing/Makefile.am +++ b/test/fuzzing/Makefile.am @@ -7,11 +7,13 @@ DISTCLEANFILES = MAINTAINERCLEANFILES = # Convenience targets: -lib: +lib-only: @$(MAKE) $(AM_MAKEFLAGS) -C $(top_builddir)/src fuzzing +lib: lib-only + @$(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) -$(top_builddir)/src/libharfbuzz-fuzzing.la: lib -$(top_builddir)/src/libharfbuzz-subset-fuzzing.la: lib +$(top_builddir)/src/libharfbuzz-fuzzing.la: lib-only +$(top_builddir)/src/libharfbuzz-subset-fuzzing.la: lib-only EXTRA_DIST += \ README \ @@ -47,7 +49,7 @@ hb_shape_fuzzer_CPPFLAGS = \ $(AM_CPPFLAGS) \ $(NULL) hb_shape_fuzzer_DEPENDENCIES = \ - lib \ + $(top_builddir)/src/libharfbuzz-fuzzing.la $(NULL) hb_subset_fuzzer_SOURCES = \ @@ -62,7 +64,7 @@ hb_subset_fuzzer_CPPFLAGS = \ $(AM_CPPFLAGS) \ $(NULL) hb_subset_fuzzer_DEPENDENCIES = \ - lib \ + $(top_builddir)/src/libharfbuzz-subset-fuzzing.la $(NULL) check: From 752bd8a192af209f44dacaf1d3510d0bfc6354b8 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 21:13:13 -0500 Subject: [PATCH 05/29] [kerx] Fix Format1 tupleKern sanitization Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11312 Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11305 --- src/hb-aat-layout-kerx-table.hh | 6 +++--- ...case-minimized-hb-shape-fuzzer-5629524117553152 | Bin 0 -> 93 bytes 2 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-shape-fuzzer-5629524117553152 diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh index 3cd80acfd..6b61186a9 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh @@ -262,10 +262,12 @@ struct KerxSubTableFormat1 if (Format1EntryT::performAction (entry)) { + unsigned int tuple_count = MAX (1u, table->header.tuple_count ()); + unsigned int kern_idx = Format1EntryT::kernActionIndex (entry); kern_idx = Types::offsetToIndex (kern_idx, &table->machine, kernAction.arrayZ); const FWORD *actions = &kernAction[kern_idx]; - if (!c->sanitizer.check_array (actions, depth)) + if (!c->sanitizer.check_array (actions, depth * tuple_count)) { depth = 0; return false; @@ -276,8 +278,6 @@ struct KerxSubTableFormat1 /* From Apple 'kern' spec: * "Each pops one glyph from the kerning stack and applies the kerning value to it. * The end of the list is marked by an odd value... */ - unsigned int tuple_count = table->header.tuple_count (); - tuple_count = tuple_count ? tuple_count : 1; bool last = false; while (!last && depth--) { diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-shape-fuzzer-5629524117553152 b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-shape-fuzzer-5629524117553152 new file mode 100644 index 0000000000000000000000000000000000000000..01ca51737da80a826de509165a8f733dcc0816cc GIT binary patch literal 93 zcmZQzWME)mQ~-nQ)S?Oy11O>b5kZhZF_5?_Pz0 Date: Sat, 10 Nov 2018 22:41:35 -0500 Subject: [PATCH 06/29] Minor --- src/hb-ot-layout.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 33bf03c13..0353c1c50 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1060,9 +1060,8 @@ hb_ot_layout_lookups_substitute_closure (hb_face_t *face, for (unsigned int i = 0; i < gsub.get_lookup_count (); i++) gsub.get_lookup (i).closure (&c, i); } - iteration_count++; - } while (iteration_count <= HB_CLOSURE_MAX_STAGES - && glyphs_length != glyphs->get_population ()); + } while (iteration_count++ <= HB_CLOSURE_MAX_STAGES && + glyphs_length != glyphs->get_population ()); } /* From 5d0078a48b246e713817e5bb6b4efada9618bea3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 23:52:15 -0500 Subject: [PATCH 07/29] Add hb_blob_ptr_t Use in a couple of places. Push to bots to see how many unhappy before I convert the rest. --- src/hb-blob.hh | 23 +++++++++++++++++++++++ src/hb-ot-layout-gdef-table.hh | 5 ++--- src/hb-ot-layout-gsubgpos.hh | 8 +++----- src/hb-ot-layout.cc | 14 ++++++-------- src/hb-ot-name-table.hh | 12 +++++------- 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/hb-blob.hh b/src/hb-blob.hh index 1f7499fbf..08afd5622 100644 --- a/src/hb-blob.hh +++ b/src/hb-blob.hh @@ -80,4 +80,27 @@ struct hb_blob_t DECLARE_NULL_INSTANCE (hb_blob_t); +/* + * hb_blob_ptr_t + */ + +template +struct hb_blob_ptr_t +{ + typedef typename hb_remove_pointer

::value T; + + inline hb_blob_ptr_t (hb_blob_t *b_ = nullptr) : b (b_) {} + inline hb_blob_t * operator = (hb_blob_t *b_) { return b = b_; } + inline const T * operator -> (void) const { return get (); } + inline const T & operator * (void) const { return *get (); } + template inline operator const C * (void) const { return get (); } + inline operator const char * (void) const { return (const char *) get (); } + inline const T * get (void) const { return b->as (); } + inline hb_blob_t * get_blob (void) const { return b.get_raw (); } + inline unsigned int get_length (void) const { return get_blob ()->length; } + + hb_nonnull_ptr_t b; +}; + + #endif /* HB_BLOB_HH */ diff --git a/src/hb-ot-layout-gdef-table.hh b/src/hb-ot-layout-gdef-table.hh index af7e5a833..aa6ffc884 100644 --- a/src/hb-ot-layout-gdef-table.hh +++ b/src/hb-ot-layout-gdef-table.hh @@ -412,11 +412,10 @@ struct GDEF inline void fini (void) { - hb_blob_destroy (this->blob); + hb_blob_destroy (this->table.get_blob ()); } - hb_blob_t *blob; - hb_nonnull_ptr_t table; + hb_blob_ptr_t table; }; inline unsigned int get_size (void) const diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index eccbcf420..2a89d495e 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -2752,8 +2752,7 @@ struct GSUBGPOS { inline void init (hb_face_t *face) { - this->blob = hb_sanitize_context_t().reference_table (face); - table = this->blob->template as (); + this->table = hb_sanitize_context_t().reference_table (face); this->lookup_count = table->get_lookup_count (); @@ -2770,11 +2769,10 @@ struct GSUBGPOS for (unsigned int i = 0; i < this->lookup_count; i++) this->accels[i].fini (); free (this->accels); - hb_blob_destroy (this->blob); + hb_blob_destroy (this->table.get_blob ()); } - hb_blob_t *blob; - hb_nonnull_ptr_t table; + hb_blob_ptr_t table; unsigned int lookup_count; hb_ot_layout_lookup_accelerator_t *accels; }; diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 0353c1c50..ec2421e3f 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -194,17 +194,15 @@ _hb_ot_blacklist_gdef (unsigned int gdef_len, void OT::GDEF::accelerator_t::init (hb_face_t *face) { - this->blob = hb_sanitize_context_t().reference_table (face); + this->table = hb_sanitize_context_t().reference_table (face); - if (unlikely (_hb_ot_blacklist_gdef (this->blob->length, - face->table.GSUB->blob->length, - face->table.GPOS->blob->length))) + if (unlikely (_hb_ot_blacklist_gdef (this->table.get_length (), + face->table.GSUB->table.get_length (), + face->table.GPOS->table.get_length ()))) { - hb_blob_destroy (this->blob); - this->blob = hb_blob_get_empty (); + hb_blob_destroy (this->table.get_blob ()); + this->table = hb_blob_get_empty (); } - - table = this->blob->as (); } static void diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh index f1e785f19..5aa068136 100644 --- a/src/hb-ot-name-table.hh +++ b/src/hb-ot-name-table.hh @@ -179,11 +179,10 @@ struct name { inline void init (hb_face_t *face) { - this->blob = hb_sanitize_context_t().reference_table (face); - this->table = this->blob->as (); - assert (this->blob->length >= this->table->stringOffset); + this->table = hb_sanitize_context_t().reference_table (face); + assert (this->table.get_length () >= this->table->stringOffset); this->pool = (this->table+this->table->stringOffset).arrayZ; - this->pool_len = this->blob->length - this->table->stringOffset; + this->pool_len = this->table.get_length () - this->table->stringOffset; const hb_array_t all_names (this->table->nameRecordZ.arrayZ, this->table->count); @@ -221,7 +220,7 @@ struct name inline void fini (void) { this->names.fini (); - hb_blob_destroy (this->blob); + hb_blob_destroy (this->table.get_blob ()); } inline int get_index (hb_ot_name_id_t name_id, @@ -253,11 +252,10 @@ struct name } private: - hb_blob_t *blob; const void *pool; unsigned int pool_len; public: - hb_nonnull_ptr_t table; + hb_blob_ptr_t table; hb_vector_t names; }; From 2ee1d9f555fba60342bab63294a6dacca10466de Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 00:11:28 -0500 Subject: [PATCH 08/29] [blob] Change null object memory mode to DUPLICATE We never rely on that being equal to readonly. Just not being writable. Maybe not even that given that the object is inert. In prep for next commit, using default null pool. --- src/hb-blob.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 9271200b1..efca833e2 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -59,7 +59,7 @@ DEFINE_NULL_INSTANCE (hb_blob_t) = nullptr, /* data */ 0, /* length */ - HB_MEMORY_MODE_READONLY, /* mode */ + HB_MEMORY_MODE_DUPLICATE, /* mode */ nullptr, /* user_data */ nullptr /* destroy */ From 34185ff3bc7ece5620145fc05da07c79da950f34 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 00:12:30 -0500 Subject: [PATCH 09/29] [blob] Use default null object --- src/hb-blob.cc | 12 ------------ src/hb-blob.hh | 1 - 2 files changed, 13 deletions(-) diff --git a/src/hb-blob.cc b/src/hb-blob.cc index efca833e2..26c0d143e 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -53,18 +53,6 @@ **/ -DEFINE_NULL_INSTANCE (hb_blob_t) = -{ - HB_OBJECT_HEADER_STATIC, - - nullptr, /* data */ - 0, /* length */ - HB_MEMORY_MODE_DUPLICATE, /* mode */ - - nullptr, /* user_data */ - nullptr /* destroy */ -}; - /** * hb_blob_create: (skip) * @data: Pointer to blob data. diff --git a/src/hb-blob.hh b/src/hb-blob.hh index 08afd5622..7007540c3 100644 --- a/src/hb-blob.hh +++ b/src/hb-blob.hh @@ -77,7 +77,6 @@ struct hb_blob_t void *user_data; hb_destroy_func_t destroy; }; -DECLARE_NULL_INSTANCE (hb_blob_t); /* From 109891d49876de4de14a91adefbdf681c2b9acc2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 00:15:08 -0500 Subject: [PATCH 10/29] [shape-plan] Make null object all zeros To remove custom null object next.. --- src/hb-shape-plan.cc | 8 ++++---- src/hb-shape-plan.hh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index f2f210196..644c1b6b0 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc @@ -107,8 +107,8 @@ DEFINE_NULL_INSTANCE (hb_shape_plan_t) = { HB_OBJECT_HEADER_STATIC, - true, /* default_shaper_list */ nullptr, /* face */ + false, /* custom_shaper_list */ HB_SEGMENT_PROPERTIES_DEFAULT, /* props */ nullptr, /* shaper_func */ @@ -196,7 +196,7 @@ hb_shape_plan_create2 (hb_face_t *face, assert (props->direction != HB_DIRECTION_INVALID); hb_face_make_immutable (face); - shape_plan->default_shaper_list = !shaper_list; + shape_plan->custom_shaper_list = shaper_list; shape_plan->face_unsafe = face; shape_plan->props = *props; shape_plan->num_user_features = num_user_features; @@ -382,7 +382,7 @@ static unsigned int hb_shape_plan_hash (const hb_shape_plan_t *shape_plan) { return hb_segment_properties_hash (&shape_plan->props) + - shape_plan->default_shaper_list ? 0 : (intptr_t) shape_plan->shaper_func; + shape_plan->custom_shaper_list ? (intptr_t) shape_plan->shaper_func : 0; } #endif @@ -436,7 +436,7 @@ hb_shape_plan_matches (const hb_shape_plan_t *shape_plan, return hb_segment_properties_equal (&shape_plan->props, &proposal->props) && hb_shape_plan_user_features_match (shape_plan, proposal) && hb_shape_plan_coords_match (shape_plan, proposal) && - ((shape_plan->default_shaper_list && !proposal->shaper_list) || + ((!shape_plan->custom_shaper_list && !proposal->shaper_list) || (shape_plan->shaper_func == proposal->shaper_func)); } diff --git a/src/hb-shape-plan.hh b/src/hb-shape-plan.hh index 403c3ebdf..fea3e10c3 100644 --- a/src/hb-shape-plan.hh +++ b/src/hb-shape-plan.hh @@ -35,8 +35,8 @@ struct hb_shape_plan_t { hb_object_header_t header; - hb_bool_t default_shaper_list; hb_face_t *face_unsafe; /* We don't carry a reference to face. */ + bool custom_shaper_list; hb_segment_properties_t props; hb_shape_func_t *shaper_func; From dcb63868333ba8e229fd8756377151440dd9fd23 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 00:16:17 -0500 Subject: [PATCH 11/29] [shape-plan] Remove use of custom null object --- src/hb-shape-plan.cc | 24 ------------------------ src/hb-shape-plan.hh | 1 - 2 files changed, 25 deletions(-) diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index 644c1b6b0..8fcc038f9 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc @@ -103,30 +103,6 @@ hb_shape_plan_plan (hb_shape_plan_t *shape_plan, * hb_shape_plan_t */ -DEFINE_NULL_INSTANCE (hb_shape_plan_t) = -{ - HB_OBJECT_HEADER_STATIC, - - nullptr, /* face */ - false, /* custom_shaper_list */ - HB_SEGMENT_PROPERTIES_DEFAULT, /* props */ - - nullptr, /* shaper_func */ - nullptr, /* shaper_name */ - - nullptr, /* user_features */ - 0, /* num_user_featurs */ - - nullptr, /* coords */ - 0, /* num_coords */ - - { -#define HB_SHAPER_IMPLEMENT(shaper) HB_ATOMIC_PTR_INIT (HB_SHAPER_DATA_INVALID), -#include "hb-shaper-list.hh" -#undef HB_SHAPER_IMPLEMENT - }, -}; - /** * hb_shape_plan_create: (Xconstructor) diff --git a/src/hb-shape-plan.hh b/src/hb-shape-plan.hh index fea3e10c3..891b99574 100644 --- a/src/hb-shape-plan.hh +++ b/src/hb-shape-plan.hh @@ -50,7 +50,6 @@ struct hb_shape_plan_t struct hb_shaper_data_t shaper_data; }; -DECLARE_NULL_INSTANCE (hb_shape_plan_t); #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS \ , const hb_feature_t *user_features \ From 925b7a214f06b83b6f2278052656dabc4ebdd6b7 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 00:17:30 -0500 Subject: [PATCH 12/29] Comment --- src/hb-font.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-font.cc b/src/hb-font.cc index b24995b12..ca710a6f6 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -1306,7 +1306,7 @@ DEFINE_NULL_INSTANCE (hb_font_t) = 0, /* num_coords */ nullptr, /* coords */ - const_cast (&_hb_Null_hb_font_funcs_t), /* klass */ + const_cast (&_hb_Null_hb_font_funcs_t), nullptr, /* user_data */ nullptr, /* destroy */ From 0b0fad3ea8888d57d1e077077f5897d1901c5371 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 00:26:55 -0500 Subject: [PATCH 13/29] [color] Port to hb_blob_ptr_t Fix hb_blob_ptr_t::get_length () as well. --- src/hb-blob.hh | 2 +- src/hb-ot-color-cbdt-table.hh | 38 ++++++++++++----------------------- src/hb-ot-color-sbix-table.hh | 10 ++++----- src/hb-ot-color-svg-table.hh | 11 +++++----- src/hb-ot-glyf-table.hh | 22 ++++++++------------ 5 files changed, 31 insertions(+), 52 deletions(-) diff --git a/src/hb-blob.hh b/src/hb-blob.hh index 7007540c3..1b7d4bed9 100644 --- a/src/hb-blob.hh +++ b/src/hb-blob.hh @@ -96,7 +96,7 @@ struct hb_blob_ptr_t inline operator const char * (void) const { return (const char *) get (); } inline const T * get (void) const { return b->as (); } inline hb_blob_t * get_blob (void) const { return b.get_raw (); } - inline unsigned int get_length (void) const { return get_blob ()->length; } + inline unsigned int get_length (void) const { return b.get ()->length; } hb_nonnull_ptr_t b; }; diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh index 580dc3769..0a8f4e1ab 100644 --- a/src/hb-ot-color-cbdt-table.hh +++ b/src/hb-ot-color-cbdt-table.hh @@ -384,26 +384,16 @@ struct CBDT { inline void init (hb_face_t *face) { + cblc = hb_sanitize_context_t().reference_table (face); + cbdt = hb_sanitize_context_t().reference_table (face); + upem = hb_face_get_upem (face); - - cblc_blob = hb_sanitize_context_t().reference_table (face); - cbdt_blob = hb_sanitize_context_t().reference_table (face); - cbdt_len = hb_blob_get_length (cbdt_blob); - - if (hb_blob_get_length (cblc_blob) == 0) { - cblc = nullptr; - cbdt = nullptr; - return; /* Not a bitmap font. */ - } - cblc = cblc_blob->as (); - cbdt = cbdt_blob->as (); - } inline void fini (void) { - hb_blob_destroy (this->cblc_blob); - hb_blob_destroy (this->cbdt_blob); + hb_blob_destroy (this->cblc.get_blob ()); + hb_blob_destroy (this->cbdt.get_blob ()); } inline bool get_extents (hb_font_t *font, hb_codepoint_t glyph, @@ -423,6 +413,7 @@ struct CBDT return false; { + unsigned int cbdt_len = cbdt.get_length (); if (unlikely (image_offset > cbdt_len || cbdt_len - image_offset < image_length)) return false; @@ -475,6 +466,7 @@ struct CBDT return hb_blob_get_empty (); { + unsigned int cbdt_len = cbdt.get_length (); if (unlikely (image_offset > cbdt_len || cbdt_len - image_offset < image_length)) return hb_blob_get_empty (); @@ -485,7 +477,7 @@ struct CBDT return hb_blob_get_empty (); const GlyphBitmapDataFormat17& glyphFormat17 = StructAtOffset (this->cbdt, image_offset); - return hb_blob_create_sub_blob (cbdt_blob, + return hb_blob_create_sub_blob (cbdt.get_blob (), image_offset + GlyphBitmapDataFormat17::min_size, glyphFormat17.data.len); } @@ -494,7 +486,7 @@ struct CBDT return hb_blob_get_empty (); const GlyphBitmapDataFormat18& glyphFormat18 = StructAtOffset (this->cbdt, image_offset); - return hb_blob_create_sub_blob (cbdt_blob, + return hb_blob_create_sub_blob (cbdt.get_blob (), image_offset + GlyphBitmapDataFormat18::min_size, glyphFormat18.data.len); } @@ -503,7 +495,7 @@ struct CBDT return hb_blob_get_empty (); const GlyphBitmapDataFormat19& glyphFormat19 = StructAtOffset (this->cbdt, image_offset); - return hb_blob_create_sub_blob (cbdt_blob, + return hb_blob_create_sub_blob (cbdt.get_blob (), image_offset + GlyphBitmapDataFormat19::min_size, glyphFormat19.data.len); } @@ -513,16 +505,12 @@ struct CBDT return hb_blob_get_empty (); } - inline bool has_data () const - { return cbdt_len; } + inline bool has_data () const { return cbdt.get_length (); } private: - hb_blob_t *cblc_blob; - hb_blob_t *cbdt_blob; - hb_nonnull_ptr_t cblc; - hb_nonnull_ptr_t cbdt; + hb_blob_ptr_t cblc; + hb_blob_ptr_t cbdt; - unsigned int cbdt_len; unsigned int upem; }; diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index 7a01d14ae..64ebb63e9 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -140,14 +140,13 @@ struct sbix { inline void init (hb_face_t *face) { - sbix_blob = hb_sanitize_context_t().reference_table (face); - table = sbix_blob->as (); + table = hb_sanitize_context_t().reference_table (face); num_glyphs = face->get_num_glyphs (); } inline void fini (void) { - hb_blob_destroy (sbix_blob); + hb_blob_destroy (table.get_blob ()); } inline bool has_data () const @@ -169,7 +168,7 @@ struct sbix int *y_offset, unsigned int *available_ppem) const { - return choose_strike (font).get_glyph_blob (glyph_id, sbix_blob, + return choose_strike (font).get_glyph_blob (glyph_id, table.get_blob (), HB_TAG ('p','n','g',' '), x_offset, y_offset, num_glyphs, available_ppem); @@ -263,8 +262,7 @@ struct sbix } private: - hb_blob_t *sbix_blob; - hb_nonnull_ptr_t table; + hb_blob_ptr_t table; unsigned int num_glyphs; }; diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh index 069c54788..37b28ea68 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh @@ -81,25 +81,24 @@ struct SVG { inline void init (hb_face_t *face) { - svg_blob = hb_sanitize_context_t().reference_table (face); - table = svg_blob->as (); + table = hb_sanitize_context_t().reference_table (face); } inline void fini (void) { - hb_blob_destroy (svg_blob); + hb_blob_destroy (table.get_blob ()); } inline hb_blob_t *reference_blob_for_glyph (hb_codepoint_t glyph_id) const { - return table->get_glyph_entry (glyph_id).reference_blob (svg_blob, table->svgDocEntries); + return table->get_glyph_entry (glyph_id).reference_blob (table.get_blob (), + table->svgDocEntries); } inline bool has_data () const { return table->has_data (); } private: - hb_blob_t *svg_blob; - hb_nonnull_ptr_t table; + hb_blob_ptr_t table; }; inline const SVGDocumentIndexEntry &get_glyph_entry (hb_codepoint_t glyph_id) const diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 0623be892..43b921e2c 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -246,19 +246,16 @@ struct glyf short_offset = 0 == head_table->indexToLocFormat; hb_blob_destroy (head_blob); - loca_blob = hb_sanitize_context_t().reference_table (face); - loca_table = loca_blob->as (); - glyf_blob = hb_sanitize_context_t().reference_table (face); - glyf_table = glyf_blob->as (); + loca_table = hb_sanitize_context_t().reference_table (face); + glyf_table = hb_sanitize_context_t().reference_table (face); - num_glyphs = MAX (1u, hb_blob_get_length (loca_blob) / (short_offset ? 2 : 4)) - 1; - glyf_len = hb_blob_get_length (glyf_blob); + num_glyphs = MAX (1u, loca_table.get_length () / (short_offset ? 2 : 4)) - 1; } inline void fini (void) { - hb_blob_destroy (loca_blob); - hb_blob_destroy (glyf_blob); + hb_blob_destroy (loca_table.get_blob ()); + hb_blob_destroy (glyf_table.get_blob ()); } /* @@ -388,7 +385,7 @@ struct glyf *end_offset = offsets[glyph + 1]; } - if (*start_offset > *end_offset || *end_offset > glyf_len) + if (*start_offset > *end_offset || *end_offset > glyf_table.get_length ()) return false; return true; @@ -476,11 +473,8 @@ struct glyf private: bool short_offset; unsigned int num_glyphs; - hb_nonnull_ptr_t loca_table; - hb_nonnull_ptr_t glyf_table; - hb_blob_t *loca_blob; - hb_blob_t *glyf_blob; - unsigned int glyf_len; + hb_blob_ptr_t loca_table; + hb_blob_ptr_t glyf_table; }; protected: From 0e2680a6e8d16afd38ffdb6e8cf244150a5e3837 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 00:28:47 -0500 Subject: [PATCH 14/29] [cmap] Port to hb_blob_ptr_t Although didn't need it... --- src/hb-ot-cmap-table.hh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index c0e08666a..8d94ad312 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -1014,8 +1014,7 @@ struct cmap { inline void init (hb_face_t *face) { - this->blob = hb_sanitize_context_t().reference_table (face); - const cmap *table = this->blob->as (); + this->table = hb_sanitize_context_t().reference_table (face); bool symbol; this->subtable = table->find_best_subtable (&symbol); this->subtable_uvs = &Null(CmapSubtableFormat14); @@ -1051,7 +1050,7 @@ struct cmap inline void fini (void) { - hb_blob_destroy (this->blob); + hb_blob_destroy (this->table.get_blob ()); } inline bool get_nominal_glyph (hb_codepoint_t unicode, @@ -1157,7 +1156,7 @@ struct cmap CmapSubtableFormat4::accelerator_t format4_accel; - hb_blob_t *blob; + hb_blob_ptr_t table; }; protected: From bb9abb4efd7d72198ffe8abb137ccf07ae17743e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 00:39:52 -0500 Subject: [PATCH 15/29] [hmtx/port] Use hb_blob_ptr_t --- src/hb-ot-hmtx-table.hh | 24 ++++++++++-------------- src/hb-ot-post-table.hh | 11 +++++------ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index f898a0336..7a1eb799a 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -113,7 +113,7 @@ struct hmtxvmtx DEBUG_MSG(SUBSET, nullptr, "%c%c%c%c in src has %d advances, %d lsbs", HB_UNTAG(T::tableTag), _mtx.num_advances, _mtx.num_metrics - _mtx.num_advances); DEBUG_MSG(SUBSET, nullptr, "%c%c%c%c in dest has %d advances, %d lsbs, %u bytes", HB_UNTAG(T::tableTag), num_advances, gids.len - num_advances, (unsigned int) dest_sz); - const char *source_table = hb_blob_get_data (_mtx.blob, nullptr); + const char *source_table = hb_blob_get_data (_mtx.table.get_blob (), nullptr); // Copy everything over LongMetric * old_metrics = (LongMetric *) source_table; FWORD *lsbs = (FWORD *) (old_metrics + _mtx.num_advances); @@ -221,10 +221,10 @@ struct hmtxvmtx has_font_extents = got_font_extents; - blob = hb_sanitize_context_t().reference_table (face, T::tableTag); + table = hb_sanitize_context_t().reference_table (face, T::tableTag); /* Cap num_metrics() and num_advances() based on table length. */ - unsigned int len = hb_blob_get_length (blob); + unsigned int len = table.get_length (); if (unlikely (num_advances * 4 > len)) num_advances = len / 4; num_metrics = num_advances + (len - 4 * num_advances) / 2; @@ -234,19 +234,17 @@ struct hmtxvmtx if (unlikely (!num_advances)) { num_metrics = num_advances = 0; - hb_blob_destroy (blob); - blob = hb_blob_get_empty (); + hb_blob_destroy (table.get_blob ()); + table = hb_blob_get_empty (); } - table = blob->as (); - var_blob = hb_sanitize_context_t().reference_table (face, T::variationsTag); - var_table = var_blob->as (); + var_table = hb_sanitize_context_t().reference_table (face, T::variationsTag); } inline void fini (void) { - hb_blob_destroy (blob); - hb_blob_destroy (var_blob); + hb_blob_destroy (table.get_blob ()); + hb_blob_destroy (var_table.get_blob ()); } /* TODO Add variations version. */ @@ -301,10 +299,8 @@ struct hmtxvmtx unsigned int default_advance; private: - const hmtxvmtx *table; - hb_blob_t *blob; - const HVARVVAR *var_table; - hb_blob_t *var_blob; + hb_blob_ptr_t table; + hb_blob_ptr_t var_table; }; protected: diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index 77eef3f5c..485058144 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -101,9 +101,8 @@ struct post { index_to_offset.init (); - blob = hb_sanitize_context_t().reference_table (face); - const post *table = blob->as (); - unsigned int table_length = blob->length; + table = hb_sanitize_context_t().reference_table (face); + unsigned int table_length = table.get_length (); version = table->version.to_int (); if (version != 0x00020000) @@ -114,7 +113,7 @@ struct post glyphNameIndex = &v2.glyphNameIndex; pool = &StructAfter (v2.glyphNameIndex); - const uint8_t *end = (uint8_t *) table + table_length; + const uint8_t *end = (const uint8_t *) (const void *) table + table_length; for (const uint8_t *data = pool; index_to_offset.len < 65535 && data < end && data + *data < end; data += 1 + *data) @@ -124,7 +123,7 @@ struct post { index_to_offset.fini (); free (gids_sorted_by_name.get ()); - hb_blob_destroy (blob); + hb_blob_destroy (table.get_blob ()); } inline bool get_glyph_name (hb_codepoint_t glyph, @@ -244,7 +243,7 @@ struct post } private: - hb_blob_t *blob; + hb_blob_ptr_t table; uint32_t version; const ArrayOf *glyphNameIndex; hb_vector_t index_to_offset; From da6aa3b0333de3f2169a5cfcb33374e1b2fe346e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 11:40:57 -0500 Subject: [PATCH 16/29] Add hb_blob_ptr_t.destroy() --- src/hb-blob.hh | 1 + src/hb-ot-cmap-table.hh | 2 +- src/hb-ot-color-cbdt-table.hh | 4 ++-- src/hb-ot-color-sbix-table.hh | 2 +- src/hb-ot-color-svg-table.hh | 2 +- src/hb-ot-glyf-table.hh | 4 ++-- src/hb-ot-hmtx-table.hh | 6 +++--- src/hb-ot-layout-gdef-table.hh | 2 +- src/hb-ot-layout-gsubgpos.hh | 2 +- src/hb-ot-name-table.hh | 2 +- src/hb-ot-post-table.hh | 2 +- 11 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/hb-blob.hh b/src/hb-blob.hh index 1b7d4bed9..802b1f07e 100644 --- a/src/hb-blob.hh +++ b/src/hb-blob.hh @@ -97,6 +97,7 @@ struct hb_blob_ptr_t inline const T * get (void) const { return b->as (); } inline hb_blob_t * get_blob (void) const { return b.get_raw (); } inline unsigned int get_length (void) const { return b.get ()->length; } + inline void destroy (void) { hb_blob_destroy (b.get ()); b = nullptr; } hb_nonnull_ptr_t b; }; diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 8d94ad312..4c24cb99c 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -1050,7 +1050,7 @@ struct cmap inline void fini (void) { - hb_blob_destroy (this->table.get_blob ()); + this->table.destroy (); } inline bool get_nominal_glyph (hb_codepoint_t unicode, diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh index 0a8f4e1ab..47774fd8f 100644 --- a/src/hb-ot-color-cbdt-table.hh +++ b/src/hb-ot-color-cbdt-table.hh @@ -392,8 +392,8 @@ struct CBDT inline void fini (void) { - hb_blob_destroy (this->cblc.get_blob ()); - hb_blob_destroy (this->cbdt.get_blob ()); + this->cblc.destroy (); + this->cbdt.destroy (); } inline bool get_extents (hb_font_t *font, hb_codepoint_t glyph, diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index 64ebb63e9..80d65022c 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -146,7 +146,7 @@ struct sbix inline void fini (void) { - hb_blob_destroy (table.get_blob ()); + table.destroy (); } inline bool has_data () const diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh index 37b28ea68..bad8ef549 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh @@ -86,7 +86,7 @@ struct SVG inline void fini (void) { - hb_blob_destroy (table.get_blob ()); + table.destroy (); } inline hb_blob_t *reference_blob_for_glyph (hb_codepoint_t glyph_id) const diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 43b921e2c..42bb03ff8 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -254,8 +254,8 @@ struct glyf inline void fini (void) { - hb_blob_destroy (loca_table.get_blob ()); - hb_blob_destroy (glyf_table.get_blob ()); + loca_table.destroy (); + glyf_table.destroy (); } /* diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index 7a1eb799a..20948edbf 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -234,7 +234,7 @@ struct hmtxvmtx if (unlikely (!num_advances)) { num_metrics = num_advances = 0; - hb_blob_destroy (table.get_blob ()); + table.destroy (); table = hb_blob_get_empty (); } @@ -243,8 +243,8 @@ struct hmtxvmtx inline void fini (void) { - hb_blob_destroy (table.get_blob ()); - hb_blob_destroy (var_table.get_blob ()); + table.destroy (); + var_table.destroy (); } /* TODO Add variations version. */ diff --git a/src/hb-ot-layout-gdef-table.hh b/src/hb-ot-layout-gdef-table.hh index aa6ffc884..e6804e6b5 100644 --- a/src/hb-ot-layout-gdef-table.hh +++ b/src/hb-ot-layout-gdef-table.hh @@ -412,7 +412,7 @@ struct GDEF inline void fini (void) { - hb_blob_destroy (this->table.get_blob ()); + this->table.destroy (); } hb_blob_ptr_t table; diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 2a89d495e..1335601a3 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -2769,7 +2769,7 @@ struct GSUBGPOS for (unsigned int i = 0; i < this->lookup_count; i++) this->accels[i].fini (); free (this->accels); - hb_blob_destroy (this->table.get_blob ()); + this->table.destroy (); } hb_blob_ptr_t table; diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh index 5aa068136..ab07b7196 100644 --- a/src/hb-ot-name-table.hh +++ b/src/hb-ot-name-table.hh @@ -220,7 +220,7 @@ struct name inline void fini (void) { this->names.fini (); - hb_blob_destroy (this->table.get_blob ()); + this->table.destroy (); } inline int get_index (hb_ot_name_id_t name_id, diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index 485058144..557fefada 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -123,7 +123,7 @@ struct post { index_to_offset.fini (); free (gids_sorted_by_name.get ()); - hb_blob_destroy (table.get_blob ()); + table.destroy (); } inline bool get_glyph_name (hb_codepoint_t glyph, From 0e0af11c62c6a55248a5d3c8868da91ef36384c5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 12:54:16 -0500 Subject: [PATCH 17/29] [hdmx] Renames --- src/hb-ot-hdmx-table.hh | 46 ++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/hb-ot-hdmx-table.hh b/src/hb-ot-hdmx-table.hh index 04511b5d0..9a5f9453e 100644 --- a/src/hb-ot-hdmx-table.hh +++ b/src/hb-ot-hdmx-table.hh @@ -44,15 +44,15 @@ struct DeviceRecord struct SubsetView { const DeviceRecord *source_device_record; - unsigned int size_device_record; + unsigned int sizeDeviceRecord; hb_subset_plan_t *subset_plan; inline void init(const DeviceRecord *source_device_record, - unsigned int size_device_record, + unsigned int sizeDeviceRecord, hb_subset_plan_t *subset_plan) { this->source_device_record = source_device_record; - this->size_device_record = size_device_record; + this->sizeDeviceRecord = sizeDeviceRecord; this->subset_plan = subset_plan; } @@ -68,7 +68,7 @@ struct DeviceRecord const HBUINT8* width = &(this->source_device_record->widthsZ[gid]); - if (width < ((const HBUINT8 *) this->source_device_record) + size_device_record) + if (width < ((const HBUINT8 *) this->source_device_record) + sizeDeviceRecord) return width; else return nullptr; @@ -92,8 +92,8 @@ struct DeviceRecord return_trace (false); } - this->pixel_size.set (subset_view.source_device_record->pixel_size); - this->max_width.set (subset_view.source_device_record->max_width); + this->pixelSize.set (subset_view.source_device_record->pixelSize); + this->maxWidth.set (subset_view.source_device_record->maxWidth); for (unsigned int i = 0; i < subset_view.len(); i++) { @@ -109,16 +109,16 @@ struct DeviceRecord return_trace (true); } - inline bool sanitize (hb_sanitize_context_t *c, unsigned int size_device_record) const + inline bool sanitize (hb_sanitize_context_t *c, unsigned int sizeDeviceRecord) const { TRACE_SANITIZE (this); return_trace (likely (c->check_struct (this) && - c->check_range (this, size_device_record))); + c->check_range (this, sizeDeviceRecord))); } - HBUINT8 pixel_size; /* Pixel size for following widths (as ppem). */ - HBUINT8 max_width; /* Maximum width. */ - UnsizedArrayOf widthsZ; /* Array of widths (numGlyphs is from the 'maxp' table). */ + HBUINT8 pixelSize; /* Pixel size for following widths (as ppem). */ + HBUINT8 maxWidth; /* Maximum width. */ + UnsizedArrayOf widthsZ; /* Array of widths (numGlyphs is from the 'maxp' table). */ public: DEFINE_SIZE_ARRAY (2, widthsZ); }; @@ -130,13 +130,13 @@ struct hdmx inline unsigned int get_size (void) const { - return min_size + num_records * size_device_record; + return min_size + numRecords * sizeDeviceRecord; } inline const DeviceRecord& operator [] (unsigned int i) const { - if (unlikely (i >= num_records)) return Null(DeviceRecord); - return StructAtOffset (&this->dataZ, i * size_device_record); + if (unlikely (i >= numRecords)) return Null(DeviceRecord); + return StructAtOffset (&this->dataZ, i * sizeDeviceRecord); } inline bool serialize (hb_serialize_context_t *c, const hdmx *source_hdmx, hb_subset_plan_t *plan) @@ -146,13 +146,13 @@ struct hdmx if (unlikely (!c->extend_min ((*this)))) return_trace (false); this->version.set (source_hdmx->version); - this->num_records.set (source_hdmx->num_records); - this->size_device_record.set (DeviceRecord::get_size (plan->glyphs.len)); + this->numRecords.set (source_hdmx->numRecords); + this->sizeDeviceRecord.set (DeviceRecord::get_size (plan->glyphs.len)); - for (unsigned int i = 0; i < source_hdmx->num_records; i++) + for (unsigned int i = 0; i < source_hdmx->numRecords; i++) { DeviceRecord::SubsetView subset_view; - subset_view.init (&(*source_hdmx)[i], source_hdmx->size_device_record, plan); + subset_view.init (&(*source_hdmx)[i], source_hdmx->sizeDeviceRecord, plan); if (!c->start_embed ()->serialize (c, subset_view)) return_trace (false); @@ -163,7 +163,7 @@ struct hdmx static inline size_t get_subsetted_size (const hdmx *source_hdmx, hb_subset_plan_t *plan) { - return min_size + source_hdmx->num_records * DeviceRecord::get_size (plan->glyphs.len); + return min_size + source_hdmx->numRecords * DeviceRecord::get_size (plan->glyphs.len); } inline bool subset (hb_subset_plan_t *plan) const @@ -201,15 +201,15 @@ struct hdmx { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && version == 0 && - !hb_unsigned_mul_overflows (num_records, size_device_record) && - size_device_record >= DeviceRecord::min_size && + !hb_unsigned_mul_overflows (numRecords, sizeDeviceRecord) && + sizeDeviceRecord >= DeviceRecord::min_size && c->check_range (this, get_size())); } protected: HBUINT16 version; /* Table version number (0) */ - HBUINT16 num_records; /* Number of device records. */ - HBUINT32 size_device_record; /* Size of a device record, 32-bit aligned. */ + HBUINT16 numRecords; /* Number of device records. */ + HBUINT32 sizeDeviceRecord; /* Size of a device record, 32-bit aligned. */ UnsizedArrayOf dataZ; /* Array of device records. */ public: DEFINE_SIZE_ARRAY (8, dataZ); From 903856ab505cbc6b756d7b904650df72e90f67a7 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 15:45:58 -0500 Subject: [PATCH 18/29] Remove unused function --- src/hb-machinery.hh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index d0e1271c7..c85c69d75 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -797,11 +797,6 @@ struct hb_lazy_loader_t : hb_data_wrapper_t inline const Returned & operator * (void) const { return *get (); } template inline operator const C * (void) const { return get (); } - inline Data * get_data (void) const - { - return *(((Data **) this) - WheresData); - } - inline Stored * get_stored (void) const { retry: From eecccc919ce15f60ae7ef9da5cfb311b4aa05c63 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 15:48:47 -0500 Subject: [PATCH 19/29] Don't store to null object Ouch :). --- src/hb-machinery.hh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index c85c69d75..160e99a58 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -782,10 +782,6 @@ struct hb_lazy_loader_t : hb_data_wrapper_t inline Stored * do_create (void) const { - Stored *p = this->template call_create (); - if (unlikely (!p)) - p = const_cast (Funcs::get_null ()); - return p; } static inline void do_destroy (Stored *p) { @@ -803,7 +799,10 @@ struct hb_lazy_loader_t : hb_data_wrapper_t Stored *p = this->instance.get (); if (unlikely (!p)) { - p = do_create (); + p = this->template call_create (); + if (unlikely (!p)) + return const_cast (Funcs::get_null ()); + if (unlikely (!this->instance.cmpexch (nullptr, p))) { do_destroy (p); From 442a72d95ab1fb3a47b486d8d1eb68e909d0ffb8 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 15:51:23 -0500 Subject: [PATCH 20/29] Declare Null() constexpr --- src/hb-null.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-null.hh b/src/hb-null.hh index 25a24f05c..5b9c7db79 100644 --- a/src/hb-null.hh +++ b/src/hb-null.hh @@ -43,7 +43,7 @@ hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_ /* Generic nul-content Null objects. */ template -static inline Type const & Null (void) { +static inline constexpr Type const & Null (void) { static_assert (sizeof (Type) <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE."); return *reinterpret_cast (_hb_NullPool); } From 98c6f03ccdd0630282ea0b166f66dcfb2a9c1f51 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 15:54:20 -0500 Subject: [PATCH 21/29] Minor --- src/hb-face.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hb-face.cc b/src/hb-face.cc index 8e731052c..952e6a6a9 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -129,7 +129,6 @@ hb_face_create_for_tables (hb_reference_table_func_t reference_table_func, face->user_data = user_data; face->destroy = destroy; - face->upem = 0; face->num_glyphs = (unsigned int) -1; face->table.init0 (face); From 55c66c7c56c1ecd493f51fe66fd434b28addfb41 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 16:09:38 -0500 Subject: [PATCH 22/29] Revert "Declare Null() constexpr" This reverts commit 442a72d95ab1fb3a47b486d8d1eb68e909d0ffb8. Doesn't make sense. No idea how my local compilers where happy with it! --- src/hb-null.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-null.hh b/src/hb-null.hh index 5b9c7db79..25a24f05c 100644 --- a/src/hb-null.hh +++ b/src/hb-null.hh @@ -43,7 +43,7 @@ hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_ /* Generic nul-content Null objects. */ template -static inline constexpr Type const & Null (void) { +static inline Type const & Null (void) { static_assert (sizeof (Type) <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE."); return *reinterpret_cast (_hb_NullPool); } From e88d47b7f2f9aee5b0b3cdc0b8f708884175a71f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 16:25:43 -0500 Subject: [PATCH 23/29] Minor --- src/hb-face.cc | 2 +- src/hb-face.hh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hb-face.cc b/src/hb-face.cc index 952e6a6a9..da73433cb 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -96,7 +96,7 @@ DEFINE_NULL_INSTANCE (hb_face_t) = #undef HB_SHAPER_IMPLEMENT }, - HB_ATOMIC_PTR_INIT (nullptr), /* shape_plans */ + /* Zero for the rest is fine. */ }; diff --git a/src/hb-face.hh b/src/hb-face.hh index 726f68837..5d22f4ada 100644 --- a/src/hb-face.hh +++ b/src/hb-face.hh @@ -54,7 +54,7 @@ struct hb_face_t struct hb_shaper_data_t shaper_data; /* Various shaper data. */ - hb_ot_face_t table; + hb_ot_face_t table; /* All the face's tables. */ /* Cache */ struct plan_node_t From 1beacdded9cd1e4467b52244cdfd8497516eb107 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 16:35:28 -0500 Subject: [PATCH 24/29] Minor --- src/hb-coretext.cc | 8 ++++---- src/hb-directwrite.cc | 4 ++-- src/hb-fallback-shape.cc | 4 ++-- src/hb-graphite2.cc | 4 ++-- src/hb-ot-shape.cc | 4 ++-- src/hb-shaper.hh | 3 ++- src/hb-uniscribe.cc | 4 ++-- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index 893a8761d..7509b8a3d 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -101,10 +101,10 @@ _hb_cg_font_release (void *data) } -HB_SHAPER_DATA_ENSURE_DEFINE(coretext, face) +HB_SHAPER_DATA_ENSURE_DEFINE(coretext, face); HB_SHAPER_DATA_ENSURE_DEFINE_WITH_CONDITION(coretext, font, fabs (CTFontGetSize((CTFontRef) data) - coretext_font_size_from_ptem (font->ptem)) <= .5 -) +); static CTFontDescriptorRef get_last_resort_font_desc (void) @@ -1152,8 +1152,8 @@ fail: * AAT shaper */ -HB_SHAPER_DATA_ENSURE_DEFINE(coretext_aat, face) -HB_SHAPER_DATA_ENSURE_DEFINE(coretext_aat, font) +HB_SHAPER_DATA_ENSURE_DEFINE(coretext_aat, face); +HB_SHAPER_DATA_ENSURE_DEFINE(coretext_aat, font); /* * shaper face data diff --git a/src/hb-directwrite.cc b/src/hb-directwrite.cc index 35197c238..cc8f6cc01 100644 --- a/src/hb-directwrite.cc +++ b/src/hb-directwrite.cc @@ -31,8 +31,8 @@ #include "hb-directwrite.h" -HB_SHAPER_DATA_ENSURE_DEFINE (directwrite, face) -HB_SHAPER_DATA_ENSURE_DEFINE (directwrite, font) +HB_SHAPER_DATA_ENSURE_DEFINE (directwrite, face); +HB_SHAPER_DATA_ENSURE_DEFINE (directwrite, font); /* diff --git a/src/hb-fallback-shape.cc b/src/hb-fallback-shape.cc index dc8536c82..ccfeba4b9 100644 --- a/src/hb-fallback-shape.cc +++ b/src/hb-fallback-shape.cc @@ -28,8 +28,8 @@ #include "hb-shaper-impl.hh" -HB_SHAPER_DATA_ENSURE_DEFINE(fallback, face) -HB_SHAPER_DATA_ENSURE_DEFINE(fallback, font) +HB_SHAPER_DATA_ENSURE_DEFINE(fallback, face); +HB_SHAPER_DATA_ENSURE_DEFINE(fallback, font); /* diff --git a/src/hb-graphite2.cc b/src/hb-graphite2.cc index 24ee3d507..38c2cd813 100644 --- a/src/hb-graphite2.cc +++ b/src/hb-graphite2.cc @@ -46,8 +46,8 @@ **/ -HB_SHAPER_DATA_ENSURE_DEFINE(graphite2, face) -HB_SHAPER_DATA_ENSURE_DEFINE(graphite2, font) +HB_SHAPER_DATA_ENSURE_DEFINE(graphite2, face); +HB_SHAPER_DATA_ENSURE_DEFINE(graphite2, font); /* diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 99d6b9d40..92a4b53ae 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -255,7 +255,7 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner, * shaper face data */ -HB_SHAPER_DATA_ENSURE_DEFINE(ot, face) +HB_SHAPER_DATA_ENSURE_DEFINE(ot, face); struct hb_ot_face_data_t {}; @@ -275,7 +275,7 @@ _hb_ot_shaper_face_data_destroy (hb_ot_face_data_t *data) * shaper font data */ -HB_SHAPER_DATA_ENSURE_DEFINE(ot, font) +HB_SHAPER_DATA_ENSURE_DEFINE(ot, font); struct hb_ot_font_data_t {}; diff --git a/src/hb-shaper.hh b/src/hb-shaper.hh index 361165e4f..e3be4119a 100644 --- a/src/hb-shaper.hh +++ b/src/hb-shaper.hh @@ -119,7 +119,8 @@ HB_SHAPER_DATA_ENSURE_FUNC(shaper, object) (hb_##object##_t *object) \ } \ } \ return data != nullptr && (void *) data != HB_SHAPER_DATA_INVALID; \ -} +} \ +static_assert (true, "") /* Require semicolon. */ /* For embedding in face / font / ... */ diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index e77825b34..76da20df7 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -314,8 +314,8 @@ struct range_record_t { unsigned int index_last; /* == end - 1 */ }; -HB_SHAPER_DATA_ENSURE_DEFINE(uniscribe, face) -HB_SHAPER_DATA_ENSURE_DEFINE(uniscribe, font) +HB_SHAPER_DATA_ENSURE_DEFINE(uniscribe, face); +HB_SHAPER_DATA_ENSURE_DEFINE(uniscribe, font); /* From 1fd183ee1c40e2eedf86b5e82d1b547c5650ebf5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 16:47:52 -0500 Subject: [PATCH 25/29] Finish off eecccc919ce15f60ae7ef9da5cfb311b4aa05c63 --- src/hb-machinery.hh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index 160e99a58..9e4c16d81 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -780,12 +780,9 @@ struct hb_lazy_loader_t : hb_data_wrapper_t do_destroy (p); } - inline Stored * do_create (void) const - { - } static inline void do_destroy (Stored *p) { - if (p && p != Funcs::get_null ()) + if (p) Funcs::destroy (p); } From fabb01210433ce1c6d5f630bc270f82a8a4a4014 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 17:10:23 -0500 Subject: [PATCH 26/29] Remove wrong comment --- src/hb-shape-plan.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index 8fcc038f9..ebf0e9f5e 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc @@ -64,7 +64,6 @@ hb_shape_plan_plan (hb_shape_plan_t *shape_plan, HB_STMT_START { \ if (hb_##shaper##_shaper_face_data_ensure (shape_plan->face_unsafe)) \ { \ - /* XXX-MT-bug What happened to *ensure*ing this?!!!! */ \ HB_SHAPER_DATA (shaper, shape_plan).set_relaxed ( \ HB_SHAPER_DATA_CREATE_FUNC (shaper, shape_plan) (shape_plan, \ user_features, num_user_features, \ From f521a28b4aad1566664cf14d70a911728ee0b962 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 21:32:01 -0500 Subject: [PATCH 27/29] Embed hb_ot_shape_plan_t into hb_shape_plan_t No other shaper will need shape_plan_data, by definition. So, remove abstraction layer and always create hb_ot_shape_plan_t as part of hb_shape_plan_t. --- src/hb-coretext.cc | 45 ------------------ src/hb-directwrite.cc | 21 --------- src/hb-fallback-shape.cc | 22 --------- src/hb-graphite2.cc | 22 --------- src/hb-ot-shape.cc | 99 +++++++++++++++++++--------------------- src/hb-ot-shape.hh | 21 ++++----- src/hb-shape-plan.cc | 22 +++++---- src/hb-shape-plan.hh | 3 +- src/hb-uniscribe.cc | 22 --------- 9 files changed, 70 insertions(+), 207 deletions(-) diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index 7509b8a3d..3cedb5b29 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -372,29 +372,6 @@ hb_coretext_font_get_ct_font (hb_font_t *font) } - -/* - * shaper shape_plan data - */ - -struct hb_coretext_shape_plan_data_t {}; - -hb_coretext_shape_plan_data_t * -_hb_coretext_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED, - const hb_feature_t *user_features HB_UNUSED, - unsigned int num_user_features HB_UNUSED, - const int *coords HB_UNUSED, - unsigned int num_coords HB_UNUSED) -{ - return (hb_coretext_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; -} - -void -_hb_coretext_shaper_shape_plan_data_destroy (hb_coretext_shape_plan_data_t *data HB_UNUSED) -{ -} - - /* * shaper */ @@ -1204,28 +1181,6 @@ _hb_coretext_aat_shaper_font_data_destroy (hb_coretext_aat_font_data_t *data HB_ } -/* - * shaper shape_plan data - */ - -struct hb_coretext_aat_shape_plan_data_t {}; - -hb_coretext_aat_shape_plan_data_t * -_hb_coretext_aat_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED, - const hb_feature_t *user_features HB_UNUSED, - unsigned int num_user_features HB_UNUSED, - const int *coords HB_UNUSED, - unsigned int num_coords HB_UNUSED) -{ - return (hb_coretext_aat_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; -} - -void -_hb_coretext_aat_shaper_shape_plan_data_destroy (hb_coretext_aat_shape_plan_data_t *data HB_UNUSED) -{ -} - - /* * shaper */ diff --git a/src/hb-directwrite.cc b/src/hb-directwrite.cc index cc8f6cc01..b34ae6016 100644 --- a/src/hb-directwrite.cc +++ b/src/hb-directwrite.cc @@ -256,27 +256,6 @@ _hb_directwrite_shaper_font_data_destroy (hb_directwrite_font_data_t *data) } -/* - * shaper shape_plan data - */ - -struct hb_directwrite_shape_plan_data_t {}; - -hb_directwrite_shape_plan_data_t * -_hb_directwrite_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED, - const hb_feature_t *user_features HB_UNUSED, - unsigned int num_user_features HB_UNUSED, - const int *coords HB_UNUSED, - unsigned int num_coords HB_UNUSED) -{ - return (hb_directwrite_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; -} - -void -_hb_directwrite_shaper_shape_plan_data_destroy (hb_directwrite_shape_plan_data_t *data HB_UNUSED) -{ -} - // Most of TextAnalysis is originally written by Bas Schouten for Mozilla project // but now is relicensed to MIT for HarfBuzz use class TextAnalysis diff --git a/src/hb-fallback-shape.cc b/src/hb-fallback-shape.cc index ccfeba4b9..40f8dad26 100644 --- a/src/hb-fallback-shape.cc +++ b/src/hb-fallback-shape.cc @@ -68,28 +68,6 @@ _hb_fallback_shaper_font_data_destroy (hb_fallback_font_data_t *data HB_UNUSED) } -/* - * shaper shape_plan data - */ - -struct hb_fallback_shape_plan_data_t {}; - -hb_fallback_shape_plan_data_t * -_hb_fallback_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED, - const hb_feature_t *user_features HB_UNUSED, - unsigned int num_user_features HB_UNUSED, - const int *coords HB_UNUSED, - unsigned int num_coords HB_UNUSED) -{ - return (hb_fallback_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; -} - -void -_hb_fallback_shaper_shape_plan_data_destroy (hb_fallback_shape_plan_data_t *data HB_UNUSED) -{ -} - - /* * shaper */ diff --git a/src/hb-graphite2.cc b/src/hb-graphite2.cc index 38c2cd813..8dce81706 100644 --- a/src/hb-graphite2.cc +++ b/src/hb-graphite2.cc @@ -220,28 +220,6 @@ hb_graphite2_font_get_gr_font (hb_font_t *font HB_UNUSED) } -/* - * shaper shape_plan data - */ - -struct hb_graphite2_shape_plan_data_t {}; - -hb_graphite2_shape_plan_data_t * -_hb_graphite2_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED, - const hb_feature_t *user_features HB_UNUSED, - unsigned int num_user_features HB_UNUSED, - const int *coords HB_UNUSED, - unsigned int num_coords HB_UNUSED) -{ - return (hb_graphite2_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; -} - -void -_hb_graphite2_shaper_shape_plan_data_destroy (hb_graphite2_shape_plan_data_t *data HB_UNUSED) -{ -} - - /* * shaper */ diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 92a4b53ae..44cf39078 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -27,7 +27,6 @@ */ #define HB_SHAPER ot -#define hb_ot_shape_plan_data_t hb_ot_shape_plan_t #include "hb-shaper-impl.hh" #include "hb-ot-shape.hh" @@ -52,6 +51,12 @@ **/ +static void +hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner, + const hb_segment_properties_t *props, + const hb_feature_t *user_features, + unsigned int num_user_features); + static bool _hb_apply_morx (hb_face_t *face) { @@ -89,7 +94,7 @@ hb_ot_shape_planner_t::compile (hb_ot_shape_plan_t &plan, plan.dnom_mask = plan.map.get_1_mask (HB_TAG ('d','n','o','m')); plan.has_frac = plan.frac_mask || (plan.numr_mask && plan.dnom_mask); plan.rtlm_mask = plan.map.get_1_mask (HB_TAG ('r','t','l','m')); - hb_tag_t kern_tag = HB_DIRECTION_IS_HORIZONTAL (plan.props.direction) ? + hb_tag_t kern_tag = HB_DIRECTION_IS_HORIZONTAL (props.direction) ? HB_TAG ('k','e','r','n') : HB_TAG ('v','k','r','n'); plan.kern_mask = plan.map.get_mask (kern_tag); plan.trak_mask = plan.map.get_mask (HB_TAG ('t','r','a','k')); @@ -142,6 +147,43 @@ hb_ot_shape_planner_t::compile (hb_ot_shape_plan_t &plan, plan.apply_trak = plan.requested_tracking && hb_aat_layout_has_tracking (face); } +bool +hb_ot_shape_plan_t::init0 (hb_shape_plan_t *shape_plan, + const hb_feature_t *user_features, + unsigned int num_user_features, + const int *coords, + unsigned int num_coords) +{ + map.init (); + aat_map.init (); + + hb_ot_shape_planner_t planner (shape_plan); + + hb_ot_shape_collect_features (&planner, &shape_plan->props, + user_features, num_user_features); + + planner.compile (*this, coords, num_coords); + + if (shaper->data_create) + { + data = shaper->data_create (this); + if (unlikely (!data)) + return false; + } + + return true; +} + +void +hb_ot_shape_plan_t::fini (void) +{ + if (shaper->data_destroy) + shaper->data_destroy (const_cast (data)); + + map.fini (); + aat_map.fini (); +} + static const hb_ot_map_feature_t common_features[] = @@ -291,54 +333,6 @@ _hb_ot_shaper_font_data_destroy (hb_ot_font_data_t *data HB_UNUSED) } -/* - * shaper shape_plan data - */ - -hb_ot_shape_plan_data_t * -_hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan, - const hb_feature_t *user_features, - unsigned int num_user_features, - const int *coords, - unsigned int num_coords) -{ - hb_ot_shape_plan_t *plan = (hb_ot_shape_plan_t *) calloc (1, sizeof (hb_ot_shape_plan_t)); - if (unlikely (!plan)) - return nullptr; - - plan->init (); - - hb_ot_shape_planner_t planner (shape_plan); - - hb_ot_shape_collect_features (&planner, &shape_plan->props, - user_features, num_user_features); - - planner.compile (*plan, coords, num_coords); - - if (plan->shaper->data_create) { - plan->data = plan->shaper->data_create (plan); - if (unlikely (!plan->data)) - { - free (plan); - return nullptr; - } - } - - return plan; -} - -void -_hb_ot_shaper_shape_plan_data_destroy (hb_ot_shape_plan_data_t *plan) -{ - if (plan->shaper->data_destroy) - plan->shaper->data_destroy (const_cast (plan->data)); - - plan->fini (); - - free (plan); -} - - /* * shaper */ @@ -978,7 +972,7 @@ _hb_ot_shape (hb_shape_plan_t *shape_plan, const hb_feature_t *features, unsigned int num_features) { - hb_ot_shape_context_t c = {HB_SHAPER_DATA_GET (shape_plan), font, font->face, buffer, features, num_features}; + hb_ot_shape_context_t c = {&shape_plan->ot, font, font->face, buffer, features, num_features}; hb_ot_shape_internal (&c); return true; @@ -995,8 +989,7 @@ hb_ot_shape_plan_collect_lookups (hb_shape_plan_t *shape_plan, hb_tag_t table_tag, hb_set_t *lookup_indexes /* OUT */) { - /* XXX Does the first part always succeed? */ - HB_SHAPER_DATA_GET (shape_plan)->collect_lookups (table_tag, lookup_indexes); + shape_plan->ot.collect_lookups (table_tag, lookup_indexes); } diff --git a/src/hb-ot-shape.hh b/src/hb-ot-shape.hh index 655e28d6d..049830a66 100644 --- a/src/hb-ot-shape.hh +++ b/src/hb-ot-shape.hh @@ -31,8 +31,6 @@ #include "hb-ot-map.hh" #include "hb-aat-map.hh" -#include "hb-shape-plan.hh" - struct hb_ot_shape_plan_t @@ -75,18 +73,17 @@ struct hb_ot_shape_plan_t inline void substitute (hb_font_t *font, hb_buffer_t *buffer) const { map.substitute (this, font, buffer); } inline void position (hb_font_t *font, hb_buffer_t *buffer) const { map.position (this, font, buffer); } - void init (void) - { - memset (this, 0, sizeof (*this)); - map.init (); - aat_map.init (); - } - void fini (void) { - map.fini (); - aat_map.fini (); - } + HB_INTERNAL bool init0 (hb_shape_plan_t *shape_plan, + const hb_feature_t *user_features, + unsigned int num_user_features, + const int *coords, + unsigned int num_coords); + + HB_INTERNAL void fini (void); }; +struct hb_shape_plan_t; + struct hb_ot_shape_planner_t { /* In the order that they are filled in. */ diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index ebf0e9f5e..5579ded7e 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc @@ -64,10 +64,6 @@ hb_shape_plan_plan (hb_shape_plan_t *shape_plan, HB_STMT_START { \ if (hb_##shaper##_shaper_face_data_ensure (shape_plan->face_unsafe)) \ { \ - HB_SHAPER_DATA (shaper, shape_plan).set_relaxed ( \ - HB_SHAPER_DATA_CREATE_FUNC (shaper, shape_plan) (shape_plan, \ - user_features, num_user_features, \ - coords, num_coords)); \ shape_plan->shaper_func = _hb_##shaper##_shape; \ shape_plan->shaper_name = #shaper; \ return; \ @@ -188,6 +184,17 @@ hb_shape_plan_create2 (hb_face_t *face, coords, num_coords, shaper_list); + if (unlikely (!shape_plan->ot.init0 (shape_plan, + user_features, + num_user_features, + coords, + num_coords))) + { + free (coords); + free (features); + return hb_shape_plan_get_empty (); + } + return shape_plan; } @@ -235,9 +242,7 @@ hb_shape_plan_destroy (hb_shape_plan_t *shape_plan) { if (!hb_object_destroy (shape_plan)) return; -#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, shape_plan); -#include "hb-shaper-list.hh" -#undef HB_SHAPER_IMPLEMENT + shape_plan->ot.fini (); free (shape_plan->user_features); free (shape_plan->coords); @@ -329,8 +334,7 @@ hb_shape_plan_execute (hb_shape_plan_t *shape_plan, #define HB_SHAPER_EXECUTE(shaper) \ HB_STMT_START { \ - return HB_SHAPER_DATA (shaper, shape_plan).get () && \ - hb_##shaper##_shaper_font_data_ensure (font) && \ + return hb_##shaper##_shaper_font_data_ensure (font) && \ _hb_##shaper##_shape (shape_plan, font, buffer, features, num_features); \ } HB_STMT_END diff --git a/src/hb-shape-plan.hh b/src/hb-shape-plan.hh index 891b99574..eaa84fd4b 100644 --- a/src/hb-shape-plan.hh +++ b/src/hb-shape-plan.hh @@ -29,6 +29,7 @@ #include "hb.hh" #include "hb-shaper.hh" +#include "hb-ot-shape.hh" struct hb_shape_plan_t @@ -48,7 +49,7 @@ struct hb_shape_plan_t int *coords; unsigned int num_coords; - struct hb_shaper_data_t shaper_data; + hb_ot_shape_plan_t ot; }; #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS \ diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index 76da20df7..dc82d6b7f 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -600,28 +600,6 @@ hb_uniscribe_font_get_hfont (hb_font_t *font) } -/* - * shaper shape_plan data - */ - -struct hb_uniscribe_shape_plan_data_t {}; - -hb_uniscribe_shape_plan_data_t * -_hb_uniscribe_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED, - const hb_feature_t *user_features HB_UNUSED, - unsigned int num_user_features HB_UNUSED, - const int *coords HB_UNUSED, - unsigned int num_coords HB_UNUSED) -{ - return (hb_uniscribe_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; -} - -void -_hb_uniscribe_shaper_shape_plan_data_destroy (hb_uniscribe_shape_plan_data_t *data HB_UNUSED) -{ -} - - /* * shaper */ From 9c767d075d0be85227b8dc146061de9bd24f3fec Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 22:03:15 -0500 Subject: [PATCH 28/29] Minor --- src/hb-shape-plan.cc | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index 5579ded7e..d42880462 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc @@ -146,27 +146,21 @@ hb_shape_plan_create2 (hb_face_t *face, hb_feature_t *features = nullptr; int *coords = nullptr; - if (unlikely (!face)) - face = hb_face_get_empty (); if (unlikely (!props)) - return hb_shape_plan_get_empty (); + goto bail; if (num_user_features && !(features = (hb_feature_t *) calloc (num_user_features, sizeof (hb_feature_t)))) - return hb_shape_plan_get_empty (); + goto bail; if (num_coords && !(coords = (int *) calloc (num_coords, sizeof (int)))) - { - free (features); - return hb_shape_plan_get_empty (); - } + goto bail; if (!(shape_plan = hb_object_create ())) - { - free (coords); - free (features); - return hb_shape_plan_get_empty (); - } + goto bail; assert (props->direction != HB_DIRECTION_INVALID); + if (unlikely (!face)) + face = hb_face_get_empty (); hb_face_make_immutable (face); + shape_plan->custom_shaper_list = shaper_list; shape_plan->face_unsafe = face; shape_plan->props = *props; @@ -189,13 +183,14 @@ hb_shape_plan_create2 (hb_face_t *face, num_user_features, coords, num_coords))) - { - free (coords); - free (features); - return hb_shape_plan_get_empty (); - } + goto bail; return shape_plan; + +bail: + free (coords); + free (features); + return hb_shape_plan_get_empty (); } /** From 77bd0a6458a9169df59f6be667a8eb79bd353dc9 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Nov 2018 22:08:48 -0500 Subject: [PATCH 29/29] Add variation coords to shape_plan proposal This is the root cause of bug worked around in 19e77e01bc13f44138e1d50533327d314dd0a018. Still no shape plan caching for variations though. --- src/hb-shape-plan.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index d42880462..2a2e0e39c 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc @@ -481,6 +481,8 @@ hb_shape_plan_create_cached2 (hb_face_t *face, shaper_list, user_features, num_user_features, + coords, + num_coords, nullptr };