[COLR] Apply variations in get_extent

This commit is contained in:
Behdad Esfahbod 2022-12-11 13:40:53 -07:00
parent 68964efa55
commit 9a3f0be291
2 changed files with 37 additions and 7 deletions

View File

@ -184,6 +184,7 @@ struct Variable
protected:
T value;
public:
VarIdx varIdxBase;
public:
DEFINE_SIZE_STATIC (4 + T::static_size);
@ -928,15 +929,27 @@ struct ClipBox
}
}
bool get_extents (hb_glyph_extents_t *extents) const
bool get_extents (hb_glyph_extents_t *extents,
const VariationStore &varStore,
hb_array_t<int> coords) const
{
switch (u.format) {
case 1:
case 2: // TODO variations
case 2:
extents->x_bearing = u.format1.xMin;
extents->y_bearing = u.format1.yMax;
extents->width = u.format1.xMax - u.format1.xMin;
extents->height = u.format1.yMin - u.format1.yMax;
if (u.format == 2 && coords)
{
uint32_t varIdx = u.format2.varIdxBase;
extents->x_bearing += _hb_roundf (varStore.get_delta (varIdx , coords));
extents->y_bearing += _hb_roundf (varStore.get_delta (varIdx+1, coords));
extents->width += _hb_roundf (varStore.get_delta (varIdx+2, coords));
extents->height += _hb_roundf (varStore.get_delta (varIdx+3, coords));
}
return true;
default:
return false;
@ -971,9 +984,12 @@ struct ClipRecord
return_trace (c->check_struct (this) && clipBox.sanitize (c, base));
}
bool get_extents (hb_glyph_extents_t *extents, const void *base) const
bool get_extents (hb_glyph_extents_t *extents,
const void *base,
const VariationStore &varStore,
hb_array_t<int> coords) const
{
return (base+clipBox).get_extents (extents);
return (base+clipBox).get_extents (extents, varStore, coords);
}
public:
@ -1077,12 +1093,15 @@ struct ClipList
}
bool
get_extents (hb_codepoint_t gid, hb_glyph_extents_t *extents) const
get_extents (hb_codepoint_t gid,
hb_glyph_extents_t *extents,
const VariationStore &varStore,
hb_array_t<int> coords) const
{
auto *rec = clips.as_array ().bsearch (gid);
if (rec)
{
rec->get_extents (extents, this);
rec->get_extents (extents, this, varStore, coords);
return true;
}
return false;
@ -1554,7 +1573,10 @@ struct COLR
{
if (version != 1)
return false;
if ((this+clipList).get_extents (glyph, extents))
if ((this+clipList).get_extents (glyph,
extents,
this+varStore,
hb_array (font->coords, font->num_coords)))
{
extents->x_bearing = font->em_scale_x (extents->x_bearing);
extents->y_bearing = font->em_scale_x (extents->y_bearing);

View File

@ -2715,6 +2715,14 @@ struct VariationStore
unsigned int inner = index & 0xFFFF;
return get_delta (outer, inner, coords, coord_count, cache);
}
float get_delta (unsigned int index,
hb_array_t<int> coords,
VarRegionList::cache_t *cache = nullptr) const
{
return get_delta (index,
coords.arrayZ, coords.length,
cache);
}
bool sanitize (hb_sanitize_context_t *c) const
{