f8b5e70a81f0930a06adda420556519899b6e072
[platform/upstream/libHarfBuzzSharp.git] / src / hb.hh
1 /*
2  * Copyright © 2007,2008,2009  Red Hat, Inc.
3  * Copyright © 2011,2012  Google, Inc.
4  *
5  *  This is part of HarfBuzz, a text shaping library.
6  *
7  * Permission is hereby granted, without written agreement and without
8  * license or royalty fees, to use, copy, modify, and distribute this
9  * software and its documentation for any purpose, provided that the
10  * above copyright notice and the following two paragraphs appear in
11  * all copies of this software.
12  *
13  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17  * DAMAGE.
18  *
19  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24  *
25  * Red Hat Author(s): Behdad Esfahbod
26  * Google Author(s): Behdad Esfahbod
27  */
28
29 #ifndef HB_HH
30 #define HB_HH
31
32
33 #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC
34 #ifdef _MSC_VER
35 #pragma warning( disable: 4068 ) /* Unknown pragma */
36 #endif
37 #if defined(__GNUC__) || defined(__clang__)
38 /* Rules:
39  *
40  * - All pragmas are declared GCC even if they are clang ones.  Otherwise GCC
41  *   nags, even though we instruct it to ignore -Wunknown-pragmas. ¯\_(ツ)_/¯
42  *
43  * - Within each category, keep sorted.
44  *
45  * - Warnings whose scope can be expanded in future compiler versions shall
46  *   be declared as "warning".  Otherwise, either ignored or error.
47  */
48
49 /* Setup.  Don't sort order within this category. */
50 #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_WARNING
51 #pragma GCC diagnostic warning "-Wall"
52 #pragma GCC diagnostic warning "-Wextra"
53 #endif
54 #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_IGNORED
55 #pragma GCC diagnostic ignored "-Wpragmas"
56 #pragma GCC diagnostic ignored "-Wunknown-pragmas"
57 #pragma GCC diagnostic ignored "-Wunknown-warning-option"
58 #endif
59 #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_WARNING
60 //#pragma GCC diagnostic warning "-Weverything"
61 #endif
62
63 /* Error.  Should never happen. */
64 #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_ERROR
65 #pragma GCC diagnostic error   "-Wc++11-narrowing"
66 #pragma GCC diagnostic error   "-Wcast-align"
67 #pragma GCC diagnostic error   "-Wcast-function-type"
68 #pragma GCC diagnostic error   "-Wdelete-non-virtual-dtor"
69 #pragma GCC diagnostic error   "-Wembedded-directive"
70 #pragma GCC diagnostic error   "-Wextra-semi-stmt"
71 #pragma GCC diagnostic error   "-Wformat-security"
72 #pragma GCC diagnostic error   "-Wimplicit-function-declaration"
73 #pragma GCC diagnostic error   "-Winit-self"
74 #pragma GCC diagnostic error   "-Winjected-class-name"
75 #pragma GCC diagnostic error   "-Wmissing-braces"
76 #pragma GCC diagnostic error   "-Wmissing-declarations"
77 #pragma GCC diagnostic error   "-Wmissing-prototypes"
78 #pragma GCC diagnostic error   "-Wnested-externs"
79 #pragma GCC diagnostic error   "-Wold-style-definition"
80 #pragma GCC diagnostic error   "-Wpointer-arith"
81 #pragma GCC diagnostic error   "-Wredundant-decls"
82 #pragma GCC diagnostic error   "-Wreorder"
83 #pragma GCC diagnostic error   "-Wsign-compare"
84 #pragma GCC diagnostic error   "-Wstrict-prototypes"
85 #pragma GCC diagnostic error   "-Wstring-conversion"
86 #pragma GCC diagnostic error   "-Wswitch-enum"
87 #pragma GCC diagnostic error   "-Wtautological-overlap-compare"
88 #pragma GCC diagnostic error   "-Wunneeded-internal-declaration"
89 #pragma GCC diagnostic error   "-Wunused"
90 #pragma GCC diagnostic error   "-Wunused-local-typedefs"
91 #pragma GCC diagnostic error   "-Wunused-value"
92 #pragma GCC diagnostic error   "-Wunused-variable"
93 #pragma GCC diagnostic error   "-Wvla"
94 #pragma GCC diagnostic error   "-Wwrite-strings"
95 #endif
96
97 /* Warning.  To be investigated if happens. */
98 #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_WARNING
99 #pragma GCC diagnostic warning "-Wbuiltin-macro-redefined"
100 #pragma GCC diagnostic warning "-Wdeprecated"
101 #pragma GCC diagnostic warning "-Wdeprecated-declarations"
102 #pragma GCC diagnostic warning "-Wdisabled-optimization"
103 #pragma GCC diagnostic warning "-Wdouble-promotion"
104 #pragma GCC diagnostic warning "-Wformat=2"
105 #pragma GCC diagnostic warning "-Wignored-pragma-optimize"
106 #pragma GCC diagnostic warning "-Wlogical-op"
107 #pragma GCC diagnostic warning "-Wmaybe-uninitialized"
108 #pragma GCC diagnostic warning "-Wmissing-format-attribute"
109 #pragma GCC diagnostic warning "-Wundef"
110 #endif
111
112 /* Ignored currently, but should be fixed at some point. */
113 #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_IGNORED
114 #pragma GCC diagnostic ignored "-Wconversion"                   // TODO fix
115 #pragma GCC diagnostic ignored "-Wformat-signedness"            // TODO fix
116 #pragma GCC diagnostic ignored "-Wshadow"                       // TODO fix
117 #pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"    // TODO fix
118 #pragma GCC diagnostic ignored "-Wunused-parameter"             // TODO fix
119 #endif
120
121 /* Ignored intentionally. */
122 #ifndef HB_NO_PRAGMA_GCC_DIAGNOSTIC_IGNORED
123 #pragma GCC diagnostic ignored "-Wclass-memaccess"
124 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
125 #pragma GCC diagnostic ignored "-Wformat-zero-length"
126 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
127 #pragma GCC diagnostic ignored "-Wpacked" // Erratic impl in clang
128 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
129 #pragma GCC diagnostic ignored "-Wtype-limits"
130 #pragma GCC diagnostic ignored "-Wc++11-compat" // only gcc raises it
131 #endif
132
133 #endif
134 #endif
135
136
137 #include "hb-config.hh"
138
139
140 /*
141  * Following added based on what AC_USE_SYSTEM_EXTENSIONS adds to
142  * config.h.in.  Copied here for the convenience of those embedding
143  * HarfBuzz and not using our build system.
144  */
145 /* Enable extensions on AIX 3, Interix.  */
146 #ifndef _ALL_SOURCE
147 # define _ALL_SOURCE 1
148 #endif
149 /* Enable GNU extensions on systems that have them.  */
150 #ifndef _GNU_SOURCE
151 # define _GNU_SOURCE 1
152 #endif
153 /* Enable threading extensions on Solaris.  */
154 #ifndef _POSIX_PTHREAD_SEMANTICS
155 # define _POSIX_PTHREAD_SEMANTICS 1
156 #endif
157 /* Enable extensions on HP NonStop.  */
158 #ifndef _TANDEM_SOURCE
159 # define _TANDEM_SOURCE 1
160 #endif
161 /* Enable general extensions on Solaris.  */
162 #ifndef __EXTENSIONS__
163 # define __EXTENSIONS__ 1
164 #endif
165
166 #if defined (_MSC_VER) && defined (HB_DLL_EXPORT)
167 #define HB_EXTERN __declspec (dllexport) extern
168 #endif
169
170 #include "hb.h"
171 #define HB_H_IN
172 #include "hb-ot.h"
173 #define HB_OT_H_IN
174 #include "hb-aat.h"
175 #define HB_AAT_H_IN
176
177 #include <limits.h>
178 #include <math.h>
179 #include <stdlib.h>
180 #include <stddef.h>
181 #include <string.h>
182 #include <assert.h>
183 #include <errno.h>
184 #include <stdio.h>
185 #include <stdarg.h>
186
187 #if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__)
188 #ifdef __MINGW32_VERSION
189 #ifndef WIN32_LEAN_AND_MEAN
190 #define WIN32_LEAN_AND_MEAN 1
191 #endif
192 #include <windows.h>
193 #else
194 #include <intrin.h>
195 #endif
196 #endif
197
198 #define HB_PASTE1(a,b) a##b
199 #define HB_PASTE(a,b) HB_PASTE1(a,b)
200
201
202 /* Compile-time custom allocator support. */
203
204 #if defined(hb_malloc_impl) \
205  && defined(hb_calloc_impl) \
206  && defined(hb_realloc_impl) \
207  && defined(hb_free_impl)
208 extern "C" void* hb_malloc_impl(size_t size);
209 extern "C" void* hb_calloc_impl(size_t nmemb, size_t size);
210 extern "C" void* hb_realloc_impl(void *ptr, size_t size);
211 extern "C" void  hb_free_impl(void *ptr);
212 #define malloc hb_malloc_impl
213 #define calloc hb_calloc_impl
214 #define realloc hb_realloc_impl
215 #define free hb_free_impl
216 #endif
217
218
219 /*
220  * Compiler attributes
221  */
222
223 #if (defined(__GNUC__) || defined(__clang__)) && defined(__OPTIMIZE__)
224 #define likely(expr) (__builtin_expect (!!(expr), 1))
225 #define unlikely(expr) (__builtin_expect (!!(expr), 0))
226 #else
227 #define likely(expr) (expr)
228 #define unlikely(expr) (expr)
229 #endif
230
231 #if !defined(__GNUC__) && !defined(__clang__)
232 #undef __attribute__
233 #define __attribute__(x)
234 #endif
235
236 #if defined(__GNUC__) && (__GNUC__ >= 3)
237 #define HB_PURE_FUNC    __attribute__((pure))
238 #define HB_CONST_FUNC   __attribute__((const))
239 #define HB_PRINTF_FUNC(format_idx, arg_idx) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
240 #else
241 #define HB_PURE_FUNC
242 #define HB_CONST_FUNC
243 #define HB_PRINTF_FUNC(format_idx, arg_idx)
244 #endif
245 #if defined(__GNUC__) && (__GNUC__ >= 4)
246 #define HB_UNUSED       __attribute__((unused))
247 #elif defined(_MSC_VER) /* https://github.com/harfbuzz/harfbuzz/issues/635 */
248 #define HB_UNUSED __pragma(warning(suppress: 4100 4101))
249 #else
250 #define HB_UNUSED
251 #endif
252
253 #ifndef HB_INTERNAL
254 # if !defined(HB_NO_VISIBILITY) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_MSC_VER) && !defined(__SUNPRO_CC)
255 #  define HB_INTERNAL __attribute__((__visibility__("hidden")))
256 # elif defined(__MINGW32__)
257    /* We use -export-symbols on mingw32, since it does not support visibility attributes. */
258 #  define HB_INTERNAL
259 # elif defined (_MSC_VER) && defined (HB_DLL_EXPORT)
260    /* We do not try to export internal symbols on Visual Studio */
261 #  define HB_INTERNAL
262 #else
263 #  define HB_INTERNAL
264 #  define HB_NO_VISIBILITY 1
265 # endif
266 #endif
267
268 /* https://github.com/harfbuzz/harfbuzz/issues/1651 */
269 #if defined(__clang__) && __clang_major__ < 10
270 #define static_const static
271 #else
272 #define static_const static const
273 #endif
274
275 #if defined(__GNUC__) && (__GNUC__ >= 3)
276 #define HB_FUNC __PRETTY_FUNCTION__
277 #elif defined(_MSC_VER)
278 #define HB_FUNC __FUNCSIG__
279 #else
280 #define HB_FUNC __func__
281 #endif
282
283 #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
284 /* https://github.com/harfbuzz/harfbuzz/issues/630 */
285 #define __restrict
286 #endif
287
288 /*
289  * Borrowed from https://bugzilla.mozilla.org/show_bug.cgi?id=1215411
290  * HB_FALLTHROUGH is an annotation to suppress compiler warnings about switch
291  * cases that fall through without a break or return statement. HB_FALLTHROUGH
292  * is only needed on cases that have code:
293  *
294  * switch (foo) {
295  *   case 1: // These cases have no code. No fallthrough annotations are needed.
296  *   case 2:
297  *   case 3:
298  *     foo = 4; // This case has code, so a fallthrough annotation is needed:
299  *     HB_FALLTHROUGH;
300  *   default:
301  *     return foo;
302  * }
303  */
304 #if defined(__clang__) && __cplusplus >= 201103L
305    /* clang's fallthrough annotations are only available starting in C++11. */
306 #  define HB_FALLTHROUGH [[clang::fallthrough]]
307 #elif defined(__GNUC__) && (__GNUC__ >= 7)
308    /* GNU fallthrough attribute is available from GCC7 */
309 #  define HB_FALLTHROUGH __attribute__((fallthrough))
310 #elif defined(_MSC_VER)
311    /*
312     * MSVC's __fallthrough annotations are checked by /analyze (Code Analysis):
313     * https://msdn.microsoft.com/en-us/library/ms235402%28VS.80%29.aspx
314     */
315 #  include <sal.h>
316 #  define HB_FALLTHROUGH __fallthrough
317 #else
318 #  define HB_FALLTHROUGH /* FALLTHROUGH */
319 #endif
320
321 #ifdef __clang__
322 /* Disable certain sanitizer errors. */
323 /* https://github.com/harfbuzz/harfbuzz/issues/1247 */
324 #define HB_NO_SANITIZE_SIGNED_INTEGER_OVERFLOW __attribute__((no_sanitize("signed-integer-overflow")))
325 #else
326 #define HB_NO_SANITIZE_SIGNED_INTEGER_OVERFLOW
327 #endif
328
329
330 #ifdef _WIN32
331    /* We need Windows Vista for both Uniscribe backend and for
332     * MemoryBarrier.  We don't support compiling on Windows XP,
333     * though we run on it fine. */
334 #  if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600
335 #    undef _WIN32_WINNT
336 #  endif
337 #  ifndef _WIN32_WINNT
338 #    if !defined(WINAPI_FAMILY) || !(WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP)
339 #      define _WIN32_WINNT 0x0600
340 #    endif
341 #  endif
342 #  ifndef WIN32_LEAN_AND_MEAN
343 #    define WIN32_LEAN_AND_MEAN 1
344 #  endif
345 #  ifndef STRICT
346 #    define STRICT 1
347 #  endif
348
349 #  if defined(_WIN32_WCE)
350      /* Some things not defined on Windows CE. */
351 #    define vsnprintf _vsnprintf
352 #    ifndef HB_NO_GETENV
353 #      define HB_NO_GETENV
354 #    endif
355 #    if _WIN32_WCE < 0x800
356 #      define HB_NO_SETLOCALE
357 static int errno = 0; /* Use something better? */
358 #    endif
359 #  elif defined(WINAPI_FAMILY) && (WINAPI_FAMILY==WINAPI_FAMILY_PC_APP || WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP)
360 #    ifndef HB_NO_GETENV
361 #      define HB_NO_GETENV
362 #    endif
363 #  endif
364 #  if defined(_MSC_VER) && _MSC_VER < 1900
365 #    define snprintf _snprintf
366 #  endif
367 #endif
368
369 #ifdef HB_NO_GETENV
370 #define getenv(Name) nullptr
371 #endif
372
373 #if defined(HAVE_ATEXIT) && !defined(HB_USE_ATEXIT)
374 /* atexit() is only safe to be called from shared libraries on certain
375  * platforms.  Whitelist.
376  * https://bugs.freedesktop.org/show_bug.cgi?id=82246 */
377 #  if defined(__linux) && defined(__GLIBC_PREREQ)
378 #    if __GLIBC_PREREQ(2,3)
379 /* From atexit() manpage, it's safe with glibc 2.2.3 on Linux. */
380 #      define HB_USE_ATEXIT 1
381 #    endif
382 #  elif defined(_MSC_VER) || defined(__MINGW32__)
383 /* For MSVC:
384  * https://msdn.microsoft.com/en-us/library/tze57ck3.aspx
385  * https://msdn.microsoft.com/en-us/library/zk17ww08.aspx
386  * mingw32 headers say atexit is safe to use in shared libraries.
387  */
388 #    define HB_USE_ATEXIT 1
389 #  elif defined(__ANDROID__)
390 /* This is available since Android NKD r8 or r8b:
391  * https://issuetracker.google.com/code/p/android/issues/detail?id=6455
392  */
393 #    define HB_USE_ATEXIT 1
394 #  elif defined(__APPLE__)
395 /* For macOS and related platforms, the atexit man page indicates
396  * that it will be invoked when the library is unloaded, not only
397  * at application exit.
398  */
399 #    define HB_USE_ATEXIT 1
400 #  endif
401 #endif
402 #ifdef HB_NO_ATEXIT
403 #  undef HB_USE_ATEXIT
404 #endif
405 #ifndef HB_USE_ATEXIT
406 #  define HB_USE_ATEXIT 0
407 #endif
408
409 #define HB_STMT_START do
410 #define HB_STMT_END   while (0)
411
412 /* Static-assert as expression. */
413 template <unsigned int cond> class hb_assert_constant_t;
414 template <> class hb_assert_constant_t<1> {};
415 #define ASSERT_STATIC_EXPR_ZERO(_cond) (0 * (unsigned int) sizeof (hb_assert_constant_t<_cond>))
416
417 /* Lets assert int types.  Saves trouble down the road. */
418 static_assert ((sizeof (int8_t) == 1), "");
419 static_assert ((sizeof (uint8_t) == 1), "");
420 static_assert ((sizeof (int16_t) == 2), "");
421 static_assert ((sizeof (uint16_t) == 2), "");
422 static_assert ((sizeof (int32_t) == 4), "");
423 static_assert ((sizeof (uint32_t) == 4), "");
424 static_assert ((sizeof (int64_t) == 8), "");
425 static_assert ((sizeof (uint64_t) == 8), "");
426 static_assert ((sizeof (hb_codepoint_t) == 4), "");
427 static_assert ((sizeof (hb_position_t) == 4), "");
428 static_assert ((sizeof (hb_mask_t) == 4), "");
429 static_assert ((sizeof (hb_var_int_t) == 4), "");
430
431 #define HB_DELETE_COPY_ASSIGN(TypeName) \
432   TypeName(const TypeName&) = delete; \
433   void operator=(const TypeName&) = delete
434 #define HB_DELETE_CREATE_COPY_ASSIGN(TypeName) \
435   TypeName() = delete; \
436   TypeName(const TypeName&) = delete; \
437   void operator=(const TypeName&) = delete
438
439
440 /* Flags */
441
442 /* Enable bitwise ops on enums marked as flags_t */
443 /* To my surprise, looks like the function resolver is happy to silently cast
444  * one enum to another...  So this doesn't provide the type-checking that I
445  * originally had in mind... :(.
446  *
447  * For MSVC warnings, see: https://github.com/harfbuzz/harfbuzz/pull/163
448  */
449 #ifdef _MSC_VER
450 # pragma warning(disable:4200)
451 # pragma warning(disable:4800)
452 #endif
453 #define HB_MARK_AS_FLAG_T(T) \
454         extern "C++" { \
455           static inline T operator | (T l, T r) { return T ((unsigned) l | (unsigned) r); } \
456           static inline T operator & (T l, T r) { return T ((unsigned) l & (unsigned) r); } \
457           static inline T operator ^ (T l, T r) { return T ((unsigned) l ^ (unsigned) r); } \
458           static inline T operator ~ (T r) { return T (~(unsigned int) r); } \
459           static inline T& operator |= (T &l, T r) { l = l | r; return l; } \
460           static inline T& operator &= (T& l, T r) { l = l & r; return l; } \
461           static inline T& operator ^= (T& l, T r) { l = l ^ r; return l; } \
462         } \
463         static_assert (true, "")
464
465 /* Useful for set-operations on small enums.
466  * For example, for testing "x ∈ {x1, x2, x3}" use:
467  * (FLAG_UNSAFE(x) & (FLAG(x1) | FLAG(x2) | FLAG(x3)))
468  */
469 #define FLAG(x) (ASSERT_STATIC_EXPR_ZERO ((unsigned)(x) < 32) + (((uint32_t) 1U) << (unsigned)(x)))
470 #define FLAG_UNSAFE(x) ((unsigned)(x) < 32 ? (((uint32_t) 1U) << (unsigned)(x)) : 0)
471 #define FLAG_RANGE(x,y) (ASSERT_STATIC_EXPR_ZERO ((x) < (y)) + FLAG(y+1) - FLAG(x))
472 #define FLAG64(x) (ASSERT_STATIC_EXPR_ZERO ((unsigned)(x) < 64) + (((uint64_t) 1ULL) << (unsigned)(x)))
473 #define FLAG64_UNSAFE(x) ((unsigned)(x) < 64 ? (((uint64_t) 1ULL) << (unsigned)(x)) : 0)
474
475
476 /* Size signifying variable-sized array */
477 #define VAR 1
478
479
480 /*
481  * Big-endian integers.  Here because fundamental.
482  */
483
484 template <typename Type, int Bytes> struct BEInt;
485
486 template <typename Type>
487 struct BEInt<Type, 1>
488 {
489   public:
490   BEInt<Type, 1>& operator = (Type V)
491   {
492     v = V;
493     return *this;
494   }
495   operator Type () const { return v; }
496   private: uint8_t v;
497 };
498 template <typename Type>
499 struct BEInt<Type, 2>
500 {
501   public:
502   BEInt<Type, 2>& operator = (Type V)
503   {
504     v[0] = (V >>  8) & 0xFF;
505     v[1] = (V      ) & 0xFF;
506     return *this;
507   }
508   operator Type () const
509   {
510 #if ((defined(__GNUC__) && __GNUC__ >= 5) || defined(__clang__)) && \
511     defined(__BYTE_ORDER) && \
512     (__BYTE_ORDER == __LITTLE_ENDIAN || __BYTE_ORDER == __BIG_ENDIAN)
513     /* Spoon-feed the compiler a big-endian integer with alignment 1.
514      * https://github.com/harfbuzz/harfbuzz/pull/1398 */
515     struct __attribute__((packed)) packed_uint16_t { uint16_t v; };
516 #if __BYTE_ORDER == __LITTLE_ENDIAN
517     return __builtin_bswap16 (((packed_uint16_t *) this)->v);
518 #else /* __BYTE_ORDER == __BIG_ENDIAN */
519     return ((packed_uint16_t *) this)->v;
520 #endif
521 #endif
522     return (v[0] <<  8)
523          + (v[1]      );
524   }
525   private: uint8_t v[2];
526 };
527 template <typename Type>
528 struct BEInt<Type, 3>
529 {
530   public:
531   BEInt<Type, 3>& operator = (Type V)
532   {
533     v[0] = (V >> 16) & 0xFF;
534     v[1] = (V >>  8) & 0xFF;
535     v[2] = (V      ) & 0xFF;
536     return *this;
537   }
538   operator Type () const
539   {
540     return (v[0] << 16)
541          + (v[1] <<  8)
542          + (v[2]      );
543   }
544   private: uint8_t v[3];
545 };
546 template <typename Type>
547 struct BEInt<Type, 4>
548 {
549   public:
550   BEInt<Type, 4>& operator = (Type V)
551   {
552     v[0] = (V >> 24) & 0xFF;
553     v[1] = (V >> 16) & 0xFF;
554     v[2] = (V >>  8) & 0xFF;
555     v[3] = (V      ) & 0xFF;
556     return *this;
557   }
558   operator Type () const
559   {
560     return (v[0] << 24)
561          + (v[1] << 16)
562          + (v[2] <<  8)
563          + (v[3]      );
564   }
565   private: uint8_t v[4];
566 };
567
568
569 /*
570  * For lack of a better place, put Zawgyi script hack here.
571  * https://github.com/harfbuzz/harfbuzz/issues/1162
572  */
573
574 #define HB_SCRIPT_MYANMAR_ZAWGYI        ((hb_script_t) HB_TAG ('Q','a','a','g'))
575
576
577 /* Headers we include for everyone.  Keep topologically sorted by dependency.
578  * They express dependency amongst themselves, but no other file should include
579  * them directly.*/
580 #include "hb-meta.hh"
581 #include "hb-mutex.hh"
582 #include "hb-atomic.hh" // Requires: hb-meta
583 #include "hb-null.hh"   // Requires: hb-meta
584 #include "hb-algs.hh"   // Requires: hb-meta hb-null
585 #include "hb-iter.hh"   // Requires: hb-algs hb-meta
586 #include "hb-debug.hh"  // Requires: hb-algs hb-atomic
587 #include "hb-array.hh"  // Requires: hb-algs hb-iter hb-null
588 #include "hb-vector.hh" // Requires: hb-array hb-null
589 #include "hb-object.hh" // Requires: hb-atomic hb-mutex hb-vector
590
591 #endif /* HB_HH */