https://bugs.winehq.org/show_bug.cgi?id=44052
Signed-off-by: Lucian Poston lucian.poston@gmail.com --- dlls/dwrite/tests/font.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index 7a14180979..744ae18445 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -2934,6 +2934,51 @@ todo_wine ok(ref == 0, "factory not released, %u\n", ref); }
+static void test_CustomFontCollection_fallback(void) +{ + static const WCHAR strW[] = {'a','b','c','d',0}; + static const WCHAR enusW[] = {'e','n','-','u','s',0}; + IDWriteFontCollectionLoader *loader; + IDWriteTextFormat *format; + IDWriteTextLayout *layout; + IDWriteFactory *factory; + LONG font_coll_key = 1; + IDWriteFontCollection *font_collection; + DWRITE_TEXT_METRICS metrics; + HRESULT hr; + + factory = create_factory(); + loader = create_collection_loader(); + hr = IDWriteFactory_RegisterFontCollectionLoader(factory, loader); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IDWriteFactory_CreateCustomFontCollection(factory, loader, + &font_coll_key, sizeof(font_coll_key), &font_collection); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, font_collection, + 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); + + hr = IDWriteFactory_CreateTextLayout(factory, strW, 4, format, + 1000.0, 1000.0, &layout); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IDWriteTextLayout_GetMetrics(layout, &metrics); + todo_wine + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IDWriteFactory_UnregisterFontCollectionLoader(factory, loader); + ok(hr == S_OK, "got 0x%08x\n", hr); + + IDWriteFontCollectionLoader_Release(loader); + IDWriteFontCollection_Release(font_collection); + IDWriteTextFormat_Release(format); + IDWriteTextLayout_Release(layout); + IDWriteFactory_Release(factory); +} + static HRESULT WINAPI fontfileloader_QueryInterface(IDWriteFontFileLoader *iface, REFIID riid, void **obj) { if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteFontFileLoader)) @@ -8467,6 +8512,7 @@ START_TEST(font) test_system_fontcollection(); test_ConvertFontFaceToLOGFONT(); test_CustomFontCollection(); + test_CustomFontCollection_fallback(); test_CreateCustomFontFileReference(); test_CreateFontFileReference(); test_shared_isolated();
https://bugs.winehq.org/show_bug.cgi?id=44052
Signed-off-by: Lucian Poston lucian.poston@gmail.com --- dlls/dwrite/analyzer.c | 15 +++++++++++---- dlls/dwrite/layout.c | 15 +++++++++++---- dlls/dwrite/tests/font.c | 1 - 3 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/dlls/dwrite/analyzer.c b/dlls/dwrite/analyzer.c index bb08017611..4a6d40f1b6 100644 --- a/dlls/dwrite/analyzer.c +++ b/dlls/dwrite/analyzer.c @@ -2139,15 +2139,22 @@ static HRESULT WINAPI fontfallback_MapCharacters(IDWriteFontFallback *iface, IDW if (length == 0) return S_OK;
- if (!basecollection) - basecollection = (IDWriteFontCollection*)fallback->systemcollection; - hr = get_text_source_ptr(source, position, length, &text, &buff); if (FAILED(hr)) goto done;
if (basefamily && *basefamily) { - hr = create_matching_font(basecollection, basefamily, weight, style, stretch, ret_font); + if (basecollection) + { + hr = create_matching_font(basecollection, basefamily, weight, style, stretch, ret_font); + } + + if (!basecollection || FAILED(hr)) + { + hr = create_matching_font((IDWriteFontCollection*)fallback->systemcollection, + basefamily, weight, style, stretch, ret_font); + } + if (FAILED(hr)) goto done;
diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c index eda90ec784..6de29129f0 100644 --- a/dlls/dwrite/layout.c +++ b/dlls/dwrite/layout.c @@ -830,12 +830,19 @@ static HRESULT layout_resolve_fonts(struct dwrite_textlayout *layout) range = get_layout_range_by_pos(layout, run->descr.textPosition);
if (run->sa.shapes == DWRITE_SCRIPT_SHAPES_NO_VISUAL) { - IDWriteFontCollection *collection; + if (range->collection) { + hr = create_matching_font(range->collection, range->fontfamily, + range->weight, range->style, range->stretch, &font); + }
- collection = range->collection ? range->collection : sys_collection; + if (range->collection == NULL || FAILED(hr)) + { + hr = create_matching_font(sys_collection, range->fontfamily, + range->weight, range->style, range->stretch, &font); + }
- if (FAILED(hr = create_matching_font(collection, range->fontfamily, range->weight, range->style, - range->stretch, &font))) { + if (FAILED(hr)) + { WARN("%s: failed to create matching font for non visual run, family %s, collection %p\n", debugstr_rundescr(&run->descr), debugstr_w(range->fontfamily), range->collection); break; diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index 744ae18445..9fb7f44c5e 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -2966,7 +2966,6 @@ static void test_CustomFontCollection_fallback(void) ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IDWriteTextLayout_GetMetrics(layout, &metrics); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IDWriteFactory_UnregisterFontCollectionLoader(factory, loader);
See my comment on patch 1/2, I don't think the test is enough to justify such code change.
The only thing this test shows is that some font is selected. To show that system collection is considered at all you'll need to use some additionally installed font that can't participate in fallback lists, and test which font is used during rendering.
Just tested this myself, and it looks like it doesn't work like that.
Cases I tested:
- format font is Noto Sans, it is installed. Layout is rendered with Segoe UI (fallback font); - format font is Tahoma, obviously present in system collection, potentially is a fallback font. Layout is still rendered with Segoe UI.
That means that if base collection does not contain base family, system collection is not considered, and fallback is applied right away.