src/hb-aat-layout-common.hh | 28 ++++++++++++++++++++++++++++ src/hb-aat-layout-morx-table.hh | 36 ++++++++++++++---------------------- src/hb-font.cc | 28 ++++++++++++++-------------- src/hb-font.h | 2 +- 4 files changed, 57 insertions(+), 37 deletions(-)
New commits: commit 36e90ef56e6c0643ef61e947d7361c6fa4eadf10 Author: Behdad Esfahbod <[email protected]> Date: Wed Oct 31 15:09:09 2018 -0700 [mort] Massage some more diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index 33d9e556..51add221 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 <typename T> + 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 <typename T> + 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 <typename T> + static inline unsigned int offsetToIndex (unsigned int offset, + const void *base, + const T *array) + { + return offset; + } + template <typename T> + static inline unsigned int wordOffsetToIndex (unsigned int offset, + const void *base, + const T *array) + { + return offset; + } }; template <typename Types, typename EntryData> diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 5ac9d781..ab867bba 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 <typename T> -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 <typename Types> struct RearrangementSubtable { @@ -265,7 +257,7 @@ struct ContextualSubtable { unsigned int offset = entry->data.markIndex + buffer->info[mark].codepoint; const UnsizedArrayOf<GlyphID> &subs_old = (const UnsizedArrayOf<GlyphID> &) 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<GlyphID> &subs_old = (const UnsizedArrayOf<GlyphID> &) 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; commit cbaff4ef1910e2872bfff61f3d5427c076b3673d Author: Behdad Esfahbod <[email protected]> Date: Wed Oct 31 15:06:12 2018 -0700 [mort] Some more diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 396457c1..5ac9d781 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 <typename T> +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 <typename Types> struct RearrangementSubtable { @@ -255,11 +263,10 @@ struct ContextualSubtable } else { - unsigned int offset = 2 * (entry->data.markIndex + buffer->info[mark].codepoint); - replacement = &StructAtOffset<GlyphID> (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<GlyphID> &subs_old = (const UnsizedArrayOf<GlyphID> &) 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<GlyphID> (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<GlyphID> &subs_old = (const UnsizedArrayOf<GlyphID> &) 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 <typename T> - 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<Types, EntryData> *driver HB_UNUSED, const Entry<EntryData> *entry) { commit 3087046d3144afb50bcc13e4afa2d20d9f71f2c8 Author: Behdad Esfahbod <[email protected]> Date: Wed Oct 31 14:59:14 2018 -0700 [mort] Refactor offset-to-index mapping diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 45dbc28a..396457c1 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -457,6 +457,14 @@ struct LigatureSubtable ligature (table+table->ligature), match_length (0) {} + template <typename T> + 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<Types, EntryData> *driver HB_UNUSED, const Entry<EntryData> *entry) { @@ -497,9 +505,9 @@ struct LigatureSubtable return false; // TODO Work on previous instead? unsigned int cursor = match_length; - const HBUINT32 *actionData = Types::extended ? - &ligAction[action_idx] : - &StructAtOffset<HBUINT32> (table, action_idx); + if (!Types::extended) + action_idx = offsetToIndex (action_idx, table, ligAction.arrayZ); + const HBUINT32 *actionData = &ligAction[action_idx]; do { if (unlikely (!cursor)) @@ -522,11 +530,8 @@ struct LigatureSubtable int32_t offset = (int32_t) uoffset; unsigned int component_idx = buffer->cur().codepoint + offset; if (!Types::extended) - component_idx *= 2; - - const HBUINT16 &componentData = Types::extended ? - component[component_idx] : - StructAtOffset<HBUINT16> (table, component_idx); + component_idx = offsetToIndex (component_idx * 2, table, component.arrayZ); + const HBUINT16 &componentData = component[component_idx]; if (unlikely (!componentData.sanitize (&c->sanitizer))) return false; ligature_idx += componentData; @@ -535,9 +540,9 @@ struct LigatureSubtable bool (action & LigActionLast)); if (action & (LigActionStore | LigActionLast)) { - const GlyphID &ligatureData = Types::extended ? - ligature[ligature_idx] : - StructAtOffset<GlyphID> (table, ligature_idx); + if (!Types::extended) + ligature_idx = 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; commit b9db610add702da0a257db2eb21f3a7fb56682f7 Author: Behdad Esfahbod <[email protected]> Date: Wed Oct 31 14:22:31 2018 -0700 Minor diff --git a/src/hb-font.cc b/src/hb-font.cc index 135d310c..86b03f4b 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -54,23 +54,23 @@ static hb_bool_t hb_font_get_font_h_extents_nil (hb_font_t *font HB_UNUSED, void *font_data HB_UNUSED, - hb_font_extents_t *metrics, + hb_font_extents_t *extents, void *user_data HB_UNUSED) { - memset (metrics, 0, sizeof (*metrics)); + memset (extents, 0, sizeof (*extents)); return false; } static hb_bool_t hb_font_get_font_h_extents_default (hb_font_t *font, void *font_data HB_UNUSED, - hb_font_extents_t *metrics, + hb_font_extents_t *extents, void *user_data HB_UNUSED) { - hb_bool_t ret = font->parent->get_font_h_extents (metrics); + hb_bool_t ret = font->parent->get_font_h_extents (extents); if (ret) { - metrics->ascender = font->parent_scale_y_distance (metrics->ascender); - metrics->descender = font->parent_scale_y_distance (metrics->descender); - metrics->line_gap = font->parent_scale_y_distance (metrics->line_gap); + extents->ascender = font->parent_scale_y_distance (extents->ascender); + extents->descender = font->parent_scale_y_distance (extents->descender); + extents->line_gap = font->parent_scale_y_distance (extents->line_gap); } return ret; } @@ -78,23 +78,23 @@ hb_font_get_font_h_extents_default (hb_font_t *font, static hb_bool_t hb_font_get_font_v_extents_nil (hb_font_t *font HB_UNUSED, void *font_data HB_UNUSED, - hb_font_extents_t *metrics, + hb_font_extents_t *extents, void *user_data HB_UNUSED) { - memset (metrics, 0, sizeof (*metrics)); + memset (extents, 0, sizeof (*extents)); return false; } static hb_bool_t hb_font_get_font_v_extents_default (hb_font_t *font, void *font_data HB_UNUSED, - hb_font_extents_t *metrics, + hb_font_extents_t *extents, void *user_data HB_UNUSED) { - hb_bool_t ret = font->parent->get_font_v_extents (metrics); + hb_bool_t ret = font->parent->get_font_v_extents (extents); if (ret) { - metrics->ascender = font->parent_scale_x_distance (metrics->ascender); - metrics->descender = font->parent_scale_x_distance (metrics->descender); - metrics->line_gap = font->parent_scale_x_distance (metrics->line_gap); + extents->ascender = font->parent_scale_x_distance (extents->ascender); + extents->descender = font->parent_scale_x_distance (extents->descender); + extents->line_gap = font->parent_scale_x_distance (extents->line_gap); } return ret; } diff --git a/src/hb-font.h b/src/hb-font.h index 74c61aba..e2086d81 100644 --- a/src/hb-font.h +++ b/src/hb-font.h @@ -110,7 +110,7 @@ typedef struct hb_glyph_extents_t /* func types */ typedef hb_bool_t (*hb_font_get_font_extents_func_t) (hb_font_t *font, void *font_data, - hb_font_extents_t *metrics, + hb_font_extents_t *extents, void *user_data); typedef hb_font_get_font_extents_func_t hb_font_get_font_h_extents_func_t; typedef hb_font_get_font_extents_func_t hb_font_get_font_v_extents_func_t; _______________________________________________ HarfBuzz mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/harfbuzz
