[aat] First sketch at using hb_set_digest_t

They are not cached in an accelerator yet.
pull/4711/head
Behdad Esfahbod 10 months ago
parent 5158255807
commit 5a405b310e
  1. 100
      src/hb-aat-layout-common.hh
  2. 25
      src/hb-aat-layout-kerx-table.hh

@ -95,6 +95,13 @@ struct LookupFormat0
return &arrayZ[glyph_id]; return &arrayZ[glyph_id];
} }
template <typename set_t>
void collect_glyphs (set_t &glyphs, unsigned num_glyphs) const
{
for (unsigned int i = 0; i < num_glyphs; i++)
glyphs.add (i);
}
bool sanitize (hb_sanitize_context_t *c) const bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
@ -123,6 +130,12 @@ struct LookupSegmentSingle
int cmp (hb_codepoint_t g) const int cmp (hb_codepoint_t g) const
{ return g < first ? -1 : g <= last ? 0 : +1 ; } { return g < first ? -1 : g <= last ? 0 : +1 ; }
template <typename set_t>
void collect_glyphs (set_t &glyphs) const
{
glyphs.add_range (first, last);
}
bool sanitize (hb_sanitize_context_t *c) const bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
@ -153,6 +166,14 @@ struct LookupFormat2
return v ? &v->value : nullptr; return v ? &v->value : nullptr;
} }
template <typename set_t>
void collect_glyphs (set_t &glyphs) const
{
unsigned count = segments.get_length ();
for (unsigned int i = 0; i < count; i++)
segments[i].collect_glyphs (glyphs);
}
bool sanitize (hb_sanitize_context_t *c) const bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
@ -184,6 +205,12 @@ struct LookupSegmentArray
return first <= glyph_id && glyph_id <= last ? &(base+valuesZ)[glyph_id - first] : nullptr; return first <= glyph_id && glyph_id <= last ? &(base+valuesZ)[glyph_id - first] : nullptr;
} }
template <typename set_t>
void collect_glyphs (set_t &glyphs) const
{
glyphs.add_range (first, last);
}
int cmp (hb_codepoint_t g) const int cmp (hb_codepoint_t g) const
{ return g < first ? -1 : g <= last ? 0 : +1; } { return g < first ? -1 : g <= last ? 0 : +1; }
@ -226,6 +253,14 @@ struct LookupFormat4
return v ? v->get_value (glyph_id, this) : nullptr; return v ? v->get_value (glyph_id, this) : nullptr;
} }
template <typename set_t>
void collect_glyphs (set_t &glyphs) const
{
unsigned count = segments.get_length ();
for (unsigned i = 0; i < count; i++)
segments[i].collect_glyphs (glyphs);
}
bool sanitize (hb_sanitize_context_t *c) const bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
@ -254,6 +289,12 @@ struct LookupSingle
int cmp (hb_codepoint_t g) const { return glyph.cmp (g); } int cmp (hb_codepoint_t g) const { return glyph.cmp (g); }
template <typename set_t>
void collect_glyphs (set_t &glyphs) const
{
glyphs.add (glyph);
}
bool sanitize (hb_sanitize_context_t *c) const bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
@ -283,6 +324,14 @@ struct LookupFormat6
return v ? &v->value : nullptr; return v ? &v->value : nullptr;
} }
template <typename set_t>
void collect_glyphs (set_t &glyphs) const
{
unsigned count = entries.get_length ();
for (unsigned i = 0; i < count; i++)
entries[i].collect_glyphs (glyphs);
}
bool sanitize (hb_sanitize_context_t *c) const bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
@ -314,6 +363,14 @@ struct LookupFormat8
&valueArrayZ[glyph_id - firstGlyph] : nullptr; &valueArrayZ[glyph_id - firstGlyph] : nullptr;
} }
template <typename set_t>
void collect_glyphs (set_t &glyphs) const
{
if (unlikely (!glyphCount))
return;
glyphs.add_range (firstGlyph, firstGlyph + glyphCount - 1);
}
bool sanitize (hb_sanitize_context_t *c) const bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
@ -406,6 +463,19 @@ struct Lookup
} }
} }
template <typename set_t>
void collect_glyphs (set_t &glyphs, unsigned int num_glyphs) const
{
switch (u.format) {
case 0: u.format0.collect_glyphs (glyphs, num_glyphs); return;
case 2: u.format2.collect_glyphs (glyphs); return;
case 4: u.format4.collect_glyphs (glyphs); return;
case 6: u.format6.collect_glyphs (glyphs); return;
case 8: u.format8.collect_glyphs (glyphs); return;
default:return;
}
}
typename T::type get_class (hb_codepoint_t glyph_id, typename T::type get_class (hb_codepoint_t glyph_id,
unsigned int num_glyphs, unsigned int num_glyphs,
unsigned int outOfRange) const unsigned int outOfRange) const
@ -535,9 +605,19 @@ struct StateTable
int new_state (unsigned int newState) const int new_state (unsigned int newState) const
{ return Types::extended ? newState : ((int) newState - (int) stateArrayTable) / (int) nClasses; } { return Types::extended ? newState : ((int) newState - (int) stateArrayTable) / (int) nClasses; }
unsigned int get_class (hb_codepoint_t glyph_id, unsigned int num_glyphs) const template <typename set_t>
void collect_glyphs (set_t &glyphs, unsigned num_glyphs) const
{
(this+classTable).collect_glyphs (glyphs, num_glyphs);
}
template <typename set_t>
unsigned int get_class (hb_codepoint_t glyph_id,
unsigned int num_glyphs,
const set_t &glyphs) const
{ {
if (unlikely (glyph_id == DELETED_GLYPH)) return CLASS_DELETED_GLYPH; if (unlikely (glyph_id == DELETED_GLYPH)) return CLASS_DELETED_GLYPH;
if (!glyphs[glyph_id]) return CLASS_OUT_OF_BOUNDS;
return (this+classTable).get_class (glyph_id, num_glyphs, 1); return (this+classTable).get_class (glyph_id, num_glyphs, 1);
} }
@ -690,6 +770,14 @@ struct ClassTable
{ {
return get_class (glyph_id, outOfRange); return get_class (glyph_id, outOfRange);
} }
template <typename set_t>
void collect_glyphs (set_t &glyphs, HB_UNUSED unsigned num_glyphs) const
{
for (unsigned int i = 0; i < classArray.len; i++)
glyphs.add (i + firstGlyph);
}
bool sanitize (hb_sanitize_context_t *c) const bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
@ -815,9 +903,12 @@ struct StateTableDriver
hb_face_t *face_) : hb_face_t *face_) :
machine (machine_), machine (machine_),
buffer (buffer_), buffer (buffer_),
num_glyphs (face_->get_num_glyphs ()) {} num_glyphs (face_->get_num_glyphs ())
{
machine.collect_glyphs (glyph_set, num_glyphs);
}
template <typename context_t> template <typename context_t, typename set_t = hb_set_digest_t>
void drive (context_t *c, hb_aat_apply_context_t *ac) void drive (context_t *c, hb_aat_apply_context_t *ac)
{ {
if (!c->in_place) if (!c->in_place)
@ -855,7 +946,7 @@ struct StateTableDriver
} }
unsigned int klass = buffer->idx < buffer->len ? unsigned int klass = buffer->idx < buffer->len ?
machine.get_class (buffer->cur().codepoint, num_glyphs) : machine.get_class (buffer->cur().codepoint, num_glyphs, glyph_set) :
(unsigned) StateTableT::CLASS_END_OF_TEXT; (unsigned) StateTableT::CLASS_END_OF_TEXT;
DEBUG_MSG (APPLY, nullptr, "c%u at %u", klass, buffer->idx); DEBUG_MSG (APPLY, nullptr, "c%u at %u", klass, buffer->idx);
const EntryT &entry = machine.get_entry (state, klass); const EntryT &entry = machine.get_entry (state, klass);
@ -946,6 +1037,7 @@ struct StateTableDriver
const StateTableT &machine; const StateTableT &machine;
hb_buffer_t *buffer; hb_buffer_t *buffer;
unsigned int num_glyphs; unsigned int num_glyphs;
hb_set_digest_t glyph_set;
}; };

@ -30,6 +30,7 @@
#include "hb-kern.hh" #include "hb-kern.hh"
#include "hb-aat-layout-ankr-table.hh" #include "hb-aat-layout-ankr-table.hh"
#include "hb-set-digest.hh"
/* /*
* kerx -- Extended Kerning * kerx -- Extended Kerning
@ -82,7 +83,7 @@ struct KernPair
return_trace (c->check_struct (this)); return_trace (c->check_struct (this));
} }
protected: public:
HBGlyphID16 left; HBGlyphID16 left;
HBGlyphID16 right; HBGlyphID16 right;
FWORD value; FWORD value;
@ -122,13 +123,31 @@ struct KerxSubTableFormat0
{ {
const KerxSubTableFormat0 &table; const KerxSubTableFormat0 &table;
hb_aat_apply_context_t *c; hb_aat_apply_context_t *c;
hb_set_digest_t left_set, right_set;
template <typename set_t>
void collect_glyphs (set_t &left, set_t &right)
{
for (const KernPair& pair : table.pairs)
{
left_set.add (pair.left);
right_set.add (pair.right);
}
}
accelerator_t (const KerxSubTableFormat0 &table_, accelerator_t (const KerxSubTableFormat0 &table_,
hb_aat_apply_context_t *c_) : hb_aat_apply_context_t *c_) :
table (table_), c (c_) {} table (table_), c (c_)
{
collect_glyphs (left_set, right_set);
}
int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const
{ return table.get_kerning (left, right, c); } {
if (!left_set[left] || !right_set[right])
return 0;
return table.get_kerning (left, right, c);
}
}; };

Loading…
Cancel
Save