Skip to content

Commit

Permalink
harfbuzz-ng roll
Browse files Browse the repository at this point in the history
previous revision: 811eefe225d20b20f1de20c6e62a0ebd6d89102a
new revision: 431bef2e16c7888ca3960f5797432d3a20903550

BUG=158978


Review URL: https://chromiumcodereview.appspot.com/11367051

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165892 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
bashi@chromium.org committed Nov 5, 2012
1 parent 19aeb1f commit aaf2a32
Show file tree
Hide file tree
Showing 26 changed files with 705 additions and 451 deletions.
4 changes: 2 additions & 2 deletions third_party/harfbuzz-ng/README.chromium
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Name: harfbuzz-ng
Short Name: harfbuzz-ng
URL: http://freedesktop.org/wiki/Software/HarfBuzz
Version: unknown
Date: 20120910
Revision: 811eefe225d20b20f1de20c6e62a0ebd6d89102a
Date: 20121102
Revision: 431bef2e16c7888ca3960f5797432d3a20903550
Security Critical: yes
License: MIT
License File: NOT_SHIPPED
Expand Down
1 change: 1 addition & 0 deletions third_party/harfbuzz-ng/harfbuzz.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
'src/hb-unicode-private.hh',
'src/hb-unicode.cc',
'src/hb-unicode.h',
'src/hb-utf-private.hh',
'src/hb-version.h',
'src/hb-warning.cc',
'src/hb.h',
Expand Down
13 changes: 0 additions & 13 deletions third_party/harfbuzz-ng/src/hb-atomic-private.hh
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,6 @@ typedef int hb_atomic_int_t;
#define hb_atomic_ptr_get(P) (void *) (__sync_synchronize (), *(P))
#define hb_atomic_ptr_cmpexch(P,O,N) __sync_bool_compare_and_swap ((P), (O), (N))

#elif !defined(HB_NO_MT) && defined(HAVE_GLIB)

#include <glib.h>
typedef int hb_atomic_int_t;
#if GLIB_CHECK_VERSION(2,29,5)
#define hb_atomic_int_add(AI, V) g_atomic_int_add (&(AI), (V))
#else
#define hb_atomic_int_add(AI, V) g_atomic_int_exchange_and_add (&(AI), (V))
#endif

#define hb_atomic_ptr_get(P) g_atomic_pointer_get (P)
#define hb_atomic_ptr_cmpexch(P,O,N) g_atomic_pointer_compare_and_exchange ((void **) (P), (void *) (O), (void *) (N))


#elif !defined(HB_NO_MT)

Expand Down
14 changes: 13 additions & 1 deletion third_party/harfbuzz-ng/src/hb-buffer-private.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright © 1998-2004 David Turner and Werner Lemberg
* Copyright © 2004,2007,2009,2010 Red Hat, Inc.
* Copyright © 2011 Google, Inc.
* Copyright © 2011,2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
Expand Down Expand Up @@ -117,9 +117,18 @@ struct hb_buffer_t {
inline hb_glyph_info_t prev (void) const { return info[out_len - 1]; }

unsigned int serial;

/* These reflect current allocations of the bytes in glyph_info_t's var1 and var2. */
uint8_t allocated_var_bytes[8];
const char *allocated_var_owner[8];

/* Text before / after the main buffer contents.
* Always in Unicode, and ordered outward.
* Index 0 is for "pre-context", 1 for "post-context". */
static const unsigned int CONTEXT_LENGTH = 5;
hb_codepoint_t context[2][CONTEXT_LENGTH];
unsigned int context_len[2];


/* Methods */

Expand All @@ -144,6 +153,7 @@ struct hb_buffer_t {
HB_INTERNAL void guess_properties (void);

HB_INTERNAL void swap_buffers (void);
HB_INTERNAL void remove_output (void);
HB_INTERNAL void clear_output (void);
HB_INTERNAL void clear_positions (void);

Expand Down Expand Up @@ -206,6 +216,8 @@ struct hb_buffer_t {
HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out);

HB_INTERNAL void *get_scratch_buffer (unsigned int *size);

inline void clear_context (unsigned int side) { context_len[side] = 0; }
};


Expand Down
207 changes: 94 additions & 113 deletions third_party/harfbuzz-ng/src/hb-buffer.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright © 1998-2004 David Turner and Werner Lemberg
* Copyright © 2004,2007,2009,2010 Red Hat, Inc.
* Copyright © 2011 Google, Inc.
* Copyright © 2011,2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
Expand All @@ -28,9 +28,7 @@
*/

#include "hb-buffer-private.hh"

#include <string.h>

#include "hb-utf-private.hh"


#ifndef HB_DEBUG_BUFFER
Expand Down Expand Up @@ -73,7 +71,7 @@ hb_buffer_t::enlarge (unsigned int size)
if (unlikely (_hb_unsigned_int_mul_overflows (size, sizeof (info[0]))))
goto done;

while (size > new_allocated)
while (size >= new_allocated)
new_allocated += (new_allocated >> 1) + 32;

ASSERT_STATIC (sizeof (info[0]) == sizeof (pos[0]));
Expand Down Expand Up @@ -160,6 +158,9 @@ hb_buffer_t::reset (void)
serial = 0;
memset (allocated_var_bytes, 0, sizeof allocated_var_bytes);
memset (allocated_var_owner, 0, sizeof allocated_var_owner);

memset (context, 0, sizeof context);
memset (context_len, 0, sizeof context_len);
}

void
Expand All @@ -181,6 +182,19 @@ hb_buffer_t::add (hb_codepoint_t codepoint,
len++;
}

void
hb_buffer_t::remove_output (void)
{
if (unlikely (hb_object_is_inert (this)))
return;

have_output = false;
have_positions = false;

out_len = 0;
out_info = info;
}

void
hb_buffer_t::clear_output (void)
{
Expand Down Expand Up @@ -572,6 +586,8 @@ hb_buffer_get_empty (void)
true, /* in_error */
true, /* have_output */
true /* have_positions */

/* Zero is good enough for everything else. */
};

return const_cast<hb_buffer_t *> (&_hb_buffer_nil);
Expand Down Expand Up @@ -725,6 +741,7 @@ hb_buffer_add (hb_buffer_t *buffer,
unsigned int cluster)
{
buffer->add (codepoint, mask, cluster);
buffer->clear_context (1);
}

hb_bool_t
Expand All @@ -745,6 +762,11 @@ hb_buffer_set_length (hb_buffer_t *buffer,
}

buffer->len = length;

if (!length)
buffer->clear_context (0);
buffer->clear_context (1);

return true;
}

Expand Down Expand Up @@ -797,68 +819,70 @@ hb_buffer_guess_properties (hb_buffer_t *buffer)
buffer->guess_properties ();
}

#define ADD_UTF(T) \
HB_STMT_START { \
if (text_length == -1) { \
text_length = 0; \
const T *p = (const T *) text; \
while (*p) { \
text_length++; \
p++; \
} \
} \
if (item_length == -1) \
item_length = text_length - item_offset; \
buffer->ensure (buffer->len + item_length * sizeof (T) / 4); \
const T *next = (const T *) text + item_offset; \
const T *end = next + item_length; \
while (next < end) { \
hb_codepoint_t u; \
const T *old_next = next; \
next = UTF_NEXT (next, end, u); \
hb_buffer_add (buffer, u, 1, old_next - (const T *) text); \
} \
} HB_STMT_END


#define UTF8_COMPUTE(Char, Mask, Len) \
if (Char < 128) { Len = 1; Mask = 0x7f; } \
else if ((Char & 0xe0) == 0xc0) { Len = 2; Mask = 0x1f; } \
else if ((Char & 0xf0) == 0xe0) { Len = 3; Mask = 0x0f; } \
else if ((Char & 0xf8) == 0xf0) { Len = 4; Mask = 0x07; } \
else Len = 0;

static inline const uint8_t *
hb_utf8_next (const uint8_t *text,
const uint8_t *end,
hb_codepoint_t *unicode)
{
uint8_t c = *text;
unsigned int mask, len;

/* TODO check for overlong sequences? */

UTF8_COMPUTE (c, mask, len);
if (unlikely (!len || (unsigned int) (end - text) < len)) {
*unicode = -1;
return text + 1;
} else {
hb_codepoint_t result;
unsigned int i;
result = c & mask;
for (i = 1; i < len; i++)
{
if (unlikely ((text[i] & 0xc0) != 0x80))
{
*unicode = -1;
return text + 1;
}
result <<= 6;
result |= (text[i] & 0x3f);
}
*unicode = result;
return text + len;
template <typename T>
static inline void
hb_buffer_add_utf (hb_buffer_t *buffer,
const T *text,
int text_length,
unsigned int item_offset,
int item_length)
{
assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE ||
(!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));

if (unlikely (hb_object_is_inert (buffer)))
return;

if (text_length == -1)
text_length = hb_utf_strlen (text);

if (item_length == -1)
item_length = text_length - item_offset;

buffer->ensure (buffer->len + item_length * sizeof (T) / 4);

/* If buffer is empty and pre-context provided, install it.
* This check is written this way, to make sure people can
* provide pre-context in one add_utf() call, then provide
* text in a follow-up call. See:
*
* https://bugzilla.mozilla.org/show_bug.cgi?id=801410#c13
*/
if (!buffer->len && item_offset > 0)
{
/* Add pre-context */
buffer->clear_context (0);
const T *prev = text + item_offset;
const T *start = text;
while (start < prev && buffer->context_len[0] < buffer->CONTEXT_LENGTH)
{
hb_codepoint_t u;
prev = hb_utf_prev (prev, start, &u);
buffer->context[0][buffer->context_len[0]++] = u;
}
}

const T *next = text + item_offset;
const T *end = next + item_length;
while (next < end)
{
hb_codepoint_t u;
const T *old_next = next;
next = hb_utf_next (next, end, &u);
buffer->add (u, 1, old_next - (const T *) text);
}

/* Add post-context */
buffer->clear_context (1);
end = text + text_length;
while (next < end && buffer->context_len[1] < buffer->CONTEXT_LENGTH)
{
hb_codepoint_t u;
next = hb_utf_next (next, end, &u);
buffer->context[1][buffer->context_len[1]++] = u;
}

buffer->content_type = HB_BUFFER_CONTENT_TYPE_UNICODE;
}

void
Expand All @@ -868,36 +892,7 @@ hb_buffer_add_utf8 (hb_buffer_t *buffer,
unsigned int item_offset,
int item_length)
{
assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE ||
(!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
if (unlikely (hb_object_is_inert (buffer)))
return;
buffer->content_type = HB_BUFFER_CONTENT_TYPE_UNICODE;
#define UTF_NEXT(S, E, U) hb_utf8_next (S, E, &(U))
ADD_UTF (uint8_t);
#undef UTF_NEXT
}

static inline const uint16_t *
hb_utf16_next (const uint16_t *text,
const uint16_t *end,
hb_codepoint_t *unicode)
{
uint16_t c = *text++;

if (unlikely (c >= 0xd800 && c < 0xdc00)) {
/* high surrogate */
uint16_t l;
if (text < end && ((l = *text), likely (l >= 0xdc00 && l < 0xe000))) {
/* low surrogate */
*unicode = ((hb_codepoint_t) ((c) - 0xd800) * 0x400 + (l) - 0xdc00 + 0x10000);
text++;
} else
*unicode = -1;
} else
*unicode = c;

return text;
hb_buffer_add_utf (buffer, (const uint8_t *) text, text_length, item_offset, item_length);
}

void
Expand All @@ -907,14 +902,7 @@ hb_buffer_add_utf16 (hb_buffer_t *buffer,
unsigned int item_offset,
int item_length)
{
assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE ||
(!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
if (unlikely (hb_object_is_inert (buffer)))
return;
buffer->content_type = HB_BUFFER_CONTENT_TYPE_UNICODE;
#define UTF_NEXT(S, E, U) hb_utf16_next (S, E, &(U))
ADD_UTF (uint16_t);
#undef UTF_NEXT
hb_buffer_add_utf (buffer, text, text_length, item_offset, item_length);
}

void
Expand All @@ -924,14 +912,7 @@ hb_buffer_add_utf32 (hb_buffer_t *buffer,
unsigned int item_offset,
int item_length)
{
assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE ||
(!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));
if (unlikely (hb_object_is_inert (buffer)))
return;
buffer->content_type = HB_BUFFER_CONTENT_TYPE_UNICODE;
#define UTF_NEXT(S, E, U) ((U) = *(S), (S)+1)
ADD_UTF (uint32_t);
#undef UTF_NEXT
hb_buffer_add_utf (buffer, text, text_length, item_offset, item_length);
}


Expand Down Expand Up @@ -994,7 +975,7 @@ void
hb_buffer_normalize_glyphs (hb_buffer_t *buffer)
{
assert (buffer->have_positions);
/* XXX assert (buffer->have_glyphs); */
assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS);

bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);

Expand Down
2 changes: 1 addition & 1 deletion third_party/harfbuzz-ng/src/hb-buffer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright © 1998-2004 David Turner and Werner Lemberg
* Copyright © 2004,2007,2009 Red Hat, Inc.
* Copyright © 2011 Google, Inc.
* Copyright © 2011,2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
Expand Down
Loading

0 comments on commit aaf2a32

Please sign in to comment.