Add hb_array_t::lfind
This commit is contained in:
parent
a783840789
commit
08d57d9eca
|
@ -129,20 +129,27 @@ struct hb_array_t : hb_iter_with_fallback_t<hb_array_t<Type>, Type&>
|
|||
template <typename T>
|
||||
Type *lsearch (const T &x, Type *not_found = nullptr)
|
||||
{
|
||||
unsigned int count = length;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
if (!this->arrayZ[i].cmp (x))
|
||||
return &this->arrayZ[i];
|
||||
return not_found;
|
||||
unsigned i;
|
||||
return lfind (x, &i) ? &this->arrayZ[i] : not_found;
|
||||
}
|
||||
template <typename T>
|
||||
const Type *lsearch (const T &x, const Type *not_found = nullptr) const
|
||||
{
|
||||
unsigned int count = length;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
unsigned i;
|
||||
return lfind (x, &i) ? &this->arrayZ[i] : not_found;
|
||||
}
|
||||
template <typename T>
|
||||
bool lfind (const T &x, unsigned *pos = nullptr) const
|
||||
{
|
||||
for (unsigned i = 0; i < length; ++i)
|
||||
if (!this->arrayZ[i].cmp (x))
|
||||
return &this->arrayZ[i];
|
||||
return not_found;
|
||||
{
|
||||
if (pos)
|
||||
*pos = i;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
hb_sorted_array_t<Type> qsort (int (*cmp_)(const void*, const void*))
|
||||
|
|
|
@ -442,6 +442,9 @@ struct UnsizedArrayOf
|
|||
template <typename T>
|
||||
const Type &lsearch (unsigned int len, const T &x, const Type ¬_found = Null (Type)) const
|
||||
{ return *as_array (len).lsearch (x, ¬_found); }
|
||||
template <typename T>
|
||||
bool lfind (unsigned int len, const T &x, unsigned *pos = nullptr) const
|
||||
{ return as_array (len).lfind (x, pos); }
|
||||
|
||||
void qsort (unsigned int len, unsigned int start = 0, unsigned int end = (unsigned int) -1)
|
||||
{ as_array (len).qsort (start, end); }
|
||||
|
@ -667,6 +670,9 @@ struct ArrayOf
|
|||
template <typename T>
|
||||
const Type &lsearch (const T &x, const Type ¬_found = Null (Type)) const
|
||||
{ return *as_array ().lsearch (x, ¬_found); }
|
||||
template <typename T>
|
||||
bool lfind (const T &x, unsigned *pos = nullptr) const
|
||||
{ return as_array ().lfind (x, pos); }
|
||||
|
||||
void qsort (unsigned int start = 0, unsigned int end = (unsigned int) -1)
|
||||
{ as_array ().qsort (start, end); }
|
||||
|
|
|
@ -292,28 +292,15 @@ struct STAT
|
|||
|
||||
bool has_data () const { return version.to_int (); }
|
||||
|
||||
bool find_axis_index (hb_tag_t tag, unsigned int *axis_index) const
|
||||
{
|
||||
hb_array_t<const StatAxisRecord> axes = get_design_axes ();
|
||||
/* TODO: add lfind in hb_array_t and use it in here and fvar's find_axis_info */
|
||||
for (unsigned int i = 0; i < axes.length; i++)
|
||||
if (!axes[i].cmp (tag))
|
||||
{
|
||||
*axis_index = i;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get_value (hb_tag_t tag, float *value) const
|
||||
{
|
||||
unsigned int axis_index;
|
||||
if (!find_axis_index (tag, &axis_index)) return false;
|
||||
if (!get_design_axes ().lfind (tag, &axis_index)) return false;
|
||||
|
||||
hb_array_t<const OffsetTo<AxisValue>> axis_values = get_axis_value_offsets ();
|
||||
for (unsigned int i = 0; i < axis_values.length; i++)
|
||||
{
|
||||
const AxisValue& axis_value = (this + axis_values[i]);
|
||||
const AxisValue& axis_value = this+axis_values[i];
|
||||
if (axis_value.get_axis_index () == axis_index)
|
||||
{
|
||||
if (value)
|
||||
|
|
|
@ -70,6 +70,8 @@ struct InstanceRecord
|
|||
|
||||
struct AxisRecord
|
||||
{
|
||||
int cmp (hb_tag_t key) const { return axisTag.cmp (key); }
|
||||
|
||||
enum
|
||||
{
|
||||
AXIS_FLAG_HIDDEN = 0x0001,
|
||||
|
@ -171,18 +173,11 @@ struct fvar
|
|||
bool
|
||||
find_axis_deprecated (hb_tag_t tag, unsigned *axis_index, hb_ot_var_axis_t *info) const
|
||||
{
|
||||
unsigned i;
|
||||
if (!axis_index) axis_index = &i;
|
||||
*axis_index = HB_OT_VAR_NO_AXIS_INDEX;
|
||||
hb_array_t<const AxisRecord> axes = get_axes ();
|
||||
for (unsigned i = 0; i < axes.length; i++)
|
||||
if (axes[i].axisTag == tag)
|
||||
{
|
||||
if (axis_index)
|
||||
*axis_index = i;
|
||||
axes[i].get_axis_deprecated (info);
|
||||
return true;
|
||||
}
|
||||
if (axis_index)
|
||||
*axis_index = HB_OT_VAR_NO_AXIS_INDEX;
|
||||
return false;
|
||||
return axes.lfind (tag, axis_index) && (axes[*axis_index].get_axis_deprecated (info), true);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -190,13 +185,8 @@ struct fvar
|
|||
find_axis_info (hb_tag_t tag, hb_ot_var_axis_info_t *info) const
|
||||
{
|
||||
hb_array_t<const AxisRecord> axes = get_axes ();
|
||||
for (unsigned i = 0; i < axes.length; i++)
|
||||
if (axes[i].axisTag == tag)
|
||||
{
|
||||
axes[i].get_axis_info (i, info);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
unsigned i;
|
||||
return axes.lfind (tag, &i) && (axes[i].get_axis_info (i, info), true);
|
||||
}
|
||||
|
||||
int normalize_axis_value (unsigned int axis_index, float v) const
|
||||
|
|
|
@ -277,6 +277,9 @@ struct hb_vector_t
|
|||
template <typename T>
|
||||
const Type *lsearch (const T &x, const Type *not_found = nullptr) const
|
||||
{ return as_array ().lsearch (x, not_found); }
|
||||
template <typename T>
|
||||
bool lfind (const T &x, unsigned *pos = nullptr) const
|
||||
{ return as_array ().lfind (x, pos); }
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
|
|
Loading…
Reference in New Issue