author | prr |
Fri, 01 Mar 2019 16:59:19 -0800 | |
changeset 54232 | 7c11a7cc7c1d |
parent 51000 | src/java.desktop/share/native/libfontmanager/harfbuzz/hb-open-type-private.hh@7c8841474f57 |
permissions | -rw-r--r-- |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
1 |
/* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
2 |
* Copyright © 2007,2008,2009,2010 Red Hat, Inc. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
3 |
* Copyright © 2012 Google, Inc. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
4 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
5 |
* This is part of HarfBuzz, a text shaping library. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
6 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
7 |
* Permission is hereby granted, without written agreement and without |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
8 |
* license or royalty fees, to use, copy, modify, and distribute this |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
9 |
* software and its documentation for any purpose, provided that the |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
10 |
* above copyright notice and the following two paragraphs appear in |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
11 |
* all copies of this software. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
12 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
13 |
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
14 |
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
15 |
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
16 |
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
17 |
* DAMAGE. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
18 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
19 |
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
20 |
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
21 |
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
22 |
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
23 |
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
24 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
25 |
* Red Hat Author(s): Behdad Esfahbod |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
26 |
* Google Author(s): Behdad Esfahbod |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
27 |
*/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
28 |
|
54232 | 29 |
#ifndef HB_OPEN_TYPE_HH |
30 |
#define HB_OPEN_TYPE_HH |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
31 |
|
54232 | 32 |
#include "hb.hh" |
33 |
#include "hb-blob.hh" |
|
34 |
#include "hb-face.hh" |
|
35 |
#include "hb-machinery.hh" |
|
36 |
#include "hb-subset.hh" |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
37 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
38 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
39 |
namespace OT { |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
40 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
41 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
42 |
/* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
43 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
44 |
* The OpenType Font File: Data Types |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
45 |
*/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
46 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
47 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
48 |
/* "The following data types are used in the OpenType font file. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
49 |
* All OpenType fonts use Motorola-style byte ordering (Big Endian):" */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
50 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
51 |
/* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
52 |
* Int types |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
53 |
*/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
54 |
|
54232 | 55 |
template <bool is_signed> struct hb_signedness_int; |
56 |
template <> struct hb_signedness_int<false> { typedef unsigned int value; }; |
|
57 |
template <> struct hb_signedness_int<true> { typedef signed int value; }; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
58 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
59 |
/* Integer types in big-endian order and no alignment requirement */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
60 |
template <typename Type, unsigned int Size> |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
61 |
struct IntType |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
62 |
{ |
54232 | 63 |
typedef Type type; |
64 |
typedef typename hb_signedness_int<hb_is_signed<Type>::value>::value wide_type; |
|
65 |
||
66 |
void set (wide_type i) { v.set (i); } |
|
67 |
operator wide_type () const { return v; } |
|
68 |
bool operator == (const IntType<Type,Size> &o) const { return (Type) v == (Type) o.v; } |
|
69 |
bool operator != (const IntType<Type,Size> &o) const { return !(*this == o); } |
|
70 |
static int cmp (const IntType<Type,Size> *a, const IntType<Type,Size> *b) { return b->cmp (*a); } |
|
48274 | 71 |
template <typename Type2> |
54232 | 72 |
int cmp (Type2 a) const |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
73 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
74 |
Type b = v; |
48274 | 75 |
if (sizeof (Type) < sizeof (int) && sizeof (Type2) < sizeof (int)) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
76 |
return (int) a - (int) b; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
77 |
else |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
78 |
return a < b ? -1 : a == b ? 0 : +1; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
79 |
} |
54232 | 80 |
bool sanitize (hb_sanitize_context_t *c) const |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
81 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
82 |
TRACE_SANITIZE (this); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
83 |
return_trace (likely (c->check_struct (this))); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
84 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
85 |
protected: |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
86 |
BEInt<Type, Size> v; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
87 |
public: |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
88 |
DEFINE_SIZE_STATIC (Size); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
89 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
90 |
|
50352 | 91 |
typedef IntType<uint8_t, 1> HBUINT8; /* 8-bit unsigned integer. */ |
92 |
typedef IntType<int8_t, 1> HBINT8; /* 8-bit signed integer. */ |
|
93 |
typedef IntType<uint16_t, 2> HBUINT16; /* 16-bit unsigned integer. */ |
|
94 |
typedef IntType<int16_t, 2> HBINT16; /* 16-bit signed integer. */ |
|
95 |
typedef IntType<uint32_t, 4> HBUINT32; /* 32-bit unsigned integer. */ |
|
96 |
typedef IntType<int32_t, 4> HBINT32; /* 32-bit signed integer. */ |
|
54232 | 97 |
/* Note: we cannot defined a signed HBINT24 because there's no corresponding C type. |
98 |
* Works for unsigned, but not signed, since we rely on compiler for sign-extension. */ |
|
50826 | 99 |
typedef IntType<uint32_t, 3> HBUINT24; /* 24-bit unsigned integer. */ |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
100 |
|
50352 | 101 |
/* 16-bit signed integer (HBINT16) that describes a quantity in FUnits. */ |
102 |
typedef HBINT16 FWORD; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
103 |
|
54232 | 104 |
/* 32-bit signed integer (HBINT32) that describes a quantity in FUnits. */ |
105 |
typedef HBINT32 FWORD32; |
|
106 |
||
50352 | 107 |
/* 16-bit unsigned integer (HBUINT16) that describes a quantity in FUnits. */ |
108 |
typedef HBUINT16 UFWORD; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
109 |
|
40435 | 110 |
/* 16-bit signed fixed number with the low 14 bits of fraction (2.14). */ |
50352 | 111 |
struct F2DOT14 : HBINT16 |
40435 | 112 |
{ |
50826 | 113 |
// 16384 means 1<<14 |
54232 | 114 |
float to_float () const { return ((int32_t) v) / 16384.f; } |
115 |
void set_float (float f) { v.set (round (f * 16384.f)); } |
|
40435 | 116 |
public: |
117 |
DEFINE_SIZE_STATIC (2); |
|
118 |
}; |
|
119 |
||
120 |
/* 32-bit signed fixed-point number (16.16). */ |
|
50826 | 121 |
struct Fixed : HBINT32 |
40435 | 122 |
{ |
50826 | 123 |
// 65536 means 1<<16 |
54232 | 124 |
float to_float () const { return ((int32_t) v) / 65536.f; } |
125 |
void set_float (float f) { v.set (round (f * 65536.f)); } |
|
40435 | 126 |
public: |
127 |
DEFINE_SIZE_STATIC (4); |
|
128 |
}; |
|
129 |
||
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
130 |
/* Date represented in number of seconds since 12:00 midnight, January 1, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
131 |
* 1904. The value is represented as a signed 64-bit integer. */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
132 |
struct LONGDATETIME |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
133 |
{ |
54232 | 134 |
bool sanitize (hb_sanitize_context_t *c) const |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
135 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
136 |
TRACE_SANITIZE (this); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
137 |
return_trace (likely (c->check_struct (this))); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
138 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
139 |
protected: |
50352 | 140 |
HBINT32 major; |
141 |
HBUINT32 minor; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
142 |
public: |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
143 |
DEFINE_SIZE_STATIC (8); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
144 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
145 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
146 |
/* Array of four uint8s (length = 32 bits) used to identify a script, language |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
147 |
* system, feature, or baseline */ |
50352 | 148 |
struct Tag : HBUINT32 |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
149 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
150 |
/* What the char* converters return is NOT nul-terminated. Print using "%.4s" */ |
54232 | 151 |
operator const char* () const { return reinterpret_cast<const char *> (&this->v); } |
152 |
operator char* () { return reinterpret_cast<char *> (&this->v); } |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
153 |
public: |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
154 |
DEFINE_SIZE_STATIC (4); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
155 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
156 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
157 |
/* Glyph index number, same as uint16 (length = 16 bits) */ |
50352 | 158 |
typedef HBUINT16 GlyphID; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
159 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
160 |
/* Script/language-system/feature index */ |
50352 | 161 |
struct Index : HBUINT16 { |
54232 | 162 |
static constexpr unsigned NOT_FOUND_INDEX = 0xFFFFu; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
163 |
}; |
54232 | 164 |
DECLARE_NULL_NAMESPACE_BYTES (OT, Index); |
165 |
||
166 |
typedef Index NameID; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
167 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
168 |
/* Offset, Null offset = 0 */ |
54232 | 169 |
template <typename Type, bool has_null=true> |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
170 |
struct Offset : Type |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
171 |
{ |
54232 | 172 |
typedef Type type; |
50352 | 173 |
|
54232 | 174 |
bool is_null () const { return has_null && 0 == *this; } |
175 |
||
176 |
void *serialize (hb_serialize_context_t *c, const void *base) |
|
50352 | 177 |
{ |
178 |
void *t = c->start_embed<void> (); |
|
179 |
this->set ((char *) t - (char *) base); /* TODO(serialize) Overflow? */ |
|
180 |
return t; |
|
181 |
} |
|
182 |
||
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
183 |
public: |
54232 | 184 |
DEFINE_SIZE_STATIC (sizeof (Type)); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
185 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
186 |
|
50352 | 187 |
typedef Offset<HBUINT16> Offset16; |
188 |
typedef Offset<HBUINT32> Offset32; |
|
189 |
||
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
190 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
191 |
/* CheckSum */ |
50352 | 192 |
struct CheckSum : HBUINT32 |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
193 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
194 |
/* This is reference implementation from the spec. */ |
54232 | 195 |
static uint32_t CalcTableChecksum (const HBUINT32 *Table, uint32_t Length) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
196 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
197 |
uint32_t Sum = 0L; |
50352 | 198 |
assert (0 == (Length & 3)); |
199 |
const HBUINT32 *EndPtr = Table + Length / HBUINT32::static_size; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
200 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
201 |
while (Table < EndPtr) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
202 |
Sum += *Table++; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
203 |
return Sum; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
204 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
205 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
206 |
/* Note: data should be 4byte aligned and have 4byte padding at the end. */ |
54232 | 207 |
void set_for_data (const void *data, unsigned int length) |
50352 | 208 |
{ set (CalcTableChecksum ((const HBUINT32 *) data, length)); } |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
209 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
210 |
public: |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
211 |
DEFINE_SIZE_STATIC (4); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
212 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
213 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
214 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
215 |
/* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
216 |
* Version Numbers |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
217 |
*/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
218 |
|
50352 | 219 |
template <typename FixedType=HBUINT16> |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
220 |
struct FixedVersion |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
221 |
{ |
54232 | 222 |
uint32_t to_int () const { return (major << (sizeof (FixedType) * 8)) + minor; } |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
223 |
|
54232 | 224 |
bool sanitize (hb_sanitize_context_t *c) const |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
225 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
226 |
TRACE_SANITIZE (this); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
227 |
return_trace (c->check_struct (this)); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
228 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
229 |
|
40435 | 230 |
FixedType major; |
231 |
FixedType minor; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
232 |
public: |
54232 | 233 |
DEFINE_SIZE_STATIC (2 * sizeof (FixedType)); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
234 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
235 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
236 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
237 |
/* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
238 |
* Template subclasses of Offset that do the dereferencing. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
239 |
* Use: (base+offset) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
240 |
*/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
241 |
|
54232 | 242 |
template <typename Type, bool has_null> |
243 |
struct _hb_has_null |
|
244 |
{ |
|
245 |
static const Type *get_null () { return nullptr; } |
|
246 |
static Type *get_crap () { return nullptr; } |
|
247 |
}; |
|
248 |
template <typename Type> |
|
249 |
struct _hb_has_null<Type, true> |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
250 |
{ |
54232 | 251 |
static const Type *get_null () { return &Null(Type); } |
252 |
static Type *get_crap () { return &Crap(Type); } |
|
253 |
}; |
|
254 |
||
255 |
template <typename Type, typename OffsetType=HBUINT16, bool has_null=true> |
|
256 |
struct OffsetTo : Offset<OffsetType, has_null> |
|
257 |
{ |
|
258 |
const Type& operator () (const void *base) const |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
259 |
{ |
54232 | 260 |
if (unlikely (this->is_null ())) return *_hb_has_null<Type, has_null>::get_null (); |
261 |
return StructAtOffset<const Type> (base, *this); |
|
50826 | 262 |
} |
54232 | 263 |
Type& operator () (void *base) const |
50826 | 264 |
{ |
54232 | 265 |
if (unlikely (this->is_null ())) return *_hb_has_null<Type, has_null>::get_crap (); |
266 |
return StructAtOffset<Type> (base, *this); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
267 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
268 |
|
54232 | 269 |
Type& serialize (hb_serialize_context_t *c, const void *base) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
270 |
{ |
50352 | 271 |
return * (Type *) Offset<OffsetType>::serialize (c, base); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
272 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
273 |
|
54232 | 274 |
template <typename T> |
275 |
void serialize_subset (hb_subset_context_t *c, const T &src, const void *base) |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
276 |
{ |
54232 | 277 |
if (&src == &Null (T)) |
278 |
{ |
|
279 |
this->set (0); |
|
280 |
return; |
|
281 |
} |
|
282 |
serialize (c->serializer, base); |
|
283 |
if (!src.subset (c)) |
|
284 |
this->set (0); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
285 |
} |
54232 | 286 |
|
287 |
bool sanitize_shallow (hb_sanitize_context_t *c, const void *base) const |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
288 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
289 |
TRACE_SANITIZE (this); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
290 |
if (unlikely (!c->check_struct (this))) return_trace (false); |
54232 | 291 |
if (unlikely (this->is_null ())) return_trace (true); |
292 |
if (unlikely (!c->check_range (base, *this))) return_trace (false); |
|
293 |
return_trace (true); |
|
294 |
} |
|
295 |
||
296 |
bool sanitize (hb_sanitize_context_t *c, const void *base) const |
|
297 |
{ |
|
298 |
TRACE_SANITIZE (this); |
|
299 |
return_trace (sanitize_shallow (c, base) && |
|
300 |
(this->is_null () || |
|
301 |
StructAtOffset<Type> (base, *this).sanitize (c) || |
|
302 |
neuter (c))); |
|
303 |
} |
|
304 |
template <typename T1> |
|
305 |
bool sanitize (hb_sanitize_context_t *c, const void *base, T1 d1) const |
|
306 |
{ |
|
307 |
TRACE_SANITIZE (this); |
|
308 |
return_trace (sanitize_shallow (c, base) && |
|
309 |
(this->is_null () || |
|
310 |
StructAtOffset<Type> (base, *this).sanitize (c, d1) || |
|
311 |
neuter (c))); |
|
312 |
} |
|
313 |
template <typename T1, typename T2> |
|
314 |
bool sanitize (hb_sanitize_context_t *c, const void *base, T1 d1, T2 d2) const |
|
315 |
{ |
|
316 |
TRACE_SANITIZE (this); |
|
317 |
return_trace (sanitize_shallow (c, base) && |
|
318 |
(this->is_null () || |
|
319 |
StructAtOffset<Type> (base, *this).sanitize (c, d1, d2) || |
|
320 |
neuter (c))); |
|
321 |
} |
|
322 |
template <typename T1, typename T2, typename T3> |
|
323 |
bool sanitize (hb_sanitize_context_t *c, const void *base, T1 d1, T2 d2, T3 d3) const |
|
324 |
{ |
|
325 |
TRACE_SANITIZE (this); |
|
326 |
return_trace (sanitize_shallow (c, base) && |
|
327 |
(this->is_null () || |
|
328 |
StructAtOffset<Type> (base, *this).sanitize (c, d1, d2, d3) || |
|
329 |
neuter (c))); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
330 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
331 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
332 |
/* Set the offset to Null */ |
54232 | 333 |
bool neuter (hb_sanitize_context_t *c) const |
334 |
{ |
|
335 |
if (!has_null) return false; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
336 |
return c->try_set (this, 0); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
337 |
} |
54232 | 338 |
DEFINE_SIZE_STATIC (sizeof (OffsetType)); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
339 |
}; |
54232 | 340 |
/* Partial specializations. */ |
341 |
template <typename Type, bool has_null=true> struct LOffsetTo : OffsetTo<Type, HBUINT32, has_null> {}; |
|
342 |
template <typename Type, typename OffsetType=HBUINT16 > struct NNOffsetTo : OffsetTo<Type, OffsetType, false> {}; |
|
343 |
template <typename Type > struct LNNOffsetTo : OffsetTo<Type, HBUINT32, false> {}; |
|
344 |
||
345 |
template <typename Base, typename OffsetType, bool has_null, typename Type> |
|
346 |
static inline const Type& operator + (const Base &base, const OffsetTo<Type, OffsetType, has_null> &offset) { return offset (base); } |
|
347 |
template <typename Base, typename OffsetType, bool has_null, typename Type> |
|
348 |
static inline Type& operator + (Base &base, OffsetTo<Type, OffsetType, has_null> &offset) { return offset (base); } |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
349 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
350 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
351 |
/* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
352 |
* Array Types |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
353 |
*/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
354 |
|
50826 | 355 |
template <typename Type> |
356 |
struct UnsizedArrayOf |
|
357 |
{ |
|
54232 | 358 |
typedef Type item_t; |
359 |
static constexpr unsigned item_size = hb_static_size (Type); |
|
360 |
||
361 |
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE (UnsizedArrayOf, Type); |
|
362 |
||
363 |
const Type& operator [] (int i_) const |
|
364 |
{ |
|
365 |
unsigned int i = (unsigned int) i_; |
|
366 |
const Type *p = &arrayZ[i]; |
|
367 |
if (unlikely (p < arrayZ)) return Null (Type); /* Overflowed. */ |
|
368 |
return *p; |
|
369 |
} |
|
370 |
Type& operator [] (int i_) |
|
371 |
{ |
|
372 |
unsigned int i = (unsigned int) i_; |
|
373 |
Type *p = &arrayZ[i]; |
|
374 |
if (unlikely (p < arrayZ)) return Crap (Type); /* Overflowed. */ |
|
375 |
return *p; |
|
376 |
} |
|
50826 | 377 |
|
54232 | 378 |
unsigned int get_size (unsigned int len) const |
379 |
{ return len * Type::static_size; } |
|
380 |
||
381 |
template <typename T> operator T * () { return arrayZ; } |
|
382 |
template <typename T> operator const T * () const { return arrayZ; } |
|
383 |
hb_array_t<Type> as_array (unsigned int len) |
|
384 |
{ return hb_array (arrayZ, len); } |
|
385 |
hb_array_t<const Type> as_array (unsigned int len) const |
|
386 |
{ return hb_array (arrayZ, len); } |
|
387 |
operator hb_array_t<Type> () { return as_array (); } |
|
388 |
operator hb_array_t<const Type> () const { return as_array (); } |
|
389 |
||
390 |
template <typename T> |
|
391 |
Type &lsearch (unsigned int len, const T &x, Type ¬_found = Crap (Type)) |
|
392 |
{ return *as_array (len).lsearch (x, ¬_found); } |
|
393 |
template <typename T> |
|
394 |
const Type &lsearch (unsigned int len, const T &x, const Type ¬_found = Null (Type)) const |
|
395 |
{ return *as_array (len).lsearch (x, ¬_found); } |
|
396 |
||
397 |
void qsort (unsigned int len, unsigned int start = 0, unsigned int end = (unsigned int) -1) |
|
398 |
{ as_array (len).qsort (start, end); } |
|
399 |
||
400 |
bool sanitize (hb_sanitize_context_t *c, unsigned int count) const |
|
50826 | 401 |
{ |
402 |
TRACE_SANITIZE (this); |
|
403 |
if (unlikely (!sanitize_shallow (c, count))) return_trace (false); |
|
404 |
||
405 |
/* Note: for structs that do not reference other structs, |
|
406 |
* we do not need to call their sanitize() as we already did |
|
407 |
* a bound check on the aggregate array size. We just include |
|
408 |
* a small unreachable expression to make sure the structs |
|
409 |
* pointed to do have a simple sanitize(), ie. they do not |
|
410 |
* reference other structs via offsets. |
|
411 |
*/ |
|
412 |
(void) (false && arrayZ[0].sanitize (c)); |
|
413 |
||
414 |
return_trace (true); |
|
415 |
} |
|
54232 | 416 |
bool sanitize (hb_sanitize_context_t *c, unsigned int count, const void *base) const |
50826 | 417 |
{ |
418 |
TRACE_SANITIZE (this); |
|
419 |
if (unlikely (!sanitize_shallow (c, count))) return_trace (false); |
|
420 |
for (unsigned int i = 0; i < count; i++) |
|
421 |
if (unlikely (!arrayZ[i].sanitize (c, base))) |
|
422 |
return_trace (false); |
|
423 |
return_trace (true); |
|
424 |
} |
|
425 |
template <typename T> |
|
54232 | 426 |
bool sanitize (hb_sanitize_context_t *c, unsigned int count, const void *base, T user_data) const |
50826 | 427 |
{ |
428 |
TRACE_SANITIZE (this); |
|
429 |
if (unlikely (!sanitize_shallow (c, count))) return_trace (false); |
|
430 |
for (unsigned int i = 0; i < count; i++) |
|
431 |
if (unlikely (!arrayZ[i].sanitize (c, base, user_data))) |
|
432 |
return_trace (false); |
|
433 |
return_trace (true); |
|
434 |
} |
|
435 |
||
54232 | 436 |
bool sanitize_shallow (hb_sanitize_context_t *c, unsigned int count) const |
50826 | 437 |
{ |
438 |
TRACE_SANITIZE (this); |
|
54232 | 439 |
return_trace (c->check_array (arrayZ, count)); |
50826 | 440 |
} |
441 |
||
442 |
public: |
|
54232 | 443 |
Type arrayZ[VAR]; |
50826 | 444 |
public: |
54232 | 445 |
DEFINE_SIZE_UNBOUNDED (0); |
50826 | 446 |
}; |
447 |
||
448 |
/* Unsized array of offset's */ |
|
54232 | 449 |
template <typename Type, typename OffsetType, bool has_null=true> |
450 |
struct UnsizedOffsetArrayOf : UnsizedArrayOf<OffsetTo<Type, OffsetType, has_null> > {}; |
|
50826 | 451 |
|
452 |
/* Unsized array of offsets relative to the beginning of the array itself. */ |
|
54232 | 453 |
template <typename Type, typename OffsetType, bool has_null=true> |
454 |
struct UnsizedOffsetListOf : UnsizedOffsetArrayOf<Type, OffsetType, has_null> |
|
50826 | 455 |
{ |
54232 | 456 |
const Type& operator [] (int i_) const |
50826 | 457 |
{ |
54232 | 458 |
unsigned int i = (unsigned int) i_; |
459 |
const OffsetTo<Type, OffsetType, has_null> *p = &this->arrayZ[i]; |
|
460 |
if (unlikely (p < this->arrayZ)) return Null (Type); /* Overflowed. */ |
|
461 |
return this+*p; |
|
462 |
} |
|
463 |
Type& operator [] (int i_) |
|
464 |
{ |
|
465 |
unsigned int i = (unsigned int) i_; |
|
466 |
const OffsetTo<Type, OffsetType, has_null> *p = &this->arrayZ[i]; |
|
467 |
if (unlikely (p < this->arrayZ)) return Crap (Type); /* Overflowed. */ |
|
468 |
return this+*p; |
|
50826 | 469 |
} |
470 |
||
54232 | 471 |
|
472 |
bool sanitize (hb_sanitize_context_t *c, unsigned int count) const |
|
50826 | 473 |
{ |
474 |
TRACE_SANITIZE (this); |
|
54232 | 475 |
return_trace ((UnsizedOffsetArrayOf<Type, OffsetType, has_null>::sanitize (c, count, this))); |
50826 | 476 |
} |
477 |
template <typename T> |
|
54232 | 478 |
bool sanitize (hb_sanitize_context_t *c, unsigned int count, T user_data) const |
50826 | 479 |
{ |
480 |
TRACE_SANITIZE (this); |
|
54232 | 481 |
return_trace ((UnsizedOffsetArrayOf<Type, OffsetType, has_null>::sanitize (c, count, this, user_data))); |
50826 | 482 |
} |
483 |
}; |
|
484 |
||
54232 | 485 |
/* An array with sorted elements. Supports binary searching. */ |
486 |
template <typename Type> |
|
487 |
struct SortedUnsizedArrayOf : UnsizedArrayOf<Type> |
|
488 |
{ |
|
489 |
hb_sorted_array_t<Type> as_array (unsigned int len) |
|
490 |
{ return hb_sorted_array (this->arrayZ, len); } |
|
491 |
hb_sorted_array_t<const Type> as_array (unsigned int len) const |
|
492 |
{ return hb_sorted_array (this->arrayZ, len); } |
|
493 |
operator hb_sorted_array_t<Type> () { return as_array (); } |
|
494 |
operator hb_sorted_array_t<const Type> () const { return as_array (); } |
|
495 |
||
496 |
template <typename T> |
|
497 |
Type &bsearch (unsigned int len, const T &x, Type ¬_found = Crap (Type)) |
|
498 |
{ return *as_array (len).bsearch (x, ¬_found); } |
|
499 |
template <typename T> |
|
500 |
const Type &bsearch (unsigned int len, const T &x, const Type ¬_found = Null (Type)) const |
|
501 |
{ return *as_array (len).bsearch (x, ¬_found); } |
|
502 |
template <typename T> |
|
503 |
bool bfind (unsigned int len, const T &x, unsigned int *i = nullptr, |
|
504 |
hb_bfind_not_found_t not_found = HB_BFIND_NOT_FOUND_DONT_STORE, |
|
505 |
unsigned int to_store = (unsigned int) -1) const |
|
506 |
{ return as_array (len).bfind (x, i, not_found, to_store); } |
|
507 |
}; |
|
508 |
||
50826 | 509 |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
510 |
/* An array with a number of elements. */ |
50352 | 511 |
template <typename Type, typename LenType=HBUINT16> |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
512 |
struct ArrayOf |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
513 |
{ |
54232 | 514 |
typedef Type item_t; |
515 |
static constexpr unsigned item_size = hb_static_size (Type); |
|
516 |
||
517 |
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (ArrayOf, Type, LenType); |
|
518 |
||
519 |
const Type& operator [] (int i_) const |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
520 |
{ |
54232 | 521 |
unsigned int i = (unsigned int) i_; |
522 |
if (unlikely (i >= len)) return Null (Type); |
|
523 |
return arrayZ[i]; |
|
524 |
} |
|
525 |
Type& operator [] (int i_) |
|
526 |
{ |
|
527 |
unsigned int i = (unsigned int) i_; |
|
528 |
if (unlikely (i >= len)) return Crap (Type); |
|
529 |
return arrayZ[i]; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
530 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
531 |
|
54232 | 532 |
unsigned int get_size () const |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
533 |
{ return len.static_size + len * Type::static_size; } |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
534 |
|
54232 | 535 |
hb_array_t<Type> as_array () |
536 |
{ return hb_array (arrayZ, len); } |
|
537 |
hb_array_t<const Type> as_array () const |
|
538 |
{ return hb_array (arrayZ, len); } |
|
539 |
operator hb_array_t<Type> (void) { return as_array (); } |
|
540 |
operator hb_array_t<const Type> (void) const { return as_array (); } |
|
541 |
||
542 |
hb_array_t<const Type> sub_array (unsigned int start_offset, unsigned int count) const |
|
543 |
{ return as_array ().sub_array (start_offset, count);} |
|
544 |
hb_array_t<const Type> sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */) const |
|
545 |
{ return as_array ().sub_array (start_offset, count);} |
|
546 |
hb_array_t<Type> sub_array (unsigned int start_offset, unsigned int count) |
|
547 |
{ return as_array ().sub_array (start_offset, count);} |
|
548 |
hb_array_t<Type> sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */) |
|
549 |
{ return as_array ().sub_array (start_offset, count);} |
|
550 |
||
551 |
bool serialize (hb_serialize_context_t *c, unsigned int items_len) |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
552 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
553 |
TRACE_SERIALIZE (this); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
554 |
if (unlikely (!c->extend_min (*this))) return_trace (false); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
555 |
len.set (items_len); /* TODO(serialize) Overflow? */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
556 |
if (unlikely (!c->extend (*this))) return_trace (false); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
557 |
return_trace (true); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
558 |
} |
54232 | 559 |
template <typename T> |
560 |
bool serialize (hb_serialize_context_t *c, hb_array_t<const T> items) |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
561 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
562 |
TRACE_SERIALIZE (this); |
54232 | 563 |
if (unlikely (!serialize (c, items.length))) return_trace (false); |
564 |
for (unsigned int i = 0; i < items.length; i++) |
|
565 |
hb_assign (arrayZ[i], items[i]); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
566 |
return_trace (true); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
567 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
568 |
|
54232 | 569 |
bool sanitize (hb_sanitize_context_t *c) const |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
570 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
571 |
TRACE_SANITIZE (this); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
572 |
if (unlikely (!sanitize_shallow (c))) return_trace (false); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
573 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
574 |
/* Note: for structs that do not reference other structs, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
575 |
* we do not need to call their sanitize() as we already did |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
576 |
* a bound check on the aggregate array size. We just include |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
577 |
* a small unreachable expression to make sure the structs |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
578 |
* pointed to do have a simple sanitize(), ie. they do not |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
579 |
* reference other structs via offsets. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
580 |
*/ |
50826 | 581 |
(void) (false && arrayZ[0].sanitize (c)); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
582 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
583 |
return_trace (true); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
584 |
} |
54232 | 585 |
bool sanitize (hb_sanitize_context_t *c, const void *base) const |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
586 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
587 |
TRACE_SANITIZE (this); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
588 |
if (unlikely (!sanitize_shallow (c))) return_trace (false); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
589 |
unsigned int count = len; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
590 |
for (unsigned int i = 0; i < count; i++) |
50826 | 591 |
if (unlikely (!arrayZ[i].sanitize (c, base))) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
592 |
return_trace (false); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
593 |
return_trace (true); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
594 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
595 |
template <typename T> |
54232 | 596 |
bool sanitize (hb_sanitize_context_t *c, const void *base, T user_data) const |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
597 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
598 |
TRACE_SANITIZE (this); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
599 |
if (unlikely (!sanitize_shallow (c))) return_trace (false); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
600 |
unsigned int count = len; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
601 |
for (unsigned int i = 0; i < count; i++) |
50826 | 602 |
if (unlikely (!arrayZ[i].sanitize (c, base, user_data))) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
603 |
return_trace (false); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
604 |
return_trace (true); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
605 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
606 |
|
54232 | 607 |
template <typename T> |
608 |
Type &lsearch (const T &x, Type ¬_found = Crap (Type)) |
|
609 |
{ return *as_array ().lsearch (x, ¬_found); } |
|
610 |
template <typename T> |
|
611 |
const Type &lsearch (const T &x, const Type ¬_found = Null (Type)) const |
|
612 |
{ return *as_array ().lsearch (x, ¬_found); } |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
613 |
|
54232 | 614 |
void qsort (unsigned int start = 0, unsigned int end = (unsigned int) -1) |
615 |
{ as_array ().qsort (start, end); } |
|
50352 | 616 |
|
54232 | 617 |
bool sanitize_shallow (hb_sanitize_context_t *c) const |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
618 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
619 |
TRACE_SANITIZE (this); |
54232 | 620 |
return_trace (len.sanitize (c) && c->check_array (arrayZ, len)); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
621 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
622 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
623 |
public: |
54232 | 624 |
LenType len; |
625 |
Type arrayZ[VAR]; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
626 |
public: |
50826 | 627 |
DEFINE_SIZE_ARRAY (sizeof (LenType), arrayZ); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
628 |
}; |
50352 | 629 |
template <typename Type> struct LArrayOf : ArrayOf<Type, HBUINT32> {}; |
51000 | 630 |
typedef ArrayOf<HBUINT8, HBUINT8> PString; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
631 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
632 |
/* Array of Offset's */ |
54232 | 633 |
template <typename Type> |
634 |
struct OffsetArrayOf : ArrayOf<OffsetTo<Type, HBUINT16> > {}; |
|
635 |
template <typename Type> |
|
636 |
struct LOffsetArrayOf : ArrayOf<OffsetTo<Type, HBUINT32> > {}; |
|
637 |
template <typename Type> |
|
638 |
struct LOffsetLArrayOf : ArrayOf<OffsetTo<Type, HBUINT32>, HBUINT32> {}; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
639 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
640 |
/* Array of offsets relative to the beginning of the array itself. */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
641 |
template <typename Type> |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
642 |
struct OffsetListOf : OffsetArrayOf<Type> |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
643 |
{ |
54232 | 644 |
const Type& operator [] (int i_) const |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
645 |
{ |
54232 | 646 |
unsigned int i = (unsigned int) i_; |
647 |
if (unlikely (i >= this->len)) return Null (Type); |
|
50826 | 648 |
return this+this->arrayZ[i]; |
649 |
} |
|
54232 | 650 |
const Type& operator [] (int i_) |
50826 | 651 |
{ |
54232 | 652 |
unsigned int i = (unsigned int) i_; |
653 |
if (unlikely (i >= this->len)) return Crap (Type); |
|
50826 | 654 |
return this+this->arrayZ[i]; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
655 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
656 |
|
54232 | 657 |
bool subset (hb_subset_context_t *c) const |
658 |
{ |
|
659 |
TRACE_SUBSET (this); |
|
660 |
struct OffsetListOf<Type> *out = c->serializer->embed (*this); |
|
661 |
if (unlikely (!out)) return_trace (false); |
|
662 |
unsigned int count = this->len; |
|
663 |
for (unsigned int i = 0; i < count; i++) |
|
664 |
out->arrayZ[i].serialize_subset (c, (*this)[i], out); |
|
665 |
return_trace (true); |
|
666 |
} |
|
667 |
||
668 |
bool sanitize (hb_sanitize_context_t *c) const |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
669 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
670 |
TRACE_SANITIZE (this); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
671 |
return_trace (OffsetArrayOf<Type>::sanitize (c, this)); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
672 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
673 |
template <typename T> |
54232 | 674 |
bool sanitize (hb_sanitize_context_t *c, T user_data) const |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
675 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
676 |
TRACE_SANITIZE (this); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
677 |
return_trace (OffsetArrayOf<Type>::sanitize (c, this, user_data)); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
678 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
679 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
680 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
681 |
/* An array starting at second element. */ |
50352 | 682 |
template <typename Type, typename LenType=HBUINT16> |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
683 |
struct HeadlessArrayOf |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
684 |
{ |
54232 | 685 |
static constexpr unsigned item_size = Type::static_size; |
686 |
||
687 |
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (HeadlessArrayOf, Type, LenType); |
|
688 |
||
689 |
const Type& operator [] (int i_) const |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
690 |
{ |
54232 | 691 |
unsigned int i = (unsigned int) i_; |
692 |
if (unlikely (i >= lenP1 || !i)) return Null (Type); |
|
50826 | 693 |
return arrayZ[i-1]; |
694 |
} |
|
54232 | 695 |
Type& operator [] (int i_) |
50826 | 696 |
{ |
54232 | 697 |
unsigned int i = (unsigned int) i_; |
698 |
if (unlikely (i >= lenP1 || !i)) return Crap (Type); |
|
50826 | 699 |
return arrayZ[i-1]; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
700 |
} |
54232 | 701 |
unsigned int get_size () const |
702 |
{ return lenP1.static_size + (lenP1 ? lenP1 - 1 : 0) * Type::static_size; } |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
703 |
|
54232 | 704 |
bool serialize (hb_serialize_context_t *c, |
705 |
hb_array_t<const Type> items) |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
706 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
707 |
TRACE_SERIALIZE (this); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
708 |
if (unlikely (!c->extend_min (*this))) return_trace (false); |
54232 | 709 |
lenP1.set (items.length + 1); /* TODO(serialize) Overflow? */ |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
710 |
if (unlikely (!c->extend (*this))) return_trace (false); |
54232 | 711 |
for (unsigned int i = 0; i < items.length; i++) |
50826 | 712 |
arrayZ[i] = items[i]; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
713 |
return_trace (true); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
714 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
715 |
|
54232 | 716 |
bool sanitize (hb_sanitize_context_t *c) const |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
717 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
718 |
TRACE_SANITIZE (this); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
719 |
if (unlikely (!sanitize_shallow (c))) return_trace (false); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
720 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
721 |
/* Note: for structs that do not reference other structs, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
722 |
* we do not need to call their sanitize() as we already did |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
723 |
* a bound check on the aggregate array size. We just include |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
724 |
* a small unreachable expression to make sure the structs |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
725 |
* pointed to do have a simple sanitize(), ie. they do not |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
726 |
* reference other structs via offsets. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
727 |
*/ |
50826 | 728 |
(void) (false && arrayZ[0].sanitize (c)); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
729 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
730 |
return_trace (true); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
731 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
732 |
|
48274 | 733 |
private: |
54232 | 734 |
bool sanitize_shallow (hb_sanitize_context_t *c) const |
48274 | 735 |
{ |
736 |
TRACE_SANITIZE (this); |
|
54232 | 737 |
return_trace (lenP1.sanitize (c) && |
738 |
(!lenP1 || c->check_array (arrayZ, lenP1 - 1))); |
|
48274 | 739 |
} |
740 |
||
741 |
public: |
|
54232 | 742 |
LenType lenP1; |
743 |
Type arrayZ[VAR]; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
744 |
public: |
50826 | 745 |
DEFINE_SIZE_ARRAY (sizeof (LenType), arrayZ); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
746 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
747 |
|
54232 | 748 |
/* An array storing length-1. */ |
749 |
template <typename Type, typename LenType=HBUINT16> |
|
750 |
struct ArrayOfM1 |
|
751 |
{ |
|
752 |
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (ArrayOfM1, Type, LenType); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
753 |
|
54232 | 754 |
const Type& operator [] (int i_) const |
755 |
{ |
|
756 |
unsigned int i = (unsigned int) i_; |
|
757 |
if (unlikely (i > lenM1)) return Null (Type); |
|
758 |
return arrayZ[i]; |
|
759 |
} |
|
760 |
Type& operator [] (int i_) |
|
761 |
{ |
|
762 |
unsigned int i = (unsigned int) i_; |
|
763 |
if (unlikely (i > lenM1)) return Crap (Type); |
|
764 |
return arrayZ[i]; |
|
765 |
} |
|
766 |
unsigned int get_size () const |
|
767 |
{ return lenM1.static_size + (lenM1 + 1) * Type::static_size; } |
|
768 |
||
769 |
template <typename T> |
|
770 |
bool sanitize (hb_sanitize_context_t *c, const void *base, T user_data) const |
|
771 |
{ |
|
772 |
TRACE_SANITIZE (this); |
|
773 |
if (unlikely (!sanitize_shallow (c))) return_trace (false); |
|
774 |
unsigned int count = lenM1 + 1; |
|
775 |
for (unsigned int i = 0; i < count; i++) |
|
776 |
if (unlikely (!arrayZ[i].sanitize (c, base, user_data))) |
|
777 |
return_trace (false); |
|
778 |
return_trace (true); |
|
779 |
} |
|
780 |
||
781 |
private: |
|
782 |
bool sanitize_shallow (hb_sanitize_context_t *c) const |
|
783 |
{ |
|
784 |
TRACE_SANITIZE (this); |
|
785 |
return_trace (lenM1.sanitize (c) && |
|
786 |
(c->check_array (arrayZ, lenM1 + 1))); |
|
787 |
} |
|
788 |
||
789 |
public: |
|
790 |
LenType lenM1; |
|
791 |
Type arrayZ[VAR]; |
|
792 |
public: |
|
793 |
DEFINE_SIZE_ARRAY (sizeof (LenType), arrayZ); |
|
794 |
}; |
|
795 |
||
796 |
/* An array with sorted elements. Supports binary searching. */ |
|
50352 | 797 |
template <typename Type, typename LenType=HBUINT16> |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
798 |
struct SortedArrayOf : ArrayOf<Type, LenType> |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
799 |
{ |
54232 | 800 |
hb_sorted_array_t<Type> as_array () |
801 |
{ return hb_sorted_array (this->arrayZ, this->len); } |
|
802 |
hb_sorted_array_t<const Type> as_array () const |
|
803 |
{ return hb_sorted_array (this->arrayZ, this->len); } |
|
804 |
operator hb_sorted_array_t<Type> () { return as_array (); } |
|
805 |
operator hb_sorted_array_t<const Type> () const { return as_array (); } |
|
806 |
||
807 |
hb_array_t<const Type> sub_array (unsigned int start_offset, unsigned int count) const |
|
808 |
{ return as_array ().sub_array (start_offset, count);} |
|
809 |
hb_array_t<const Type> sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */) const |
|
810 |
{ return as_array ().sub_array (start_offset, count);} |
|
811 |
hb_array_t<Type> sub_array (unsigned int start_offset, unsigned int count) |
|
812 |
{ return as_array ().sub_array (start_offset, count);} |
|
813 |
hb_array_t<Type> sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */) |
|
814 |
{ return as_array ().sub_array (start_offset, count);} |
|
815 |
||
816 |
template <typename T> |
|
817 |
Type &bsearch (const T &x, Type ¬_found = Crap (Type)) |
|
818 |
{ return *as_array ().bsearch (x, ¬_found); } |
|
819 |
template <typename T> |
|
820 |
const Type &bsearch (const T &x, const Type ¬_found = Null (Type)) const |
|
821 |
{ return *as_array ().bsearch (x, ¬_found); } |
|
822 |
template <typename T> |
|
823 |
bool bfind (const T &x, unsigned int *i = nullptr, |
|
824 |
hb_bfind_not_found_t not_found = HB_BFIND_NOT_FOUND_DONT_STORE, |
|
825 |
unsigned int to_store = (unsigned int) -1) const |
|
826 |
{ return as_array ().bfind (x, i, not_found, to_store); } |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
827 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
828 |
|
48274 | 829 |
/* |
830 |
* Binary-search arrays |
|
831 |
*/ |
|
832 |
||
54232 | 833 |
template <typename LenType=HBUINT16> |
48274 | 834 |
struct BinSearchHeader |
835 |
{ |
|
54232 | 836 |
operator uint32_t () const { return len; } |
48274 | 837 |
|
54232 | 838 |
bool sanitize (hb_sanitize_context_t *c) const |
48274 | 839 |
{ |
840 |
TRACE_SANITIZE (this); |
|
841 |
return_trace (c->check_struct (this)); |
|
842 |
} |
|
843 |
||
54232 | 844 |
void set (unsigned int v) |
50352 | 845 |
{ |
846 |
len.set (v); |
|
847 |
assert (len == v); |
|
54232 | 848 |
entrySelector.set (MAX (1u, hb_bit_storage (v)) - 1); |
50826 | 849 |
searchRange.set (16 * (1u << entrySelector)); |
850 |
rangeShift.set (v * 16 > searchRange |
|
851 |
? 16 * v - searchRange |
|
852 |
: 0); |
|
50352 | 853 |
} |
854 |
||
48274 | 855 |
protected: |
54232 | 856 |
LenType len; |
857 |
LenType searchRange; |
|
858 |
LenType entrySelector; |
|
859 |
LenType rangeShift; |
|
48274 | 860 |
|
861 |
public: |
|
862 |
DEFINE_SIZE_STATIC (8); |
|
863 |
}; |
|
864 |
||
54232 | 865 |
template <typename Type, typename LenType=HBUINT16> |
866 |
struct BinSearchArrayOf : SortedArrayOf<Type, BinSearchHeader<LenType> > {}; |
|
48274 | 867 |
|
868 |
||
54232 | 869 |
struct VarSizedBinSearchHeader |
870 |
{ |
|
48274 | 871 |
|
54232 | 872 |
bool sanitize (hb_sanitize_context_t *c) const |
48274 | 873 |
{ |
54232 | 874 |
TRACE_SANITIZE (this); |
875 |
return_trace (c->check_struct (this)); |
|
48274 | 876 |
} |
877 |
||
54232 | 878 |
HBUINT16 unitSize; /* Size of a lookup unit for this search in bytes. */ |
879 |
HBUINT16 nUnits; /* Number of units of the preceding size to be searched. */ |
|
880 |
HBUINT16 searchRange; /* The value of unitSize times the largest power of 2 |
|
881 |
* that is less than or equal to the value of nUnits. */ |
|
882 |
HBUINT16 entrySelector; /* The log base 2 of the largest power of 2 less than |
|
883 |
* or equal to the value of nUnits. */ |
|
884 |
HBUINT16 rangeShift; /* The value of unitSize times the difference of the |
|
885 |
* value of nUnits minus the largest power of 2 less |
|
886 |
* than or equal to the value of nUnits. */ |
|
887 |
public: |
|
888 |
DEFINE_SIZE_STATIC (10); |
|
889 |
}; |
|
890 |
||
891 |
template <typename Type> |
|
892 |
struct VarSizedBinSearchArrayOf |
|
893 |
{ |
|
894 |
static constexpr unsigned item_size = Type::static_size; |
|
895 |
||
896 |
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE (VarSizedBinSearchArrayOf, Type); |
|
897 |
||
898 |
bool last_is_terminator () const |
|
48274 | 899 |
{ |
54232 | 900 |
if (unlikely (!header.nUnits)) return false; |
901 |
||
902 |
/* Gah. |
|
903 |
* |
|
904 |
* "The number of termination values that need to be included is table-specific. |
|
905 |
* The value that indicates binary search termination is 0xFFFF." */ |
|
906 |
const HBUINT16 *words = &StructAtOffset<HBUINT16> (&bytesZ, (header.nUnits - 1) * header.unitSize); |
|
907 |
unsigned int count = Type::TerminationWordCount; |
|
908 |
for (unsigned int i = 0; i < count; i++) |
|
909 |
if (words[i] != 0xFFFFu) |
|
910 |
return false; |
|
911 |
return true; |
|
48274 | 912 |
} |
913 |
||
54232 | 914 |
const Type& operator [] (int i_) const |
915 |
{ |
|
916 |
unsigned int i = (unsigned int) i_; |
|
917 |
if (unlikely (i >= get_length ())) return Null (Type); |
|
918 |
return StructAtOffset<Type> (&bytesZ, i * header.unitSize); |
|
919 |
} |
|
920 |
Type& operator [] (int i_) |
|
921 |
{ |
|
922 |
unsigned int i = (unsigned int) i_; |
|
923 |
if (unlikely (i >= get_length ())) return Crap (Type); |
|
924 |
return StructAtOffset<Type> (&bytesZ, i * header.unitSize); |
|
925 |
} |
|
926 |
unsigned int get_length () const |
|
927 |
{ return header.nUnits - last_is_terminator (); } |
|
928 |
unsigned int get_size () const |
|
929 |
{ return header.static_size + header.nUnits * header.unitSize; } |
|
930 |
||
931 |
bool sanitize (hb_sanitize_context_t *c) const |
|
48274 | 932 |
{ |
54232 | 933 |
TRACE_SANITIZE (this); |
934 |
if (unlikely (!sanitize_shallow (c))) return_trace (false); |
|
935 |
||
936 |
/* Note: for structs that do not reference other structs, |
|
937 |
* we do not need to call their sanitize() as we already did |
|
938 |
* a bound check on the aggregate array size. We just include |
|
939 |
* a small unreachable expression to make sure the structs |
|
940 |
* pointed to do have a simple sanitize(), ie. they do not |
|
941 |
* reference other structs via offsets. |
|
942 |
*/ |
|
943 |
(void) (false && StructAtOffset<Type> (&bytesZ, 0).sanitize (c)); |
|
944 |
||
945 |
return_trace (true); |
|
946 |
} |
|
947 |
bool sanitize (hb_sanitize_context_t *c, const void *base) const |
|
948 |
{ |
|
949 |
TRACE_SANITIZE (this); |
|
950 |
if (unlikely (!sanitize_shallow (c))) return_trace (false); |
|
951 |
unsigned int count = get_length (); |
|
952 |
for (unsigned int i = 0; i < count; i++) |
|
953 |
if (unlikely (!(*this)[i].sanitize (c, base))) |
|
954 |
return_trace (false); |
|
955 |
return_trace (true); |
|
956 |
} |
|
957 |
template <typename T> |
|
958 |
bool sanitize (hb_sanitize_context_t *c, const void *base, T user_data) const |
|
959 |
{ |
|
960 |
TRACE_SANITIZE (this); |
|
961 |
if (unlikely (!sanitize_shallow (c))) return_trace (false); |
|
962 |
unsigned int count = get_length (); |
|
963 |
for (unsigned int i = 0; i < count; i++) |
|
964 |
if (unlikely (!(*this)[i].sanitize (c, base, user_data))) |
|
965 |
return_trace (false); |
|
966 |
return_trace (true); |
|
48274 | 967 |
} |
968 |
||
54232 | 969 |
template <typename T> |
970 |
const Type *bsearch (const T &key) const |
|
48274 | 971 |
{ |
54232 | 972 |
unsigned int size = header.unitSize; |
973 |
int min = 0, max = (int) get_length () - 1; |
|
974 |
while (min <= max) |
|
975 |
{ |
|
976 |
int mid = ((unsigned int) min + (unsigned int) max) / 2; |
|
977 |
const Type *p = (const Type *) (((const char *) &bytesZ) + (mid * size)); |
|
978 |
int c = p->cmp (key); |
|
979 |
if (c < 0) max = mid - 1; |
|
980 |
else if (c > 0) min = mid + 1; |
|
981 |
else return p; |
|
982 |
} |
|
983 |
return nullptr; |
|
48274 | 984 |
} |
985 |
||
986 |
private: |
|
54232 | 987 |
bool sanitize_shallow (hb_sanitize_context_t *c) const |
48274 | 988 |
{ |
54232 | 989 |
TRACE_SANITIZE (this); |
990 |
return_trace (header.sanitize (c) && |
|
991 |
Type::static_size <= header.unitSize && |
|
992 |
c->check_range (bytesZ.arrayZ, |
|
993 |
header.nUnits, |
|
994 |
header.unitSize)); |
|
48274 | 995 |
} |
996 |
||
54232 | 997 |
protected: |
998 |
VarSizedBinSearchHeader header; |
|
999 |
UnsizedArrayOf<HBUINT8> bytesZ; |
|
1000 |
public: |
|
1001 |
DEFINE_SIZE_ARRAY (10, bytesZ); |
|
48274 | 1002 |
}; |
1003 |
||
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
1004 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
1005 |
} /* namespace OT */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
1006 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
1007 |
|
54232 | 1008 |
#endif /* HB_OPEN_TYPE_HH */ |