Start converging Ligature and match_input
This commit is contained in:
parent
2eef71737e
commit
93814ca7dc
|
@ -495,38 +495,12 @@ struct Ligature
|
||||||
if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false);
|
if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is perhaps the trickiest part of GSUB... Remarks:
|
* This is perhaps the trickiest part of OpenType... Remarks:
|
||||||
*
|
*
|
||||||
* - If all components of the ligature were marks, we call this a mark ligature.
|
* - If all components of the ligature were marks, we call this a mark ligature.
|
||||||
*
|
*
|
||||||
* - If there is no GDEF, and the ligature is NOT a mark ligature, we categorize
|
* - If there is no GDEF, and the ligature is NOT a mark ligature, we categorize
|
||||||
* it as a ligature glyph. Though, really, this will not really be used...
|
* it as a ligature glyph.
|
||||||
*
|
|
||||||
* - If it *is* a mark ligature, we don't allocate a new ligature id, and leave
|
|
||||||
* the ligature to keep its old ligature id. This will allow it to attach to
|
|
||||||
* a base ligature in GPOS. Eg. if the sequence is: LAM,LAM,SHADDA,FATHA,HEH,
|
|
||||||
* and LAM,LAM,HEH for a ligature, they will leave SHADDA and FATHA wit a
|
|
||||||
* ligature id and component value of 2. Then if SHADDA,FATHA form a ligature
|
|
||||||
* later, we don't want them to lose their ligature id/component, otherwise
|
|
||||||
* GPOS will fail to correctly position the mark ligature on top of the
|
|
||||||
* LAM,LAM,HEH ligature. See:
|
|
||||||
* https://bugzilla.gnome.org/show_bug.cgi?id=676343
|
|
||||||
*
|
|
||||||
* - If a ligature is formed of components that some of which are also ligatures
|
|
||||||
* themselves, and those ligature components had marks attached to *their*
|
|
||||||
* components, we have to attach the marks to the new ligature component
|
|
||||||
* positions! Now *that*'s tricky! And these marks may be following the
|
|
||||||
* last component of the whole sequence, so we should loop forward looking
|
|
||||||
* for them and update them.
|
|
||||||
*
|
|
||||||
* Eg. the sequence is LAM,LAM,SHADDA,FATHA,HEH, and the font first forms a
|
|
||||||
* 'calt' ligature of LAM,HEH, leaving the SHADDA and FATHA with a ligature
|
|
||||||
* id and component == 1. Now, during 'liga', the LAM and the LAM-HEH ligature
|
|
||||||
* form a LAM-LAM-HEH ligature. We need to reassign the SHADDA and FATHA to
|
|
||||||
* the new ligature with a component value of 2.
|
|
||||||
*
|
|
||||||
* This in fact happened to a font... See:
|
|
||||||
* https://bugzilla.gnome.org/show_bug.cgi?id=437633
|
|
||||||
*
|
*
|
||||||
* - Ligatures cannot be formed across glyphs attached to different components
|
* - Ligatures cannot be formed across glyphs attached to different components
|
||||||
* of previous ligatures. Eg. the sequence is LAM,SHADDA,LAM,FATHA,HEH, and
|
* of previous ligatures. Eg. the sequence is LAM,SHADDA,LAM,FATHA,HEH, and
|
||||||
|
@ -578,6 +552,34 @@ struct Ligature
|
||||||
/* Deal, we are forming the ligature. */
|
/* Deal, we are forming the ligature. */
|
||||||
c->buffer->merge_clusters (c->buffer->idx, skippy_iter.idx + 1);
|
c->buffer->merge_clusters (c->buffer->idx, skippy_iter.idx + 1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* - If it *is* a mark ligature, we don't allocate a new ligature id, and leave
|
||||||
|
* the ligature to keep its old ligature id. This will allow it to attach to
|
||||||
|
* a base ligature in GPOS. Eg. if the sequence is: LAM,LAM,SHADDA,FATHA,HEH,
|
||||||
|
* and LAM,LAM,HEH for a ligature, they will leave SHADDA and FATHA wit a
|
||||||
|
* ligature id and component value of 2. Then if SHADDA,FATHA form a ligature
|
||||||
|
* later, we don't want them to lose their ligature id/component, otherwise
|
||||||
|
* GPOS will fail to correctly position the mark ligature on top of the
|
||||||
|
* LAM,LAM,HEH ligature. See:
|
||||||
|
* https://bugzilla.gnome.org/show_bug.cgi?id=676343
|
||||||
|
*
|
||||||
|
* - If a ligature is formed of components that some of which are also ligatures
|
||||||
|
* themselves, and those ligature components had marks attached to *their*
|
||||||
|
* components, we have to attach the marks to the new ligature component
|
||||||
|
* positions! Now *that*'s tricky! And these marks may be following the
|
||||||
|
* last component of the whole sequence, so we should loop forward looking
|
||||||
|
* for them and update them.
|
||||||
|
*
|
||||||
|
* Eg. the sequence is LAM,LAM,SHADDA,FATHA,HEH, and the font first forms a
|
||||||
|
* 'calt' ligature of LAM,HEH, leaving the SHADDA and FATHA with a ligature
|
||||||
|
* id and component == 1. Now, during 'liga', the LAM and the LAM-HEH ligature
|
||||||
|
* form a LAM-LAM-HEH ligature. We need to reassign the SHADDA and FATHA to
|
||||||
|
* the new ligature with a component value of 2.
|
||||||
|
*
|
||||||
|
* This in fact happened to a font... See:
|
||||||
|
* https://bugzilla.gnome.org/show_bug.cgi?id=437633
|
||||||
|
*/
|
||||||
|
|
||||||
unsigned int klass = is_mark_ligature ? 0 : HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE;
|
unsigned int klass = is_mark_ligature ? 0 : HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE;
|
||||||
unsigned int lig_id = is_mark_ligature ? 0 : allocate_lig_id (c->buffer);
|
unsigned int lig_id = is_mark_ligature ? 0 : allocate_lig_id (c->buffer);
|
||||||
unsigned int last_lig_id = get_lig_id (c->buffer->cur());
|
unsigned int last_lig_id = get_lig_id (c->buffer->cur());
|
||||||
|
|
|
@ -423,17 +423,47 @@ static inline bool match_input (hb_apply_context_t *c,
|
||||||
const void *match_data,
|
const void *match_data,
|
||||||
unsigned int *end_offset = NULL)
|
unsigned int *end_offset = NULL)
|
||||||
{
|
{
|
||||||
|
hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", NULL, HB_FUNC, "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint);
|
||||||
|
|
||||||
hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx, count - 1);
|
hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx, count - 1);
|
||||||
if (skippy_iter.has_no_chance ())
|
if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false);
|
||||||
return false;
|
|
||||||
|
bool is_mark_ligature = !!(c->property & HB_OT_LAYOUT_GLYPH_CLASS_MARK);
|
||||||
|
|
||||||
|
unsigned int total_component_count = 0;
|
||||||
|
total_component_count += get_lig_num_comps (c->buffer->cur());
|
||||||
|
|
||||||
|
unsigned int first_lig_id = get_lig_id (c->buffer->cur());
|
||||||
|
unsigned int first_lig_comp = get_lig_comp (c->buffer->cur());
|
||||||
|
|
||||||
for (unsigned int i = 1; i < count; i++)
|
for (unsigned int i = 1; i < count; i++)
|
||||||
{
|
{
|
||||||
if (!skippy_iter.next ())
|
unsigned int property;
|
||||||
return false;
|
|
||||||
|
|
||||||
if (likely (!match_func (c->buffer->info[skippy_iter.idx].codepoint, input[i - 1], match_data)))
|
if (!skippy_iter.next (&property)) return TRACE_RETURN (false);
|
||||||
return false;
|
|
||||||
|
if (likely (!match_func (c->buffer->info[skippy_iter.idx].codepoint, input[i - 1], match_data))) return false;
|
||||||
|
// if (likely (c->buffer->info[skippy_iter.idx].codepoint != component[i])) return TRACE_RETURN (false);
|
||||||
|
|
||||||
|
unsigned int this_lig_id = get_lig_id (c->buffer->info[skippy_iter.idx]);
|
||||||
|
unsigned int this_lig_comp = get_lig_comp (c->buffer->info[skippy_iter.idx]);
|
||||||
|
|
||||||
|
if (first_lig_id && first_lig_comp) {
|
||||||
|
/* If first component was attached to a previous ligature component,
|
||||||
|
* all subsequent components should be attached to the same ligature
|
||||||
|
* component, otherwise we shouldn't ligate them. */
|
||||||
|
if (first_lig_id != this_lig_id || first_lig_comp != this_lig_comp)
|
||||||
|
return TRACE_RETURN (false);
|
||||||
|
} else {
|
||||||
|
/* If first component was NOT attached to a previous ligature component,
|
||||||
|
* all subsequent components should also NOT be attached to any ligature
|
||||||
|
* component, unless they are attached to the first component itself! */
|
||||||
|
if (this_lig_id && this_lig_comp && (this_lig_id != first_lig_id))
|
||||||
|
return TRACE_RETURN (false);
|
||||||
|
}
|
||||||
|
|
||||||
|
is_mark_ligature = is_mark_ligature && (property & HB_OT_LAYOUT_GLYPH_CLASS_MARK);
|
||||||
|
total_component_count += get_lig_num_comps (c->buffer->info[skippy_iter.idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end_offset)
|
if (end_offset)
|
||||||
|
@ -448,20 +478,22 @@ static inline bool match_backtrack (hb_apply_context_t *c,
|
||||||
match_func_t match_func,
|
match_func_t match_func,
|
||||||
const void *match_data)
|
const void *match_data)
|
||||||
{
|
{
|
||||||
|
hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", NULL, HB_FUNC, "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint);
|
||||||
|
|
||||||
hb_apply_context_t::mark_skipping_backward_iterator_t skippy_iter (c, c->buffer->backtrack_len (), count, true);
|
hb_apply_context_t::mark_skipping_backward_iterator_t skippy_iter (c, c->buffer->backtrack_len (), count, true);
|
||||||
if (skippy_iter.has_no_chance ())
|
if (skippy_iter.has_no_chance ())
|
||||||
return false;
|
return TRACE_RETURN (false);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
if (!skippy_iter.prev ())
|
if (!skippy_iter.prev ())
|
||||||
return false;
|
return TRACE_RETURN (false);
|
||||||
|
|
||||||
if (likely (!match_func (c->buffer->out_info[skippy_iter.idx].codepoint, backtrack[i], match_data)))
|
if (likely (!match_func (c->buffer->out_info[skippy_iter.idx].codepoint, backtrack[i], match_data)))
|
||||||
return false;
|
return TRACE_RETURN (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return TRACE_RETURN (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool match_lookahead (hb_apply_context_t *c,
|
static inline bool match_lookahead (hb_apply_context_t *c,
|
||||||
|
@ -471,20 +503,22 @@ static inline bool match_lookahead (hb_apply_context_t *c,
|
||||||
const void *match_data,
|
const void *match_data,
|
||||||
unsigned int offset)
|
unsigned int offset)
|
||||||
{
|
{
|
||||||
|
hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", NULL, HB_FUNC, "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint);
|
||||||
|
|
||||||
hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx + offset - 1, count, true);
|
hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx + offset - 1, count, true);
|
||||||
if (skippy_iter.has_no_chance ())
|
if (skippy_iter.has_no_chance ())
|
||||||
return false;
|
return TRACE_RETURN (false);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
if (!skippy_iter.next ())
|
if (!skippy_iter.next ())
|
||||||
return false;
|
return TRACE_RETURN (false);
|
||||||
|
|
||||||
if (likely (!match_func (c->buffer->info[skippy_iter.idx].codepoint, lookahead[i], match_data)))
|
if (likely (!match_func (c->buffer->info[skippy_iter.idx].codepoint, lookahead[i], match_data)))
|
||||||
return false;
|
return TRACE_RETURN (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return TRACE_RETURN (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue