提交 c61be03d 编写于 作者: B Behdad Esfahbod

[OT] A bit more serialize

上级 abcc5ac1
...@@ -678,6 +678,20 @@ struct GenericArrayOf ...@@ -678,6 +678,20 @@ struct GenericArrayOf
inline unsigned int get_size (void) const inline unsigned int get_size (void) const
{ return len.static_size + len * Type::static_size; } { return len.static_size + len * Type::static_size; }
inline bool serialize (hb_serialize_context_t *c,
const Type *items,
unsigned int items_len)
{
TRACE_SERIALIZE ();
if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false);
len.set (items_len); /* TODO may overflow */
if (unlikely (!c->extend (*this))) return TRACE_RETURN (false);
unsigned int count = items_len;
for (unsigned int i = 0; i < count; i++)
array[i].set (items[i]);
return TRACE_RETURN (true);
}
inline bool sanitize (hb_sanitize_context_t *c) { inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE (); TRACE_SANITIZE ();
if (unlikely (!sanitize_shallow (c))) return TRACE_RETURN (false); if (unlikely (!sanitize_shallow (c))) return TRACE_RETURN (false);
......
...@@ -530,7 +530,7 @@ struct Coverage ...@@ -530,7 +530,7 @@ struct Coverage
unsigned int num_glyphs) unsigned int num_glyphs)
{ {
TRACE_SERIALIZE (); TRACE_SERIALIZE ();
if (unlikely (c->extend_min (*this))) return TRACE_RETURN (false); if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (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])
......
...@@ -75,12 +75,12 @@ struct SingleSubstFormat1 ...@@ -75,12 +75,12 @@ struct SingleSubstFormat1
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
const USHORT *glyphs, const USHORT *glyphs,
unsigned int num_glyphs, unsigned int num_glyphs,
SHORT delta) unsigned int delta)
{ {
TRACE_SERIALIZE (); TRACE_SERIALIZE ();
if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false);
if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false); if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false);
deltaGlyphID.set (delta); deltaGlyphID.set (delta); /* TODO overflow? */
return TRACE_RETURN (true); return TRACE_RETURN (true);
} }
...@@ -136,6 +136,18 @@ struct SingleSubstFormat2 ...@@ -136,6 +136,18 @@ struct SingleSubstFormat2
return TRACE_RETURN (true); return TRACE_RETURN (true);
} }
inline bool serialize (hb_serialize_context_t *c,
const USHORT *glyphs,
const USHORT *substitutes,
unsigned int num_glyphs)
{
TRACE_SERIALIZE ();
if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false);
if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false);
if (unlikely (!substitute.serialize (c, substitutes, num_glyphs))) return TRACE_RETURN (false);
return TRACE_RETURN (true);
}
inline bool sanitize (hb_sanitize_context_t *c) { inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE (); TRACE_SANITIZE ();
return TRACE_RETURN (coverage.sanitize (c, this) && substitute.sanitize (c)); return TRACE_RETURN (coverage.sanitize (c, this) && substitute.sanitize (c));
...@@ -188,6 +200,33 @@ struct SingleSubst ...@@ -188,6 +200,33 @@ struct SingleSubst
} }
} }
inline bool serialize (hb_serialize_context_t *c,
const USHORT *glyphs,
const USHORT *substitutes,
unsigned int num_glyphs)
{
TRACE_SERIALIZE ();
if (unlikely (!c->extend_min (u.format))) return TRACE_RETURN (false);
unsigned int format = 2;
unsigned int delta;
if (num_glyphs) {
format = 1;
/* TODO check for wrap-around */
delta = substitutes[0] - glyphs[0];
for (unsigned int i = 1; i < num_glyphs; i++)
if (delta != substitutes[i] - glyphs[i]) {
format = 2;
break;
}
}
u.format.set (format);
switch (u.format) {
case 1: return TRACE_RETURN (u.format1.serialize (c, glyphs, num_glyphs, delta));
case 2: return TRACE_RETURN (u.format2.serialize (c, glyphs, substitutes, num_glyphs));
default:return TRACE_RETURN (false);
}
}
inline bool sanitize (hb_sanitize_context_t *c) { inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE (); TRACE_SANITIZE ();
if (!u.format.sanitize (c)) return TRACE_RETURN (false); if (!u.format.sanitize (c)) return TRACE_RETURN (false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册