Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/opentype.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-)
diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c index 05ef7d76cdf..c0a29d08df9 100644 --- a/dlls/dwrite/opentype.c +++ b/dlls/dwrite/opentype.c @@ -4793,38 +4793,33 @@ static void opentype_layout_replace_glyph(struct scriptshaping_context *context, static BOOL opentype_layout_apply_gsub_single_substitution(struct scriptshaping_context *context, const struct lookup *lookup, unsigned int subtable_offset) { - const struct dwrite_fonttable *gsub = &context->table->table; + const struct dwrite_fonttable *table = &context->table->table; UINT16 format, coverage, orig_glyph, glyph; - unsigned int idx, coverage_index; + unsigned int coverage_index;
- idx = context->cur; - orig_glyph = glyph = context->u.subst.glyphs[idx]; + orig_glyph = glyph = context->u.subst.glyphs[context->cur];
- format = table_read_be_word(gsub, subtable_offset); + format = table_read_be_word(table, subtable_offset);
- coverage = table_read_be_word(gsub, subtable_offset + FIELD_OFFSET(struct ot_gsub_singlesubst_format1, coverage)); + coverage = table_read_be_word(table, subtable_offset + FIELD_OFFSET(struct ot_gsub_singlesubst_format1, coverage));
if (format == 1) { - const struct ot_gsub_singlesubst_format1 *format1 = table_read_ensure(gsub, subtable_offset, sizeof(*format1)); - - coverage_index = opentype_layout_is_glyph_covered(gsub, subtable_offset + coverage, glyph); - if (coverage_index == GLYPH_NOT_COVERED) - return FALSE; + coverage_index = opentype_layout_is_glyph_covered(table, subtable_offset + coverage, glyph); + if (coverage_index == GLYPH_NOT_COVERED) return FALSE;
- glyph = orig_glyph + GET_BE_WORD(format1->delta); + glyph = orig_glyph + table_read_be_word(table, subtable_offset + FIELD_OFFSET(struct ot_gsub_singlesubst_format1, delta)); } else if (format == 2) { - UINT16 count = table_read_be_word(gsub, subtable_offset + FIELD_OFFSET(struct ot_gsub_singlesubst_format2, count)); - const struct ot_gsub_singlesubst_format2 *format2 = table_read_ensure(gsub, subtable_offset, - FIELD_OFFSET(struct ot_gsub_singlesubst_format2, count) + count * sizeof(UINT16)); + coverage_index = opentype_layout_is_glyph_covered(table, subtable_offset + coverage, glyph); + if (coverage_index == GLYPH_NOT_COVERED) return FALSE;
- coverage_index = opentype_layout_is_glyph_covered(gsub, subtable_offset + coverage, glyph); - if (coverage_index == GLYPH_NOT_COVERED || coverage_index >= count) + if (!table_read_array_be_word(table, subtable_offset + FIELD_OFFSET(struct ot_gsub_singlesubst_format2, count), + coverage_index, &glyph)) + { return FALSE; - - glyph = GET_BE_WORD(format2->substitutes[coverage_index]); + } } else {
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/opentype.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c index c0a29d08df9..e729be9b20f 100644 --- a/dlls/dwrite/opentype.c +++ b/dlls/dwrite/opentype.c @@ -4862,37 +4862,34 @@ static BOOL opentype_layout_gsub_ensure_buffer(struct scriptshaping_context *con static BOOL opentype_layout_apply_gsub_mult_substitution(struct scriptshaping_context *context, const struct lookup *lookup, unsigned int subtable_offset) { - const struct dwrite_fonttable *gsub = &context->table->table; - UINT16 format, coverage, glyph, seq_count, glyph_count; - const struct ot_gsub_multsubst_format1 *format1; + const struct dwrite_fonttable *table = &context->table->table; + UINT16 format, coverage, glyph, glyph_count; unsigned int i, idx, coverage_index; const UINT16 *glyphs;
idx = context->cur; glyph = context->u.subst.glyphs[idx];
- format = table_read_be_word(gsub, subtable_offset); + format = table_read_be_word(table, subtable_offset);
- coverage = table_read_be_word(gsub, subtable_offset + FIELD_OFFSET(struct ot_gsub_multsubst_format1, coverage)); + coverage = table_read_be_word(table, subtable_offset + FIELD_OFFSET(struct ot_gsub_multsubst_format1, coverage));
if (format == 1) { - coverage_index = opentype_layout_is_glyph_covered(gsub, subtable_offset + coverage, glyph); - if (coverage_index == GLYPH_NOT_COVERED) - return FALSE; - - seq_count = table_read_be_word(gsub, subtable_offset + FIELD_OFFSET(struct ot_gsub_multsubst_format1, seq_count)); + UINT16 seq_offset;
- format1 = table_read_ensure(gsub, subtable_offset, FIELD_OFFSET(struct ot_gsub_multsubst_format1, seq[seq_count])); + coverage_index = opentype_layout_is_glyph_covered(table, subtable_offset + coverage, glyph); + if (coverage_index == GLYPH_NOT_COVERED) return FALSE;
- if (!seq_count || seq_count <= coverage_index || !format1) + if (!table_read_array_be_word(table, subtable_offset + FIELD_OFFSET(struct ot_gsub_multsubst_format1, seq_count), + coverage_index, &seq_offset)) + { return FALSE; + }
- glyph_count = table_read_be_word(gsub, subtable_offset + GET_BE_WORD(format1->seq[coverage_index])); + glyph_count = table_read_be_word(table, subtable_offset + seq_offset);
- glyphs = table_read_ensure(gsub, subtable_offset + GET_BE_WORD(format1->seq[coverage_index]) + 2, - glyph_count * sizeof(*glyphs)); - if (!glyphs) + if (!(glyphs = table_read_ensure(table, subtable_offset + seq_offset + 2, glyph_count * sizeof(*glyphs)))) return FALSE;
if (glyph_count == 1)
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/opentype.c | 48 +++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 29 deletions(-)
diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c index e729be9b20f..e8d20683975 100644 --- a/dlls/dwrite/opentype.c +++ b/dlls/dwrite/opentype.c @@ -4221,16 +4221,16 @@ static BOOL opentype_layout_apply_gpos_mark_to_base_attachment(struct scriptshap return TRUE; }
-static BOOL table_read_array_be_word(const struct dwrite_fonttable *table, unsigned int offset, +static const UINT16 * table_read_array_be_word(const struct dwrite_fonttable *table, unsigned int offset, unsigned int index, UINT16 *data) { unsigned int count = table_read_be_word(table, offset); const UINT16 *array;
- if (index >= count) return FALSE; + if (index != ~0u && index >= count) return NULL; if (!(array = table_read_ensure(table, offset + 2, count * sizeof(*array)))) return FALSE; - *data = GET_BE_WORD(array[index]); - return TRUE; + *data = index == ~0u ? count : GET_BE_WORD(array[index]); + return array; }
static BOOL opentype_layout_apply_gpos_mark_to_lig_attachment(struct scriptshaping_context *context, @@ -4887,10 +4887,7 @@ static BOOL opentype_layout_apply_gsub_mult_substitution(struct scriptshaping_co return FALSE; }
- glyph_count = table_read_be_word(table, subtable_offset + seq_offset); - - if (!(glyphs = table_read_ensure(table, subtable_offset + seq_offset + 2, glyph_count * sizeof(*glyphs)))) - return FALSE; + if (!(glyphs = table_read_array_be_word(table, subtable_offset + seq_offset, ~0u, &glyph_count))) return FALSE;
if (glyph_count == 1) { @@ -4959,43 +4956,36 @@ static BOOL opentype_layout_apply_gsub_mult_substitution(struct scriptshaping_co static BOOL opentype_layout_apply_gsub_alt_substitution(struct scriptshaping_context *context, const struct lookup *lookup, unsigned int subtable_offset) { - const struct dwrite_fonttable *gsub = &context->table->table; - unsigned int idx, coverage_index, offset; + const struct dwrite_fonttable *table = &context->table->table; + unsigned int idx, coverage_index; UINT16 format, coverage, glyph;
idx = context->cur; glyph = context->u.subst.glyphs[idx];
- format = table_read_be_word(gsub, subtable_offset); + format = table_read_be_word(table, subtable_offset);
if (format == 1) { - const struct ot_gsub_altsubst_format1 *format1 = table_read_ensure(gsub, subtable_offset, sizeof(*format1)); - unsigned int count, shift, alt_index; + const struct ot_gsub_altsubst_format1 *format1 = table_read_ensure(table, subtable_offset, sizeof(*format1)); + unsigned int shift, alt_index; + UINT16 set_offset;
- coverage = table_read_be_word(gsub, subtable_offset + FIELD_OFFSET(struct ot_gsub_altsubst_format1, coverage)); + coverage = table_read_be_word(table, subtable_offset + FIELD_OFFSET(struct ot_gsub_altsubst_format1, coverage));
- coverage_index = opentype_layout_is_glyph_covered(gsub, subtable_offset + coverage, glyph); - if (coverage_index == GLYPH_NOT_COVERED) - return FALSE; - - if (coverage_index >= GET_BE_WORD(format1->count)) - return FALSE; - - offset = table_read_be_word(gsub, subtable_offset + - FIELD_OFFSET(struct ot_gsub_altsubst_format1, sets[coverage_index])); + 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(gsub, subtable_offset + offset); - if (!count) + if (!table_read_array_be_word(table, subtable_offset + FIELD_OFFSET(struct ot_gsub_altsubst_format1, count), + coverage_index, &set_offset)) return FALSE;
+ /* Argument is 1-based. */ BitScanForward(&shift, context->lookup_mask); alt_index = (context->lookup_mask & context->glyph_infos[idx].mask) >> shift; + if (!alt_index) return FALSE;
- if (alt_index > count || !alt_index) - return FALSE; - - glyph = table_read_be_word(gsub, subtable_offset + offset + 2 + (alt_index - 1) * sizeof(glyph)); + if (!table_read_array_be_word(table, subtable_offset + set_offset, alt_index - 1, &glyph)) return FALSE; } else {
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/opentype.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-)
diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c index e8d20683975..53925465a12 100644 --- a/dlls/dwrite/opentype.c +++ b/dlls/dwrite/opentype.c @@ -5119,46 +5119,37 @@ static BOOL opentype_layout_apply_ligature(struct scriptshaping_context *context static BOOL opentype_layout_apply_gsub_lig_substitution(struct scriptshaping_context *context, const struct lookup *lookup, unsigned int subtable_offset) { - const struct dwrite_fonttable *gsub = &context->table->table; - unsigned int coverage_index, offset, lig_set_offset, lig_set_count; - UINT16 format, coverage, glyph; + const struct dwrite_fonttable *table = &context->table->table; + UINT16 format, coverage, glyph, lig_set_offset; + unsigned int coverage_index;
glyph = context->u.subst.glyphs[context->cur];
- format = table_read_be_word(gsub, subtable_offset); + format = table_read_be_word(table, subtable_offset);
if (format == 1) { - const struct ot_gsub_ligsubst_format1 *format1 = table_read_ensure(gsub, subtable_offset, sizeof(*format1)); - const struct ot_gsub_ligset *lig_set; - unsigned int i, lig_count; + const struct ot_gsub_ligsubst_format1 *format1 = table_read_ensure(table, subtable_offset, sizeof(*format1)); + unsigned int i; + const UINT16 *offsets; + UINT16 lig_count;
- coverage = table_read_be_word(gsub, subtable_offset + FIELD_OFFSET(struct ot_gsub_ligsubst_format1, coverage)); + coverage = table_read_be_word(table, subtable_offset + FIELD_OFFSET(struct ot_gsub_ligsubst_format1, coverage));
- coverage_index = opentype_layout_is_glyph_covered(gsub, subtable_offset + coverage, glyph); - if (coverage_index == GLYPH_NOT_COVERED) - return FALSE; + coverage_index = opentype_layout_is_glyph_covered(table, subtable_offset + coverage, glyph); + if (coverage_index == GLYPH_NOT_COVERED) return FALSE;
- lig_set_count = table_read_be_word(gsub, subtable_offset + FIELD_OFFSET(struct ot_gsub_ligsubst_format1, lig_set_count)); - if (coverage_index >= lig_set_count || !table_read_ensure(gsub, subtable_offset, - FIELD_OFFSET(struct ot_gsub_ligsubst_format1, lig_sets[lig_set_count]))) - { + if (!table_read_array_be_word(table, subtable_offset + FIELD_OFFSET(struct ot_gsub_ligsubst_format1, lig_set_count), + coverage_index, &lig_set_offset)) return FALSE; - } - - lig_set_offset = table_read_be_word(gsub, subtable_offset + - FIELD_OFFSET(struct ot_gsub_ligsubst_format1, lig_sets[coverage_index])); - offset = subtable_offset + lig_set_offset;
- lig_count = table_read_be_word(gsub, offset); - lig_set = table_read_ensure(gsub, offset, FIELD_OFFSET(struct ot_gsub_ligset, offsets[lig_count])); - if (!lig_count || !lig_set) + if (!(offsets = table_read_array_be_word(table, subtable_offset + lig_set_offset, ~0u, &lig_count))) return FALSE;
/* First applicable ligature is used. */ for (i = 0; i < lig_count; ++i) { - if (opentype_layout_apply_ligature(context, offset + GET_BE_WORD(lig_set->offsets[i]), lookup)) + if (opentype_layout_apply_ligature(context, subtable_offset + lig_set_offset + GET_BE_WORD(offsets[i]), lookup)) return TRUE; } }