[gvar] minor

This commit is contained in:
Ebrahim Byagowi 2019-10-05 23:58:52 +03:30
parent 5752863640
commit 21c80d955f
1 changed files with 21 additions and 22 deletions

View File

@ -306,7 +306,7 @@ struct GlyphVarData
uint16_t count = *p++; uint16_t count = *p++;
if (count & POINTS_ARE_WORDS) if (count & POINTS_ARE_WORDS)
{ {
if (!check.in_range (p)) return false; if (unlikely (!check.in_range (p))) return false;
count = ((count & POINT_RUN_COUNT_MASK) << 8) | *p++; count = ((count & POINT_RUN_COUNT_MASK) << 8) | *p++;
} }
points.resize (count); points.resize (count);
@ -315,7 +315,7 @@ struct GlyphVarData
uint16_t i = 0; uint16_t i = 0;
while (i < count) while (i < count)
{ {
if (!check.in_range (p)) return false; if (unlikely (!check.in_range (p))) return false;
uint16_t j; uint16_t j;
uint8_t control = *p++; uint8_t control = *p++;
uint16_t run_count = (control & POINT_RUN_COUNT_MASK) + 1; uint16_t run_count = (control & POINT_RUN_COUNT_MASK) + 1;
@ -323,7 +323,8 @@ struct GlyphVarData
{ {
for (j = 0; j < run_count && i < count; j++, i++) for (j = 0; j < run_count && i < count; j++, i++)
{ {
if (!check.in_range ((const HBUINT16 *)p)) return false; if (unlikely (!check.in_range ((const HBUINT16 *) p)))
return false;
n += *(const HBUINT16 *)p; n += *(const HBUINT16 *)p;
points[i] = n; points[i] = n;
p += HBUINT16::static_size; p += HBUINT16::static_size;
@ -333,7 +334,7 @@ struct GlyphVarData
{ {
for (j = 0; j < run_count && i < count; j++, i++) for (j = 0; j < run_count && i < count; j++, i++)
{ {
if (!check.in_range (p)) return false; if (unlikely (!check.in_range (p))) return false;
n += *p++; n += *p++;
points[i] = n; points[i] = n;
} }
@ -358,7 +359,7 @@ struct GlyphVarData
unsigned int count = deltas.length; unsigned int count = deltas.length;
while (i < count) while (i < count)
{ {
if (!check.in_range (p)) return false; if (unlikely (!check.in_range (p))) return false;
uint8_t control = *p++; uint8_t control = *p++;
unsigned int run_count = (control & DELTA_RUN_COUNT_MASK) + 1; unsigned int run_count = (control & DELTA_RUN_COUNT_MASK) + 1;
unsigned int j; unsigned int j;
@ -368,7 +369,7 @@ struct GlyphVarData
else if (control & DELTAS_ARE_WORDS) else if (control & DELTAS_ARE_WORDS)
for (j = 0; j < run_count && i < count; j++, i++) for (j = 0; j < run_count && i < count; j++, i++)
{ {
if (!check.in_range ((const HBUINT16 *)p)) if (unlikely (!check.in_range ((const HBUINT16 *) p)))
return false; return false;
deltas[i] = *(const HBINT16 *) p; deltas[i] = *(const HBINT16 *) p;
p += HBUINT16::static_size; p += HBUINT16::static_size;
@ -376,7 +377,7 @@ struct GlyphVarData
else else
for (j = 0; j < run_count && i < count; j++, i++) for (j = 0; j < run_count && i < count; j++, i++)
{ {
if (!check.in_range (p)) if (unlikely (!check.in_range (p)))
return false; return false;
deltas[i] = *(const HBINT8 *) p++; deltas[i] = *(const HBINT8 *) p++;
} }
@ -404,8 +405,8 @@ struct gvar
return_trace (c->check_struct (this) && (version.major == 1) && return_trace (c->check_struct (this) && (version.major == 1) &&
(glyphCount == c->get_num_glyphs ()) && (glyphCount == c->get_num_glyphs ()) &&
c->check_array (&(this+sharedTuples), axisCount * sharedTupleCount) && c->check_array (&(this+sharedTuples), axisCount * sharedTupleCount) &&
(is_long_offset ()? (is_long_offset () ?
c->check_array (get_long_offset_array (), glyphCount+1): c->check_array (get_long_offset_array (), glyphCount+1) :
c->check_array (get_short_offset_array (), glyphCount+1)) && c->check_array (get_short_offset_array (), glyphCount+1)) &&
c->check_array (((const HBUINT8*)&(this+dataZ)) + get_offset (0), c->check_array (((const HBUINT8*)&(this+dataZ)) + get_offset (0),
get_offset (glyphCount) - get_offset (0))); get_offset (glyphCount) - get_offset (0)));
@ -439,9 +440,9 @@ struct gvar
} }
bool long_offset = subset_data_size & ~0xFFFFu; bool long_offset = subset_data_size & ~0xFFFFu;
out->flags = long_offset? 1: 0; out->flags = long_offset ? 1 : 0;
HBUINT8 *subset_offsets = c->serializer->allocate_size<HBUINT8> ((long_offset? 4: 2) * (num_glyphs+1)); HBUINT8 *subset_offsets = c->serializer->allocate_size<HBUINT8> ((long_offset ? 4 : 2) * (num_glyphs + 1));
if (!subset_offsets) return_trace (false); if (!subset_offsets) return_trace (false);
/* shared tuples */ /* shared tuples */
@ -523,8 +524,6 @@ struct gvar
{ {
void init (hb_face_t *face) void init (hb_face_t *face)
{ {
memset (this, 0, sizeof (accelerator_t));
gvar_table = hb_sanitize_context_t ().reference_table<gvar> (face); gvar_table = hb_sanitize_context_t ().reference_table<gvar> (face);
hb_blob_ptr_t<fvar> fvar_table = hb_sanitize_context_t ().reference_table<fvar> (face); hb_blob_ptr_t<fvar> fvar_table = hb_sanitize_context_t ().reference_table<fvar> (face);
unsigned int axis_count = fvar_table->get_axis_count (); unsigned int axis_count = fvar_table->get_axis_count ();
@ -585,8 +584,8 @@ struct gvar
if (unlikely (coord_count != gvar_table->axisCount)) return false; if (unlikely (coord_count != gvar_table->axisCount)) return false;
const GlyphVarData *var_data = gvar_table->get_glyph_var_data (glyph); const GlyphVarData *var_data = gvar_table->get_glyph_var_data (glyph);
if (var_data == &Null(GlyphVarData)) return true; if (var_data == &Null (GlyphVarData)) return true;
hb_vector_t <unsigned int> shared_indices; hb_vector_t<unsigned int> shared_indices;
GlyphVarData::tuple_iterator_t iterator; GlyphVarData::tuple_iterator_t iterator;
if (!GlyphVarData::get_tuple_iterator (var_data, if (!GlyphVarData::get_tuple_iterator (var_data,
gvar_table->get_glyph_var_data_length (glyph), gvar_table->get_glyph_var_data_length (glyph),
@ -614,19 +613,19 @@ struct gvar
return false; return false;
range_checker_t checker (p, 0, length); range_checker_t checker (p, 0, length);
hb_vector_t <unsigned int> private_indices; hb_vector_t<unsigned int> private_indices;
if (iterator.current_tuple->has_private_points () && if (iterator.current_tuple->has_private_points () &&
!GlyphVarData::unpack_points (p, private_indices, checker)) !GlyphVarData::unpack_points (p, private_indices, checker))
return false; return false;
const hb_array_t<unsigned int> &indices = private_indices.length ? private_indices : shared_indices; const hb_array_t<unsigned int> &indices = private_indices.length ? private_indices : shared_indices;
bool apply_to_all = (indices.length == 0); bool apply_to_all = (indices.length == 0);
unsigned int num_deltas = apply_to_all ? points.length : indices.length; unsigned int num_deltas = apply_to_all ? points.length : indices.length;
hb_vector_t <int> x_deltas; hb_vector_t<int> x_deltas;
x_deltas.resize (num_deltas); x_deltas.resize (num_deltas);
if (!GlyphVarData::unpack_deltas (p, x_deltas, checker)) if (!GlyphVarData::unpack_deltas (p, x_deltas, checker))
return false; return false;
hb_vector_t <int> y_deltas; hb_vector_t<int> y_deltas;
y_deltas.resize (num_deltas); y_deltas.resize (num_deltas);
if (!GlyphVarData::unpack_deltas (p, y_deltas, checker)) if (!GlyphVarData::unpack_deltas (p, y_deltas, checker))
return false; return false;
@ -635,7 +634,7 @@ struct gvar
deltas[i].init (); deltas[i].init ();
for (unsigned int i = 0; i < num_deltas; i++) for (unsigned int i = 0; i < num_deltas; i++)
{ {
unsigned int pt_index = apply_to_all? i: indices[i]; unsigned int pt_index = apply_to_all ? i : indices[i];
deltas[pt_index].flag = 1; /* this point is referenced, i.e., explicit deltas specified */ deltas[pt_index].flag = 1; /* this point is referenced, i.e., explicit deltas specified */
deltas[pt_index].x += x_deltas[i] * scalar; deltas[pt_index].x += x_deltas[i] * scalar;
deltas[pt_index].y += y_deltas[i] * scalar; deltas[pt_index].y += y_deltas[i] * scalar;
@ -709,8 +708,8 @@ no_more_gaps:
{ return gvar_table->get_glyph_var_data (glyph); } { return gvar_table->get_glyph_var_data (glyph); }
private: private:
hb_blob_ptr_t<gvar> gvar_table; hb_blob_ptr_t<gvar> gvar_table;
hb_vector_t<F2DOT14> shared_tuples; hb_vector_t<F2DOT14> shared_tuples;
}; };
protected: protected: