inline void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; }
inline void set_lookup (const Lookup &l) { lookup_props = l.get_props (); }
+ struct matcher_t
+ {
+ inline matcher_t (void) :
+ lookup_props (0),
+ ignore_zwnj (true),
+ mask (-1),
+#define arg1(arg) (arg) /* Remove the macro to see why it's needed! */
+ syllable arg1(0),
+#undef arg1
+ match_func (NULL),
+ match_data (NULL) {};
+
+ typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, const void *data);
+
+ inline void set_ignore_zwnj (bool ignore_zwnj_) { ignore_zwnj = ignore_zwnj_; }
+ inline void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; }
+ inline void set_mask (hb_mask_t mask_) { mask = mask_; }
+ inline void set_syllable (uint8_t syllable_) { syllable = syllable_; }
+ inline void set_match_func (match_func_t match_func_,
+ const void *match_data_)
+ { match_func = match_func_; match_data = match_data_; }
+
+ inline bool matches (const hb_glyph_info_t &info,
+ const USHORT *glyph_data) const
+ {
+ return (info.mask & mask) &&
+ (!syllable || syllable == info.syllable ()) &&
+ (!match_func || match_func (info.codepoint, *glyph_data, match_data));
+ }
+
+ enum may_skip_t {
+ SKIP_NO,
+ SKIP_YES,
+ SKIP_MAYBE
+ };
+
+ inline may_skip_t
+ may_skip (const hb_apply_context_t *c,
+ const hb_glyph_info_t &info) const
+ {
+ unsigned int property;
+
+ property = info.glyph_props();
+
+ if (!c->match_properties (info.codepoint, property, lookup_props))
+ return SKIP_YES;
+
+ if (unlikely ((_hb_glyph_info_is_default_ignorable (&info) &&
+ (ignore_zwnj || !_hb_glyph_info_is_zwnj (&info))) &&
+ !is_a_ligature (info)))
+ return SKIP_MAYBE;
+
+ return SKIP_NO;
+ }
+
+ protected:
+ unsigned int lookup_props;
+ bool ignore_zwnj;
+ hb_mask_t mask;
+ uint8_t syllable;
+ match_func_t match_func;
+ const void *match_data;
+ };
+
struct skipping_forward_iterator_t
{
inline skipping_forward_iterator_t (hb_apply_context_t *c_,
unsigned int start_index_,
unsigned int num_items_,
- bool context_match = false)
+ bool context_match = false) :
+ idx (start_index_),
+ c (c_),
+ match_glyph_data (NULL),
+ num_items (num_items_),
+ end (c->buffer->len)
{
- c = c_;
- lookup_props = c->lookup_props;
- idx = start_index_;
- num_items = num_items_;
- mask = context_match ? -1 : c->lookup_mask;
- syllable = context_match ? 0 : c->buffer->cur().syllable ();
- end = c->buffer->len;
- }
- inline void set_lookup_props (unsigned int lookup_props_)
- {
- lookup_props = lookup_props_;
- }
- inline bool has_no_chance (void) const
- {
- return unlikely (num_items && idx + num_items >= end);
+ matcher.set_lookup_props (c->lookup_props);
+ /* Ignore ZWNJ if we are matching GSUB context, or matching GPOS. */
+ matcher.set_ignore_zwnj (context_match || c->table_index == 1);
+ if (!context_match)
+ {
+ matcher.set_mask (c->lookup_mask);
+ matcher.set_syllable (start_index_ == c->buffer->idx ? c->buffer->cur().syllable () : 0);
+ }
}
- inline void reject (void)
+ inline void set_lookup_props (unsigned int lookup_props) { matcher.set_lookup_props (lookup_props); }
+ inline void set_syllable (unsigned int syllable) { matcher.set_syllable (syllable); }
+ inline void set_match_func (matcher_t::match_func_t match_func,
+ const void *match_data,
+ const USHORT glyph_data[])
{
- num_items++;
+ matcher.set_match_func (match_func, match_data);
+ match_glyph_data = glyph_data;
}
+
+ inline bool has_no_chance (void) const { return unlikely (num_items && idx + num_items >= end); }
+ inline void reject (void) { num_items++; match_glyph_data--; }
inline bool next (void)
{
assert (num_items > 0);
- do
+ matcher_t::may_skip_t skip;
+ while (!has_no_chance ())
{
- if (has_no_chance ())
- return false;
idx++;
- } while (c->should_skip (&c->buffer->info[idx], lookup_props));
- num_items--;
- return (c->buffer->info[idx].mask & mask) && (!syllable || syllable == c->buffer->info[idx].syllable ());
+ const hb_glyph_info_t &info = c->buffer->info[idx];
+
+ skip = matcher.may_skip (c, info);
+
+ if (unlikely (skip == matcher_t::SKIP_YES))
+ continue;
+
+ if (matcher.matches (info, match_glyph_data))
+ {
+ num_items--;
+ match_glyph_data++;
+ return true;
+ }
+
+ if (skip == matcher_t::SKIP_NO)
+ return false;
+ }
+ return false;
}
unsigned int idx;
protected:
hb_apply_context_t *c;
- unsigned int lookup_props;
+ matcher_t matcher;
+ const USHORT *match_glyph_data;
+
unsigned int num_items;
- hb_mask_t mask;
- uint8_t syllable;
unsigned int end;
};
inline skipping_backward_iterator_t (hb_apply_context_t *c_,
unsigned int start_index_,
unsigned int num_items_,
- bool context_match = false)
+ bool context_match = false) :
+ idx (start_index_),
+ c (c_),
+ match_glyph_data (NULL),
+ num_items (num_items_)
{
- c = c_;
- lookup_props = c->lookup_props;
- idx = start_index_;
- num_items = num_items_;
- mask = context_match ? -1 : c->lookup_mask;
- syllable = context_match ? 0 : c->buffer->cur().syllable ();
- }
- inline void set_lookup_props (unsigned int lookup_props_)
- {
- lookup_props = lookup_props_;
- }
- inline bool has_no_chance (void) const
- {
- return unlikely (idx < num_items);
+ matcher.set_lookup_props (c->lookup_props);
+ /* Ignore ZWNJ if we are matching GSUB context, or matching GPOS. */
+ matcher.set_ignore_zwnj (context_match || c->table_index == 1);
+ if (!context_match)
+ {
+ matcher.set_mask (c->lookup_mask);
+ matcher.set_syllable (start_index_ == c->buffer->idx ? c->buffer->cur().syllable () : 0);
+ }
}
- inline void reject (void)
+ inline void set_lookup_props (unsigned int lookup_props) { matcher.set_lookup_props (lookup_props); }
+ inline void set_syllable (unsigned int syllable) { matcher.set_syllable (syllable); }
+ inline void set_match_func (matcher_t::match_func_t match_func,
+ const void *match_data,
+ const USHORT glyph_data[])
{
- num_items++;
+ matcher.set_match_func (match_func, match_data);
+ match_glyph_data = glyph_data;
}
+
+ inline bool has_no_chance (void) const { return unlikely (idx < num_items); }
+ inline void reject (void) { num_items++; }
inline bool prev (void)
{
assert (num_items > 0);
- do
+ matcher_t::may_skip_t skip;
+ while (!has_no_chance ())
{
- if (has_no_chance ())
- return false;
idx--;
- } while (c->should_skip (&c->buffer->out_info[idx], lookup_props));
- num_items--;
- return (c->buffer->out_info[idx].mask & mask) && (!syllable || syllable == c->buffer->out_info[idx].syllable ());
+ const hb_glyph_info_t &info = c->buffer->out_info[idx];
+
+ skip = matcher.may_skip (c, info);
+
+ if (unlikely (skip == matcher_t::SKIP_YES))
+ continue;
+
+ if (matcher.matches (info, match_glyph_data))
+ {
+ num_items--;
+ match_glyph_data++;
+ return true;
+ }
+
+ if (skip == matcher_t::SKIP_NO)
+ return false;
+ }
+ return false;
}
unsigned int idx;
protected:
hb_apply_context_t *c;
- unsigned int lookup_props;
+ matcher_t matcher;
+ const USHORT *match_glyph_data;
+
unsigned int num_items;
- hb_mask_t mask;
- uint8_t syllable;
};
inline bool
return match_properties (info->codepoint, property, lookup_props);
}
- inline bool
- should_skip (hb_glyph_info_t *info,
- unsigned int lookup_props) const
- {
- unsigned int property;
-
- property = info->glyph_props();
-
- return !match_properties (info->codepoint, property, lookup_props);
- }
-
-
inline void set_class (hb_codepoint_t glyph_index, unsigned int class_guess) const
{
if (likely (has_glyph_classes))
TRACE_APPLY (NULL);
hb_apply_context_t::skipping_forward_iterator_t skippy_iter (c, c->buffer->idx, count - 1);
+ skippy_iter.set_match_func (match_func, match_data, input);
if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false);
/*
{
if (!skippy_iter.next ()) return TRACE_RETURN (false);
- if (likely (!match_func (c->buffer->info[skippy_iter.idx].codepoint, input[i - 1], match_data))) return TRACE_RETURN (false);
-
unsigned int this_lig_id = get_lig_id (c->buffer->info[skippy_iter.idx]);
unsigned int this_lig_comp = get_lig_comp (c->buffer->info[skippy_iter.idx]);
}
static inline void ligate_input (hb_apply_context_t *c,
unsigned int count, /* Including the first glyph (not matched) */
- const USHORT input[] HB_UNUSED, /* Array of input values--start with second glyph */
+ const USHORT input[], /* Array of input values--start with second glyph */
+ match_func_t match_func,
+ const void *match_data,
hb_codepoint_t lig_glyph,
- match_func_t match_func HB_UNUSED,
- const void *match_data HB_UNUSED,
bool is_mark_ligature,
unsigned int total_component_count)
{
+ hb_apply_context_t::skipping_forward_iterator_t skippy_iter (c, c->buffer->idx, count - 1);
+ skippy_iter.set_match_func (match_func, match_data, input);
+ if (skippy_iter.has_no_chance ()) return;
+
/*
* - If it *is* a mark ligature, we don't allocate a new ligature id, and leave
* the ligature to keep its old ligature id. This will allow it to attach to
unsigned int last_num_components = get_lig_num_comps (c->buffer->cur());
unsigned int components_so_far = last_num_components;
- hb_apply_context_t::skipping_forward_iterator_t skippy_iter (c, c->buffer->idx, count - 1);
-
if (!is_mark_ligature)
set_lig_props_for_ligature (c->buffer->cur(), lig_id, total_component_count);
c->replace_glyph (lig_glyph, klass);
for (unsigned int i = 1; i < count; i++)
{
if (!skippy_iter.next ()) return;
+
while (c->buffer->idx < skippy_iter.idx)
{
if (!is_mark_ligature) {
TRACE_APPLY (NULL);
hb_apply_context_t::skipping_backward_iterator_t skippy_iter (c, c->buffer->backtrack_len (), count, true);
- if (skippy_iter.has_no_chance ())
- return TRACE_RETURN (false);
+ skippy_iter.set_match_func (match_func, match_data, backtrack);
+ if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false);
for (unsigned int i = 0; i < count; i++)
- {
if (!skippy_iter.prev ())
return TRACE_RETURN (false);
- if (likely (!match_func (c->buffer->out_info[skippy_iter.idx].codepoint, backtrack[i], match_data)))
- return TRACE_RETURN (false);
- }
-
return TRACE_RETURN (true);
}
TRACE_APPLY (NULL);
hb_apply_context_t::skipping_forward_iterator_t skippy_iter (c, c->buffer->idx + offset - 1, count, true);
- if (skippy_iter.has_no_chance ())
- return TRACE_RETURN (false);
+ skippy_iter.set_match_func (match_func, match_data, lookahead);
+ if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false);
for (unsigned int i = 0; i < count; i++)
- {
if (!skippy_iter.next ())
return TRACE_RETURN (false);
- if (likely (!match_func (c->buffer->info[skippy_iter.idx].codepoint, lookahead[i], match_data)))
- return TRACE_RETURN (false);
- }
-
return TRACE_RETURN (true);
}
static inline bool apply_lookup (hb_apply_context_t *c,
unsigned int count, /* Including the first glyph */
+ const USHORT input[], /* Array of input values--start with second glyph */
+ match_func_t match_func,
+ const void *match_data,
unsigned int lookupCount,
const LookupRecord lookupRecord[] /* Array of LookupRecords--in design order */)
{
* and we jump out of it. Not entirely disastrous. So we don't check
* for reverse lookup here.
*/
+
+ hb_apply_context_t::skipping_forward_iterator_t skippy_iter (c, c->buffer->idx, count - 1);
+ skippy_iter.set_match_func (match_func, match_data, input);
+ uint8_t syllable = c->buffer->cur().syllable();
+
unsigned int i = 0;
if (lookupCount && 0 == lookupRecord->sequenceIndex)
{
if (!done)
goto not_applied;
+ else
+ {
+ /* Reinitialize iterator. */
+ hb_apply_context_t::skipping_forward_iterator_t tmp (c, c->buffer->idx - 1, count - i);
+ tmp.set_syllable (syllable);
+ skippy_iter = tmp;
+ }
}
else
{
c->buffer->next_glyph ();
i++;
}
- hb_apply_context_t::skipping_forward_iterator_t skippy_iter (c, c->buffer->idx - 1, count - i);
while (i < count)
{
if (!skippy_iter.next ()) return TRACE_RETURN (true);
{
/* Reinitialize iterator. */
hb_apply_context_t::skipping_forward_iterator_t tmp (c, c->buffer->idx - 1, count - i);
+ tmp.set_syllable (syllable);
skippy_iter = tmp;
}
}
inputCount, input,
lookup_context.funcs.match, lookup_context.match_data)
&& apply_lookup (c,
- inputCount,
+ inputCount, input,
+ lookup_context.funcs.match, lookup_context.match_data,
lookupCount, lookupRecord);
}
lookup_context.funcs.match, lookup_context.match_data[2],
lookahead_offset)
&& apply_lookup (c,
- inputCount,
+ inputCount, input,
+ lookup_context.funcs.match, lookup_context.match_data[1],
lookupCount, lookupRecord);
}