dwrite: Implement chaining contextual substitution of format 2.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
7e798dae37
commit
d1ae4a5647
|
@ -3536,6 +3536,13 @@ static BOOL opentype_match_glyph_func(UINT16 glyph, UINT16 glyph_data, const str
|
|||
return glyph == glyph_data;
|
||||
}
|
||||
|
||||
static BOOL opentype_match_class_func(UINT16 glyph, UINT16 glyph_data, const struct match_data *data)
|
||||
{
|
||||
const struct match_context *mc = data->mc;
|
||||
UINT16 glyph_class = opentype_layout_get_glyph_class(&mc->context->table->table, data->subtable_offset, glyph);
|
||||
return glyph_class == glyph_data;
|
||||
}
|
||||
|
||||
static BOOL opentype_match_coverage_func(UINT16 glyph, UINT16 glyph_data, const struct match_data *data)
|
||||
{
|
||||
const struct match_context *mc = data->mc;
|
||||
|
@ -5145,45 +5152,17 @@ static BOOL opentype_layout_apply_gsub_chain_context_lookup(unsigned int backtra
|
|||
opentype_layout_context_gsub_apply_lookup(mc->context, input_count, match_positions, lookup_count, lookup_records, match_length);
|
||||
}
|
||||
|
||||
static BOOL opentype_layout_apply_gsub_chain_context_substitution(struct scriptshaping_context *context,
|
||||
const struct lookup *lookup, unsigned int subtable_offset)
|
||||
static BOOL opentype_layout_apply_chain_rule_set(const struct match_context *mc, unsigned int offset)
|
||||
{
|
||||
struct match_context mc = { .context = context, .mask = lookup->mask };
|
||||
const struct dwrite_fonttable *table = &context->table->table;
|
||||
unsigned int i, coverage_index = GLYPH_NOT_COVERED, count, offset;
|
||||
unsigned int backtrack_count, input_count, lookahead_count, lookup_count;
|
||||
const struct dwrite_fonttable *table = &mc->context->table->table;
|
||||
const UINT16 *backtrack, *lookahead, *input, *lookup_records;
|
||||
UINT16 glyph, format, coverage;
|
||||
BOOL ret = FALSE;
|
||||
|
||||
glyph = context->u.subst.glyphs[context->cur];
|
||||
|
||||
format = table_read_be_word(table, subtable_offset);
|
||||
|
||||
if (format == 1)
|
||||
{
|
||||
const struct ot_gsub_ruleset *ruleset;
|
||||
|
||||
coverage = table_read_be_word(table, subtable_offset +
|
||||
FIELD_OFFSET(struct ot_gsub_chaincontext_subst_format1, coverage));
|
||||
|
||||
coverage_index = opentype_layout_is_glyph_covered(table, subtable_offset + coverage, glyph);
|
||||
if (coverage_index == GLYPH_NOT_COVERED)
|
||||
return FALSE;
|
||||
|
||||
count = table_read_be_word(table, subtable_offset + FIELD_OFFSET(struct ot_gsub_chaincontext_subst_format1,
|
||||
ruleset_count));
|
||||
if (coverage_index >= count)
|
||||
return FALSE;
|
||||
|
||||
offset = table_read_be_word(table, subtable_offset + FIELD_OFFSET(struct ot_gsub_chaincontext_subst_format1,
|
||||
rulesets[coverage_index]));
|
||||
offset += subtable_offset;
|
||||
unsigned int i, count;
|
||||
|
||||
count = table_read_be_word(table, offset);
|
||||
ruleset = table_read_ensure(table, offset, count * sizeof(ruleset->offsets));
|
||||
|
||||
mc.match_func = opentype_match_glyph_func;
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
unsigned int rule_offset = offset + GET_BE_WORD(ruleset->offsets[i]);
|
||||
|
@ -5209,13 +5188,29 @@ static BOOL opentype_layout_apply_gsub_chain_context_substitution(struct scripts
|
|||
|
||||
/* First applicable rule is used. */
|
||||
if (opentype_layout_apply_gsub_chain_context_lookup(backtrack_count, backtrack, input_count, input, lookahead_count,
|
||||
lookahead, lookup_count, lookup_records, &mc))
|
||||
lookahead, lookup_count, lookup_records, mc))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (format == 2)
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOL opentype_layout_apply_gsub_chain_context_substitution(struct scriptshaping_context *context,
|
||||
const struct lookup *lookup, unsigned int subtable_offset)
|
||||
{
|
||||
struct match_context mc = { .context = context, .mask = lookup->mask };
|
||||
const struct dwrite_fonttable *table = &context->table->table;
|
||||
unsigned int coverage_index = GLYPH_NOT_COVERED, count, offset;
|
||||
UINT16 glyph, format, coverage;
|
||||
BOOL ret = FALSE;
|
||||
|
||||
glyph = context->u.subst.glyphs[context->cur];
|
||||
|
||||
format = table_read_be_word(table, subtable_offset);
|
||||
|
||||
if (format == 1)
|
||||
{
|
||||
coverage = table_read_be_word(table, subtable_offset +
|
||||
FIELD_OFFSET(struct ot_gsub_chaincontext_subst_format1, coverage));
|
||||
|
@ -5224,7 +5219,57 @@ static BOOL opentype_layout_apply_gsub_chain_context_substitution(struct scripts
|
|||
if (coverage_index == GLYPH_NOT_COVERED)
|
||||
return FALSE;
|
||||
|
||||
WARN("Chaining contextual substitution (2) is not supported.\n");
|
||||
count = table_read_be_word(table, subtable_offset + FIELD_OFFSET(struct ot_gsub_chaincontext_subst_format1,
|
||||
ruleset_count));
|
||||
if (coverage_index >= count)
|
||||
return FALSE;
|
||||
|
||||
offset = table_read_be_word(table, subtable_offset + FIELD_OFFSET(struct ot_gsub_chaincontext_subst_format1,
|
||||
rulesets[coverage_index]));
|
||||
offset += subtable_offset;
|
||||
|
||||
mc.match_func = opentype_match_glyph_func;
|
||||
|
||||
ret = opentype_layout_apply_chain_rule_set(&mc, offset);
|
||||
}
|
||||
else if (format == 2)
|
||||
{
|
||||
unsigned int backtrack_classdef, input_classdef, lookahead_classdef, rule_set_idx;
|
||||
|
||||
offset = subtable_offset + 2 /* format */;
|
||||
|
||||
coverage = table_read_be_word(table, offset);
|
||||
offset += 2;
|
||||
|
||||
coverage_index = opentype_layout_is_glyph_covered(table, subtable_offset + coverage, glyph);
|
||||
if (coverage_index == GLYPH_NOT_COVERED)
|
||||
return FALSE;
|
||||
|
||||
backtrack_classdef = table_read_be_word(table, offset) + subtable_offset;
|
||||
offset += 2;
|
||||
|
||||
input_classdef = table_read_be_word(table, offset) + subtable_offset;
|
||||
offset += 2;
|
||||
|
||||
lookahead_classdef = table_read_be_word(table, offset) + subtable_offset;
|
||||
offset += 2;
|
||||
|
||||
count = table_read_be_word(table, offset);
|
||||
offset+= 2;
|
||||
|
||||
rule_set_idx = opentype_layout_get_glyph_class(table, input_classdef, glyph);
|
||||
if (rule_set_idx >= count)
|
||||
return FALSE;
|
||||
|
||||
offset = table_read_be_word(table, offset + rule_set_idx * 2);
|
||||
offset += subtable_offset;
|
||||
|
||||
mc.backtrack_offset = backtrack_classdef;
|
||||
mc.input_offset = input_classdef;
|
||||
mc.lookahead_offset = lookahead_classdef;
|
||||
mc.match_func = opentype_match_class_func;
|
||||
|
||||
ret = opentype_layout_apply_chain_rule_set(&mc, offset);
|
||||
}
|
||||
else if (format == 3)
|
||||
{
|
||||
|
@ -5262,6 +5307,7 @@ static BOOL opentype_layout_apply_gsub_chain_context_substitution(struct scripts
|
|||
mc.input_offset = subtable_offset;
|
||||
mc.lookahead_offset = subtable_offset;
|
||||
mc.match_func = opentype_match_coverage_func;
|
||||
|
||||
ret = opentype_layout_apply_gsub_chain_context_lookup(backtrack_count, backtrack, input_count, input + 1,
|
||||
lookahead_count, lookahead, lookup_count, lookup_records, &mc);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue