calculate VF advance widths from gvar & glyf

This commit is contained in:
Michiharu Ariza 2019-03-01 15:14:22 -08:00
parent d0b6d539f6
commit 40dfca7213
3 changed files with 543 additions and 43 deletions

View File

@ -22,6 +22,7 @@
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Google Author(s): Behdad Esfahbod
* Adobe Author(s): Michiharu Ariza
*/
#ifndef HB_OT_GLYF_TABLE_HH
@ -281,6 +282,156 @@ struct glyf
FLAG_RESERVED2 = 0x80
};
enum phantom_point_index_t {
PHANTOM_LEFT = 0,
PHANTOM_RIGHT = 1,
PHANTOM_TOP = 2,
PHANTOM_BOTTOM = 3,
PHANTOM_COUNT = 4
};
struct contour_point_t
{
void init () { flag = 0; x = y = 0.0f; }
uint8_t flag;
float x, y;
};
struct range_checker_t
{
range_checker_t (const void *_table, unsigned int _start_offset, unsigned int _end_offset)
: table ((const char*)_table), start_offset (_start_offset), end_offset (_end_offset) {}
template <typename T>
bool in_range (const T *p) const
{
return ((const char *) p) >= table + start_offset
&& ((const char *) (p + T::static_size)) <= table + end_offset;
}
protected:
const char *table;
const unsigned int start_offset;
const unsigned int end_offset;
};
struct x_setter_t
{
void set (contour_point_t &point, float v) const { point.x = v; }
bool is_short (uint8_t flag) const { return (flag & FLAG_X_SHORT) != 0; }
bool is_same (uint8_t flag) const { return (flag & FLAG_X_SAME) != 0; }
};
struct y_setter_t
{
void set (contour_point_t &point, float v) const { point.y = v; }
bool is_short (uint8_t flag) const { return (flag & FLAG_Y_SHORT) != 0; }
bool is_same (uint8_t flag) const { return (flag & FLAG_Y_SAME) != 0; }
};
template <typename T>
static bool read_points (const HBUINT8 *&p /* IN/OUT */,
hb_vector_t<contour_point_t> &_points /* IN/OUT */,
const range_checker_t &checker)
{
const T coord_setter;
float v = 0;
for (unsigned int i = 0; i < _points.length - PHANTOM_COUNT; i++)
{
uint8_t flag = _points[i].flag;
if (coord_setter.is_short (flag))
{
if (unlikely (!checker.in_range (p))) return false;
if (coord_setter.is_same (flag))
v += *p++;
else
v -= *p++;
}
else
{
if (unlikely (!checker.in_range ((const HBUINT16 *)p))) return false;
if (!coord_setter.is_same (flag))
{
v = *(const HBINT16 *)p;
p += HBINT16::static_size;
}
}
coord_setter.set (_points[i], v);
}
return true;
};
/* for a simple glyph, return contour end points, flags, along with coordinate points
* for a composite glyph, return pseudo component points
* in both cases points trailed with four phantom points
*/
bool get_contour_points (hb_codepoint_t glyph,
bool phantom_only,
hb_vector_t<contour_point_t> &_points /* OUT */,
hb_vector_t<unsigned int> &_end_points /* OUT */) const
{
unsigned int num_points = 0;
unsigned int start_offset, end_offset;
if (unlikely (!get_offsets (glyph, &start_offset, &end_offset)))
return false;
if (end_offset - start_offset < GlyphHeader::static_size)
return false;
const GlyphHeader &glyph_header = StructAtOffset<GlyphHeader> (glyf_table, start_offset);
if (unlikely (glyph_header.numberOfContours < 0)) return false;
int16_t num_contours = (int16_t) glyph_header.numberOfContours;
const HBUINT16 *end_pts = &StructAfter<HBUINT16, GlyphHeader> (glyph_header);
range_checker_t checker (glyf_table, start_offset, end_offset);
num_points = 0;
if (num_contours > 0)
{
if (unlikely (!checker.in_range (&end_pts[num_contours + 1]))) return false;
num_points = end_pts[num_contours - 1] + 1;
}
else if (num_contours < 0)
{
CompositeGlyphHeader::Iterator composite;
if (!get_composite (glyph, &composite)) return false;
do
{
num_points++;
} while (composite.move_to_next());
}
_points.resize (num_points + PHANTOM_COUNT);
for (unsigned int i = 0; i < _points.length; i++) _points[i].init ();
if ((num_contours <= 0) || phantom_only) return true;
/* Read simple glyph points if !phantom_only */
_end_points.resize (num_contours);
for (int16_t i = 0; i < num_contours; i++)
_end_points[i] = end_pts[i];
/* Skip instructions */
const HBUINT8 *p = &StructAtOffset<HBUINT8> (&end_pts[num_contours+1], end_pts[num_contours]);
/* Read flags */
for (unsigned int i = 0; i < num_points; i++)
{
if (unlikely (!checker.in_range (p))) return false;
uint8_t flag = *p++;
_points[i].flag = flag;
if ((flag & FLAG_REPEAT) != 0)
{
if (unlikely (!checker.in_range (p))) return false;
unsigned int repeat_count = *p++;
while ((repeat_count-- > 0) && (++i < num_points))
_points[i].flag = flag;
}
}
/* Read x & y coordinates */
return (!read_points<x_setter_t> (p, _points, checker) &&
!read_points<y_setter_t> (p, _points, checker));
}
/* based on FontTools _g_l_y_f.py::trim */
bool remove_padding (unsigned int start_offset,
unsigned int *end_offset) const

View File

@ -31,6 +31,7 @@
#include "hb-ot-hhea-table.hh"
#include "hb-ot-os2-table.hh"
#include "hb-ot-var-hvar-table.hh"
#include "hb-ot-var-gvar-table.hh"
/*
* hmtx -- Horizontal Metrics
@ -163,6 +164,7 @@ struct hmtxvmtx
void init (hb_face_t *face,
unsigned int default_advance_ = 0)
{
memset (this, 0, sizeof (*this));
default_advance = default_advance_ ? default_advance_ : hb_face_get_upem (face);
bool got_font_extents = false;
@ -206,12 +208,24 @@ struct hmtxvmtx
}
var_table = hb_sanitize_context_t().reference_table<HVARVVAR> (face, T::variationsTag);
/* If a TrueType variable font has no HVAR/VVAR table, gvar & glyf table is required for metrics calculation */
if (var_table.get_blob () == hb_blob_get_empty ())
{
hb_blob_ptr_t<fvar> fvar_table = hb_sanitize_context_t().reference_table<fvar> (face, HB_OT_TAG_fvar);
if (fvar_table.get_blob () != hb_blob_get_empty ())
{
gvar_accel.init (face);
}
fvar_table.destroy ();
}
}
void fini ()
{
table.destroy ();
var_table.destroy ();
gvar_accel.fini ();
}
/* TODO Add variations version. */
@ -249,7 +263,13 @@ struct hmtxvmtx
unsigned int advance = get_advance (glyph);
if (likely (glyph < num_metrics))
{
advance += (font->num_coords ? var_table->get_advance_var (glyph, font->coords, font->num_coords) : 0); // TODO Optimize?!
if (font->num_coords)
{
if (var_table.get_blob () != hb_blob_get_empty ())
advance += var_table->get_advance_var (glyph, font->coords, font->num_coords); // TODO Optimize?!
else
advance += gvar_accel.get_advance_var (glyph, font->coords, font->num_coords, T::tableTag==HB_OT_TAG_vmtx);
}
}
return advance;
}
@ -294,6 +314,7 @@ struct hmtxvmtx
private:
hb_blob_ptr_t<hmtxvmtx> table;
hb_blob_ptr_t<HVARVVAR> var_table;
gvar::accelerator_t gvar_accel;
};
protected:

View File

@ -28,6 +28,8 @@
#define HB_OT_VAR_GVAR_TABLE_HH
#include "hb-open-type.hh"
#include "hb-ot-glyf-table.hh"
#include "hb-ot-var-fvar-table.hh"
/*
* gvar -- Glyph Variation Table
@ -41,12 +43,6 @@ struct Tuple : UnsizedArrayOf<F2DOT14> {};
struct TuppleIndex : HBUINT16
{
bool has_peak () const { return ((*this) & EmbeddedPeakTuple) != 0; }
bool has_intermediate () const { return ((*this) & IntermediateRegion) != 0; }
bool has_private_points () const { return ((*this) & PrivatePointNumbers) != 0; }
unsigned int get_index () const { return (*this) & TupleIndexMask; }
protected:
enum Flags {
EmbeddedPeakTuple = 0x8000u,
IntermediateRegion = 0x4000u,
@ -54,7 +50,6 @@ struct TuppleIndex : HBUINT16
TupleIndexMask = 0x0FFFu
};
public:
DEFINE_SIZE_STATIC (2);
};
@ -63,17 +58,77 @@ struct TupleVarHeader
unsigned int get_size (unsigned int axis_count) const
{
return min_size +
(tupleIndex.has_peak ()? get_peak_tuple ().get_size (axis_count): 0) +
(tupleIndex.has_intermediate ()? (get_start_tuple (axis_count).get_size (axis_count) +
get_end_tuple (axis_count).get_size (axis_count)): 0);
(has_peak ()? get_peak_tuple ().get_size (axis_count): 0) +
(has_intermediate ()? (get_start_tuple (axis_count).get_size (axis_count) +
get_end_tuple (axis_count).get_size (axis_count)): 0);
}
const TupleVarHeader &get_next (unsigned int axis_count) const
{ return StructAtOffset<TupleVarHeader> (this, get_size (axis_count)); }
float calculate_scalar (const int *coords, unsigned int coord_count,
const hb_array_t<const F2DOT14> shared_tuples) const
{
const F2DOT14 *peak_tuple;
if (has_peak ())
peak_tuple = &(get_peak_tuple ()[0]);
else
{
unsigned int index = get_index ();
if (unlikely (index * coord_count >= shared_tuples.length))
return 0.f;
peak_tuple = &shared_tuples[coord_count * index];
}
const F2DOT14 *start_tuple = nullptr;
const F2DOT14 *end_tuple = nullptr;
if (has_intermediate ())
{
start_tuple = get_start_tuple (coord_count);
end_tuple = get_end_tuple (coord_count);
}
float scalar = 1.f;
for (unsigned int i = 0; i < coord_count; i++)
{
int v = coords[i];
int peak = peak_tuple[i];
if (!peak || v == peak) continue;
if (has_intermediate ())
{
int start = start_tuple[i];
int end = end_tuple[i];
if (unlikely (start > peak || peak > end ||
start < 0 && end > 0 && peak)) continue;
if (v < start || v > end) return 0.f;
if (v < peak)
{ if (peak != start) scalar *= (float)(v - start) / (peak - start); }
else
{ if (peak != end) scalar *= (float)(end - v) / (end - peak); }
}
else if (!v || v < MIN (0, peak) || v > MAX (0, peak)) return 0.f;
else
scalar *= (float)v / peak;
}
return scalar;
}
unsigned int get_data_size () const { return varDataSize; }
bool has_peak () const { return (tupleIndex & TuppleIndex::EmbeddedPeakTuple) != 0; }
bool has_intermediate () const { return (tupleIndex & TuppleIndex::IntermediateRegion) != 0; }
bool has_private_points () const { return (tupleIndex & TuppleIndex::PrivatePointNumbers) != 0; }
unsigned int get_index () const { return (tupleIndex & TuppleIndex::TupleIndexMask); }
protected:
const Tuple &get_peak_tuple () const
{ return StructAfter<Tuple> (tupleIndex); }
const Tuple &get_start_tuple (unsigned int axis_count) const
{ return StructAfter<Tuple> (get_peak_tuple ()[tupleIndex.has_peak ()? axis_count: 0]); }
{ return StructAfter<Tuple> (get_peak_tuple ()[has_peak ()? axis_count: 0]); }
const Tuple &get_end_tuple (unsigned int axis_count) const
{ return StructAfter<Tuple> (get_peak_tuple ()[tupleIndex.has_peak ()? (axis_count * 2): 0]); }
{ return StructAfter<Tuple> (get_peak_tuple ()[has_peak ()? (axis_count * 2): 0]); }
HBUINT16 varDataSize;
TuppleIndex tupleIndex;
@ -81,6 +136,7 @@ struct TupleVarHeader
/* UnsizedArrayOf<F2DOT14> intermediateStartTuple - optional */
/* UnsizedArrayOf<F2DOT14> intermediateEndTuple - optional */
public:
DEFINE_SIZE_MIN (4);
};
@ -101,30 +157,72 @@ struct TupleVarCount : HBUINT16
struct GlyphVarData
{
bool check_size (unsigned int axis_count, unsigned int len) const
{ return (get_header_size (axis_count) <= len) && (data <= len); }
const TupleVarHeader &get_tuple_var_header (void) const
{ return StructAfter<TupleVarHeader>(data); }
unsigned int get_header_size (unsigned int axis_count) const
struct tuple_iterator_t
{
unsigned int size = min_size;
for (unsigned int i = 0; i < tupleVarCount.get_count (); i++)
size += get_tuple_var_header (axis_count, i).get_size (axis_count); // FIX THIS O(n^2)
return size;
void init (const GlyphVarData *_var_data, unsigned int _length, unsigned int _axis_count)
{
var_data = _var_data;
length = _length;
index = 0;
axis_count = _axis_count;
current_tuple = &var_data->get_tuple_var_header ();
data_offset = 0;
}
bool is_valid () const
{
return (index < var_data->tupleVarCount.get_count ()) &&
in_range (current_tuple) &&
current_tuple->get_size (axis_count);
};
bool move_to_next ()
{
data_offset += current_tuple->get_data_size ();
current_tuple = &current_tuple->get_next (axis_count);
index++;
return is_valid ();
}
bool in_range (const void *p, unsigned int l) const
{ return (const char*)p >= (const char*)var_data && (const char*)p+l <= (const char*)var_data + length; }
template <typename T> bool in_range (const T *p) const { return in_range (p, sizeof (*p)); }
const HBUINT8 *get_serialized_data () const
{ return &(var_data+var_data->data) + data_offset; }
private:
const GlyphVarData *var_data;
unsigned int length;
unsigned int index;
unsigned int axis_count;
unsigned int data_offset;
public:
const TupleVarHeader *current_tuple;
};
static bool get_tuple_iterator (const GlyphVarData *var_data,
unsigned int length,
unsigned int axis_count,
tuple_iterator_t *iterator /* OUT */)
{
iterator->init (var_data, length, axis_count);
return iterator->is_valid ();
}
const TupleVarHeader &get_tuple_var_header (unsigned int axis_count, unsigned int i) const
{
const TupleVarHeader *header = &StructAfter<TupleVarHeader>(data);
while (i-- > 0)
header = &StructAtOffset<TupleVarHeader> (header, header->get_size (axis_count));
return *header;
}
bool has_shared_point_numbers () const { return tupleVarCount.has_shared_point_numbers (); }
protected:
TupleVarCount tupleVarCount;
OffsetTo<HBUINT8> data;
/* TupleVarHeader tupleVarHeaders[] */
public:
DEFINE_SIZE_MIN (4);
};
@ -169,13 +267,13 @@ struct gvar
{
unsigned int old_gid;
if (!c->plan->old_gid_for_new_gid (gid, &old_gid)) continue;
subset_data_size += get_data_length (old_gid);
subset_data_size += get_glyph_var_data_length (old_gid);
}
bool long_offset = subset_data_size & ~0xFFFFu;
out->flags.set (long_offset? 1: 0);
HBUINT8 *subset_offsets = c->serializer->allocate_size<HBUINT8> ((long_offset?HBUINT32::static_size: HBUINT16::static_size) * (num_glyphs+1));
HBUINT8 *subset_offsets = c->serializer->allocate_size<HBUINT8> ((long_offset? 4: 2) * (num_glyphs+1));
if (!subset_offsets) return_trace (false);
char *subset_data = c->serializer->allocate_size<char>(subset_data_size);
@ -186,7 +284,7 @@ struct gvar
for (hb_codepoint_t gid = 0; gid < num_glyphs; gid++)
{
unsigned int old_gid;
unsigned int length = c->plan->old_gid_for_new_gid (gid, &old_gid)? get_data_length (old_gid): 0;
unsigned int length = c->plan->old_gid_for_new_gid (gid, &old_gid)? get_glyph_var_data_length (old_gid): 0;
if (long_offset)
((HBUINT32 *)subset_offsets)[gid].set (glyph_offset);
@ -218,37 +316,267 @@ struct gvar
}
protected:
const GlyphVarData *get_glyph_var_data (unsigned int gid) const
const GlyphVarData *get_glyph_var_data (hb_codepoint_t glyph) const
{
unsigned int start_offset = get_offset (gid);
unsigned int end_offset = get_offset (gid+1);
unsigned int start_offset = get_offset (glyph);
unsigned int end_offset = get_offset (glyph+1);
if ((start_offset == end_offset) ||
unlikely ((start_offset > get_offset (glyphCount)) ||
(start_offset + GlyphVarData::min_size > end_offset)))
return &Null(GlyphVarData);
const GlyphVarData *var_data = &(((unsigned char *)this+start_offset)+dataZ);
if (unlikely (!var_data->check_size (axisCount, end_offset - start_offset)))
return &Null (GlyphVarData);
return var_data;
return &(((unsigned char *)this+start_offset)+dataZ);
}
bool is_long_offset () const { return (flags & 1)!=0; }
unsigned int get_offset (unsigned int gid) const
unsigned int get_offset (unsigned int i) const
{
if (is_long_offset ())
return get_long_offset_array ()[gid];
return get_long_offset_array ()[i];
else
return get_short_offset_array ()[gid] * 2;
return get_short_offset_array ()[i] * 2;
}
unsigned int get_data_length (unsigned int gid) const
{ return get_offset (gid+1) - get_offset (gid); }
unsigned int get_glyph_var_data_length (unsigned int glyph) const
{ return get_offset (glyph+1) - get_offset (glyph); }
const HBUINT32 *get_long_offset_array () const { return (const HBUINT32 *)&offsetZ; }
const HBUINT16 *get_short_offset_array () const { return (const HBUINT16 *)&offsetZ; }
typedef glyf::accelerator_t::contour_point_t contour_point_t;
typedef glyf::accelerator_t::phantom_point_index_t pp_t;
typedef glyf::accelerator_t::range_checker_t range_checker_t;
public:
struct accelerator_t
{
void init (hb_face_t *face)
{
memset (this, 0, sizeof (accelerator_t));
gvar_table = hb_sanitize_context_t ().reference_table<gvar> (face);
glyf.init (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 ();
fvar_table.destroy ();
if (unlikely ((gvar_table->glyphCount != face->get_num_glyphs ()) ||
(gvar_table->axisCount != axis_count)))
fini ();
unsigned int num_shared_coord = gvar_table->sharedTupleCount * gvar_table->axisCount;
shared_tuples.resize (num_shared_coord);
for (unsigned int i = 0; i < num_shared_coord; i++)
shared_tuples[i] = (&(gvar_table+gvar_table->sharedTuples))[i];
}
void fini ()
{
gvar_table.destroy ();
glyf.fini ();
}
bool apply_deltas_to_points (hb_codepoint_t glyph,
const int *coords, unsigned int coord_count,
const hb_array_t<contour_point_t> points,
const hb_array_t<unsigned int> end_points) const
{
if (unlikely (coord_count != gvar_table->axisCount)) return false;
const GlyphVarData *var_data = gvar_table->get_glyph_var_data (glyph);
GlyphVarData::tuple_iterator_t iterator;
if (!GlyphVarData::get_tuple_iterator (var_data,
gvar_table->get_glyph_var_data_length (glyph),
gvar_table->axisCount,
&iterator))
return false;
do {
float scalar = iterator.current_tuple->calculate_scalar (coords, coord_count, shared_tuples.as_array ());
if (scalar == 0.f) continue;
const HBUINT8 *p = iterator.get_serialized_data ();
unsigned int length = iterator.current_tuple->get_data_size ();
if (unlikely (!iterator.in_range (p, length))) return false;
range_checker_t checker (p, 0, length);
hb_vector_t <unsigned int> shared_indices;
if (var_data->has_shared_point_numbers () &&
!unpack_points (p, shared_indices, checker)) return false;
hb_vector_t <unsigned int> private_indices;
if (iterator.current_tuple->has_private_points () &&
!unpack_points (p, private_indices, checker)) return false;
const hb_array_t<unsigned int> &indices = shared_indices.length? shared_indices: private_indices;
bool apply_to_all = (indices.length == 0);
unsigned int num_deltas = apply_to_all? points.length: indices.length;
hb_vector_t <int> x_deltas;
x_deltas.resize (num_deltas);
if (!unpack_deltas (p, x_deltas, checker)) return false;
hb_vector_t <int> y_deltas;
y_deltas.resize (num_deltas);
if (!unpack_deltas (p, y_deltas, checker)) return false;
for (unsigned int i = 0; i < num_deltas; i++)
{
unsigned int pt_index = apply_to_all? i: indices[i];
points[pt_index].x += x_deltas[i] * scalar;
points[pt_index].y += y_deltas[i] * scalar;
}
/* TODO: interpolate untouched points for glyph extents */
} while (iterator.move_to_next ());
return true;
}
/* Note: Recursively calls itself. Who's checking recursively nested composite glyph BTW? */
bool get_var_metrics (hb_codepoint_t glyph,
const int *coords, unsigned int coord_count,
hb_vector_t<contour_point_t> &phantoms) const
{
hb_vector_t<contour_point_t> points;
hb_vector_t<unsigned int> end_points;
if (!glyf.get_contour_points (glyph, true, points, end_points)) return false;
if (!apply_deltas_to_points (glyph, coords, coord_count, points.as_array (), end_points.as_array ())) return false;
for (unsigned int i = 0; i < pp_t::PHANTOM_COUNT; i++)
phantoms[i] = points[points.length - pp_t::PHANTOM_COUNT + i];
glyf::CompositeGlyphHeader::Iterator composite;
if (!glyf.get_composite (glyph, &composite)) return true; /* simple glyph */
do
{
/* TODO: support component scale/transformation */
if (((composite.current->flags & glyf::CompositeGlyphHeader::USE_MY_METRICS) != 0) &&
!get_var_metrics (composite.current->glyphIndex, coords, coord_count, phantoms))
return false;
} while (composite.move_to_next());
return true;
}
float get_advance_var (hb_codepoint_t glyph,
const int *coords, unsigned int coord_count,
bool vertical) const
{
float advance = 0.f;
if (coord_count != gvar_table->axisCount) return advance;
hb_vector_t<contour_point_t> points;
points.resize (pp_t::PHANTOM_COUNT);
if (!get_var_metrics (glyph, coords, coord_count, points))
return advance;
if (vertical)
return -(points[pp_t::PHANTOM_BOTTOM].y - points[pp_t::PHANTOM_TOP].y); // is this sign correct?
else
return points[pp_t::PHANTOM_RIGHT].x - points[pp_t::PHANTOM_LEFT].x;
}
protected:
const GlyphVarData *get_glyph_var_data (hb_codepoint_t glyph) const
{ return gvar_table->get_glyph_var_data (glyph); }
static bool unpack_points (const HBUINT8 *&p /* IN/OUT */,
hb_vector_t<unsigned int> &points /* OUT */,
const range_checker_t &check)
{
enum packed_point_flag_t
{
POINTS_ARE_WORDS = 0x80,
POINT_RUN_COUNT_MASK = 0x7F
};
if (!check.in_range (p)) return false;
uint16_t count = *p++;
if ((count & POINTS_ARE_WORDS) != 0)
{
if (!check.in_range (p)) return false;
count = ((count & POINT_RUN_COUNT_MASK) << 8) | *p++;
}
points.resize (count);
uint16_t i = 0;
while (i < count)
{
if (!check.in_range (p)) return false;
uint16_t j;
uint8_t control = *p++;
uint16_t run_count = (control & POINT_RUN_COUNT_MASK) + 1;
if ((control & POINTS_ARE_WORDS) != 0)
{
for (j = 0; j < run_count && i < count; j++, i++)
{
if (!check.in_range ((const HBUINT16 *)p)) return false;
points[i] = *(const HBUINT16 *)p;
p += HBUINT16::static_size;
}
}
else
{
for (j = 0; j < run_count && i < count; j++, i++)
{
if (!check.in_range (p)) return false;
points[i] = *p++;
}
}
if (j < run_count) return false;
}
return true;
}
static bool unpack_deltas (const HBUINT8 *&p /* IN/OUT */,
hb_vector_t<int> &deltas /* IN/OUT */,
const range_checker_t &check)
{
enum packed_delta_flag_t
{
DELTAS_ARE_ZERO = 0x80,
DELTAS_ARE_WORDS = 0x40,
DELTA_RUN_COUNT_MASK = 0x3F
};
unsigned int i = 0;
unsigned int count = deltas.length;
while (i < count)
{
if (!check.in_range (p)) return false;
uint16_t j;
uint8_t control = *p++;
uint16_t run_count = (control & DELTA_RUN_COUNT_MASK) + 1;
if ((control & DELTAS_ARE_ZERO) != 0)
{
for (j = 0; j < run_count && i < count; j++, i++)
deltas[i] = 0;
}
else if ((control & DELTAS_ARE_WORDS) != 0)
{
for (j = 0; j < run_count && i < count; j++, i++)
{
if (!check.in_range ((const HBUINT16 *)p)) return false;
deltas[i] = *(const HBINT16 *)p;
p += HBUINT16::static_size;
}
}
else
{
for (j = 0; j < run_count && i < count; j++, i++)
{
if (!check.in_range (p)) return false;
deltas[i] = *(const HBINT8 *)p++;
}
}
if (j < run_count) return false;
}
return true;
}
private:
hb_blob_ptr_t<gvar> gvar_table;
hb_vector_t<F2DOT14> shared_tuples;
glyf::accelerator_t glyf;
};
protected:
FixedVersion<> version; /* Version of gvar table. Set to 0x00010000u. */
HBUINT16 axisCount;