[GSUB] Allow non-zero-context matching in would_apply()

To be used in the next patch.
This commit is contained in:
Behdad Esfahbod 2012-08-23 16:22:28 -04:00
parent 1f2bb172fe
commit d9b204d3d2
7 changed files with 22 additions and 24 deletions

View File

@ -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]);

View File

@ -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. */

View File

@ -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);

View File

@ -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

View File

@ -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)

View File

@ -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;
}

View File

@ -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);
}