From f3aca6aa267f7687a0406c7c545aefb5eed300b2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 31 Mar 2019 21:37:14 -0700 Subject: [PATCH] [serialize] Implement linking Untested! --- src/hb-serialize.hh | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index ab07080..451afc3 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -67,7 +67,7 @@ struct hb_serialize_context_t struct link_t { bool wide: 1; - unsigned offset : 31; + unsigned position : 31; objidx_t objidx; }; @@ -220,7 +220,32 @@ struct hb_serialize_context_t void link () { - // XXX + assert (!current.length); + + for (auto obj_it = packed.iter (); obj_it; ++obj_it) + { + const object_t &parent = *obj_it; + + for (auto link_it = parent.links.iter (); link_it; ++link_it) + { + const object_t::link_t &link = *link_it; + const object_t &child = packed[link.objidx]; + unsigned offset = child.head - parent.head; + + if (link.wide) + { + auto &off = * ((BEInt *) (parent.head + offset)); + off = offset; + propagate_error (off == offset); + } + else + { + auto &off = * ((BEInt *) (parent.head + offset)); + off = offset; + propagate_error (off == offset); + } + } + } } unsigned int length () const { return this->head - current.tail ().head; } -- 2.7.4