From cc610a09334731f1832492c79d7b0075df2556d5 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Mon, 16 May 2016 20:51:36 +0300 Subject: [PATCH] dwrite: Don't reset advances if original and modified advances are the same array. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/dwrite/analyzer.c | 3 +- dlls/dwrite/tests/analyzer.c | 64 ++++++++++++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/dlls/dwrite/analyzer.c b/dlls/dwrite/analyzer.c index 90b53adc554..9ae0ccacc2d 100644 --- a/dlls/dwrite/analyzer.c +++ b/dlls/dwrite/analyzer.c @@ -1374,7 +1374,8 @@ static HRESULT WINAPI dwritetextanalyzer1_ApplyCharacterSpacing(IDWriteTextAnaly len, glyph_count, clustermap, advances, offsets, props, modified_advances, modified_offsets); if (min_advance_width < 0.0f) { - memset(modified_advances, 0, glyph_count*sizeof(*modified_advances)); + if (modified_advances != advances) + memset(modified_advances, 0, glyph_count*sizeof(*modified_advances)); return E_INVALIDARG; } diff --git a/dlls/dwrite/tests/analyzer.c b/dlls/dwrite/tests/analyzer.c index 23c3d22234e..ea09bd5ee0c 100644 --- a/dlls/dwrite/tests/analyzer.c +++ b/dlls/dwrite/tests/analyzer.c @@ -1723,7 +1723,7 @@ static void test_ApplyCharacterSpacing(void) offsets[0].advanceOffset = ptr->offsets[0]; offsets[1].advanceOffset = ptr->offsets[1]; offsets[2].advanceOffset = ptr->offsets[2]; - /* Ascender offsets are never thouched as spacing applies in reading direction only, + /* Ascender offsets are never touched as spacing applies in reading direction only, we'll only test them to see if they are not changed */ offsets[0].ascenderOffset = 23.0; offsets[1].ascenderOffset = 32.0; @@ -1758,11 +1758,8 @@ static void test_ApplyCharacterSpacing(void) props, advances, offsets); - /* invalid argument cases */ - if (ptr->min_advance < 0.0) - ok(hr == E_INVALIDARG, "%d: got 0x%08x\n", i, hr); - else - ok(hr == S_OK, "%d: got 0x%08x\n", i, hr); + ok(hr == (ptr->min_advance < 0.0f ? E_INVALIDARG : S_OK), "%d: got 0x%08x\n", i, hr); + if (hr == S_OK) { ok(ptr->modified_advances[0] == advances[0], "%d: got advance[0] %.2f, expected %.2f\n", i, advances[0], ptr->modified_advances[0]); ok(ptr->modified_advances[1] == advances[1], "%d: got advance[1] %.2f, expected %.2f\n", i, advances[1], ptr->modified_advances[1]); @@ -1791,6 +1788,61 @@ static void test_ApplyCharacterSpacing(void) ok(offsets[0].ascenderOffset == 23.0, "%d: unexpected ascenderOffset %.2f\n", i, offsets[0].ascenderOffset); ok(offsets[1].ascenderOffset == 32.0, "%d: unexpected ascenderOffset %.2f\n", i, offsets[1].ascenderOffset); } + + /* same, with argument aliasing */ + memcpy(advances, ptr->advances, glyph_count * sizeof(*advances)); + offsets[0].advanceOffset = ptr->offsets[0]; + offsets[1].advanceOffset = ptr->offsets[1]; + offsets[2].advanceOffset = ptr->offsets[2]; + /* Ascender offsets are never touched as spacing applies in reading direction only, + we'll only test them to see if they are not changed */ + offsets[0].ascenderOffset = 23.0f; + offsets[1].ascenderOffset = 32.0f; + offsets[2].ascenderOffset = 31.0f; + + hr = IDWriteTextAnalyzer1_ApplyCharacterSpacing(analyzer1, + ptr->leading, + ptr->trailing, + ptr->min_advance, + sizeof(clustermap)/sizeof(clustermap[0]), + glyph_count, + clustermap, + advances, + offsets, + props, + advances, + offsets); + ok(hr == (ptr->min_advance < 0.0f ? E_INVALIDARG : S_OK), "%d: got 0x%08x\n", i, hr); + + if (hr == S_OK) { + ok(ptr->modified_advances[0] == advances[0], "%d: got advance[0] %.2f, expected %.2f\n", i, advances[0], ptr->modified_advances[0]); + ok(ptr->modified_advances[1] == advances[1], "%d: got advance[1] %.2f, expected %.2f\n", i, advances[1], ptr->modified_advances[1]); + if (glyph_count > 2) + ok(ptr->modified_advances[2] == advances[2], "%d: got advance[2] %.2f, expected %.2f\n", i, advances[2], ptr->modified_advances[2]); + + ok(ptr->modified_offsets[0] == offsets[0].advanceOffset, "%d: got offset[0] %.2f, expected %.2f\n", i, + offsets[0].advanceOffset, ptr->modified_offsets[0]); + ok(ptr->modified_offsets[1] == offsets[1].advanceOffset, "%d: got offset[1] %.2f, expected %.2f\n", i, + offsets[1].advanceOffset, ptr->modified_offsets[1]); + if (glyph_count > 2) + ok(ptr->modified_offsets[2] == offsets[2].advanceOffset, "%d: got offset[2] %.2f, expected %.2f\n", i, + offsets[2].advanceOffset, ptr->modified_offsets[2]); + + ok(offsets[0].ascenderOffset == 23.0f, "%d: unexpected ascenderOffset %.2f\n", i, offsets[0].ascenderOffset); + ok(offsets[1].ascenderOffset == 32.0f, "%d: unexpected ascenderOffset %.2f\n", i, offsets[1].ascenderOffset); + ok(offsets[2].ascenderOffset == 31.0f, "%d: unexpected ascenderOffset %.2f\n", i, offsets[2].ascenderOffset); + } + else { + /* with aliased advances original values are retained */ + ok(ptr->advances[0] == advances[0], "%d: got advance[0] %.2f, expected %.2f\n", i, advances[0], ptr->advances[0]); + ok(ptr->advances[1] == advances[1], "%d: got advance[1] %.2f, expected %.2f\n", i, advances[1], ptr->advances[1]); + ok(ptr->offsets[0] == offsets[0].advanceOffset, "%d: got offset[0] %.2f, expected %.2f\n", i, + offsets[0].advanceOffset, ptr->modified_offsets[0]); + ok(ptr->offsets[1] == offsets[1].advanceOffset, "%d: got offset[1] %.2f, expected %.2f\n", i, + offsets[1].advanceOffset, ptr->modified_offsets[1]); + ok(offsets[0].ascenderOffset == 23.0f, "%d: unexpected ascenderOffset %.2f\n", i, offsets[0].ascenderOffset); + ok(offsets[1].ascenderOffset == 32.0f, "%d: unexpected ascenderOffset %.2f\n", i, offsets[1].ascenderOffset); + } } IDWriteTextAnalyzer1_Release(analyzer1);