wine-staging/patches/dwrite-FontFallback/0002-dwrite-Test-GetMetrics-with-custom-fontcollection.patch

324 lines
14 KiB
Diff
Raw Normal View History

2018-07-28 01:13:02 -07:00
From 22fd0a86b6be3d2e203beee7a0b55f717f32436b Mon Sep 17 00:00:00 2001
From: Lucian Poston <lucianposton@pm.me>
Date: Wed, 23 May 2018 00:01:42 -0700
Subject: [PATCH 2/6] dwrite: Test GetMetrics with custom fontcollection
Signed-off-by: Lucian Poston <lucianposton@pm.me>
---
dlls/dwrite/tests/layout.c | 278 +++++++++++++++++++++++++++++++++++++
1 file changed, 278 insertions(+)
diff --git a/dlls/dwrite/tests/layout.c b/dlls/dwrite/tests/layout.c
index 4198b8a1b1..7542cad8d7 100644
--- a/dlls/dwrite/tests/layout.c
+++ b/dlls/dwrite/tests/layout.c
@@ -4489,6 +4489,7 @@ static void test_SetWordWrapping(void)
/* Collection dedicated to fallback testing */
static const WCHAR g_blahfontW[] = {'B','l','a','h',0};
+static const WCHAR g_fontNotInCollectionW[] = {'n','o','t','B','l','a','h',0};
static HRESULT WINAPI fontcollection_QI(IDWriteFontCollection *iface, REFIID riid, void **obj)
{
if (IsEqualIID(riid, &IID_IDWriteFontCollection) || IsEqualIID(riid, &IID_IUnknown)) {
@@ -4548,6 +4549,9 @@ static HRESULT WINAPI fontcollection_FindFamilyName(IDWriteFontCollection *iface
*index = 123456;
*exists = TRUE;
return S_OK;
+ } else if (!lstrcmpW(name, g_fontNotInCollectionW)) {
+ *exists = FALSE;
+ return S_OK;
}
ok(0, "unexpected call, name %s\n", wine_dbgstr_w(name));
return E_NOTIMPL;
@@ -5568,6 +5572,279 @@ static void test_GetOverhangMetrics(void)
IDWriteFactory_Release(factory);
}
+static void test_GetMetrics_with_custom_fontcollection(void)
+{
+ static const WCHAR emptystringW[] = {0};
+ static const WCHAR mappedW[] = {'a','b','c','d',0};
+ static const WCHAR notmappedW[] = {'a',0xffff,'b',0}; // u+ffff = not a unicode character
+ DWRITE_CLUSTER_METRICS clusters[4];
+ DWRITE_TEXT_METRICS metrics;
+ IDWriteTextFormat *format;
+ IDWriteTextLayout *layout;
+ IDWriteFactory *factory;
+ UINT32 count, i;
+ FLOAT width;
+ HRESULT hr;
+
+ factory = create_factory();
+
+ /* font is in font collection */
+ hr = IDWriteFactory_CreateTextFormat(factory, g_blahfontW, &fallbackcollection,
+ DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
+ DWRITE_FONT_STRETCH_NORMAL, 10.0, enusW, &format);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ /* text is mapped by fontfallback */
+ hr = IDWriteFactory_CreateTextLayout(factory, mappedW, 4, format, 1000.0, 1000.0, &layout);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ count = 9999;
+ hr = IDWriteTextLayout_GetClusterMetrics(layout, clusters, 4, &count);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(count == 4, "got %u\n", count);
+ for (i = 0, width = 0.0; i < count; i++)
+ width += clusters[i].width;
+ memset(&metrics, 0xcc, sizeof(metrics));
+ hr = IDWriteTextLayout_GetMetrics(layout, &metrics);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(metrics.left == 0.0, "got %.2f\n", metrics.left);
+ ok(metrics.top == 0.0, "got %.2f\n", metrics.top);
+ ok(metrics.width == width, "got %.2f, expected %.2f\n", metrics.width, width);
+ ok(metrics.widthIncludingTrailingWhitespace == width, "got %.2f, expected %.2f\n",
+ metrics.widthIncludingTrailingWhitespace, width);
+ ok(metrics.height > 0.0, "got %.2f\n", metrics.height);
+ ok(metrics.layoutWidth == 1000.0, "got %.2f\n", metrics.layoutWidth);
+ ok(metrics.layoutHeight == 1000.0, "got %.2f\n", metrics.layoutHeight);
+ ok(metrics.maxBidiReorderingDepth == 1, "got %u\n", metrics.maxBidiReorderingDepth);
+ ok(metrics.lineCount == 1, "got %u\n", metrics.lineCount);
+ IDWriteTextLayout_Release(layout);
+
+ /* text is not mapped by fontfallback */
+ hr = IDWriteFactory_CreateTextLayout(factory, notmappedW, 4, format, 1000.0, 1000.0, &layout);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ count = 9999;
+ hr = IDWriteTextLayout_GetClusterMetrics(layout, clusters, 4, &count);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(count == 4, "got %u\n", count);
+ for (i = 0, width = 0.0; i < count; i++)
+ width += clusters[i].width;
+ memset(&metrics, 0xcc, sizeof(metrics));
+ hr = IDWriteTextLayout_GetMetrics(layout, &metrics);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(metrics.left == 0.0, "got %.2f\n", metrics.left);
+ ok(metrics.top == 0.0, "got %.2f\n", metrics.top);
+ ok(metrics.width == width, "got %.2f, expected %.2f\n", metrics.width, width);
+ ok(metrics.widthIncludingTrailingWhitespace == width, "got %.2f, expected %.2f\n",
+ metrics.widthIncludingTrailingWhitespace, width);
+ ok(metrics.height > 0.0, "got %.2f\n", metrics.height);
+ ok(metrics.layoutWidth == 1000.0, "got %.2f\n", metrics.layoutWidth);
+ ok(metrics.layoutHeight == 1000.0, "got %.2f\n", metrics.layoutHeight);
+ ok(metrics.maxBidiReorderingDepth == 1, "got %u\n", metrics.maxBidiReorderingDepth);
+ ok(metrics.lineCount == 1, "got %u\n", metrics.lineCount);
+ IDWriteTextLayout_Release(layout);
+
+ /* empty string */
+ hr = IDWriteFactory_CreateTextLayout(factory, emptystringW, 4, format, 1000.0, 1000.0, &layout);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ count = 9999;
+ hr = IDWriteTextLayout_GetClusterMetrics(layout, clusters, 4, &count);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(count == 4, "got %u\n", count);
+ for (i = 0, width = 0.0; i < count; i++)
+ width += clusters[i].width;
+ memset(&metrics, 0xcc, sizeof(metrics));
+ hr = IDWriteTextLayout_GetMetrics(layout, &metrics);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(metrics.left == 0.0, "got %.2f\n", metrics.left);
+ ok(metrics.top == 0.0, "got %.2f\n", metrics.top);
+ ok(metrics.width == width, "got %.2f, expected %.2f\n", metrics.width, width);
+ ok(metrics.widthIncludingTrailingWhitespace == width, "got %.2f, expected %.2f\n",
+ metrics.widthIncludingTrailingWhitespace, width);
+ ok(metrics.height > 0.0, "got %.2f\n", metrics.height);
+ ok(metrics.layoutWidth == 1000.0, "got %.2f\n", metrics.layoutWidth);
+ ok(metrics.layoutHeight == 1000.0, "got %.2f\n", metrics.layoutHeight);
+ ok(metrics.maxBidiReorderingDepth == 1, "got %u\n", metrics.maxBidiReorderingDepth);
+ ok(metrics.lineCount == 1, "got %u\n", metrics.lineCount);
+ IDWriteTextLayout_Release(layout);
+
+ /* zero-length empty string */
+ hr = IDWriteFactory_CreateTextLayout(factory, emptystringW, 0, format, 1000.0, 1000.0, &layout);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ count = 9999;
+ hr = IDWriteTextLayout_GetClusterMetrics(layout, clusters, 4, &count);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(count == 0, "got %u\n", count);
+ for (i = 0, width = 0.0; i < count; i++)
+ width += clusters[i].width;
+ memset(&metrics, 0xcc, sizeof(metrics));
+ hr = IDWriteTextLayout_GetMetrics(layout, &metrics);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(metrics.left == 0.0, "got %.2f\n", metrics.left);
+ ok(metrics.top == 0.0, "got %.2f\n", metrics.top);
+ ok(metrics.width == width, "got %.2f, expected %.2f\n", metrics.width, width);
+ ok(metrics.widthIncludingTrailingWhitespace == width, "got %.2f, expected %.2f\n",
+ metrics.widthIncludingTrailingWhitespace, width);
+ ok(metrics.height > 0.0, "got %.2f\n", metrics.height);
+ ok(metrics.layoutWidth == 1000.0, "got %.2f\n", metrics.layoutWidth);
+ ok(metrics.layoutHeight == 1000.0, "got %.2f\n", metrics.layoutHeight);
+ ok(metrics.maxBidiReorderingDepth == 1, "got %u\n", metrics.maxBidiReorderingDepth);
+ ok(metrics.lineCount == 1, "got %u\n", metrics.lineCount);
+ IDWriteTextLayout_Release(layout);
+
+ IDWriteTextFormat_Release(format);
+
+ /* font not in font collection */
+ hr = IDWriteFactory_CreateTextFormat(factory, g_fontNotInCollectionW, &fallbackcollection,
+ DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
+ DWRITE_FONT_STRETCH_NORMAL, 10.0, enusW, &format);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ /* text is mapped by fontfallback */
+ hr = IDWriteFactory_CreateTextLayout(factory, mappedW, 4, format, 1000.0, 1000.0, &layout);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ count = 9999;
+ hr = IDWriteTextLayout_GetClusterMetrics(layout, clusters, 4, &count);
+ todo_wine
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ todo_wine
+ ok(count == 4, "got %u\n", count);
+ for (i = 0, width = 0.0; i < count; i++)
+ 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);
+ IDWriteTextLayout_Release(layout);
+
+ /* text is not mapped by fontfallback */
+ hr = IDWriteFactory_CreateTextLayout(factory, notmappedW, 4, format, 1000.0, 1000.0, &layout);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ count = 9999;
+ hr = IDWriteTextLayout_GetClusterMetrics(layout, clusters, 4, &count);
+ todo_wine
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ todo_wine
+ ok(count == 4, "got %u\n", count);
+ for (i = 0, width = 0.0; i < count; i++)
+ 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);
+ IDWriteTextLayout_Release(layout);
+
+ /* empty string */
+ hr = IDWriteFactory_CreateTextLayout(factory, emptystringW, 4, format, 1000.0, 1000.0, &layout);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ count = 9999;
+ hr = IDWriteTextLayout_GetClusterMetrics(layout, clusters, 4, &count);
+ todo_wine
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ todo_wine
+ ok(count == 4, "got %u\n", count);
+ for (i = 0, width = 0.0; i < count; i++)
+ 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);
+ IDWriteTextLayout_Release(layout);
+
+ /* zero-length empty string */
+ hr = IDWriteFactory_CreateTextLayout(factory, emptystringW, 0, format, 1000.0, 1000.0, &layout);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ count = 9999;
+ hr = IDWriteTextLayout_GetClusterMetrics(layout, clusters, 4, &count);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(count == 0, "got %u\n", count);
+ for (i = 0, width = 0.0; i < count; i++)
+ 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);
+ IDWriteTextLayout_Release(layout);
+
+ IDWriteTextFormat_Release(format);
+
+ IDWriteFactory_Release(factory);
+}
+
START_TEST(layout)
{
IDWriteFactory *factory;
@@ -5601,6 +5878,7 @@ START_TEST(layout)
test_SetFontStretch();
test_SetStrikethrough();
test_GetMetrics();
+ test_GetMetrics_with_custom_fontcollection();
test_SetFlowDirection();
test_SetDrawingEffect();
test_GetLineMetrics();
--
2.18.0