[serialize] Implement for ClassDef
This commit is contained in:
parent
e5309e4fd8
commit
cc65901ca7
|
@ -1058,11 +1058,13 @@ struct Coverage
|
||||||
{
|
{
|
||||||
TRACE_SERIALIZE (this);
|
TRACE_SERIALIZE (this);
|
||||||
if (unlikely (!c->extend_min (*this))) return_trace (false);
|
if (unlikely (!c->extend_min (*this))) return_trace (false);
|
||||||
|
|
||||||
unsigned int num_ranges = 1;
|
unsigned int num_ranges = 1;
|
||||||
for (unsigned int i = 1; i < num_glyphs; i++)
|
for (unsigned int i = 1; i < num_glyphs; i++)
|
||||||
if (glyphs[i - 1] + 1 != glyphs[i])
|
if (glyphs[i - 1] + 1 != glyphs[i])
|
||||||
num_ranges++;
|
num_ranges++;
|
||||||
u.format.set (num_glyphs * 2 < num_ranges * 3 ? 1 : 2);
|
u.format.set (num_glyphs * 2 < num_ranges * 3 ? 1 : 2);
|
||||||
|
|
||||||
switch (u.format)
|
switch (u.format)
|
||||||
{
|
{
|
||||||
case 1: return_trace (u.format1.serialize (c, glyphs, num_glyphs));
|
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,
|
inline bool serialize (hb_serialize_context_t *c,
|
||||||
hb_codepoint_t first_glyph,
|
|
||||||
Supplier<HBUINT16> &glyphs,
|
Supplier<HBUINT16> &glyphs,
|
||||||
Supplier<HBUINT16> &klasses,
|
Supplier<HBUINT16> &klasses,
|
||||||
unsigned int num_glyphs)
|
unsigned int num_glyphs)
|
||||||
|
@ -1316,7 +1317,6 @@ struct ClassDefFormat2
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool serialize (hb_serialize_context_t *c,
|
inline bool serialize (hb_serialize_context_t *c,
|
||||||
hb_codepoint_t first_glyph,
|
|
||||||
Supplier<HBUINT16> &glyphs,
|
Supplier<HBUINT16> &glyphs,
|
||||||
Supplier<HBUINT16> &klasses,
|
Supplier<HBUINT16> &klasses,
|
||||||
unsigned int num_glyphs)
|
unsigned int num_glyphs)
|
||||||
|
@ -1440,6 +1440,35 @@ struct ClassDef
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool serialize (hb_serialize_context_t *c,
|
||||||
|
Supplier<GlyphID> &glyphs,
|
||||||
|
Supplier<HBUINT16> &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<hb_codepoint_t> (glyph_min, glyphs[i]);
|
||||||
|
glyph_max = MAX<hb_codepoint_t> (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
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
||||||
{
|
{
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
|
|
Loading…
Reference in New Issue