From 22acd424ca77c16d28405021f06c5562497920ab Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 31 Aug 2018 16:38:04 -0700 Subject: [PATCH] [serialize] Add a couple small methods --- src/hb-machinery.hh | 25 +++++++++++++++++-------- src/hb-open-file.hh | 3 +-- src/hb-ot-layout-gsub-table.hh | 1 + 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index 1e0f7cc..0452693 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -443,6 +443,7 @@ struct hb_serialize_context_t this->debug_depth = 0; } + /* To be called around main operation. */ template inline Type *start_serialize (void) { @@ -453,7 +454,6 @@ struct hb_serialize_context_t return start_embed (); } - 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 (alignment - l); + } + + template + inline Type *start_embed (void) + { + Type *ret = reinterpret_cast (this->head); + return ret; + } + template inline Type *allocate_size (unsigned int size) { @@ -483,13 +499,6 @@ struct hb_serialize_context_t } template - inline Type *start_embed (void) - { - Type *ret = reinterpret_cast (this->head); - return ret; - } - - template inline Type *embed (const Type &obj) { unsigned int size = obj.get_size (); diff --git a/src/hb-open-file.hh b/src/hb-open-file.hh index 97e736e..847f9b0 100644 --- a/src/hb-open-file.hh +++ b/src/hb-open-file.hh @@ -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 (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) diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index 5737b21..d7f8983 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -1312,6 +1312,7 @@ struct GSUB : GSUBGPOS inline bool subset (hb_subset_context_t *c) { TRACE_SUBSET (this); + //struct GSUB *out = c->serializer->start_embed (); //XXX if (unlikely (!GSUBGPOS::subset (c))) return_trace (false); return_trace (true); } -- 2.7.4