From a0f4bde380003f7a8e3b713028215bf985dbb3c0 Mon Sep 17 00:00:00 2001
From: Lucian Poston <lucianposton@pm.me>
Date: Wed, 23 May 2018 07:03:44 -0700
Subject: [PATCH 6/6] dwrite: Use MapCharacters for dummy line metrics

Fixes: https://bugs.winehq.org/show_bug.cgi?id=44052

Signed-off-by: Lucian Poston <lucianposton@pm.me>
---
 dlls/dwrite/layout.c       | 29 +++++++++++++++++++++++++++++
 dlls/dwrite/tests/layout.c |  8 --------
 2 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c
index 5d06bf9348..2213717f92 100644
--- a/dlls/dwrite/layout.c
+++ b/dlls/dwrite/layout.c
@@ -1808,8 +1808,11 @@ static HRESULT layout_set_dummy_line_metrics(struct dwrite_textlayout *layout, U
     DWRITE_FONT_METRICS fontmetrics;
     struct layout_range *range;
     IDWriteFontFace *fontface;
+    IDWriteFontFallback *fallback;
     IDWriteFont *font;
     HRESULT hr;
+    UINT32 mapped_length;
+    FLOAT scale;
 
     range = get_layout_range_by_pos(layout, pos);
     hr = create_matching_font(range->collection,
@@ -1818,8 +1821,34 @@ static HRESULT layout_set_dummy_line_metrics(struct dwrite_textlayout *layout, U
         range->style,
         range->stretch,
         &font);
+
+    if (FAILED(hr)) {
+        if (layout->format.fallback) {
+            fallback = layout->format.fallback;
+            IDWriteFontFallback_AddRef(fallback);
+        } else if (FAILED(hr = IDWriteFactory5_GetSystemFontFallback(layout->factory, &fallback))) {
+            WARN("Failed to get system fallback, hr %#x.\n", hr);
+            return hr;
+        }
+
+        hr = IDWriteFontFallback_MapCharacters(fallback,
+                (IDWriteTextAnalysisSource *)&layout->IDWriteTextAnalysisSource1_iface,
+                pos,
+                layout->len,
+                range->collection,
+                range->fontfamily,
+                range->weight,
+                range->style,
+                range->stretch,
+                &mapped_length,
+                &font,
+                &scale);
+        IDWriteFontFallback_Release(fallback);
+    }
     if (FAILED(hr))
         return hr;
+    if (font == NULL)
+        return S_OK;
     hr = IDWriteFont_CreateFontFace(font, &fontface);
     IDWriteFont_Release(font);
     if (FAILED(hr))
diff --git a/dlls/dwrite/tests/layout.c b/dlls/dwrite/tests/layout.c
index cf1d5d7060..6ed7b3c334 100644
--- a/dlls/dwrite/tests/layout.c
+++ b/dlls/dwrite/tests/layout.c
@@ -5767,24 +5767,16 @@ static void test_GetMetrics_with_custom_fontcollection(void)
         width += clusters[i].width;
     memset(&metrics, 0xcc, sizeof(metrics));
     hr = IDWriteTextLayout_GetMetrics(layout, &metrics);
-    todo_wine
     ok(hr == S_OK, "got 0x%08x\n", hr);
-    todo_wine
     ok(metrics.left == 0.0, "got %.2f\n", metrics.left);
-    todo_wine
     ok(metrics.top == 0.0, "got %.2f\n", metrics.top);
-    todo_wine
     ok(metrics.width == width, "got %.2f, expected %.2f\n", metrics.width, width);
-    todo_wine
     ok(metrics.widthIncludingTrailingWhitespace == width, "got %.2f, expected %.2f\n",
         metrics.widthIncludingTrailingWhitespace, width);
     todo_wine
     ok(metrics.height > 0.0, "got %.2f\n", metrics.height);
-    todo_wine
     ok(metrics.layoutWidth == 1000.0, "got %.2f\n", metrics.layoutWidth);
-    todo_wine
     ok(metrics.layoutHeight == 1000.0, "got %.2f\n", metrics.layoutHeight);
-    todo_wine
     ok(metrics.maxBidiReorderingDepth == 1, "got %u\n", metrics.maxBidiReorderingDepth);
     todo_wine
     ok(metrics.lineCount == 1, "got %u\n", metrics.lineCount);
-- 
2.18.0

