Skip to content

Commit

Permalink
Turn some byte data into unsigned char, from char
Browse files Browse the repository at this point in the history
  • Loading branch information
behdad committed Aug 29, 2024
1 parent 28cc53c commit 2ba0b9e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/hb-open-type.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ struct TupleValues
};

static unsigned compile (hb_array_t<const int> values, /* IN */
hb_array_t<char> encoded_bytes /* OUT */)
hb_array_t<unsigned char> encoded_bytes /* OUT */)
{
unsigned num_values = values.length;
unsigned encoded_len = 0;
Expand All @@ -1517,7 +1517,7 @@ struct TupleValues
}

static unsigned encode_value_run_as_zeroes (unsigned& i,
hb_array_t<char> encoded_bytes,
hb_array_t<unsigned char> encoded_bytes,
hb_array_t<const int> values)
{
unsigned num_values = values.length;
Expand Down Expand Up @@ -1546,7 +1546,7 @@ struct TupleValues
}

static unsigned encode_value_run_as_bytes (unsigned &i,
hb_array_t<char> encoded_bytes,
hb_array_t<unsigned char> encoded_bytes,
hb_array_t<const int> values)
{
unsigned start = i;
Expand Down Expand Up @@ -1600,7 +1600,7 @@ struct TupleValues
}

static unsigned encode_value_run_as_words (unsigned &i,
hb_array_t<char> encoded_bytes,
hb_array_t<unsigned char> encoded_bytes,
hb_array_t<const int> values)
{
unsigned start = i;
Expand Down Expand Up @@ -1661,7 +1661,7 @@ struct TupleValues
}

static unsigned encode_value_run_as_longs (unsigned &i,
hb_array_t<char> encoded_bytes,
hb_array_t<unsigned char> encoded_bytes,
hb_array_t<const int> values)
{
unsigned start = i;
Expand Down
20 changes: 10 additions & 10 deletions src/hb-ot-var-common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ struct tuple_delta_t
/* compiled data: header and deltas
* compiled point data is saved in a hashmap within tuple_variations_t cause
* some point sets might be reused by different tuple variations */
hb_vector_t<char> compiled_tuple_header;
hb_vector_t<char> compiled_deltas;
hb_vector_t<unsigned char> compiled_tuple_header;
hb_vector_t<unsigned char> compiled_deltas;

/* compiled peak coords, empty for non-gvar tuples */
hb_vector_t<char> compiled_peak_coords;
Expand Down Expand Up @@ -517,7 +517,7 @@ struct tuple_delta_t
static bool compile_deltas (const hb_vector_t<bool> &point_indices,
const hb_vector_t<double> &x_deltas,
const hb_vector_t<double> &y_deltas,
hb_vector_t<char> &compiled_deltas /* OUT */)
hb_vector_t<unsigned char> &compiled_deltas /* OUT */)
{
hb_vector_t<int> rounded_deltas;
if (unlikely (!rounded_deltas.alloc (point_indices.length)))
Expand Down Expand Up @@ -560,7 +560,7 @@ struct tuple_delta_t
return compiled_deltas.resize (encoded_len);
}

static unsigned compile_deltas (hb_array_t<char> encoded_bytes,
static unsigned compile_deltas (hb_array_t<unsigned char> encoded_bytes,
hb_array_t<const int> deltas)
{
return TupleValues::compile (deltas, encoded_bytes);
Expand Down Expand Up @@ -705,20 +705,20 @@ struct tuple_delta_t
opt_indices.arrayZ[i] = false;
}

hb_vector_t<char> opt_point_data;
hb_vector_t<unsigned char> opt_point_data;
if (!compile_point_set (opt_indices, opt_point_data))
return false;
hb_vector_t<char> opt_deltas_data;
hb_vector_t<unsigned char> opt_deltas_data;
if (!compile_deltas (opt_indices,
is_comp_glyph_wo_deltas ? opt_deltas_x : deltas_x,
is_comp_glyph_wo_deltas ? opt_deltas_y : deltas_y,
opt_deltas_data))
return false;

hb_vector_t<char> point_data;
hb_vector_t<unsigned char> point_data;
if (!compile_point_set (indices, point_data))
return false;
hb_vector_t<char> deltas_data;
hb_vector_t<unsigned char> deltas_data;
if (!compile_deltas (indices, deltas_x, deltas_y, deltas_data))
return false;

Expand All @@ -740,7 +740,7 @@ struct tuple_delta_t
}

static bool compile_point_set (const hb_vector_t<bool> &point_indices,
hb_vector_t<char>& compiled_points /* OUT */)
hb_vector_t<unsigned char>& compiled_points /* OUT */)
{
unsigned num_points = 0;
for (bool i : point_indices)
Expand Down Expand Up @@ -1134,7 +1134,7 @@ struct TupleVariationData
continue;
}

hb_vector_t<char> compiled_point_data;
hb_vector_t<unsigned char> compiled_point_data;
if (!tuple_delta_t::compile_point_set (*points_set, compiled_point_data))
return false;

Expand Down
12 changes: 6 additions & 6 deletions src/test-tuple-varstore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "hb-ot-var-cvar-table.hh"

// cvar table data from Multi-ABC.ttf
const char cvar_data[] = "\x0\x1\x0\x0\x0\x2\x0\x14\x0\x51\xa0\x0\xc0\x0\x0\x54\xa0\x0\x40\x0\x2a\x29\x17\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\xd\xff\x0\xfd\x1\x0\xff\x0\xfd\x1\x0\xdb\xdb\xe6\xe6\x82\x0\xfd\x84\x6\xfd\x0\x2\xe3\xe3\xec\xec\x82\x4\x1\xe3\xe3\xec\xec\x82\x0\x1\x2a\x29\x17\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\xd\x1\x0\x5\xfd\x0\x1\x0\x5\xfd\x0\x61\x61\x44\x44\x82\x0\x5\x81\x9\x1\xff\x1\x7\xff\xfb\x49\x49\x35\x35\x82\x4\xff\x49\x49\x35\x35\x82\x0\xff";
const unsigned char cvar_data[] = "\x0\x1\x0\x0\x0\x2\x0\x14\x0\x51\xa0\x0\xc0\x0\x0\x54\xa0\x0\x40\x0\x2a\x29\x17\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\xd\xff\x0\xfd\x1\x0\xff\x0\xfd\x1\x0\xdb\xdb\xe6\xe6\x82\x0\xfd\x84\x6\xfd\x0\x2\xe3\xe3\xec\xec\x82\x4\x1\xe3\xe3\xec\xec\x82\x0\x1\x2a\x29\x17\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\xd\x1\x0\x5\xfd\x0\x1\x0\x5\xfd\x0\x61\x61\x44\x44\x82\x0\x5\x81\x9\x1\xff\x1\x7\xff\xfb\x49\x49\x35\x35\x82\x4\xff\x49\x49\x35\x35\x82\x0\xff";

static void
test_decompile_cvar ()
Expand All @@ -45,7 +45,7 @@ test_decompile_cvar ()
const OT::TupleVariationData* tuple_var_data = reinterpret_cast<const OT::TupleVariationData*> (cvar_data + 4);

unsigned len = sizeof (cvar_data);
hb_bytes_t var_data_bytes{cvar_data+4, len - 4};
hb_bytes_t var_data_bytes{(const char* ) cvar_data + 4, len - 4};
bool result = OT::TupleVariationData::get_tuple_iterator (var_data_bytes, axis_count, cvar_table,
shared_indices, &iterator);
assert (result);
Expand Down Expand Up @@ -131,22 +131,22 @@ test_decompile_cvar ()
bool res = tuple_variations.compile_bytes (axes_index_map, axis_idx_tag_map, false);
assert (res);
assert (tuple_variations.tuple_vars[0].compiled_tuple_header.length == 6);
const char tuple_var_header_1[] = "\x0\x51\xa0\x0\xc0\x0";
const unsigned char tuple_var_header_1[] = "\x0\x51\xa0\x0\xc0\x0";
for (unsigned i = 0; i < 6; i++)
assert(tuple_variations.tuple_vars[0].compiled_tuple_header.arrayZ[i] == tuple_var_header_1[i]);

assert (tuple_variations.tuple_vars[1].compiled_tuple_header.length == 6);
const char tuple_var_header_2[] = "\x0\x54\xa0\x0\x40\x0";
const unsigned char tuple_var_header_2[] = "\x0\x54\xa0\x0\x40\x0";
for (unsigned i = 0; i < 6; i++)
assert(tuple_variations.tuple_vars[1].compiled_tuple_header.arrayZ[i] == tuple_var_header_2[i]);

assert (tuple_variations.tuple_vars[0].compiled_deltas.length == 37);
assert (tuple_variations.tuple_vars[1].compiled_deltas.length == 40);
const char compiled_deltas_1[] = "\x0d\xff\x00\xfe\x01\x00\xff\x00\xfe\x01\x00\xed\xed\xf3\xf3\x82\x00\xfe\x84\x06\xfe\x00\x01\xf1\xf1\xf6\xf6\x82\x04\x01\xf1\xf1\xf6\xf6\x82\x00\x01";
const unsigned char compiled_deltas_1[] = "\x0d\xff\x00\xfe\x01\x00\xff\x00\xfe\x01\x00\xed\xed\xf3\xf3\x82\x00\xfe\x84\x06\xfe\x00\x01\xf1\xf1\xf6\xf6\x82\x04\x01\xf1\xf1\xf6\xf6\x82\x00\x01";
for (unsigned i = 0; i < 37; i++)
assert (tuple_variations.tuple_vars[0].compiled_deltas.arrayZ[i] == compiled_deltas_1[i]);

const char compiled_deltas_2[] = "\x0d\x01\x00\x04\xfe\x00\x01\x00\x04\xfe\x00\x44\x44\x30\x30\x82\x00\x04\x81\x09\x01\xff\x01\x05\xff\xfc\x33\x33\x25\x25\x82\x04\xff\x33\x33\x25\x25\x82\x00\xff";
const unsigned char compiled_deltas_2[] = "\x0d\x01\x00\x04\xfe\x00\x01\x00\x04\xfe\x00\x44\x44\x30\x30\x82\x00\x04\x81\x09\x01\xff\x01\x05\xff\xfc\x33\x33\x25\x25\x82\x04\xff\x33\x33\x25\x25\x82\x00\xff";
for (unsigned i = 0; i < 40; i++)
assert (tuple_variations.tuple_vars[1].compiled_deltas.arrayZ[i] == compiled_deltas_2[i]);
}
Expand Down

0 comments on commit 2ba0b9e

Please sign in to comment.