[serialize] Add a couple small methods

This commit is contained in:
Behdad Esfahbod 2018-08-31 16:38:04 -07:00
parent d1f29908c2
commit 22acd424ca
3 changed files with 19 additions and 10 deletions

View 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)
{
@ -482,13 +498,6 @@ struct hb_serialize_context_t
return this->allocate_size<Type> (Type::min_size);
}
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)
{

View 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)

View 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);
}