From 2aaa6d1af98cd3b1f50339a17a0b7fff82334770 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Thu, 21 May 2020 15:28:45 +0300 Subject: [PATCH] dwrite: Remove feature duplicates before applying them. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/dwrite/shape.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/dlls/dwrite/shape.c b/dlls/dwrite/shape.c index 0372d739b56..82ad3a2a1e7 100644 --- a/dlls/dwrite/shape.c +++ b/dlls/dwrite/shape.c @@ -210,6 +210,27 @@ static void shape_add_feature(struct shaping_features *features, unsigned int ta features->features[features->count++].tag = tag; } +static int features_sorting_compare(const void *a, const void *b) +{ + const struct shaping_feature *left = a, *right = b; + return left->tag != right->tag ? (left->tag < right->tag ? -1 : 1) : 0; +}; + +static void shape_merge_features(struct shaping_features *features) +{ + unsigned int j = 0, i; + + /* Sort and merge duplicates. */ + qsort(features->features, features->count, sizeof(*features->features), features_sorting_compare); + + for (i = 1; i < features->count; ++i) + { + if (features->features[i].tag != features->features[j].tag) + features->features[++j] = features->features[i]; + } + features->count = j + 1; +} + HRESULT shape_get_positions(struct scriptshaping_context *context, const unsigned int *scripts) { static const unsigned int common_features[] = @@ -239,6 +260,8 @@ HRESULT shape_get_positions(struct scriptshaping_context *context, const unsigne shape_add_feature(&features, horizontal_features[i]); } + shape_merge_features(&features); + /* Resolve script tag to actually supported script. */ if (cache->gpos.table.data) { @@ -322,6 +345,8 @@ HRESULT shape_get_glyphs(struct scriptshaping_context *context, const unsigned i shape_add_feature(&features, horizontal_features[i]); } + shape_merge_features(&features); + /* Resolve script tag to actually supported script. */ if (cache->gsub.table.data) {