[subset] Move hdmx to subset2.
authorGarret Rieger <grieger@google.com>
Tue, 7 May 2019 22:47:38 +0000 (15:47 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 8 May 2019 22:47:24 +0000 (15:47 -0700)
src/hb-ot-hdmx-table.hh
src/hb-subset.cc

index 847b326..abf4440 100644 (file)
@@ -157,40 +157,16 @@ struct hdmx
     return_trace (true);
   }
 
-  static size_t get_subsetted_size (const hdmx *source_hdmx, hb_subset_plan_t *plan)
-  {
-    return min_size + source_hdmx->numRecords * DeviceRecord::get_size (plan->num_output_glyphs ());
-  }
 
-  bool subset (hb_subset_plan_t *plan) const
+  bool subset (hb_subset_context_t *c) const
   {
-    size_t dest_size = get_subsetted_size (this, plan);
-    hdmx *dest = (hdmx *) malloc (dest_size);
-    if (unlikely (!dest))
-    {
-      DEBUG_MSG(SUBSET, nullptr, "Unable to alloc %lu for hdmx subset output.", (unsigned long) dest_size);
-      return false;
-    }
+    TRACE_SUBSET (this);
 
-    hb_serialize_context_t c (dest, dest_size);
-    hdmx *hdmx_prime = c.start_serialize<hdmx> ();
-    if (!hdmx_prime || !hdmx_prime->serialize (&c, this, plan))
-    {
-      free (dest);
-      DEBUG_MSG(SUBSET, nullptr, "Failed to serialize write new hdmx.");
-      return false;
-    }
-    c.end_serialize ();
+    hdmx *hdmx_prime = c->serializer->start_embed <hdmx> ();
+    if (unlikely (!hdmx_prime)) return_trace (false);
 
-    hb_blob_t *hdmx_prime_blob = hb_blob_create ((const char *) dest,
-                                                dest_size,
-                                                HB_MEMORY_MODE_READONLY,
-                                                dest,
-                                                free);
-    bool result = plan->add_table (HB_OT_TAG_hdmx, hdmx_prime_blob);
-    hb_blob_destroy (hdmx_prime_blob);
-
-    return result;
+    hdmx_prime->serialize (c->serializer, this, c->plan);
+    return_trace (true);
   }
 
   bool sanitize (hb_sanitize_context_t *c) const
index 800bd35..f4fc771 100644 (file)
@@ -159,7 +159,7 @@ _subset_table (hb_subset_plan_t *plan,
       result = _subset<const OT::glyf> (plan);
       break;
     case HB_OT_TAG_hdmx:
-      result = _subset<const OT::hdmx> (plan);
+      result = _subset2<const OT::hdmx> (plan);
       break;
     case HB_OT_TAG_name:
       result = _subset2<const OT::name> (plan);