dwrite: Implement AnalyzeContainerType(). Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h index 38cf11a..6c3088b 100644 --- a/dlls/dwrite/dwrite_private.h +++ b/dlls/dwrite/dwrite_private.h
@@ -243,6 +243,7 @@ extern HRESULT opentype_get_cpal_entries(const void*,UINT32,UINT32,UINT32,DWRITE_COLOR_F*) DECLSPEC_HIDDEN; extern BOOL opentype_has_vertical_variants(IDWriteFontFace4*) DECLSPEC_HIDDEN; extern UINT32 opentype_get_glyph_image_formats(IDWriteFontFace4*) DECLSPEC_HIDDEN; +extern DWRITE_CONTAINER_TYPE opentype_analyze_container_type(void const *, UINT32) DECLSPEC_HIDDEN; struct dwrite_colorglyph { USHORT layer; /* [0, num_layers) index indicating current layer */
diff --git a/dlls/dwrite/main.c b/dlls/dwrite/main.c index 1cdcc7e..7237a0e 100644 --- a/dlls/dwrite/main.c +++ b/dlls/dwrite/main.c
@@ -1636,9 +1636,9 @@ { struct dwritefactory *This = impl_from_IDWriteFactory5(iface); - FIXME("(%p)->(%p %u): stub\n", This, data, data_size); + TRACE("(%p)->(%p %u)\n", This, data, data_size); - return DWRITE_CONTAINER_TYPE_UNKNOWN; + return opentype_analyze_container_type(data, data_size); } static HRESULT WINAPI dwritefactory5_UnpackFontFile(IDWriteFactory5 *iface, DWRITE_CONTAINER_TYPE container_type, void const *data,
diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c index 36c34b6..bb6f274 100644 --- a/dlls/dwrite/opentype.c +++ b/dlls/dwrite/opentype.c
@@ -47,6 +47,9 @@ #define MS_JPG__TAG DWRITE_MAKE_OPENTYPE_TAG('j','p','g',' ') #define MS_TIFF_TAG DWRITE_MAKE_OPENTYPE_TAG('t','i','f','f') +#define MS_WOFF_TAG DWRITE_MAKE_OPENTYPE_TAG('w','O','F','F') +#define MS_WOF2_TAG DWRITE_MAKE_OPENTYPE_TAG('w','O','F','2') + #ifdef WORDS_BIGENDIAN #define GET_BE_WORD(x) (x) #define GET_BE_DWORD(x) (x) @@ -2167,3 +2170,24 @@ /* TODO: handle embedded bitmaps tables */ return ret; } + +DWRITE_CONTAINER_TYPE opentype_analyze_container_type(void const *data, UINT32 data_size) +{ + DWORD signature; + + if (data_size < sizeof(DWORD)) + return DWRITE_CONTAINER_TYPE_UNKNOWN; + + /* Both WOFF and WOFF2 start with 4 bytes signature. */ + signature = *(DWORD *)data; + + switch (signature) + { + case MS_WOFF_TAG: + return DWRITE_CONTAINER_TYPE_WOFF; + case MS_WOF2_TAG: + return DWRITE_CONTAINER_TYPE_WOFF2; + default: + return DWRITE_CONTAINER_TYPE_UNKNOWN; + } +}
diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index e97c4d1..c579d94 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c
@@ -54,12 +54,19 @@ #define MS_JPG__TAG DWRITE_MAKE_OPENTYPE_TAG('j','p','g',' ') #define MS_TIFF_TAG DWRITE_MAKE_OPENTYPE_TAG('t','i','f','f') +#define MS_WOFF_TAG DWRITE_MAKE_OPENTYPE_TAG('w','O','F','F') +#define MS_WOF2_TAG DWRITE_MAKE_OPENTYPE_TAG('w','O','F','2') + #ifdef WORDS_BIGENDIAN #define GET_BE_WORD(x) (x) #define GET_BE_DWORD(x) (x) +#define GET_LE_WORD(x) RtlUshortByteSwap(x) +#define GET_LE_DWORD(x) RtlUlongByteSwap(x) #else #define GET_BE_WORD(x) RtlUshortByteSwap(x) #define GET_BE_DWORD(x) RtlUlongByteSwap(x) +#define GET_LE_WORD(x) (x) +#define GET_LE_DWORD(x) (x) #endif #define EXPECT_HR(hr,hr_exp) \ @@ -334,13 +341,54 @@ WORD numGlyphs; } maxp; +struct WOFFHeader +{ + ULONG signature; + ULONG flavor; + ULONG length; + USHORT numTables; + USHORT reserved; + ULONG totalSfntSize; + USHORT majorVersion; + USHORT minorVersion; + ULONG metaOffset; + ULONG metaLength; + ULONG metaOrigLength; + ULONG privOffset; + ULONG privLength; +}; + +struct WOFFHeader2 +{ + ULONG signature; + ULONG flavor; + ULONG length; + USHORT numTables; + USHORT reserved; + ULONG totalSfntSize; + ULONG totalCompressedSize; + USHORT majorVersion; + USHORT minorVersion; + ULONG metaOffset; + ULONG metaLength; + ULONG metaOrigLength; + ULONG privOffset; + ULONG privLength; +}; + #include "poppack.h" +static void *create_factory_iid(REFIID riid) +{ + IUnknown *factory = NULL; + DWriteCreateFactory(DWRITE_FACTORY_TYPE_ISOLATED, riid, &factory); + return factory; +} + static IDWriteFactory *create_factory(void) { - IDWriteFactory *factory; - HRESULT hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_ISOLATED, &IID_IDWriteFactory, (IUnknown**)&factory); - ok(hr == S_OK, "Failed to create factory, hr %#x.\n", hr); + IDWriteFactory *factory = create_factory_iid(&IID_IDWriteFactory); + ok(factory != NULL, "Failed to create factory.\n"); return factory; } @@ -4459,32 +4507,28 @@ static void test_GetEudcFontCollection(void) { IDWriteFontCollection *coll, *coll2; - IDWriteFactory1 *factory1; - IDWriteFactory *factory; + IDWriteFactory1 *factory; HRESULT hr; ULONG ref; - factory = create_factory(); - - hr = IDWriteFactory_QueryInterface(factory, &IID_IDWriteFactory1, (void**)&factory1); - IDWriteFactory_Release(factory); - if (hr != S_OK) { + factory = create_factory_iid(&IID_IDWriteFactory1); + if (!factory) { win_skip("GetEudcFontCollection() is not supported.\n"); return; } - EXPECT_REF(factory1, 1); - hr = IDWriteFactory1_GetEudcFontCollection(factory1, &coll, FALSE); + EXPECT_REF(factory, 1); + hr = IDWriteFactory1_GetEudcFontCollection(factory, &coll, FALSE); ok(hr == S_OK, "got 0x%08x\n", hr); - EXPECT_REF(factory1, 2); - hr = IDWriteFactory1_GetEudcFontCollection(factory1, &coll2, FALSE); + EXPECT_REF(factory, 2); + hr = IDWriteFactory1_GetEudcFontCollection(factory, &coll2, FALSE); ok(hr == S_OK, "got 0x%08x\n", hr); - EXPECT_REF(factory1, 2); + EXPECT_REF(factory, 2); ok(coll == coll2, "got %p, %p\n", coll, coll2); IDWriteFontCollection_Release(coll); IDWriteFontCollection_Release(coll2); - ref = IDWriteFactory1_Release(factory1); + ref = IDWriteFactory1_Release(factory); ok(ref == 0, "factory not released, %u\n", ref); } @@ -6643,8 +6687,7 @@ const DWRITE_COLOR_GLYPH_RUN *colorrun; IDWriteFontFace2 *fontface2; IDWriteFontFace *fontface; - IDWriteFactory2 *factory2; - IDWriteFactory *factory; + IDWriteFactory2 *factory; DWRITE_GLYPH_RUN run; UINT32 codepoints[2]; IDWriteFont *font; @@ -6653,17 +6696,14 @@ HRESULT hr; ULONG ref; - factory = create_factory(); - - hr = IDWriteFactory_QueryInterface(factory, &IID_IDWriteFactory2, (void**)&factory2); - IDWriteFactory_Release(factory); - if (hr != S_OK) { + factory = create_factory_iid(&IID_IDWriteFactory2); + if (!factory) { win_skip("TranslateColorGlyphRun() is not supported.\n"); return; } /* Tahoma, no color support */ - fontface = create_fontface((IDWriteFactory*)factory2); + fontface = create_fontface((IDWriteFactory *)factory); codepoints[0] = 'A'; hr = IDWriteFontFace_GetGlyphIndices(fontface, codepoints, 1, glyphs); @@ -6679,16 +6719,16 @@ run.bidiLevel = 0; layers = (void*)0xdeadbeef; - hr = IDWriteFactory2_TranslateColorGlyphRun(factory2, 0.0, 0.0, &run, NULL, + hr = IDWriteFactory2_TranslateColorGlyphRun(factory, 0.0f, 0.0f, &run, NULL, DWRITE_MEASURING_MODE_NATURAL, NULL, 0, &layers); ok(hr == DWRITE_E_NOCOLOR, "got 0x%08x\n", hr); ok(layers == NULL, "got %p\n", layers); IDWriteFontFace_Release(fontface); /* Segoe UI Emoji, with color support */ - font = get_font((IDWriteFactory*)factory2, emojiW, DWRITE_FONT_STYLE_NORMAL); + font = get_font((IDWriteFactory *)factory, emojiW, DWRITE_FONT_STYLE_NORMAL); if (!font) { - IDWriteFactory2_Release(factory2); + IDWriteFactory2_Release(factory); skip("Segoe UI Emoji font not found.\n"); return; } @@ -6704,12 +6744,12 @@ run.fontFace = fontface; layers = NULL; - hr = IDWriteFactory2_TranslateColorGlyphRun(factory2, 0.0, 0.0, &run, NULL, + hr = IDWriteFactory2_TranslateColorGlyphRun(factory, 0.0f, 0.0f, &run, NULL, DWRITE_MEASURING_MODE_NATURAL, NULL, 0, &layers); ok(hr == S_OK, "got 0x%08x\n", hr); ok(layers != NULL, "got %p\n", layers); - while (1) { + for (;;) { hasrun = FALSE; hr = IDWriteColorGlyphRunEnumerator_MoveNext(layers, &hasrun); ok(hr == S_OK, "got 0x%08x\n", hr); @@ -6737,14 +6777,14 @@ /* invalid palette index */ layers = (void*)0xdeadbeef; - hr = IDWriteFactory2_TranslateColorGlyphRun(factory2, 0.0f, 0.0f, &run, NULL, + hr = IDWriteFactory2_TranslateColorGlyphRun(factory, 0.0f, 0.0f, &run, NULL, DWRITE_MEASURING_MODE_NATURAL, NULL, IDWriteFontFace2_GetColorPaletteCount(fontface2), &layers); ok(hr == DWRITE_E_NOCOLOR, "got 0x%08x\n", hr); ok(layers == NULL, "got %p\n", layers); layers = NULL; - hr = IDWriteFactory2_TranslateColorGlyphRun(factory2, 0.0f, 0.0f, &run, NULL, + hr = IDWriteFactory2_TranslateColorGlyphRun(factory, 0.0f, 0.0f, &run, NULL, DWRITE_MEASURING_MODE_NATURAL, NULL, IDWriteFontFace2_GetColorPaletteCount(fontface2) - 1, &layers); ok(hr == S_OK, "got 0x%08x\n", hr); @@ -6756,7 +6796,7 @@ ok(hr == S_OK, "got 0x%08x\n", hr); layers = (void*)0xdeadbeef; - hr = IDWriteFactory2_TranslateColorGlyphRun(factory2, 0.0, 0.0, &run, NULL, + hr = IDWriteFactory2_TranslateColorGlyphRun(factory, 0.0f, 0.0f, &run, NULL, DWRITE_MEASURING_MODE_NATURAL, NULL, 0, &layers); ok(hr == DWRITE_E_NOCOLOR, "got 0x%08x\n", hr); ok(layers == NULL, "got %p\n", layers); @@ -6771,7 +6811,7 @@ run.glyphCount = 2; layers = NULL; - hr = IDWriteFactory2_TranslateColorGlyphRun(factory2, 0.0, 0.0, &run, NULL, + hr = IDWriteFactory2_TranslateColorGlyphRun(factory, 0.0f, 0.0f, &run, NULL, DWRITE_MEASURING_MODE_NATURAL, NULL, 0, &layers); ok(hr == S_OK, "got 0x%08x\n", hr); ok(layers != NULL, "got %p\n", layers); @@ -6779,7 +6819,7 @@ IDWriteFontFace2_Release(fontface2); IDWriteFontFace_Release(fontface); - ref = IDWriteFactory2_Release(factory2); + ref = IDWriteFactory2_Release(factory); ok(ref == 0, "factory not released, %u\n", ref); } @@ -6824,8 +6864,7 @@ IDWriteFontFace3 *fontface, *fontface1; IDWriteFontFaceReference *ref, *ref1; IDWriteFontFile *file, *file1; - IDWriteFactory3 *factory3; - IDWriteFactory *factory; + IDWriteFactory3 *factory; IDWriteFont3 *font3; IDWriteFont *font; ULONG refcount; @@ -6834,26 +6873,23 @@ HRESULT hr; BOOL ret; - factory = create_factory(); - - hr = IDWriteFactory_QueryInterface(factory, &IID_IDWriteFactory3, (void**)&factory3); - IDWriteFactory_Release(factory); - if (FAILED(hr)) { + factory = create_factory_iid(&IID_IDWriteFactory3); + if (!factory) { win_skip("CreateFontFaceReference() is not supported.\n"); return; } path = create_testfontfile(test_fontfile); - hr = IDWriteFactory3_CreateFontFaceReference(factory3, NULL, NULL, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref); + hr = IDWriteFactory3_CreateFontFaceReference(factory, NULL, NULL, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); /* out of range simulation flags */ - hr = IDWriteFactory3_CreateFontFaceReference(factory3, path, NULL, 0, ~0u, &ref); + hr = IDWriteFactory3_CreateFontFaceReference(factory, path, NULL, 0, ~0u, &ref); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); /* test file is not a collection, but reference could still be created with non-zero face index */ - hr = IDWriteFactory3_CreateFontFaceReference(factory3, path, NULL, 1, DWRITE_FONT_SIMULATIONS_NONE, &ref); + hr = IDWriteFactory3_CreateFontFaceReference(factory, path, NULL, 1, DWRITE_FONT_SIMULATIONS_NONE, &ref); ok(hr == S_OK, "got 0x%08x\n", hr); index = IDWriteFontFaceReference_GetFontFaceIndex(ref); @@ -6870,16 +6906,16 @@ IDWriteFontFaceReference_Release(ref); /* path however has to be valid */ - hr = IDWriteFactory3_CreateFontFaceReference(factory3, dummyW, NULL, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref); + hr = IDWriteFactory3_CreateFontFaceReference(factory, dummyW, NULL, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref); todo_wine ok(hr == DWRITE_E_FILENOTFOUND, "got 0x%08x\n", hr); if (hr == S_OK) IDWriteFontFaceReference_Release(ref); - EXPECT_REF(factory3, 1); - hr = IDWriteFactory3_CreateFontFaceReference(factory3, path, NULL, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref); + EXPECT_REF(factory, 1); + hr = IDWriteFactory3_CreateFontFaceReference(factory, path, NULL, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref); ok(hr == S_OK, "got 0x%08x\n", hr); - EXPECT_REF(factory3, 2); + EXPECT_REF(factory, 2); /* new file is returned */ hr = IDWriteFontFaceReference_GetFontFile(ref, &file); @@ -6893,7 +6929,7 @@ IDWriteFontFile_Release(file1); /* references are not reused */ - hr = IDWriteFactory3_CreateFontFaceReference(factory3, path, NULL, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref1); + hr = IDWriteFactory3_CreateFontFaceReference(factory, path, NULL, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref1); ok(hr == S_OK, "got 0x%08x\n", hr); ok(ref1 != ref, "got %p, previous ref %p\n", ref1, ref); @@ -6912,13 +6948,13 @@ ok(ret, "got %d\n", ret); IDWriteFontFaceReference_Release(ref1); - hr = IDWriteFactory3_CreateFontFaceReference(factory3, path, NULL, 1, DWRITE_FONT_SIMULATIONS_NONE, &ref1); + hr = IDWriteFactory3_CreateFontFaceReference(factory, path, NULL, 1, DWRITE_FONT_SIMULATIONS_NONE, &ref1); ok(hr == S_OK, "got 0x%08x\n", hr); ret = IDWriteFontFaceReference_Equals(ref, ref1); ok(!ret, "got %d\n", ret); IDWriteFontFaceReference_Release(ref1); - hr = IDWriteFactory3_CreateFontFaceReference(factory3, path, NULL, 0, DWRITE_FONT_SIMULATIONS_BOLD, &ref1); + hr = IDWriteFactory3_CreateFontFaceReference(factory, path, NULL, 0, DWRITE_FONT_SIMULATIONS_BOLD, &ref1); ok(hr == S_OK, "got 0x%08x\n", hr); ret = IDWriteFontFaceReference_Equals(ref, ref1); ok(!ret, "got %d\n", ret); @@ -6927,10 +6963,10 @@ IDWriteFontFaceReference_Release(ref); /* create reference from a file */ - hr = IDWriteFactory3_CreateFontFileReference(factory3, path, NULL, &file); + hr = IDWriteFactory3_CreateFontFileReference(factory, path, NULL, &file); ok(hr == S_OK, "got 0x%08x\n", hr); - hr = IDWriteFactory3_CreateFontFaceReference_(factory3, file, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref); + hr = IDWriteFactory3_CreateFontFaceReference_(factory, file, 0, DWRITE_FONT_SIMULATIONS_NONE, &ref); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IDWriteFontFaceReference_GetFontFile(ref, &file1); @@ -6942,7 +6978,7 @@ IDWriteFontFile_Release(file1); /* references returned from IDWriteFont3 */ - font = get_tahoma_instance((IDWriteFactory*)factory3, DWRITE_FONT_STYLE_NORMAL); + font = get_tahoma_instance((IDWriteFactory *)factory, DWRITE_FONT_STYLE_NORMAL); hr = IDWriteFont_QueryInterface(font, &IID_IDWriteFont3, (void**)&font3); ok(hr == S_OK, "got 0x%08x\n", hr); IDWriteFont_Release(font); @@ -6983,7 +7019,7 @@ IDWriteFontFace3_Release(fontface); IDWriteFont3_Release(font3); - refcount = IDWriteFactory3_Release(factory3); + refcount = IDWriteFactory3_Release(factory); ok(refcount == 0, "factory not released, %u\n", refcount); DELETE_FONTFILE(path); } @@ -7370,8 +7406,7 @@ static void test_ComputeGlyphOrigins(void) { - IDWriteFactory4 *factory4; - IDWriteFactory *factory; + IDWriteFactory4 *factory; DWRITE_GLYPH_RUN run; HRESULT hr; D2D1_POINT_2F origins[2]; @@ -7381,10 +7416,8 @@ DWRITE_MATRIX m; ULONG ref; - factory = create_factory(); - hr = IDWriteFactory_QueryInterface(factory, &IID_IDWriteFactory4, (void **)&factory4); - IDWriteFactory_Release(factory); - if (FAILED(hr)) { + factory = create_factory_iid(&IID_IDWriteFactory4); + if (!factory) { win_skip("ComputeGlyphOrigins() is not supported.\n"); return; } @@ -7405,13 +7438,13 @@ baseline_origin.y = 321.0f; memset(origins, 0, sizeof(origins)); - hr = IDWriteFactory4_ComputeGlyphOrigins_(factory4, &run, baseline_origin, origins); + hr = IDWriteFactory4_ComputeGlyphOrigins_(factory, &run, baseline_origin, origins); ok(hr == S_OK, "got 0x%08x\n", hr); ok(origins[0].x == 123.0f && origins[0].y == 321.0f, "origins[0] %f,%f\n", origins[0].x, origins[0].y); ok(origins[1].x == 133.0f && origins[1].y == 321.0f, "origins[1] %f,%f\n", origins[1].x, origins[1].y); memset(origins, 0, sizeof(origins)); - hr = IDWriteFactory4_ComputeGlyphOrigins(factory4, &run, DWRITE_MEASURING_MODE_NATURAL, baseline_origin, + hr = IDWriteFactory4_ComputeGlyphOrigins(factory, &run, DWRITE_MEASURING_MODE_NATURAL, baseline_origin, NULL, origins); ok(origins[0].x == 123.0f && origins[0].y == 321.0f, "origins[0] %f,%f\n", origins[0].x, origins[0].y); ok(origins[1].x == 133.0f && origins[1].y == 321.0f, "origins[1] %f,%f\n", origins[1].x, origins[1].y); @@ -7425,12 +7458,12 @@ m.dy = 0.0f; memset(origins, 0, sizeof(origins)); - hr = IDWriteFactory4_ComputeGlyphOrigins(factory4, &run, DWRITE_MEASURING_MODE_NATURAL, baseline_origin, + hr = IDWriteFactory4_ComputeGlyphOrigins(factory, &run, DWRITE_MEASURING_MODE_NATURAL, baseline_origin, &m, origins); ok(origins[0].x == 123.0f && origins[0].y == 321.0f, "origins[0] %f,%f\n", origins[0].x, origins[0].y); ok(origins[1].x == 133.0f && origins[1].y == 321.0f, "origins[1] %f,%f\n", origins[1].x, origins[1].y); - ref = IDWriteFactory4_Release(factory4); + ref = IDWriteFactory4_Release(factory); ok(ref == 0, "factory not released, %u\n", ref); } @@ -7648,32 +7681,28 @@ UINT64 file_size, size, writetime; IDWriteFontFile *file, *file2; IDWriteFontFace *fontface; - IDWriteFactory5 *factory5; void *context, *context2; - IDWriteFactory *factory; + IDWriteFactory5 *factory; UINT32 count, key_size; DWORD ref_key; HRESULT hr; ULONG ref; - factory = create_factory(); - - hr = IDWriteFactory_QueryInterface(factory, &IID_IDWriteFactory5, (void **)&factory5); - IDWriteFactory_Release(factory); - if (FAILED(hr)) { - win_skip("CreateInMemoryFontFileLoader is not supported\n"); + factory = create_factory_iid(&IID_IDWriteFactory5); + if (!factory) { + win_skip("CreateInMemoryFontFileLoader() is not supported\n"); return; } - EXPECT_REF(factory5, 1); - hr = IDWriteFactory5_CreateInMemoryFontFileLoader(factory5, &loader); + EXPECT_REF(factory, 1); + hr = IDWriteFactory5_CreateInMemoryFontFileLoader(factory, &loader); ok(hr == S_OK, "got %#x\n", hr); - EXPECT_REF(factory5, 1); + EXPECT_REF(factory, 1); testowner_init(&ownerobject); - fontface = create_fontface((IDWriteFactory *)factory5); + fontface = create_fontface((IDWriteFactory *)factory); - hr = IDWriteFactory5_CreateInMemoryFontFileLoader(factory5, &loader2); + hr = IDWriteFactory5_CreateInMemoryFontFileLoader(factory, &loader2); ok(hr == S_OK, "got %#x\n", hr); ok(loader != loader2, "unexpected pointer\n"); IDWriteFontFileLoader_Release(loader2); @@ -7709,19 +7738,19 @@ ok(hr == S_OK, "got %#x\n", hr); /* Not registered yet. */ - hr = IDWriteInMemoryFontFileLoader_CreateInMemoryFontFileReference(inmemory, (IDWriteFactory *)factory5, data, + hr = IDWriteInMemoryFontFileLoader_CreateInMemoryFontFileReference(inmemory, (IDWriteFactory *)factory, data, file_size, NULL, &file); ok(hr == E_INVALIDARG, "got %#x\n", hr); count = IDWriteInMemoryFontFileLoader_GetFileCount(inmemory); ok(count == 1, "Unexpected file count %u.\n", count); - hr = IDWriteFactory5_RegisterFontFileLoader(factory5, (IDWriteFontFileLoader *)inmemory); + hr = IDWriteFactory5_RegisterFontFileLoader(factory, (IDWriteFontFileLoader *)inmemory); ok(hr == S_OK, "got %#x\n", hr); EXPECT_REF(inmemory, 2); EXPECT_REF(&ownerobject.IUnknown_iface, 1); - hr = IDWriteInMemoryFontFileLoader_CreateInMemoryFontFileReference(inmemory, (IDWriteFactory *)factory5, data, + hr = IDWriteInMemoryFontFileLoader_CreateInMemoryFontFileReference(inmemory, (IDWriteFactory *)factory, data, file_size, &ownerobject.IUnknown_iface, &file); ok(hr == S_OK, "got %#x\n", hr); EXPECT_REF(&ownerobject.IUnknown_iface, 2); @@ -7730,7 +7759,7 @@ count = IDWriteInMemoryFontFileLoader_GetFileCount(inmemory); ok(count == 2, "Unexpected file count %u.\n", count); - hr = IDWriteInMemoryFontFileLoader_CreateInMemoryFontFileReference(inmemory, (IDWriteFactory *)factory5, data, + hr = IDWriteInMemoryFontFileLoader_CreateInMemoryFontFileReference(inmemory, (IDWriteFactory *)factory, data, file_size, &ownerobject.IUnknown_iface, &file2); ok(hr == S_OK, "got %#x\n", hr); ok(file2 != file, "got unexpected file\n"); @@ -7784,7 +7813,7 @@ count = IDWriteInMemoryFontFileLoader_GetFileCount(inmemory); ok(count == 3, "Unexpected file count %u.\n", count); - hr = IDWriteFactory5_UnregisterFontFileLoader(factory5, (IDWriteFontFileLoader *)inmemory); + hr = IDWriteFactory5_UnregisterFontFileLoader(factory, (IDWriteFontFileLoader *)inmemory); ok(hr == S_OK, "got %#x\n", hr); EXPECT_REF(&ownerobject.IUnknown_iface, 3); @@ -7794,21 +7823,21 @@ EXPECT_REF(&ownerobject.IUnknown_iface, 1); /* Test reference key for first added file. */ - hr = IDWriteFactory5_CreateInMemoryFontFileLoader(factory5, &loader); + hr = IDWriteFactory5_CreateInMemoryFontFileLoader(factory, &loader); ok(hr == S_OK, "Failed to create loader, hr %#x.\n", hr); hr = IDWriteFontFileLoader_QueryInterface(loader, &IID_IDWriteInMemoryFontFileLoader, (void **)&inmemory); ok(hr == S_OK, "Failed to get in-memory interface, hr %#x.\n", hr); IDWriteFontFileLoader_Release(loader); - hr = IDWriteFactory5_RegisterFontFileLoader(factory5, (IDWriteFontFileLoader *)inmemory); + hr = IDWriteFactory5_RegisterFontFileLoader(factory, (IDWriteFontFileLoader *)inmemory); ok(hr == S_OK, "Failed to register loader, hr %#x.\n", hr); ref_key = 0; hr = IDWriteInMemoryFontFileLoader_CreateStreamFromKey(inmemory, &ref_key, sizeof(ref_key), &stream2); ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr); - hr = IDWriteInMemoryFontFileLoader_CreateInMemoryFontFileReference(inmemory, (IDWriteFactory *)factory5, data, + hr = IDWriteInMemoryFontFileLoader_CreateInMemoryFontFileReference(inmemory, (IDWriteFactory *)factory, data, file_size, &ownerobject.IUnknown_iface, &file); ok(hr == S_OK, "Failed to create in-memory file reference, hr %#x.\n", hr); @@ -7861,14 +7890,14 @@ count = IDWriteInMemoryFontFileLoader_GetFileCount(inmemory); ok(count == 1, "Unexpected file count %u.\n", count); - hr = IDWriteFactory5_UnregisterFontFileLoader(factory5, (IDWriteFontFileLoader *)inmemory); + hr = IDWriteFactory5_UnregisterFontFileLoader(factory, (IDWriteFontFileLoader *)inmemory); ok(hr == S_OK, "Failed to unregister loader, hr %#x.\n", hr); IDWriteFontFileStream_ReleaseFileFragment(stream, context); IDWriteFontFileStream_Release(stream); IDWriteFontFace_Release(fontface); - ref = IDWriteFactory5_Release(factory5); + ref = IDWriteFactory5_Release(factory); ok(ref == 0, "factory not released, %u\n", ref); } @@ -8156,6 +8185,59 @@ DELETE_FONTFILE(path); } +static void test_AnalyzeContainerType(void) +{ + struct WOFFHeader2 woff2_header; + struct WOFFHeader woff_header; + DWRITE_CONTAINER_TYPE type; + IDWriteFactory5 *factory; + + factory = create_factory_iid(&IID_IDWriteFactory5); + if (!factory) { + win_skip("AnalyzeContainerType() is not supported.\n"); + return; + } + + type = IDWriteFactory5_AnalyzeContainerType(factory, NULL, 0); + ok(type == DWRITE_CONTAINER_TYPE_UNKNOWN, "Unexpected container type %u.\n", type); + + type = IDWriteFactory5_AnalyzeContainerType(factory, (void const *)0xdeadbeef, 0); + ok(type == DWRITE_CONTAINER_TYPE_UNKNOWN, "Unexpected container type %u.\n", type); + + memset(&woff_header, 0xff, sizeof(woff_header)); + woff_header.signature = GET_LE_DWORD(MS_WOFF_TAG); + woff_header.length = 0; + type = IDWriteFactory5_AnalyzeContainerType(factory, &woff_header, sizeof(woff_header)); + ok(type == DWRITE_CONTAINER_TYPE_WOFF, "Unexpected container type %u.\n", type); + + memset(&woff_header, 0xff, sizeof(woff_header)); + woff_header.signature = GET_LE_DWORD(MS_WOFF_TAG); + type = IDWriteFactory5_AnalyzeContainerType(factory, &woff_header, sizeof(woff_header.signature)); + ok(type == DWRITE_CONTAINER_TYPE_WOFF, "Unexpected container type %u.\n", type); + + memset(&woff_header, 0xff, sizeof(woff_header)); + woff_header.signature = GET_LE_DWORD(MS_WOFF_TAG); + type = IDWriteFactory5_AnalyzeContainerType(factory, &woff_header, sizeof(woff_header.signature) - 1); + ok(type == DWRITE_CONTAINER_TYPE_UNKNOWN, "Unexpected container type %u.\n", type); + + memset(&woff2_header, 0xff, sizeof(woff2_header)); + woff2_header.signature = GET_LE_DWORD(MS_WOF2_TAG); + type = IDWriteFactory5_AnalyzeContainerType(factory, &woff2_header, sizeof(woff2_header)); + ok(type == DWRITE_CONTAINER_TYPE_WOFF2, "Unexpected container type %u.\n", type); + + memset(&woff2_header, 0xff, sizeof(woff2_header)); + woff2_header.signature = GET_LE_DWORD(MS_WOF2_TAG); + type = IDWriteFactory5_AnalyzeContainerType(factory, &woff2_header, sizeof(woff2_header.signature)); + ok(type == DWRITE_CONTAINER_TYPE_WOFF2, "Unexpected container type %u.\n", type); + + memset(&woff2_header, 0xff, sizeof(woff2_header)); + woff2_header.signature = GET_LE_DWORD(MS_WOF2_TAG); + type = IDWriteFactory5_AnalyzeContainerType(factory, &woff2_header, sizeof(woff2_header.signature) - 1); + ok(type == DWRITE_CONTAINER_TYPE_UNKNOWN, "Unexpected container type %u.\n", type); + + IDWriteFactory5_Release(factory); +} + START_TEST(font) { IDWriteFactory *factory; @@ -8221,6 +8303,7 @@ test_GetGlyphImageFormats(); test_CreateCustomRenderingParams(); test_localfontfileloader(); + test_AnalyzeContainerType(); IDWriteFactory_Release(factory); }