Merge pull request #4205 from harfbuzz/gvar-optimize

Gvar optimize
pull/4207/head
Behdad Esfahbod 2 years ago committed by GitHub
commit 1d31da91ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      src/hb-ot-var-common.hh
  2. 54
      src/hb-ot-var-gvar-table.hh
  3. BIN
      test/subset/data/expected/full_instance/Roboto-Variable.default.retain-all-codepoint.wght=300,wdth=90.ttf
  4. BIN
      test/subset/data/expected/full_instance/Roboto-Variable.no-prune-unicode-ranges.retain-all-codepoint.wght=300,wdth=90.ttf
  5. 3
      test/subset/data/tests/full_instance.tests

@ -260,14 +260,15 @@ struct TupleVariationHeader
else
{
unsigned int index = get_index ();
if (unlikely (index * coord_count >= shared_tuples.length))
if (unlikely ((index + 1) * coord_count > shared_tuples.length))
return 0.f;
peak_tuple = shared_tuples.sub_array (coord_count * index, coord_count);
}
hb_array_t<const F2DOT14> start_tuple;
hb_array_t<const F2DOT14> end_tuple;
if (has_intermediate ())
bool has_interm = has_intermediate ();
if (has_interm)
{
start_tuple = get_start_tuple (coord_count);
end_tuple = get_end_tuple (coord_count);
@ -276,14 +277,16 @@ struct TupleVariationHeader
float scalar = 1.f;
for (unsigned int i = 0; i < coord_count; i++)
{
int peak = peak_tuple.arrayZ[i].to_int ();
if (!peak) continue;
int v = coords[i];
int peak = peak_tuple[i].to_int ();
if (!peak || v == peak) continue;
if (v == peak) continue;
if (has_intermediate ())
if (has_interm)
{
int start = start_tuple[i].to_int ();
int end = end_tuple[i].to_int ();
int start = start_tuple.arrayZ[i].to_int ();
int end = end_tuple.arrayZ[i].to_int ();
if (unlikely (start > peak || peak > end ||
(start < 0 && end > 0 && peak))) continue;
if (v < start || v > end) return 0.f;

@ -274,19 +274,14 @@ struct gvar
return true; /* so isn't applied at all */
/* Save original points for inferred delta calculation */
contour_point_vector_t orig_points_vec;
orig_points_vec.extend (points);
if (unlikely (orig_points_vec.in_error ())) return false;
contour_point_vector_t orig_points_vec; // Populated lazily
auto orig_points = orig_points_vec.as_array ();
contour_point_vector_t deltas_vec; /* flag is used to indicate referenced point */
if (unlikely (!deltas_vec.resize (points.length, false))) return false;
if (unlikely (!deltas_vec.resize (points.length))) return false;
auto deltas = deltas_vec.as_array ();
hb_vector_t<unsigned> end_points;
for (unsigned i = 0; i < points.length; ++i)
if (points.arrayZ[i].is_end_point)
end_points.push (i);
hb_vector_t<unsigned> end_points; // Populated lazily
unsigned num_coords = table->axisCount;
hb_array_t<const F2DOT14> shared_tuples = (table+table->sharedTuples).as_array (table->sharedTupleCount * table->axisCount);
@ -294,6 +289,7 @@ struct gvar
hb_vector_t<unsigned int> private_indices;
hb_vector_t<int> x_deltas;
hb_vector_t<int> y_deltas;
bool flush = false;
do
{
float scalar = iterator.current_tuple->calculate_scalar (coords, num_coords, shared_tuples);
@ -318,16 +314,31 @@ struct gvar
if (unlikely (!y_deltas.resize (num_deltas, false))) return false;
if (unlikely (!GlyphVariationData::unpack_deltas (p, y_deltas, end))) return false;
hb_memset (deltas.arrayZ, 0, deltas.get_size ());
if (!apply_to_all)
{
if (!orig_points)
{
orig_points_vec.extend (points);
if (unlikely (orig_points_vec.in_error ())) return false;
orig_points = orig_points_vec.as_array ();
}
if (flush)
{
for (unsigned int i = 0; i < points.length; i++)
points.arrayZ[i].translate (deltas.arrayZ[i]);
flush = false;
}
hb_memset (deltas.arrayZ, 0, deltas.get_size ());
}
unsigned ref_points = 0;
if (scalar != 1.0f)
for (unsigned int i = 0; i < num_deltas; i++)
{
unsigned int pt_index = apply_to_all ? i : indices[i];
if (unlikely (pt_index >= deltas.length)) continue;
auto &delta = deltas.arrayZ[pt_index];
ref_points += !delta.flag;
delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */
delta.x += x_deltas.arrayZ[i] * scalar;
delta.y += y_deltas.arrayZ[i] * scalar;
@ -338,20 +349,23 @@ struct gvar
unsigned int pt_index = apply_to_all ? i : indices[i];
if (unlikely (pt_index >= deltas.length)) continue;
auto &delta = deltas.arrayZ[pt_index];
ref_points += !delta.flag;
delta.flag = 1; /* this point is referenced, i.e., explicit deltas specified */
delta.x += x_deltas.arrayZ[i];
delta.y += y_deltas.arrayZ[i];
}
/* infer deltas for unreferenced points */
if (ref_points && ref_points < orig_points.length)
if (!apply_to_all)
{
if (!end_points)
for (unsigned i = 0; i < points.length; ++i)
if (points.arrayZ[i].is_end_point)
end_points.push (i);
if (unlikely (end_points.in_error ())) return false;
unsigned start_point = 0;
for (unsigned c = 0; c < end_points.length; c++)
for (unsigned end_point : end_points)
{
unsigned end_point = end_points.arrayZ[c];
/* Check the number of unreferenced points in a contour. If no unref points or no ref points, nothing to do. */
unsigned unref_count = 0;
for (unsigned i = start_point; i < end_point + 1; i++)
@ -398,12 +412,14 @@ struct gvar
}
}
/* apply specified / inferred deltas to points */
for (unsigned int i = 0; i < points.length; i++)
points.arrayZ[i].translate (deltas.arrayZ[i]);
flush = true;
} while (iterator.move_to_next ());
if (flush)
for (unsigned int i = 0; i < points.length; i++)
points.arrayZ[i].translate (deltas.arrayZ[i]);
return true;
}

@ -11,3 +11,6 @@ SUBSETS:
INSTANCES:
wght=150,wdth=80
wght=300,wdth=90
OPTIONS:
no_fonttools

Loading…
Cancel
Save