dwrite/layout: Fix layout metrics width for whitespace-only lines.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2019-05-13 14:21:45 +03:00 committed by Alexandre Julliard
parent 6dc35e2d17
commit 93a852e262
2 changed files with 23 additions and 2 deletions

View File

@ -1831,7 +1831,7 @@ static void layout_add_line(struct dwrite_textlayout *layout, UINT32 first_clust
FLOAT descent, trailingspacewidth;
BOOL append_trimming_run = FALSE;
const struct layout_run *run;
FLOAT width, origin_x;
float width = 0.0f, origin_x;
HRESULT hr;
/* Take a look at clusters we got for this line in reverse order to set trailing properties for current line */
@ -1871,7 +1871,8 @@ static void layout_add_line(struct dwrite_textlayout *layout, UINT32 first_clust
}
/* Does not include trailing space width */
width = get_cluster_range_width(layout, first_cluster, last_cluster + 1);
if (!layout->clustermetrics[last_cluster].isWhitespace)
width = get_cluster_range_width(layout, first_cluster, last_cluster + 1);
/* Append trimming run if necessary */
if (width > layout->metrics.layoutWidth && layout->format.trimmingsign != NULL &&

View File

@ -3205,6 +3205,7 @@ static void test_GetMetrics(void)
static const WCHAR str2W[] = {0x2066,')',')',0x661,'(',0x627,')',0};
static const WCHAR strW[] = {'a','b','c','d',0};
static const WCHAR str3W[] = {'a',0};
static const WCHAR str4W[] = {' ',0};
DWRITE_CLUSTER_METRICS clusters[4];
DWRITE_TEXT_METRICS metrics;
IDWriteTextFormat *format;
@ -3290,6 +3291,25 @@ todo_wine
ok(metrics.lineCount == 1, "got %u\n", metrics.lineCount);
IDWriteTextLayout_Release(layout);
/* Whitespace only. */
hr = IDWriteFactory_CreateTextLayout(factory, str4W, 1, format, 500.0, 1000.0, &layout);
ok(hr == S_OK, "Failed to create text layout, hr %#x.\n", hr);
memset(&metrics, 0xcc, sizeof(metrics));
hr = IDWriteTextLayout_GetMetrics(layout, &metrics);
ok(hr == S_OK, "Failed to get layout metrics, hr %#x.\n", hr);
ok(metrics.left == 0.0f, "Unexpected value for left %f.\n", metrics.left);
ok(metrics.top == 0.0f, "Unexpected value for top %f.\n", metrics.top);
ok(metrics.width == 0.0f, "Unexpected width %f.\n", metrics.width);
ok(metrics.widthIncludingTrailingWhitespace > 0.0f, "Unexpected full width %f.\n",
metrics.widthIncludingTrailingWhitespace);
ok(metrics.height > 0.0, "Unexpected height %f.\n", metrics.height);
ok(metrics.layoutWidth == 500.0, "Unexpected box width %f.\n", metrics.layoutWidth);
ok(metrics.layoutHeight == 1000.0, "Unexpected box height %f.\n", metrics.layoutHeight);
ok(metrics.maxBidiReorderingDepth == 1, "Unexpected reordering depth %u.\n", metrics.maxBidiReorderingDepth);
ok(metrics.lineCount == 1, "Unexpected line coun %u.\n", metrics.lineCount);
IDWriteTextLayout_Release(layout);
IDWriteTextFormat_Release(format);
IDWriteFactory_Release(factory);
}