Skip to content

Commit

Permalink
[COLR] Make template arguments sharable
Browse files Browse the repository at this point in the history
  • Loading branch information
behdad committed Aug 4, 2023
1 parent 7d23f7c commit 7e1c71c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
25 changes: 15 additions & 10 deletions src/OT/Color/COLR/COLR.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace OT {
struct COLR;

struct Paint;
struct PaintTemplateInstance;
struct TemplateArgumentList;

struct hb_paint_context_t :
hb_dispatch_context_t<hb_paint_context_t>
Expand All @@ -69,7 +69,7 @@ public:
unsigned int palette_index;
hb_color_t foreground;
VarStoreInstancer &instancer;
hb_vector_t<const PaintTemplateInstance *> template_stack;
hb_vector_t<const TemplateArgumentList *> template_arguments_stack;
int depth_left = HB_MAX_NESTING_LEVEL;
int edge_count = HB_COLRV1_MAX_EDGE_COUNT;

Expand Down Expand Up @@ -1456,6 +1456,8 @@ struct PaintComposite
DEFINE_SIZE_STATIC (8);
};

struct TemplateArgumentList : List8OfOffsetTo<Paint, HBUINT24> {};

struct PaintTemplateInstance
{
void closurev1 (hb_colrv1_closure_context_t* c) const;
Expand All @@ -1470,6 +1472,8 @@ struct PaintTemplateInstance
if (unlikely (!out->templatePaint.serialize_subset (c, templatePaint, this, instancer)))
return_trace (false);

// XXX
/*
for (auto _ : hb_zip (arguments, out->arguments.writer ()))
{
const auto &inPaint = _.first;
Expand All @@ -1478,6 +1482,7 @@ struct PaintTemplateInstance
if (unlikely (!outPaint.serialize_subset (c, inPaint, this, instancer)))
return_trace (false);
}
*/

return_trace (true);
}
Expand All @@ -1492,17 +1497,17 @@ struct PaintTemplateInstance

void paint_glyph (hb_paint_context_t *c) const
{
c->template_stack.push (this);
c->template_arguments_stack.push (&(this+arguments));
c->recurse (this+templatePaint);
c->template_stack.pop ();
c->template_arguments_stack.pop ();
}

HBUINT8 format; /* format = 33 */
Offset24To<Paint> templatePaint; /* Offset (from beginning of PaintTemplateInstance table) to Paint subtable. */
ArrayOf<Offset24To<Paint>, HBUINT8>
arguments; /* Array of offsets (from beginning of PaintTemplateInstance table) to Paint subtables. */
Offset24To<TemplateArgumentList>
arguments; /* Offset to TemplateArgumentList (from beginning of PaintTemplateInstance table). */
public:
DEFINE_SIZE_ARRAY_SIZED (5, arguments);
DEFINE_SIZE_STATIC (7);
};

struct PaintTemplateArgument
Expand All @@ -1524,9 +1529,9 @@ struct PaintTemplateArgument

void paint_glyph (hb_paint_context_t *c) const
{
auto *templatePaint = c->template_stack.tail ();
if (!templatePaint) return;
c->recurse (templatePaint+templatePaint->arguments[index]);
auto *arguments = c->template_arguments_stack.tail ();
if (!arguments) return;
c->recurse ((*arguments)[index]);
}

HBUINT8 format; /* format = 34 */
Expand Down
6 changes: 4 additions & 2 deletions src/OT/Color/COLR/colrv1-closure.hh
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ HB_INTERNAL void PaintComposite::closurev1 (hb_colrv1_closure_context_t* c) cons
HB_INTERNAL void PaintTemplateInstance::closurev1 (hb_colrv1_closure_context_t* c) const
{
(this+templatePaint).dispatch (c);
for (auto &argument : arguments)
(this+argument).dispatch (c);
auto &args = this+arguments;
unsigned count = args.len;
for (unsigned i = 0; i < count; i++)
args[i].dispatch (c);
}

} /* namespace OT */
Expand Down
14 changes: 10 additions & 4 deletions src/hb-open-type.hh
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,8 @@ template <typename Type> using Array16OfOffset32To = ArrayOf<OffsetTo<Type, HBUI
template <typename Type> using Array32OfOffset32To = ArrayOf<OffsetTo<Type, HBUINT32>, HBUINT32>;

/* Array of offsets relative to the beginning of the array itself. */
template <typename Type, typename OffsetType>
struct List16OfOffsetTo : ArrayOf<OffsetTo<Type, OffsetType>, HBUINT16>
template <typename Type, typename LengthType, typename OffsetType>
struct ListOfOffsetTo : ArrayOf<OffsetTo<Type, OffsetType>, LengthType>
{
const Type& operator [] (int i_) const
{
Expand All @@ -776,7 +776,7 @@ struct List16OfOffsetTo : ArrayOf<OffsetTo<Type, OffsetType>, HBUINT16>
bool subset (hb_subset_context_t *c) const
{
TRACE_SUBSET (this);
struct List16OfOffsetTo *out = c->serializer->embed (*this);
struct ListOfOffsetTo *out = c->serializer->embed (*this);
if (unlikely (!out)) return_trace (false);
unsigned int count = this->len;
for (unsigned int i = 0; i < count; i++)
Expand All @@ -788,10 +788,16 @@ struct List16OfOffsetTo : ArrayOf<OffsetTo<Type, OffsetType>, HBUINT16>
bool sanitize (hb_sanitize_context_t *c, Ts&&... ds) const
{
TRACE_SANITIZE (this);
return_trace ((Array16Of<OffsetTo<Type, OffsetType>>::sanitize (c, this, std::forward<Ts> (ds)...)));
return_trace ((ArrayOf<OffsetTo<Type, OffsetType>, LengthType>::sanitize (c, this, std::forward<Ts> (ds)...)));
}
};

template <typename Type, typename OffsetType>
using List8OfOffsetTo = ListOfOffsetTo<Type, HBUINT8, OffsetType>;

template <typename Type, typename OffsetType>
using List16OfOffsetTo = ListOfOffsetTo<Type, HBUINT16, OffsetType>;

template <typename Type>
using List16OfOffset16To = List16OfOffsetTo<Type, HBUINT16>;

Expand Down

0 comments on commit 7e1c71c

Please sign in to comment.