diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 396457c1f..5ac9d7814 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -45,6 +45,14 @@ namespace AAT { using namespace OT; +template +static inline unsigned int offsetToIndex (unsigned int offset, + const void *base, + const T *array) +{ + return (offset - ((const char *) array - (const char *) base)) / sizeof (T); +} + template struct RearrangementSubtable { @@ -255,11 +263,10 @@ struct ContextualSubtable } else { - unsigned int offset = 2 * (entry->data.markIndex + buffer->info[mark].codepoint); - replacement = &StructAtOffset (table, offset); - if ((const void *) replacement < (const void *) subs || - !replacement->sanitize (&c->sanitizer) || - !*replacement) + unsigned int offset = entry->data.markIndex + buffer->info[mark].codepoint; + const UnsizedArrayOf &subs_old = (const UnsizedArrayOf &) subs; + replacement = &subs_old[offsetToIndex (offset * 2, table, subs_old.arrayZ)]; + if (!replacement->sanitize (&c->sanitizer) || !*replacement) replacement = nullptr; } if (replacement) @@ -281,11 +288,10 @@ struct ContextualSubtable } else { - unsigned int offset = 2 * (entry->data.currentIndex + buffer->info[idx].codepoint); - replacement = &StructAtOffset (table, offset); - if ((const void *) replacement < (const void *) subs || - !replacement->sanitize (&c->sanitizer) || - !*replacement) + unsigned int offset = entry->data.currentIndex + buffer->info[idx].codepoint; + const UnsizedArrayOf &subs_old = (const UnsizedArrayOf &) subs; + replacement = &subs_old[offsetToIndex (offset * 2, table, subs_old.arrayZ)]; + if (!replacement->sanitize (&c->sanitizer) || !*replacement) replacement = nullptr; } if (replacement) @@ -457,14 +463,6 @@ struct LigatureSubtable ligature (table+table->ligature), match_length (0) {} - template - static inline unsigned int offsetToIndex (unsigned int offset, - const void *base, - const T *array) - { - return (offset - ((const char *) array - (const char *) base)) / sizeof (T); - } - inline bool is_actionable (StateTableDriver *driver HB_UNUSED, const Entry *entry) {