dwrite: Fix newlineLength metric to include all newline chars at the end of the line.
authorNikolay Sivov <nsivov@codeweavers.com>
Mon, 1 Feb 2016 22:41:09 +0000 (01:41 +0300)
committerAlexandre Julliard <julliard@winehq.org>
Tue, 2 Feb 2016 05:39:11 +0000 (14:39 +0900)
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
dlls/dwrite/layout.c
dlls/dwrite/tests/layout.c

index 86eab090eb3ed552cd40a60b9820c6518fb72e5d..7345f78efbd42a6e724d8931cb775fc6822ed8eb 100644 (file)
@@ -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--;
index b2cdfc3900df8d9712e5450102d6c06f7274ccad..fe760c6d9af0693632b7c09e580d9eb13ddbd66e 100644 (file)
@@ -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 */