void fini () {}
- unsigned int get_count () const { return (subrs == nullptr)? 0: subrs->count; }
- unsigned int get_bias () const { return bias; }
+ unsigned int get_count () const { return (subrs == nullptr) ? 0 : subrs->count; }
+ unsigned int get_bias () const { return bias; }
byte_str_t operator [] (unsigned int index) const
{
return value;
case END:
- value = (double)(neg? -int_part: int_part);
+ value = (double) (neg ? -int_part : int_part);
if (frac_count > 0)
{
- double frac = (frac_part / pow (10.0, (double)frac_count));
+ double frac = (frac_part / pow (10.0, (double) frac_count));
if (neg) frac = -frac;
value += frac;
}
if (value == 0.0)
return value;
if (exp_neg)
- return neg? -DBL_MIN: DBL_MIN;
+ return neg ? -DBL_MIN : DBL_MIN;
else
- return neg? -DBL_MAX: DBL_MAX;
+ return neg ? -DBL_MAX : DBL_MAX;
}
if (exp_part != 0)
{
if (exp_neg)
- value /= pow (10.0, (double)exp_part);
+ value /= pow (10.0, (double) exp_part);
else
- value *= pow (10.0, (double)exp_part);
+ value *= pow (10.0, (double) exp_part);
}
return value;
template <typename COUNT>
struct CFFIndex
{
- bool sanitize (hb_sanitize_context_t *c) const
- {
- TRACE_SANITIZE (this);
- return_trace (likely ((count.sanitize (c) && count == 0) || /* empty INDEX */
- (c->check_struct (this) && offSize >= 1 && offSize <= 4 &&
- c->check_array (offsets, offSize, count + 1) &&
- c->check_array ((const HBUINT8*)data_base (), 1, max_offset () - 1))));
- }
-
static unsigned int calculate_offset_array_size (unsigned int offSize, unsigned int count)
{ return offSize * (count + 1); }
unsigned int offset_array_size () const
{ return calculate_offset_array_size (offSize, count); }
- static unsigned int calculate_serialized_size (unsigned int offSize_, unsigned int count, unsigned int dataSize)
+ static unsigned int calculate_serialized_size (unsigned int offSize_, unsigned int count,
+ unsigned int dataSize)
{
if (count == 0)
return COUNT::static_size;
unsigned int length_at (unsigned int index) const
{
- if (likely ((offset_at (index + 1) >= offset_at (index)) &&
- (offset_at (index + 1) <= offset_at (count))))
- return offset_at (index + 1) - offset_at (index);
- else
- return 0;
+ if (likely ((offset_at (index + 1) >= offset_at (index)) &&
+ (offset_at (index + 1) <= offset_at (count))))
+ return offset_at (index + 1) - offset_at (index);
+ else
+ return 0;
}
const unsigned char *data_base () const
if (likely (index < count))
return byte_str_t (data_base () + offset_at (index) - 1, length_at (index));
else
- return Null(byte_str_t);
+ return Null (byte_str_t);
}
unsigned int get_size () const
{
- if (this != &Null(CFFIndex))
+ if (this != &Null (CFFIndex))
{
if (count > 0)
return min_size + offset_array_size () + (offset_at (count) - 1);
return 0;
}
+ bool sanitize (hb_sanitize_context_t *c) const
+ {
+ TRACE_SANITIZE (this);
+ return_trace (likely ((count.sanitize (c) && count == 0) || /* empty INDEX */
+ (c->check_struct (this) && offSize >= 1 && offSize <= 4 &&
+ c->check_array (offsets, offSize, count + 1) &&
+ c->check_array ((const HBUINT8*) data_base (), 1, max_offset () - 1))));
+ }
+
protected:
unsigned int max_offset () const
{
}
public:
- COUNT count; /* Number of object data. Note there are (count+1) offsets */
- HBUINT8 offSize; /* The byte size of each offset in the offsets array. */
- HBUINT8 offsets[VAR]; /* The array of (count + 1) offsets into objects array (1-base). */
- /* HBUINT8 data[VAR]; Object data */
+ COUNT count; /* Number of object data. Note there are (count+1) offsets */
+ HBUINT8 offSize; /* The byte size of each offset in the offsets array. */
+ HBUINT8 offsets[VAR]; /* The array of (count + 1) offsets into objects array (1-base). */
+ /* HBUINT8 data[VAR]; Object data */
public:
DEFINE_SIZE_ARRAY (COUNT::static_size + HBUINT8::static_size, offsets);
};
/* serialize data */
for (unsigned int i = 0; i < dataArrayLen; i++)
{
- TYPE *dest = c->start_embed<TYPE> ();
+ TYPE *dest = c->start_embed<TYPE> ();
if (unlikely (dest == nullptr ||
!dest->serialize (c, dataArray[i], param1, param2)))
return_trace (false);
const PARAM ¶m)
{
/* determine offset size */
- unsigned int totalDataSize = 0;
+ unsigned int totalDataSize = 0;
for (unsigned int i = 0; i < dataArrayLen; i++)
{
unsigned int dataSize = TYPE::calculate_serialized_size (dataArray[i], param);
{
TRACE_SERIALIZE (this);
for (unsigned int i = 0; i < dictval.get_count (); i++)
- {
if (unlikely (!opszr.serialize (c, dictval[i], param)))
return_trace (false);
- }
+
return_trace (true);
}
{ return serialize_int_op<HBUINT16, 0, 0x7FFF> (c, op, value, OpCode_shortint); }
static bool serialize_offset4_op (hb_serialize_context_t *c, op_code_t op, int value)
- {
- return serialize_uint4_op (c, op, value);
- }
+ { return serialize_uint4_op (c, op, value); }
static bool serialize_offset2_op (hb_serialize_context_t *c, op_code_t op, int value)
- {
- return serialize_uint2_op (c, op, value);
- }
+ { return serialize_uint2_op (c, op, value); }
};
struct TopDict : Dict {};
return_trace (false);
/* serialize font dict offsets */
- unsigned int offset = 1;
+ unsigned int offset = 1;
unsigned int fid = 0;
for (; fid < fontDicts.length; fid++)
{
}
hb_codepoint_t get_fd (hb_codepoint_t glyph) const
- {
- return (hb_codepoint_t)fds[glyph];
- }
+ { return (hb_codepoint_t) fds[glyph]; }
unsigned int get_size (unsigned int num_glyphs) const
{ return HBUINT8::static_size * num_glyphs; }
};
template <typename GID_TYPE, typename FD_TYPE>
-struct FDSelect3_4_Range {
+struct FDSelect3_4_Range
+{
bool sanitize (hb_sanitize_context_t *c, const void * /*nullptr*/, unsigned int fdcount) const
{
TRACE_SANITIZE (this);
GID_TYPE first;
FD_TYPE fd;
-
+ public:
DEFINE_SIZE_STATIC (GID_TYPE::static_size + FD_TYPE::static_size);
};
template <typename GID_TYPE, typename FD_TYPE>
-struct FDSelect3_4 {
+struct FDSelect3_4
+{
unsigned int get_size () const
{ return GID_TYPE::static_size * 2 + ranges.get_size (); }
return_trace (false);
for (unsigned int i = 1; i < nRanges (); i++)
- {
if (unlikely (ranges[i - 1].first >= ranges[i].first))
- return_trace (false);
- }
+ return_trace (false);
if (unlikely (!sentinel().sanitize (c) || (sentinel() != c->get_num_glyphs ())))
return_trace (false);
typedef FDSelect3_4<HBUINT16, HBUINT8> FDSelect3;
typedef FDSelect3_4_Range<HBUINT16, HBUINT8> FDSelect3_Range;
-struct FDSelect {
- bool sanitize (hb_sanitize_context_t *c, unsigned int fdcount) const
- {
- TRACE_SANITIZE (this);
-
- return_trace (likely (c->check_struct (this) && (format == 0 || format == 3) &&
- ((format == 0)?
- u.format0.sanitize (c, fdcount):
- u.format3.sanitize (c, fdcount))));
- }
-
+struct FDSelect
+{
bool serialize (hb_serialize_context_t *c, const FDSelect &src, unsigned int num_glyphs)
{
TRACE_SERIALIZE (this);
unsigned int get_size (unsigned int num_glyphs) const
{
- unsigned int size = format.static_size;
- if (format == 0)
- size += u.format0.get_size (num_glyphs);
- else
- size += u.format3.get_size ();
- return size;
+ switch (format)
+ {
+ case 0: return format.static_size + u.format0.get_size (num_glyphs);
+ case 3: return format.static_size + u.format3.get_size ();
+ default:return 0;
+ }
}
hb_codepoint_t get_fd (hb_codepoint_t glyph) const
{
- if (this == &Null(FDSelect))
+ if (this == &Null (FDSelect))
return 0;
- if (format == 0)
- return u.format0.get_fd (glyph);
- else
- return u.format3.get_fd (glyph);
+ switch (format)
+ {
+ case 0: return u.format0.get_fd (glyph);
+ case 3: return u.format3.get_fd (glyph);
+ default:return 0;
+ }
}
- HBUINT8 format;
+ bool sanitize (hb_sanitize_context_t *c, unsigned int fdcount) const
+ {
+ TRACE_SANITIZE (this);
+ if (unlikely (!c->check_struct (this)))
+ return_trace (false);
+
+ switch (format)
+ {
+ case 0: return_trace (u.format0.sanitize (c, fdcount));
+ case 3: return_trace (u.format3.sanitize (c, fdcount));
+ default:return_trace (false);
+ }
+ }
+
+ HBUINT8 format;
union {
- FDSelect0 format0;
- FDSelect3 format3;
+ FDSelect0 format0;
+ FDSelect3 format3;
} u;
-
+ public:
DEFINE_SIZE_MIN (1);
};
DEFINE_SIZE_ARRAY_SIZED (1, supps);
};
-struct Encoding {
- bool sanitize (hb_sanitize_context_t *c) const
- {
- TRACE_SANITIZE (this);
-
- if (unlikely (!c->check_struct (this)))
- return_trace (false);
- unsigned int fmt = format & 0x7F;
- if (unlikely (fmt > 1))
- return_trace (false);
- if (unlikely (!((fmt == 0)? u.format0.sanitize (c): u.format1.sanitize (c))))
- return_trace (false);
- return_trace (((format & 0x80) == 0) || suppEncData ().sanitize (c));
- }
-
+struct Encoding
+{
/* serialize a fullset Encoding */
bool serialize (hb_serialize_context_t *c, const Encoding &src)
{
TRACE_SERIALIZE (this);
Encoding *dest = c->extend_min (*this);
if (unlikely (dest == nullptr)) return_trace (false);
- dest->format = format | ((supp_codes.length > 0)? 0x80: 0);
- if (format == 0)
+ dest->format = format | ((supp_codes.length > 0) ? 0x80 : 0);
+ switch (format) {
+ case 0:
{
Encoding0 *fmt0 = c->allocate_size<Encoding0> (Encoding0::min_size + HBUINT8::static_size * enc_count);
- if (unlikely (fmt0 == nullptr)) return_trace (false);
+ if (unlikely (fmt0 == nullptr)) return_trace (false);
fmt0->nCodes () = enc_count;
unsigned int glyph = 0;
for (unsigned int i = 0; i < code_ranges.length; i++)
return_trace (false);
}
}
- else
+ break;
+
+ case 1:
{
Encoding1 *fmt1 = c->allocate_size<Encoding1> (Encoding1::min_size + Encoding1_Range::static_size * code_ranges.length);
if (unlikely (fmt1 == nullptr)) return_trace (false);
fmt1->ranges[i].nLeft = code_ranges[i].glyph;
}
}
- if (supp_codes.length > 0)
+ break;
+
+ }
+
+ if (supp_codes.length)
{
CFF1SuppEncData *suppData = c->allocate_size<CFF1SuppEncData> (CFF1SuppEncData::min_size + SuppEncoding::static_size * supp_codes.length);
if (unlikely (suppData == nullptr)) return_trace (false);
suppData->supps[i].glyph = supp_codes[i].glyph; /* actually SID */
}
}
+
return_trace (true);
}
unsigned int enc_count,
unsigned int supp_count)
{
- unsigned int size = min_size;
- if (format == 0)
- size += Encoding0::min_size + HBUINT8::static_size * enc_count;
- else
- size += Encoding1::min_size + Encoding1_Range::static_size * enc_count;
+ unsigned int size = min_size;
+ switch (format)
+ {
+ case 0: size += Encoding0::min_size + HBUINT8::static_size * enc_count; break;
+ case 1: size += Encoding1::min_size + Encoding1_Range::static_size * enc_count; break;
+ default:return 0;
+ }
if (supp_count > 0)
size += CFF1SuppEncData::min_size + SuppEncoding::static_size * supp_count;
return size;
unsigned int get_size () const
{
unsigned int size = min_size;
- if (table_format () == 0)
- size += u.format0.get_size ();
- else
- size += u.format1.get_size ();
+ switch (table_format ())
+ {
+ case 0: size += u.format0.get_size (); break;
+ case 1: size += u.format1.get_size (); break;
+ }
if (has_supplement ())
size += suppEncData ().get_size ();
return size;
hb_codepoint_t get_code (hb_codepoint_t glyph) const
{
- if (table_format () == 0)
- return u.format0.get_code (glyph);
- else
- return u.format1.get_code (glyph);
+ switch (table_format ())
+ {
+ case 0: return u.format0.get_code (glyph);
+ case 1: return u.format1.get_code (glyph);
+ default:return 0;
+ }
}
- uint8_t table_format () const { return (format & 0x7F); }
- bool has_supplement () const { return (format & 0x80) != 0; }
+ uint8_t table_format () const { return format & 0x7F; }
+ bool has_supplement () const { return format & 0x80; }
void get_supplement_codes (hb_codepoint_t sid, hb_vector_t<hb_codepoint_t> &codes) const
{
suppEncData().get_codes (sid, codes);
}
+ bool sanitize (hb_sanitize_context_t *c) const
+ {
+ TRACE_SANITIZE (this);
+ if (unlikely (!c->check_struct (this)))
+ return_trace (false);
+
+ switch (table_format ())
+ {
+ case 0: if (unlikely (!u.format0.sanitize (c))) { return_trace (false); } break;
+ case 1: if (unlikely (!u.format1.sanitize (c))) { return_trace (false); } break;
+ default:return_trace (false);
+ }
+ return_trace (likely (!has_supplement () || suppEncData ().sanitize (c)));
+ }
+
protected:
const CFF1SuppEncData &suppEncData () const
{
- if ((format & 0x7F) == 0)
- return StructAfter<CFF1SuppEncData> (u.format0.codes[u.format0.nCodes ()-1]);
- else
- return StructAfter<CFF1SuppEncData> (u.format1.ranges[u.format1.nRanges ()-1]);
+ switch (table_format ())
+ {
+ case 0: return StructAfter<CFF1SuppEncData> (u.format0.codes[u.format0.nCodes ()-1]);
+ case 1: return StructAfter<CFF1SuppEncData> (u.format1.ranges[u.format1.nRanges ()-1]);
+ default:return Null (CFF1SuppEncData);
+ }
}
public:
- HBUINT8 format;
-
+ HBUINT8 format;
union {
- Encoding0 format0;
- Encoding1 format1;
+ Encoding0 format0;
+ Encoding1 format1;
} u;
/* CFF1SuppEncData suppEncData; */
typedef Charset_Range<HBUINT8> Charset1_Range;
typedef Charset_Range<HBUINT16> Charset2_Range;
-struct Charset {
- bool sanitize (hb_sanitize_context_t *c) const
- {
- TRACE_SANITIZE (this);
-
- if (unlikely (!c->check_struct (this)))
- return_trace (false);
- if (format == 0)
- return_trace (u.format0.sanitize (c, c->get_num_glyphs ()));
- else if (format == 1)
- return_trace (u.format1.sanitize (c, c->get_num_glyphs ()));
- else if (likely (format == 2))
- return_trace (u.format2.sanitize (c, c->get_num_glyphs ()));
- else
- return_trace (false);
- }
-
+struct Charset
+{
/* serialize a fullset Charset */
bool serialize (hb_serialize_context_t *c, const Charset &src, unsigned int num_glyphs)
{
Charset *dest = c->extend_min (*this);
if (unlikely (dest == nullptr)) return_trace (false);
dest->format = format;
- if (format == 0)
+ switch (format)
+ {
+ case 0:
{
Charset0 *fmt0 = c->allocate_size<Charset0> (Charset0::min_size + HBUINT16::static_size * (num_glyphs - 1));
- if (unlikely (fmt0 == nullptr)) return_trace (false);
+ if (unlikely (fmt0 == nullptr)) return_trace (false);
unsigned int glyph = 0;
for (unsigned int i = 0; i < sid_ranges.length; i++)
{
fmt0->sids[glyph++] = sid++;
}
}
- else if (format == 1)
+ break;
+
+ case 1:
{
Charset1 *fmt1 = c->allocate_size<Charset1> (Charset1::min_size + Charset1_Range::static_size * sid_ranges.length);
if (unlikely (fmt1 == nullptr)) return_trace (false);
fmt1->ranges[i].nLeft = sid_ranges[i].glyph;
}
}
- else /* format 2 */
+ break;
+
+ case 2:
{
Charset2 *fmt2 = c->allocate_size<Charset2> (Charset2::min_size + Charset2_Range::static_size * sid_ranges.length);
if (unlikely (fmt2 == nullptr)) return_trace (false);
fmt2->ranges[i].nLeft = sid_ranges[i].glyph;
}
}
+ break;
+
+ }
return_trace (true);
}
/* parallel to above: calculate the size of a subset Charset */
- static unsigned int calculate_serialized_size (
- uint8_t format,
- unsigned int count)
+ static unsigned int calculate_serialized_size (uint8_t format,
+ unsigned int count)
{
- unsigned int size = min_size;
- if (format == 0)
- size += Charset0::min_size + HBUINT16::static_size * (count - 1);
- else if (format == 1)
- size += Charset1::min_size + Charset1_Range::static_size * count;
- else
- size += Charset2::min_size + Charset2_Range::static_size * count;
-
- return size;
+ switch (format)
+ {
+ case 0: return min_size + Charset0::min_size + HBUINT16::static_size * (count - 1);
+ case 1: return min_size + Charset1::min_size + Charset1_Range::static_size * count;
+ case 2: return min_size + Charset2::min_size + Charset2_Range::static_size * count;
+ default:return 0;
+ }
}
unsigned int get_size (unsigned int num_glyphs) const
{
- unsigned int size = min_size;
- if (format == 0)
- size += u.format0.get_size (num_glyphs);
- else if (format == 1)
- size += u.format1.get_size (num_glyphs);
- else
- size += u.format2.get_size (num_glyphs);
- return size;
+ switch (format)
+ {
+ case 0: return min_size + u.format0.get_size (num_glyphs);
+ case 1: return min_size + u.format1.get_size (num_glyphs);
+ case 2: return min_size + u.format2.get_size (num_glyphs);
+ default:return 0;
+ }
}
hb_codepoint_t get_sid (hb_codepoint_t glyph) const
{
- if (format == 0)
- return u.format0.get_sid (glyph);
- else if (format == 1)
- return u.format1.get_sid (glyph);
- else
- return u.format2.get_sid (glyph);
+ switch (format)
+ {
+ case 0: return u.format0.get_sid (glyph);
+ case 1: return u.format1.get_sid (glyph);
+ case 2: return u.format2.get_sid (glyph);
+ default:return 0;
+ }
}
hb_codepoint_t get_glyph (hb_codepoint_t sid, unsigned int num_glyphs) const
{
- if (format == 0)
- return u.format0.get_glyph (sid, num_glyphs);
- else if (format == 1)
- return u.format1.get_glyph (sid, num_glyphs);
- else
- return u.format2.get_glyph (sid, num_glyphs);
+ switch (format)
+ {
+ case 0: return u.format0.get_glyph (sid, num_glyphs);
+ case 1: return u.format1.get_glyph (sid, num_glyphs);
+ case 2: return u.format2.get_glyph (sid, num_glyphs);
+ default:return 0;
+ }
+ }
+
+ bool sanitize (hb_sanitize_context_t *c) const
+ {
+ TRACE_SANITIZE (this);
+ if (unlikely (!c->check_struct (this)))
+ return_trace (false);
+
+ switch (format)
+ {
+ case 0: return_trace (u.format0.sanitize (c, c->get_num_glyphs ()));
+ case 1: return_trace (u.format1.sanitize (c, c->get_num_glyphs ()));
+ case 2: return_trace (u.format2.sanitize (c, c->get_num_glyphs ()));
+ default:return_trace (false);
+ }
}
HBUINT8 format;
struct CFF2FDSelect
{
- bool sanitize (hb_sanitize_context_t *c, unsigned int fdcount) const
- {
- TRACE_SANITIZE (this);
-
- return_trace (likely (c->check_struct (this) && (format == 0 || format == 3 || format == 4) &&
- ((format == 0)?
- u.format0.sanitize (c, fdcount):
- ((format == 3)?
- u.format3.sanitize (c, fdcount):
- u.format4.sanitize (c, fdcount)))));
- }
-
bool serialize (hb_serialize_context_t *c, const CFF2FDSelect &src, unsigned int num_glyphs)
{
TRACE_SERIALIZE (this);
unsigned int get_size (unsigned int num_glyphs) const
{
- unsigned int size = format.static_size;
- if (format == 0)
- size += u.format0.get_size (num_glyphs);
- else if (format == 3)
- size += u.format3.get_size ();
- else
- size += u.format4.get_size ();
- return size;
+ switch (format)
+ {
+ case 0: return format.static_size + u.format0.get_size (num_glyphs);
+ case 3: return format.static_size + u.format3.get_size ();
+ case 4: return format.static_size + u.format4.get_size ();
+ default:return 0;
+ }
}
hb_codepoint_t get_fd (hb_codepoint_t glyph) const
{
- if (this == &Null(CFF2FDSelect))
+ if (this == &Null (CFF2FDSelect))
return 0;
- if (format == 0)
- return u.format0.get_fd (glyph);
- else if (format == 3)
- return u.format3.get_fd (glyph);
- else
- return u.format4.get_fd (glyph);
+
+ switch (format)
+ {
+ case 0: return u.format0.get_fd (glyph);
+ case 3: return u.format3.get_fd (glyph);
+ case 4: return u.format4.get_fd (glyph);
+ default:return 0;
+ }
}
- HBUINT8 format;
+ bool sanitize (hb_sanitize_context_t *c, unsigned int fdcount) const
+ {
+ TRACE_SANITIZE (this);
+ if (unlikely (!c->check_struct (this)))
+ return_trace (false);
+
+ switch (format)
+ {
+ case 0: return_trace (u.format0.sanitize (c, fdcount));
+ case 3: return_trace (u.format3.sanitize (c, fdcount));
+ case 4: return_trace (u.format4.sanitize (c, fdcount));
+ default:return_trace (false);
+ }
+ }
+
+ HBUINT8 format;
union {
- FDSelect0 format0;
- FDSelect3 format3;
- FDSelect4 format4;
+ FDSelect0 format0;
+ FDSelect3 format3;
+ FDSelect4 format4;
} u;
-
+ public:
DEFINE_SIZE_MIN (2);
};
bool result;
cff_private_dict_op_serializer_t privSzr (plan.desubroutinize, plan.drop_hints);
/* N.B. local subrs immediately follows its corresponding private dict. i.e., subr offset == private dict size */
- unsigned int subroffset = (plan.offsets.localSubrsInfos[i].size > 0)? priv_size: 0;
+ unsigned int subroffset = (plan.offsets.localSubrsInfos[i].size > 0) ? priv_size : 0;
result = pd->serialize (&c, acc.privateDicts[i], privSzr, subroffset);
if (unlikely (!result))
{
bool result;
cff_private_dict_op_serializer_t privSzr (plan.desubroutinize, plan.drop_hints);
/* N.B. local subrs immediately follows its corresponding private dict. i.e., subr offset == private dict size */
- unsigned int subroffset = (plan.offsets.localSubrsInfos[i].size > 0)? priv_size: 0;
+ unsigned int subroffset = (plan.offsets.localSubrsInfos[i].size > 0) ? priv_size : 0;
result = pd->serialize (&c, acc.privateDicts[i], privSzr, subroffset);
if (unlikely (!result))
{