diff --git a/src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh b/src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh index ceff125e4..ba994cdcc 100644 --- a/src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh +++ b/src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh @@ -69,7 +69,7 @@ struct ReverseChainSingleSubstFormat1 #ifndef HB_NO_SUBSET_DEPEND bool depend (hb_depend_context_t *c) const { - // Filter by intersects and parent_active_glyphs like closure does (lines 83-95) + // Filter by intersects and parent_active_glyphs like closure does if (!intersects (c->glyphs)) return true; const auto &lookahead = StructAfter (backtrack); @@ -91,7 +91,7 @@ struct ReverseChainSingleSubstFormat1 else if (back_glyphs.get_population () > 1) { hb_codepoint_t set_idx = c->depend_data->find_or_create_context_set (back_glyphs); - context_glyphs.add (0x80000000 | set_idx); + context_glyphs.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx); } } @@ -106,7 +106,7 @@ struct ReverseChainSingleSubstFormat1 else if (look_glyphs.get_population () > 1) { hb_codepoint_t set_idx = c->depend_data->find_or_create_context_set (look_glyphs); - context_glyphs.add (0x80000000 | set_idx); + context_glyphs.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx); } } diff --git a/src/hb-depend-data.hh b/src/hb-depend-data.hh index a53adfdb3..8a4fd2e21 100644 --- a/src/hb-depend-data.hh +++ b/src/hb-depend-data.hh @@ -61,8 +61,16 @@ * context). The outer context's requirements are not preserved on this edge, * so it may over-approximate. */ -#define HB_DEPEND_EDGE_FLAG_FROM_CONTEXT_POSITION 0x01 -#define HB_DEPEND_EDGE_FLAG_FROM_NESTED_CONTEXT 0x02 +enum hb_depend_edge_flags_t { + HB_DEPEND_EDGE_FLAG_NONE = 0x00u, + HB_DEPEND_EDGE_FLAG_FROM_CONTEXT_POSITION = 0x01u, + HB_DEPEND_EDGE_FLAG_FROM_NESTED_CONTEXT = 0x02u, +}; +HB_MARK_AS_FLAG_T (hb_depend_edge_flags_t); + +/* High bit of a context-set element marks it as an index into the sets array + * rather than a raw glyph ID. */ +#define HB_DEPEND_CONTEXT_SET_FLAG 0x80000000u /** * hb_depend_edge_t: @@ -85,7 +93,7 @@ struct hb_depend_edge_t { hb_tag_t layout_tag, hb_codepoint_t ligature_set, hb_codepoint_t context_set, - uint8_t flags = 0) : table_tag(table_tag), + hb_depend_edge_flags_t flags = HB_DEPEND_EDGE_FLAG_NONE) : table_tag(table_tag), dependent(dependent), layout_tag(layout_tag), ligature_set(ligature_set), context_set(context_set), flags(flags) @@ -127,7 +135,7 @@ struct hb_depend_edge_t { hb_tag_t layout_tag; hb_codepoint_t ligature_set; hb_codepoint_t context_set; - uint8_t flags; + hb_depend_edge_flags_t flags; }; /** @@ -140,7 +148,7 @@ struct hb_depend_edge_key_t { hb_codepoint_t source; hb_depend_edge_t record; - hb_depend_edge_key_t () : source (0), record (0, 0, 0, HB_CODEPOINT_INVALID, HB_CODEPOINT_INVALID, 0) {} + hb_depend_edge_key_t () : source (0), record (0, 0, 0, HB_CODEPOINT_INVALID, HB_CODEPOINT_INVALID, HB_DEPEND_EDGE_FLAG_NONE) {} hb_depend_edge_key_t (hb_codepoint_t source, hb_tag_t table_tag, @@ -149,7 +157,7 @@ struct hb_depend_edge_key_t { hb_codepoint_t ligature_set, hb_codepoint_t context_set) : source (source), - record (table_tag, dependent, layout_tag, ligature_set, context_set, 0) {} + record (table_tag, dependent, layout_tag, ligature_set, context_set, HB_DEPEND_EDGE_FLAG_NONE) {} bool operator == (const hb_depend_edge_key_t &o) const { @@ -287,7 +295,7 @@ struct hb_depend_data_builder_t { hb_depend_data_builder_t (hb_depend_data_t &data_) : current_context_set_index (HB_CODEPOINT_INVALID), - current_edge_flags (0), + current_edge_flags (HB_DEPEND_EDGE_FLAG_NONE), data (data_) {} /* Forward to data for use during construction (e.g. from hb_depend_context_t) */ @@ -408,7 +416,7 @@ struct hb_depend_data_builder_t if (!filtered_set.is_empty ()) { hb_codepoint_t set_idx = find_or_create_context_set (filtered_set); - context_elements.add (0x80000000 | set_idx); + context_elements.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx); } } } @@ -427,7 +435,7 @@ struct hb_depend_data_builder_t if (!filtered_set.is_empty ()) { hb_codepoint_t set_idx = find_or_create_context_set (filtered_set); - context_elements.add (0x80000000 | set_idx); + context_elements.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx); } } } @@ -446,7 +454,7 @@ struct hb_depend_data_builder_t hb_codepoint_t dependent, hb_codepoint_t lig_set = HB_CODEPOINT_INVALID, hb_codepoint_t context_set = HB_CODEPOINT_INVALID, - uint8_t flags = 0) + hb_depend_edge_flags_t flags = HB_DEPEND_EDGE_FLAG_NONE) { if (target >= data.glyph_dependencies.length) { DEBUG_MSG (SUBSET, nullptr, "Dependency glyph %u for %c%c%c%c too large", @@ -473,7 +481,7 @@ struct hb_depend_data_builder_t { if (context_set == HB_CODEPOINT_INVALID) context_set = current_context_set_index; - uint8_t flags = current_edge_flags; + hb_depend_edge_flags_t flags = current_edge_flags; bool any_added = false; for (auto t : lookup_features[lookup_index]) { @@ -487,7 +495,7 @@ struct hb_depend_data_builder_t hb_codepoint_t dependent, hb_codepoint_t lig_set = HB_CODEPOINT_INVALID, hb_codepoint_t context_set = HB_CODEPOINT_INVALID, - uint8_t flags = 0) + hb_depend_edge_flags_t flags = HB_DEPEND_EDGE_FLAG_NONE) { add_depend_layout (target, table_tag, HB_CODEPOINT_INVALID, dependent, lig_set, context_set, flags); @@ -514,7 +522,7 @@ struct hb_depend_data_builder_t hb_hashmap_t set_to_index; hb_vector_t free_set_list; hb_codepoint_t current_context_set_index; - uint8_t current_edge_flags; + hb_depend_edge_flags_t current_edge_flags; hb_depend_data_t &data; }; diff --git a/src/hb-depend.cc b/src/hb-depend.cc index df5893328..ec811695a 100644 --- a/src/hb-depend.cc +++ b/src/hb-depend.cc @@ -64,10 +64,6 @@ hb_depend_t::hb_depend_t (hb_face_t *f) { - if (unlikely (f == nullptr)) { - successful = false; - return; - } face = hb_face_reference(f); if (unlikely (!data.glyph_dependencies.resize_exact (face->get_num_glyphs ()))) { successful = false; diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index ba882ab5c..237aed31f 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -1932,7 +1932,7 @@ static void context_depend_recurse_lookups (hb_depend_context_t *c, /* Process preliminary_context in one pass */ hb_codepoint_t elem = HB_SET_VALUE_INVALID; while (preliminary_context.next (&elem)) { - if (elem < 0x80000000) { + if (!(elem & HB_DEPEND_CONTEXT_SET_FLAG)) { /* Direct glyph */ position_context.add (elem); } else { @@ -1982,7 +1982,7 @@ static void context_depend_recurse_lookups (hb_depend_context_t *c, if (filtered == (*input_position_glyphs)[j]) { /* No overlap with position_context - add full requirement */ hb_codepoint_t idx = c->depend_data->find_or_create_context_set ((*input_position_glyphs)[j]); - filtered_disjunctive_indices.add (0x80000000 | idx); + filtered_disjunctive_indices.add (HB_DEPEND_CONTEXT_SET_FLAG | idx); } /* Otherwise: position_context intersects, requirement satisfied */ } @@ -2000,7 +2000,7 @@ static void context_depend_recurse_lookups (hb_depend_context_t *c, * calls another contextual lookup, we want each lookup in this rule to see * the same outer context, not context from a sibling lookup. */ hb_codepoint_t saved_context_set_index = c->depend_data->current_context_set_index; - uint8_t saved_edge_flags = c->depend_data->current_edge_flags; + hb_depend_edge_flags_t saved_edge_flags = c->depend_data->current_edge_flags; /* Detect nested contextual: if we already have a context set, we're inside * an outer contextual rule that called this one. The outer context will be @@ -2018,7 +2018,7 @@ static void context_depend_recurse_lookups (hb_depend_context_t *c, * lookups at the same position may interact (one produces a glyph, another * immediately consumes it as an "intermediate"). So a glyph matching the * coverage might not persist at that position when closure traverses. */ - c->depend_data->current_edge_flags = 0; + c->depend_data->current_edge_flags = HB_DEPEND_EDGE_FLAG_NONE; if (inputCount > 1) { c->depend_data->current_edge_flags |= HB_DEPEND_EDGE_FLAG_FROM_CONTEXT_POSITION; } @@ -3720,7 +3720,7 @@ static inline void chain_context_depend_lookup (hb_depend_context_t *c, preliminary_context.add (back_set.get_min ()); // Direct glyph } else if (back_set.get_population () > 1) { hb_codepoint_t set_idx = c->depend_data->find_or_create_context_set (back_set); - preliminary_context.add (0x80000000 | set_idx); // Encoded set reference + preliminary_context.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx); // Encoded set reference } } for (const auto &look_set : ctx_info.lookahead_sets) @@ -3729,7 +3729,7 @@ static inline void chain_context_depend_lookup (hb_depend_context_t *c, preliminary_context.add (look_set.get_min ()); // Direct glyph } else if (look_set.get_population () > 1) { hb_codepoint_t set_idx = c->depend_data->find_or_create_context_set (look_set); - preliminary_context.add (0x80000000 | set_idx); // Encoded set reference + preliminary_context.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx); // Encoded set reference } }