X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fhb-ot-layout-common-private.hh;h=ce47e22a065e86c715c26e9cc64f9bc469d2a0df;hb=45412523dc295cb5ee12e096bfacb282cc925843;hp=fd224b79502d54d2a0f3a79018db7543776d63af;hpb=2cb08458f674301cde9d962c13911035a251f7c5;p=framework%2Fuifw%2Fharfbuzz.git diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index fd224b7..ce47e22 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -1,7 +1,8 @@ /* - * Copyright (C) 2007,2008,2009 Red Hat, Inc. + * Copyright © 2007,2008,2009 Red Hat, Inc. + * Copyright © 2010 Google, Inc. * - * This is part of HarfBuzz, an OpenType Layout engine library. + * This is part of HarfBuzz, a text shaping library. * * Permission is hereby granted, without written agreement and without * license or royalty fees, to use, copy, modify, and distribute this @@ -22,12 +23,13 @@ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod */ #ifndef HB_OT_LAYOUT_COMMON_PRIVATE_HH #define HB_OT_LAYOUT_COMMON_PRIVATE_HH -#include "hb-ot-layout-private.h" +#include "hb-ot-layout-private.hh" #include "hb-open-type-private.hh" @@ -36,6 +38,9 @@ #define NOT_COVERED ((unsigned int) 0x110000) #define MAX_NESTING_LEVEL 8 +HB_BEGIN_DECLS +HB_END_DECLS + /* * @@ -51,24 +56,32 @@ template struct Record { - static inline unsigned int get_size () { return sizeof (Record); } + inline int cmp (hb_tag_t a) const { + return tag.cmp (a); + } - inline bool sanitize (SANITIZE_ARG_DEF, const void *base) { + inline bool sanitize (hb_sanitize_context_t *c, void *base) { TRACE_SANITIZE (); - return SANITIZE (tag) && SANITIZE_BASE (offset, base); + return c->check_struct (this) + && offset.sanitize (c, base); } Tag tag; /* 4-byte Tag identifier */ OffsetTo offset; /* Offset from beginning of object holding * the Record */ + public: + DEFINE_SIZE_STATIC (6); }; template -struct RecordArrayOf : ArrayOf > { +struct RecordArrayOf : SortedArrayOf > { inline const Tag& get_tag (unsigned int i) const { - if (HB_UNLIKELY (i >= this->len)) return Null(Tag); + /* We cheat slightly and don't define separate Null objects + * for Record types. Instead, we return the correct Null(Tag) + * here. */ + if (unlikely (i >= this->len)) return Null(Tag); return (*this)[i].tag; } inline unsigned int get_tags (unsigned int start_offset, @@ -76,30 +89,23 @@ struct RecordArrayOf : ArrayOf > { hb_tag_t *record_tags /* OUT */) const { if (record_count) { - const Record *array = this->const_sub_array (start_offset, record_count); + const Record *arr = this->sub_array (start_offset, record_count); unsigned int count = *record_count; for (unsigned int i = 0; i < count; i++) - record_tags[i] = array[i].tag; + record_tags[i] = arr[i].tag; } return this->len; } inline bool find_index (hb_tag_t tag, unsigned int *index) const { - Tag t; - t.set (tag); - // TODO bsearch - const Record *a = this->array(); - unsigned int count = this->len; - for (unsigned int i = 0; i < count; i++) - { - if (t == a[i].tag) - { + int i = this->search (tag); + if (i != -1) { if (index) *index = i; return true; - } + } else { + if (index) *index = Index::NOT_FOUND_INDEX; + return false; } - if (index) *index = NO_INDEX; - return false; } }; @@ -109,30 +115,45 @@ struct RecordListOf : RecordArrayOf inline const Type& operator [] (unsigned int i) const { return this+RecordArrayOf::operator [](i).offset; } - inline bool sanitize (SANITIZE_ARG_DEF) { + inline bool sanitize (hb_sanitize_context_t *c) { TRACE_SANITIZE (); - return RecordArrayOf::sanitize (SANITIZE_ARG, ConstCharP(this)); + return RecordArrayOf::sanitize (c, this); } }; -struct IndexArray : ArrayOf +struct RangeRecord { - inline unsigned int operator [] (unsigned int i) const - { - if (HB_UNLIKELY (i >= this->len)) - return NO_INDEX; - return this->array()[i]; + inline int cmp (hb_codepoint_t g) const { + hb_codepoint_t a = start, b = end; + return g < a ? -1 : g <= b ? 0 : +1 ; } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (); + return c->check_struct (this); + } + + GlyphID start; /* First GlyphID in the range */ + GlyphID end; /* Last GlyphID in the range */ + USHORT value; /* Value */ + public: + DEFINE_SIZE_STATIC (6); +}; +DEFINE_NULL_DATA (RangeRecord, "\000\001"); + + +struct IndexArray : ArrayOf +{ inline unsigned int get_indexes (unsigned int start_offset, unsigned int *_count /* IN/OUT */, unsigned int *_indexes /* OUT */) const { if (_count) { - const USHORT *array = this->const_sub_array (start_offset, _count); + const USHORT *arr = this->sub_array (start_offset, _count); unsigned int count = *_count; for (unsigned int i = 0; i < count; i++) - _indexes[i] = array[i]; + _indexes[i] = arr[i]; } return this->len; } @@ -156,16 +177,17 @@ struct LangSys { return featureIndex.get_indexes (start_offset, feature_count, feature_indexes); } inline bool has_required_feature (void) const { return reqFeatureIndex != 0xffff; } - inline int get_required_feature_index (void) const + inline unsigned int get_required_feature_index (void) const { if (reqFeatureIndex == 0xffff) - return NO_INDEX; + return Index::NOT_FOUND_INDEX; return reqFeatureIndex;; } - inline bool sanitize (SANITIZE_ARG_DEF) { + inline bool sanitize (hb_sanitize_context_t *c) { TRACE_SANITIZE (); - return SANITIZE_SELF () && SANITIZE (featureIndex); + return c->check_struct (this) + && featureIndex.sanitize (c); } Offset lookupOrder; /* = Null (reserved for an offset to a @@ -174,9 +196,10 @@ struct LangSys * language system--if no required features * = 0xFFFF */ IndexArray featureIndex; /* Array of indices into the FeatureList */ + public: + DEFINE_SIZE_ARRAY (6, featureIndex); }; -ASSERT_SIZE (LangSys, 6); -DEFINE_NULL_DATA (LangSys, 6, "\0\0\xFF\xFF"); +DEFINE_NULL_DATA (LangSys, "\0\0\xFF\xFF"); struct Script @@ -191,7 +214,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 @@ -200,9 +223,10 @@ struct Script inline bool has_default_lang_sys (void) const { return defaultLangSys != 0; } inline const LangSys& get_default_lang_sys (void) const { return this+defaultLangSys; } - inline bool sanitize (SANITIZE_ARG_DEF) { + inline bool sanitize (hb_sanitize_context_t *c) { TRACE_SANITIZE (); - return SANITIZE_THIS (defaultLangSys) && SANITIZE_THIS (langSys); + return defaultLangSys.sanitize (c, this) + && langSys.sanitize (c, this); } private: @@ -212,11 +236,11 @@ struct Script RecordArrayOf langSys; /* Array of LangSysRecords--listed * alphabetically by LangSysTag */ + public: + DEFINE_SIZE_ARRAY (4, langSys); }; -ASSERT_SIZE (Script, 4); typedef RecordListOf