.circleci/config.yml | 4 +++ src/hb-open-file-private.hh | 40 +++++++++++++------------------ src/hb-open-type-private.hh | 50 ++++++++++++++++++++++++++++++++------- src/hb-ot-font.cc | 2 - src/hb-ot-shape-complex-indic.cc | 4 +-- 5 files changed, 66 insertions(+), 34 deletions(-)
New commits: commit 65d4e5bcda543c17e09867418365ba44b441d5d6 Author: Behdad Esfahbod <[email protected]> Date: Wed Nov 1 01:15:27 2017 -0600 [CircleCI] Ignore gh-pages branch https://github.com/behdad/harfbuzz/pull/592 diff --git a/.circleci/config.yml b/.circleci/config.yml index 7135b853..d4835e44 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,8 @@ version: 2 + +branches: + ignore: + - gh-pages jobs: base: commit 92bb5086424d7454d666732e39117a7d32490646 Author: Behdad Esfahbod <[email protected]> Date: Tue Oct 31 22:58:03 2017 -0600 [indic] Use mutable for virama_glyph diff --git a/src/hb-ot-shape-complex-indic.cc b/src/hb-ot-shape-complex-indic.cc index 0cb326aa..f17a974d 100644 --- a/src/hb-ot-shape-complex-indic.cc +++ b/src/hb-ot-shape-complex-indic.cc @@ -508,7 +508,7 @@ struct indic_shape_plan_t /* Our get_nominal_glyph() function needs a font, so we can't get the virama glyph * during shape planning... Instead, overwrite it here. It's safe. Don't worry! */ - (const_cast<indic_shape_plan_t *> (this))->virama_glyph = glyph; + virama_glyph = glyph; } *pglyph = glyph; @@ -518,7 +518,7 @@ struct indic_shape_plan_t const indic_config_t *config; bool is_old_spec; - hb_codepoint_t virama_glyph; + mutable hb_codepoint_t virama_glyph; would_substitute_feature_t rphf; would_substitute_feature_t pref; commit 6c04dcb28dcafc7d97799c80c0bc714c76d51d1c Author: Behdad Esfahbod <[email protected]> Date: Tue Oct 31 20:11:00 2017 -0600 Use bsearch() for large SFNT table directories diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh index 77caddd2..a6d5a6b1 100644 --- a/src/hb-open-file-private.hh +++ b/src/hb-open-file-private.hh @@ -53,6 +53,9 @@ struct TTCHeader; typedef struct TableRecord { + int cmp (Tag t) const + { return t.cmp (tag); } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -100,18 +103,12 @@ typedef struct OffsetTable { Tag t; t.set (tag); - unsigned int count = tables.len; - /* TODO bsearch() */ - for (unsigned int i = 0; i < count; i++) - { - if (t == tables.array[i].tag) - { - if (table_index) *table_index = i; - return true; - } - } - if (table_index) *table_index = Index::NOT_FOUND_INDEX; - return false; + /* Linear-search for small tables to work around fonts with unsorted + * table list. */ + int i = tables.len < 64 ? tables.lsearch (t) : tables.bsearch (t); + if (table_index) + *table_index = i == -1 ? Index::NOT_FOUND_INDEX : (unsigned int) i; + return i != -1; } inline const TableRecord& get_table_by_tag (hb_tag_t tag) const { commit b0e33da02d062200dd41e4503ecc21fb4bd636e6 Author: Behdad Esfahbod <[email protected]> Date: Tue Oct 31 20:05:37 2017 -0600 Add BinSearchArrayOf<> diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh index dcfdfd6c..77caddd2 100644 --- a/src/hb-open-file-private.hh +++ b/src/hb-open-file-private.hh @@ -73,10 +73,9 @@ typedef struct OffsetTable friend struct OpenTypeFontFile; inline unsigned int get_table_count (void) const - { return numTables; } + { return tables.len; } inline const TableRecord& get_table (unsigned int i) const { - if (unlikely (i >= numTables)) return Null(TableRecord); return tables[i]; } inline unsigned int get_table_tags (unsigned int start_offset, @@ -85,26 +84,27 @@ typedef struct OffsetTable { if (table_count) { - if (start_offset >= numTables) + if (start_offset >= tables.len) *table_count = 0; else - *table_count = MIN (*table_count, numTables - start_offset); + *table_count = MIN (*table_count, tables.len - start_offset); - const TableRecord *sub_tables = tables + start_offset; + const TableRecord *sub_tables = tables.array + start_offset; unsigned int count = *table_count; for (unsigned int i = 0; i < count; i++) table_tags[i] = sub_tables[i].tag; } - return numTables; + return tables.len; } inline bool find_table_index (hb_tag_t tag, unsigned int *table_index) const { Tag t; t.set (tag); - unsigned int count = numTables; + unsigned int count = tables.len; + /* TODO bsearch() */ for (unsigned int i = 0; i < count; i++) { - if (t == tables[i].tag) + if (t == tables.array[i].tag) { if (table_index) *table_index = i; return true; @@ -124,16 +124,13 @@ typedef struct OffsetTable inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && c->check_array (tables, TableRecord::static_size, numTables)); + return_trace (c->check_struct (this) && tables.sanitize (c)); } protected: Tag sfnt_version; /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */ - USHORT numTables; /* Number of tables. */ - USHORT searchRangeZ; /* (Maximum power of 2 <= numTables) x 16 */ - USHORT entrySelectorZ; /* Log2(maximum power of 2 <= numTables). */ - USHORT rangeShiftZ; /* NumTables x 16-searchRange. */ - TableRecord tables[VAR]; /* TableRecord entries. numTables items */ + BinSearchArrayOf<TableRecord> + tables; public: DEFINE_SIZE_ARRAY (12, tables); } OpenTypeFontFace; diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index e41e7451..90db791e 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -1045,7 +1045,9 @@ struct HeadlessArrayOf }; -/* An array with sorted elements. Supports binary searching. */ +/* + * An array with sorted elements. Supports binary searching. + */ template <typename Type, typename LenType=USHORT> struct SortedArrayOf : ArrayOf<Type, LenType> { @@ -1070,6 +1072,35 @@ struct SortedArrayOf : ArrayOf<Type, LenType> } }; +/* + * Binary-search arrays + */ + +struct BinSearchHeader +{ + inline operator uint32_t (void) const { return len; } + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this)); + } + + protected: + USHORT len; + USHORT searchRangeZ; + USHORT entrySelectorZ; + USHORT rangeShiftZ; + + public: + DEFINE_SIZE_STATIC (8); +}; + +template <typename Type> +struct BinSearchArrayOf : SortedArrayOf<Type, BinSearchHeader> +{ +}; + /* Lazy struct and blob loaders. */ diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 5759a30d..38f61493 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -37,8 +37,8 @@ #include "hb-ot-hhea-table.hh" #include "hb-ot-hmtx-table.hh" #include "hb-ot-os2-table.hh" -#include "hb-ot-var-hvar-table.hh" #include "hb-ot-post-table.hh" +#include "hb-ot-var-hvar-table.hh" struct hb_ot_face_metrics_accelerator_t commit aca378f51ecf682ea1454071f671bbc7eef808bd Author: Behdad Esfahbod <[email protected]> Date: Tue Oct 31 18:11:10 2017 -0600 Sanitize (Headless)ArrayOf()::len to ensure it doesn't use offsets diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 7a62dcb8..e41e7451 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -946,7 +946,7 @@ struct ArrayOf inline bool sanitize_shallow (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && c->check_array (array, Type::static_size, len)); + return_trace (len.sanitize (c) && c->check_array (array, Type::static_size, len)); } public: @@ -1033,7 +1033,7 @@ struct HeadlessArrayOf inline bool sanitize_shallow (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && + return_trace (len.sanitize (c) && (!len || c->check_array (array, Type::static_size, len - 1))); } commit 5f047113142349ecf0dd6d00384f7ef7b3d1a85e Author: Behdad Esfahbod <[email protected]> Date: Tue Oct 31 18:10:40 2017 -0600 Fix HeadlessArrayOf::sanitize_shallow() diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index a49071d2..7a62dcb8 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -1012,12 +1012,6 @@ struct HeadlessArrayOf return_trace (true); } - inline bool sanitize_shallow (hb_sanitize_context_t *c) const - { - return c->check_struct (this) - && c->check_array (this, Type::static_size, len); - } - inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -1035,6 +1029,15 @@ struct HeadlessArrayOf return_trace (true); } + private: + inline bool sanitize_shallow (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + (!len || c->check_array (array, Type::static_size, len - 1))); + } + + public: LenType len; Type array[VAR]; public: _______________________________________________ HarfBuzz mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/harfbuzz
