mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 15:01:01 +01:00
3 files changed
+46
-34
No files matched your search
@@ -82,6 +82,7 @@ struct NumType
|
||||
NumType operator ++ (int) { NumType c (*this); ++*this; return c; }
|
||||
NumType operator -- (int) { NumType c (*this); --*this; return c; }
|
||||
|
||||
unsigned hash () const { return hb_array ((const char *) &v, sizeof (v)).hash (); }
|
||||
HB_INTERNAL static int cmp (const NumType *a, const NumType *b)
|
||||
{ return b->cmp (*a); }
|
||||
HB_INTERNAL static int cmp (const void *a, const void *b)
|
||||
|
||||
+32
-21
@@ -242,7 +242,7 @@ struct tuple_delta_t
|
||||
hb_vector_t<unsigned char> compiled_tuple_header;
|
||||
hb_vector_t<unsigned char> compiled_deltas;
|
||||
|
||||
hb_vector_t<char> compiled_peak_coords;
|
||||
hb_vector_t<F2DOT14> compiled_peak_coords;
|
||||
hb_vector_t<F2DOT14> compiled_interm_coords;
|
||||
|
||||
tuple_delta_t () = default;
|
||||
@@ -374,13 +374,10 @@ struct tuple_delta_t
|
||||
const hb_map_t& axes_old_index_tag_map)
|
||||
{
|
||||
unsigned cur_axis_count = axes_index_map.get_population ();
|
||||
if (unlikely (!compiled_peak_coords.resize (cur_axis_count * F2DOT14::static_size)))
|
||||
if (unlikely (!compiled_peak_coords.resize (cur_axis_count)))
|
||||
return false;
|
||||
if (unlikely (!compiled_interm_coords.resize (2 * cur_axis_count)))
|
||||
return false;
|
||||
auto start_coords = compiled_interm_coords.as_array ().sub_array (0, cur_axis_count);
|
||||
auto end_coords = compiled_interm_coords.as_array (). sub_array (cur_axis_count);
|
||||
bool interms_needed = false;
|
||||
|
||||
hb_array_t<F2DOT14> start_coords, end_coords;
|
||||
|
||||
unsigned orig_axis_count = axes_old_index_tag_map.get_population ();
|
||||
unsigned j = 0;
|
||||
@@ -391,30 +388,44 @@ struct tuple_delta_t
|
||||
|
||||
hb_tag_t axis_tag = axes_old_index_tag_map.get (i);
|
||||
Triple *coords = nullptr;
|
||||
F2DOT14 peak_coord;
|
||||
if (axis_tuples.has (axis_tag, &coords))
|
||||
{
|
||||
float min_val = coords->minimum;
|
||||
float val = coords->middle;
|
||||
float max_val = coords->maximum;
|
||||
|
||||
peak_coord.set_float (val);
|
||||
int16_t peak_val = peak_coord.to_int ();
|
||||
compiled_peak_coords.arrayZ[2 * j] = static_cast<char> (peak_val >> 8);
|
||||
compiled_peak_coords.arrayZ[2 * j + 1] = static_cast<char> (peak_val & 0xFF);
|
||||
compiled_peak_coords.arrayZ[j].set_float (val);
|
||||
|
||||
start_coords[j].set_float (min_val);
|
||||
end_coords[j].set_float (max_val);
|
||||
if (min_val != hb_min (val, 0.f) || max_val != hb_max (val, 0.f))
|
||||
interms_needed = true;
|
||||
{
|
||||
if (!compiled_interm_coords)
|
||||
{
|
||||
if (unlikely (!compiled_interm_coords.resize (2 * cur_axis_count)))
|
||||
return false;
|
||||
start_coords = compiled_interm_coords.as_array ().sub_array (0, cur_axis_count);
|
||||
end_coords = compiled_interm_coords.as_array ().sub_array (cur_axis_count);
|
||||
|
||||
for (unsigned k = 0; k < j; k++)
|
||||
{
|
||||
signed peak = compiled_peak_coords.arrayZ[k].to_int ();
|
||||
if (!peak) continue;
|
||||
start_coords.arrayZ[k].set_int (hb_min (peak, 0));
|
||||
end_coords.arrayZ[k].set_int (hb_max (peak, 0));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (compiled_interm_coords)
|
||||
{
|
||||
start_coords.arrayZ[j].set_float (min_val);
|
||||
end_coords.arrayZ[j].set_float (max_val);
|
||||
}
|
||||
}
|
||||
|
||||
j++;
|
||||
}
|
||||
|
||||
if (!interms_needed)
|
||||
compiled_interm_coords.clear ();
|
||||
|
||||
return !compiled_peak_coords.in_error () && !compiled_interm_coords.in_error ();
|
||||
}
|
||||
|
||||
@@ -424,7 +435,7 @@ struct tuple_delta_t
|
||||
bool compile_tuple_var_header (const hb_map_t& axes_index_map,
|
||||
unsigned points_data_length,
|
||||
const hb_map_t& axes_old_index_tag_map,
|
||||
const hb_hashmap_t<const hb_vector_t<char>*, unsigned>* shared_tuples_idx_map)
|
||||
const hb_hashmap_t<const hb_vector_t<F2DOT14>*, unsigned>* shared_tuples_idx_map)
|
||||
{
|
||||
/* compiled_deltas could be empty after iup delta optimization, we can skip
|
||||
* compiling this tuple and return true */
|
||||
@@ -479,7 +490,7 @@ struct tuple_delta_t
|
||||
{
|
||||
hb_memcpy (&peak_coords[0], &compiled_peak_coords[0], compiled_peak_coords.length * sizeof (compiled_peak_coords[0]));
|
||||
flag |= TupleVariationHeader::TuppleIndex::EmbeddedPeakTuple;
|
||||
return compiled_peak_coords.length / F2DOT14::static_size;
|
||||
return compiled_peak_coords.length;
|
||||
}
|
||||
|
||||
/* if no need to encode intermediate coords, then just return p */
|
||||
@@ -1223,7 +1234,7 @@ struct TupleVariationData
|
||||
const hb_map_t& axes_old_index_tag_map,
|
||||
bool use_shared_points,
|
||||
bool is_gvar = false,
|
||||
const hb_hashmap_t<const hb_vector_t<char>*, unsigned>* shared_tuples_idx_map = nullptr)
|
||||
const hb_hashmap_t<const hb_vector_t<F2DOT14>*, unsigned>* shared_tuples_idx_map = nullptr)
|
||||
{
|
||||
// return true for empty glyph
|
||||
if (!tuple_vars)
|
||||
|
||||
+13
-13
@@ -66,12 +66,12 @@ struct glyph_variations_t
|
||||
|
||||
hb_vector_t<tuple_variations_t> glyph_variations;
|
||||
|
||||
hb_vector_t<char> compiled_shared_tuples;
|
||||
hb_vector_t<F2DOT14> compiled_shared_tuples;
|
||||
private:
|
||||
unsigned shared_tuples_count = 0;
|
||||
|
||||
/* shared coords-> index map after instantiation */
|
||||
hb_hashmap_t<const hb_vector_t<char>*, unsigned> shared_tuples_idx_map;
|
||||
hb_hashmap_t<const hb_vector_t<F2DOT14>*, unsigned> shared_tuples_idx_map;
|
||||
|
||||
public:
|
||||
unsigned compiled_shared_tuples_count () const
|
||||
@@ -172,7 +172,7 @@ struct glyph_variations_t
|
||||
{
|
||||
/* key is pointer to compiled_peak_coords inside each tuple, hashing
|
||||
* function will always deref pointers first */
|
||||
hb_hashmap_t<const hb_vector_t<char>*, unsigned> coords_count_map;
|
||||
hb_hashmap_t<const hb_vector_t<F2DOT14>*, unsigned> coords_count_map;
|
||||
|
||||
/* count the num of shared coords */
|
||||
for (tuple_variations_t& vars: glyph_variations)
|
||||
@@ -193,7 +193,7 @@ struct glyph_variations_t
|
||||
return false;
|
||||
|
||||
/* add only those coords that are used more than once into the vector and sort */
|
||||
hb_vector_t<const hb_vector_t<char>*> shared_coords;
|
||||
hb_vector_t<const hb_vector_t<F2DOT14>*> shared_coords;
|
||||
if (unlikely (!shared_coords.alloc (coords_count_map.get_population ())))
|
||||
return false;
|
||||
|
||||
@@ -207,7 +207,7 @@ struct glyph_variations_t
|
||||
if (!shared_coords) return true;
|
||||
/* sorting based on the coords frequency first (high to low), then compare
|
||||
* the coords bytes */
|
||||
hb_qsort (shared_coords.arrayZ, shared_coords.length, sizeof (hb_vector_t<char>*), _cmp_coords, (void *) (&coords_count_map));
|
||||
hb_qsort (shared_coords.arrayZ, shared_coords.length, sizeof (hb_vector_t<F2DOT14>*), _cmp_coords, (void *) (&coords_count_map));
|
||||
|
||||
/* build shared_coords->idx map and shared tuples byte array */
|
||||
|
||||
@@ -220,7 +220,7 @@ struct glyph_variations_t
|
||||
{
|
||||
shared_tuples_idx_map.set (shared_coords[i], i);
|
||||
/* add a concat() in hb_vector_t? */
|
||||
for (char c : shared_coords[i]->iter ())
|
||||
for (auto c : shared_coords[i]->iter ())
|
||||
compiled_shared_tuples.push (c);
|
||||
}
|
||||
|
||||
@@ -229,13 +229,13 @@ struct glyph_variations_t
|
||||
|
||||
static int _cmp_coords (const void *pa, const void *pb, void *arg)
|
||||
{
|
||||
const hb_hashmap_t<const hb_vector_t<char>*, unsigned>* coords_count_map =
|
||||
reinterpret_cast<const hb_hashmap_t<const hb_vector_t<char>*, unsigned>*> (arg);
|
||||
const hb_hashmap_t<const hb_vector_t<F2DOT14>*, unsigned>* coords_count_map =
|
||||
reinterpret_cast<const hb_hashmap_t<const hb_vector_t<F2DOT14>*, unsigned>*> (arg);
|
||||
|
||||
/* shared_coords is hb_vector_t<const hb_vector_t<char>*> so casting pa/pb
|
||||
/* shared_coords is hb_vector_t<const hb_vector_t<F2DOT14>*> so casting pa/pb
|
||||
* to be a pointer to a pointer */
|
||||
const hb_vector_t<char>** a = reinterpret_cast<const hb_vector_t<char>**> (const_cast<void*>(pa));
|
||||
const hb_vector_t<char>** b = reinterpret_cast<const hb_vector_t<char>**> (const_cast<void*>(pb));
|
||||
const hb_vector_t<F2DOT14>** a = reinterpret_cast<const hb_vector_t<F2DOT14>**> (const_cast<void*>(pa));
|
||||
const hb_vector_t<F2DOT14>** b = reinterpret_cast<const hb_vector_t<F2DOT14>**> (const_cast<void*>(pb));
|
||||
|
||||
bool has_a = coords_count_map->has (*a);
|
||||
bool has_b = coords_count_map->has (*b);
|
||||
@@ -402,9 +402,9 @@ struct gvar_GVAR
|
||||
out->sharedTuples = 0;
|
||||
else
|
||||
{
|
||||
hb_array_t<const char> shared_tuples = glyph_vars.compiled_shared_tuples.as_array ().copy (c);
|
||||
hb_array_t<const F2DOT14> shared_tuples = glyph_vars.compiled_shared_tuples.as_array ().copy (c);
|
||||
if (!shared_tuples.arrayZ) return_trace (false);
|
||||
out->sharedTuples = shared_tuples.arrayZ - (char *) out;
|
||||
out->sharedTuples = (const char *) shared_tuples.arrayZ - (char *) out;
|
||||
}
|
||||
|
||||
char *glyph_var_data = c->start_embed<char> ();
|
||||
|
||||
Reference in new issue
Block a user