From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/tests/font.c | 60 ++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 8 deletions(-)
diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index ba93e9b2064..8cbf97a1a7e 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -3451,44 +3451,88 @@ if (face2) {
static void test_CreateFontFileReference(void) { + IDWriteFontFile *file, *file2; + IDWriteFontFileLoader *loader; + IDWriteFontFileStream *stream; + UINT32 key1_size, key2_size; + const void *key1, *key2; HRESULT hr; - IDWriteFontFile *ffile = NULL; BOOL support; DWRITE_FONT_FILE_TYPE type; DWRITE_FONT_FACE_TYPE face; UINT32 count; IDWriteFontFace *fface = NULL; IDWriteFactory *factory; + FILETIME timestamp; WCHAR *path; ULONG ref;
path = create_testfontfile(test_fontfile); factory = create_factory();
- ffile = (void*)0xdeadbeef; - hr = IDWriteFactory_CreateFontFileReference(factory, NULL, NULL, &ffile); + file = (void *)0xdeadbeef; + hr = IDWriteFactory_CreateFontFileReference(factory, NULL, NULL, &file); ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n",hr); - ok(ffile == NULL, "got %p\n", ffile); + ok(!file, "Unexpected pointer %p.\n", file);
- hr = IDWriteFactory_CreateFontFileReference(factory, path, NULL, &ffile); + hr = IDWriteFactory_CreateFontFileReference(factory, path, NULL, &file); ok(hr == S_OK, "Unexpected hr %#lx.\n",hr);
support = FALSE; type = DWRITE_FONT_FILE_TYPE_UNKNOWN; face = DWRITE_FONT_FACE_TYPE_CFF; count = 0; - hr = IDWriteFontFile_Analyze(ffile, &support, &type, &face, &count); + hr = IDWriteFontFile_Analyze(file, &support, &type, &face, &count); ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(support == TRUE, "got %i\n", support); ok(type == DWRITE_FONT_FILE_TYPE_TRUETYPE, "got %i\n", type); ok(face == DWRITE_FONT_FACE_TYPE_TRUETYPE, "got %i\n", face); ok(count == 1, "got %i\n", count);
- hr = IDWriteFactory_CreateFontFace(factory, face, 1, &ffile, 0, DWRITE_FONT_SIMULATIONS_NONE, &fface); + hr = IDWriteFactory_CreateFontFace(factory, face, 1, &file, 0, DWRITE_FONT_SIMULATIONS_NONE, &fface); ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
IDWriteFontFace_Release(fface); - IDWriteFontFile_Release(ffile); + IDWriteFontFile_Release(file); + + /* File does not have to exist, if timestamp is provided. */ + file = (void *)0xdeadbeef; + hr = IDWriteFactory_CreateFontFileReference(factory, L"[hello].ttf", NULL, &file); + todo_wine + ok(hr == DWRITE_E_FILENOTFOUND, "Unexpected hr %#lx.\n",hr); + todo_wine + ok(!file, "Unexpected pointer %p.\n", file); + if (hr == S_OK) + IDWriteFontFile_Release(file); + + memset(×tamp, 0xab, sizeof(timestamp)); + hr = IDWriteFactory_CreateFontFileReference(factory, L"[hello].ttf", ×tamp, &file); + ok(hr == S_OK, "Unexpected hr %#lx.\n",hr); + + hr = IDWriteFactory_CreateFontFileReference(factory, L"[Hello].ttf", ×tamp, &file2); + ok(hr == S_OK, "Unexpected hr %#lx.\n",hr); + ok(file != file2, "Unexpected pointer.\n"); + + hr = IDWriteFontFile_GetReferenceKey(file, &key1, &key1_size); + ok(hr == S_OK, "Failed to get ref key, hr %#lx.\n", hr); + hr = IDWriteFontFile_GetReferenceKey(file2, &key2, &key2_size); + ok(hr == S_OK, "Failed to get ref key, hr %#lx.\n", hr); + ok(key1_size == key2_size, "Unexpected key sizes %u, %u.\n", key1_size, key2_size); + if (key1_size == key2_size) + todo_wine ok(!memcmp(key1, key2, key1_size), "Expected matching keys.\n"); + + hr = IDWriteFontFile_GetLoader(file, &loader); + ok(hr == S_OK, "Unexpected hr %#lx.\n",hr); + + hr = IDWriteFontFileLoader_CreateStreamFromKey(loader, key1, key1_size, &stream); + todo_wine + ok(hr == DWRITE_E_FILENOTFOUND, "Unexpected hr %#lx.\n",hr); + + IDWriteFontFileLoader_Release(loader); + + IDWriteFontFile_Release(file2); + IDWriteFontFile_Release(file); + ref = IDWriteFactory_Release(factory); ok(ref == 0, "factory not released, %lu\n", ref);
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/font.c | 8 ++++++-- dlls/dwrite/tests/font.c | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index a37600299cd..ffe2981432e 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -5751,11 +5751,14 @@ IDWriteFontFileLoader *get_local_fontfile_loader(void) HRESULT get_local_refkey(const WCHAR *path, const FILETIME *writetime, void **key, UINT32 *size) { struct local_refkey *refkey; + size_t len;
if (!path) return E_INVALIDARG;
- *size = FIELD_OFFSET(struct local_refkey, name) + (wcslen(path)+1)*sizeof(WCHAR); + len = wcslen(path) + 1; + + *size = FIELD_OFFSET(struct local_refkey, name) + len * sizeof(WCHAR); *key = NULL;
if (!(refkey = malloc(*size))) @@ -5771,7 +5774,8 @@ HRESULT get_local_refkey(const WCHAR *path, const FILETIME *writetime, void **ke else memset(&refkey->writetime, 0, sizeof(refkey->writetime)); } - wcscpy(refkey->name, path); + memcpy(refkey->name, path, len * sizeof(WCHAR)); + wcsupr(refkey->name);
*key = refkey;
diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index 8cbf97a1a7e..faffd32a7ae 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -3519,7 +3519,7 @@ static void test_CreateFontFileReference(void) ok(hr == S_OK, "Failed to get ref key, hr %#lx.\n", hr); ok(key1_size == key2_size, "Unexpected key sizes %u, %u.\n", key1_size, key2_size); if (key1_size == key2_size) - todo_wine ok(!memcmp(key1, key2, key1_size), "Expected matching keys.\n"); + ok(!memcmp(key1, key2, key1_size), "Expected matching keys.\n");
hr = IDWriteFontFile_GetLoader(file, &loader); ok(hr == S_OK, "Unexpected hr %#lx.\n",hr);
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/font.c | 20 ++++++++++---------- dlls/dwrite/tests/font.c | 7 ------- 2 files changed, 10 insertions(+), 17 deletions(-)
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index ffe2981432e..b0f72010e31 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -5750,12 +5750,21 @@ IDWriteFontFileLoader *get_local_fontfile_loader(void)
HRESULT get_local_refkey(const WCHAR *path, const FILETIME *writetime, void **key, UINT32 *size) { + WIN32_FILE_ATTRIBUTE_DATA info; struct local_refkey *refkey; size_t len;
if (!path) return E_INVALIDARG;
+ if (!writetime) + { + if (!GetFileAttributesExW(path, GetFileExInfoStandard, &info)) + return DWRITE_E_FILENOTFOUND; + + writetime = &info.ftLastWriteTime; + } + len = wcslen(path) + 1;
*size = FIELD_OFFSET(struct local_refkey, name) + len * sizeof(WCHAR); @@ -5764,16 +5773,7 @@ HRESULT get_local_refkey(const WCHAR *path, const FILETIME *writetime, void **ke if (!(refkey = malloc(*size))) return E_OUTOFMEMORY;
- if (writetime) - refkey->writetime = *writetime; - else { - WIN32_FILE_ATTRIBUTE_DATA info; - - if (GetFileAttributesExW(path, GetFileExInfoStandard, &info)) - refkey->writetime = info.ftLastWriteTime; - else - memset(&refkey->writetime, 0, sizeof(refkey->writetime)); - } + refkey->writetime = *writetime; memcpy(refkey->name, path, len * sizeof(WCHAR)); wcsupr(refkey->name);
diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index faffd32a7ae..3a670558fb2 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -3498,12 +3498,8 @@ static void test_CreateFontFileReference(void) /* File does not have to exist, if timestamp is provided. */ file = (void *)0xdeadbeef; hr = IDWriteFactory_CreateFontFileReference(factory, L"[hello].ttf", NULL, &file); - todo_wine ok(hr == DWRITE_E_FILENOTFOUND, "Unexpected hr %#lx.\n",hr); - todo_wine ok(!file, "Unexpected pointer %p.\n", file); - if (hr == S_OK) - IDWriteFontFile_Release(file);
memset(×tamp, 0xab, sizeof(timestamp)); hr = IDWriteFactory_CreateFontFileReference(factory, L"[hello].ttf", ×tamp, &file); @@ -8196,10 +8192,7 @@ static void test_CreateFontFaceReference(void)
/* path however has to be valid */ hr = IDWriteFactory3_CreateFontFaceReference(factory, L"dummy", NULL, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref); - todo_wine ok(hr == DWRITE_E_FILENOTFOUND, "Unexpected hr %#lx.\n", hr); - if (hr == S_OK) - IDWriteFontFaceReference_Release(ref);
EXPECT_REF(factory, 1); hr = IDWriteFactory3_CreateFontFaceReference(factory, path, NULL, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref);
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/tests/font.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index 3a670558fb2..a39d8a36413 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -8153,6 +8153,7 @@ static void test_CreateFontFaceReference(void) IDWriteFontFile *file, *file1; IDWriteFactory3 *factory; IDWriteFont3 *font3; + FILETIME timestamp; ULONG refcount; WCHAR *path; HRESULT hr; @@ -8194,6 +8195,11 @@ static void test_CreateFontFaceReference(void) hr = IDWriteFactory3_CreateFontFaceReference(factory, L"dummy", NULL, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref); ok(hr == DWRITE_E_FILENOTFOUND, "Unexpected hr %#lx.\n", hr);
+ memset(×tamp, 0, sizeof(timestamp)); + hr = IDWriteFactory3_CreateFontFaceReference(factory, L"dummy", ×tamp, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + IDWriteFontFaceReference_Release(ref); + EXPECT_REF(factory, 1); hr = IDWriteFactory3_CreateFontFaceReference(factory, path, NULL, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref); ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);