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

Alexandre Julliard julliard at winehq.org
Mon May 13 16:24:17 CDT 2019


Module: wine
Branch: master
Commit: 93a852e26227ef6ca7c52ada9d274c9acb6da3ff
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=93a852e26227ef6ca7c52ada9d274c9acb6da3ff

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Mon May 13 14:21:45 2019 +0300

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

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dwrite/layout.c       |  5 +++--
 dlls/dwrite/tests/layout.c | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c
index 3e316c2..2b62758 100644
--- a/dlls/dwrite/layout.c
+++ b/dlls/dwrite/layout.c
@@ -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 &&
diff --git a/dlls/dwrite/tests/layout.c b/dlls/dwrite/tests/layout.c
index 14b287c..8337ce7 100644
--- a/dlls/dwrite/tests/layout.c
+++ b/dlls/dwrite/tests/layout.c
@@ -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);
 }




More information about the wine-cvs mailing list