Imported Upstream version 3.4.0
[platform/upstream/harfbuzz.git] / src / hb-ot-stat-table.hh
index 8813523..41d1734 100644 (file)
@@ -59,6 +59,9 @@ enum
 
 struct AxisValueFormat1
 {
+  unsigned int get_axis_index () const { return axisIndex; }
+  float get_value ()             const { return value.to_float (); }
+
   hb_ot_name_id_t get_value_name_id () const { return valueNameID; }
 
   bool sanitize (hb_sanitize_context_t *c) const
@@ -84,6 +87,9 @@ struct AxisValueFormat1
 
 struct AxisValueFormat2
 {
+  unsigned int get_axis_index () const { return axisIndex; }
+  float get_value ()             const { return nominalValue.to_float (); }
+
   hb_ot_name_id_t get_value_name_id () const { return valueNameID; }
 
   bool sanitize (hb_sanitize_context_t *c) const
@@ -113,6 +119,9 @@ struct AxisValueFormat2
 
 struct AxisValueFormat3
 {
+  unsigned int get_axis_index () const { return axisIndex; }
+  float get_value ()             const { return value.to_float (); }
+
   hb_ot_name_id_t get_value_name_id () const { return valueNameID; }
 
   bool sanitize (hb_sanitize_context_t *c) const
@@ -140,6 +149,9 @@ struct AxisValueFormat3
 
 struct AxisValueRecord
 {
+  unsigned int get_axis_index () const { return axisIndex; }
+  float get_value ()             const { return value.to_float (); }
+
   bool sanitize (hb_sanitize_context_t *c) const
   {
     TRACE_SANITIZE (this);
@@ -157,6 +169,9 @@ struct AxisValueRecord
 
 struct AxisValueFormat4
 {
+  const AxisValueRecord &get_axis_record (unsigned int axis_index) const
+  { return axisValues.as_array (axisCount)[axis_index]; }
+
   hb_ot_name_id_t get_value_name_id () const { return valueNameID; }
 
   bool sanitize (hb_sanitize_context_t *c) const
@@ -183,6 +198,30 @@ struct AxisValueFormat4
 
 struct AxisValue
 {
+  bool get_value (unsigned int axis_index) const
+  {
+    switch (u.format)
+    {
+    case 1: return u.format1.get_value ();
+    case 2: return u.format2.get_value ();
+    case 3: return u.format3.get_value ();
+    case 4: return u.format4.get_axis_record (axis_index).get_value ();
+    default:return 0;
+    }
+  }
+
+  unsigned int get_axis_index () const
+  {
+    switch (u.format)
+    {
+    case 1: return u.format1.get_axis_index ();
+    case 2: return u.format2.get_axis_index ();
+    case 3: return u.format3.get_axis_index ();
+    /* case 4: Makes more sense for variable fonts which are handled by fvar in hb-style */
+    default:return -1;
+    }
+  }
+
   hb_ot_name_id_t get_value_name_id () const
   {
     switch (u.format)
@@ -226,6 +265,8 @@ struct AxisValue
 
 struct StatAxisRecord
 {
+  int cmp (hb_tag_t key) const { return tag.cmp (key); }
+
   hb_ot_name_id_t get_name_id () const { return nameID; }
 
   bool sanitize (hb_sanitize_context_t *c) const
@@ -251,6 +292,25 @@ struct STAT
 
   bool has_data () const { return version.to_int (); }
 
+  bool get_value (hb_tag_t tag, float *value) const
+  {
+    unsigned int axis_index;
+    if (!get_design_axes ().lfind (tag, &axis_index)) return false;
+
+    hb_array_t<const Offset16To<AxisValue>> axis_values = get_axis_value_offsets ();
+    for (unsigned int i = 0; i < axis_values.length; i++)
+    {
+      const AxisValue& axis_value = this+axis_values[i];
+      if (axis_value.get_axis_index () == axis_index)
+      {
+       if (value)
+         *value = axis_value.get_value (axis_index);
+       return true;
+      }
+    }
+    return false;
+  }
+
   unsigned get_design_axis_count () const { return designAxisCount; }
 
   hb_ot_name_id_t get_axis_record_name_id (unsigned axis_record_index) const
@@ -299,7 +359,7 @@ struct STAT
   hb_array_t<const StatAxisRecord> const get_design_axes () const
   { return (this+designAxesOffset).as_array (designAxisCount); }
 
-  hb_array_t<const OffsetTo<AxisValue>> const get_axis_value_offsets () const
+  hb_array_t<const Offset16To<AxisValue>> const get_axis_value_offsets () const
   { return (this+offsetToAxisValueOffsets).as_array (axisValueCount); }
 
 
@@ -313,7 +373,7 @@ struct STAT
                                 * in the 'fvar' table. In all fonts, must
                                 * be greater than zero if axisValueCount
                                 * is greater than zero. */
-  LNNOffsetTo<UnsizedArrayOf<StatAxisRecord>>
+  NNOffset32To<UnsizedArrayOf<StatAxisRecord>>
                designAxesOffset;
                                /* Offset in bytes from the beginning of
                                 * the STAT table to the start of the design
@@ -321,7 +381,7 @@ struct STAT
                                 * set to zero; if designAxisCount is greater
                                 * than zero, must be greater than zero. */
   HBUINT16     axisValueCount; /* The number of axis value tables. */
-  LNNOffsetTo<UnsizedArrayOf<OffsetTo<AxisValue>>>
+  NNOffset32To<UnsizedArrayOf<Offset16To<AxisValue>>>
                offsetToAxisValueOffsets;
                                /* Offset in bytes from the beginning of
                                 * the STAT table to the start of the design