Merge pull request #3928 from harfbuzz/colrv1-extents
COLRv1: use ClipBoxes for extents
This commit is contained in:
commit
199345eb29
|
@ -184,6 +184,7 @@ struct Variable
|
|||
|
||||
protected:
|
||||
T value;
|
||||
public:
|
||||
VarIdx varIdxBase;
|
||||
public:
|
||||
DEFINE_SIZE_STATIC (4 + T::static_size);
|
||||
|
@ -928,6 +929,32 @@ struct ClipBox
|
|||
}
|
||||
}
|
||||
|
||||
bool get_extents (hb_glyph_extents_t *extents,
|
||||
const VarStoreInstancer &instancer) const
|
||||
{
|
||||
switch (u.format) {
|
||||
case 1:
|
||||
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 && instancer && u.format2.varIdxBase != HB_OT_LAYOUT_NO_VARIATIONS_INDEX)
|
||||
{
|
||||
uint32_t varIdx = u.format2.varIdxBase;
|
||||
extents->x_bearing += _hb_roundf (instancer (varIdx+0));
|
||||
extents->y_bearing += _hb_roundf (instancer (varIdx+1));
|
||||
extents->width += _hb_roundf (instancer (varIdx+2));
|
||||
extents->height += _hb_roundf (instancer (varIdx+3));
|
||||
}
|
||||
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
union {
|
||||
HBUINT8 format; /* Format identifier */
|
||||
|
@ -938,6 +965,9 @@ struct ClipBox
|
|||
|
||||
struct ClipRecord
|
||||
{
|
||||
int cmp (hb_codepoint_t g) const
|
||||
{ return g < startGlyphID ? -1 : g <= endGlyphID ? 0 : +1; }
|
||||
|
||||
ClipRecord* copy (hb_serialize_context_t *c, const void *base) const
|
||||
{
|
||||
TRACE_SERIALIZE (this);
|
||||
|
@ -953,6 +983,13 @@ struct ClipRecord
|
|||
return_trace (c->check_struct (this) && clipBox.sanitize (c, base));
|
||||
}
|
||||
|
||||
bool get_extents (hb_glyph_extents_t *extents,
|
||||
const void *base,
|
||||
const VarStoreInstancer &instancer) const
|
||||
{
|
||||
return (base+clipBox).get_extents (extents, instancer);
|
||||
}
|
||||
|
||||
public:
|
||||
HBUINT16 startGlyphID; // first gid clip applies to
|
||||
HBUINT16 endGlyphID; // last gid clip applies to, inclusive
|
||||
|
@ -960,6 +997,7 @@ struct ClipRecord
|
|||
public:
|
||||
DEFINE_SIZE_STATIC (7);
|
||||
};
|
||||
DECLARE_NULL_NAMESPACE_BYTES (OT, ClipRecord);
|
||||
|
||||
struct ClipList
|
||||
{
|
||||
|
@ -1052,6 +1090,20 @@ struct ClipList
|
|||
return_trace (c->check_struct (this) && clips.sanitize (c, this));
|
||||
}
|
||||
|
||||
bool
|
||||
get_extents (hb_codepoint_t gid,
|
||||
hb_glyph_extents_t *extents,
|
||||
const VarStoreInstancer &instancer) const
|
||||
{
|
||||
auto *rec = clips.as_array ().bsearch (gid);
|
||||
if (rec)
|
||||
{
|
||||
rec->get_extents (extents, this, instancer);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
HBUINT8 format; // Set to 1.
|
||||
SortedArray32Of<ClipRecord> clips; // Clip records, sorted by startGlyphID
|
||||
public:
|
||||
|
@ -1513,6 +1565,30 @@ struct COLR
|
|||
return_trace (true);
|
||||
}
|
||||
|
||||
bool
|
||||
get_extents (hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents) const
|
||||
{
|
||||
if (version != 1)
|
||||
return false;
|
||||
|
||||
VarStoreInstancer instancer (this+varStore,
|
||||
this+varIdxMap,
|
||||
hb_array (font->coords, font->num_coords));
|
||||
|
||||
if ((this+clipList).get_extents (glyph,
|
||||
extents,
|
||||
instancer))
|
||||
{
|
||||
extents->x_bearing = font->em_scale_x (extents->x_bearing);
|
||||
extents->y_bearing = font->em_scale_x (extents->y_bearing);
|
||||
extents->width = font->em_scale_x (extents->width);
|
||||
extents->height = font->em_scale_x (extents->height);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
HBUINT16 version; /* Table version number (starts at 0). */
|
||||
HBUINT16 numBaseGlyphs; /* Number of Base Glyph Records. */
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "hb-ot-vorg-table.hh"
|
||||
#include "hb-ot-color-cbdt-table.hh"
|
||||
#include "hb-ot-color-sbix-table.hh"
|
||||
#include "hb-ot-color-colr-table.hh"
|
||||
|
||||
|
||||
/**
|
||||
|
@ -349,6 +350,9 @@ hb_ot_get_glyph_extents (hb_font_t *font,
|
|||
#if !defined(HB_NO_OT_FONT_BITMAP) && !defined(HB_NO_COLOR)
|
||||
if (ot_face->sbix->get_extents (font, glyph, extents)) return true;
|
||||
if (ot_face->CBDT->get_extents (font, glyph, extents)) return true;
|
||||
#endif
|
||||
#if !defined(HB_NO_COLOR)
|
||||
if (ot_face->COLR->get_extents (font, glyph, extents)) return true;
|
||||
#endif
|
||||
if (ot_face->glyf->get_extents (font, glyph, extents)) return true;
|
||||
#ifndef HB_NO_OT_FONT_CFF
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -219,6 +219,25 @@ struct DeltaSetIndexMap
|
|||
DEFINE_SIZE_UNION (1, format);
|
||||
};
|
||||
|
||||
|
||||
struct VarStoreInstancer
|
||||
{
|
||||
VarStoreInstancer (const VariationStore &varStore,
|
||||
const DeltaSetIndexMap &varIdxMap,
|
||||
hb_array_t<int> coords) :
|
||||
varStore (varStore), varIdxMap (varIdxMap), coords (coords) {}
|
||||
|
||||
operator bool () const { return bool (coords); }
|
||||
|
||||
float operator() (uint32_t varIdx) const
|
||||
{ return varStore.get_delta (varIdxMap.map (varIdx), coords); }
|
||||
|
||||
const VariationStore &varStore;
|
||||
const DeltaSetIndexMap &varIdxMap;
|
||||
hb_array_t<int> coords;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace OT */
|
||||
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "hb-aat-layout-feat-table.hh"
|
||||
#include "hb-ot-layout-common.hh"
|
||||
#include "hb-ot-cmap-table.hh"
|
||||
#include "hb-ot-color-colr-table.hh"
|
||||
#include "hb-ot-glyf-table.hh"
|
||||
#include "hb-ot-head-table.hh"
|
||||
#include "hb-ot-maxp-table.hh"
|
||||
|
@ -47,6 +48,7 @@ DEFINE_NULL_NAMESPACE_BYTES (OT, Index) = {0xFF,0xFF};
|
|||
DEFINE_NULL_NAMESPACE_BYTES (OT, VarIdx) = {0xFF,0xFF,0xFF,0xFF};
|
||||
DEFINE_NULL_NAMESPACE_BYTES (OT, LangSys) = {0x00,0x00, 0xFF,0xFF, 0x00,0x00};
|
||||
DEFINE_NULL_NAMESPACE_BYTES (OT, RangeRecord) = {0x01};
|
||||
DEFINE_NULL_NAMESPACE_BYTES (OT, ClipRecord) = {0x01};
|
||||
DEFINE_NULL_NAMESPACE_BYTES (OT, CmapSubtableLongGroup) = {0x00,0x00,0x00,0x01, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00};
|
||||
DEFINE_NULL_NAMESPACE_BYTES (AAT, SettingName) = {0xFF,0xFF, 0xFF,0xFF};
|
||||
DEFINE_NULL_NAMESPACE_BYTES (AAT, Lookup) = {0xFF,0xFF};
|
||||
|
|
Loading…
Reference in New Issue