d2d1: Implement d2d_d3d_render_target_CreateBitmap().
[wine/multimedia.git] / dlls / dwrite / main.c
blobbcddbba3b37fcefccfdd1320503a0506175716fe
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>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
29 #include "initguid.h"
30 #include "dwrite.h"
32 #include "dwrite_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
37 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID reserved)
39 switch (reason)
41 case DLL_WINE_PREATTACH:
42 return FALSE; /* prefer native version */
43 case DLL_PROCESS_ATTACH:
44 DisableThreadLibraryCalls( hinstDLL );
45 break;
47 return TRUE;
50 struct renderingparams {
51 IDWriteRenderingParams IDWriteRenderingParams_iface;
52 LONG ref;
54 FLOAT gamma;
55 FLOAT enh_contrast;
56 FLOAT cleartype_level;
57 DWRITE_PIXEL_GEOMETRY geometry;
58 DWRITE_RENDERING_MODE mode;
61 static inline struct renderingparams *impl_from_IDWriteRenderingParams(IDWriteRenderingParams *iface)
63 return CONTAINING_RECORD(iface, struct renderingparams, IDWriteRenderingParams_iface);
66 static HRESULT WINAPI renderingparams_QueryInterface(IDWriteRenderingParams *iface, REFIID riid, void **obj)
68 struct renderingparams *This = impl_from_IDWriteRenderingParams(iface);
70 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
72 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteRenderingParams))
74 *obj = iface;
75 IDWriteRenderingParams_AddRef(iface);
76 return S_OK;
79 *obj = NULL;
81 return E_NOINTERFACE;
84 static ULONG WINAPI renderingparams_AddRef(IDWriteRenderingParams *iface)
86 struct renderingparams *This = impl_from_IDWriteRenderingParams(iface);
87 ULONG ref = InterlockedIncrement(&This->ref);
88 TRACE("(%p)->(%d)\n", This, ref);
89 return ref;
92 static ULONG WINAPI renderingparams_Release(IDWriteRenderingParams *iface)
94 struct renderingparams *This = impl_from_IDWriteRenderingParams(iface);
95 ULONG ref = InterlockedDecrement(&This->ref);
97 TRACE("(%p)->(%d)\n", This, ref);
99 if (!ref)
100 heap_free(This);
102 return ref;
105 static FLOAT WINAPI renderingparams_GetGamma(IDWriteRenderingParams *iface)
107 struct renderingparams *This = impl_from_IDWriteRenderingParams(iface);
108 TRACE("(%p)\n", This);
109 return This->gamma;
112 static FLOAT WINAPI renderingparams_GetEnhancedContrast(IDWriteRenderingParams *iface)
114 struct renderingparams *This = impl_from_IDWriteRenderingParams(iface);
115 TRACE("(%p)\n", This);
116 return This->enh_contrast;
119 static FLOAT WINAPI renderingparams_GetClearTypeLevel(IDWriteRenderingParams *iface)
121 struct renderingparams *This = impl_from_IDWriteRenderingParams(iface);
122 TRACE("(%p)\n", This);
123 return This->cleartype_level;
126 static DWRITE_PIXEL_GEOMETRY WINAPI renderingparams_GetPixelGeometry(IDWriteRenderingParams *iface)
128 struct renderingparams *This = impl_from_IDWriteRenderingParams(iface);
129 TRACE("(%p)\n", This);
130 return This->geometry;
133 static DWRITE_RENDERING_MODE WINAPI renderingparams_GetRenderingMode(IDWriteRenderingParams *iface)
135 struct renderingparams *This = impl_from_IDWriteRenderingParams(iface);
136 TRACE("(%p)\n", This);
137 return This->mode;
140 static const struct IDWriteRenderingParamsVtbl renderingparamsvtbl = {
141 renderingparams_QueryInterface,
142 renderingparams_AddRef,
143 renderingparams_Release,
144 renderingparams_GetGamma,
145 renderingparams_GetEnhancedContrast,
146 renderingparams_GetClearTypeLevel,
147 renderingparams_GetPixelGeometry,
148 renderingparams_GetRenderingMode
151 static HRESULT create_renderingparams(FLOAT gamma, FLOAT enhancedContrast, FLOAT cleartype_level,
152 DWRITE_PIXEL_GEOMETRY geometry, DWRITE_RENDERING_MODE mode, IDWriteRenderingParams **params)
154 struct renderingparams *This;
156 *params = NULL;
158 This = heap_alloc(sizeof(struct renderingparams));
159 if (!This) return E_OUTOFMEMORY;
161 This->IDWriteRenderingParams_iface.lpVtbl = &renderingparamsvtbl;
162 This->ref = 1;
164 This->gamma = gamma;
165 This->enh_contrast = enhancedContrast;
166 This->cleartype_level = cleartype_level;
167 This->geometry = geometry;
168 This->mode = mode;
170 *params = &This->IDWriteRenderingParams_iface;
172 return S_OK;
175 struct localizedpair {
176 WCHAR *locale;
177 WCHAR *string;
180 struct localizedstrings {
181 IDWriteLocalizedStrings IDWriteLocalizedStrings_iface;
182 LONG ref;
184 struct localizedpair *data;
185 UINT32 count;
186 UINT32 alloc;
189 static inline struct localizedstrings *impl_from_IDWriteLocalizedStrings(IDWriteLocalizedStrings *iface)
191 return CONTAINING_RECORD(iface, struct localizedstrings, IDWriteLocalizedStrings_iface);
194 static HRESULT WINAPI localizedstrings_QueryInterface(IDWriteLocalizedStrings *iface, REFIID riid, void **obj)
196 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
198 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
200 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteLocalizedStrings))
202 *obj = iface;
203 IDWriteLocalizedStrings_AddRef(iface);
204 return S_OK;
207 *obj = NULL;
209 return E_NOINTERFACE;
212 static ULONG WINAPI localizedstrings_AddRef(IDWriteLocalizedStrings *iface)
214 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
215 ULONG ref = InterlockedIncrement(&This->ref);
216 TRACE("(%p)->(%d)\n", This, ref);
217 return ref;
220 static ULONG WINAPI localizedstrings_Release(IDWriteLocalizedStrings *iface)
222 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
223 ULONG ref = InterlockedDecrement(&This->ref);
225 TRACE("(%p)->(%d)\n", This, ref);
227 if (!ref) {
228 unsigned int i;
230 for (i = 0; i < This->count; i++) {
231 heap_free(This->data[i].locale);
232 heap_free(This->data[i].string);
235 heap_free(This->data);
236 heap_free(This);
239 return ref;
242 static UINT32 WINAPI localizedstrings_GetCount(IDWriteLocalizedStrings *iface)
244 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
245 TRACE("(%p)\n", This);
246 return This->count;
249 static HRESULT WINAPI localizedstrings_FindLocaleName(IDWriteLocalizedStrings *iface,
250 WCHAR const *locale_name, UINT32 *index, BOOL *exists)
252 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
253 FIXME("(%p)->(%s %p %p): stub\n", This, debugstr_w(locale_name), index, exists);
254 return E_NOTIMPL;
257 static HRESULT WINAPI localizedstrings_GetLocaleNameLength(IDWriteLocalizedStrings *iface, UINT32 index, UINT32 *length)
259 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
260 FIXME("(%p)->(%u %p): stub\n", This, index, length);
261 return E_NOTIMPL;
264 static HRESULT WINAPI localizedstrings_GetLocaleName(IDWriteLocalizedStrings *iface, UINT32 index, WCHAR *locale_name, UINT32 size)
266 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
267 FIXME("(%p)->(%u %p %u): stub\n", This, index, locale_name, size);
268 return E_NOTIMPL;
271 static HRESULT WINAPI localizedstrings_GetStringLength(IDWriteLocalizedStrings *iface, UINT32 index, UINT32 *length)
273 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
275 TRACE("(%p)->(%u %p)\n", This, index, length);
277 if (index >= This->count) {
278 *length = (UINT32)-1;
279 return E_FAIL;
282 *length = strlenW(This->data[index].string);
283 return S_OK;
286 static HRESULT WINAPI localizedstrings_GetString(IDWriteLocalizedStrings *iface, UINT32 index, WCHAR *buffer, UINT32 size)
288 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
290 TRACE("(%p)->(%u %p %u)\n", This, index, buffer, size);
292 if (index >= This->count) {
293 if (buffer) *buffer = 0;
294 return E_FAIL;
297 if (size < strlenW(This->data[index].string)+1) {
298 if (buffer) *buffer = 0;
299 return E_NOT_SUFFICIENT_BUFFER;
302 strcpyW(buffer, This->data[index].string);
303 return S_OK;
306 static const IDWriteLocalizedStringsVtbl localizedstringsvtbl = {
307 localizedstrings_QueryInterface,
308 localizedstrings_AddRef,
309 localizedstrings_Release,
310 localizedstrings_GetCount,
311 localizedstrings_FindLocaleName,
312 localizedstrings_GetLocaleNameLength,
313 localizedstrings_GetLocaleName,
314 localizedstrings_GetStringLength,
315 localizedstrings_GetString
318 HRESULT create_localizedstrings(IDWriteLocalizedStrings **strings)
320 struct localizedstrings *This;
322 *strings = NULL;
324 This = heap_alloc(sizeof(struct localizedstrings));
325 if (!This) return E_OUTOFMEMORY;
327 This->IDWriteLocalizedStrings_iface.lpVtbl = &localizedstringsvtbl;
328 This->ref = 1;
329 This->count = 0;
330 This->data = heap_alloc_zero(sizeof(struct localizedpair));
331 if (!This->data) {
332 heap_free(This);
333 return E_OUTOFMEMORY;
335 This->alloc = 1;
337 *strings = &This->IDWriteLocalizedStrings_iface;
339 return S_OK;
342 HRESULT add_localizedstring(IDWriteLocalizedStrings *iface, const WCHAR *locale, const WCHAR *string)
344 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
346 if (This->count == This->alloc) {
347 This->alloc *= 2;
348 This->data = heap_realloc(This->data, This->alloc*sizeof(struct localizedpair));
351 This->data[This->count].locale = heap_strdupW(locale);
352 This->data[This->count].string = heap_strdupW(string);
353 This->count++;
355 return S_OK;
358 HRESULT clone_localizedstring(IDWriteLocalizedStrings *iface, IDWriteLocalizedStrings **strings)
360 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
361 struct localizedstrings *New;
362 int i;
364 *strings = NULL;
366 New = heap_alloc(sizeof(struct localizedstrings));
367 if (!This) return E_OUTOFMEMORY;
369 New->IDWriteLocalizedStrings_iface.lpVtbl = &localizedstringsvtbl;
370 New->ref = 1;
371 New->count = This->count;
372 New->data = heap_alloc(sizeof(struct localizedpair) * New->count);
373 if (!New->data) {
374 heap_free(New);
375 return E_OUTOFMEMORY;
377 for (i = 0; i < New->count; i++)
379 New->data[i].locale = heap_strdupW(This->data[i].locale);
380 New->data[i].string = heap_strdupW(This->data[i].string);
382 New->alloc = New->count;
384 *strings = &New->IDWriteLocalizedStrings_iface;
386 return S_OK;
389 struct dwritefactory{
390 IDWriteFactory IDWriteFactory_iface;
391 LONG ref;
393 IDWriteLocalFontFileLoader* localfontfileloader;
394 IDWriteFontCollection *system_collection;
396 IDWriteFontCollectionLoader **loaders;
397 LONG loader_count;
398 IDWriteFontFileLoader **file_loaders;
399 LONG file_loader_count;
402 static inline struct dwritefactory *impl_from_IDWriteFactory(IDWriteFactory *iface)
404 return CONTAINING_RECORD(iface, struct dwritefactory, IDWriteFactory_iface);
407 static HRESULT WINAPI dwritefactory_QueryInterface(IDWriteFactory *iface, REFIID riid, void **obj)
409 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
411 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
413 if (IsEqualIID(riid, &IID_IUnknown) ||
414 IsEqualIID(riid, &IID_IDWriteFactory))
416 *obj = iface;
417 IDWriteFactory_AddRef(iface);
418 return S_OK;
421 *obj = NULL;
423 return E_NOINTERFACE;
426 static ULONG WINAPI dwritefactory_AddRef(IDWriteFactory *iface)
428 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
429 ULONG ref = InterlockedIncrement(&This->ref);
430 TRACE("(%p)->(%d)\n", This, ref);
431 return ref;
434 static ULONG WINAPI dwritefactory_Release(IDWriteFactory *iface)
436 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
437 ULONG ref = InterlockedDecrement(&This->ref);
439 TRACE("(%p)->(%d)\n", This, ref);
441 if (!ref) {
442 int i;
443 if (This->localfontfileloader)
444 IDWriteLocalFontFileLoader_Release(This->localfontfileloader);
445 for (i = 0; i < This->loader_count; i++)
446 if (This->loaders[i])
447 IDWriteFontCollectionLoader_Release(This->loaders[i]);
448 heap_free(This->loaders);
449 for (i = 0; i < This->file_loader_count; i++)
450 if (This->file_loaders[i])
451 IDWriteFontFileLoader_Release(This->file_loaders[i]);
452 heap_free(This->file_loaders);
453 if (This->system_collection)
454 IDWriteFontCollection_Release(This->system_collection);
455 heap_free(This);
458 return ref;
461 static HRESULT WINAPI dwritefactory_GetSystemFontCollection(IDWriteFactory *iface,
462 IDWriteFontCollection **collection, BOOL check_for_updates)
464 HRESULT hr = S_OK;
465 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
466 TRACE("(%p)->(%p %d)\n", This, collection, check_for_updates);
468 if (check_for_updates)
469 FIXME("checking for system font updates not implemented\n");
471 if (!This->system_collection)
472 hr = get_system_fontcollection(&This->system_collection);
474 if (SUCCEEDED(hr))
475 IDWriteFontCollection_AddRef(This->system_collection);
477 *collection = This->system_collection;
479 return hr;
482 static HRESULT WINAPI dwritefactory_CreateCustomFontCollection(IDWriteFactory *iface,
483 IDWriteFontCollectionLoader *loader, void const *key, UINT32 key_size, IDWriteFontCollection **collection)
485 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
486 FIXME("(%p)->(%p %p %u %p): stub\n", This, loader, key, key_size, collection);
487 return E_NOTIMPL;
490 static HRESULT WINAPI dwritefactory_RegisterFontCollectionLoader(IDWriteFactory *iface,
491 IDWriteFontCollectionLoader *loader)
493 int i;
494 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
496 TRACE("(%p)->(%p)\n", This, loader);
498 for (i = 0; i < This->loader_count; i++)
499 if (This->loaders[i] == loader)
500 return DWRITE_E_ALREADYREGISTERED;
501 else if (This->loaders[i] == NULL)
502 break;
504 if (i == This->loader_count)
506 IDWriteFontCollectionLoader **new_list = NULL;
507 int new_count = 0;
509 new_count = This->loader_count * 2;
510 new_list = heap_realloc_zero(This->loaders, new_count * sizeof(*This->loaders));
512 if (!new_list)
513 return E_OUTOFMEMORY;
514 else
516 This->loader_count = new_count;
517 This->loaders = new_list;
520 IDWriteFontCollectionLoader_AddRef(loader);
521 This->loaders[i] = loader;
523 return S_OK;
526 static HRESULT WINAPI dwritefactory_UnregisterFontCollectionLoader(IDWriteFactory *iface,
527 IDWriteFontCollectionLoader *loader)
529 int i;
530 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
532 TRACE("(%p)->(%p)\n", This, loader);
534 for (i = 0; i < This->loader_count; i++)
535 if (This->loaders[i] == loader) break;
536 if (i == This->loader_count)
537 return E_INVALIDARG;
538 IDWriteFontCollectionLoader_Release(This->loaders[i]);
539 This->loaders[i] = NULL;
541 return S_OK;
544 static HRESULT WINAPI dwritefactory_CreateFontFileReference(IDWriteFactory *iface,
545 WCHAR const *path, FILETIME const *writetime, IDWriteFontFile **font_file)
547 HRESULT hr;
548 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
549 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(path), writetime, font_file);
551 if (!This->localfontfileloader)
553 hr = create_localfontfileloader(&This->localfontfileloader);
554 if (FAILED(hr))
555 return hr;
557 return create_font_file((IDWriteFontFileLoader*)This->localfontfileloader, path, sizeof(WCHAR) * (strlenW(path)+1), font_file);
560 static HRESULT WINAPI dwritefactory_CreateCustomFontFileReference(IDWriteFactory *iface,
561 void const *reference_key, UINT32 key_size, IDWriteFontFileLoader *loader, IDWriteFontFile **font_file)
563 int i;
564 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
565 HRESULT hr;
567 TRACE("(%p)->(%p %u %p %p)\n", This, reference_key, key_size, loader, font_file);
569 if (loader == NULL)
570 return E_INVALIDARG;
572 for (i = 0; i < This->file_loader_count; i++)
573 if (This->file_loaders[i] == loader) break;
574 if (i == This->file_loader_count)
575 return E_INVALIDARG;
576 hr = create_font_file(loader, reference_key, key_size, font_file);
577 return hr;
580 static HRESULT WINAPI dwritefactory_CreateFontFace(IDWriteFactory *iface,
581 DWRITE_FONT_FACE_TYPE facetype, UINT32 files_number, IDWriteFontFile* const* font_files,
582 UINT32 index, DWRITE_FONT_SIMULATIONS sim_flags, IDWriteFontFace **font_face)
584 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
585 TRACE("(%p)->(%d %u %p %u 0x%x %p)\n", This, facetype, files_number, font_files, index, sim_flags, font_face);
586 return font_create_fontface(iface, facetype, files_number, font_files, index, sim_flags, font_face);
589 static HRESULT WINAPI dwritefactory_CreateRenderingParams(IDWriteFactory *iface, IDWriteRenderingParams **params)
591 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
592 HMONITOR monitor;
593 POINT pt;
595 TRACE("(%p)->(%p)\n", This, params);
597 pt.x = pt.y = 0;
598 monitor = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
599 return IDWriteFactory_CreateMonitorRenderingParams(iface, monitor, params);
602 static HRESULT WINAPI dwritefactory_CreateMonitorRenderingParams(IDWriteFactory *iface, HMONITOR monitor,
603 IDWriteRenderingParams **params)
605 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
606 static int fixme_once = 0;
608 TRACE("(%p)->(%p %p)\n", This, monitor, params);
610 if (!fixme_once++)
611 FIXME("(%p): monitor setting ignored\n", monitor);
612 return IDWriteFactory_CreateCustomRenderingParams(iface, 0.0, 0.0, 0.0, DWRITE_PIXEL_GEOMETRY_FLAT,
613 DWRITE_RENDERING_MODE_DEFAULT, params);
616 static HRESULT WINAPI dwritefactory_CreateCustomRenderingParams(IDWriteFactory *iface, FLOAT gamma, FLOAT enhancedContrast,
617 FLOAT cleartype_level, DWRITE_PIXEL_GEOMETRY geometry, DWRITE_RENDERING_MODE mode, IDWriteRenderingParams **params)
619 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
620 TRACE("(%p)->(%f %f %f %d %d %p)\n", This, gamma, enhancedContrast, cleartype_level, geometry, mode, params);
621 return create_renderingparams(gamma, enhancedContrast, cleartype_level, geometry, mode, params);
624 static HRESULT WINAPI dwritefactory_RegisterFontFileLoader(IDWriteFactory *iface, IDWriteFontFileLoader *loader)
626 int i;
627 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
628 TRACE("(%p)->(%p)\n", This, loader);
630 if (!loader)
631 return E_INVALIDARG;
633 for (i = 0; i < This->file_loader_count; i++)
634 if (This->file_loaders[i] == loader)
635 return DWRITE_E_ALREADYREGISTERED;
636 else if (This->file_loaders[i] == NULL)
637 break;
639 if (i == This->file_loader_count)
641 IDWriteFontFileLoader **new_list = NULL;
642 int new_count = 0;
644 new_count = This->file_loader_count * 2;
645 new_list = heap_realloc_zero(This->file_loaders, new_count * sizeof(*This->file_loaders));
647 if (!new_list)
648 return E_OUTOFMEMORY;
649 else
651 This->file_loader_count = new_count;
652 This->file_loaders = new_list;
655 IDWriteFontFileLoader_AddRef(loader);
656 This->file_loaders[i] = loader;
658 return S_OK;
661 static HRESULT WINAPI dwritefactory_UnregisterFontFileLoader(IDWriteFactory *iface, IDWriteFontFileLoader *loader)
663 int i;
664 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
665 TRACE("(%p)->(%p)\n", This, loader);
667 for (i = 0; i < This->file_loader_count; i++)
668 if (This->file_loaders[i] == loader) break;
669 if (i == This->file_loader_count)
670 return E_INVALIDARG;
671 IDWriteFontFileLoader_Release(This->file_loaders[i]);
672 This->file_loaders[i] = NULL;
674 return S_OK;
677 static HRESULT WINAPI dwritefactory_CreateTextFormat(IDWriteFactory *iface, WCHAR const* family_name,
678 IDWriteFontCollection *collection, DWRITE_FONT_WEIGHT weight, DWRITE_FONT_STYLE style,
679 DWRITE_FONT_STRETCH stretch, FLOAT size, WCHAR const *locale, IDWriteTextFormat **format)
681 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
682 TRACE("(%p)->(%s %p %d %d %d %f %s %p)\n", This, debugstr_w(family_name), collection, weight, style, stretch,
683 size, debugstr_w(locale), format);
685 if (!collection)
687 HRESULT hr = IDWriteFactory_GetSystemFontCollection(iface, &collection, FALSE);
688 if (hr != S_OK)
689 return hr;
690 /* Our ref count is 1 too many, since we will add ref in create_textformat */
691 IDWriteFontCollection_Release(This->system_collection);
693 return create_textformat(family_name, collection, weight, style, stretch, size, locale, format);
696 static HRESULT WINAPI dwritefactory_CreateTypography(IDWriteFactory *iface, IDWriteTypography **typography)
698 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
699 FIXME("(%p)->(%p): stub\n", This, typography);
700 return E_NOTIMPL;
703 static HRESULT WINAPI dwritefactory_GetGdiInterop(IDWriteFactory *iface, IDWriteGdiInterop **gdi_interop)
705 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
706 TRACE("(%p)->(%p)\n", This, gdi_interop);
707 return get_gdiinterop(gdi_interop);
710 static HRESULT WINAPI dwritefactory_CreateTextLayout(IDWriteFactory *iface, WCHAR const* string,
711 UINT32 len, IDWriteTextFormat *format, FLOAT max_width, FLOAT max_height, IDWriteTextLayout **layout)
713 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
714 TRACE("(%p)->(%s %u %p %f %f %p)\n", This, debugstr_w(string), len, format, max_width, max_height, layout);
716 if (!format) return E_INVALIDARG;
717 return create_textlayout(string, len, format, max_width, max_height, layout);
720 static HRESULT WINAPI dwritefactory_CreateGdiCompatibleTextLayout(IDWriteFactory *iface, WCHAR const* string,
721 UINT32 len, IDWriteTextFormat *format, FLOAT layout_width, FLOAT layout_height, FLOAT pixels_per_dip,
722 DWRITE_MATRIX const* transform, BOOL use_gdi_natural, IDWriteTextLayout **layout)
724 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
725 FIXME("(%p)->(%s:%u %p %f %f %f %p %d %p): semi-stub\n", This, debugstr_wn(string, len), len, format, layout_width, layout_height,
726 pixels_per_dip, transform, use_gdi_natural, layout);
728 if (!format) return E_INVALIDARG;
729 return create_textlayout(string, len, format, layout_width, layout_height, layout);
732 static HRESULT WINAPI dwritefactory_CreateEllipsisTrimmingSign(IDWriteFactory *iface, IDWriteTextFormat *format,
733 IDWriteInlineObject **trimming_sign)
735 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
736 FIXME("(%p)->(%p %p): semi-stub\n", This, format, trimming_sign);
737 return create_trimmingsign(trimming_sign);
740 static HRESULT WINAPI dwritefactory_CreateTextAnalyzer(IDWriteFactory *iface, IDWriteTextAnalyzer **analyzer)
742 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
743 TRACE("(%p)->(%p)\n", This, analyzer);
744 return get_textanalyzer(analyzer);
747 static HRESULT WINAPI dwritefactory_CreateNumberSubstitution(IDWriteFactory *iface, DWRITE_NUMBER_SUBSTITUTION_METHOD method,
748 WCHAR const* locale, BOOL ignore_user_override, IDWriteNumberSubstitution **substitution)
750 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
751 FIXME("(%p)->(%d %s %d %p): stub\n", This, method, debugstr_w(locale), ignore_user_override, substitution);
752 return E_NOTIMPL;
755 static HRESULT WINAPI dwritefactory_CreateGlyphRunAnalysis(IDWriteFactory *iface, DWRITE_GLYPH_RUN const *glyph_run,
756 FLOAT pixels_per_dip, DWRITE_MATRIX const* transform, DWRITE_RENDERING_MODE rendering_mode,
757 DWRITE_MEASURING_MODE measuring_mode, FLOAT baseline_x, FLOAT baseline_y, IDWriteGlyphRunAnalysis **analysis)
759 struct dwritefactory *This = impl_from_IDWriteFactory(iface);
760 FIXME("(%p)->(%p %f %p %d %d %f %f %p): stub\n", This, glyph_run, pixels_per_dip, transform, rendering_mode,
761 measuring_mode, baseline_x, baseline_y, analysis);
762 return E_NOTIMPL;
765 static const struct IDWriteFactoryVtbl dwritefactoryvtbl = {
766 dwritefactory_QueryInterface,
767 dwritefactory_AddRef,
768 dwritefactory_Release,
769 dwritefactory_GetSystemFontCollection,
770 dwritefactory_CreateCustomFontCollection,
771 dwritefactory_RegisterFontCollectionLoader,
772 dwritefactory_UnregisterFontCollectionLoader,
773 dwritefactory_CreateFontFileReference,
774 dwritefactory_CreateCustomFontFileReference,
775 dwritefactory_CreateFontFace,
776 dwritefactory_CreateRenderingParams,
777 dwritefactory_CreateMonitorRenderingParams,
778 dwritefactory_CreateCustomRenderingParams,
779 dwritefactory_RegisterFontFileLoader,
780 dwritefactory_UnregisterFontFileLoader,
781 dwritefactory_CreateTextFormat,
782 dwritefactory_CreateTypography,
783 dwritefactory_GetGdiInterop,
784 dwritefactory_CreateTextLayout,
785 dwritefactory_CreateGdiCompatibleTextLayout,
786 dwritefactory_CreateEllipsisTrimmingSign,
787 dwritefactory_CreateTextAnalyzer,
788 dwritefactory_CreateNumberSubstitution,
789 dwritefactory_CreateGlyphRunAnalysis
792 HRESULT WINAPI DWriteCreateFactory(DWRITE_FACTORY_TYPE type, REFIID riid, IUnknown **factory)
794 struct dwritefactory *This;
796 TRACE("(%d, %s, %p)\n", type, debugstr_guid(riid), factory);
798 if (!IsEqualIID(riid, &IID_IDWriteFactory)) return E_FAIL;
800 This = heap_alloc(sizeof(struct dwritefactory));
801 if (!This) return E_OUTOFMEMORY;
803 This->IDWriteFactory_iface.lpVtbl = &dwritefactoryvtbl;
804 This->ref = 1;
805 This->localfontfileloader = NULL;
806 This->loader_count = 2;
807 This->loaders = heap_alloc_zero(sizeof(*This->loaders) * 2);
808 This->file_loader_count = 2;
809 This->file_loaders = heap_alloc_zero(sizeof(*This->file_loaders) * 2);
810 This->system_collection = NULL;
812 *factory = (IUnknown*)&This->IDWriteFactory_iface;
814 return S_OK;