[icu_le] Support non-BMP text

This commit is contained in:
Behdad Esfahbod 2013-05-24 15:28:11 -04:00
parent a447c528e6
commit cf059ac69d
1 changed files with 28 additions and 7 deletions

View File

@ -134,25 +134,46 @@ retry:
unsigned int scratch_size;
char *scratch = (char *) buffer->get_scratch_buffer (&scratch_size);
LEUnicode *pchars = (LEUnicode *) scratch;
unsigned int chars_len = 0;
for (unsigned int i = 0; i < buffer->len; i++) {
hb_codepoint_t c = buffer->info[i].codepoint;
if (likely (c < 0x10000))
pchars[chars_len++] = c;
else if (unlikely (c >= 0x110000))
pchars[chars_len++] = 0xFFFD;
else {
pchars[chars_len++] = 0xD800 + ((c - 0x10000) >> 10);
pchars[chars_len++] = 0xDC00 + ((c - 0x10000) & ((1 << 10) - 1));
}
}
#define ALLOCATE_ARRAY(Type, name, len) \
Type *name = (Type *) scratch; \
scratch += (len) * sizeof ((name)[0]); \
scratch_size -= (len) * sizeof ((name)[0]);
ALLOCATE_ARRAY (LEUnicode, chars, buffer->len);
ALLOCATE_ARRAY (unsigned int, clusters, buffer->len);
ALLOCATE_ARRAY (LEUnicode, chars, chars_len);
ALLOCATE_ARRAY (unsigned int, clusters, chars_len);
/* XXX Use UTF-16 decoder! */
chars_len = 0;
for (unsigned int i = 0; i < buffer->len; i++) {
chars[i] = buffer->info[i].codepoint;
clusters[i] = buffer->info[i].cluster;
hb_codepoint_t c = buffer->info[i].codepoint;
if (likely (c < 0x10000))
clusters[chars_len++] = buffer->info[i].cluster;
else if (unlikely (c >= 0x110000))
clusters[chars_len++] = buffer->info[i].cluster;
else {
clusters[chars_len++] = buffer->info[i].cluster;
clusters[chars_len++] = buffer->info[i].cluster;
}
}
unsigned int glyph_count = le_layoutChars (le,
chars,
0,
buffer->len,
buffer->len,
chars_len,
chars_len,
HB_DIRECTION_IS_BACKWARD (buffer->props.direction),
0., 0.,
&status);