X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fhb-ot-layout-common-private.hh;h=ce47e22a065e86c715c26e9cc64f9bc469d2a0df;hb=743807a3ce1b2229e5307a8aea074a7544623d8d;hp=a4032d9a9e220cdd4ea09fb8055838bd100fad16;hpb=284899ccbe79fda7405ab09d3092fc25fd89e810;p=framework%2Fuifw%2Fharfbuzz.git diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index a4032d9..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,16 +23,25 @@ * 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" +#define NO_CONTEXT ((unsigned int) 0x110000) +#define NOT_COVERED ((unsigned int) 0x110000) +#define MAX_NESTING_LEVEL 8 + +HB_BEGIN_DECLS +HB_END_DECLS + + /* * * OpenType Layout Common Table Formats @@ -46,49 +56,56 @@ template struct Record { - inline bool sanitize (SANITIZE_ARG_DEF, const void *base) { - SANITIZE_DEBUG (); - return SANITIZE (tag) && SANITIZE_BASE (offset, base); + inline int cmp (hb_tag_t a) const { + return tag.cmp (a); + } + + inline bool sanitize (hb_sanitize_context_t *c, void *base) { + TRACE_SANITIZE (); + 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); - return this->array[i].tag; - } - inline bool get_tags (unsigned int *record_count /* IN/OUT */, - hb_tag_t *record_tags /* OUT */) const + /* 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, + unsigned int *record_count /* IN/OUT */, + hb_tag_t *record_tags /* OUT */) const { - unsigned int count = MIN (this->len, *record_count); - for (unsigned int i = 0; i < count; i++) - record_tags[i] = this->array[i].tag; - - *record_count = this->len; - return !!this->len; + if (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] = arr[i].tag; + } + return this->len; } inline bool find_index (hb_tag_t tag, unsigned int *index) const { - const Tag t = tag; - // TODO bsearch - unsigned int count = this->len; - for (unsigned int i = 0; i < count; i++) - { - if (t == this->array[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; } }; @@ -96,32 +113,49 @@ template struct RecordListOf : RecordArrayOf { inline const Type& operator [] (unsigned int i) const - { return this+RecordArrayOf::operator[](i).offset; } + { return this+RecordArrayOf::operator [](i).offset; } - inline bool sanitize (SANITIZE_ARG_DEF) { - SANITIZE_DEBUG (); - return RecordArrayOf::sanitize (SANITIZE_ARG, CONST_CHARP(this)); + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (); + 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 get_indexes (unsigned int *_count /* IN/OUT */, - unsigned int *_indexes /* OUT */) const - { - unsigned int count = MIN (this->len, *_count); - for (unsigned int i = 0; i < count; i++) - _indexes[i] = this->array[i]; - *_count = this->len; - return !!this->len; + 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 *arr = this->sub_array (start_offset, _count); + unsigned int count = *_count; + for (unsigned int i = 0; i < count; i++) + _indexes[i] = arr[i]; + } + return this->len; } }; @@ -137,21 +171,23 @@ struct LangSys { return featureIndex.len; } inline hb_tag_t get_feature_index (unsigned int i) const { return featureIndex[i]; } - inline bool get_feature_indexes (unsigned int *feature_count /* IN/OUT */, - hb_tag_t *feature_tags /* OUT */) const - { return featureIndex.get_indexes (feature_count, feature_tags); } + inline unsigned int get_feature_indexes (unsigned int start_offset, + unsigned int *feature_count /* IN/OUT */, + unsigned int *feature_indexes /* OUT */) const + { 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) { - SANITIZE_DEBUG (); - return SANITIZE_SELF () && SANITIZE (featureIndex); + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (); + return c->check_struct (this) + && featureIndex.sanitize (c); } Offset lookupOrder; /* = Null (reserved for an offset to a @@ -160,8 +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_DATA (LangSys, 6, "\0\0\xFF\xFF"); +DEFINE_NULL_DATA (LangSys, "\0\0\xFF\xFF"); struct Script @@ -170,12 +208,13 @@ struct Script { return langSys.len; } inline const Tag& get_lang_sys_tag (unsigned int i) const { return langSys.get_tag (i); } - inline bool get_lang_sys_tags (unsigned int *lang_sys_count /* IN/OUT */, - hb_tag_t *lang_sys_tags /* OUT */) const - { return langSys.get_tags (lang_sys_count, lang_sys_tags); } + inline unsigned int get_lang_sys_tags (unsigned int start_offset, + unsigned int *lang_sys_count /* IN/OUT */, + hb_tag_t *lang_sys_tags /* OUT */) const + { 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 @@ -184,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) { - SANITIZE_DEBUG (); - return SANITIZE_THIS (defaultLangSys) && SANITIZE_THIS (langSys); + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (); + return defaultLangSys.sanitize (c, this) + && langSys.sanitize (c, this); } private: @@ -196,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