summaryrefslogtreecommitdiffstats
path: root/thirdparty/harfbuzz/src/hb-ot-var-common.hh
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/harfbuzz/src/hb-ot-var-common.hh')
-rw-r--r--thirdparty/harfbuzz/src/hb-ot-var-common.hh105
1 files changed, 49 insertions, 56 deletions
diff --git a/thirdparty/harfbuzz/src/hb-ot-var-common.hh b/thirdparty/harfbuzz/src/hb-ot-var-common.hh
index 44ec64bc03..9e813f6d2d 100644
--- a/thirdparty/harfbuzz/src/hb-ot-var-common.hh
+++ b/thirdparty/harfbuzz/src/hb-ot-var-common.hh
@@ -60,18 +60,21 @@ struct DeltaSetIndexMapFormat01
entryFormat = ((width-1)<<4)|(inner_bit_count-1);
mapCount = output_map.length;
- HBUINT8 *p = c->allocate_size<HBUINT8> (width * output_map.length, false);
+ HBUINT8 *p = c->allocate_size<HBUINT8> (width * output_map.length);
if (unlikely (!p)) return_trace (false);
for (unsigned int i = 0; i < output_map.length; i++)
{
- unsigned int v = output_map[i];
- unsigned int outer = v >> 16;
- unsigned int inner = v & 0xFFFF;
- unsigned int u = (outer << inner_bit_count) | inner;
- for (unsigned int w = width; w > 0;)
+ unsigned int v = output_map.arrayZ[i];
+ if (v)
{
- p[--w] = u;
- u >>= 8;
+ unsigned int outer = v >> 16;
+ unsigned int inner = v & 0xFFFF;
+ unsigned int u = (outer << inner_bit_count) | inner;
+ for (unsigned int w = width; w > 0;)
+ {
+ p[--w] = u;
+ u >>= 8;
+ }
}
p += width;
}
@@ -421,25 +424,6 @@ struct TupleVariationHeader
DEFINE_SIZE_MIN (4);
};
-/* not using hb_bytes_t: avoid potential build issues with some compilers */
-struct byte_data_t
-{
- hb_bytes_t bytes;
-
- byte_data_t () = default;
- byte_data_t (const char *p_, unsigned len_) : bytes (hb_bytes_t (p_, len_)) {}
-
- void fini () { bytes.fini (); }
-
- bool operator == (const byte_data_t& o) const
- { return bytes.arrayZ == o.bytes.arrayZ && bytes.length == o.bytes.length; }
-
- explicit operator bool () const { return bytes.length; }
-
- void copy (hb_serialize_context_t *c) const
- { c->embed (bytes.arrayZ, bytes.length); }
-};
-
enum packed_delta_flag_t
{
DELTAS_ARE_ZERO = 0x80,
@@ -505,6 +489,7 @@ struct tuple_delta_t
else
{
if (!o.indices.arrayZ[i]) continue;
+ indices.arrayZ[i] = true;
deltas_x[i] = o.deltas_x[i];
if (deltas_y && o.deltas_y)
deltas_y[i] = o.deltas_y[i];
@@ -530,7 +515,8 @@ struct tuple_delta_t
return *this;
}
- hb_vector_t<tuple_delta_t> change_tuple_var_axis_limit (hb_tag_t axis_tag, Triple axis_limit) const
+ hb_vector_t<tuple_delta_t> change_tuple_var_axis_limit (hb_tag_t axis_tag, Triple axis_limit,
+ TripleDistances axis_triple_distances) const
{
hb_vector_t<tuple_delta_t> out;
Triple *tent;
@@ -550,7 +536,7 @@ struct tuple_delta_t
return out;
}
- result_t solutions = rebase_tent (*tent, axis_limit);
+ result_t solutions = rebase_tent (*tent, axis_limit, axis_triple_distances);
for (auto t : solutions)
{
tuple_delta_t new_var = *this;
@@ -715,6 +701,8 @@ struct tuple_delta_t
}
if (j != rounded_deltas.length) return false;
+ /* reset i because we reuse rounded_deltas for deltas_y */
+ i = 0;
encoded_len += encode_delta_run (i, compiled_deltas.as_array ().sub_array (encoded_len), rounded_deltas);
}
return compiled_deltas.resize (encoded_len);
@@ -755,14 +743,14 @@ struct tuple_delta_t
while (run_length >= 64)
{
- *it++ = (DELTAS_ARE_ZERO | 63);
+ *it++ = char (DELTAS_ARE_ZERO | 63);
run_length -= 64;
encoded_len++;
}
if (run_length)
{
- *it++ = (DELTAS_ARE_ZERO | (run_length - 1));
+ *it++ = char (DELTAS_ARE_ZERO | (run_length - 1));
encoded_len++;
}
return encoded_len;
@@ -870,6 +858,7 @@ struct tuple_delta_t
if (run_length)
{
*it++ = (DELTAS_ARE_WORDS | (run_length - 1));
+ encoded_len++;
while (start < i)
{
int16_t delta_val = deltas[start++];
@@ -917,7 +906,7 @@ struct TupleVariationData
private:
/* referenced point set->compiled point data map */
- hb_hashmap_t<const hb_vector_t<bool>*, byte_data_t> point_data_map;
+ hb_hashmap_t<const hb_vector_t<bool>*, hb_bytes_t> point_data_map;
/* referenced point set-> count map, used in finding shared points */
hb_hashmap_t<const hb_vector_t<bool>*, unsigned> point_set_count_map;
@@ -1003,16 +992,21 @@ struct TupleVariationData
return true;
}
- void change_tuple_variations_axis_limits (const hb_hashmap_t<hb_tag_t, Triple> *normalized_axes_location)
+ void change_tuple_variations_axis_limits (const hb_hashmap_t<hb_tag_t, Triple>& normalized_axes_location,
+ const hb_hashmap_t<hb_tag_t, TripleDistances>& axes_triple_distances)
{
- for (auto _ : *normalized_axes_location)
+ for (auto _ : normalized_axes_location)
{
hb_tag_t axis_tag = _.first;
Triple axis_limit = _.second;
+ TripleDistances axis_triple_distances{1.f, 1.f};
+ if (axes_triple_distances.has (axis_tag))
+ axis_triple_distances = axes_triple_distances.get (axis_tag);
+
hb_vector_t<tuple_delta_t> new_vars;
for (const tuple_delta_t& var : tuple_vars)
{
- hb_vector_t<tuple_delta_t> out = var.change_tuple_var_axis_limit (axis_tag, axis_limit);
+ hb_vector_t<tuple_delta_t> out = var.change_tuple_var_axis_limit (axis_tag, axis_limit, axis_triple_distances);
if (!out) continue;
unsigned new_len = new_vars.length + out.length;
@@ -1054,7 +1048,7 @@ struct TupleVariationData
tuple_vars = std::move (new_vars);
}
- byte_data_t compile_point_set (const hb_vector_t<bool> &point_indices)
+ hb_bytes_t compile_point_set (const hb_vector_t<bool> &point_indices)
{
unsigned num_points = 0;
for (bool i : point_indices)
@@ -1066,15 +1060,15 @@ struct TupleVariationData
if (num_points == indices_length)
{
char *p = (char *) hb_calloc (1, sizeof (char));
- if (unlikely (!p)) return byte_data_t ();
+ if (unlikely (!p)) return hb_bytes_t ();
- return byte_data_t (p, 1);
+ return hb_bytes_t (p, 1);
}
/* allocate enough memories: 2 bytes for count + 3 bytes for each point */
unsigned num_bytes = 2 + 3 *num_points;
char *p = (char *) hb_calloc (num_bytes, sizeof (char));
- if (unlikely (!p)) return byte_data_t ();
+ if (unlikely (!p)) return hb_bytes_t ();
unsigned pos = 0;
/* binary data starts with the total number of reference points */
@@ -1137,10 +1131,10 @@ struct TupleVariationData
else
p[header_pos] = (run_length - 1) | 0x80;
}
- return byte_data_t (p, pos);
+ return hb_bytes_t (p, pos);
}
- /* compile all point set and store byte data in a point_set->byte_data_t hashmap,
+ /* compile all point set and store byte data in a point_set->hb_bytes_t hashmap,
* also update point_set->count map, which will be used in finding shared
* point set*/
bool compile_all_point_sets ()
@@ -1157,8 +1151,8 @@ struct TupleVariationData
continue;
}
- byte_data_t compiled_data = compile_point_set (*points_set);
- if (unlikely (compiled_data == byte_data_t ()))
+ hb_bytes_t compiled_data = compile_point_set (*points_set);
+ if (unlikely (compiled_data == hb_bytes_t ()))
return false;
if (!point_data_map.set (points_set, compiled_data) ||
@@ -1169,19 +1163,19 @@ struct TupleVariationData
}
/* find shared points set which saves most bytes */
- byte_data_t find_shared_points ()
+ hb_bytes_t find_shared_points ()
{
unsigned max_saved_bytes = 0;
- byte_data_t res{};
+ hb_bytes_t res{};
for (const auto& _ : point_data_map.iter ())
{
const hb_vector_t<bool>* points_set = _.first;
- unsigned data_length = _.second.bytes.length;
+ unsigned data_length = _.second.length;
unsigned *count;
if (unlikely (!point_set_count_map.has (points_set, &count) ||
*count <= 1))
- return byte_data_t ();
+ return hb_bytes_t ();
unsigned saved_bytes = data_length * ((*count) -1);
if (saved_bytes > max_saved_bytes)
@@ -1193,9 +1187,10 @@ struct TupleVariationData
return res;
}
- void instantiate (const hb_hashmap_t<hb_tag_t, Triple>& normalized_axes_location)
+ void instantiate (const hb_hashmap_t<hb_tag_t, Triple>& normalized_axes_location,
+ const hb_hashmap_t<hb_tag_t, TripleDistances>& axes_triple_distances)
{
- change_tuple_variations_axis_limits (&normalized_axes_location);
+ change_tuple_variations_axis_limits (normalized_axes_location, axes_triple_distances);
merge_tuple_variations ();
}
@@ -1209,14 +1204,14 @@ struct TupleVariationData
for (auto& tuple: tuple_vars)
{
const hb_vector_t<bool>* points_set = &(tuple.indices);
- byte_data_t *points_data;
+ hb_bytes_t *points_data;
if (unlikely (!point_data_map.has (points_set, &points_data)))
return false;
if (!tuple.compile_deltas ())
return false;
- if (!tuple.compile_tuple_var_header (axes_index_map, points_data->bytes.length, axes_old_index_tag_map))
+ if (!tuple.compile_tuple_var_header (axes_index_map, points_data->length, axes_old_index_tag_map))
return false;
}
return true;
@@ -1227,8 +1222,7 @@ struct TupleVariationData
TRACE_SERIALIZE (this);
for (const auto& tuple: tuple_vars)
{
- byte_data_t compiled_bytes {tuple.compiled_tuple_header.arrayZ, tuple.compiled_tuple_header.length};
- compiled_bytes.copy (c);
+ tuple.compiled_tuple_header.as_array ().copy (c);
if (c->in_error ()) return_trace (false);
total_header_len += tuple.compiled_tuple_header.length;
}
@@ -1241,13 +1235,12 @@ struct TupleVariationData
for (const auto& tuple: tuple_vars)
{
const hb_vector_t<bool>* points_set = &(tuple.indices);
- byte_data_t *point_data;
+ hb_bytes_t *point_data;
if (!point_data_map.has (points_set, &point_data))
return_trace (false);
point_data->copy (c);
- byte_data_t compiled_bytes {tuple.compiled_deltas.arrayZ, tuple.compiled_deltas.length};
- compiled_bytes.copy (c);
+ tuple.compiled_deltas.as_array ().copy (c);
if (c->in_error ()) return_trace (false);
}
return_trace (true);