Nikolay Sivov : dwrite: Fix newlineLength metric to include all newline chars at the end of the line.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Feb 2 09:59:29 CST 2016


Module: wine
Branch: master
Commit: f84eaad8dcbab78ed94b1e5a2516ae2e5fe23b02
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f84eaad8dcbab78ed94b1e5a2516ae2e5fe23b02

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Tue Feb  2 01:41:09 2016 +0300

dwrite: Fix newlineLength metric to include all newline chars at the end of the line.

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

---

 dlls/dwrite/layout.c       | 19 +++++++++++--------
 dlls/dwrite/tests/layout.c | 20 +++++++++++++++-----
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c
index 86eab09..7345f78 100644
--- a/dlls/dwrite/layout.c
+++ b/dlls/dwrite/layout.c
@@ -1654,19 +1654,22 @@ static HRESULT layout_compute_effective_runs(struct dwrite_textlayout *layout)
             trailingspacewidth = 0.0f;
             while (strlength) {
                 DWRITE_CLUSTER_METRICS *cluster = &layout->clustermetrics[index];
+                struct layout_cluster *lc = &layout->clusters[index];
+                WCHAR ch;
 
-                if (!cluster->isNewline && !cluster->isWhitespace)
+                /* This also filters out clusters added from inline objects, those are never
+                   treated as a white space. */
+                if (!cluster->isWhitespace)
                     break;
 
-                if (cluster->isNewline) {
-                    metrics.trailingWhitespaceLength += cluster->length;
+                /* Every isNewline cluster is also isWhitespace, but not every
+                   newline character cluster has isNewline set, so go back to original string. */
+                ch = lc->run->u.regular.descr.string[lc->position];
+                if (cluster->length == 1 && lb_is_newline_char(ch))
                     metrics.newlineLength += cluster->length;
-                }
 
-                if (cluster->isWhitespace) {
-                    metrics.trailingWhitespaceLength += cluster->length;
-                    trailingspacewidth += cluster->width;
-                }
+                metrics.trailingWhitespaceLength += cluster->length;
+                trailingspacewidth += cluster->width;
 
                 strlength -= cluster->length;
                 index--;
diff --git a/dlls/dwrite/tests/layout.c b/dlls/dwrite/tests/layout.c
index b2cdfc3..fe760c6 100644
--- a/dlls/dwrite/tests/layout.c
+++ b/dlls/dwrite/tests/layout.c
@@ -2030,6 +2030,7 @@ todo_wine
                 todo_wine ok(metrics[i].width == 0.0f, "%u: got width %f\n", i, metrics[i].width);
             else
                 ok(metrics[i].width == 0.0f, "%u: got width %f\n", i, metrics[i].width);
+            ok(metrics[i].isWhitespace == 1, "%u: got %d\n", i, metrics[i].isWhitespace);
             ok(metrics[i].canWrapLineAfter == 1, "%u: got %d\n", i, metrics[i].canWrapLineAfter);
         }
     }
@@ -3341,8 +3342,8 @@ static void test_GetLineMetrics(void)
     ok(hr == S_OK, "got 0x%08x\n", hr);
 
     memset(metrics, 0, sizeof(metrics));
-    count = 2;
-    hr = IDWriteTextLayout_GetLineMetrics(layout, metrics, 2, &count);
+    count = 0;
+    hr = IDWriteTextLayout_GetLineMetrics(layout, metrics, sizeof(metrics)/sizeof(*metrics), &count);
     ok(hr == S_OK, "got 0x%08x\n", hr);
     ok(count == 2, "got %u\n", count);
     /* baseline is relative to a line, and is not accumulated */
@@ -3361,7 +3362,8 @@ static void test_GetLineMetrics(void)
     ok(hr == S_OK, "got 0x%08x\n", hr);
 
     memset(metrics, 0xcc, sizeof(metrics));
-    hr = IDWriteTextLayout_GetLineMetrics(layout, metrics, 6, &count);
+    count = 0;
+    hr = IDWriteTextLayout_GetLineMetrics(layout, metrics, sizeof(metrics)/sizeof(*metrics), &count);
     ok(hr == S_OK, "got 0x%08x\n", hr);
 todo_wine
     ok(count == 6, "got %u\n", count);
@@ -3378,10 +3380,18 @@ todo_wine
     ok(metrics[1].newlineLength == 1, "got %u\n", metrics[1].newlineLength);
     ok(metrics[2].newlineLength == 1, "got %u\n", metrics[2].newlineLength);
     ok(metrics[3].newlineLength == 1, "got %u\n", metrics[3].newlineLength);
-todo_wine {
     ok(metrics[4].newlineLength == 2, "got %u\n", metrics[4].newlineLength);
+todo_wine
     ok(metrics[5].newlineLength == 0, "got %u\n", metrics[5].newlineLength);
-}
+
+    ok(metrics[0].trailingWhitespaceLength == 1, "got %u\n", metrics[0].newlineLength);
+    ok(metrics[1].trailingWhitespaceLength == 1, "got %u\n", metrics[1].newlineLength);
+    ok(metrics[2].trailingWhitespaceLength == 1, "got %u\n", metrics[2].newlineLength);
+    ok(metrics[3].trailingWhitespaceLength == 1, "got %u\n", metrics[3].newlineLength);
+    ok(metrics[4].trailingWhitespaceLength == 2, "got %u\n", metrics[4].newlineLength);
+todo_wine
+    ok(metrics[5].trailingWhitespaceLength == 0, "got %u\n", metrics[5].newlineLength);
+
     IDWriteTextLayout_Release(layout);
 
     /* empty text layout */




More information about the wine-cvs mailing list