From 8237809f065f41653a12c95885e3b76409c42f36 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 7 Jan 2019 22:00:45 -0500 Subject: [PATCH] [serialize] Make SortedArrayOf:;serialize() take sorted-iterator --- src/hb-open-type.hh | 17 +++++++++++++++++ src/hb-ot-cmap-table.hh | 18 +++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 5f06b96..70c1654 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -815,6 +815,23 @@ struct SortedArrayOf : ArrayOf hb_array_t sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */) { return as_array ().sub_array (start_offset, count);} + bool serialize (hb_serialize_context_t *c, unsigned int items_len) + { + TRACE_SERIALIZE (this); + bool ret = ArrayOf::serialize (c, items_len); + return_trace (ret); + } + template + hb_enable_if_t (hb_is_sorted_iterator (Iterator, const Type), + bool) serialize (hb_serialize_context_t *c, + Iterator items) + { + TRACE_SERIALIZE (this); + bool ret = ArrayOf::serialize (c, items); + return_trace (ret); + } + + template Type &bsearch (const T &x, Type ¬_found = Crap (Type)) { return *as_array ().bsearch (x, ¬_found); } diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 802231a..0882dc8 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -83,7 +83,7 @@ struct CmapSubtableFormat4 bool serialize (hb_serialize_context_t *c, const hb_subset_plan_t *plan, - const hb_vector_t &segments) + const hb_sorted_vector_t &segments) { TRACE_SERIALIZE (this); @@ -154,7 +154,7 @@ struct CmapSubtableFormat4 return_trace (true); } - static size_t get_sub_table_size (const hb_vector_t &segments) + static size_t get_sub_table_size (const hb_sorted_vector_t &segments) { size_t segment_size = 0; for (unsigned int i = 0; i < segments.length; i++) @@ -177,7 +177,7 @@ struct CmapSubtableFormat4 } static bool create_sub_table_plan (const hb_subset_plan_t *plan, - hb_vector_t *segments) + hb_sorted_vector_t *segments) { segment_plan *segment = nullptr; hb_codepoint_t last_gid = 0; @@ -491,7 +491,7 @@ struct CmapSubtableLongSegmented } bool serialize (hb_serialize_context_t *c, - const hb_vector_t &group_data) + const hb_sorted_vector_t &group_data) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); @@ -519,7 +519,7 @@ struct CmapSubtableFormat12 : CmapSubtableLongSegmented bool serialize (hb_serialize_context_t *c, - const hb_vector_t &groups) + const hb_sorted_vector_t &groups) { if (unlikely (!c->extend_min (*this))) return false; @@ -530,13 +530,13 @@ struct CmapSubtableFormat12 : CmapSubtableLongSegmented return CmapSubtableLongSegmented::serialize (c, groups); } - static size_t get_sub_table_size (const hb_vector_t &groups) + static size_t get_sub_table_size (const hb_sorted_vector_t &groups) { return 16 + 12 * groups.length; } static bool create_sub_table_plan (const hb_subset_plan_t *plan, - hb_vector_t *groups) + hb_sorted_vector_t *groups) { CmapSubtableLongGroup *group = nullptr; @@ -853,8 +853,8 @@ struct cmap + CmapSubtableFormat12::get_sub_table_size (this->format12_groups); } - hb_vector_t format4_segments; - hb_vector_t format12_groups; + hb_sorted_vector_t format4_segments; + hb_sorted_vector_t format12_groups; }; bool _create_plan (const hb_subset_plan_t *plan, -- 2.7.4