[subset] In hdmx serialize set the correct value of sizeDeviceRecord.

This commit is contained in:
Garret Rieger 2018-02-21 15:43:47 -08:00
parent dddf44279f
commit 84b68e5886
1 changed files with 16 additions and 13 deletions

View File

@ -53,15 +53,6 @@ struct DeviceRecord
return this->subset_plan->gids_to_retain_sorted.len;
}
inline unsigned int get_size () const
{
unsigned int raw_size = min_size + len () * HBUINT8::static_size;
if (raw_size % 4)
/* Align to 32 bits */
return raw_size + (4 - (raw_size % 4));
return raw_size;
}
inline const HBUINT8& operator [] (unsigned int i) const
{
if (unlikely (i >= len())) return Null(HBUINT8);
@ -70,11 +61,20 @@ struct DeviceRecord
}
};
static inline unsigned int get_size (unsigned int count)
{
unsigned int raw_size = min_size + count * HBUINT8::static_size;
if (raw_size % 4)
/* Align to 32 bits */
return raw_size + (4 - (raw_size % 4));
return raw_size;
}
inline bool serialize (hb_serialize_context_t *c, const SubsetView &subset_view)
{
TRACE_SERIALIZE (this);
if (unlikely (!c->allocate_size<DeviceRecord> (subset_view.get_size())))
if (unlikely (!c->allocate_size<DeviceRecord> (get_size (subset_view.len()))))
return_trace (false);
this->pixel_size.set (subset_view.source_device_record->pixel_size);
@ -93,8 +93,6 @@ struct DeviceRecord
DEFINE_SIZE_MIN (2);
};
struct hdmx
{
@ -117,7 +115,7 @@ struct hdmx
this->version.set (source_hdmx->version);
this->num_records.set (source_hdmx->num_records);
this->size_device_record.set (source_hdmx->size_device_record);
this->size_device_record.set (DeviceRecord::get_size (plan->gids_to_retain_sorted.len));
for (unsigned int i = 0; i < source_hdmx->num_records; i++)
{
@ -130,6 +128,11 @@ struct hdmx
return_trace (true);
}
static inline unsigned int get_subsetted_size (hb_subset_plan_t *plan)
{
return min_size + DeviceRecord::get_size (plan->gids_to_retain_sorted.len);
}
inline bool subset (hb_subset_plan_t *plan) const
{
// TODO(grieger)