Decomposition works now!
This commit is contained in:
parent
468e9cb25c
commit
4ff0d2d9df
|
@ -66,65 +66,74 @@ HB_BEGIN_DECLS
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
decompose (hb_ot_shape_context_t *c,
|
decompose (hb_ot_shape_context_t *c,
|
||||||
bool recompose,
|
bool shortest,
|
||||||
hb_codepoint_t ab)
|
hb_codepoint_t ab)
|
||||||
{
|
{
|
||||||
hb_codepoint_t a, b, glyph;
|
hb_codepoint_t a, b, glyph;
|
||||||
bool has_this = hb_font_get_glyph (c->font, ab, 0, &glyph);
|
|
||||||
|
|
||||||
/* If recomposing and the single char is supported by the font, we're good. */
|
if (!hb_unicode_decompose (c->buffer->unicode, ab, &a, &b) ||
|
||||||
if (recompose && has_this)
|
!hb_font_get_glyph (c->font, b, 0, &glyph))
|
||||||
return TRUE;
|
return FALSE;
|
||||||
|
|
||||||
if (hb_unicode_decompose (c->buffer->unicode, ab, &a, &b) &&
|
|
||||||
hb_font_get_glyph (c->font, b, 0, &glyph) &&
|
|
||||||
decompose (c, recompose, a))
|
|
||||||
{
|
|
||||||
/* Successfully decomposed. */
|
|
||||||
|
|
||||||
if (recompose) {
|
|
||||||
/* Try composing b with base if not blocked */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* XXX handle singleton decompositions */
|
||||||
|
bool has_a = hb_font_get_glyph (c->font, a, 0, &glyph);
|
||||||
|
if (shortest && has_a) {
|
||||||
|
/* Output a and b */
|
||||||
|
c->buffer->output_glyph (a);
|
||||||
|
c->buffer->output_glyph (b);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return has_this;
|
if (decompose (c, shortest, a)) {
|
||||||
}
|
c->buffer->output_glyph (b);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_a) {
|
||||||
|
c->buffer->output_glyph (a);
|
||||||
|
c->buffer->output_glyph (b);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
|
||||||
decompose_single_char_cluster (hb_ot_shape_context_t *c,
|
|
||||||
bool recompose,
|
|
||||||
unsigned int i)
|
|
||||||
{
|
|
||||||
// c->buffer->copy ();
|
|
||||||
// bool ret = decompose (c, recompose, c->buffer->info[i].codepoint);
|
|
||||||
// c->buffer->skip ();
|
|
||||||
// return ret;
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_single_char_cluster (hb_ot_shape_context_t *c,
|
decompose_current_glyph (hb_ot_shape_context_t *c,
|
||||||
bool recompose,
|
bool shortest)
|
||||||
unsigned int i)
|
|
||||||
{
|
{
|
||||||
/* Decompose */
|
if (decompose (c, shortest, c->buffer->info[c->buffer->idx].codepoint))
|
||||||
decompose_single_char_cluster (c, recompose, i);
|
c->buffer->skip_glyph ();
|
||||||
|
else
|
||||||
|
c->buffer->next_glyph ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_multi_char_cluster (hb_ot_shape_context_t *c,
|
decompose_single_char_cluster (hb_ot_shape_context_t *c,
|
||||||
bool recompose,
|
bool will_recompose)
|
||||||
unsigned int start,
|
{
|
||||||
unsigned int end)
|
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 ();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
decompose_current_glyph (c, will_recompose);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
decompose_multi_char_cluster (hb_ot_shape_context_t *c,
|
||||||
|
unsigned int end)
|
||||||
{
|
{
|
||||||
/* TODO Currently if there's a variation-selector we give-up, it's just too hard. */
|
/* TODO Currently if there's a variation-selector we give-up, it's just too hard. */
|
||||||
for (unsigned int i = start; i < end; i++)
|
for (unsigned int i = c->buffer->idx; i < end; i++)
|
||||||
if (unlikely (is_variation_selector (c->buffer->info[i].codepoint)))
|
if (unlikely (is_variation_selector (c->buffer->info[i].codepoint)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
while (c->buffer->idx < end)
|
||||||
|
decompose_current_glyph (c, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -132,27 +141,45 @@ _hb_ot_shape_normalize (hb_ot_shape_context_t *c)
|
||||||
{
|
{
|
||||||
hb_buffer_t *buffer = c->buffer;
|
hb_buffer_t *buffer = c->buffer;
|
||||||
bool recompose = !hb_ot_shape_complex_prefer_decomposed (c->plan->shaper);
|
bool recompose = !hb_ot_shape_complex_prefer_decomposed (c->plan->shaper);
|
||||||
|
bool has_multichar_clusters = FALSE;
|
||||||
|
|
||||||
buffer->clear_output ();
|
buffer->clear_output ();
|
||||||
|
|
||||||
|
/* First round, decompose */
|
||||||
|
|
||||||
unsigned int count = buffer->len;
|
unsigned int count = buffer->len;
|
||||||
for (buffer->idx = 0; buffer->idx < count;)
|
for (buffer->idx = 0; buffer->idx < count;)
|
||||||
{
|
{
|
||||||
|
|
||||||
unsigned int end;
|
unsigned int end;
|
||||||
for (end = buffer->idx + 1; end < count; end++)
|
for (end = buffer->idx + 1; end < count; end++)
|
||||||
if (buffer->info[buffer->idx].cluster != buffer->info[end].cluster)
|
if (buffer->info[buffer->idx].cluster != buffer->info[end].cluster)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (buffer->idx + 1 == end)
|
if (buffer->idx + 1 == end)
|
||||||
handle_single_char_cluster (c, recompose, buffer->idx);
|
decompose_single_char_cluster (c, recompose);
|
||||||
else
|
else {
|
||||||
handle_multi_char_cluster (c, recompose, buffer->idx, end);
|
decompose_multi_char_cluster (c, end);
|
||||||
while (buffer->idx < end)
|
has_multichar_clusters = TRUE;
|
||||||
c->buffer->next_glyph ();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->swap_buffers ();
|
buffer->swap_buffers ();
|
||||||
|
|
||||||
|
/* Technically speaking, two characters with ccc=0 may combine. But all
|
||||||
|
* those cases are in languages that the indic module handles (which expects
|
||||||
|
* decomposed), or in Hangul jamo, which again, we want decomposed anyway.
|
||||||
|
* So we don't bother combining across cluster boundaries. */
|
||||||
|
|
||||||
|
if (!has_multichar_clusters)
|
||||||
|
return; /* Done! */
|
||||||
|
|
||||||
|
/* Second round, reorder (inplace) */
|
||||||
|
|
||||||
|
|
||||||
|
/* Third round, recompose */
|
||||||
|
if (recompose) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HB_END_DECLS
|
HB_END_DECLS
|
||||||
|
|
|
@ -208,7 +208,6 @@ hb_ensure_native_direction (hb_buffer_t *buffer)
|
||||||
if ((HB_DIRECTION_IS_HORIZONTAL (direction) && direction != hb_script_get_horizontal_direction (buffer->props.script)) ||
|
if ((HB_DIRECTION_IS_HORIZONTAL (direction) && direction != hb_script_get_horizontal_direction (buffer->props.script)) ||
|
||||||
(HB_DIRECTION_IS_VERTICAL (direction) && direction != HB_DIRECTION_TTB))
|
(HB_DIRECTION_IS_VERTICAL (direction) && direction != HB_DIRECTION_TTB))
|
||||||
{
|
{
|
||||||
hb_form_clusters (buffer);
|
|
||||||
hb_buffer_reverse_clusters (buffer);
|
hb_buffer_reverse_clusters (buffer);
|
||||||
buffer->props.direction = HB_DIRECTION_REVERSE (buffer->props.direction);
|
buffer->props.direction = HB_DIRECTION_REVERSE (buffer->props.direction);
|
||||||
}
|
}
|
||||||
|
@ -358,6 +357,8 @@ hb_ot_shape_execute_internal (hb_ot_shape_context_t *c)
|
||||||
|
|
||||||
hb_set_unicode_props (c->buffer); /* BUFFER: Set general_category and combining_class in var1 */
|
hb_set_unicode_props (c->buffer); /* BUFFER: Set general_category and combining_class in var1 */
|
||||||
|
|
||||||
|
hb_form_clusters (c->buffer);
|
||||||
|
|
||||||
hb_ensure_native_direction (c->buffer);
|
hb_ensure_native_direction (c->buffer);
|
||||||
|
|
||||||
_hb_ot_shape_normalize (c);
|
_hb_ot_shape_normalize (c);
|
||||||
|
|
Loading…
Reference in New Issue