From a0175e75bc40b5496d7fd37afd434cb2000e5b9b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 17 Aug 2017 16:55:54 -0700 Subject: [PATCH] [aat] Start implementing common table formats --- src/Makefile.sources | 2 + src/hb-aat-layout-common-private.hh | 134 ++++++++++++++++++++++++++++ src/hb-aat-layout-morx-table.hh | 1 + src/hb-aat-layout-private.hh | 37 ++++++++ src/hb-aat-layout.cc | 1 + 5 files changed, 175 insertions(+) create mode 100644 src/hb-aat-layout-common-private.hh create mode 100644 src/hb-aat-layout-private.hh diff --git a/src/Makefile.sources b/src/Makefile.sources index a728fc09..4349e0a7 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 00000000..17c78332 --- /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 d3a694b5..0e366be0 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 00000000..6adf084c --- /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 c5277ed7..73ceafe3 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" /* -- GitLab