Add normalize mode

In preparation for Hangul shaper.
This commit is contained in:
Behdad Esfahbod 2012-04-05 17:25:19 -04:00
parent 6769f21d57
commit 11138ccff7
10 changed files with 102 additions and 61 deletions

View File

@ -70,6 +70,7 @@ HBSOURCES += \
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)

View File

@ -30,7 +30,6 @@
#define HB_OT_LAYOUT_COMMON_PRIVATE_HH
#include "hb-ot-layout-private.hh"
#include "hb-open-type-private.hh"

View File

@ -183,10 +183,10 @@ _hb_ot_shape_complex_collect_features_arabic (hb_ot_map_builder_t *map, const hb
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

View File

@ -369,11 +369,11 @@ _hb_ot_shape_complex_collect_features_indic (hb_ot_map_builder_t *map, const hb_
}
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;
}

View File

@ -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 @@ _hb_ot_shape_complex_collect_features_default (hb_ot_map_builder_t *map, const h
{
}
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

View File

@ -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 @@ hb_ot_shape_complex_collect_features (hb_ot_complex_shaper_t shaper,
/*
* 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
}

View File

@ -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 */

View File

@ -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 @@ decompose (hb_ot_shape_context_t *c,
}
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 @@ compare_combining_class (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb)
}
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 @@ _hb_ot_shape_normalize (hb_ot_shape_context_t *c)
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_ot_shape_normalize (hb_ot_shape_context_t *c)
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 @@ _hb_ot_shape_normalize (hb_ot_shape_context_t *c)
buffer->swap_buffers ();
}

View File

@ -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_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_unicode_funcs_t *unic
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 */

View File

@ -362,7 +362,7 @@ hb_ot_shape_execute_internal (hb_ot_shape_context_t *c)
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);