diff --git a/src/Makefile.sources b/src/Makefile.sources index a728fc0923b6f1cb68d42098f9c6120306bb6144..4349e0a7ee3645c177d7d486c8217bb6f41b5e98 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -83,7 +83,9 @@ HB_FALLBACK_sources = \ HB_OT_sources = \ hb-aat-layout.cc \ + hb-aat-layout-common-private.hh \ hb-aat-layout-morx-table.hh \ + hb-aat-layout-private.hh \ hb-ot-font.cc \ hb-ot-layout.cc \ hb-ot-layout-common-private.hh \ diff --git a/src/hb-aat-layout-common-private.hh b/src/hb-aat-layout-common-private.hh new file mode 100644 index 0000000000000000000000000000000000000000..17c783322745a011700cefb6a40b031afe39adcb --- /dev/null +++ b/src/hb-aat-layout-common-private.hh @@ -0,0 +1,134 @@ +/* + * Copyright © 2017 Google, Inc. + * + * 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 + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_AAT_LAYOUT_COMMON_PRIVATE_HH +#define HB_AAT_LAYOUT_COMMON_PRIVATE_HH + +#include "hb-aat-layout-private.hh" + + +namespace AAT { + +using namespace OT; + + +/* + * Binary Searching Tables + */ + +struct BinSearchHeader +{ + friend struct BinSearchArray; + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this)); + } + + protected: + USHORT unitSize; /* Size of a lookup unit for this search in bytes. */ + USHORT nUnits; /* Number of units of the preceding size to be searched. */ + USHORT searchRange; /* The value of unitSize times the largest power of 2 + * that is less than or equal to the value of nUnits. */ + USHORT entrySelector; /* The log base 2 of the largest power of 2 less than + * or equal to the value of nUnits. */ + USHORT rangeShift; /* The value of unitSize times the difference of the + * value of nUnits minus the largest power of 2 less + * than or equal to the value of nUnits. */ + public: + DEFINE_SIZE_STATIC (10); +}; + +template +struct BinSearchArrayOf +{ + inline const Type& operator [] (unsigned int i) const + { + if (unlikely (i >= header.nUnits)) return Null(Type); + return StructAtOffset (bytes, i * header.unitSize); + } + inline Type& operator [] (unsigned int i) + { + return StructAtOffset (bytes, i * header.unitSize); + } + inline unsigned int get_size (void) const + { return header.static_size + header.nUnits * header.unitSize; } + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + if (unlikely (!sanitize_shallow (c))) return_trace (false); + + /* Note: for structs that do not reference other structs, + * we do not need to call their sanitize() as we already did + * a bound check on the aggregate array size. We just include + * a small unreachable expression to make sure the structs + * pointed to do have a simple sanitize(), ie. they do not + * reference other structs via offsets. + */ + (void) (false && StructAtOffset (bytes, 0).sanitize (c)); + + return_trace (true); + } + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const + { + TRACE_SANITIZE (this); + if (unlikely (!sanitize_shallow (c))) return_trace (false); + unsigned int count = header.nUnits; + for (unsigned int i = 0; i < count; i++) + if (unlikely (!(*this)[i].sanitize (c, base))) + return_trace (false); + return_trace (true); + } + + template + inline Type *bsearch (const T &key) const + { + return ::bsearch (&key, bytes, header.nUnits, header.unitSize, (hb_compare_func_t) Type::cmp); + } + + private: + inline bool sanitize_shallow (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (header.sanitize (c) && + Type::static_size >= header.unitSize && + c->check_array (bytes, header.unitSize, header.nUnits)); + } + + protected: + BinSearchHeader header; + BYTE bytes[VAR]; + public: + DEFINE_SIZE_ARRAY (10, bytes); +}; + + +} /* namespace AAT */ + + +#endif /* HB_AAT_LAYOUT_COMMON_PRIVATE_HH */ diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index d3a694b5f539e64f95097391f12ab8db90d0f85b..0e366be0aeef041dab62744f078650ea6049eedf 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -28,6 +28,7 @@ #define HB_AAT_LAYOUT_MORX_TABLE_HH #include +#include #define HB_AAT_TAG_MORT HB_TAG('m','o','r','t') #define HB_AAT_TAG_MORX HB_TAG('m','o','r','x') diff --git a/src/hb-aat-layout-private.hh b/src/hb-aat-layout-private.hh new file mode 100644 index 0000000000000000000000000000000000000000..6adf084c3ff7667b7405e7610ba4af5318f38719 --- /dev/null +++ b/src/hb-aat-layout-private.hh @@ -0,0 +1,37 @@ +/* + * Copyright © 2017 Google, Inc. + * + * 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 + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_AAT_LAYOUT_PRIVATE_HH +#define HB_AAT_LAYOUT_PRIVATE_HH + +#include "hb-private.hh" + +#include "hb-font-private.hh" +#include "hb-buffer-private.hh" +#include "hb-open-type-private.hh" + + +#endif /* HB_AAT_LAYOUT_PRIVATE_HH */ diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index c5277ed72a53047e38bc151c5425eaa17ff65295..73ceafe3266f9c5c8cbc791f92ad7d94b705c89f 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -27,6 +27,7 @@ #include "hb-open-type-private.hh" #include "hb-ot-layout-private.hh" +#include "hb-aat-layout-private.hh" #include "hb-aat-layout-morx-table.hh" /*