Skip to content

Commit

Permalink
[COLR] Implement paint templates
Browse files Browse the repository at this point in the history
  • Loading branch information
behdad committed Aug 3, 2023
1 parent 1d665c2 commit 3b73c70
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/OT/Color/COLR/COLR.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace OT {
struct COLR;

struct Paint;
struct PaintTemplateInstance;

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

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

struct PaintTemplateInstance
{
void closurev1 (hb_colrv1_closure_context_t* c) const;

bool subset (hb_subset_context_t *c,

Check warning on line 1463 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1463

Added line #L1463 was not covered by tests
const VarStoreInstancer &instancer) const
{
TRACE_SUBSET (this);

Check warning on line 1466 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1466

Added line #L1466 was not covered by tests
// XXX
//auto *out = c->serializer->embed (this);
//return_trace (out);
return_trace (false);

Check warning on line 1470 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1470

Added line #L1470 was not covered by tests
}

bool sanitize (hb_sanitize_context_t *c) const

Check warning on line 1473 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1473

Added line #L1473 was not covered by tests
{
TRACE_SANITIZE (this);
return_trace (c->check_struct (this));

Check warning on line 1476 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1475-L1476

Added lines #L1475 - L1476 were not covered by tests
}

void paint_glyph (hb_paint_context_t *c) const

Check warning on line 1479 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1479

Added line #L1479 was not covered by tests
{
c->template_stack.push (this);

Check warning on line 1481 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1481

Added line #L1481 was not covered by tests
c->recurse (this+templatePaint);
c->template_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. */
public:
DEFINE_SIZE_ARRAY (5, arguments);
};

struct PaintTemplateArgument
{
void closurev1 (hb_colrv1_closure_context_t* c) const {}

bool subset (hb_subset_context_t *c,

Check warning on line 1498 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1498

Added line #L1498 was not covered by tests
const VarStoreInstancer &instancer) const
{
TRACE_SUBSET (this);
auto *out = c->serializer->embed (this);
return_trace (out);

Check warning on line 1503 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1501-L1503

Added lines #L1501 - L1503 were not covered by tests
}

bool sanitize (hb_sanitize_context_t *c) const

Check warning on line 1506 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1506

Added line #L1506 was not covered by tests
{
TRACE_SANITIZE (this);
return_trace (c->check_struct (this));

Check warning on line 1509 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1508-L1509

Added lines #L1508 - L1509 were not covered by tests
}

void paint_glyph (hb_paint_context_t *c) const

Check warning on line 1512 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1512

Added line #L1512 was not covered by tests
{
auto *templatePaint = c->template_stack.tail ();
if (!templatePaint) return;
c->recurse (templatePaint+templatePaint->arguments[index]);
}

HBUINT8 format; /* format = 34 */
HBUINT8 index;
public:
DEFINE_SIZE_STATIC (2);

Check warning on line 1522 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1522

Added line #L1522 was not covered by tests
};

struct ClipBoxData
{
int xMin, yMin, xMax, yMax;
Expand Down Expand Up @@ -1780,6 +1848,8 @@ struct Paint
case 30: return_trace (c->dispatch (u.paintformat30, std::forward<Ts> (ds)...));
case 31: return_trace (c->dispatch (u.paintformat31, std::forward<Ts> (ds)...));
case 32: return_trace (c->dispatch (u.paintformat32, std::forward<Ts> (ds)...));
case 33: return_trace (c->dispatch (u.paintformat33, std::forward<Ts> (ds)...));

Check warning on line 1851 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1851

Added line #L1851 was not covered by tests
case 34: return_trace (c->dispatch (u.paintformat34, std::forward<Ts> (ds)...));
default:return_trace (c->default_return_value ());
}
}
Expand Down Expand Up @@ -1819,6 +1889,8 @@ struct Paint
NoVariable<PaintSkewAroundCenter> paintformat30;
Variable<PaintSkewAroundCenter> paintformat31;
PaintComposite paintformat32;
PaintTemplateInstance paintformat33;
PaintTemplateArgument paintformat34;
} u;
public:
DEFINE_SIZE_MIN (2);
Expand Down
4 changes: 4 additions & 0 deletions src/OT/Color/COLR/colrv1-closure.hh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ HB_INTERNAL void PaintComposite::closurev1 (hb_colrv1_closure_context_t* c) cons
(this+src).dispatch (c);
(this+backdrop).dispatch (c);
}
HB_INTERNAL void PaintTemplateInstance::closurev1 (hb_colrv1_closure_context_t* c) const

Check warning on line 103 in src/OT/Color/COLR/colrv1-closure.hh

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/colrv1-closure.hh#L103

Added line #L103 was not covered by tests
{
(this+templatePaint).dispatch (c);
}

} /* namespace OT */

Expand Down

0 comments on commit 3b73c70

Please sign in to comment.