[serialize] Add a couple small methods
authorBehdad Esfahbod <behdad@behdad.org>
Fri, 31 Aug 2018 23:38:04 +0000 (16:38 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Fri, 31 Aug 2018 23:41:18 +0000 (16:41 -0700)
src/hb-machinery.hh
src/hb-open-file.hh
src/hb-ot-layout-gsub-table.hh

index 1e0f7cc..0452693 100644 (file)
@@ -443,6 +443,7 @@ struct hb_serialize_context_t
     this->debug_depth = 0;
   }
 
+  /* To be called around main operation. */
   template <typename Type>
   inline Type *start_serialize (void)
   {
@@ -453,7 +454,6 @@ struct hb_serialize_context_t
 
     return start_embed<Type> ();
   }
-
   inline void end_serialize (void)
   {
     DEBUG_MSG_LEVEL (SERIALIZE, this->start, 0, -1,
@@ -463,6 +463,22 @@ struct hb_serialize_context_t
                     this->ran_out_of_room ? "RAN OUT OF ROOM" : "did not ran out of room");
   }
 
+  inline unsigned int length (void) const { return this->head - this->start; }
+
+  inline void align (unsigned int alignment)
+  {
+    unsigned int l = length () % alignment;
+    if (l)
+      allocate_size<void> (alignment - l);
+  }
+
+  template <typename Type>
+  inline Type *start_embed (void)
+  {
+    Type *ret = reinterpret_cast<Type *> (this->head);
+    return ret;
+  }
+
   template <typename Type>
   inline Type *allocate_size (unsigned int size)
   {
@@ -483,13 +499,6 @@ struct hb_serialize_context_t
   }
 
   template <typename Type>
-  inline Type *start_embed (void)
-  {
-    Type *ret = reinterpret_cast<Type *> (this->head);
-    return ret;
-  }
-
-  template <typename Type>
   inline Type *embed (const Type &obj)
   {
     unsigned int size = obj.get_size ();
index 97e736e..847f9b0 100644 (file)
@@ -161,8 +161,7 @@ typedef struct OffsetTable
       memcpy (start, hb_blob_get_data (blob, nullptr), rec.length);
 
       /* 4-byte allignment. */
-      if (rec.length % 4)
-       c->allocate_size<void> (4 - rec.length % 4);
+      c->align (4);
       const char *end = (const char *) c->head;
 
       if (tags[i] == HB_OT_TAG_head && end - start >= head::static_size)
index 5737b21..d7f8983 100644 (file)
@@ -1312,6 +1312,7 @@ struct GSUB : GSUBGPOS
   inline bool subset (hb_subset_context_t<Serializer> *c)
   {
     TRACE_SUBSET (this);
+    //struct GSUB *out = c->serializer->start_embed<GSUB> ();
     //XXX if (unlikely (!GSUBGPOS::subset (c))) return_trace (false);
     return_trace (true);
   }