From: Behdad Esfahbod Date: Thu, 13 Dec 2018 21:01:45 +0000 (-0500) Subject: [serialize] Implement for ClassDef X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cc65901ca7185df926570d5067ace763a2cc759e;p=platform%2Fupstream%2FlibHarfBuzzSharp.git [serialize] Implement for ClassDef --- diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index e533aac..d3f75af 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -1058,11 +1058,13 @@ struct Coverage { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); + unsigned int num_ranges = 1; for (unsigned int i = 1; i < num_glyphs; i++) if (glyphs[i - 1] + 1 != glyphs[i]) num_ranges++; u.format.set (num_glyphs * 2 < num_ranges * 3 ? 1 : 2); + switch (u.format) { case 1: return_trace (u.format1.serialize (c, glyphs, num_glyphs)); @@ -1199,7 +1201,6 @@ struct ClassDefFormat1 } inline bool serialize (hb_serialize_context_t *c, - hb_codepoint_t first_glyph, Supplier &glyphs, Supplier &klasses, unsigned int num_glyphs) @@ -1316,7 +1317,6 @@ struct ClassDefFormat2 } inline bool serialize (hb_serialize_context_t *c, - hb_codepoint_t first_glyph, Supplier &glyphs, Supplier &klasses, unsigned int num_glyphs) @@ -1440,6 +1440,35 @@ struct ClassDef } } + inline bool serialize (hb_serialize_context_t *c, + Supplier &glyphs, + Supplier &klasses, + unsigned int num_glyphs) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return_trace (false); + + hb_codepoint_t glyph_min = (hb_codepoint_t) -1, glyph_max = 0; + for (unsigned int i = 0; i < num_glyphs; i++) + { + glyph_min = MIN (glyph_min, glyphs[i]); + glyph_max = MAX (glyph_max, glyphs[i]); + } + unsigned int num_ranges = 1; + for (unsigned int i = 1; i < num_glyphs; i++) + if (glyphs[i - 1] + 1 != glyphs[i] || + klasses[i - 1] != klasses[i]) + num_ranges++; + u.format.set (1 + (glyph_max - glyph_min + 1) < num_ranges * 3 ? 1 : 2); + + switch (u.format) + { + case 1: return_trace (u.format1.serialize (c, glyphs, klasses, num_glyphs)); + case 2: return_trace (u.format2.serialize (c, glyphs, klasses, num_glyphs)); + default:return_trace (false); + } + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this);