[trak] More
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 11 Oct 2018 14:29:02 +0000 (10:29 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Thu, 11 Oct 2018 14:29:02 +0000 (10:29 -0400)
src/hb-aat-layout-trak-table.hh

index dbad449..9054922 100644 (file)
@@ -98,33 +98,41 @@ struct TrackData
     unsigned int sizes = nSizes;
 
     const TrackTableEntry *trackTableEntry = nullptr;
-    for (unsigned int i = 0; i < sizes; ++i)
-      // For now we only seek for track entries with zero tracking value
+    for (unsigned int i = 0; i < sizes; i++)
+    {
+      /* Note: Seems like the track entries are sorted by values.  But the
+       * spec doesn't explicitly say that.  It just mentions it in the example. */
+
+      /* For now we only seek for track entries with zero tracking value */
+
       if (trackTable[i].get_track_value () == 0.f)
-        trackTableEntry = &trackTable[0];
+      {
+       trackTableEntry = &trackTable[0];
+       break;
+      }
+    }
 
-    // We couldn't match any, exit
     if (!trackTableEntry) return 0.;
 
     /* TODO bfind() */
     unsigned int size_index;
     UnsizedArrayOf<Fixed> size_table = base+sizeTable;
-    for (size_index = 0; size_index < sizes; ++size_index)
+    for (size_index = 0; size_index < sizes; size_index++)
       if (size_table[size_index] >= fixed_size)
         break;
 
     // TODO(ebraminio): We don't attempt to extrapolate to larger or
     // smaller values for now but we should do, per spec
     if (size_index == sizes)
-      return trackTableEntry->get_value (base, sizes - 1, nSizes);
+      return trackTableEntry->get_value (base, sizes - 1, sizes);
     if (size_index == 0 || size_table[size_index] == fixed_size)
-      return trackTableEntry->get_value (base, size_index, nSizes);
+      return trackTableEntry->get_value (base, size_index, sizes);
 
     float s0 = size_table[size_index - 1].to_float ();
     float s1 = size_table[size_index].to_float ();
     float t = (csspx - s0) / (s1 - s0);
-    return (float) t * trackTableEntry->get_value (base, size_index, nSizes) +
-          ((float) 1.0 - t) * trackTableEntry->get_value (base, size_index - 1, nSizes);
+    return (float) t * trackTableEntry->get_value (base, size_index, sizes) +
+          ((float) 1.0 - t) * trackTableEntry->get_value (base, size_index - 1, sizes);
   }
 
   inline bool sanitize (hb_sanitize_context_t *c, const void *base) const