Fix ChanContext backtrack matching with GPOS
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 6 Jan 2011 19:58:52 +0000 (14:58 -0500)
committerBehdad Esfahbod <behdad@behdad.org>
Thu, 6 Jan 2011 19:58:52 +0000 (14:58 -0500)
Reported on mailing list by Keith Stribley and Khaled Hosny.

src/hb-buffer-private.hh
src/hb-buffer.cc
src/hb-ot-layout-gsubgpos-private.hh

index a129165..d8834c5 100644 (file)
@@ -99,7 +99,7 @@ struct _hb_buffer_t {
 
   unsigned int i; /* Cursor into ->info and ->pos arrays */
   unsigned int len; /* Length of ->info and ->pos arrays */
-  unsigned int out_len; /* Length of ->out array */
+  unsigned int out_len; /* Length of ->out array if have_output */
 
   hb_glyph_info_t     *info;
   hb_glyph_info_t     *out_info;
@@ -111,6 +111,8 @@ struct _hb_buffer_t {
 
 
   /* Methods */
+  inline unsigned int backtrack_len (void) const
+  { return this->have_output? this->out_len : this->i; }
   inline unsigned int next_serial (void) { return serial++; }
   inline void swap (void) { _hb_buffer_swap (this); }
   inline void clear_output (void) { _hb_buffer_clear_output (this); }
@@ -137,7 +139,6 @@ struct _hb_buffer_t {
                         unsigned int cluster_start,
                         unsigned int cluster_end)
   { _hb_buffer_set_masks (this, value, mask, cluster_start, cluster_end); }
-
 };
 
 
index f50d87b..04ae8c9 100644 (file)
@@ -45,7 +45,7 @@ static hb_buffer_t _hb_buffer_nil = {
  *
  * As an optimization, both info and out_info may point to the
  * same piece of memory, which is owned by info.  This remains the
- * case as long as out_len doesn't exceed len at any time.
+ * case as long as out_len doesn't exceed i at any time.
  * In that case, swap() is no-op and the glyph operations operate
  * mostly in-place.
  *
index c2b2eea..f2aca6b 100644 (file)
@@ -155,10 +155,10 @@ static inline bool match_backtrack (hb_apply_context_t *c,
                                    match_func_t match_func,
                                    const void *match_data)
 {
-  if (unlikely (c->buffer->out_len < count))
+  if (unlikely (c->buffer->backtrack_len () < count))
     return false;
 
-  for (unsigned int i = 0, j = c->buffer->out_len - 1; i < count; i++, j--)
+  for (unsigned int i = 0, j = c->buffer->backtrack_len () - 1; i < count; i++, j--)
   {
     while (_hb_ot_layout_skip_mark (c->layout->face, &c->buffer->out_info[j], c->lookup_props, NULL))
     {
@@ -562,7 +562,7 @@ static inline bool chain_context_lookup (hb_apply_context_t *c,
                                         ChainContextLookupContext &lookup_context)
 {
   /* First guess */
-  if (unlikely (c->buffer->out_len < backtrackCount ||
+  if (unlikely (c->buffer->backtrack_len () < backtrackCount ||
                c->buffer->i + inputCount + lookaheadCount > c->buffer->len ||
                inputCount + lookaheadCount > c->context_length))
     return false;