[aat] Port RearrangementSubtable to StateTableDriver

This commit is contained in:
Behdad Esfahbod 2018-01-12 00:08:22 +01:00
parent 117cfe7bb7
commit c70d58f97d
1 changed files with 45 additions and 48 deletions

View File

@ -40,6 +40,8 @@ using namespace OT;
struct RearrangementSubtable struct RearrangementSubtable
{ {
struct driver_context_t
{
enum Flags { enum Flags {
MarkFirst = 0x8000, /* If set, make the current glyph the first MarkFirst = 0x8000, /* If set, make the current glyph the first
* glyph to be rearranged. */ * glyph to be rearranged. */
@ -53,44 +55,25 @@ struct RearrangementSubtable
Verb = 0x000F, /* The type of rearrangement specified. */ Verb = 0x000F, /* The type of rearrangement specified. */
}; };
inline bool apply (hb_apply_context_t *c) const inline driver_context_t (const RearrangementSubtable *table) :
ret (false),
start (0), end (0),
last_zero_before_start (0) {}
inline void transition (StateTableDriver<void> *driver,
const Entry<void> *entry)
{ {
TRACE_APPLY (this); hb_buffer_t *buffer = driver->buffer;
bool ret = false;
unsigned int num_glyphs = c->face->get_num_glyphs ();
unsigned int state = 0;
unsigned int last_zero = 0;
unsigned int last_zero_before_start = 0;
unsigned int start = 0;
unsigned int end = 0;
hb_glyph_info_t *info = c->buffer->info;
unsigned int count = c->buffer->len;
for (unsigned int i = 0; i <= count; i++)
{
if (!state)
last_zero = i;
unsigned int klass = i < count ?
machine.get_class (info[i].codepoint, num_glyphs) :
0 /* End of text */;
const Entry<void> *entry = machine.get_entryZ (state, klass);
if (unlikely (!entry))
break;
unsigned int flags = entry->flags; unsigned int flags = entry->flags;
if (flags & MarkFirst) if (flags & MarkFirst)
{ {
start = i; start = buffer->idx;
last_zero_before_start = last_zero; last_zero_before_start = driver->last_zero;
} }
if (flags & MarkLast) if (flags & MarkLast)
end = MIN (i + 1, count); end = MIN (buffer->idx + 1, buffer->len);
if ((flags & Verb) && start < end) if ((flags & Verb) && start < end)
{ {
@ -126,10 +109,12 @@ struct RearrangementSubtable
if (end - start >= l + r) if (end - start >= l + r)
{ {
c->buffer->unsafe_to_break (last_zero_before_start, MIN (i + 1, count)); buffer->unsafe_to_break (last_zero_before_start, MIN (buffer->idx + 1, buffer->len));
c->buffer->merge_clusters (start, end); buffer->merge_clusters (start, end);
hb_glyph_info_t *info = buffer->info;
hb_glyph_info_t buf[4]; hb_glyph_info_t buf[4];
memcpy (buf, info + start, l * sizeof (buf[0])); memcpy (buf, info + start, l * sizeof (buf[0]));
memcpy (buf + 2, info + end - r, r * sizeof (buf[0])); memcpy (buf + 2, info + end - r, r * sizeof (buf[0]));
@ -152,14 +137,26 @@ struct RearrangementSubtable
} }
} }
} }
if (flags & DontAdvance)
i--; /* TODO Detect infinite loop. */
state = entry->newState;
} }
return_trace (ret); public:
bool ret;
private:
unsigned int start = 0;
unsigned int end = 0;
unsigned int last_zero_before_start = 0;
};
inline bool apply (hb_apply_context_t *c) const
{
TRACE_APPLY (this);
driver_context_t dc (this);
StateTableDriver<void> driver (machine, c->buffer, c->face);
driver.drive (&dc);
return_trace (dc.ret);
} }
inline bool sanitize (hb_sanitize_context_t *c) const inline bool sanitize (hb_sanitize_context_t *c) const