From ab7a8f3b7419b604816e12cb93e77c0ba45a57af Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 21 Feb 2018 15:15:22 -0800 Subject: [PATCH] [subset] Begin implementing serialize for hdmx. --- src/hb-ot-hdmx-table.hh | 79 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/src/hb-ot-hdmx-table.hh b/src/hb-ot-hdmx-table.hh index 7117a9779..a506c2940 100644 --- a/src/hb-ot-hdmx-table.hh +++ b/src/hb-ot-hdmx-table.hh @@ -36,13 +36,61 @@ namespace OT { struct DeviceRecord { + struct SubsetView + { + const DeviceRecord *source_device_record; + hb_subset_plan_t *subset_plan; + + inline void init(const DeviceRecord *source_device_record, + hb_subset_plan_t *subset_plan) + { + this->source_device_record = source_device_record; + this->subset_plan = subset_plan; + } + + inline unsigned int len () const + { + return this->subset_plan->gids_to_retain_sorted.len; + } + + inline const HBUINT8& operator [] (unsigned int i) const + { + if (unlikely (i >= len())) return Null(HBUINT8); + hb_codepoint_t gid = this->subset_plan->gids_to_retain_sorted [i]; + return this->source_device_record->widths[gid]; + } + }; + + inline bool serialize (hb_serialize_context_t *c, const SubsetView &subset_view) + { + TRACE_SERIALIZE (this); + + if (unlikely (!c->extend_min ((*this)))) return_trace (false); + this->pixel_size.set (subset_view.source_device_record->pixel_size); + this->max_width.set (subset_view.source_device_record->max_width); + + for (unsigned int i = 0; i < subset_view.len(); i++) + { + HBUINT8 *width = c->extend (this->widths[i]); + if (unlikely (!width)) return_trace (false); + width->set (subset_view[i]); + } + + return_trace (true); + } + HBUINT8 pixel_size; HBUINT8 max_width; HBUINT8 widths[VAR]; + + DEFINE_SIZE_MIN (2); }; + + struct hdmx { + inline unsigned int get_size (void) const { return min_size + num_records * size_device_record; @@ -54,6 +102,33 @@ struct hdmx return StructAtOffset (this, min_size + i * size_device_record); } + inline bool serialize (hb_serialize_context_t *c, const hdmx *source_hdmx, hb_subset_plan_t *plan) + { + TRACE_SERIALIZE (this); + + if (unlikely (!c->extend_min ((*this)))) return_trace (false); + + this->version.set (source_hdmx->version); + this->num_records.set (source_hdmx->num_records); + this->size_device_record.set (source_hdmx->size_device_record); + + for (unsigned int i = 0; i < source_hdmx->num_records; i++) + { + DeviceRecord::SubsetView subset_view; + subset_view.init (&(*source_hdmx)[i], plan); + + c->start_embed ()->serialize (c, subset_view); + } + + return_trace (true); + } + + inline bool subset (hb_subset_plan_t *plan) const + { + // TODO(grieger) + return false; + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -65,10 +140,10 @@ struct hdmx HBINT16 num_records; HBINT32 size_device_record; - DeviceRecord records[VAR]; - DEFINE_SIZE_MIN (8); + private: + DeviceRecord records[VAR]; }; } /* namespace OT */