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