Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COLRv2 #4363

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

COLRv2 #4363

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 182 additions & 1 deletion src/OT/Color/COLR/COLR.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
struct COLR;

struct Paint;
struct PaintTemplateInstance;

struct hb_paint_context_t :
hb_dispatch_context_t<hb_paint_context_t>
Expand All @@ -65,23 +66,27 @@
hb_paint_funcs_t *funcs;
void *data;
hb_font_t *font;
hb_codepoint_t gid = HB_CODEPOINT_INVALID;
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;

hb_paint_context_t (const void *base_,
hb_paint_funcs_t *funcs_,
void *data_,
hb_font_t *font_,
hb_codepoint_t gid_,
unsigned int palette_,
hb_color_t foreground_,
VarStoreInstancer &instancer_) :
base (base_),
funcs (funcs_),
data (data_),
font (font_),
gid (gid_),
palette_index (palette_),
foreground (foreground_),
instancer (instancer_)
Expand Down Expand Up @@ -157,6 +162,7 @@
{ palette_indices->add (palette_index); }

public:
hb_codepoint_t gid = HB_CODEPOINT_INVALID;
const void *base;
hb_set_t visited_paint;
hb_set_t *glyphs;
Expand All @@ -175,6 +181,8 @@
palette_indices (palette_indices_),
nesting_level_left (nesting_level_left_)
{}

void set_gid (hb_codepoint_t gid_) { gid = gid_; }
};

struct LayerRecord
Expand Down Expand Up @@ -1454,6 +1462,170 @@
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 1469 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

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

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

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#L1472-L1473

Added lines #L1472 - L1473 were not covered by tests
if (unlikely (!out)) return_trace (false);

if (unlikely (!out->templatePaint.serialize_subset (c, templatePaint, this, instancer)))
return_trace (false);

for (auto _ : hb_zip (arguments, out->arguments.writer ()))
{
const auto &inPaint = _.first;
auto &outPaint = _.second;

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L1481 - L1482 were not covered by tests

if (unlikely (!outPaint.serialize_subset (c, inPaint, this, instancer)))
return_trace (false);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1485 was not covered by tests
}

return_trace (true);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1488 was not covered by tests
}

bool sanitize (hb_sanitize_context_t *c) const

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1491 was not covered by tests
{
TRACE_SANITIZE (this);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1493 was not covered by tests
return_trace (c->check_struct (this) &&
templatePaint.sanitize (c, this) &&
arguments.sanitize (c, this));
}

void paint_glyph (hb_paint_context_t *c) const

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1501 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_SIZED (5, arguments);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1511 was not covered by tests
};

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

bool subset (hb_subset_context_t *c,

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

View check run for this annotation

Codecov / codecov/patch

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

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

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#L1521-L1522

Added lines #L1521 - L1522 were not covered by tests
}

bool sanitize (hb_sanitize_context_t *c) const

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1527-L1528

Added lines #L1527 - L1528 were not covered by tests
}

void paint_glyph (hb_paint_context_t *c) const

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1531 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 1541 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1541 was not covered by tests
};

// Paint a non-COLR glyph with same root glyph ID, filled as indicated by paint.
struct PaintGlyphSelf
{
void closurev1 (hb_colrv1_closure_context_t* c) const;

bool subset (hb_subset_context_t *c,

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1552-L1553

Added lines #L1552 - L1553 were not covered by tests
if (unlikely (!out)) return_trace (false);

return_trace (out->paint.serialize_subset (c, paint, this, instancer));

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1556 was not covered by tests
}

bool sanitize (hb_sanitize_context_t *c) const

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1559 was not covered by tests
{
TRACE_SANITIZE (this);
return_trace (paint.sanitize (c, this));

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

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1561-L1562

Added lines #L1561 - L1562 were not covered by tests
}

void paint_glyph (hb_paint_context_t *c) const

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1565 was not covered by tests
{
c->funcs->push_inverse_root_transform (c->data, c->font);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1567 was not covered by tests
c->funcs->push_clip_glyph (c->data, c->gid, c->font);
c->funcs->push_root_transform (c->data, c->font);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1569 was not covered by tests
c->recurse (this+paint);
c->funcs->pop_transform (c->data);
c->funcs->pop_clip (c->data);
c->funcs->pop_transform (c->data);
}

HBUINT8 format; /* format = 35 */
Offset24To<Paint> paint; /* Offset (from beginning of PaintGlyph table) to Paint subtable. */
public:
DEFINE_SIZE_STATIC (4);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1579 was not covered by tests
};

// Paint a non-COLR glyph with glyph ID relative to the root glyph ID, filled as indicated by paint.
struct PaintGlyphDelta
{
void closurev1 (hb_colrv1_closure_context_t* c) const;

bool subset (hb_subset_context_t *c,

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1590-L1591

Added lines #L1590 - L1591 were not covered by tests
if (unlikely (!out)) return_trace (false);

#if 0
XXX
unsigned delta = ...
if (! c->serializer->check_assign (out->delta, c->plan->glyph_map->get (gid),
HB_SERIALIZE_ERROR_INT_OVERFLOW))
return_trace (false);
#endif

return_trace (out->paint.serialize_subset (c, paint, this, instancer));

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1602 was not covered by tests
}

bool sanitize (hb_sanitize_context_t *c) const

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1605 was not covered by tests
{
TRACE_SANITIZE (this);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1607 was not covered by tests
return_trace (c->check_struct (this) && paint.sanitize (c, this));
}

void paint_glyph (hb_paint_context_t *c) const

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1611 was not covered by tests
{
c->funcs->push_inverse_root_transform (c->data, c->font);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1613 was not covered by tests
c->funcs->push_clip_glyph (c->data, (c->gid + delta) % 65536, c->font);
c->funcs->push_root_transform (c->data, c->font);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1615 was not covered by tests
c->recurse (this+paint);
c->funcs->pop_transform (c->data);
c->funcs->pop_clip (c->data);
c->funcs->pop_transform (c->data);
}

HBUINT8 format; /* format = 10 */
Offset24To<Paint> paint; /* Offset (from beginning of PaintGlyph table) to Paint subtable. */
HBUINT16 delta;
public:
DEFINE_SIZE_STATIC (6);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1626 was not covered by tests
};

struct ClipBoxData
{
int xMin, yMin, xMax, yMax;
Expand Down Expand Up @@ -1780,6 +1952,10 @@
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 1955 in src/OT/Color/COLR/COLR.hh

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1955 was not covered by tests
case 34: return_trace (c->dispatch (u.paintformat34, std::forward<Ts> (ds)...));
case 35: return_trace (c->dispatch (u.paintformat35, std::forward<Ts> (ds)...));
case 36: return_trace (c->dispatch (u.paintformat36, std::forward<Ts> (ds)...));

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

View check run for this annotation

Codecov / codecov/patch

src/OT/Color/COLR/COLR.hh#L1957-L1958

Added lines #L1957 - L1958 were not covered by tests
default:return_trace (c->default_return_value ());
}
}
Expand Down Expand Up @@ -1819,6 +1995,10 @@
NoVariable<PaintSkewAroundCenter> paintformat30;
Variable<PaintSkewAroundCenter> paintformat31;
PaintComposite paintformat32;
PaintTemplateInstance paintformat33;
PaintTemplateArgument paintformat34;
PaintGlyphSelf paintformat35;
PaintGlyphDelta paintformat36;
} u;
public:
DEFINE_SIZE_MIN (2);
Expand Down Expand Up @@ -2017,6 +2197,7 @@
unsigned gid = baseglyph_paintrecord.glyphId;
if (!glyphset->has (gid)) continue;

c.set_gid (gid);
const Paint &paint = &baseglyph_paintrecords+baseglyph_paintrecord.paint;
paint.dispatch (&c);
}
Expand Down Expand Up @@ -2283,7 +2464,7 @@
VarStoreInstancer instancer (&(this+varStore),
&(this+varIdxMap),
hb_array (font->coords, font->num_coords));
hb_paint_context_t c (this, funcs, data, font, palette_index, foreground, instancer);
hb_paint_context_t c (this, funcs, data, font, glyph, palette_index, foreground, instancer);

if (version == 1)
{
Expand Down
17 changes: 17 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,23 @@
(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);
for (auto &argument : arguments)
(this+argument).dispatch (c);
}
HB_INTERNAL void PaintGlyphSelf::closurev1 (hb_colrv1_closure_context_t* c) const

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L109 was not covered by tests
{
c->add_glyph (c->gid);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L111 was not covered by tests
(this+paint).dispatch (c);
}
HB_INTERNAL void PaintGlyphDelta::closurev1 (hb_colrv1_closure_context_t* c) const

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L114 was not covered by tests
{
c->add_glyph ((c->gid = delta) % 65536);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L116 was not covered by tests
(this+paint).dispatch (c);
}


} /* namespace OT */

Expand Down