namespace OT {
-
-#define TRACE_PROCESS(this) \
- hb_auto_trace_t<context_t::max_debug_depth, typename context_t::return_t> trace \
- (&c->debug_depth, c->get_name (), this, HB_FUNC, \
- "");
-
-
#ifndef HB_DEBUG_CLOSURE
#define HB_DEBUG_CLOSURE (HB_DEBUG+0)
#endif
(&c->debug_depth, c->get_name (), this, HB_FUNC, \
"");
-struct hb_closure_context_t
+struct hb_closure_context_t :
+ hb_dispatch_context_t<hb_closure_context_t, hb_void_t, HB_DEBUG_CLOSURE>
{
inline const char *get_name (void) { return "CLOSURE"; }
- static const unsigned int max_debug_depth = HB_DEBUG_CLOSURE;
- typedef hb_void_t return_t;
typedef return_t (*recurse_func_t) (hb_closure_context_t *c, unsigned int lookup_index);
template <typename T>
- inline return_t process (const T &obj) { obj.closure (this); return HB_VOID; }
+ inline return_t dispatch (const T &obj) { obj.closure (this); return HB_VOID; }
static return_t default_return_value (void) { return HB_VOID; }
bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; }
return_t recurse (unsigned int lookup_index)
hb_closure_context_t (hb_face_t *face_,
hb_set_t *glyphs_,
- unsigned int nesting_level_left_ = MAX_NESTING_LEVEL) :
+ unsigned int nesting_level_left_ = HB_MAX_NESTING_LEVEL) :
face (face_),
glyphs (glyphs_),
recurse_func (NULL),
(&c->debug_depth, c->get_name (), this, HB_FUNC, \
"%d glyphs", c->len);
-struct hb_would_apply_context_t
+struct hb_would_apply_context_t :
+ hb_dispatch_context_t<hb_would_apply_context_t, bool, HB_DEBUG_WOULD_APPLY>
{
inline const char *get_name (void) { return "WOULD_APPLY"; }
- static const unsigned int max_debug_depth = HB_DEBUG_WOULD_APPLY;
- typedef bool return_t;
template <typename T>
- inline return_t process (const T &obj) { return obj.would_apply (this); }
+ inline return_t dispatch (const T &obj) { return obj.would_apply (this); }
static return_t default_return_value (void) { return false; }
bool stop_sublookup_iteration (return_t r) const { return r; }
(&c->debug_depth, c->get_name (), this, HB_FUNC, \
"");
-struct hb_collect_glyphs_context_t
+struct hb_collect_glyphs_context_t :
+ hb_dispatch_context_t<hb_collect_glyphs_context_t, hb_void_t, HB_DEBUG_COLLECT_GLYPHS>
{
inline const char *get_name (void) { return "COLLECT_GLYPHS"; }
- static const unsigned int max_debug_depth = HB_DEBUG_COLLECT_GLYPHS;
- typedef hb_void_t return_t;
typedef return_t (*recurse_func_t) (hb_collect_glyphs_context_t *c, unsigned int lookup_index);
template <typename T>
- inline return_t process (const T &obj) { obj.collect_glyphs (this); return HB_VOID; }
+ inline return_t dispatch (const T &obj) { obj.collect_glyphs (this); return HB_VOID; }
static return_t default_return_value (void) { return HB_VOID; }
bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; }
return_t recurse (unsigned int lookup_index)
/* Note that GPOS sets recurse_func to NULL already, so it doesn't get
* past the previous check. For GSUB, we only want to collect the output
- * glyphs in the recursion. If output is not requested, we can go home now. */
+ * glyphs in the recursion. If output is not requested, we can go home now.
+ *
+ * Note further, that the above is not exactly correct. A recursed lookup
+ * is allowed to match input that is not matched in the context, but that's
+ * not how most fonts are built. It's possible to relax that and recurse
+ * with all sets here if it proves to be an issue.
+ */
if (output == hb_set_get_empty ())
return HB_VOID;
+ /* Return if new lookup was recursed to before. */
+ if (recursed_lookups.has (lookup_index))
+ return HB_VOID;
+
hb_set_t *old_before = before;
hb_set_t *old_input = input;
hb_set_t *old_after = after;
input = old_input;
after = old_after;
+ recursed_lookups.add (lookup_index);
+
return HB_VOID;
}
hb_set_t *after;
hb_set_t *output;
recurse_func_t recurse_func;
+ hb_set_t recursed_lookups;
unsigned int nesting_level_left;
unsigned int debug_depth;
hb_set_t *glyphs_input, /* OUT. May be NULL */
hb_set_t *glyphs_after, /* OUT. May be NULL */
hb_set_t *glyphs_output, /* OUT. May be NULL */
- unsigned int nesting_level_left_ = MAX_NESTING_LEVEL) :
+ unsigned int nesting_level_left_ = HB_MAX_NESTING_LEVEL) :
face (face_),
before (glyphs_before ? glyphs_before : hb_set_get_empty ()),
input (glyphs_input ? glyphs_input : hb_set_get_empty ()),
after (glyphs_after ? glyphs_after : hb_set_get_empty ()),
output (glyphs_output ? glyphs_output : hb_set_get_empty ()),
recurse_func (NULL),
+ recursed_lookups (),
nesting_level_left (nesting_level_left_),
- debug_depth (0) {}
+ debug_depth (0)
+ {
+ recursed_lookups.init ();
+ }
+ ~hb_collect_glyphs_context_t (void)
+ {
+ recursed_lookups.fini ();
+ }
void set_recurse_func (recurse_func_t func) { recurse_func = func; }
};
-struct hb_get_coverage_context_t
+#ifndef HB_DEBUG_GET_COVERAGE
+#define HB_DEBUG_GET_COVERAGE (HB_DEBUG+0)
+#endif
+
+/* XXX Can we remove this? */
+
+template <typename set_t>
+struct hb_add_coverage_context_t :
+ hb_dispatch_context_t<hb_add_coverage_context_t<set_t>, const Coverage &, HB_DEBUG_GET_COVERAGE>
{
inline const char *get_name (void) { return "GET_COVERAGE"; }
- static const unsigned int max_debug_depth = 0;
typedef const Coverage &return_t;
template <typename T>
- inline return_t process (const T &obj) { return obj.get_coverage (); }
+ inline return_t dispatch (const T &obj) { return obj.get_coverage (); }
static return_t default_return_value (void) { return Null(Coverage); }
+ bool stop_sublookup_iteration (return_t r) const
+ {
+ r.add_coverage (set);
+ return false;
+ }
- hb_get_coverage_context_t (void) :
+ hb_add_coverage_context_t (set_t *set_) :
+ set (set_),
debug_depth (0) {}
+ set_t *set;
unsigned int debug_depth;
};
#define TRACE_APPLY(this) \
hb_auto_trace_t<HB_DEBUG_APPLY, bool> trace \
(&c->debug_depth, c->get_name (), this, HB_FUNC, \
- "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint);
+ "idx %d gid %u lookup %d", \
+ c->buffer->idx, c->buffer->cur().codepoint, (int) c->lookup_index);
-struct hb_apply_context_t
+struct hb_apply_context_t :
+ hb_dispatch_context_t<hb_apply_context_t, bool, HB_DEBUG_APPLY>
{
+ struct matcher_t
+ {
+ inline matcher_t (void) :
+ lookup_props (0),
+ ignore_zwnj (false),
+ ignore_zwj (false),
+ 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_ignore_zwj (bool ignore_zwj_) { ignore_zwj = ignore_zwj_; }
+ 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_; }
+
+ enum may_match_t {
+ MATCH_NO,
+ MATCH_YES,
+ MATCH_MAYBE
+ };
+
+ inline may_match_t may_match (const hb_glyph_info_t &info,
+ const USHORT *glyph_data) const
+ {
+ if (!(info.mask & mask) ||
+ (syllable && syllable != info.syllable ()))
+ return MATCH_NO;
+
+ if (match_func)
+ return match_func (info.codepoint, *glyph_data, match_data) ? MATCH_YES : MATCH_NO;
+
+ return MATCH_MAYBE;
+ }
+
+ 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
+ {
+ if (!c->check_glyph_property (&info, lookup_props))
+ return SKIP_YES;
+
+ if (unlikely (_hb_glyph_info_is_default_ignorable_and_not_fvs (&info) &&
+ (ignore_zwnj || !_hb_glyph_info_is_zwnj (&info)) &&
+ (ignore_zwj || !_hb_glyph_info_is_zwj (&info))))
+ return SKIP_MAYBE;
+
+ return SKIP_NO;
+ }
+
+ protected:
+ unsigned int lookup_props;
+ bool ignore_zwnj;
+ bool ignore_zwj;
+ hb_mask_t mask;
+ uint8_t syllable;
+ match_func_t match_func;
+ const void *match_data;
+ };
+
+ struct skipping_iterator_t
+ {
+ inline void init (hb_apply_context_t *c_, bool context_match = false)
+ {
+ c = c_;
+ match_glyph_data = NULL,
+ matcher.set_match_func (NULL, NULL);
+ 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);
+ /* Ignore ZWJ if we are matching GSUB context, or matching GPOS, or if asked to. */
+ matcher.set_ignore_zwj (context_match || c->table_index == 1 || c->auto_zwj);
+ matcher.set_mask (context_match ? -1 : c->lookup_mask);
+ }
+ inline void set_lookup_props (unsigned int lookup_props)
+ {
+ matcher.set_lookup_props (lookup_props);
+ }
+ inline void set_match_func (matcher_t::match_func_t match_func_,
+ const void *match_data_,
+ const USHORT glyph_data[])
+ {
+ matcher.set_match_func (match_func_, match_data_);
+ match_glyph_data = glyph_data;
+ }
+
+ inline void reset (unsigned int start_index_,
+ unsigned int num_items_)
+ {
+ idx = start_index_;
+ num_items = num_items_;
+ end = c->buffer->len;
+ matcher.set_syllable (start_index_ == c->buffer->idx ? c->buffer->cur().syllable () : 0);
+ }
+
+ inline void reject (void) { num_items++; match_glyph_data--; }
+
+ inline bool next (void)
+ {
+ assert (num_items > 0);
+ while (idx + num_items < end)
+ {
+ idx++;
+ const hb_glyph_info_t &info = c->buffer->info[idx];
+
+ matcher_t::may_skip_t skip = matcher.may_skip (c, info);
+ if (unlikely (skip == matcher_t::SKIP_YES))
+ continue;
+
+ matcher_t::may_match_t match = matcher.may_match (info, match_glyph_data);
+ if (match == matcher_t::MATCH_YES ||
+ (match == matcher_t::MATCH_MAYBE &&
+ skip == matcher_t::SKIP_NO))
+ {
+ num_items--;
+ match_glyph_data++;
+ return true;
+ }
+
+ if (skip == matcher_t::SKIP_NO)
+ return false;
+ }
+ return false;
+ }
+ inline bool prev (void)
+ {
+ assert (num_items > 0);
+ while (idx >= num_items)
+ {
+ idx--;
+ const hb_glyph_info_t &info = c->buffer->out_info[idx];
+
+ matcher_t::may_skip_t skip = matcher.may_skip (c, info);
+ if (unlikely (skip == matcher_t::SKIP_YES))
+ continue;
+
+ matcher_t::may_match_t match = matcher.may_match (info, match_glyph_data);
+ if (match == matcher_t::MATCH_YES ||
+ (match == matcher_t::MATCH_MAYBE &&
+ skip == matcher_t::SKIP_NO))
+ {
+ 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;
+ matcher_t matcher;
+ const USHORT *match_glyph_data;
+
+ unsigned int num_items;
+ unsigned int end;
+ };
+
+
inline const char *get_name (void) { return "APPLY"; }
- static const unsigned int max_debug_depth = HB_DEBUG_APPLY;
- typedef bool return_t;
typedef return_t (*recurse_func_t) (hb_apply_context_t *c, unsigned int lookup_index);
template <typename T>
- inline return_t process (const T &obj) { return obj.apply (this); }
+ inline return_t dispatch (const T &obj) { return obj.apply (this); }
static return_t default_return_value (void) { return false; }
bool stop_sublookup_iteration (return_t r) const { return r; }
return_t recurse (unsigned int lookup_index)
return ret;
}
+ unsigned int table_index; /* GSUB/GPOS */
hb_font_t *font;
hb_face_t *face;
hb_buffer_t *buffer;
hb_direction_t direction;
hb_mask_t lookup_mask;
+ bool auto_zwj;
recurse_func_t recurse_func;
unsigned int nesting_level_left;
unsigned int lookup_props;
- unsigned int property; /* propety of first glyph */
const GDEF &gdef;
bool has_glyph_classes;
+ skipping_iterator_t iter_input, iter_context;
+ unsigned int lookup_index;
unsigned int debug_depth;
- hb_apply_context_t (hb_font_t *font_,
- hb_buffer_t *buffer_,
- hb_mask_t lookup_mask_) :
+ hb_apply_context_t (unsigned int table_index_,
+ hb_font_t *font_,
+ hb_buffer_t *buffer_) :
+ table_index (table_index_),
font (font_), face (font->face), buffer (buffer_),
direction (buffer_->props.direction),
- lookup_mask (lookup_mask_),
+ lookup_mask (1),
+ auto_zwj (true),
recurse_func (NULL),
- nesting_level_left (MAX_NESTING_LEVEL),
- lookup_props (0), property (0),
+ nesting_level_left (HB_MAX_NESTING_LEVEL),
+ lookup_props (0),
gdef (*hb_ot_layout_from_face (face)->gdef),
has_glyph_classes (gdef.has_glyph_classes ()),
+ iter_input (),
+ iter_context (),
+ lookup_index ((unsigned int) -1),
debug_depth (0) {}
- void set_recurse_func (recurse_func_t func) { recurse_func = func; }
- void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; }
- void set_lookup (const Lookup &l) { lookup_props = l.get_props (); }
-
- struct mark_skipping_forward_iterator_t
+ inline void set_lookup_mask (hb_mask_t mask) { lookup_mask = mask; }
+ inline void set_auto_zwj (bool auto_zwj_) { auto_zwj = auto_zwj_; }
+ inline void set_recurse_func (recurse_func_t func) { recurse_func = func; }
+ inline void set_lookup_index (unsigned int lookup_index_) { lookup_index = lookup_index_; }
+ inline void set_lookup_props (unsigned int lookup_props_)
{
- inline mark_skipping_forward_iterator_t (hb_apply_context_t *c_,
- unsigned int start_index_,
- unsigned int num_items_,
- bool context_match = false)
- {
- c = c_;
- 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 bool has_no_chance (void) const
- {
- return unlikely (num_items && idx + num_items >= end);
- }
- inline void reject (void)
- {
- num_items++;
- }
- inline bool next (unsigned int *property_out,
- unsigned int lookup_props)
- {
- assert (num_items > 0);
- do
- {
- if (has_no_chance ())
- return false;
- idx++;
- } while (c->should_skip_mark (&c->buffer->info[idx], lookup_props, property_out));
- num_items--;
- return (c->buffer->info[idx].mask & mask) && (!syllable || syllable == c->buffer->info[idx].syllable ());
- }
- inline bool next (unsigned int *property_out = NULL)
- {
- return next (property_out, c->lookup_props);
- }
-
- unsigned int idx;
- protected:
- hb_apply_context_t *c;
- unsigned int num_items;
- hb_mask_t mask;
- uint8_t syllable;
- unsigned int end;
- };
-
- struct mark_skipping_backward_iterator_t
- {
- inline mark_skipping_backward_iterator_t (hb_apply_context_t *c_,
- unsigned int start_index_,
- unsigned int num_items_,
- hb_mask_t mask_ = 0,
- bool match_syllable_ = true)
- {
- c = c_;
- idx = start_index_;
- num_items = num_items_;
- mask = mask_ ? mask_ : c->lookup_mask;
- syllable = match_syllable_ ? c->buffer->cur().syllable () : 0;
- }
- inline bool has_no_chance (void) const
- {
- return unlikely (idx < num_items);
- }
- inline void reject (void)
- {
- num_items++;
- }
- inline bool prev (unsigned int *property_out,
- unsigned int lookup_props)
- {
- assert (num_items > 0);
- do
- {
- if (has_no_chance ())
- return false;
- idx--;
- } while (c->should_skip_mark (&c->buffer->out_info[idx], lookup_props, property_out));
- num_items--;
- return (c->buffer->out_info[idx].mask & mask) && (!syllable || syllable == c->buffer->out_info[idx].syllable ());
- }
- inline bool prev (unsigned int *property_out = NULL)
- {
- return prev (property_out, c->lookup_props);
- }
-
- unsigned int idx;
- protected:
- hb_apply_context_t *c;
- unsigned int num_items;
- hb_mask_t mask;
- uint8_t syllable;
- };
+ lookup_props = lookup_props_;
+ iter_input.init (this, false);
+ iter_context.init (this, true);
+ }
inline bool
match_properties_mark (hb_codepoint_t glyph,
unsigned int glyph_props,
- unsigned int lookup_props) const
+ unsigned int match_props) const
{
/* If using mark filtering sets, the high short of
- * lookup_props has the set index.
+ * match_props has the set index.
*/
- if (lookup_props & LookupFlag::UseMarkFilteringSet)
- return gdef.mark_set_covers (lookup_props >> 16, glyph);
+ if (match_props & LookupFlag::UseMarkFilteringSet)
+ return gdef.mark_set_covers (match_props >> 16, glyph);
- /* The second byte of lookup_props has the meaning
+ /* The second byte of match_props has the meaning
* "ignore marks of attachment type different than
* the attachment type specified."
*/
- if (lookup_props & LookupFlag::MarkAttachmentType)
- return (lookup_props & LookupFlag::MarkAttachmentType) == (glyph_props & LookupFlag::MarkAttachmentType);
+ if (match_props & LookupFlag::MarkAttachmentType)
+ return (match_props & LookupFlag::MarkAttachmentType) == (glyph_props & LookupFlag::MarkAttachmentType);
return true;
}
inline bool
- match_properties (hb_codepoint_t glyph,
- unsigned int glyph_props,
- unsigned int lookup_props) const
+ check_glyph_property (const hb_glyph_info_t *info,
+ unsigned int match_props) const
{
+ hb_codepoint_t glyph = info->codepoint;
+ unsigned int glyph_props = _hb_glyph_info_get_glyph_props (info);
+
/* Not covered, if, for example, glyph class is ligature and
- * lookup_props includes LookupFlags::IgnoreLigatures
+ * match_props includes LookupFlags::IgnoreLigatures
*/
- if (glyph_props & lookup_props & LookupFlag::IgnoreFlags)
+ if (glyph_props & match_props & LookupFlag::IgnoreFlags)
return false;
if (unlikely (glyph_props & HB_OT_LAYOUT_GLYPH_PROPS_MARK))
- return match_properties_mark (glyph, glyph_props, lookup_props);
+ return match_properties_mark (glyph, glyph_props, match_props);
return true;
}
- inline bool
- check_glyph_property (hb_glyph_info_t *info,
- unsigned int lookup_props,
- unsigned int *property_out) const
- {
- unsigned int property;
-
- property = info->glyph_props();
- *property_out = property;
-
- return match_properties (info->codepoint, property, lookup_props);
- }
-
- inline bool
- should_skip_mark (hb_glyph_info_t *info,
- unsigned int lookup_props,
- unsigned int *property_out) const
- {
- unsigned int property;
-
- property = info->glyph_props();
- if (property_out)
- *property_out = property;
-
- /* If it's a mark, skip it if we don't accept it. */
- if (unlikely (property & HB_OT_LAYOUT_GLYPH_PROPS_MARK))
- return !match_properties (info->codepoint, property, lookup_props);
-
- /* If not a mark, don't skip. */
- return false;
- }
-
-
- inline bool should_mark_skip_current_glyph (void) const
- {
- return should_skip_mark (&buffer->cur(), lookup_props, NULL);
- }
-
- inline void set_class (hb_codepoint_t glyph_index, unsigned int class_guess) const
+ inline void _set_glyph_props (hb_codepoint_t glyph_index,
+ unsigned int class_guess = 0,
+ bool ligature = false,
+ bool component = false) const
{
+ unsigned int add_in = _hb_glyph_info_get_glyph_props (&buffer->cur()) &
+ HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE;
+ add_in |= HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED;
+ if (ligature)
+ {
+ add_in |= HB_OT_LAYOUT_GLYPH_PROPS_LIGATED;
+ /* In the only place that the MULTIPLIED bit is used, Uniscribe
+ * seems to only care about the "last" transformation between
+ * Ligature and Multiple substitions. Ie. if you ligate, expand,
+ * and ligate again, it forgives the multiplication and acts as
+ * if only ligation happened. As such, clear MULTIPLIED bit.
+ */
+ add_in &= ~HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED;
+ }
+ if (component)
+ add_in |= HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED;
if (likely (has_glyph_classes))
- buffer->cur().glyph_props() = gdef.get_glyph_props (glyph_index);
+ _hb_glyph_info_set_glyph_props (&buffer->cur(), add_in | gdef.get_glyph_props (glyph_index));
else if (class_guess)
- buffer->cur().glyph_props() = class_guess;
+ _hb_glyph_info_set_glyph_props (&buffer->cur(), add_in | class_guess);
}
- inline void output_glyph (hb_codepoint_t glyph_index,
- unsigned int class_guess = 0) const
+ inline void replace_glyph (hb_codepoint_t glyph_index) const
{
- set_class (glyph_index, class_guess);
- buffer->output_glyph (glyph_index);
+ _set_glyph_props (glyph_index);
+ buffer->replace_glyph (glyph_index);
+ }
+ inline void replace_glyph_inplace (hb_codepoint_t glyph_index) const
+ {
+ _set_glyph_props (glyph_index);
+ buffer->cur().codepoint = glyph_index;
}
- inline void replace_glyph (hb_codepoint_t glyph_index,
- unsigned int class_guess = 0) const
+ inline void replace_glyph_with_ligature (hb_codepoint_t glyph_index,
+ unsigned int class_guess) const
{
- set_class (glyph_index, class_guess);
+ _set_glyph_props (glyph_index, class_guess, true);
buffer->replace_glyph (glyph_index);
}
- inline void replace_glyph_inplace (hb_codepoint_t glyph_index,
- unsigned int class_guess = 0) const
+ inline void output_glyph_for_component (hb_codepoint_t glyph_index,
+ unsigned int class_guess) const
{
- set_class (glyph_index, class_guess);
- buffer->cur().codepoint = glyph_index;
+ _set_glyph_props (glyph_index, class_guess, false, true);
+ buffer->output_glyph (glyph_index);
}
};
const USHORT input[], /* Array of input values--start with second glyph */
match_func_t match_func,
const void *match_data,
- unsigned int *end_offset = NULL,
+ unsigned int *end_offset,
+ unsigned int match_positions[HB_MAX_CONTEXT_LENGTH],
bool *p_is_mark_ligature = NULL,
unsigned int *p_total_component_count = NULL)
{
TRACE_APPLY (NULL);
- hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx, count - 1);
- if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false);
+ if (unlikely (count > HB_MAX_CONTEXT_LENGTH)) return_trace (false);
+
+ hb_buffer_t *buffer = c->buffer;
+
+ hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
+ skippy_iter.reset (buffer->idx, count - 1);
+ skippy_iter.set_match_func (match_func, match_data, input);
/*
* This is perhaps the trickiest part of OpenType... Remarks:
* ligate with a conjunct...)
*/
- bool is_mark_ligature = !!(c->property & HB_OT_LAYOUT_GLYPH_PROPS_MARK);
+ bool is_mark_ligature = _hb_glyph_info_is_mark (&buffer->cur());
unsigned int total_component_count = 0;
- total_component_count += get_lig_num_comps (c->buffer->cur());
+ total_component_count += _hb_glyph_info_get_lig_num_comps (&buffer->cur());
- unsigned int first_lig_id = get_lig_id (c->buffer->cur());
- unsigned int first_lig_comp = get_lig_comp (c->buffer->cur());
+ unsigned int first_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur());
+ unsigned int first_lig_comp = _hb_glyph_info_get_lig_comp (&buffer->cur());
+ match_positions[0] = buffer->idx;
for (unsigned int i = 1; i < count; i++)
{
- unsigned int property;
+ if (!skippy_iter.next ()) return_trace (false);
- if (!skippy_iter.next (&property)) return TRACE_RETURN (false);
+ match_positions[i] = skippy_iter.idx;
- 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]);
+ unsigned int this_lig_id = _hb_glyph_info_get_lig_id (&buffer->info[skippy_iter.idx]);
+ unsigned int this_lig_comp = _hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx]);
if (first_lig_id && first_lig_comp) {
/* If first component was attached to a previous ligature component,
* all subsequent components should be attached to the same ligature
* component, otherwise we shouldn't ligate them. */
if (first_lig_id != this_lig_id || first_lig_comp != this_lig_comp)
- return TRACE_RETURN (false);
+ return_trace (false);
} else {
/* If first component was NOT attached to a previous ligature component,
* all subsequent components should also NOT be attached to any ligature
* component, unless they are attached to the first component itself! */
if (this_lig_id && this_lig_comp && (this_lig_id != first_lig_id))
- return TRACE_RETURN (false);
+ return_trace (false);
}
- is_mark_ligature = is_mark_ligature && (property & HB_OT_LAYOUT_GLYPH_PROPS_MARK);
- total_component_count += get_lig_num_comps (c->buffer->info[skippy_iter.idx]);
+ is_mark_ligature = is_mark_ligature && _hb_glyph_info_is_mark (&buffer->info[skippy_iter.idx]);
+ total_component_count += _hb_glyph_info_get_lig_num_comps (&buffer->info[skippy_iter.idx]);
}
- if (end_offset)
- *end_offset = skippy_iter.idx - c->buffer->idx + 1;
+ *end_offset = skippy_iter.idx - buffer->idx + 1;
if (p_is_mark_ligature)
*p_is_mark_ligature = is_mark_ligature;
if (p_total_component_count)
*p_total_component_count = total_component_count;
- return TRACE_RETURN (true);
+ return_trace (true);
}
-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 */
+static inline bool ligate_input (hb_apply_context_t *c,
+ unsigned int count, /* Including the first glyph */
+ unsigned int match_positions[HB_MAX_CONTEXT_LENGTH], /* Including the first glyph */
+ unsigned int match_length,
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)
{
+ TRACE_APPLY (NULL);
+
+ hb_buffer_t *buffer = c->buffer;
+
+ buffer->merge_clusters (buffer->idx, buffer->idx + match_length);
+
/*
* - 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 klass = is_mark_ligature ? 0 : HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE;
- unsigned int lig_id = is_mark_ligature ? 0 : allocate_lig_id (c->buffer);
- unsigned int last_lig_id = get_lig_id (c->buffer->cur());
- unsigned int last_num_components = get_lig_num_comps (c->buffer->cur());
+ unsigned int lig_id = is_mark_ligature ? 0 : _hb_allocate_lig_id (buffer);
+ unsigned int last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur());
+ unsigned int last_num_components = _hb_glyph_info_get_lig_num_comps (&buffer->cur());
unsigned int components_so_far = last_num_components;
if (!is_mark_ligature)
- set_lig_props_for_ligature (c->buffer->cur(), lig_id, total_component_count);
- c->replace_glyph (lig_glyph, klass);
+ {
+ _hb_glyph_info_set_lig_props_for_ligature (&buffer->cur(), lig_id, total_component_count);
+ if (_hb_glyph_info_get_general_category (&buffer->cur()) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
+ {
+ _hb_glyph_info_set_general_category (&buffer->cur(), HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER);
+ }
+ }
+ c->replace_glyph_with_ligature (lig_glyph, klass);
for (unsigned int i = 1; i < count; i++)
{
- while (c->should_mark_skip_current_glyph ())
+ while (buffer->idx < match_positions[i] && !buffer->in_error)
{
if (!is_mark_ligature) {
+ unsigned int this_comp = _hb_glyph_info_get_lig_comp (&buffer->cur());
+ if (this_comp == 0)
+ this_comp = last_num_components;
unsigned int new_lig_comp = components_so_far - last_num_components +
- MIN (MAX (get_lig_comp (c->buffer->cur()), 1u), last_num_components);
- set_lig_props_for_mark (c->buffer->cur(), lig_id, new_lig_comp);
+ MIN (this_comp, last_num_components);
+ _hb_glyph_info_set_lig_props_for_mark (&buffer->cur(), lig_id, new_lig_comp);
}
- c->buffer->next_glyph ();
+ buffer->next_glyph ();
}
- last_lig_id = get_lig_id (c->buffer->cur());
- last_num_components = get_lig_num_comps (c->buffer->cur());
+ last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur());
+ last_num_components = _hb_glyph_info_get_lig_num_comps (&buffer->cur());
components_so_far += last_num_components;
/* Skip the base glyph */
- c->buffer->idx++;
+ buffer->idx++;
}
if (!is_mark_ligature && last_lig_id) {
/* Re-adjust components for any marks following. */
- for (unsigned int i = c->buffer->idx; i < c->buffer->len; i++) {
- if (last_lig_id == get_lig_id (c->buffer->info[i])) {
+ for (unsigned int i = buffer->idx; i < buffer->len; i++) {
+ if (last_lig_id == _hb_glyph_info_get_lig_id (&buffer->info[i])) {
+ unsigned int this_comp = _hb_glyph_info_get_lig_comp (&buffer->info[i]);
+ if (!this_comp)
+ break;
unsigned int new_lig_comp = components_so_far - last_num_components +
- MIN (MAX (get_lig_comp (c->buffer->info[i]), 1u), last_num_components);
- set_lig_props_for_mark (c->buffer->info[i], lig_id, new_lig_comp);
+ MIN (this_comp, last_num_components);
+ _hb_glyph_info_set_lig_props_for_mark (&buffer->info[i], lig_id, new_lig_comp);
} else
break;
}
}
+ return_trace (true);
}
static inline bool match_backtrack (hb_apply_context_t *c,
{
TRACE_APPLY (NULL);
- hb_apply_context_t::mark_skipping_backward_iterator_t skippy_iter (c, c->buffer->backtrack_len (), count, true);
- if (skippy_iter.has_no_chance ())
- return TRACE_RETURN (false);
+ hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_context;
+ skippy_iter.reset (c->buffer->backtrack_len (), count);
+ skippy_iter.set_match_func (match_func, match_data, backtrack);
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 (false);
- return TRACE_RETURN (true);
+ return_trace (true);
}
static inline bool match_lookahead (hb_apply_context_t *c,
{
TRACE_APPLY (NULL);
- hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx + offset - 1, count, true);
- if (skippy_iter.has_no_chance ())
- return TRACE_RETURN (false);
+ hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_context;
+ skippy_iter.reset (c->buffer->idx + offset - 1, count);
+ skippy_iter.set_match_func (match_func, match_data, lookahead);
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 (false);
- return TRACE_RETURN (true);
+ return_trace (true);
}
struct LookupRecord
{
- inline bool sanitize (hb_sanitize_context_t *c) {
+ inline bool sanitize (hb_sanitize_context_t *c) const
+ {
TRACE_SANITIZE (this);
- return TRACE_RETURN (c->check_struct (this));
+ return_trace (c->check_struct (this));
}
USHORT sequenceIndex; /* Index into current glyph
const LookupRecord lookupRecord[] /* Array of LookupRecords--in design order */)
{
for (unsigned int i = 0; i < lookupCount; i++)
- c->recurse (lookupRecord->lookupListIndex);
+ c->recurse (lookupRecord[i].lookupListIndex);
}
static inline bool apply_lookup (hb_apply_context_t *c,
unsigned int count, /* Including the first glyph */
+ unsigned int match_positions[HB_MAX_CONTEXT_LENGTH], /* Including the first glyph */
unsigned int lookupCount,
- const LookupRecord lookupRecord[] /* Array of LookupRecords--in design order */)
+ const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */
+ unsigned int match_length)
{
TRACE_APPLY (NULL);
- unsigned int end = c->buffer->len;
- if (unlikely (count == 0 || c->buffer->idx + count > end))
- return TRACE_RETURN (false);
+ hb_buffer_t *buffer = c->buffer;
+ unsigned int end;
- /* TODO We don't support lookupRecord arrays that are not increasing:
- * Should be easy for in_place ones at least. */
+ /* All positions are distance from beginning of *output* buffer.
+ * Adjust. */
+ {
+ unsigned int bl = buffer->backtrack_len ();
+ end = bl + match_length;
- /* Note: If sublookup is reverse, it will underflow after the first loop
- * and we jump out of it. Not entirely disastrous. So we don't check
- * for reverse lookup here.
- */
- for (unsigned int i = 0; i < count; /* NOP */)
+ int delta = bl - buffer->idx;
+ /* Convert positions to new indexing. */
+ for (unsigned int j = 0; j < count; j++)
+ match_positions[j] += delta;
+ }
+
+ for (unsigned int i = 0; i < lookupCount && !buffer->in_error; i++)
{
- if (unlikely (c->buffer->idx == end))
- return TRACE_RETURN (true);
- while (c->should_mark_skip_current_glyph ())
- {
- /* No lookup applied for this index */
- c->buffer->next_glyph ();
- if (unlikely (c->buffer->idx == end))
- return TRACE_RETURN (true);
- }
+ unsigned int idx = lookupRecord[i].sequenceIndex;
+ if (idx >= count)
+ continue;
- if (lookupCount && i == lookupRecord->sequenceIndex)
- {
- unsigned int old_pos = c->buffer->idx;
+ /* Don't recurse to ourself at same position.
+ * Note that this test is too naive, it doesn't catch longer loops. */
+ if (idx == 0 && lookupRecord[i].lookupListIndex == c->lookup_index)
+ continue;
+
+ buffer->move_to (match_positions[idx]);
+
+ unsigned int orig_len = buffer->backtrack_len () + buffer->lookahead_len ();
+ if (!c->recurse (lookupRecord[i].lookupListIndex))
+ continue;
+
+ unsigned int new_len = buffer->backtrack_len () + buffer->lookahead_len ();
+ int delta = new_len - orig_len;
+
+ if (!delta)
+ continue;
- /* Apply a lookup */
- bool done = c->recurse (lookupRecord->lookupListIndex);
+ /* Recursed lookup changed buffer len. Adjust. */
- lookupRecord++;
- lookupCount--;
- /* Err, this is wrong if the lookup jumped over some glyphs */
- i += c->buffer->idx - old_pos;
- if (unlikely (c->buffer->idx == end))
- return TRACE_RETURN (true);
+ /* end can't go back past the current match position.
+ * Note: this is only true because we do NOT allow MultipleSubst
+ * with zero sequence len. */
+ end = MAX (MIN((int) match_positions[idx] + 1, (int) new_len), int (end) + delta);
- if (!done)
- goto not_applied;
+ unsigned int next = idx + 1; /* next now is the position after the recursed lookup. */
+
+ if (delta > 0)
+ {
+ if (unlikely (delta + count > HB_MAX_CONTEXT_LENGTH))
+ break;
}
else
{
- not_applied:
- /* No lookup applied for this index */
- c->buffer->next_glyph ();
- i++;
+ /* NOTE: delta is negative. */
+ delta = MAX (delta, (int) next - (int) count);
+ next -= delta;
}
+
+ /* Shift! */
+ memmove (match_positions + next + delta, match_positions + next,
+ (count - next) * sizeof (match_positions[0]));
+ next += delta;
+ count += delta;
+
+ /* Fill in new entries. */
+ for (unsigned int j = idx + 1; j < next; j++)
+ match_positions[j] = match_positions[j - 1] + 1;
+
+ /* And fixup the rest. */
+ for (; next < count; next++)
+ match_positions[next] += delta;
}
- return TRACE_RETURN (true);
+ buffer->move_to (end);
+
+ return_trace (true);
}
const LookupRecord lookupRecord[],
ContextApplyLookupContext &lookup_context)
{
+ unsigned int match_length = 0;
+ unsigned int match_positions[HB_MAX_CONTEXT_LENGTH];
return match_input (c,
inputCount, input,
- lookup_context.funcs.match, lookup_context.match_data)
+ lookup_context.funcs.match, lookup_context.match_data,
+ &match_length, match_positions)
&& apply_lookup (c,
- inputCount,
- lookupCount, lookupRecord);
+ inputCount, match_positions,
+ lookupCount, lookupRecord,
+ match_length);
}
struct Rule
inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const
{
TRACE_CLOSURE (this);
- const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (input, input[0].static_size * (inputCount ? inputCount - 1 : 0));
+ const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
context_closure_lookup (c,
- inputCount, input,
+ inputCount, inputZ,
lookupCount, lookupRecord,
lookup_context);
}
inline void collect_glyphs (hb_collect_glyphs_context_t *c, ContextCollectGlyphsLookupContext &lookup_context) const
{
TRACE_COLLECT_GLYPHS (this);
- const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (input, input[0].static_size * (inputCount ? inputCount - 1 : 0));
+ const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
context_collect_glyphs_lookup (c,
- inputCount, input,
+ inputCount, inputZ,
lookupCount, lookupRecord,
lookup_context);
}
inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
{
TRACE_WOULD_APPLY (this);
- const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (input, input[0].static_size * (inputCount ? inputCount - 1 : 0));
- return TRACE_RETURN (context_would_apply_lookup (c, inputCount, input, lookupCount, lookupRecord, lookup_context));
+ const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
+ return_trace (context_would_apply_lookup (c, inputCount, inputZ, lookupCount, lookupRecord, lookup_context));
}
inline bool apply (hb_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
{
TRACE_APPLY (this);
- const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (input, input[0].static_size * (inputCount ? inputCount - 1 : 0));
- return TRACE_RETURN (context_apply_lookup (c, inputCount, input, lookupCount, lookupRecord, lookup_context));
+ const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
+ return_trace (context_apply_lookup (c, inputCount, inputZ, lookupCount, lookupRecord, lookup_context));
}
public:
- inline bool sanitize (hb_sanitize_context_t *c) {
+ inline bool sanitize (hb_sanitize_context_t *c) const
+ {
TRACE_SANITIZE (this);
return inputCount.sanitize (c)
&& lookupCount.sanitize (c)
- && c->check_range (input,
- input[0].static_size * inputCount
+ && c->check_range (inputZ,
+ inputZ[0].static_size * inputCount
+ lookupRecordX[0].static_size * lookupCount);
}
* glyph sequence--includes the first
* glyph */
USHORT lookupCount; /* Number of LookupRecords */
- USHORT input[VAR]; /* Array of match inputs--start with
+ USHORT inputZ[VAR]; /* Array of match inputs--start with
* second glyph */
LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in
* design order */
public:
- DEFINE_SIZE_ARRAY2 (4, input, lookupRecordX);
+ DEFINE_SIZE_ARRAY2 (4, inputZ, lookupRecordX);
};
struct RuleSet
for (unsigned int i = 0; i < num_rules; i++)
{
if ((this+rule[i]).would_apply (c, lookup_context))
- return TRACE_RETURN (true);
+ return_trace (true);
}
- return TRACE_RETURN (false);
+ return_trace (false);
}
inline bool apply (hb_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
for (unsigned int i = 0; i < num_rules; i++)
{
if ((this+rule[i]).apply (c, lookup_context))
- return TRACE_RETURN (true);
+ return_trace (true);
}
- return TRACE_RETURN (false);
+ return_trace (false);
}
- inline bool sanitize (hb_sanitize_context_t *c) {
+ inline bool sanitize (hb_sanitize_context_t *c) const
+ {
TRACE_SANITIZE (this);
- return TRACE_RETURN (rule.sanitize (c, this));
+ return_trace (rule.sanitize (c, this));
}
protected:
{match_glyph},
NULL
};
- return TRACE_RETURN (rule_set.would_apply (c, lookup_context));
+ return_trace (rule_set.would_apply (c, lookup_context));
}
inline const Coverage &get_coverage (void) const
TRACE_APPLY (this);
unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
if (likely (index == NOT_COVERED))
- return TRACE_RETURN (false);
+ return_trace (false);
const RuleSet &rule_set = this+ruleSet[index];
struct ContextApplyLookupContext lookup_context = {
{match_glyph},
NULL
};
- return TRACE_RETURN (rule_set.apply (c, lookup_context));
+ return_trace (rule_set.apply (c, lookup_context));
}
- inline bool sanitize (hb_sanitize_context_t *c) {
+ inline bool sanitize (hb_sanitize_context_t *c) const
+ {
TRACE_SANITIZE (this);
- return TRACE_RETURN (coverage.sanitize (c, this) && ruleSet.sanitize (c, this));
+ return_trace (coverage.sanitize (c, this) && ruleSet.sanitize (c, this));
}
protected:
{match_class},
&class_def
};
- return TRACE_RETURN (rule_set.would_apply (c, lookup_context));
+ return_trace (rule_set.would_apply (c, lookup_context));
}
inline const Coverage &get_coverage (void) const
{
TRACE_APPLY (this);
unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
- if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
+ if (likely (index == NOT_COVERED)) return_trace (false);
const ClassDef &class_def = this+classDef;
index = class_def.get_class (c->buffer->cur().codepoint);
{match_class},
&class_def
};
- return TRACE_RETURN (rule_set.apply (c, lookup_context));
+ return_trace (rule_set.apply (c, lookup_context));
}
- inline bool sanitize (hb_sanitize_context_t *c) {
+ inline bool sanitize (hb_sanitize_context_t *c) const
+ {
TRACE_SANITIZE (this);
- return TRACE_RETURN (coverage.sanitize (c, this) && classDef.sanitize (c, this) && ruleSet.sanitize (c, this));
+ return_trace (coverage.sanitize (c, this) && classDef.sanitize (c, this) && ruleSet.sanitize (c, this));
}
protected:
inline void closure (hb_closure_context_t *c) const
{
TRACE_CLOSURE (this);
- if (!(this+coverage[0]).intersects (c->glyphs))
+ if (!(this+coverageZ[0]).intersects (c->glyphs))
return;
- const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * glyphCount);
+ const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
struct ContextClosureLookupContext lookup_context = {
{intersects_coverage},
this
};
context_closure_lookup (c,
- glyphCount, (const USHORT *) (coverage + 1),
+ glyphCount, (const USHORT *) (coverageZ + 1),
lookupCount, lookupRecord,
lookup_context);
}
inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
{
TRACE_COLLECT_GLYPHS (this);
- (this+coverage[0]).add_coverage (c->input);
+ (this+coverageZ[0]).add_coverage (c->input);
- const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * glyphCount);
+ const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
struct ContextCollectGlyphsLookupContext lookup_context = {
{collect_coverage},
this
};
context_collect_glyphs_lookup (c,
- glyphCount, (const USHORT *) (coverage + 1),
+ glyphCount, (const USHORT *) (coverageZ + 1),
lookupCount, lookupRecord,
lookup_context);
}
{
TRACE_WOULD_APPLY (this);
- const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * glyphCount);
+ const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
struct ContextApplyLookupContext lookup_context = {
{match_coverage},
this
};
- return TRACE_RETURN (context_would_apply_lookup (c, glyphCount, (const USHORT *) (coverage + 1), lookupCount, lookupRecord, lookup_context));
+ return_trace (context_would_apply_lookup (c, glyphCount, (const USHORT *) (coverageZ + 1), lookupCount, lookupRecord, lookup_context));
}
inline const Coverage &get_coverage (void) const
{
- return this+coverage[0];
+ return this+coverageZ[0];
}
inline bool apply (hb_apply_context_t *c) const
{
TRACE_APPLY (this);
- unsigned int index = (this+coverage[0]).get_coverage (c->buffer->cur().codepoint);
- if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
+ unsigned int index = (this+coverageZ[0]).get_coverage (c->buffer->cur().codepoint);
+ if (likely (index == NOT_COVERED)) return_trace (false);
- const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * glyphCount);
+ const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
struct ContextApplyLookupContext lookup_context = {
{match_coverage},
this
};
- return TRACE_RETURN (context_apply_lookup (c, glyphCount, (const USHORT *) (coverage + 1), lookupCount, lookupRecord, lookup_context));
+ return_trace (context_apply_lookup (c, glyphCount, (const USHORT *) (coverageZ + 1), lookupCount, lookupRecord, lookup_context));
}
- inline bool sanitize (hb_sanitize_context_t *c) {
+ inline bool sanitize (hb_sanitize_context_t *c) const
+ {
TRACE_SANITIZE (this);
- if (!c->check_struct (this)) return TRACE_RETURN (false);
+ if (!c->check_struct (this)) return_trace (false);
unsigned int count = glyphCount;
- if (!c->check_array (coverage, coverage[0].static_size, count)) return TRACE_RETURN (false);
+ if (!count) return_trace (false); /* We want to access coverageZ[0] freely. */
+ if (!c->check_array (coverageZ, coverageZ[0].static_size, count)) return_trace (false);
for (unsigned int i = 0; i < count; i++)
- if (!coverage[i].sanitize (c, this)) return TRACE_RETURN (false);
- LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * count);
- return TRACE_RETURN (c->check_array (lookupRecord, lookupRecord[0].static_size, lookupCount));
+ if (!coverageZ[i].sanitize (c, this)) return_trace (false);
+ const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * count);
+ return_trace (c->check_array (lookupRecord, lookupRecord[0].static_size, lookupCount));
}
protected:
* sequence */
USHORT lookupCount; /* Number of LookupRecords */
OffsetTo<Coverage>
- coverage[VAR]; /* Array of offsets to Coverage
+ coverageZ[VAR]; /* Array of offsets to Coverage
* table in glyph sequence order */
LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in
* design order */
public:
- DEFINE_SIZE_ARRAY2 (6, coverage, lookupRecordX);
+ DEFINE_SIZE_ARRAY2 (6, coverageZ, lookupRecordX);
};
struct Context
{
template <typename context_t>
- inline typename context_t::return_t process (context_t *c) const
+ inline typename context_t::return_t dispatch (context_t *c) const
{
- TRACE_PROCESS (this);
+ TRACE_DISPATCH (this, u.format);
+ if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
switch (u.format) {
- case 1: return TRACE_RETURN (c->process (u.format1));
- case 2: return TRACE_RETURN (c->process (u.format2));
- case 3: return TRACE_RETURN (c->process (u.format3));
- default:return TRACE_RETURN (c->default_return_value ());
- }
- }
-
- inline bool sanitize (hb_sanitize_context_t *c) {
- TRACE_SANITIZE (this);
- if (!u.format.sanitize (c)) return TRACE_RETURN (false);
- switch (u.format) {
- case 1: return TRACE_RETURN (u.format1.sanitize (c));
- case 2: return TRACE_RETURN (u.format2.sanitize (c));
- case 3: return TRACE_RETURN (u.format3.sanitize (c));
- default:return TRACE_RETURN (true);
+ case 1: return_trace (c->dispatch (u.format1));
+ case 2: return_trace (c->dispatch (u.format2));
+ case 3: return_trace (c->dispatch (u.format3));
+ default:return_trace (c->default_return_value ());
}
}
&& intersects_array (c,
inputCount ? inputCount - 1 : 0, input,
lookup_context.funcs.intersects, lookup_context.intersects_data[1])
- && intersects_array (c,
+ && intersects_array (c,
lookaheadCount, lookahead,
lookup_context.funcs.intersects, lookup_context.intersects_data[2]))
recurse_lookups (c,
const LookupRecord lookupRecord[],
ChainContextApplyLookupContext &lookup_context)
{
- unsigned int lookahead_offset = 0;
+ unsigned int match_length = 0;
+ unsigned int match_positions[HB_MAX_CONTEXT_LENGTH];
return match_input (c,
inputCount, input,
lookup_context.funcs.match, lookup_context.match_data[1],
- &lookahead_offset)
+ &match_length, match_positions)
&& match_backtrack (c,
backtrackCount, backtrack,
lookup_context.funcs.match, lookup_context.match_data[0])
&& match_lookahead (c,
lookaheadCount, lookahead,
lookup_context.funcs.match, lookup_context.match_data[2],
- lookahead_offset)
+ match_length)
&& apply_lookup (c,
- inputCount,
- lookupCount, lookupRecord);
+ inputCount, match_positions,
+ lookupCount, lookupRecord,
+ match_length);
}
struct ChainRule
const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
- return TRACE_RETURN (chain_context_would_apply_lookup (c,
- backtrack.len, backtrack.array,
- input.len, input.array,
- lookahead.len, lookahead.array, lookup.len,
- lookup.array, lookup_context));
+ return_trace (chain_context_would_apply_lookup (c,
+ backtrack.len, backtrack.array,
+ input.len, input.array,
+ lookahead.len, lookahead.array, lookup.len,
+ lookup.array, lookup_context));
}
inline bool apply (hb_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
- return TRACE_RETURN (chain_context_apply_lookup (c,
- backtrack.len, backtrack.array,
- input.len, input.array,
- lookahead.len, lookahead.array, lookup.len,
- lookup.array, lookup_context));
+ return_trace (chain_context_apply_lookup (c,
+ backtrack.len, backtrack.array,
+ input.len, input.array,
+ lookahead.len, lookahead.array, lookup.len,
+ lookup.array, lookup_context));
}
- inline bool sanitize (hb_sanitize_context_t *c) {
+ inline bool sanitize (hb_sanitize_context_t *c) const
+ {
TRACE_SANITIZE (this);
- if (!backtrack.sanitize (c)) return TRACE_RETURN (false);
- HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
- if (!input.sanitize (c)) return TRACE_RETURN (false);
- ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
- if (!lookahead.sanitize (c)) return TRACE_RETURN (false);
- ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
- return TRACE_RETURN (lookup.sanitize (c));
+ if (!backtrack.sanitize (c)) return_trace (false);
+ const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
+ if (!input.sanitize (c)) return_trace (false);
+ const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
+ if (!lookahead.sanitize (c)) return_trace (false);
+ const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
+ return_trace (lookup.sanitize (c));
}
protected:
unsigned int num_rules = rule.len;
for (unsigned int i = 0; i < num_rules; i++)
if ((this+rule[i]).would_apply (c, lookup_context))
- return TRACE_RETURN (true);
+ return_trace (true);
- return TRACE_RETURN (false);
+ return_trace (false);
}
inline bool apply (hb_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
unsigned int num_rules = rule.len;
for (unsigned int i = 0; i < num_rules; i++)
if ((this+rule[i]).apply (c, lookup_context))
- return TRACE_RETURN (true);
+ return_trace (true);
- return TRACE_RETURN (false);
+ return_trace (false);
}
- inline bool sanitize (hb_sanitize_context_t *c) {
+ inline bool sanitize (hb_sanitize_context_t *c) const
+ {
TRACE_SANITIZE (this);
- return TRACE_RETURN (rule.sanitize (c, this));
+ return_trace (rule.sanitize (c, this));
}
protected:
{match_glyph},
{NULL, NULL, NULL}
};
- return TRACE_RETURN (rule_set.would_apply (c, lookup_context));
+ return_trace (rule_set.would_apply (c, lookup_context));
}
inline const Coverage &get_coverage (void) const
{
TRACE_APPLY (this);
unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
- if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
+ if (likely (index == NOT_COVERED)) return_trace (false);
const ChainRuleSet &rule_set = this+ruleSet[index];
struct ChainContextApplyLookupContext lookup_context = {
{match_glyph},
{NULL, NULL, NULL}
};
- return TRACE_RETURN (rule_set.apply (c, lookup_context));
+ return_trace (rule_set.apply (c, lookup_context));
}
- inline bool sanitize (hb_sanitize_context_t *c) {
+ inline bool sanitize (hb_sanitize_context_t *c) const
+ {
TRACE_SANITIZE (this);
- return TRACE_RETURN (coverage.sanitize (c, this) && ruleSet.sanitize (c, this));
+ return_trace (coverage.sanitize (c, this) && ruleSet.sanitize (c, this));
}
protected:
&input_class_def,
&lookahead_class_def}
};
- return TRACE_RETURN (rule_set.would_apply (c, lookup_context));
+ return_trace (rule_set.would_apply (c, lookup_context));
}
inline const Coverage &get_coverage (void) const
{
TRACE_APPLY (this);
unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
- if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
+ if (likely (index == NOT_COVERED)) return_trace (false);
const ClassDef &backtrack_class_def = this+backtrackClassDef;
const ClassDef &input_class_def = this+inputClassDef;
&input_class_def,
&lookahead_class_def}
};
- return TRACE_RETURN (rule_set.apply (c, lookup_context));
+ return_trace (rule_set.apply (c, lookup_context));
}
- inline bool sanitize (hb_sanitize_context_t *c) {
+ inline bool sanitize (hb_sanitize_context_t *c) const
+ {
TRACE_SANITIZE (this);
- return TRACE_RETURN (coverage.sanitize (c, this) && backtrackClassDef.sanitize (c, this) &&
- inputClassDef.sanitize (c, this) && lookaheadClassDef.sanitize (c, this) &&
- ruleSet.sanitize (c, this));
+ return_trace (coverage.sanitize (c, this) &&
+ backtrackClassDef.sanitize (c, this) &&
+ inputClassDef.sanitize (c, this) &&
+ lookaheadClassDef.sanitize (c, this) &&
+ ruleSet.sanitize (c, this));
}
protected:
{match_coverage},
{this, this, this}
};
- return TRACE_RETURN (chain_context_would_apply_lookup (c,
- backtrack.len, (const USHORT *) backtrack.array,
- input.len, (const USHORT *) input.array + 1,
- lookahead.len, (const USHORT *) lookahead.array,
- lookup.len, lookup.array, lookup_context));
+ return_trace (chain_context_would_apply_lookup (c,
+ backtrack.len, (const USHORT *) backtrack.array,
+ input.len, (const USHORT *) input.array + 1,
+ lookahead.len, (const USHORT *) lookahead.array,
+ lookup.len, lookup.array, lookup_context));
}
inline const Coverage &get_coverage (void) const
const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
unsigned int index = (this+input[0]).get_coverage (c->buffer->cur().codepoint);
- if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
+ if (likely (index == NOT_COVERED)) return_trace (false);
const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
{match_coverage},
{this, this, this}
};
- return TRACE_RETURN (chain_context_apply_lookup (c,
- backtrack.len, (const USHORT *) backtrack.array,
- input.len, (const USHORT *) input.array + 1,
- lookahead.len, (const USHORT *) lookahead.array,
- lookup.len, lookup.array, lookup_context));
+ return_trace (chain_context_apply_lookup (c,
+ backtrack.len, (const USHORT *) backtrack.array,
+ input.len, (const USHORT *) input.array + 1,
+ lookahead.len, (const USHORT *) lookahead.array,
+ lookup.len, lookup.array, lookup_context));
}
- inline bool sanitize (hb_sanitize_context_t *c) {
+ inline bool sanitize (hb_sanitize_context_t *c) const
+ {
TRACE_SANITIZE (this);
- if (!backtrack.sanitize (c, this)) return TRACE_RETURN (false);
- OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
- if (!input.sanitize (c, this)) return TRACE_RETURN (false);
- OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
- if (!lookahead.sanitize (c, this)) return TRACE_RETURN (false);
- ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
- return TRACE_RETURN (lookup.sanitize (c));
+ if (!backtrack.sanitize (c, this)) return_trace (false);
+ const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
+ if (!input.sanitize (c, this)) return_trace (false);
+ if (!input.len) return_trace (false); /* To be consistent with Context. */
+ const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
+ if (!lookahead.sanitize (c, this)) return_trace (false);
+ const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
+ return_trace (lookup.sanitize (c));
}
protected:
struct ChainContext
{
template <typename context_t>
- inline typename context_t::return_t process (context_t *c) const
+ inline typename context_t::return_t dispatch (context_t *c) const
{
- TRACE_PROCESS (this);
+ TRACE_DISPATCH (this, u.format);
+ if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
switch (u.format) {
- case 1: return TRACE_RETURN (c->process (u.format1));
- case 2: return TRACE_RETURN (c->process (u.format2));
- case 3: return TRACE_RETURN (c->process (u.format3));
- default:return TRACE_RETURN (c->default_return_value ());
- }
- }
-
- inline bool sanitize (hb_sanitize_context_t *c) {
- TRACE_SANITIZE (this);
- if (!u.format.sanitize (c)) return TRACE_RETURN (false);
- switch (u.format) {
- case 1: return TRACE_RETURN (u.format1.sanitize (c));
- case 2: return TRACE_RETURN (u.format2.sanitize (c));
- case 3: return TRACE_RETURN (u.format3.sanitize (c));
- default:return TRACE_RETURN (true);
+ case 1: return_trace (c->dispatch (u.format1));
+ case 2: return_trace (c->dispatch (u.format2));
+ case 3: return_trace (c->dispatch (u.format3));
+ default:return_trace (c->default_return_value ());
}
}
};
+template <typename T>
struct ExtensionFormat1
{
inline unsigned int get_type (void) const { return extensionLookupType; }
- inline unsigned int get_offset (void) const { return extensionOffset; }
- inline bool sanitize (hb_sanitize_context_t *c) {
+ template <typename X>
+ inline const X& get_subtable (void) const
+ {
+ unsigned int offset = extensionOffset;
+ if (unlikely (!offset)) return Null(typename T::LookupSubTable);
+ return StructAtOffset<typename T::LookupSubTable> (this, offset);
+ }
+
+ template <typename context_t>
+ inline typename context_t::return_t dispatch (context_t *c) const
+ {
+ TRACE_DISPATCH (this, format);
+ if (unlikely (!c->may_dispatch (this, this))) return_trace (c->no_dispatch_return_value ());
+ return_trace (get_subtable<typename T::LookupSubTable> ().dispatch (c, get_type ()));
+ }
+
+ /* This is called from may_dispatch() above with hb_sanitize_context_t. */
+ inline bool sanitize (hb_sanitize_context_t *c) const
+ {
TRACE_SANITIZE (this);
- return TRACE_RETURN (c->check_struct (this));
+ return_trace (c->check_struct (this) && extensionOffset != 0);
}
protected:
default:return 0;
}
}
- inline unsigned int get_offset (void) const
- {
- switch (u.format) {
- case 1: return u.format1.get_offset ();
- default:return 0;
- }
- }
-
template <typename X>
inline const X& get_subtable (void) const
{
- unsigned int offset = get_offset ();
- if (unlikely (!offset)) return Null(typename T::LookupSubTable);
- return StructAtOffset<typename T::LookupSubTable> (this, offset);
+ switch (u.format) {
+ case 1: return u.format1.template get_subtable<typename T::LookupSubTable> ();
+ default:return Null(typename T::LookupSubTable);
+ }
}
template <typename context_t>
- inline typename context_t::return_t process (context_t *c) const
+ inline typename context_t::return_t dispatch (context_t *c) const
{
- return get_subtable<typename T::LookupSubTable> ().process (c, get_type ());
- }
-
- inline bool sanitize_self (hb_sanitize_context_t *c) {
- TRACE_SANITIZE (this);
- if (!u.format.sanitize (c)) return TRACE_RETURN (false);
+ TRACE_DISPATCH (this, u.format);
+ if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
switch (u.format) {
- case 1: return TRACE_RETURN (u.format1.sanitize (c));
- default:return TRACE_RETURN (true);
+ case 1: return_trace (u.format1.dispatch (c));
+ default:return_trace (c->default_return_value ());
}
}
- inline bool sanitize (hb_sanitize_context_t *c) {
- TRACE_SANITIZE (this);
- if (!sanitize_self (c)) return TRACE_RETURN (false);
- unsigned int offset = get_offset ();
- if (unlikely (!offset)) return TRACE_RETURN (true);
- return TRACE_RETURN (StructAtOffset<typename T::LookupSubTable> (this, offset).sanitize (c, get_type ()));
- }
-
protected:
union {
USHORT format; /* Format identifier */
- ExtensionFormat1 format1;
+ ExtensionFormat1<T> format1;
} u;
};
inline unsigned int get_feature_count (void) const
{ return (this+featureList).len; }
- inline const Tag& get_feature_tag (unsigned int i) const
- { return (this+featureList).get_tag (i); }
+ inline hb_tag_t get_feature_tag (unsigned int i) const
+ { return i == Index::NOT_FOUND_INDEX ? HB_TAG_NONE : (this+featureList).get_tag (i); }
inline unsigned int get_feature_tags (unsigned int start_offset,
unsigned int *feature_count /* IN/OUT */,
hb_tag_t *feature_tags /* OUT */) const
inline const Lookup& get_lookup (unsigned int i) const
{ return (this+lookupList)[i]; }
- inline bool sanitize (hb_sanitize_context_t *c) {
+ inline bool sanitize (hb_sanitize_context_t *c) const
+ {
TRACE_SANITIZE (this);
- return TRACE_RETURN (version.sanitize (c) && likely (version.major == 1) &&
- scriptList.sanitize (c, this) &&
- featureList.sanitize (c, this) &&
- lookupList.sanitize (c, this));
+ return_trace (version.sanitize (c) &&
+ likely (version.major == 1) &&
+ scriptList.sanitize (c, this) &&
+ featureList.sanitize (c, this) &&
+ lookupList.sanitize (c, this));
}
protected:
- FixedVersion version; /* Version of the GSUB/GPOS table--initially set
- * to 0x00010000 */
+ FixedVersion<>version; /* Version of the GSUB/GPOS table--initially set
+ * to 0x00010000u */
OffsetTo<ScriptList>
scriptList; /* ScriptList table */
OffsetTo<FeatureList>