d3d11: Report D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW in CheckFormatSupport().
[wine.git] / dlls / dwrite / main.c
bloba96874b2c2c7a364c3fe157e4394a5f5a822e728
1 /*
2 * DWrite
4 * Copyright 2012 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <stdarg.h>
24 #include <math.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
30 #include "initguid.h"
32 #include "dwrite_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
37 static IDWriteFactory7 *shared_factory;
38 static void release_shared_factory(IDWriteFactory7 *factory);
40 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID reserved)
42 switch (reason)
44 case DLL_PROCESS_ATTACH:
45 DisableThreadLibraryCalls( hinstDLL );
46 init_freetype();
47 init_local_fontfile_loader();
48 break;
49 case DLL_PROCESS_DETACH:
50 if (reserved) break;
51 release_shared_factory(shared_factory);
52 release_freetype();
54 return TRUE;
57 struct renderingparams {
58 IDWriteRenderingParams3 IDWriteRenderingParams3_iface;
59 LONG ref;
61 FLOAT gamma;
62 FLOAT contrast;
63 FLOAT grayscalecontrast;
64 FLOAT cleartype_level;
65 DWRITE_PIXEL_GEOMETRY geometry;
66 DWRITE_RENDERING_MODE1 mode;
67 DWRITE_GRID_FIT_MODE gridfit;
70 static inline struct renderingparams *impl_from_IDWriteRenderingParams3(IDWriteRenderingParams3 *iface)
72 return CONTAINING_RECORD(iface, struct renderingparams, IDWriteRenderingParams3_iface);
75 static HRESULT WINAPI renderingparams_QueryInterface(IDWriteRenderingParams3 *iface, REFIID riid, void **obj)
77 struct renderingparams *This = impl_from_IDWriteRenderingParams3(iface);
79 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
81 if (IsEqualIID(riid, &IID_IDWriteRenderingParams3) ||
82 IsEqualIID(riid, &IID_IDWriteRenderingParams2) ||
83 IsEqualIID(riid, &IID_IDWriteRenderingParams1) ||
84 IsEqualIID(riid, &IID_IDWriteRenderingParams) ||
85 IsEqualIID(riid, &IID_IUnknown))
87 *obj = iface;
88 IDWriteRenderingParams3_AddRef(iface);
89 return S_OK;
92 *obj = NULL;
94 return E_NOINTERFACE;
97 static ULONG WINAPI renderingparams_AddRef(IDWriteRenderingParams3 *iface)
99 struct renderingparams *This = impl_from_IDWriteRenderingParams3(iface);
100 ULONG ref = InterlockedIncrement(&This->ref);
101 TRACE("(%p)->(%d)\n", This, ref);
102 return ref;
105 static ULONG WINAPI renderingparams_Release(IDWriteRenderingParams3 *iface)
107 struct renderingparams *This = impl_from_IDWriteRenderingParams3(iface);
108 ULONG ref = InterlockedDecrement(&This->ref);
110 TRACE("(%p)->(%d)\n", This, ref);
112 if (!ref)
113 heap_free(This);
115 return ref;
118 static FLOAT WINAPI renderingparams_GetGamma(IDWriteRenderingParams3 *iface)
120 struct renderingparams *This = impl_from_IDWriteRenderingParams3(iface);
121 TRACE("(%p)\n", This);
122 return This->gamma;
125 static FLOAT WINAPI renderingparams_GetEnhancedContrast(IDWriteRenderingParams3 *iface)
127 struct renderingparams *This = impl_from_IDWriteRenderingParams3(iface);
128 TRACE("(%p)\n", This);
129 return This->contrast;
132 static FLOAT WINAPI renderingparams_GetClearTypeLevel(IDWriteRenderingParams3 *iface)
134 struct renderingparams *This = impl_from_IDWriteRenderingParams3(iface);
135 TRACE("(%p)\n", This);
136 return This->cleartype_level;
139 static DWRITE_PIXEL_GEOMETRY WINAPI renderingparams_GetPixelGeometry(IDWriteRenderingParams3 *iface)
141 struct renderingparams *This = impl_from_IDWriteRenderingParams3(iface);
142 TRACE("(%p)\n", This);
143 return This->geometry;
146 static DWRITE_RENDERING_MODE rendering_mode_from_mode1(DWRITE_RENDERING_MODE1 mode)
148 static const DWRITE_RENDERING_MODE rendering_modes[] = {
149 DWRITE_RENDERING_MODE_DEFAULT, /* DWRITE_RENDERING_MODE1_DEFAULT */
150 DWRITE_RENDERING_MODE_ALIASED, /* DWRITE_RENDERING_MODE1_ALIASED */
151 DWRITE_RENDERING_MODE_GDI_CLASSIC, /* DWRITE_RENDERING_MODE1_GDI_CLASSIC */
152 DWRITE_RENDERING_MODE_GDI_NATURAL, /* DWRITE_RENDERING_MODE1_GDI_NATURAL */
153 DWRITE_RENDERING_MODE_NATURAL, /* DWRITE_RENDERING_MODE1_NATURAL */
154 DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC, /* DWRITE_RENDERING_MODE1_NATURAL_SYMMETRIC */
155 DWRITE_RENDERING_MODE_OUTLINE, /* DWRITE_RENDERING_MODE1_OUTLINE */
156 DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC, /* DWRITE_RENDERING_MODE1_NATURAL_SYMMETRIC_DOWNSAMPLED */
159 return rendering_modes[mode];
162 static DWRITE_RENDERING_MODE WINAPI renderingparams_GetRenderingMode(IDWriteRenderingParams3 *iface)
164 struct renderingparams *This = impl_from_IDWriteRenderingParams3(iface);
166 TRACE("(%p)\n", This);
168 return rendering_mode_from_mode1(This->mode);
171 static FLOAT WINAPI renderingparams1_GetGrayscaleEnhancedContrast(IDWriteRenderingParams3 *iface)
173 struct renderingparams *This = impl_from_IDWriteRenderingParams3(iface);
174 TRACE("(%p)\n", This);
175 return This->grayscalecontrast;
178 static DWRITE_GRID_FIT_MODE WINAPI renderingparams2_GetGridFitMode(IDWriteRenderingParams3 *iface)
180 struct renderingparams *This = impl_from_IDWriteRenderingParams3(iface);
181 TRACE("(%p)\n", This);
182 return This->gridfit;
185 static DWRITE_RENDERING_MODE1 WINAPI renderingparams3_GetRenderingMode1(IDWriteRenderingParams3 *iface)
187 struct renderingparams *This = impl_from_IDWriteRenderingParams3(iface);
188 TRACE("(%p)\n", This);
189 return This->mode;
192 static const struct IDWriteRenderingParams3Vtbl renderingparamsvtbl = {
193 renderingparams_QueryInterface,
194 renderingparams_AddRef,
195 renderingparams_Release,
196 renderingparams_GetGamma,
197 renderingparams_GetEnhancedContrast,
198 renderingparams_GetClearTypeLevel,
199 renderingparams_GetPixelGeometry,
200 renderingparams_GetRenderingMode,
201 renderingparams1_GetGrayscaleEnhancedContrast,
202 renderingparams2_GetGridFitMode,
203 renderingparams3_GetRenderingMode1
206 static HRESULT create_renderingparams(FLOAT gamma, FLOAT contrast, FLOAT grayscalecontrast, FLOAT cleartype_level,
207 DWRITE_PIXEL_GEOMETRY geometry, DWRITE_RENDERING_MODE1 mode, DWRITE_GRID_FIT_MODE gridfit,
208 IDWriteRenderingParams3 **params)
210 struct renderingparams *This;
212 *params = NULL;
214 if (gamma <= 0.0f || contrast < 0.0f || grayscalecontrast < 0.0f || cleartype_level < 0.0f)
215 return E_INVALIDARG;
217 if ((UINT32)gridfit > DWRITE_GRID_FIT_MODE_ENABLED || (UINT32)geometry > DWRITE_PIXEL_GEOMETRY_BGR)
218 return E_INVALIDARG;
220 This = heap_alloc(sizeof(struct renderingparams));
221 if (!This) return E_OUTOFMEMORY;
223 This->IDWriteRenderingParams3_iface.lpVtbl = &renderingparamsvtbl;
224 This->ref = 1;
226 This->gamma = gamma;
227 This->contrast = contrast;
228 This->grayscalecontrast = grayscalecontrast;
229 This->cleartype_level = cleartype_level;
230 This->geometry = geometry;
231 This->mode = mode;
232 This->gridfit = gridfit;
234 *params = &This->IDWriteRenderingParams3_iface;
236 return S_OK;
239 struct localizedpair {
240 WCHAR *locale;
241 WCHAR *string;
244 struct localizedstrings
246 IDWriteLocalizedStrings IDWriteLocalizedStrings_iface;
247 LONG refcount;
249 struct localizedpair *data;
250 size_t size;
251 size_t count;
254 static inline struct localizedstrings *impl_from_IDWriteLocalizedStrings(IDWriteLocalizedStrings *iface)
256 return CONTAINING_RECORD(iface, struct localizedstrings, IDWriteLocalizedStrings_iface);
259 static HRESULT WINAPI localizedstrings_QueryInterface(IDWriteLocalizedStrings *iface, REFIID riid, void **obj)
261 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
263 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
265 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteLocalizedStrings))
267 *obj = iface;
268 IDWriteLocalizedStrings_AddRef(iface);
269 return S_OK;
272 *obj = NULL;
274 return E_NOINTERFACE;
277 static ULONG WINAPI localizedstrings_AddRef(IDWriteLocalizedStrings *iface)
279 struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface);
280 ULONG refcount = InterlockedIncrement(&strings->refcount);
282 TRACE("%p, refcount %d.\n", iface, refcount);
284 return refcount;
287 static ULONG WINAPI localizedstrings_Release(IDWriteLocalizedStrings *iface)
289 struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface);
290 ULONG refcount = InterlockedDecrement(&strings->refcount);
291 size_t i;
293 TRACE("%p, refcount %d.\n", iface, refcount);
295 if (!refcount)
297 for (i = 0; i < strings->count; ++i)
299 heap_free(strings->data[i].locale);
300 heap_free(strings->data[i].string);
303 heap_free(strings->data);
304 heap_free(strings);
307 return refcount;
310 static UINT32 WINAPI localizedstrings_GetCount(IDWriteLocalizedStrings *iface)
312 struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface);
314 TRACE("%p.\n", iface);
316 return strings->count;
319 static HRESULT WINAPI localizedstrings_FindLocaleName(IDWriteLocalizedStrings *iface,
320 WCHAR const *locale_name, UINT32 *index, BOOL *exists)
322 struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface);
323 size_t i;
325 TRACE("%p, %s, %p, %p.\n", iface, debugstr_w(locale_name), index, exists);
327 *exists = FALSE;
328 *index = ~0;
330 for (i = 0; i < strings->count; ++i)
332 if (!strcmpiW(strings->data[i].locale, locale_name))
334 *exists = TRUE;
335 *index = i;
336 break;
340 return S_OK;
343 static HRESULT WINAPI localizedstrings_GetLocaleNameLength(IDWriteLocalizedStrings *iface, UINT32 index, UINT32 *length)
345 struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface);
347 TRACE("%p, %u, %p.\n", iface, index, length);
349 if (index >= strings->count)
351 *length = (UINT32)-1;
352 return E_FAIL;
355 *length = strlenW(strings->data[index].locale);
356 return S_OK;
359 static HRESULT WINAPI localizedstrings_GetLocaleName(IDWriteLocalizedStrings *iface, UINT32 index, WCHAR *buffer, UINT32 size)
361 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
363 TRACE("(%p)->(%u %p %u)\n", This, index, buffer, size);
365 if (index >= This->count) {
366 if (buffer) *buffer = 0;
367 return E_FAIL;
370 if (size < strlenW(This->data[index].locale)+1) {
371 if (buffer) *buffer = 0;
372 return E_NOT_SUFFICIENT_BUFFER;
375 strcpyW(buffer, This->data[index].locale);
376 return S_OK;
379 static HRESULT WINAPI localizedstrings_GetStringLength(IDWriteLocalizedStrings *iface, UINT32 index, UINT32 *length)
381 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
383 TRACE("(%p)->(%u %p)\n", This, index, length);
385 if (index >= This->count) {
386 *length = (UINT32)-1;
387 return E_FAIL;
390 *length = strlenW(This->data[index].string);
391 return S_OK;
394 static HRESULT WINAPI localizedstrings_GetString(IDWriteLocalizedStrings *iface, UINT32 index, WCHAR *buffer, UINT32 size)
396 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
398 TRACE("(%p)->(%u %p %u)\n", This, index, buffer, size);
400 if (index >= This->count) {
401 if (buffer) *buffer = 0;
402 return E_FAIL;
405 if (size < strlenW(This->data[index].string)+1) {
406 if (buffer) *buffer = 0;
407 return E_NOT_SUFFICIENT_BUFFER;
410 strcpyW(buffer, This->data[index].string);
411 return S_OK;
414 static const IDWriteLocalizedStringsVtbl localizedstringsvtbl = {
415 localizedstrings_QueryInterface,
416 localizedstrings_AddRef,
417 localizedstrings_Release,
418 localizedstrings_GetCount,
419 localizedstrings_FindLocaleName,
420 localizedstrings_GetLocaleNameLength,
421 localizedstrings_GetLocaleName,
422 localizedstrings_GetStringLength,
423 localizedstrings_GetString
426 HRESULT create_localizedstrings(IDWriteLocalizedStrings **strings)
428 struct localizedstrings *object;
430 *strings = NULL;
432 object = heap_alloc_zero(sizeof(*object));
433 if (!object)
434 return E_OUTOFMEMORY;
436 object->IDWriteLocalizedStrings_iface.lpVtbl = &localizedstringsvtbl;
437 object->refcount = 1;
439 *strings = &object->IDWriteLocalizedStrings_iface;
441 return S_OK;
444 HRESULT add_localizedstring(IDWriteLocalizedStrings *iface, const WCHAR *locale, const WCHAR *string)
446 struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface);
447 size_t i, count = strings->count;
449 /* Make sure there's no duplicates, unless it's empty. This is used by dlng/slng entries of 'meta' table. */
450 if (*locale)
452 for (i = 0; i < count; i++)
453 if (!strcmpW(strings->data[i].locale, locale))
454 return S_OK;
457 if (!dwrite_array_reserve((void **)&strings->data, &strings->size, strings->count + 1, sizeof(*strings->data)))
458 return E_OUTOFMEMORY;
460 strings->data[count].locale = heap_strdupW(locale);
461 strings->data[count].string = heap_strdupW(string);
462 if (!strings->data[count].locale || !strings->data[count].string)
464 heap_free(strings->data[count].locale);
465 heap_free(strings->data[count].string);
466 return E_OUTOFMEMORY;
469 strings->count++;
471 return S_OK;
474 HRESULT clone_localizedstrings(IDWriteLocalizedStrings *iface, IDWriteLocalizedStrings **ret)
476 struct localizedstrings *strings, *strings_clone;
477 size_t i;
479 *ret = NULL;
481 if (!iface)
482 return S_FALSE;
484 strings = impl_from_IDWriteLocalizedStrings(iface);
485 strings_clone = heap_alloc_zero(sizeof(*strings_clone));
486 if (!strings_clone)
487 return E_OUTOFMEMORY;
489 if (!dwrite_array_reserve((void **)&strings_clone->data, &strings_clone->size, strings->count,
490 sizeof(*strings_clone->data)))
492 heap_free(strings_clone);
493 return E_OUTOFMEMORY;
496 strings_clone->IDWriteLocalizedStrings_iface.lpVtbl = &localizedstringsvtbl;
497 strings_clone->refcount = 1;
498 strings_clone->count = strings->count;
500 for (i = 0; i < strings_clone->count; ++i)
502 strings_clone->data[i].locale = heap_strdupW(strings->data[i].locale);
503 strings_clone->data[i].string = heap_strdupW(strings->data[i].string);
506 *ret = &strings_clone->IDWriteLocalizedStrings_iface;
508 return S_OK;
511 void set_en_localizedstring(IDWriteLocalizedStrings *iface, const WCHAR *string)
513 static const WCHAR enusW[] = {'e','n','-','U','S',0};
514 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
515 UINT32 i;
517 for (i = 0; i < This->count; i++) {
518 if (!strcmpiW(This->data[i].locale, enusW)) {
519 heap_free(This->data[i].string);
520 This->data[i].string = heap_strdupW(string);
521 break;
526 static int localizedstrings_sorting_compare(const void *left, const void *right)
528 const struct localizedpair *_l = left, *_r = right;
530 return strcmpW(_l->locale, _r->locale);
533 void sort_localizedstrings(IDWriteLocalizedStrings *iface)
535 struct localizedstrings *strings = impl_from_IDWriteLocalizedStrings(iface);
537 qsort(strings->data, strings->count, sizeof(*strings->data), localizedstrings_sorting_compare);
540 struct collectionloader
542 struct list entry;
543 IDWriteFontCollectionLoader *loader;
546 struct fileloader
548 struct list entry;
549 struct list fontfaces;
550 IDWriteFontFileLoader *loader;
553 struct dwritefactory
555 IDWriteFactory7 IDWriteFactory7_iface;
556 LONG refcount;
558 IDWriteFontCollection1 *system_collection;
559 IDWriteFontCollection1 *eudc_collection;
560 IDWriteGdiInterop1 *gdiinterop;
561 IDWriteFontFallback1 *fallback;
563 IDWriteFontFileLoader *localfontfileloader;
564 struct list localfontfaces;
566 struct list collection_loaders;
567 struct list file_loaders;
569 CRITICAL_SECTION cs;
572 static inline struct dwritefactory *impl_from_IDWriteFactory7(IDWriteFactory7 *iface)
574 return CONTAINING_RECORD(iface, struct dwritefactory, IDWriteFactory7_iface);
577 static void release_fontface_cache(struct list *fontfaces)
579 struct fontfacecached *fontface, *fontface2;
581 LIST_FOR_EACH_ENTRY_SAFE(fontface, fontface2, fontfaces, struct fontfacecached, entry) {
582 list_remove(&fontface->entry);
583 fontface_detach_from_cache(fontface->fontface);
584 heap_free(fontface);
588 static void release_fileloader(struct fileloader *fileloader)
590 list_remove(&fileloader->entry);
591 release_fontface_cache(&fileloader->fontfaces);
592 IDWriteFontFileLoader_Release(fileloader->loader);
593 heap_free(fileloader);
596 static void release_dwritefactory(struct dwritefactory *factory)
598 struct fileloader *fileloader, *fileloader2;
599 struct collectionloader *loader, *loader2;
601 EnterCriticalSection(&factory->cs);
602 release_fontface_cache(&factory->localfontfaces);
603 LeaveCriticalSection(&factory->cs);
605 LIST_FOR_EACH_ENTRY_SAFE(loader, loader2, &factory->collection_loaders, struct collectionloader, entry) {
606 list_remove(&loader->entry);
607 IDWriteFontCollectionLoader_Release(loader->loader);
608 heap_free(loader);
611 LIST_FOR_EACH_ENTRY_SAFE(fileloader, fileloader2, &factory->file_loaders, struct fileloader, entry)
612 release_fileloader(fileloader);
614 if (factory->system_collection)
615 IDWriteFontCollection1_Release(factory->system_collection);
616 if (factory->eudc_collection)
617 IDWriteFontCollection1_Release(factory->eudc_collection);
618 if (factory->fallback)
619 release_system_fontfallback(factory->fallback);
621 factory->cs.DebugInfo->Spare[0] = 0;
622 DeleteCriticalSection(&factory->cs);
623 heap_free(factory);
626 static void release_shared_factory(IDWriteFactory7 *iface)
628 struct dwritefactory *factory;
629 if (!iface) return;
630 factory = impl_from_IDWriteFactory7(iface);
631 release_dwritefactory(factory);
634 static struct fileloader *factory_get_file_loader(struct dwritefactory *factory, IDWriteFontFileLoader *loader)
636 struct fileloader *entry, *found = NULL;
638 LIST_FOR_EACH_ENTRY(entry, &factory->file_loaders, struct fileloader, entry) {
639 if (entry->loader == loader) {
640 found = entry;
641 break;
645 return found;
648 static struct collectionloader *factory_get_collection_loader(struct dwritefactory *factory,
649 IDWriteFontCollectionLoader *loader)
651 struct collectionloader *entry, *found = NULL;
653 LIST_FOR_EACH_ENTRY(entry, &factory->collection_loaders, struct collectionloader, entry) {
654 if (entry->loader == loader) {
655 found = entry;
656 break;
660 return found;
663 static IDWriteFontCollection1 *factory_get_system_collection(struct dwritefactory *factory)
665 IDWriteFontCollection1 *collection;
666 HRESULT hr;
668 if (factory->system_collection) {
669 IDWriteFontCollection1_AddRef(factory->system_collection);
670 return factory->system_collection;
673 if (FAILED(hr = get_system_fontcollection(&factory->IDWriteFactory7_iface, &collection)))
675 WARN("Failed to create system font collection, hr %#x.\n", hr);
676 return NULL;
679 if (InterlockedCompareExchangePointer((void **)&factory->system_collection, collection, NULL))
680 IDWriteFontCollection1_Release(collection);
682 return factory->system_collection;
685 static HRESULT WINAPI dwritefactory_QueryInterface(IDWriteFactory7 *iface, REFIID riid, void **obj)
687 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
689 if (IsEqualIID(riid, &IID_IDWriteFactory7) ||
690 IsEqualIID(riid, &IID_IDWriteFactory6) ||
691 IsEqualIID(riid, &IID_IDWriteFactory5) ||
692 IsEqualIID(riid, &IID_IDWriteFactory4) ||
693 IsEqualIID(riid, &IID_IDWriteFactory3) ||
694 IsEqualIID(riid, &IID_IDWriteFactory2) ||
695 IsEqualIID(riid, &IID_IDWriteFactory1) ||
696 IsEqualIID(riid, &IID_IDWriteFactory) ||
697 IsEqualIID(riid, &IID_IUnknown))
699 *obj = iface;
700 IDWriteFactory7_AddRef(iface);
701 return S_OK;
704 *obj = NULL;
706 return E_NOINTERFACE;
709 static ULONG WINAPI dwritefactory_AddRef(IDWriteFactory7 *iface)
711 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
712 ULONG refcount = InterlockedIncrement(&factory->refcount);
714 TRACE("%p, refcount %u.\n", iface, refcount);
716 return refcount;
719 static ULONG WINAPI dwritefactory_Release(IDWriteFactory7 *iface)
721 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
722 ULONG refcount = InterlockedDecrement(&factory->refcount);
724 TRACE("%p, refcount %u.\n", iface, refcount);
726 if (!refcount)
727 release_dwritefactory(factory);
729 return refcount;
732 static HRESULT WINAPI dwritefactory_GetSystemFontCollection(IDWriteFactory7 *iface,
733 IDWriteFontCollection **collection, BOOL check_for_updates)
735 return IDWriteFactory5_GetSystemFontCollection((IDWriteFactory5 *)iface, FALSE, (IDWriteFontCollection1 **)collection,
736 check_for_updates);
739 static HRESULT WINAPI dwritefactory_CreateCustomFontCollection(IDWriteFactory7 *iface,
740 IDWriteFontCollectionLoader *loader, void const *key, UINT32 key_size, IDWriteFontCollection **collection)
742 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
743 IDWriteFontFileEnumerator *enumerator;
744 struct collectionloader *found;
745 HRESULT hr;
747 TRACE("%p, %p, %p, %u, %p.\n", iface, loader, key, key_size, collection);
749 *collection = NULL;
751 if (!loader)
752 return E_INVALIDARG;
754 found = factory_get_collection_loader(factory, loader);
755 if (!found)
756 return E_INVALIDARG;
758 hr = IDWriteFontCollectionLoader_CreateEnumeratorFromKey(found->loader, (IDWriteFactory *)iface,
759 key, key_size, &enumerator);
760 if (FAILED(hr))
761 return hr;
763 hr = create_font_collection(iface, enumerator, FALSE, (IDWriteFontCollection3 **)collection);
764 IDWriteFontFileEnumerator_Release(enumerator);
765 return hr;
768 static HRESULT WINAPI dwritefactory_RegisterFontCollectionLoader(IDWriteFactory7 *iface,
769 IDWriteFontCollectionLoader *loader)
771 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
772 struct collectionloader *entry;
774 TRACE("%p, %p.\n", iface, loader);
776 if (!loader)
777 return E_INVALIDARG;
779 if (factory_get_collection_loader(factory, loader))
780 return DWRITE_E_ALREADYREGISTERED;
782 entry = heap_alloc(sizeof(*entry));
783 if (!entry)
784 return E_OUTOFMEMORY;
786 entry->loader = loader;
787 IDWriteFontCollectionLoader_AddRef(loader);
788 list_add_tail(&factory->collection_loaders, &entry->entry);
790 return S_OK;
793 static HRESULT WINAPI dwritefactory_UnregisterFontCollectionLoader(IDWriteFactory7 *iface,
794 IDWriteFontCollectionLoader *loader)
796 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
797 struct collectionloader *found;
799 TRACE("%p, %p.\n", iface, loader);
801 if (!loader)
802 return E_INVALIDARG;
804 found = factory_get_collection_loader(factory, loader);
805 if (!found)
806 return E_INVALIDARG;
808 IDWriteFontCollectionLoader_Release(found->loader);
809 list_remove(&found->entry);
810 heap_free(found);
812 return S_OK;
815 static HRESULT WINAPI dwritefactory_CreateFontFileReference(IDWriteFactory7 *iface,
816 WCHAR const *path, FILETIME const *writetime, IDWriteFontFile **font_file)
818 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
819 UINT32 key_size;
820 HRESULT hr;
821 void *key;
823 TRACE("%p, %s, %p, %p.\n", iface, debugstr_w(path), writetime, font_file);
825 *font_file = NULL;
827 /* Get a reference key in local file loader format. */
828 hr = get_local_refkey(path, writetime, &key, &key_size);
829 if (FAILED(hr))
830 return hr;
832 hr = create_font_file(factory->localfontfileloader, key, key_size, font_file);
833 heap_free(key);
835 return hr;
838 static HRESULT WINAPI dwritefactory_CreateCustomFontFileReference(IDWriteFactory7 *iface,
839 void const *reference_key, UINT32 key_size, IDWriteFontFileLoader *loader, IDWriteFontFile **font_file)
841 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
843 TRACE("%p, %p, %u, %p, %p.\n", iface, reference_key, key_size, loader, font_file);
845 *font_file = NULL;
847 if (!loader || !(factory_get_file_loader(factory, loader) || factory->localfontfileloader == loader))
848 return E_INVALIDARG;
850 return create_font_file(loader, reference_key, key_size, font_file);
853 void factory_lock(IDWriteFactory7 *iface)
855 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
856 EnterCriticalSection(&factory->cs);
859 void factory_unlock(IDWriteFactory7 *iface)
861 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
862 LeaveCriticalSection(&factory->cs);
865 HRESULT factory_get_cached_fontface(IDWriteFactory7 *iface, IDWriteFontFile * const *font_files, UINT32 index,
866 DWRITE_FONT_SIMULATIONS simulations, struct list **cached_list, REFIID riid, void **obj)
868 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
869 struct fontfacecached *cached;
870 IDWriteFontFileLoader *loader;
871 struct list *fontfaces;
872 UINT32 key_size;
873 const void *key;
874 HRESULT hr;
876 *obj = NULL;
877 *cached_list = NULL;
879 hr = IDWriteFontFile_GetReferenceKey(*font_files, &key, &key_size);
880 if (FAILED(hr))
881 return hr;
883 hr = IDWriteFontFile_GetLoader(*font_files, &loader);
884 if (FAILED(hr))
885 return hr;
887 if (loader == factory->localfontfileloader) {
888 fontfaces = &factory->localfontfaces;
889 IDWriteFontFileLoader_Release(loader);
891 else {
892 struct fileloader *fileloader = factory_get_file_loader(factory, loader);
893 IDWriteFontFileLoader_Release(loader);
894 if (!fileloader)
895 return E_INVALIDARG;
896 fontfaces = &fileloader->fontfaces;
899 *cached_list = fontfaces;
901 EnterCriticalSection(&factory->cs);
903 /* search through cache list */
904 LIST_FOR_EACH_ENTRY(cached, fontfaces, struct fontfacecached, entry) {
905 UINT32 cached_key_size, count = 1, cached_face_index;
906 DWRITE_FONT_SIMULATIONS cached_simulations;
907 const void *cached_key;
908 IDWriteFontFile *file;
910 cached_face_index = IDWriteFontFace5_GetIndex(cached->fontface);
911 cached_simulations = IDWriteFontFace5_GetSimulations(cached->fontface);
913 /* skip earlier */
914 if (cached_face_index != index || cached_simulations != simulations)
915 continue;
917 hr = IDWriteFontFace5_GetFiles(cached->fontface, &count, &file);
918 if (FAILED(hr))
919 break;
921 hr = IDWriteFontFile_GetReferenceKey(file, &cached_key, &cached_key_size);
922 IDWriteFontFile_Release(file);
923 if (FAILED(hr))
924 break;
926 if (cached_key_size == key_size && !memcmp(cached_key, key, key_size))
928 if (FAILED(hr = IDWriteFontFace5_QueryInterface(cached->fontface, riid, obj)))
929 WARN("Failed to get %s from fontface, hr %#x.\n", debugstr_guid(riid), hr);
931 TRACE("returning cached fontface %p\n", cached->fontface);
932 break;
936 LeaveCriticalSection(&factory->cs);
938 return *obj ? S_OK : S_FALSE;
941 struct fontfacecached *factory_cache_fontface(IDWriteFactory7 *iface, struct list *fontfaces,
942 IDWriteFontFace5 *fontface)
944 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
945 struct fontfacecached *cached;
947 /* new cache entry */
948 cached = heap_alloc(sizeof(*cached));
949 if (!cached)
950 return NULL;
952 cached->fontface = fontface;
953 EnterCriticalSection(&factory->cs);
954 list_add_tail(fontfaces, &cached->entry);
955 LeaveCriticalSection(&factory->cs);
957 return cached;
960 static HRESULT WINAPI dwritefactory_CreateFontFace(IDWriteFactory7 *iface, DWRITE_FONT_FACE_TYPE req_facetype,
961 UINT32 files_number, IDWriteFontFile* const* font_files, UINT32 index, DWRITE_FONT_SIMULATIONS simulations,
962 IDWriteFontFace **fontface)
964 DWRITE_FONT_FILE_TYPE file_type;
965 DWRITE_FONT_FACE_TYPE face_type;
966 IDWriteFontFileStream *stream;
967 struct fontface_desc desc;
968 struct list *fontfaces;
969 BOOL is_supported;
970 UINT32 face_count;
971 HRESULT hr;
973 TRACE("%p, %d, %u, %p, %u, %#x, %p.\n", iface, req_facetype, files_number, font_files, index,
974 simulations, fontface);
976 *fontface = NULL;
978 if (!is_face_type_supported(req_facetype))
979 return E_INVALIDARG;
981 if (req_facetype != DWRITE_FONT_FACE_TYPE_OPENTYPE_COLLECTION && index)
982 return E_INVALIDARG;
984 if (!is_simulation_valid(simulations))
985 return E_INVALIDARG;
987 if (FAILED(hr = get_filestream_from_file(*font_files, &stream)))
988 return hr;
990 /* check actual file/face type */
991 is_supported = FALSE;
992 face_type = DWRITE_FONT_FACE_TYPE_UNKNOWN;
993 hr = opentype_analyze_font(stream, &is_supported, &file_type, &face_type, &face_count);
994 if (FAILED(hr))
995 goto failed;
997 if (!is_supported) {
998 hr = E_FAIL;
999 goto failed;
1002 if (face_type != req_facetype) {
1003 hr = DWRITE_E_FILEFORMAT;
1004 goto failed;
1007 hr = factory_get_cached_fontface(iface, font_files, index, simulations, &fontfaces,
1008 &IID_IDWriteFontFace, (void **)fontface);
1009 if (hr != S_FALSE)
1010 goto failed;
1012 desc.factory = iface;
1013 desc.face_type = req_facetype;
1014 desc.files = font_files;
1015 desc.stream = stream;
1016 desc.files_number = files_number;
1017 desc.index = index;
1018 desc.simulations = simulations;
1019 desc.font_data = NULL;
1020 hr = create_fontface(&desc, fontfaces, (IDWriteFontFace5 **)fontface);
1022 failed:
1023 IDWriteFontFileStream_Release(stream);
1024 return hr;
1027 static HRESULT WINAPI dwritefactory_CreateRenderingParams(IDWriteFactory7 *iface, IDWriteRenderingParams **params)
1029 HMONITOR monitor;
1030 POINT pt;
1032 TRACE("%p, %p.\n", iface, params);
1034 pt.x = pt.y = 0;
1035 monitor = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
1036 return IDWriteFactory7_CreateMonitorRenderingParams(iface, monitor, params);
1039 static HRESULT WINAPI dwritefactory_CreateMonitorRenderingParams(IDWriteFactory7 *iface, HMONITOR monitor,
1040 IDWriteRenderingParams **params)
1042 IDWriteRenderingParams3 *params3;
1043 static int fixme_once = 0;
1044 HRESULT hr;
1046 TRACE("%p, %p, %p.\n", iface, monitor, params);
1048 if (!fixme_once++)
1049 FIXME("(%p): monitor setting ignored\n", monitor);
1051 /* FIXME: use actual per-monitor gamma factor */
1052 hr = IDWriteFactory7_CreateCustomRenderingParams(iface, 2.0f, 0.0f, 1.0f, 0.0f, DWRITE_PIXEL_GEOMETRY_FLAT,
1053 DWRITE_RENDERING_MODE1_DEFAULT, DWRITE_GRID_FIT_MODE_DEFAULT, &params3);
1054 *params = (IDWriteRenderingParams*)params3;
1055 return hr;
1058 static HRESULT WINAPI dwritefactory_CreateCustomRenderingParams(IDWriteFactory7 *iface, FLOAT gamma,
1059 FLOAT enhancedContrast, FLOAT cleartype_level, DWRITE_PIXEL_GEOMETRY geometry, DWRITE_RENDERING_MODE mode,
1060 IDWriteRenderingParams **params)
1062 IDWriteRenderingParams3 *params3;
1063 HRESULT hr;
1065 TRACE("%p, %.8e, %.8e, %.8e, %d, %d, %p.\n", iface, gamma, enhancedContrast, cleartype_level, geometry, mode, params);
1067 if ((UINT32)mode > DWRITE_RENDERING_MODE_OUTLINE) {
1068 *params = NULL;
1069 return E_INVALIDARG;
1072 hr = IDWriteFactory7_CreateCustomRenderingParams(iface, gamma, enhancedContrast, 1.0f, cleartype_level, geometry,
1073 (DWRITE_RENDERING_MODE1)mode, DWRITE_GRID_FIT_MODE_DEFAULT, &params3);
1074 *params = (IDWriteRenderingParams*)params3;
1075 return hr;
1078 static HRESULT WINAPI dwritefactory_RegisterFontFileLoader(IDWriteFactory7 *iface, IDWriteFontFileLoader *loader)
1080 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
1081 struct fileloader *entry;
1083 TRACE("%p, %p.\n", iface, loader);
1085 if (!loader)
1086 return E_INVALIDARG;
1088 if (factory_get_file_loader(factory, loader))
1089 return DWRITE_E_ALREADYREGISTERED;
1091 entry = heap_alloc(sizeof(*entry));
1092 if (!entry)
1093 return E_OUTOFMEMORY;
1095 entry->loader = loader;
1096 list_init(&entry->fontfaces);
1097 IDWriteFontFileLoader_AddRef(loader);
1098 list_add_tail(&factory->file_loaders, &entry->entry);
1100 return S_OK;
1103 static HRESULT WINAPI dwritefactory_UnregisterFontFileLoader(IDWriteFactory7 *iface, IDWriteFontFileLoader *loader)
1105 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
1106 struct fileloader *found;
1108 TRACE("%p, %p.\n", iface, loader);
1110 if (!loader)
1111 return E_INVALIDARG;
1113 found = factory_get_file_loader(factory, loader);
1114 if (!found)
1115 return E_INVALIDARG;
1117 release_fileloader(found);
1118 return S_OK;
1121 static HRESULT WINAPI dwritefactory_CreateTextFormat(IDWriteFactory7 *iface, WCHAR const* family_name,
1122 IDWriteFontCollection *collection, DWRITE_FONT_WEIGHT weight, DWRITE_FONT_STYLE style,
1123 DWRITE_FONT_STRETCH stretch, FLOAT size, WCHAR const *locale, IDWriteTextFormat **format)
1125 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
1126 HRESULT hr;
1128 TRACE("%p, %s, %p, %d, %d, %d, %.8e, %s, %p.\n", iface, debugstr_w(family_name), collection, weight, style, stretch,
1129 size, debugstr_w(locale), format);
1131 if (collection)
1132 IDWriteFontCollection_AddRef(collection);
1133 else {
1134 collection = (IDWriteFontCollection *)factory_get_system_collection(factory);
1135 if (!collection) {
1136 *format = NULL;
1137 return E_FAIL;
1141 hr = create_textformat(family_name, collection, weight, style, stretch, size, locale, format);
1142 IDWriteFontCollection_Release(collection);
1143 return hr;
1146 static HRESULT WINAPI dwritefactory_CreateTypography(IDWriteFactory7 *iface, IDWriteTypography **typography)
1148 TRACE("%p, %p.\n", iface, typography);
1150 return create_typography(typography);
1153 static HRESULT WINAPI dwritefactory_GetGdiInterop(IDWriteFactory7 *iface, IDWriteGdiInterop **gdi_interop)
1155 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
1156 HRESULT hr = S_OK;
1158 TRACE("%p, %p.\n", iface, gdi_interop);
1160 if (factory->gdiinterop)
1161 IDWriteGdiInterop1_AddRef(factory->gdiinterop);
1162 else
1163 hr = create_gdiinterop(iface, &factory->gdiinterop);
1165 *gdi_interop = (IDWriteGdiInterop *)factory->gdiinterop;
1167 return hr;
1170 static HRESULT WINAPI dwritefactory_CreateTextLayout(IDWriteFactory7 *iface, WCHAR const* string,
1171 UINT32 length, IDWriteTextFormat *format, FLOAT max_width, FLOAT max_height, IDWriteTextLayout **layout)
1173 struct textlayout_desc desc;
1175 TRACE("%p, %s:%u, %p, %.8e, %.8e, %p.\n", iface, debugstr_wn(string, length), length, format, max_width, max_height, layout);
1177 desc.factory = iface;
1178 desc.string = string;
1179 desc.length = length;
1180 desc.format = format;
1181 desc.max_width = max_width;
1182 desc.max_height = max_height;
1183 desc.is_gdi_compatible = FALSE;
1184 desc.ppdip = 1.0f;
1185 desc.transform = NULL;
1186 desc.use_gdi_natural = FALSE;
1187 return create_textlayout(&desc, layout);
1190 static HRESULT WINAPI dwritefactory_CreateGdiCompatibleTextLayout(IDWriteFactory7 *iface, WCHAR const* string,
1191 UINT32 length, IDWriteTextFormat *format, FLOAT max_width, FLOAT max_height, FLOAT pixels_per_dip,
1192 DWRITE_MATRIX const* transform, BOOL use_gdi_natural, IDWriteTextLayout **layout)
1194 struct textlayout_desc desc;
1196 TRACE("%p, %s:%u, %p, %.8e, %.8e, %.8e, %p, %d, %p.\n", iface, debugstr_wn(string, length), length, format,
1197 max_width, max_height, pixels_per_dip, transform, use_gdi_natural, layout);
1199 desc.factory = iface;
1200 desc.string = string;
1201 desc.length = length;
1202 desc.format = format;
1203 desc.max_width = max_width;
1204 desc.max_height = max_height;
1205 desc.is_gdi_compatible = TRUE;
1206 desc.ppdip = pixels_per_dip;
1207 desc.transform = transform;
1208 desc.use_gdi_natural = use_gdi_natural;
1209 return create_textlayout(&desc, layout);
1212 static HRESULT WINAPI dwritefactory_CreateEllipsisTrimmingSign(IDWriteFactory7 *iface, IDWriteTextFormat *format,
1213 IDWriteInlineObject **trimming_sign)
1215 TRACE("%p, %p, %p.\n", iface, format, trimming_sign);
1217 return create_trimmingsign(iface, format, trimming_sign);
1220 static HRESULT WINAPI dwritefactory_CreateTextAnalyzer(IDWriteFactory7 *iface, IDWriteTextAnalyzer **analyzer)
1222 TRACE("%p, %p.\n", iface, analyzer);
1224 *analyzer = get_text_analyzer();
1226 return S_OK;
1229 static HRESULT WINAPI dwritefactory_CreateNumberSubstitution(IDWriteFactory7 *iface,
1230 DWRITE_NUMBER_SUBSTITUTION_METHOD method, WCHAR const* locale, BOOL ignore_user_override,
1231 IDWriteNumberSubstitution **substitution)
1233 TRACE("%p, %d, %s, %d, %p.\n", iface, method, debugstr_w(locale), ignore_user_override, substitution);
1235 return create_numbersubstitution(method, locale, ignore_user_override, substitution);
1238 static inline void dwrite_matrix_multiply(DWRITE_MATRIX *a, const DWRITE_MATRIX *b)
1240 DWRITE_MATRIX tmp = *a;
1242 a->m11 = tmp.m11 * b->m11 + tmp.m12 * b->m21;
1243 a->m12 = tmp.m11 * b->m12 + tmp.m12 * b->m22;
1244 a->m21 = tmp.m21 * b->m11 + tmp.m22 * b->m21;
1245 a->m22 = tmp.m21 * b->m12 + tmp.m22 * b->m22;
1246 a->dx = tmp.dx * b->m11 + tmp.dy * b->m21 + b->dx;
1247 a->dy = tmp.dy * b->m12 + tmp.dy * b->m22 + b->dx;
1250 static HRESULT WINAPI dwritefactory_CreateGlyphRunAnalysis(IDWriteFactory7 *iface, DWRITE_GLYPH_RUN const *run,
1251 FLOAT ppdip, DWRITE_MATRIX const* transform, DWRITE_RENDERING_MODE rendering_mode,
1252 DWRITE_MEASURING_MODE measuring_mode, FLOAT originX, FLOAT originY, IDWriteGlyphRunAnalysis **analysis)
1254 struct glyphrunanalysis_desc desc;
1255 DWRITE_MATRIX m, scale = { 0 };
1257 TRACE("%p, %p, %.8e, %p, %d, %d, %.8e, %.8e, %p.\n", iface, run, ppdip, transform, rendering_mode,
1258 measuring_mode, originX, originY, analysis);
1260 if (ppdip <= 0.0f) {
1261 *analysis = NULL;
1262 return E_INVALIDARG;
1265 m = transform ? *transform : identity;
1266 scale.m11 = ppdip;
1267 scale.m22 = ppdip;
1268 dwrite_matrix_multiply(&m, &scale);
1269 desc.run = run;
1270 desc.transform = &m;
1271 desc.rendering_mode = (DWRITE_RENDERING_MODE1)rendering_mode;
1272 desc.measuring_mode = measuring_mode;
1273 desc.gridfit_mode = DWRITE_GRID_FIT_MODE_DEFAULT;
1274 desc.aa_mode = DWRITE_TEXT_ANTIALIAS_MODE_CLEARTYPE;
1275 desc.origin.x = originX;
1276 desc.origin.y = originY;
1277 return create_glyphrunanalysis(&desc, analysis);
1280 static HRESULT WINAPI dwritefactory1_GetEudcFontCollection(IDWriteFactory7 *iface, IDWriteFontCollection **collection,
1281 BOOL check_for_updates)
1283 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
1284 HRESULT hr = S_OK;
1286 TRACE("%p, %p, %d.\n", iface, collection, check_for_updates);
1288 if (check_for_updates)
1289 FIXME("checking for eudc updates not implemented\n");
1291 if (factory->eudc_collection)
1292 IDWriteFontCollection1_AddRef(factory->eudc_collection);
1293 else {
1294 IDWriteFontCollection3 *eudc_collection;
1296 if (FAILED(hr = get_eudc_fontcollection(iface, &eudc_collection)))
1298 *collection = NULL;
1299 WARN("Failed to get EUDC collection, hr %#x.\n", hr);
1300 return hr;
1303 if (InterlockedCompareExchangePointer((void **)&factory->eudc_collection, eudc_collection, NULL))
1304 IDWriteFontCollection3_Release(eudc_collection);
1307 *collection = (IDWriteFontCollection *)factory->eudc_collection;
1309 return hr;
1312 static HRESULT WINAPI dwritefactory1_CreateCustomRenderingParams(IDWriteFactory7 *iface, FLOAT gamma,
1313 FLOAT enhcontrast, FLOAT enhcontrast_grayscale, FLOAT cleartype_level, DWRITE_PIXEL_GEOMETRY geometry,
1314 DWRITE_RENDERING_MODE mode, IDWriteRenderingParams1** params)
1316 IDWriteRenderingParams3 *params3;
1317 HRESULT hr;
1319 TRACE("%p, %.8e, %.8e, %.8e, %.8e, %d, %d, %p.\n", iface, gamma, enhcontrast, enhcontrast_grayscale,
1320 cleartype_level, geometry, mode, params);
1322 if ((UINT32)mode > DWRITE_RENDERING_MODE_OUTLINE) {
1323 *params = NULL;
1324 return E_INVALIDARG;
1327 hr = IDWriteFactory7_CreateCustomRenderingParams(iface, gamma, enhcontrast, enhcontrast_grayscale,
1328 cleartype_level, geometry, (DWRITE_RENDERING_MODE1)mode, DWRITE_GRID_FIT_MODE_DEFAULT, &params3);
1329 *params = (IDWriteRenderingParams1*)params3;
1330 return hr;
1333 static HRESULT WINAPI dwritefactory2_GetSystemFontFallback(IDWriteFactory7 *iface, IDWriteFontFallback **fallback)
1335 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
1337 TRACE("%p, %p.\n", iface, fallback);
1339 *fallback = NULL;
1341 if (!factory->fallback)
1343 HRESULT hr = create_system_fontfallback(iface, &factory->fallback);
1344 if (FAILED(hr))
1345 return hr;
1348 *fallback = (IDWriteFontFallback *)factory->fallback;
1349 IDWriteFontFallback_AddRef(*fallback);
1350 return S_OK;
1353 static HRESULT WINAPI dwritefactory2_CreateFontFallbackBuilder(IDWriteFactory7 *iface,
1354 IDWriteFontFallbackBuilder **fallbackbuilder)
1356 TRACE("%p, %p.\n", iface, fallbackbuilder);
1358 return create_fontfallback_builder(iface, fallbackbuilder);
1361 static HRESULT WINAPI dwritefactory2_TranslateColorGlyphRun(IDWriteFactory7 *iface, FLOAT originX, FLOAT originY,
1362 const DWRITE_GLYPH_RUN *run, const DWRITE_GLYPH_RUN_DESCRIPTION *rundescr, DWRITE_MEASURING_MODE mode,
1363 const DWRITE_MATRIX *transform, UINT32 palette, IDWriteColorGlyphRunEnumerator **colorlayers)
1365 TRACE("%p, %.8e, %.8e, %p, %p, %d, %p, %u, %p.\n", iface, originX, originY, run, rundescr, mode,
1366 transform, palette, colorlayers);
1368 return create_colorglyphenum(originX, originY, run, rundescr, mode, transform, palette, colorlayers);
1371 static HRESULT WINAPI dwritefactory2_CreateCustomRenderingParams(IDWriteFactory7 *iface, FLOAT gamma, FLOAT contrast,
1372 FLOAT grayscalecontrast, FLOAT cleartype_level, DWRITE_PIXEL_GEOMETRY geometry, DWRITE_RENDERING_MODE mode,
1373 DWRITE_GRID_FIT_MODE gridfit, IDWriteRenderingParams2 **params)
1375 IDWriteRenderingParams3 *params3;
1376 HRESULT hr;
1378 TRACE("%p, %.8e, %.8e, %.8e, %.8e, %d, %d, %d, %p.\n", iface, gamma, contrast, grayscalecontrast, cleartype_level,
1379 geometry, mode, gridfit, params);
1381 if ((UINT32)mode > DWRITE_RENDERING_MODE_OUTLINE) {
1382 *params = NULL;
1383 return E_INVALIDARG;
1386 hr = IDWriteFactory7_CreateCustomRenderingParams(iface, gamma, contrast, grayscalecontrast,
1387 cleartype_level, geometry, (DWRITE_RENDERING_MODE1)mode, DWRITE_GRID_FIT_MODE_DEFAULT, &params3);
1388 *params = (IDWriteRenderingParams2*)params3;
1389 return hr;
1392 static HRESULT factory_create_glyphrun_analysis(const DWRITE_GLYPH_RUN *run, const DWRITE_MATRIX *transform,
1393 DWRITE_RENDERING_MODE1 rendering_mode, DWRITE_MEASURING_MODE measuring_mode, DWRITE_GRID_FIT_MODE gridfit_mode,
1394 DWRITE_TEXT_ANTIALIAS_MODE aa_mode, FLOAT originX, FLOAT originY, IDWriteGlyphRunAnalysis **analysis)
1396 struct glyphrunanalysis_desc desc;
1398 desc.run = run;
1399 desc.transform = transform;
1400 desc.rendering_mode = rendering_mode;
1401 desc.measuring_mode = measuring_mode;
1402 desc.gridfit_mode = gridfit_mode;
1403 desc.aa_mode = aa_mode;
1404 desc.origin.x = originX;
1405 desc.origin.y = originY;
1406 return create_glyphrunanalysis(&desc, analysis);
1409 static HRESULT WINAPI dwritefactory2_CreateGlyphRunAnalysis(IDWriteFactory7 *iface, const DWRITE_GLYPH_RUN *run,
1410 const DWRITE_MATRIX *transform, DWRITE_RENDERING_MODE rendering_mode, DWRITE_MEASURING_MODE measuring_mode,
1411 DWRITE_GRID_FIT_MODE gridfit_mode, DWRITE_TEXT_ANTIALIAS_MODE aa_mode, FLOAT originX, FLOAT originY,
1412 IDWriteGlyphRunAnalysis **analysis)
1414 TRACE("%p, %p, %p, %d, %d, %d, %d, %.8e, %.8e, %p.\n", iface, run, transform, rendering_mode, measuring_mode,
1415 gridfit_mode, aa_mode, originX, originY, analysis);
1417 return factory_create_glyphrun_analysis(run, transform, (DWRITE_RENDERING_MODE1)rendering_mode, measuring_mode,
1418 gridfit_mode, aa_mode, originX, originY, analysis);
1421 static HRESULT WINAPI dwritefactory3_CreateGlyphRunAnalysis(IDWriteFactory7 *iface, DWRITE_GLYPH_RUN const *run,
1422 DWRITE_MATRIX const *transform, DWRITE_RENDERING_MODE1 rendering_mode, DWRITE_MEASURING_MODE measuring_mode,
1423 DWRITE_GRID_FIT_MODE gridfit_mode, DWRITE_TEXT_ANTIALIAS_MODE aa_mode, FLOAT originX, FLOAT originY,
1424 IDWriteGlyphRunAnalysis **analysis)
1426 TRACE("%p, %p, %p, %d, %d, %d, %d, %.8e, %.8e, %p.\n", iface, run, transform, rendering_mode, measuring_mode,
1427 gridfit_mode, aa_mode, originX, originY, analysis);
1429 return factory_create_glyphrun_analysis(run, transform, rendering_mode, measuring_mode, gridfit_mode,
1430 aa_mode, originX, originY, analysis);
1433 static HRESULT WINAPI dwritefactory3_CreateCustomRenderingParams(IDWriteFactory7 *iface, FLOAT gamma, FLOAT contrast,
1434 FLOAT grayscale_contrast, FLOAT cleartype_level, DWRITE_PIXEL_GEOMETRY pixel_geometry,
1435 DWRITE_RENDERING_MODE1 rendering_mode, DWRITE_GRID_FIT_MODE gridfit_mode, IDWriteRenderingParams3 **params)
1437 TRACE("%p, %.8e, %.8e, %.8e, %.8e, %d, %d, %d, %p.\n", iface, gamma, contrast, grayscale_contrast, cleartype_level,
1438 pixel_geometry, rendering_mode, gridfit_mode, params);
1440 return create_renderingparams(gamma, contrast, grayscale_contrast, cleartype_level, pixel_geometry, rendering_mode,
1441 gridfit_mode, params);
1444 static HRESULT WINAPI dwritefactory3_CreateFontFaceReference_(IDWriteFactory7 *iface, IDWriteFontFile *file,
1445 UINT32 index, DWRITE_FONT_SIMULATIONS simulations, IDWriteFontFaceReference **reference)
1447 TRACE("%p, %p, %u, %x, %p.\n", iface, file, index, simulations, reference);
1449 return create_fontfacereference(iface, file, index, simulations, NULL, 0, (IDWriteFontFaceReference1 **)reference);
1452 static HRESULT WINAPI dwritefactory3_CreateFontFaceReference(IDWriteFactory7 *iface, WCHAR const *path,
1453 FILETIME const *writetime, UINT32 index, DWRITE_FONT_SIMULATIONS simulations,
1454 IDWriteFontFaceReference **reference)
1456 IDWriteFontFile *file;
1457 HRESULT hr;
1459 TRACE("%p, %s, %p, %u, %#x, %p.\n", iface, debugstr_w(path), writetime, index, simulations, reference);
1461 hr = IDWriteFactory7_CreateFontFileReference(iface, path, writetime, &file);
1462 if (FAILED(hr))
1464 *reference = NULL;
1465 return hr;
1468 hr = create_fontfacereference(iface, file, index, simulations, NULL, 0, (IDWriteFontFaceReference1 **)reference);
1469 IDWriteFontFile_Release(file);
1470 return hr;
1473 static HRESULT WINAPI dwritefactory3_GetSystemFontSet(IDWriteFactory7 *iface, IDWriteFontSet **fontset)
1475 FIXME("%p, %p: stub\n", iface, fontset);
1477 return E_NOTIMPL;
1480 static HRESULT WINAPI dwritefactory3_CreateFontSetBuilder(IDWriteFactory7 *iface, IDWriteFontSetBuilder **builder)
1482 FIXME("%p, %p: stub\n", iface, builder);
1484 return E_NOTIMPL;
1487 static HRESULT WINAPI dwritefactory3_CreateFontCollectionFromFontSet(IDWriteFactory7 *iface, IDWriteFontSet *fontset,
1488 IDWriteFontCollection1 **collection)
1490 FIXME("%p, %p, %p: stub\n", iface, fontset, collection);
1492 return E_NOTIMPL;
1495 static HRESULT WINAPI dwritefactory3_GetSystemFontCollection(IDWriteFactory7 *iface, BOOL include_downloadable,
1496 IDWriteFontCollection1 **collection, BOOL check_for_updates)
1498 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
1500 TRACE("%p, %d, %p, %d.\n", iface, include_downloadable, collection, check_for_updates);
1502 if (include_downloadable)
1503 FIXME("remote fonts are not supported\n");
1505 if (check_for_updates)
1506 FIXME("checking for system font updates not implemented\n");
1508 *collection = factory_get_system_collection(factory);
1510 return *collection ? S_OK : E_FAIL;
1513 static HRESULT WINAPI dwritefactory3_GetFontDownloadQueue(IDWriteFactory7 *iface, IDWriteFontDownloadQueue **queue)
1515 FIXME("%p, %p: stub\n", iface, queue);
1517 return E_NOTIMPL;
1520 static HRESULT WINAPI dwritefactory4_TranslateColorGlyphRun(IDWriteFactory7 *iface, D2D1_POINT_2F baseline_origin,
1521 DWRITE_GLYPH_RUN const *run, DWRITE_GLYPH_RUN_DESCRIPTION const *run_desc,
1522 DWRITE_GLYPH_IMAGE_FORMATS desired_formats, DWRITE_MEASURING_MODE measuring_mode, DWRITE_MATRIX const *transform,
1523 UINT32 palette, IDWriteColorGlyphRunEnumerator1 **layers)
1525 FIXME("%p, %p, %p, %u, %d, %p, %u, %p: stub\n", iface, run, run_desc, desired_formats, measuring_mode,
1526 transform, palette, layers);
1528 return E_NOTIMPL;
1531 static HRESULT compute_glyph_origins(DWRITE_GLYPH_RUN const *run, DWRITE_MEASURING_MODE measuring_mode,
1532 D2D1_POINT_2F baseline_origin, DWRITE_MATRIX const *transform, D2D1_POINT_2F *origins)
1534 IDWriteFontFace1 *fontface1 = NULL;
1535 DWRITE_FONT_METRICS metrics;
1536 FLOAT rtl_factor;
1537 HRESULT hr;
1538 UINT32 i;
1540 rtl_factor = run->bidiLevel & 1 ? -1.0f : 1.0f;
1542 if (run->fontFace) {
1543 IDWriteFontFace_GetMetrics(run->fontFace, &metrics);
1544 if (FAILED(hr = IDWriteFontFace_QueryInterface(run->fontFace, &IID_IDWriteFontFace1, (void **)&fontface1)))
1545 WARN("Failed to get IDWriteFontFace1, %#x.\n", hr);
1548 for (i = 0; i < run->glyphCount; i++) {
1549 FLOAT advance;
1551 /* Use nominal advances if not provided by caller. */
1552 if (run->glyphAdvances)
1553 advance = rtl_factor * run->glyphAdvances[i];
1554 else {
1555 INT32 a;
1557 advance = 0.0f;
1558 switch (measuring_mode)
1560 case DWRITE_MEASURING_MODE_NATURAL:
1561 if (SUCCEEDED(IDWriteFontFace1_GetDesignGlyphAdvances(fontface1, 1, run->glyphIndices + i, &a,
1562 run->isSideways)))
1563 advance = rtl_factor * get_scaled_advance_width(a, run->fontEmSize, &metrics);
1564 break;
1565 case DWRITE_MEASURING_MODE_GDI_CLASSIC:
1566 case DWRITE_MEASURING_MODE_GDI_NATURAL:
1567 if (SUCCEEDED(IDWriteFontFace1_GetGdiCompatibleGlyphAdvances(fontface1, run->fontEmSize,
1568 1.0f, transform, measuring_mode == DWRITE_MEASURING_MODE_GDI_NATURAL,
1569 run->isSideways, 1, run->glyphIndices + i, &a)))
1570 advance = rtl_factor * floorf(a * run->fontEmSize / metrics.designUnitsPerEm + 0.5f);
1571 break;
1572 default:
1577 origins[i] = baseline_origin;
1579 /* Apply offsets. */
1580 if (run->glyphOffsets) {
1581 FLOAT advanceoffset = rtl_factor * run->glyphOffsets[i].advanceOffset;
1582 FLOAT ascenderoffset = -run->glyphOffsets[i].ascenderOffset;
1584 if (run->isSideways) {
1585 origins[i].x += ascenderoffset;
1586 origins[i].y += advanceoffset;
1588 else {
1589 origins[i].x += advanceoffset;
1590 origins[i].y += ascenderoffset;
1594 if (run->isSideways)
1595 baseline_origin.y += advance;
1596 else
1597 baseline_origin.x += advance;
1600 if (fontface1)
1601 IDWriteFontFace1_Release(fontface1);
1602 return S_OK;
1605 static HRESULT WINAPI dwritefactory4_ComputeGlyphOrigins_(IDWriteFactory7 *iface, DWRITE_GLYPH_RUN const *run,
1606 D2D1_POINT_2F baseline_origin, D2D1_POINT_2F *origins)
1608 TRACE("%p, %p, {%.8e,%.8e}, %p.\n", iface, run, baseline_origin.x, baseline_origin.y, origins);
1610 return compute_glyph_origins(run, DWRITE_MEASURING_MODE_NATURAL, baseline_origin, NULL, origins);
1613 static HRESULT WINAPI dwritefactory4_ComputeGlyphOrigins(IDWriteFactory7 *iface, DWRITE_GLYPH_RUN const *run,
1614 DWRITE_MEASURING_MODE measuring_mode, D2D1_POINT_2F baseline_origin, DWRITE_MATRIX const *transform,
1615 D2D1_POINT_2F *origins)
1617 TRACE("%p, %p, %d, {%.8e,%.8e}, %p, %p.\n", iface, run, measuring_mode, baseline_origin.x, baseline_origin.y,
1618 transform, origins);
1620 return compute_glyph_origins(run, measuring_mode, baseline_origin, transform, origins);
1623 static HRESULT WINAPI dwritefactory5_CreateFontSetBuilder(IDWriteFactory7 *iface, IDWriteFontSetBuilder1 **builder)
1625 FIXME("%p, %p: stub\n", iface, builder);
1627 return E_NOTIMPL;
1630 static HRESULT WINAPI dwritefactory5_CreateInMemoryFontFileLoader(IDWriteFactory7 *iface,
1631 IDWriteInMemoryFontFileLoader **loader)
1633 TRACE("%p, %p.\n", iface, loader);
1635 return create_inmemory_fileloader(loader);
1638 static HRESULT WINAPI dwritefactory5_CreateHttpFontFileLoader(IDWriteFactory7 *iface, WCHAR const *referrer_url,
1639 WCHAR const *extra_headers, IDWriteRemoteFontFileLoader **loader)
1641 FIXME("%p, %s, %s, %p: stub\n", iface, debugstr_w(referrer_url), wine_dbgstr_w(extra_headers), loader);
1643 return E_NOTIMPL;
1646 static DWRITE_CONTAINER_TYPE WINAPI dwritefactory5_AnalyzeContainerType(IDWriteFactory7 *iface, void const *data,
1647 UINT32 data_size)
1649 TRACE("%p, %p, %u.\n", iface, data, data_size);
1651 return opentype_analyze_container_type(data, data_size);
1654 static HRESULT WINAPI dwritefactory5_UnpackFontFile(IDWriteFactory7 *iface, DWRITE_CONTAINER_TYPE container_type, void const *data,
1655 UINT32 data_size, IDWriteFontFileStream **stream)
1657 FIXME("%p, %d, %p, %u, %p: stub\n", iface, container_type, data, data_size, stream);
1659 return E_NOTIMPL;
1662 static HRESULT WINAPI dwritefactory6_CreateFontFaceReference(IDWriteFactory7 *iface, IDWriteFontFile *file,
1663 UINT32 face_index, DWRITE_FONT_SIMULATIONS simulations, DWRITE_FONT_AXIS_VALUE const *axis_values,
1664 UINT32 axis_values_count, IDWriteFontFaceReference1 **reference)
1666 TRACE("%p, %p, %u, %#x, %p, %u, %p.\n", iface, file, face_index, simulations, axis_values, axis_values_count,
1667 reference);
1669 return create_fontfacereference(iface, file, face_index, simulations, axis_values, axis_values_count, reference);
1672 static HRESULT WINAPI dwritefactory6_CreateFontResource(IDWriteFactory7 *iface, IDWriteFontFile *file,
1673 UINT32 face_index, IDWriteFontResource **resource)
1675 TRACE("%p, %p, %u, %p.\n", iface, file, face_index, resource);
1677 return create_font_resource(iface, file, face_index, resource);
1680 static HRESULT WINAPI dwritefactory6_GetSystemFontSet(IDWriteFactory7 *iface, BOOL include_downloadable,
1681 IDWriteFontSet1 **fontset)
1683 FIXME("%p, %d, %p.\n", iface, include_downloadable, fontset);
1685 return E_NOTIMPL;
1688 static HRESULT WINAPI dwritefactory6_GetSystemFontCollection(IDWriteFactory7 *iface, BOOL include_downloadable,
1689 DWRITE_FONT_FAMILY_MODEL family_model, IDWriteFontCollection2 **collection)
1691 FIXME("%p, %d, %d, %p.\n", iface, include_downloadable, family_model, collection);
1693 return E_NOTIMPL;
1696 static HRESULT WINAPI dwritefactory6_CreateFontCollectionFromFontSet(IDWriteFactory7 *iface, IDWriteFontSet *fontset,
1697 DWRITE_FONT_FAMILY_MODEL family_model, IDWriteFontCollection2 **collection)
1699 FIXME("%p, %p, %d, %p.\n", iface, fontset, family_model, collection);
1701 return E_NOTIMPL;
1704 static HRESULT WINAPI dwritefactory6_CreateFontSetBuilder(IDWriteFactory7 *iface, IDWriteFontSetBuilder2 **builder)
1706 FIXME("%p, %p.\n", iface, builder);
1708 return E_NOTIMPL;
1711 static HRESULT WINAPI dwritefactory6_CreateTextFormat(IDWriteFactory7 *iface, const WCHAR *familyname,
1712 IDWriteFontCollection *collection, DWRITE_FONT_AXIS_VALUE const *axis_values, UINT32 num_axis,
1713 FLOAT fontsize, const WCHAR *localename, IDWriteTextFormat3 **format)
1715 FIXME("%p, %s, %p, %p, %u, %.8e, %s, %p.\n", iface, debugstr_w(familyname), collection, axis_values, num_axis,
1716 fontsize, debugstr_w(localename), format);
1718 return E_NOTIMPL;
1721 static HRESULT WINAPI dwritefactory7_GetSystemFontSet(IDWriteFactory7 *iface, BOOL include_downloadable,
1722 IDWriteFontSet2 **fontset)
1724 FIXME("%p, %d, %p.\n", iface, include_downloadable, fontset);
1726 return E_NOTIMPL;
1729 static HRESULT WINAPI dwritefactory7_GetSystemFontCollection(IDWriteFactory7 *iface, BOOL include_downloadable,
1730 DWRITE_FONT_FAMILY_MODEL family_model, IDWriteFontCollection3 **collection)
1732 FIXME("%p, %d, %d, %p.\n", iface, include_downloadable, family_model, collection);
1734 return E_NOTIMPL;
1737 static const struct IDWriteFactory7Vtbl dwritefactoryvtbl =
1739 dwritefactory_QueryInterface,
1740 dwritefactory_AddRef,
1741 dwritefactory_Release,
1742 dwritefactory_GetSystemFontCollection,
1743 dwritefactory_CreateCustomFontCollection,
1744 dwritefactory_RegisterFontCollectionLoader,
1745 dwritefactory_UnregisterFontCollectionLoader,
1746 dwritefactory_CreateFontFileReference,
1747 dwritefactory_CreateCustomFontFileReference,
1748 dwritefactory_CreateFontFace,
1749 dwritefactory_CreateRenderingParams,
1750 dwritefactory_CreateMonitorRenderingParams,
1751 dwritefactory_CreateCustomRenderingParams,
1752 dwritefactory_RegisterFontFileLoader,
1753 dwritefactory_UnregisterFontFileLoader,
1754 dwritefactory_CreateTextFormat,
1755 dwritefactory_CreateTypography,
1756 dwritefactory_GetGdiInterop,
1757 dwritefactory_CreateTextLayout,
1758 dwritefactory_CreateGdiCompatibleTextLayout,
1759 dwritefactory_CreateEllipsisTrimmingSign,
1760 dwritefactory_CreateTextAnalyzer,
1761 dwritefactory_CreateNumberSubstitution,
1762 dwritefactory_CreateGlyphRunAnalysis,
1763 dwritefactory1_GetEudcFontCollection,
1764 dwritefactory1_CreateCustomRenderingParams,
1765 dwritefactory2_GetSystemFontFallback,
1766 dwritefactory2_CreateFontFallbackBuilder,
1767 dwritefactory2_TranslateColorGlyphRun,
1768 dwritefactory2_CreateCustomRenderingParams,
1769 dwritefactory2_CreateGlyphRunAnalysis,
1770 dwritefactory3_CreateGlyphRunAnalysis,
1771 dwritefactory3_CreateCustomRenderingParams,
1772 dwritefactory3_CreateFontFaceReference_,
1773 dwritefactory3_CreateFontFaceReference,
1774 dwritefactory3_GetSystemFontSet,
1775 dwritefactory3_CreateFontSetBuilder,
1776 dwritefactory3_CreateFontCollectionFromFontSet,
1777 dwritefactory3_GetSystemFontCollection,
1778 dwritefactory3_GetFontDownloadQueue,
1779 dwritefactory4_TranslateColorGlyphRun,
1780 dwritefactory4_ComputeGlyphOrigins_,
1781 dwritefactory4_ComputeGlyphOrigins,
1782 dwritefactory5_CreateFontSetBuilder,
1783 dwritefactory5_CreateInMemoryFontFileLoader,
1784 dwritefactory5_CreateHttpFontFileLoader,
1785 dwritefactory5_AnalyzeContainerType,
1786 dwritefactory5_UnpackFontFile,
1787 dwritefactory6_CreateFontFaceReference,
1788 dwritefactory6_CreateFontResource,
1789 dwritefactory6_GetSystemFontSet,
1790 dwritefactory6_GetSystemFontCollection,
1791 dwritefactory6_CreateFontCollectionFromFontSet,
1792 dwritefactory6_CreateFontSetBuilder,
1793 dwritefactory6_CreateTextFormat,
1794 dwritefactory7_GetSystemFontSet,
1795 dwritefactory7_GetSystemFontCollection,
1798 static ULONG WINAPI shareddwritefactory_AddRef(IDWriteFactory7 *iface)
1800 TRACE("%p.\n", iface);
1802 return 2;
1805 static ULONG WINAPI shareddwritefactory_Release(IDWriteFactory7 *iface)
1807 TRACE("%p.\n", iface);
1809 return 1;
1812 static const struct IDWriteFactory7Vtbl shareddwritefactoryvtbl =
1814 dwritefactory_QueryInterface,
1815 shareddwritefactory_AddRef,
1816 shareddwritefactory_Release,
1817 dwritefactory_GetSystemFontCollection,
1818 dwritefactory_CreateCustomFontCollection,
1819 dwritefactory_RegisterFontCollectionLoader,
1820 dwritefactory_UnregisterFontCollectionLoader,
1821 dwritefactory_CreateFontFileReference,
1822 dwritefactory_CreateCustomFontFileReference,
1823 dwritefactory_CreateFontFace,
1824 dwritefactory_CreateRenderingParams,
1825 dwritefactory_CreateMonitorRenderingParams,
1826 dwritefactory_CreateCustomRenderingParams,
1827 dwritefactory_RegisterFontFileLoader,
1828 dwritefactory_UnregisterFontFileLoader,
1829 dwritefactory_CreateTextFormat,
1830 dwritefactory_CreateTypography,
1831 dwritefactory_GetGdiInterop,
1832 dwritefactory_CreateTextLayout,
1833 dwritefactory_CreateGdiCompatibleTextLayout,
1834 dwritefactory_CreateEllipsisTrimmingSign,
1835 dwritefactory_CreateTextAnalyzer,
1836 dwritefactory_CreateNumberSubstitution,
1837 dwritefactory_CreateGlyphRunAnalysis,
1838 dwritefactory1_GetEudcFontCollection,
1839 dwritefactory1_CreateCustomRenderingParams,
1840 dwritefactory2_GetSystemFontFallback,
1841 dwritefactory2_CreateFontFallbackBuilder,
1842 dwritefactory2_TranslateColorGlyphRun,
1843 dwritefactory2_CreateCustomRenderingParams,
1844 dwritefactory2_CreateGlyphRunAnalysis,
1845 dwritefactory3_CreateGlyphRunAnalysis,
1846 dwritefactory3_CreateCustomRenderingParams,
1847 dwritefactory3_CreateFontFaceReference_,
1848 dwritefactory3_CreateFontFaceReference,
1849 dwritefactory3_GetSystemFontSet,
1850 dwritefactory3_CreateFontSetBuilder,
1851 dwritefactory3_CreateFontCollectionFromFontSet,
1852 dwritefactory3_GetSystemFontCollection,
1853 dwritefactory3_GetFontDownloadQueue,
1854 dwritefactory4_TranslateColorGlyphRun,
1855 dwritefactory4_ComputeGlyphOrigins_,
1856 dwritefactory4_ComputeGlyphOrigins,
1857 dwritefactory5_CreateFontSetBuilder,
1858 dwritefactory5_CreateInMemoryFontFileLoader,
1859 dwritefactory5_CreateHttpFontFileLoader,
1860 dwritefactory5_AnalyzeContainerType,
1861 dwritefactory5_UnpackFontFile,
1862 dwritefactory6_CreateFontFaceReference,
1863 dwritefactory6_CreateFontResource,
1864 dwritefactory6_GetSystemFontSet,
1865 dwritefactory6_GetSystemFontCollection,
1866 dwritefactory6_CreateFontCollectionFromFontSet,
1867 dwritefactory6_CreateFontSetBuilder,
1868 dwritefactory6_CreateTextFormat,
1869 dwritefactory7_GetSystemFontSet,
1870 dwritefactory7_GetSystemFontCollection,
1873 static void init_dwritefactory(struct dwritefactory *factory, DWRITE_FACTORY_TYPE type)
1875 factory->IDWriteFactory7_iface.lpVtbl = type == DWRITE_FACTORY_TYPE_SHARED ?
1876 &shareddwritefactoryvtbl : &dwritefactoryvtbl;
1877 factory->refcount = 1;
1878 factory->localfontfileloader = get_local_fontfile_loader();
1879 factory->system_collection = NULL;
1880 factory->eudc_collection = NULL;
1881 factory->gdiinterop = NULL;
1882 factory->fallback = NULL;
1884 list_init(&factory->collection_loaders);
1885 list_init(&factory->file_loaders);
1886 list_init(&factory->localfontfaces);
1888 InitializeCriticalSection(&factory->cs);
1889 factory->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": dwritefactory.lock");
1892 void factory_detach_fontcollection(IDWriteFactory7 *iface, IDWriteFontCollection3 *collection)
1894 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
1895 InterlockedCompareExchangePointer((void **)&factory->system_collection, NULL, collection);
1896 InterlockedCompareExchangePointer((void **)&factory->eudc_collection, NULL, collection);
1897 IDWriteFactory7_Release(iface);
1900 void factory_detach_gdiinterop(IDWriteFactory7 *iface, IDWriteGdiInterop1 *interop)
1902 struct dwritefactory *factory = impl_from_IDWriteFactory7(iface);
1903 factory->gdiinterop = NULL;
1904 IDWriteFactory7_Release(iface);
1907 HRESULT WINAPI DWriteCreateFactory(DWRITE_FACTORY_TYPE type, REFIID riid, IUnknown **ret)
1909 struct dwritefactory *factory;
1910 HRESULT hr;
1912 TRACE("(%d, %s, %p)\n", type, debugstr_guid(riid), ret);
1914 *ret = NULL;
1916 if (type == DWRITE_FACTORY_TYPE_SHARED && shared_factory)
1917 return IDWriteFactory7_QueryInterface(shared_factory, riid, (void**)ret);
1919 factory = heap_alloc(sizeof(struct dwritefactory));
1920 if (!factory) return E_OUTOFMEMORY;
1922 init_dwritefactory(factory, type);
1924 if (type == DWRITE_FACTORY_TYPE_SHARED)
1925 if (InterlockedCompareExchangePointer((void **)&shared_factory, &factory->IDWriteFactory7_iface, NULL))
1927 release_shared_factory(&factory->IDWriteFactory7_iface);
1928 return IDWriteFactory7_QueryInterface(shared_factory, riid, (void**)ret);
1931 hr = IDWriteFactory7_QueryInterface(&factory->IDWriteFactory7_iface, riid, (void**)ret);
1932 IDWriteFactory7_Release(&factory->IDWriteFactory7_iface);
1933 return hr;