Nikolay Sivov : dwrite/tests: Add some tests for CreateFontCollectionFromFontSet().
Alexandre Julliard
julliard at winehq.org
Mon Mar 29 16:00:03 CDT 2021
Module: wine
Branch: master
Commit: ff983fe75fde1b9e17f7e46269dc04b8b02305a1
URL: https://source.winehq.org/git/wine.git/?a=commit;h=ff983fe75fde1b9e17f7e46269dc04b8b02305a1
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Mon Mar 29 10:15:17 2021 +0300
dwrite/tests: Add some tests for CreateFontCollectionFromFontSet().
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/dwrite/tests/font.c | 117 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 113 insertions(+), 4 deletions(-)
diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c
index 27c2a9d0b7d..54e279ea11e 100644
--- a/dlls/dwrite/tests/font.c
+++ b/dlls/dwrite/tests/font.c
@@ -587,6 +587,20 @@ static BOOL has_face_variations(IDWriteFontFace *fontface)
return ret;
}
+#define check_familymodel(a,b) _check_familymodel(a,b,__LINE__)
+static void _check_familymodel(void *iface_ptr, DWRITE_FONT_FAMILY_MODEL expected_model, unsigned int line)
+{
+ IDWriteFontCollection2 *collection;
+ DWRITE_FONT_FAMILY_MODEL model;
+
+ if (SUCCEEDED(IUnknown_QueryInterface((IUnknown *)iface_ptr, &IID_IDWriteFontCollection2, (void **)&collection)))
+ {
+ model = IDWriteFontCollection2_GetFontFamilyModel(collection);
+ ok_(__FILE__,line)(model == expected_model, "Unexpected family model %d, expected %d.\n", model, expected_model);
+ IDWriteFontCollection2_Release(collection);
+ }
+}
+
struct test_fontenumerator
{
IDWriteFontFileEnumerator IDWriteFontFileEnumerator_iface;
@@ -2441,7 +2455,6 @@ static void test_system_fontcollection(void)
IDWriteFontCollection2 *collection2;
IDWriteFontCollection3 *collection3;
IDWriteFactory *factory, *factory2;
- DWRITE_FONT_FAMILY_MODEL model;
IDWriteFontFileLoader *loader;
IDWriteFontFamily *family;
IDWriteFontFace *fontface;
@@ -2621,8 +2634,7 @@ static void test_system_fontcollection(void)
todo_wine
ok(!!event, "Expected event handle.\n");
- model = IDWriteFontCollection3_GetFontFamilyModel(collection3);
- ok(model == DWRITE_FONT_FAMILY_MODEL_WEIGHT_STRETCH_STYLE, "Unexpected model.\n");
+ check_familymodel(collection3, DWRITE_FONT_FAMILY_MODEL_WEIGHT_STRETCH_STYLE);
IDWriteFontCollection3_Release(collection3);
}
@@ -9423,8 +9435,8 @@ static void test_AnalyzeContainerType(void)
static void test_fontsetbuilder(void)
{
IDWriteFontFaceReference *ref, *ref2, *ref3;
- IDWriteFontFaceReference1 *ref1;
IDWriteFontCollection1 *collection;
+ IDWriteFontFaceReference1 *ref1;
IDWriteFontSetBuilder1 *builder1;
IDWriteFontSetBuilder *builder;
DWRITE_FONT_AXIS_VALUE axis_values[4];
@@ -9457,12 +9469,36 @@ static void test_fontsetbuilder(void)
hr = IDWriteFontSetBuilder1_AddFontFile(builder1, file);
ok(hr == S_OK, "Unexpected hr %#x.\n",hr);
+ hr = IDWriteFontSetBuilder1_CreateFontSet(builder1, &fontset);
+ ok(hr == S_OK, "Unexpected hr %#x.\n",hr);
+ hr = IDWriteFactory3_CreateFontCollectionFromFontSet(factory, fontset, &collection);
+ todo_wine
+ ok(hr == S_OK, "Unexpected hr %#x.\n",hr);
+ if (SUCCEEDED(hr))
+ {
+ count = IDWriteFontCollection1_GetFontFamilyCount(collection);
+ ok(count == 1, "Unexpected family count %u.\n", count);
+ IDWriteFontCollection1_Release(collection);
+ }
+ IDWriteFontSet_Release(fontset);
+
hr = IDWriteFontSetBuilder1_AddFontFile(builder1, file);
ok(hr == S_OK, "Unexpected hr %#x.\n",hr);
hr = IDWriteFontSetBuilder1_CreateFontSet(builder1, &fontset);
ok(hr == S_OK, "Unexpected hr %#x.\n",hr);
+ hr = IDWriteFactory3_CreateFontCollectionFromFontSet(factory, fontset, &collection);
+ todo_wine
+ ok(hr == S_OK, "Unexpected hr %#x.\n",hr);
+ if (SUCCEEDED(hr))
+ {
+ check_familymodel(collection, DWRITE_FONT_FAMILY_MODEL_WEIGHT_STRETCH_STYLE);
+ count = IDWriteFontCollection1_GetFontFamilyCount(collection);
+ ok(count == 1, "Unexpected family count %u.\n", count);
+ IDWriteFontCollection1_Release(collection);
+ }
+
/* No attempt to eliminate duplicates. */
count = IDWriteFontSet_GetFontCount(fontset);
ok(count == 2, "Unexpected font count %u.\n", count);
@@ -10139,6 +10175,78 @@ static void test_system_font_set(void)
IDWriteFactory3_Release(factory);
}
+static void test_CreateFontCollectionFromFontSet(void)
+{
+ unsigned int index, count, refcount;
+ IDWriteFontCollection1 *collection;
+ IDWriteFontSetBuilder1 *builder;
+ DWRITE_FONT_PROPERTY props[1];
+ IDWriteFontFaceReference *ref;
+ IDWriteFactory5 *factory;
+ IDWriteFontSet *fontset;
+ IDWriteFontFile *file;
+ WCHAR *path;
+ BOOL exists;
+ HRESULT hr;
+
+ if (!(factory = create_factory_iid(&IID_IDWriteFactory5)))
+ {
+ win_skip("_CreateFontCollectionFromFontSet() is not available.\n");
+ return;
+ }
+
+ hr = IDWriteFactory5_CreateFontSetBuilder(factory, &builder);
+ ok(hr == S_OK, "Failed to create font set builder, hr %#x.\n", hr);
+
+ path = create_testfontfile(test_fontfile);
+
+ hr = IDWriteFactory5_CreateFontFileReference(factory, path, NULL, &file);
+ ok(hr == S_OK, "Unexpected hr %#x.\n",hr);
+
+ hr = IDWriteFontSetBuilder1_AddFontFile(builder, file);
+ ok(hr == S_OK, "Unexpected hr %#x.\n",hr);
+
+ /* Add same file, with explicit properties. */
+ hr = IDWriteFactory5_CreateFontFaceReference_(factory, file, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref);
+ ok(hr == S_OK, "Unexpected hr %#x.\n",hr);
+ props[0].propertyId = DWRITE_FONT_PROPERTY_ID_WEIGHT_STRETCH_STYLE_FAMILY_NAME;
+ props[0].propertyValue = L"Another Font";
+ props[0].localeName = L"en-US";
+ hr = IDWriteFontSetBuilder1_AddFontFaceReference_(builder, ref, props, 1);
+todo_wine
+ ok(hr == S_OK, "Unexpected hr %#x.\n",hr);
+ IDWriteFontFaceReference_Release(ref);
+
+ hr = IDWriteFontSetBuilder1_CreateFontSet(builder, &fontset);
+ ok(hr == S_OK, "Unexpected hr %#x.\n",hr);
+
+ hr = IDWriteFactory5_CreateFontCollectionFromFontSet(factory, fontset, &collection);
+todo_wine
+ ok(hr == S_OK, "Unexpected hr %#x.\n",hr);
+
+if (SUCCEEDED(hr))
+{
+ count = IDWriteFontCollection1_GetFontFamilyCount(collection);
+ ok(count == 2, "Unexpected family count %u.\n", count);
+
+ /* Explicit fontset properties are prioritized and not replaced by actual properties from a file. */
+ exists = FALSE;
+ hr = IDWriteFontCollection1_FindFamilyName(collection, L"Another Font", &index, &exists);
+ ok(hr == S_OK, "Unexpected hr %#x.\n",hr);
+ ok(!!exists, "Unexpected return value %d.\n", exists);
+
+ IDWriteFontCollection1_Release(collection);
+}
+ IDWriteFontSet_Release(fontset);
+
+ IDWriteFontSetBuilder1_Release(builder);
+
+ IDWriteFontFile_Release(file);
+ refcount = IDWriteFactory5_Release(factory);
+ ok(!refcount, "Unexpected factory refcount %u.\n", refcount);
+ DELETE_FONTFILE(path);
+}
+
START_TEST(font)
{
IDWriteFactory *factory;
@@ -10212,6 +10320,7 @@ START_TEST(font)
test_expiration_event();
test_family_font_set();
test_system_font_set();
+ test_CreateFontCollectionFromFontSet();
IDWriteFactory_Release(factory);
}
More information about the wine-cvs
mailing list