[hvgl] Add IndexOf<>

This commit is contained in:
Behdad Esfahbod committed 2025-03-02 16:56:38 -07:00
1 parent e71d56c5c1
commit a438ea6252
1 file changed
+21 -1
+21 -1
View File
@@ -395,6 +395,26 @@ struct Index
DEFINE_SIZE_MIN (4);
};
template <typename Type>
struct IndexOf : Index
{
public:
Type get (unsigned index, unsigned count) const
{
hb_ubytes_t data = Index::get (index, count);
hb_sanitize_context_t c (data.begin (), data.end ());
Type &item = *reinterpret_cast<Type *> (data.begin ());
if (unlikely (!item.sanitize (c))) return Null(Type);
return item;
}
bool sanitize (hb_sanitize_context_t *c, unsigned count) const
{ return Index::sanitize (c, count); }
};
using PartsIndex = IndexOf<Part>;
struct hvgl
{
public:
@@ -405,7 +425,7 @@ struct hvgl
if (unlikely (!c->check_struct (this))) return_trace (false);
hb_barrier ();
const auto &parts = StructAtOffset<Index> (this, partsOff);
const auto &parts = StructAtOffset<PartsIndex> (this, partsOff);
if (unlikely (!parts.sanitize (c, (unsigned) partCount))) return_trace (false);
return_trace (true);