Add normalize mode
In preparation for Hangul shaper.
diff --git a/src/Makefile.am b/src/Makefile.am
index c70e198..d64efdf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -70,6 +70,7 @@
hb-ot-shape-complex-indic-table.hh \
hb-ot-shape-complex-misc.cc \
hb-ot-shape-complex-private.hh \
+ hb-ot-shape-normalize-private.hh \
hb-ot-shape-normalize.cc \
hb-ot-shape-private.hh \
$(NULL)
diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh
index 5d19e08..d478e29 100644
--- a/src/hb-ot-layout-common-private.hh
+++ b/src/hb-ot-layout-common-private.hh
@@ -30,7 +30,6 @@
#define HB_OT_LAYOUT_COMMON_PRIVATE_HH
#include "hb-ot-layout-private.hh"
-
#include "hb-open-type-private.hh"
diff --git a/src/hb-ot-shape-complex-arabic.cc b/src/hb-ot-shape-complex-arabic.cc
index 2b863ef..89d6b53 100644
--- a/src/hb-ot-shape-complex-arabic.cc
+++ b/src/hb-ot-shape-complex-arabic.cc
@@ -183,10 +183,10 @@
map->add_bool_feature (HB_TAG('c','s','w','h'));
}
-bool
-_hb_ot_shape_complex_prefer_decomposed_arabic (void)
+hb_ot_shape_normalization_mode_t
+_hb_ot_shape_complex_normalization_preference_arabic (void)
{
- return FALSE;
+ return HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS;
}
void
diff --git a/src/hb-ot-shape-complex-indic.cc b/src/hb-ot-shape-complex-indic.cc
index 9f50ef2..9dcba81 100644
--- a/src/hb-ot-shape-complex-indic.cc
+++ b/src/hb-ot-shape-complex-indic.cc
@@ -369,11 +369,11 @@
}
-bool
-_hb_ot_shape_complex_prefer_decomposed_indic (void)
+hb_ot_shape_normalization_mode_t
+_hb_ot_shape_complex_normalization_preference_indic (void)
{
/* We want split matras decomposed by the common shaping logic. */
- return TRUE;
+ return HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED;
}
diff --git a/src/hb-ot-shape-complex-misc.cc b/src/hb-ot-shape-complex-misc.cc
index 230704f..98831fb 100644
--- a/src/hb-ot-shape-complex-misc.cc
+++ b/src/hb-ot-shape-complex-misc.cc
@@ -27,7 +27,7 @@
#include "hb-ot-shape-complex-private.hh"
-/* TODO Add kana, hangul, and other small sahpers here */
+/* TODO Add kana, hangul, and other small shapers here */
/* When adding trivial shapers, eg. kana, hangul, etc, we can either
* add a full shaper enum value for them, or switch on the script in
@@ -41,10 +41,10 @@
{
}
-bool
-_hb_ot_shape_complex_prefer_decomposed_default (void)
+hb_ot_shape_normalization_mode_t
+_hb_ot_shape_complex_normalization_preference_default (void)
{
- return FALSE;
+ return HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS;
}
void
diff --git a/src/hb-ot-shape-complex-private.hh b/src/hb-ot-shape-complex-private.hh
index 32ac854..ae01a3a 100644
--- a/src/hb-ot-shape-complex-private.hh
+++ b/src/hb-ot-shape-complex-private.hh
@@ -30,6 +30,7 @@
#include "hb-private.hh"
#include "hb-ot-map-private.hh"
+#include "hb-ot-shape-normalize-private.hh"
@@ -227,26 +228,26 @@
/*
- * prefer_decomposed()
+ * normalization_preference()
*
* Called during shape_execute().
*
* Shapers should return TRUE if it prefers decomposed (NFD) input rather than precomposed (NFC).
*/
-typedef bool hb_ot_shape_complex_prefer_decomposed_func_t (void);
+typedef hb_ot_shape_normalization_mode_t hb_ot_shape_complex_normalization_preference_func_t (void);
#define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
- HB_INTERNAL hb_ot_shape_complex_prefer_decomposed_func_t _hb_ot_shape_complex_prefer_decomposed_##name;
+ HB_INTERNAL hb_ot_shape_complex_normalization_preference_func_t _hb_ot_shape_complex_normalization_preference_##name;
HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
#undef HB_COMPLEX_SHAPER_IMPLEMENT
-static inline bool
-hb_ot_shape_complex_prefer_decomposed (hb_ot_complex_shaper_t shaper)
+static inline hb_ot_shape_normalization_mode_t
+hb_ot_shape_complex_normalization_preference (hb_ot_complex_shaper_t shaper)
{
switch (shaper) {
default:
#define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
- case hb_ot_complex_shaper_##name: return _hb_ot_shape_complex_prefer_decomposed_##name ();
+ case hb_ot_complex_shaper_##name: return _hb_ot_shape_complex_normalization_preference_##name ();
HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
#undef HB_COMPLEX_SHAPER_IMPLEMENT
}
diff --git a/src/hb-ot-shape-normalize-private.hh b/src/hb-ot-shape-normalize-private.hh
new file mode 100644
index 0000000..bb81f00
--- /dev/null
+++ b/src/hb-ot-shape-normalize-private.hh
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2012 Google, Inc.
+ *
+ * This is part of HarfBuzz, a text shaping library.
+ *
+ * Permission is hereby granted, without written agreement and without
+ * license or royalty fees, to use, copy, modify, and distribute this
+ * software and its documentation for any purpose, provided that the
+ * above copyright notice and the following two paragraphs appear in
+ * all copies of this software.
+ *
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
+ * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Google Author(s): Behdad Esfahbod
+ */
+
+#ifndef HB_OT_SHAPE_NORMALIZE_PRIVATE_HH
+#define HB_OT_SHAPE_NORMALIZE_PRIVATE_HH
+
+#include "hb-private.hh"
+
+#include "hb-font.h"
+#include "hb-buffer.h"
+
+
+enum hb_ot_shape_normalization_mode_t {
+ HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED,
+ HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS, /* never composes base-to-base */
+ HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_FULL /* including base-to-base composition */
+};
+
+HB_INTERNAL void _hb_ot_shape_normalize (hb_font_t *font,
+ hb_buffer_t *buffer,
+ hb_ot_shape_normalization_mode_t mode);
+
+#endif /* HB_OT_SHAPE_NORMALIZE_PRIVATE_HH */
diff --git a/src/hb-ot-shape-normalize.cc b/src/hb-ot-shape-normalize.cc
index a1ad6d7..15de312 100644
--- a/src/hb-ot-shape-normalize.cc
+++ b/src/hb-ot-shape-normalize.cc
@@ -1,5 +1,5 @@
/*
- * Copyright © 2011 Google, Inc.
+ * Copyright © 2011,2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
@@ -24,8 +24,8 @@
* Google Author(s): Behdad Esfahbod
*/
+#include "hb-ot-shape-normalize-private.hh"
#include "hb-ot-shape-private.hh"
-#include "hb-ot-shape-complex-private.hh"
/*
@@ -69,45 +69,43 @@
*/
static void
-output_glyph (hb_ot_shape_context_t *c,
+output_glyph (hb_font_t *font, hb_buffer_t *buffer,
hb_codepoint_t glyph)
{
- hb_buffer_t *buffer = c->buffer;
-
buffer->output_glyph (glyph);
hb_glyph_info_set_unicode_props (&buffer->out_info[buffer->out_len - 1], buffer->unicode);
}
static bool
-decompose (hb_ot_shape_context_t *c,
+decompose (hb_font_t *font, hb_buffer_t *buffer,
bool shortest,
hb_codepoint_t ab)
{
hb_codepoint_t a, b, glyph;
- if (!hb_unicode_decompose (c->buffer->unicode, ab, &a, &b) ||
- (b && !hb_font_get_glyph (c->font, b, 0, &glyph)))
+ if (!hb_unicode_decompose (buffer->unicode, ab, &a, &b) ||
+ (b && !hb_font_get_glyph (font, b, 0, &glyph)))
return FALSE;
- bool has_a = hb_font_get_glyph (c->font, a, 0, &glyph);
+ bool has_a = hb_font_get_glyph (font, a, 0, &glyph);
if (shortest && has_a) {
/* Output a and b */
- output_glyph (c, a);
+ output_glyph (font, buffer, a);
if (b)
- output_glyph (c, b);
+ output_glyph (font, buffer, b);
return TRUE;
}
- if (decompose (c, shortest, a)) {
+ if (decompose (font, buffer, shortest, a)) {
if (b)
- output_glyph (c, b);
+ output_glyph (font, buffer, b);
return TRUE;
}
if (has_a) {
- output_glyph (c, a);
+ output_glyph (font, buffer, a);
if (b)
- output_glyph (c, b);
+ output_glyph (font, buffer, b);
return TRUE;
}
@@ -115,44 +113,44 @@
}
static void
-decompose_current_glyph (hb_ot_shape_context_t *c,
+decompose_current_glyph (hb_font_t *font, hb_buffer_t *buffer,
bool shortest)
{
- if (decompose (c, shortest, c->buffer->info[c->buffer->idx].codepoint))
- c->buffer->skip_glyph ();
+ if (decompose (font, buffer, shortest, buffer->info[buffer->idx].codepoint))
+ buffer->skip_glyph ();
else
- c->buffer->next_glyph ();
+ buffer->next_glyph ();
}
static void
-decompose_single_char_cluster (hb_ot_shape_context_t *c,
+decompose_single_char_cluster (hb_font_t *font, hb_buffer_t *buffer,
bool will_recompose)
{
hb_codepoint_t glyph;
/* If recomposing and font supports this, we're good to go */
- if (will_recompose && hb_font_get_glyph (c->font, c->buffer->info[c->buffer->idx].codepoint, 0, &glyph)) {
- c->buffer->next_glyph ();
+ if (will_recompose && hb_font_get_glyph (font, buffer->info[buffer->idx].codepoint, 0, &glyph)) {
+ buffer->next_glyph ();
return;
}
- decompose_current_glyph (c, will_recompose);
+ decompose_current_glyph (font, buffer, will_recompose);
}
static void
-decompose_multi_char_cluster (hb_ot_shape_context_t *c,
+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 = c->buffer->idx; i < end; i++)
- if (unlikely (_hb_unicode_is_variation_selector (c->buffer->info[i].codepoint))) {
- while (c->buffer->idx < end)
- c->buffer->next_glyph ();
+ for (unsigned int i = buffer->idx; i < end; i++)
+ if (unlikely (_hb_unicode_is_variation_selector (buffer->info[i].codepoint))) {
+ while (buffer->idx < end)
+ buffer->next_glyph ();
return;
}
- while (c->buffer->idx < end)
- decompose_current_glyph (c, FALSE);
+ while (buffer->idx < end)
+ decompose_current_glyph (font, buffer, FALSE);
}
static int
@@ -165,10 +163,10 @@
}
void
-_hb_ot_shape_normalize (hb_ot_shape_context_t *c)
+_hb_ot_shape_normalize (hb_font_t *font, hb_buffer_t *buffer,
+ hb_ot_shape_normalization_mode_t mode)
{
- hb_buffer_t *buffer = c->buffer;
- bool recompose = !hb_ot_shape_complex_prefer_decomposed (c->plan->shaper);
+ bool recompose = mode != HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED;
bool has_multichar_clusters = FALSE;
unsigned int count;
@@ -191,9 +189,9 @@
break;
if (buffer->idx + 1 == end)
- decompose_single_char_cluster (c, recompose);
+ decompose_single_char_cluster (font, buffer, recompose);
else {
- decompose_multi_char_cluster (c, end);
+ decompose_multi_char_cluster (font, buffer, end);
has_multichar_clusters = TRUE;
}
}
@@ -265,11 +263,11 @@
hb_codepoint_t composed, glyph;
if ((buffer->out_info[buffer->out_len - 1].combining_class() >=
buffer->info[buffer->idx].combining_class()) ||
- !hb_unicode_compose (c->buffer->unicode,
+ !hb_unicode_compose (buffer->unicode,
buffer->out_info[starter].codepoint,
buffer->info[buffer->idx].codepoint,
&composed) ||
- !hb_font_get_glyph (c->font, composed, 0, &glyph))
+ !hb_font_get_glyph (font, composed, 0, &glyph))
{
/* Blocked, or doesn't compose. */
buffer->next_glyph ();
@@ -285,4 +283,3 @@
buffer->swap_buffers ();
}
-
diff --git a/src/hb-ot-shape-private.hh b/src/hb-ot-shape-private.hh
index 7347377..0e33dae 100644
--- a/src/hb-ot-shape-private.hh
+++ b/src/hb-ot-shape-private.hh
@@ -33,11 +33,9 @@
#include "hb-ot-map-private.hh"
#include "hb-ot-shape-complex-private.hh"
+#include "hb-ot-shape-normalize-private.hh"
-
-enum hb_ot_complex_shaper_t;
-
struct hb_ot_shape_plan_t
{
friend struct hb_ot_shape_planner_t;
@@ -99,7 +97,6 @@
HB_INTERNAL void _hb_set_unicode_props (hb_buffer_t *buffer);
-HB_INTERNAL void _hb_ot_shape_normalize (hb_ot_shape_context_t *c);
-
+#include "hb-ot-shape-complex-private.hh"
#endif /* HB_OT_SHAPE_PRIVATE_HH */
diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index d61eb75..d0d1850 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -362,7 +362,7 @@
hb_ensure_native_direction (c->buffer);
- _hb_ot_shape_normalize (c);
+ _hb_ot_shape_normalize (c->font, c->buffer, hb_ot_shape_complex_normalization_preference (c->plan->shaper));
hb_ot_shape_setup_masks (c);