From d9b204d3d24cde165167714728bf380267903d6a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 23 Aug 2012 16:22:28 -0400 Subject: [PATCH] [GSUB] Allow non-zero-context matching in would_apply() To be used in the next patch. --- src/hb-ot-layout-gsubgpos-private.hh | 6 ++++-- src/hb-ot-layout-private.hh | 3 ++- src/hb-ot-layout.cc | 14 ++++++++------ src/hb-ot-layout.h | 7 ++++--- src/hb-ot-map.cc | 12 ++---------- src/hb-ot-shape-complex-indic.cc | 2 +- src/test-would-substitute.cc | 2 +- 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index ba2a7e0..7d4849f 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -76,17 +76,20 @@ struct hb_would_apply_context_t hb_face_t *face; const hb_codepoint_t *glyphs; unsigned int len; + bool zero_context; const hb_set_digest_t digest; unsigned int debug_depth; hb_would_apply_context_t (hb_face_t *face_, const hb_codepoint_t *glyphs_, unsigned int len_, + bool zero_context_, const hb_set_digest_t *digest_ ) : face (face_), glyphs (glyphs_), len (len_), + zero_context (zero_context_), digest (*digest_), debug_depth (0) {}; }; @@ -1066,8 +1069,7 @@ static inline bool chain_context_would_apply_lookup (hb_would_apply_context_t *c const LookupRecord lookupRecord[], ChainContextApplyLookupContext &lookup_context) { - return !backtrackCount - && !lookaheadCount + return (c->zero_context ? !backtrackCount && !lookaheadCount : true) && would_match_input (c, inputCount, input, lookup_context.funcs.match, lookup_context.match_data[1]); diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh index e101782..3f2c3ef 100644 --- a/src/hb-ot-layout-private.hh +++ b/src/hb-ot-layout-private.hh @@ -139,9 +139,10 @@ static inline uint8_t allocate_lig_id (hb_buffer_t *buffer) { HB_INTERNAL hb_bool_t hb_ot_layout_would_substitute_lookup_fast (hb_face_t *face, + unsigned int lookup_index, const hb_codepoint_t *glyphs, unsigned int glyphs_length, - unsigned int lookup_index); + hb_bool_t zero_context); /* Should be called before all the substitute_lookup's are done. */ diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index e4d84e8..44420ff 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -401,22 +401,24 @@ hb_ot_layout_has_substitution (hb_face_t *face) hb_bool_t hb_ot_layout_would_substitute_lookup (hb_face_t *face, + unsigned int lookup_index, const hb_codepoint_t *glyphs, unsigned int glyphs_length, - unsigned int lookup_index) + hb_bool_t zero_context) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return false; - return hb_ot_layout_would_substitute_lookup_fast (face, glyphs, glyphs_length, lookup_index); + return hb_ot_layout_would_substitute_lookup_fast (face, lookup_index, glyphs, glyphs_length, zero_context); } hb_bool_t hb_ot_layout_would_substitute_lookup_fast (hb_face_t *face, + unsigned int lookup_index, const hb_codepoint_t *glyphs, unsigned int glyphs_length, - unsigned int lookup_index) + hb_bool_t zero_context) { if (unlikely (lookup_index >= hb_ot_layout_from_face (face)->gsub_lookup_count)) return false; - hb_would_apply_context_t c (face, glyphs, glyphs_length, &hb_ot_layout_from_face (face)->gsub_digests[lookup_index]); + hb_would_apply_context_t c (face, glyphs, glyphs_length, zero_context, &hb_ot_layout_from_face (face)->gsub_digests[lookup_index]); return hb_ot_layout_from_face (face)->gsub->would_substitute_lookup (&c, lookup_index); } @@ -445,8 +447,8 @@ hb_ot_layout_substitute_finish (hb_font_t *font, hb_buffer_t *buffer) void hb_ot_layout_substitute_closure_lookup (hb_face_t *face, - hb_set_t *glyphs, - unsigned int lookup_index) + unsigned int lookup_index, + hb_set_t *glyphs) { hb_closure_context_t c (face, glyphs); _get_gsub (face).closure_lookup (&c, lookup_index); diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index 2ad4ff4..d431a38 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -171,14 +171,15 @@ hb_ot_layout_has_substitution (hb_face_t *face); hb_bool_t hb_ot_layout_would_substitute_lookup (hb_face_t *face, + unsigned int lookup_index, const hb_codepoint_t *glyphs, unsigned int glyphs_length, - unsigned int lookup_index); + hb_bool_t zero_context); void hb_ot_layout_substitute_closure_lookup (hb_face_t *face, - hb_set_t *glyphs, - unsigned int lookup_index); + unsigned int lookup_index, + hb_set_t *glyphs); /* * GPOS diff --git a/src/hb-ot-map.cc b/src/hb-ot-map.cc index 7eed624..b8b2dbe 100644 --- a/src/hb-ot-map.cc +++ b/src/hb-ot-map.cc @@ -116,16 +116,8 @@ void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_ void hb_ot_map_t::substitute_closure (const hb_ot_shape_plan_t *plan, hb_face_t *face, hb_set_t *glyphs) const { unsigned int table_index = 0; - unsigned int i = 0; - - for (unsigned int pause_index = 0; pause_index < pauses[table_index].len; pause_index++) { - const pause_map_t *pause = &pauses[table_index][pause_index]; - for (; i < pause->num_lookups; i++) - hb_ot_layout_substitute_closure_lookup (face, glyphs, lookups[table_index][i].index); - } - - for (; i < lookups[table_index].len; i++) - hb_ot_layout_substitute_closure_lookup (face, glyphs, lookups[table_index][i].index); + for (unsigned int i = 0; i < lookups[table_index].len; i++) + hb_ot_layout_substitute_closure_lookup (face, lookups[table_index][i].index, glyphs); } void hb_ot_map_builder_t::add_pause (unsigned int table_index, hb_ot_map_t::pause_func_t pause_func) diff --git a/src/hb-ot-shape-complex-indic.cc b/src/hb-ot-shape-complex-indic.cc index e2a6f58..0df179c 100644 --- a/src/hb-ot-shape-complex-indic.cc +++ b/src/hb-ot-shape-complex-indic.cc @@ -257,7 +257,7 @@ struct would_substitute_feature_t hb_face_t *face) const { for (unsigned int i = 0; i < count; i++) - if (hb_ot_layout_would_substitute_lookup_fast (face, glyphs, glyphs_count, lookups[i].index)) + if (hb_ot_layout_would_substitute_lookup_fast (face, lookups[i].index, glyphs, glyphs_count, true)) return true; return false; } diff --git a/src/test-would-substitute.cc b/src/test-would-substitute.cc index 95626ed..d15aec4 100644 --- a/src/test-would-substitute.cc +++ b/src/test-would-substitute.cc @@ -99,5 +99,5 @@ main (int argc, char **argv) (argc > 4 && !hb_font_glyph_from_string (font, argv[4], -1, &glyphs[1]))) return 2; - return !hb_ot_layout_would_substitute_lookup (face, glyphs, len, strtol (argv[2], NULL, 0)); + return !hb_ot_layout_would_substitute_lookup (face, strtol (argv[2], NULL, 0), glyphs, len, false); } -- 2.7.4