[HarfBuzz] harfbuzz-ng: Branch 'master' - 2 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Fri Aug 10 00:53:30 PDT 2012
src/hb-ot-shape-normalize.cc | 106 +++++++++++++++++++++++++------------------
src/hb-ot-shape.cc | 2
2 files changed, 63 insertions(+), 45 deletions(-)
New commits:
commit f4cb4762986a28634fa7de9b706f9d37859b881e
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Fri Aug 10 03:51:44 2012 -0400
[OT] Slightly adjust normalizer
The change is very subtle. If we have a single-char cluster that
decomposes to three or more characters, then try recomposition, in
case the farther mark may compose with the base.
diff --git a/src/hb-ot-shape-normalize.cc b/src/hb-ot-shape-normalize.cc
index 23c28cc..93dd00c 100644
--- a/src/hb-ot-shape-normalize.cc
+++ b/src/hb-ot-shape-normalize.cc
@@ -286,41 +286,50 @@ skip_char (hb_buffer_t *buffer)
buffer->skip_glyph ();
}
-static bool
+/* Returns 0 if didn't decompose, number of resulting characters otherwise. */
+static inline unsigned int
decompose (hb_font_t *font, hb_buffer_t *buffer, bool shortest, hb_codepoint_t ab)
{
hb_codepoint_t a, b, a_glyph, b_glyph;
if (!decompose_func (buffer->unicode, ab, &a, &b) ||
(b && !font->get_glyph (b, 0, &b_glyph)))
- return false;
+ return 0;
bool has_a = font->get_glyph (a, 0, &a_glyph);
if (shortest && has_a) {
/* Output a and b */
output_char (buffer, a, a_glyph);
- if (b)
+ if (likely (b)) {
output_char (buffer, b, b_glyph);
- return true;
+ return 2;
+ }
+ return 1;
}
- if (decompose (font, buffer, shortest, a)) {
- if (b)
+ unsigned int ret;
+ if ((ret = decompose (font, buffer, shortest, a))) {
+ if (b) {
output_char (buffer, b, b_glyph);
- return true;
+ return ret + 1;
+ }
+ return ret;
}
if (has_a) {
output_char (buffer, a, a_glyph);
- if (b)
+ if (likely (b)) {
output_char (buffer, b, b_glyph);
- return true;
+ return 2;
+ }
+ return 1;
}
- return false;
+ return 0;
}
-static bool
+/* Returns 0 if didn't decompose, number of resulting characters otherwise. */
+static inline bool
decompose_compatibility (hb_font_t *font, hb_buffer_t *buffer, hb_codepoint_t u)
{
unsigned int len, i;
@@ -329,34 +338,42 @@ decompose_compatibility (hb_font_t *font, hb_buffer_t *buffer, hb_codepoint_t u)
len = buffer->unicode->decompose_compatibility (u, decomposed);
if (!len)
- return false;
+ return 0;
for (i = 0; i < len; i++)
if (!font->get_glyph (decomposed[i], 0, &glyphs[i]))
- return false;
+ return 0;
for (i = 0; i < len; i++)
output_char (buffer, decomposed[i], glyphs[i]);
- return true;
+ return len;
}
-static void
+/* Returns true if recomposition may be benefitial. */
+static inline bool
decompose_current_character (hb_font_t *font, hb_buffer_t *buffer, bool shortest)
{
hb_codepoint_t glyph;
+ unsigned int len = 1;
/* Kind of a cute waterfall here... */
if (shortest && font->get_glyph (buffer->cur().codepoint, 0, &glyph))
next_char (buffer, glyph);
- else if (decompose (font, buffer, shortest, buffer->cur().codepoint))
+ else if ((len = decompose (font, buffer, shortest, buffer->cur().codepoint)))
skip_char (buffer);
else if (!shortest && font->get_glyph (buffer->cur().codepoint, 0, &glyph))
next_char (buffer, glyph);
- else if (decompose_compatibility (font, buffer, buffer->cur().codepoint))
+ else if ((len = decompose_compatibility (font, buffer, buffer->cur().codepoint)))
skip_char (buffer);
else
next_char (buffer, glyph); /* glyph is initialized in earlier branches. */
+
+ /*
+ * A recomposition would only be useful if we decomposed into at least three
+ * characters...
+ */
+ return len > 2;
}
static inline void
@@ -378,20 +395,34 @@ handle_variation_selector_cluster (hb_font_t *font, hb_buffer_t *buffer, unsigne
}
}
-static void
+/* Returns true if recomposition may be benefitial. */
+static inline bool
decompose_multi_char_cluster (hb_font_t *font, hb_buffer_t *buffer, unsigned int end)
{
/* TODO Currently if there's a variation-selector we give-up, it's just too hard. */
for (unsigned int i = buffer->idx; i < end; i++)
if (unlikely (buffer->unicode->is_variation_selector (buffer->info[i].codepoint))) {
handle_variation_selector_cluster (font, buffer, end);
- return;
+ return false;
}
while (buffer->idx < end)
decompose_current_character (font, buffer, false);
+ /* We can be smarter here and only return true if there are at least two ccc!=0 marks.
+ * But does not matter. */
+ return true;
+}
+
+static inline bool
+decompose_cluster (hb_font_t *font, hb_buffer_t *buffer, bool recompose, unsigned int end)
+{
+ if (likely (buffer->idx + 1 == end))
+ return decompose_current_character (font, buffer, recompose);
+ else
+ return decompose_multi_char_cluster (font, buffer, end);
}
+
static int
compare_combining_class (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb)
{
@@ -401,12 +432,13 @@ compare_combining_class (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb)
return a < b ? -1 : a == b ? 0 : +1;
}
+
void
_hb_ot_shape_normalize (hb_font_t *font, hb_buffer_t *buffer,
hb_ot_shape_normalization_mode_t mode)
{
bool recompose = mode != HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED;
- bool has_multichar_clusters = false;
+ bool can_use_recompose = false;
unsigned int count;
/* We do a fairly straightforward yet custom normalization process in three
@@ -427,17 +459,12 @@ _hb_ot_shape_normalize (hb_font_t *font, hb_buffer_t *buffer,
if (buffer->cur().cluster != buffer->info[end].cluster)
break;
- if (buffer->idx + 1 == end)
- decompose_current_character (font, buffer, recompose);
- else {
- decompose_multi_char_cluster (font, buffer, end);
- has_multichar_clusters = true;
- }
+ can_use_recompose = decompose_cluster (font, buffer, recompose, end) || can_use_recompose;
}
buffer->swap_buffers ();
- if (mode != HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_FULL && !has_multichar_clusters)
+ if (mode != HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_FULL && !can_use_recompose)
return; /* Done! */
commit 07d682806349aee81f53114778ce0beb23909ed7
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Fri Aug 10 03:28:50 2012 -0400
Minor
diff --git a/src/hb-ot-shape-normalize.cc b/src/hb-ot-shape-normalize.cc
index e6092d6..23c28cc 100644
--- a/src/hb-ot-shape-normalize.cc
+++ b/src/hb-ot-shape-normalize.cc
@@ -262,7 +262,7 @@ compose_func (hb_unicode_funcs_t *unicode,
static inline void
set_glyph (hb_glyph_info_t &info, hb_font_t *font)
{
- hb_font_get_glyph (font, info.codepoint, 0, &info.glyph_index());
+ font->get_glyph (info.codepoint, 0, &info.glyph_index());
}
static inline void
@@ -287,9 +287,7 @@ skip_char (hb_buffer_t *buffer)
}
static bool
-decompose (hb_font_t *font, hb_buffer_t *buffer,
- bool shortest,
- hb_codepoint_t ab)
+decompose (hb_font_t *font, hb_buffer_t *buffer, bool shortest, hb_codepoint_t ab)
{
hb_codepoint_t a, b, a_glyph, b_glyph;
@@ -323,8 +321,7 @@ decompose (hb_font_t *font, hb_buffer_t *buffer,
}
static bool
-decompose_compatibility (hb_font_t *font, hb_buffer_t *buffer,
- hb_codepoint_t u)
+decompose_compatibility (hb_font_t *font, hb_buffer_t *buffer, hb_codepoint_t u)
{
unsigned int len, i;
hb_codepoint_t decomposed[HB_UNICODE_MAX_DECOMPOSITION_LEN];
@@ -345,8 +342,7 @@ decompose_compatibility (hb_font_t *font, hb_buffer_t *buffer,
}
static void
-decompose_current_character (hb_font_t *font, hb_buffer_t *buffer,
- bool shortest)
+decompose_current_character (hb_font_t *font, hb_buffer_t *buffer, bool shortest)
{
hb_codepoint_t glyph;
@@ -359,16 +355,12 @@ decompose_current_character (hb_font_t *font, hb_buffer_t *buffer,
next_char (buffer, glyph);
else if (decompose_compatibility (font, buffer, buffer->cur().codepoint))
skip_char (buffer);
- else {
- /* A glyph-not-found case... */
- font->get_glyph (buffer->cur().codepoint, 0, &glyph);
- next_char (buffer, glyph);
- }
+ else
+ next_char (buffer, glyph); /* glyph is initialized in earlier branches. */
}
static inline void
-handle_variation_selector_cluster (hb_font_t *font, hb_buffer_t *buffer,
- unsigned int end)
+handle_variation_selector_cluster (hb_font_t *font, hb_buffer_t *buffer, unsigned int end)
{
for (; buffer->idx < end - 1;) {
if (unlikely (buffer->unicode->is_variation_selector (buffer->cur(+1).codepoint))) {
@@ -387,8 +379,7 @@ handle_variation_selector_cluster (hb_font_t *font, hb_buffer_t *buffer,
}
static void
-decompose_multi_char_cluster (hb_font_t *font, hb_buffer_t *buffer,
- unsigned int end)
+decompose_multi_char_cluster (hb_font_t *font, hb_buffer_t *buffer, unsigned int end)
{
/* TODO Currently if there's a variation-selector we give-up, it's just too hard. */
for (unsigned int i = buffer->idx; i < end; i++)
diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index 2062102..823eced 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -1,6 +1,6 @@
/*
* Copyright © 2009,2010 Red Hat, Inc.
- * Copyright © 2010,2011 Google, Inc.
+ * Copyright © 2010,2011,2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
More information about the HarfBuzz
mailing list