author | prr |
Fri, 01 Mar 2019 16:59:19 -0800 | |
changeset 54232 | 7c11a7cc7c1d |
parent 48274 | src/java.desktop/share/native/libfontmanager/harfbuzz/hb-utf-private.hh@51772bf1fb0c |
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 © 2011,2012,2014 Google, Inc. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
3 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
4 |
* This is part of HarfBuzz, a text shaping library. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
5 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
6 |
* Permission is hereby granted, without written agreement and without |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
7 |
* 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
|
8 |
* software and its documentation for any purpose, provided that the |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
9 |
* above copyright notice and the following two paragraphs appear in |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
10 |
* all copies of this software. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
11 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
12 |
* 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
|
13 |
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
14 |
* 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
|
15 |
* 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
|
16 |
* DAMAGE. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
17 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
18 |
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
19 |
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
20 |
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
21 |
* 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
|
22 |
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
23 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
24 |
* Google Author(s): Behdad Esfahbod |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
25 |
*/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
26 |
|
54232 | 27 |
#ifndef HB_UTF_HH |
28 |
#define HB_UTF_HH |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
29 |
|
54232 | 30 |
#include "hb.hh" |
31 |
||
32 |
#include "hb-open-type.hh" |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
33 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
34 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
35 |
struct hb_utf8_t |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
36 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
37 |
typedef uint8_t codepoint_t; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
38 |
|
54232 | 39 |
static const codepoint_t * |
40 |
next (const codepoint_t *text, |
|
41 |
const codepoint_t *end, |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
42 |
hb_codepoint_t *unicode, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
43 |
hb_codepoint_t replacement) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
44 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
45 |
/* Written to only accept well-formed sequences. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
46 |
* Based on ideas from ICU's U8_NEXT. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
47 |
* Generates one "replacement" for each ill-formed byte. */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
48 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
49 |
hb_codepoint_t c = *text++; |
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 |
if (c > 0x7Fu) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
52 |
{ |
48274 | 53 |
if (hb_in_range<hb_codepoint_t> (c, 0xC2u, 0xDFu)) /* Two-byte */ |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
54 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
55 |
unsigned int t1; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
56 |
if (likely (text < end && |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
57 |
(t1 = text[0] - 0x80u) <= 0x3Fu)) |
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 |
c = ((c&0x1Fu)<<6) | t1; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
60 |
text++; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
61 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
62 |
else |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
63 |
goto error; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
64 |
} |
48274 | 65 |
else if (hb_in_range<hb_codepoint_t> (c, 0xE0u, 0xEFu)) /* Three-byte */ |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
66 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
67 |
unsigned int t1, t2; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
68 |
if (likely (1 < end - text && |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
69 |
(t1 = text[0] - 0x80u) <= 0x3Fu && |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
70 |
(t2 = text[1] - 0x80u) <= 0x3Fu)) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
71 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
72 |
c = ((c&0xFu)<<12) | (t1<<6) | t2; |
48274 | 73 |
if (unlikely (c < 0x0800u || hb_in_range<hb_codepoint_t> (c, 0xD800u, 0xDFFFu))) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
74 |
goto error; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
75 |
text += 2; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
76 |
} |
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 |
goto error; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
79 |
} |
48274 | 80 |
else if (hb_in_range<hb_codepoint_t> (c, 0xF0u, 0xF4u)) /* Four-byte */ |
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 |
unsigned int t1, t2, t3; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
83 |
if (likely (2 < end - text && |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
84 |
(t1 = text[0] - 0x80u) <= 0x3Fu && |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
85 |
(t2 = text[1] - 0x80u) <= 0x3Fu && |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
86 |
(t3 = text[2] - 0x80u) <= 0x3Fu)) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
87 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
88 |
c = ((c&0x7u)<<18) | (t1<<12) | (t2<<6) | t3; |
48274 | 89 |
if (unlikely (!hb_in_range<hb_codepoint_t> (c, 0x10000u, 0x10FFFFu))) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
90 |
goto error; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
91 |
text += 3; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
92 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
93 |
else |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
94 |
goto error; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
95 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
96 |
else |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
97 |
goto error; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
98 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
99 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
100 |
*unicode = c; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
101 |
return text; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
102 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
103 |
error: |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
104 |
*unicode = replacement; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
105 |
return text; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
106 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
107 |
|
54232 | 108 |
static const codepoint_t * |
109 |
prev (const codepoint_t *text, |
|
110 |
const codepoint_t *start, |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
111 |
hb_codepoint_t *unicode, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
112 |
hb_codepoint_t replacement) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
113 |
{ |
54232 | 114 |
const codepoint_t *end = text--; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
115 |
while (start < text && (*text & 0xc0) == 0x80 && end - text < 4) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
116 |
text--; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
117 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
118 |
if (likely (next (text, end, unicode, replacement) == end)) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
119 |
return text; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
120 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
121 |
*unicode = replacement; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
122 |
return end - 1; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
123 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
124 |
|
54232 | 125 |
static unsigned int |
126 |
strlen (const codepoint_t *text) |
|
127 |
{ return ::strlen ((const char *) text); } |
|
128 |
||
129 |
static unsigned int |
|
130 |
encode_len (hb_codepoint_t unicode) |
|
131 |
{ |
|
132 |
if (unicode < 0x0080u) return 1; |
|
133 |
if (unicode < 0x0800u) return 2; |
|
134 |
if (unicode < 0x10000u) return 3; |
|
135 |
if (unicode < 0x110000u) return 4; |
|
136 |
return 3; |
|
137 |
} |
|
138 |
||
139 |
static codepoint_t * |
|
140 |
encode (codepoint_t *text, |
|
141 |
const codepoint_t *end, |
|
142 |
hb_codepoint_t unicode) |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
143 |
{ |
54232 | 144 |
if (unlikely (unicode >= 0xD800u && (unicode <= 0xDFFFu || unicode > 0x10FFFFu))) |
145 |
unicode = 0xFFFDu; |
|
146 |
if (unicode < 0x0080u) |
|
147 |
*text++ = unicode; |
|
148 |
else if (unicode < 0x0800u) |
|
149 |
{ |
|
150 |
if (end - text >= 2) |
|
151 |
{ |
|
152 |
*text++ = 0xC0u + (0x1Fu & (unicode >> 6)); |
|
153 |
*text++ = 0x80u + (0x3Fu & (unicode )); |
|
154 |
} |
|
155 |
} |
|
156 |
else if (unicode < 0x10000u) |
|
157 |
{ |
|
158 |
if (end - text >= 3) |
|
159 |
{ |
|
160 |
*text++ = 0xE0u + (0x0Fu & (unicode >> 12)); |
|
161 |
*text++ = 0x80u + (0x3Fu & (unicode >> 6)); |
|
162 |
*text++ = 0x80u + (0x3Fu & (unicode )); |
|
163 |
} |
|
164 |
} |
|
165 |
else |
|
166 |
{ |
|
167 |
if (end - text >= 4) |
|
168 |
{ |
|
169 |
*text++ = 0xF0u + (0x07u & (unicode >> 18)); |
|
170 |
*text++ = 0x80u + (0x3Fu & (unicode >> 12)); |
|
171 |
*text++ = 0x80u + (0x3Fu & (unicode >> 6)); |
|
172 |
*text++ = 0x80u + (0x3Fu & (unicode )); |
|
173 |
} |
|
174 |
} |
|
175 |
return text; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
176 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
177 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
178 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
179 |
|
54232 | 180 |
template <typename TCodepoint> |
181 |
struct hb_utf16_xe_t |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
182 |
{ |
54232 | 183 |
static_assert (sizeof (TCodepoint) == 2, ""); |
184 |
typedef TCodepoint codepoint_t; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
185 |
|
54232 | 186 |
static const codepoint_t * |
187 |
next (const codepoint_t *text, |
|
188 |
const codepoint_t *end, |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
189 |
hb_codepoint_t *unicode, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
190 |
hb_codepoint_t replacement) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
191 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
192 |
hb_codepoint_t c = *text++; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
193 |
|
48274 | 194 |
if (likely (!hb_in_range<hb_codepoint_t> (c, 0xD800u, 0xDFFFu))) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
195 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
196 |
*unicode = c; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
197 |
return text; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
198 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
199 |
|
40435 | 200 |
if (likely (c <= 0xDBFFu && text < end)) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
201 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
202 |
/* High-surrogate in c */ |
40435 | 203 |
hb_codepoint_t l = *text; |
48274 | 204 |
if (likely (hb_in_range<hb_codepoint_t> (l, 0xDC00u, 0xDFFFu))) |
34414
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 |
/* Low-surrogate in l */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
207 |
*unicode = (c << 10) + l - ((0xD800u << 10) - 0x10000u + 0xDC00u); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
208 |
text++; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
209 |
return text; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
210 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
211 |
} |
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 |
/* Lonely / out-of-order surrogate. */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
214 |
*unicode = replacement; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
215 |
return text; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
216 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
217 |
|
54232 | 218 |
static const codepoint_t * |
219 |
prev (const codepoint_t *text, |
|
220 |
const codepoint_t *start, |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
221 |
hb_codepoint_t *unicode, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
222 |
hb_codepoint_t replacement) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
223 |
{ |
40435 | 224 |
hb_codepoint_t c = *--text; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
225 |
|
48274 | 226 |
if (likely (!hb_in_range<hb_codepoint_t> (c, 0xD800u, 0xDFFFu))) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
227 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
228 |
*unicode = c; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
229 |
return text; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
230 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
231 |
|
40435 | 232 |
if (likely (c >= 0xDC00u && start < text)) |
233 |
{ |
|
234 |
/* Low-surrogate in c */ |
|
235 |
hb_codepoint_t h = text[-1]; |
|
48274 | 236 |
if (likely (hb_in_range<hb_codepoint_t> (h, 0xD800u, 0xDBFFu))) |
40435 | 237 |
{ |
238 |
/* High-surrogate in h */ |
|
239 |
*unicode = (h << 10) + c - ((0xD800u << 10) - 0x10000u + 0xDC00u); |
|
240 |
text--; |
|
241 |
return text; |
|
242 |
} |
|
243 |
} |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
244 |
|
40435 | 245 |
/* Lonely / out-of-order surrogate. */ |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
246 |
*unicode = replacement; |
40435 | 247 |
return text; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
248 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
249 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
250 |
|
54232 | 251 |
static unsigned int |
252 |
strlen (const codepoint_t *text) |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
253 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
254 |
unsigned int l = 0; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
255 |
while (*text++) l++; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
256 |
return l; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
257 |
} |
54232 | 258 |
|
259 |
static unsigned int |
|
260 |
encode_len (hb_codepoint_t unicode) |
|
261 |
{ |
|
262 |
return unicode < 0x10000 ? 1 : 2; |
|
263 |
} |
|
264 |
||
265 |
static codepoint_t * |
|
266 |
encode (codepoint_t *text, |
|
267 |
const codepoint_t *end, |
|
268 |
hb_codepoint_t unicode) |
|
269 |
{ |
|
270 |
if (unlikely (unicode >= 0xD800u && (unicode <= 0xDFFFu || unicode > 0x10FFFFu))) |
|
271 |
unicode = 0xFFFDu; |
|
272 |
if (unicode < 0x10000u) |
|
273 |
*text++ = unicode; |
|
274 |
else if (end - text >= 2) |
|
275 |
{ |
|
276 |
unicode -= 0x10000u; |
|
277 |
*text++ = 0xD800u + (unicode >> 10); |
|
278 |
*text++ = 0xDC00u + (unicode & 0x03FFu); |
|
279 |
} |
|
280 |
return text; |
|
281 |
} |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
282 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
283 |
|
54232 | 284 |
typedef hb_utf16_xe_t<uint16_t> hb_utf16_t; |
285 |
typedef hb_utf16_xe_t<OT::HBUINT16> hb_utf16_be_t; |
|
286 |
||
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
287 |
|
54232 | 288 |
template <typename TCodepoint, bool validate=true> |
289 |
struct hb_utf32_xe_t |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
290 |
{ |
54232 | 291 |
static_assert (sizeof (TCodepoint) == 4, ""); |
292 |
typedef TCodepoint codepoint_t; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
293 |
|
54232 | 294 |
static const TCodepoint * |
295 |
next (const TCodepoint *text, |
|
296 |
const TCodepoint *end HB_UNUSED, |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
297 |
hb_codepoint_t *unicode, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
298 |
hb_codepoint_t replacement) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
299 |
{ |
40435 | 300 |
hb_codepoint_t c = *unicode = *text++; |
301 |
if (validate && unlikely (c >= 0xD800u && (c <= 0xDFFFu || c > 0x10FFFFu))) |
|
302 |
*unicode = replacement; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
303 |
return text; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
304 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
305 |
|
54232 | 306 |
static const TCodepoint * |
307 |
prev (const TCodepoint *text, |
|
308 |
const TCodepoint *start HB_UNUSED, |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
309 |
hb_codepoint_t *unicode, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
310 |
hb_codepoint_t replacement) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
311 |
{ |
40435 | 312 |
hb_codepoint_t c = *unicode = *--text; |
313 |
if (validate && unlikely (c >= 0xD800u && (c <= 0xDFFFu || c > 0x10FFFFu))) |
|
314 |
*unicode = replacement; |
|
315 |
return text; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
316 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
317 |
|
54232 | 318 |
static unsigned int |
319 |
strlen (const TCodepoint *text) |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
320 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
321 |
unsigned int l = 0; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
322 |
while (*text++) l++; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
323 |
return l; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
324 |
} |
54232 | 325 |
|
326 |
static unsigned int |
|
327 |
encode_len (hb_codepoint_t unicode HB_UNUSED) |
|
328 |
{ |
|
329 |
return 1; |
|
330 |
} |
|
331 |
||
332 |
static codepoint_t * |
|
333 |
encode (codepoint_t *text, |
|
334 |
const codepoint_t *end HB_UNUSED, |
|
335 |
hb_codepoint_t unicode) |
|
336 |
{ |
|
337 |
if (validate && unlikely (unicode >= 0xD800u && (unicode <= 0xDFFFu || unicode > 0x10FFFFu))) |
|
338 |
unicode = 0xFFFDu; |
|
339 |
*text++ = unicode; |
|
340 |
return text; |
|
341 |
} |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
342 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
343 |
|
54232 | 344 |
typedef hb_utf32_xe_t<uint32_t> hb_utf32_t; |
345 |
typedef hb_utf32_xe_t<uint32_t, false> hb_utf32_novalidate_t; |
|
346 |
||
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
347 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
348 |
struct hb_latin1_t |
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 |
typedef uint8_t codepoint_t; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
351 |
|
54232 | 352 |
static const codepoint_t * |
353 |
next (const codepoint_t *text, |
|
354 |
const codepoint_t *end HB_UNUSED, |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
355 |
hb_codepoint_t *unicode, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
356 |
hb_codepoint_t replacement HB_UNUSED) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
357 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
358 |
*unicode = *text++; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
359 |
return text; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
360 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
361 |
|
54232 | 362 |
static const codepoint_t * |
363 |
prev (const codepoint_t *text, |
|
364 |
const codepoint_t *start HB_UNUSED, |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
365 |
hb_codepoint_t *unicode, |
54232 | 366 |
hb_codepoint_t replacement HB_UNUSED) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
367 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
368 |
*unicode = *--text; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
369 |
return text; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
370 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
371 |
|
54232 | 372 |
static unsigned int |
373 |
strlen (const codepoint_t *text) |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
374 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
375 |
unsigned int l = 0; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
376 |
while (*text++) l++; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
377 |
return l; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
378 |
} |
54232 | 379 |
|
380 |
static unsigned int |
|
381 |
encode_len (hb_codepoint_t unicode HB_UNUSED) |
|
382 |
{ |
|
383 |
return 1; |
|
384 |
} |
|
385 |
||
386 |
static codepoint_t * |
|
387 |
encode (codepoint_t *text, |
|
388 |
const codepoint_t *end HB_UNUSED, |
|
389 |
hb_codepoint_t unicode) |
|
390 |
{ |
|
391 |
if (unlikely (unicode >= 0x0100u)) |
|
392 |
unicode = '?'; |
|
393 |
*text++ = unicode; |
|
394 |
return text; |
|
395 |
} |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
396 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
397 |
|
54232 | 398 |
|
399 |
struct hb_ascii_t |
|
400 |
{ |
|
401 |
typedef uint8_t codepoint_t; |
|
402 |
||
403 |
static const codepoint_t * |
|
404 |
next (const codepoint_t *text, |
|
405 |
const codepoint_t *end HB_UNUSED, |
|
406 |
hb_codepoint_t *unicode, |
|
407 |
hb_codepoint_t replacement HB_UNUSED) |
|
408 |
{ |
|
409 |
*unicode = *text++; |
|
410 |
if (*unicode >= 0x0080u) |
|
411 |
*unicode = replacement; |
|
412 |
return text; |
|
413 |
} |
|
414 |
||
415 |
static const codepoint_t * |
|
416 |
prev (const codepoint_t *text, |
|
417 |
const codepoint_t *start HB_UNUSED, |
|
418 |
hb_codepoint_t *unicode, |
|
419 |
hb_codepoint_t replacement) |
|
420 |
{ |
|
421 |
*unicode = *--text; |
|
422 |
if (*unicode >= 0x0080u) |
|
423 |
*unicode = replacement; |
|
424 |
return text; |
|
425 |
} |
|
426 |
||
427 |
static unsigned int |
|
428 |
strlen (const codepoint_t *text) |
|
429 |
{ |
|
430 |
unsigned int l = 0; |
|
431 |
while (*text++) l++; |
|
432 |
return l; |
|
433 |
} |
|
434 |
||
435 |
static unsigned int |
|
436 |
encode_len (hb_codepoint_t unicode HB_UNUSED) |
|
437 |
{ |
|
438 |
return 1; |
|
439 |
} |
|
440 |
||
441 |
static codepoint_t * |
|
442 |
encode (codepoint_t *text, |
|
443 |
const codepoint_t *end HB_UNUSED, |
|
444 |
hb_codepoint_t unicode) |
|
445 |
{ |
|
446 |
if (unlikely (unicode >= 0x0080u)) |
|
447 |
unicode = '?'; |
|
448 |
*text++ = unicode; |
|
449 |
return text; |
|
450 |
} |
|
451 |
}; |
|
452 |
||
453 |
#endif /* HB_UTF_HH */ |