From 36e90ef56e6c0643ef61e947d7361c6fa4eadf10 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 31 Oct 2018 15:09:09 -0700 Subject: [PATCH] [mort] Massage some more --- src/hb-aat-layout-common.hh | 28 ++++++++++++++++++++++++++++ src/hb-aat-layout-morx-table.hh | 21 +++++---------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index 33d9e55..51add22 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -560,6 +560,20 @@ struct MortTypes return ClassTable::get_class (glyph_id); } }; + 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 + static inline unsigned int wordOffsetToIndex (unsigned int offset, + const void *base, + const T *array) + { + return offsetToIndex (2 * offset, base, array); + } }; struct MorxTypes { @@ -574,6 +588,20 @@ struct MorxTypes return v ? *v : 1; } }; + template + static inline unsigned int offsetToIndex (unsigned int offset, + const void *base, + const T *array) + { + return offset; + } + template + static inline unsigned int wordOffsetToIndex (unsigned int offset, + const void *base, + const T *array) + { + return offset; + } }; template diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 5ac9d78..ab867bb 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -45,14 +45,6 @@ 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 { @@ -265,7 +257,7 @@ struct ContextualSubtable { 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)]; + replacement = &subs_old[Types::wordOffsetToIndex (offset, table, subs_old.arrayZ)]; if (!replacement->sanitize (&c->sanitizer) || !*replacement) replacement = nullptr; } @@ -290,7 +282,7 @@ struct ContextualSubtable { 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)]; + replacement = &subs_old[Types::wordOffsetToIndex (offset, table, subs_old.arrayZ)]; if (!replacement->sanitize (&c->sanitizer) || !*replacement) replacement = nullptr; } @@ -503,8 +495,7 @@ struct LigatureSubtable return false; // TODO Work on previous instead? unsigned int cursor = match_length; - if (!Types::extended) - action_idx = offsetToIndex (action_idx, table, ligAction.arrayZ); + action_idx = Types::offsetToIndex (action_idx, table, ligAction.arrayZ); const HBUINT32 *actionData = &ligAction[action_idx]; do { @@ -527,8 +518,7 @@ struct LigatureSubtable uoffset |= 0xC0000000; /* Sign-extend. */ int32_t offset = (int32_t) uoffset; unsigned int component_idx = buffer->cur().codepoint + offset; - if (!Types::extended) - component_idx = offsetToIndex (component_idx * 2, table, component.arrayZ); + component_idx = Types::wordOffsetToIndex (component_idx, table, component.arrayZ); const HBUINT16 &componentData = component[component_idx]; if (unlikely (!componentData.sanitize (&c->sanitizer))) return false; ligature_idx += componentData; @@ -538,8 +528,7 @@ struct LigatureSubtable bool (action & LigActionLast)); if (action & (LigActionStore | LigActionLast)) { - if (!Types::extended) - ligature_idx = offsetToIndex (ligature_idx, table, ligature.arrayZ); + ligature_idx = Types::offsetToIndex (ligature_idx, table, ligature.arrayZ); const GlyphID &ligatureData = ligature[ligature_idx]; if (unlikely (!ligatureData.sanitize (&c->sanitizer))) return false; hb_codepoint_t lig = ligatureData; -- 2.7.4