From b5db4f1e4eefa266a71a28b5496f47ff9d1a81e8 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 May 2010 22:22:22 -0400 Subject: [PATCH] Clean up NO_INDEX --- src/hb-open-file-private.hh | 2 +- src/hb-open-type-private.hh | 10 ++++++---- src/hb-ot-layout-common-private.hh | 17 ++++------------- src/hb-ot-layout.cc | 8 ++++---- src/main.cc | 2 +- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh index 066c3b2..6d17db7 100644 --- a/src/hb-open-file-private.hh +++ b/src/hb-open-file-private.hh @@ -87,7 +87,7 @@ typedef struct OffsetTable return true; } } - if (table_index) *table_index = NO_INDEX; + if (table_index) *table_index = Index::NOT_FOUND_INDEX; return false; } inline const TableDirectory& get_table_by_tag (hb_tag_t tag) const diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index eabe1b8..71fb44e 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -32,10 +32,6 @@ #include "hb-blob.h" -/* Table/script/language-system/feature/... not found */ -#define NO_INDEX ((unsigned int) 0xFFFF) - - /* * Casts @@ -418,6 +414,12 @@ DEFINE_NULL_DATA (Tag, " "); /* Glyph index number, same as uint16 (length = 16 bits) */ typedef USHORT GlyphID; +/* Script/language-system/feature index */ +struct Index : USHORT { + static const unsigned int NOT_FOUND_INDEX = 0xFFFF; +}; +DEFINE_NULL_DATA (Index, "\xff\xff"); + /* Offset to a table, same as uint16 (length = 16 bits), Null offset = 0x0000 */ typedef USHORT Offset; diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index e5ecc8f..e724d99 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -99,7 +99,7 @@ struct RecordArrayOf : ArrayOf > { return true; } } - if (index) *index = NO_INDEX; + if (index) *index = Index::NOT_FOUND_INDEX; return false; } }; @@ -117,17 +117,8 @@ struct RecordListOf : RecordArrayOf }; -struct IndexArray : ArrayOf +struct IndexArray : ArrayOf { - inline USHORT operator [] (unsigned int i) const - { - if (unlikely (i >= this->len)) { - USHORT u; - u.set (NO_INDEX); - return u; - } - return this->array[i]; - } inline unsigned int get_indexes (unsigned int start_offset, unsigned int *_count /* IN/OUT */, unsigned int *_indexes /* OUT */) const @@ -163,7 +154,7 @@ struct LangSys inline int get_required_feature_index (void) const { if (reqFeatureIndex == 0xffff) - return NO_INDEX; + return Index::NOT_FOUND_INDEX; return reqFeatureIndex;; } @@ -197,7 +188,7 @@ struct Script { return langSys.get_tags (start_offset, lang_sys_count, lang_sys_tags); } inline const LangSys& get_lang_sys (unsigned int i) const { - if (i == NO_INDEX) return get_default_lang_sys (); + if (i == Index::NOT_FOUND_INDEX) return get_default_lang_sys (); return this+langSys[i].offset; } inline bool find_lang_sys_index (hb_tag_t tag, unsigned int *index) const diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 91f9fe9..5908cdd 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -360,7 +360,7 @@ hb_ot_layout_table_find_script (hb_face_t *face, hb_tag_t script_tag, unsigned int *script_index) { - ASSERT_STATIC (NO_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX); + ASSERT_STATIC (Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX); const GSUBGPOS &g = get_gsubgpos_table (face, table_tag); if (g.find_script_index (script_tag, script_index)) @@ -384,7 +384,7 @@ hb_ot_layout_table_choose_script (hb_face_t *face, const hb_tag_t *script_tags, unsigned int *script_index) { - ASSERT_STATIC (NO_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX); + ASSERT_STATIC (Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX); const GSUBGPOS &g = get_gsubgpos_table (face, table_tag); while (*script_tags) @@ -439,7 +439,7 @@ hb_ot_layout_script_find_language (hb_face_t *face, hb_tag_t language_tag, unsigned int *language_index) { - ASSERT_STATIC (NO_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX); + ASSERT_STATIC (Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX); const Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index); if (s.find_lang_sys_index (language_tag, language_index)) @@ -515,7 +515,7 @@ hb_ot_layout_language_find_feature (hb_face_t *face, hb_tag_t feature_tag, unsigned int *feature_index) { - ASSERT_STATIC (NO_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX); + ASSERT_STATIC (Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX); const GSUBGPOS &g = get_gsubgpos_table (face, table_tag); const LangSys &l = g.get_script (script_index).get_lang_sys (language_index); diff --git a/src/main.cc b/src/main.cc index b3b12d0..5d68862 100644 --- a/src/main.cc +++ b/src/main.cc @@ -126,7 +126,7 @@ main (int argc, char **argv) ? " Default Language System\n" : " Language System %2d of %2d: %.4s\n", n_langsys, num_langsys, (const char *)script.get_lang_sys_tag (n_langsys)); - if (langsys.get_required_feature_index () == NO_INDEX) + if (langsys.get_required_feature_index () == Index::NOT_FOUND_INDEX) printf (" No required feature\n"); int num_features = langsys.get_feature_count (); -- 2.7.4