[colr][feat][meta] Port sub_array iteration to dagger (#1868)
authorEbrahim Byagowi <ebrahim@gnu.org>
Tue, 30 Jul 2019 00:14:23 +0000 (04:44 +0430)
committerGitHub <noreply@github.com>
Tue, 30 Jul 2019 00:14:23 +0000 (04:44 +0430)
src/hb-aat-layout-feat-table.hh
src/hb-ot-color-colr-table.hh
src/hb-ot-meta-table.hh

index 2345f21..c822994 100644 (file)
@@ -47,17 +47,16 @@ struct SettingName
   hb_aat_layout_feature_selector_t get_selector () const
   { return (hb_aat_layout_feature_selector_t) (unsigned) setting; }
 
-  void get_info (hb_aat_layout_feature_selector_info_t *s,
-                       hb_aat_layout_feature_selector_t default_selector) const
+  hb_aat_layout_feature_selector_info_t get_info (hb_aat_layout_feature_selector_t default_selector) const
   {
-    s->name_id = nameIndex;
-
-    s->enable = (hb_aat_layout_feature_selector_t) (unsigned int) setting;
-    s->disable = default_selector == HB_AAT_LAYOUT_FEATURE_SELECTOR_INVALID ?
-                (hb_aat_layout_feature_selector_t) (s->enable + 1) :
-                default_selector;
-
-    s->reserved = 0;
+    return {
+      nameIndex,
+      (hb_aat_layout_feature_selector_t) (unsigned int) setting,
+      default_selector == HB_AAT_LAYOUT_FEATURE_SELECTOR_INVALID
+       ? (hb_aat_layout_feature_selector_t) (setting + 1)
+       : default_selector,
+      0
+    };
   }
 
   bool sanitize (hb_sanitize_context_t *c) const
@@ -117,9 +116,10 @@ struct FeatureName
 
     if (selectors_count)
     {
-      hb_array_t<const SettingName> arr = settings_table.sub_array (start_offset, selectors_count);
-      for (unsigned int i = 0; i < arr.length; i++)
-        settings_table[start_offset + i].get_info (&selectors[i], default_selector);
+      + settings_table.sub_array (start_offset, selectors_count)
+      | hb_map ([=] (const SettingName& setting) { return setting.get_info (default_selector); })
+      | hb_sink (hb_array (selectors, *selectors_count))
+      ;
     }
     return settings_table.length;
   }
@@ -162,13 +162,12 @@ struct feat
                                  unsigned int                 *count,
                                  hb_aat_layout_feature_type_t *features) const
   {
-    unsigned int feature_count = featureNameCount;
-    if (count && *count)
+    if (count)
     {
-      unsigned int len = hb_min (feature_count - start_offset, *count);
-      for (unsigned int i = 0; i < len; i++)
-       features[i] = namesZ[i + start_offset].get_feature_type ();
-      *count = len;
+      + namesZ.as_array (featureNameCount).sub_array (start_offset, count)
+      | hb_map (&FeatureName::get_feature_type)
+      | hb_sink (hb_array (features, *count))
+      ;
     }
     return featureNameCount;
   }
index 90f89d5..41f9f71 100644 (file)
@@ -39,13 +39,15 @@ namespace OT {
 
 struct LayerRecord
 {
+  operator hb_ot_color_layer_t () const { return {glyphId, colorIdx}; }
+
   bool sanitize (hb_sanitize_context_t *c) const
   {
     TRACE_SANITIZE (this);
     return_trace (c->check_struct (this));
   }
 
-  public:
+  protected:
   GlyphID      glyphId;        /* Glyph ID of layer glyph */
   Index                colorIdx;       /* Index value to use with a
                                 * selected color palette.
@@ -103,13 +105,9 @@ struct COLR
                                                                       record.numLayers);
     if (count)
     {
-      hb_array_t<const LayerRecord> segment_layers = glyph_layers.sub_array (start_offset, *count);
-      *count = segment_layers.length;
-      for (unsigned int i = 0; i < segment_layers.length; i++)
-      {
-        layers[i].glyph = segment_layers.arrayZ[i].glyphId;
-        layers[i].color_index = segment_layers.arrayZ[i].colorIdx;
-      }
+      + glyph_layers.sub_array (start_offset, count)
+      | hb_sink (hb_array (layers, *count))
+      ;
     }
     return glyph_layers.length;
   }
index f0842e4..43a02d6 100644 (file)
@@ -84,9 +84,11 @@ struct meta
     {
       if (count)
       {
-       hb_array_t<const DataMap> arr = table->dataMaps.sub_array (start_offset, count);
-       for (unsigned int i = 0; i < arr.length; i++)
-         entries[i] = (hb_ot_meta_tag_t) arr[i].get_tag ();
+       + table->dataMaps.sub_array (start_offset, count)
+       | hb_map (&DataMap::get_tag)
+       | hb_map ([](hb_tag_t tag) { return (hb_ot_meta_tag_t) tag; })
+       | hb_sink (hb_array (entries, *count))
+       ;
       }
       return table->dataMaps.len;
     }