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
32 #include "dwrite_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dwrite
);
37 static IDWriteFactory5
*shared_factory
;
38 static void release_shared_factory(IDWriteFactory5
*);
40 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD reason
, LPVOID reserved
)
44 case DLL_PROCESS_ATTACH
:
45 DisableThreadLibraryCalls( hinstDLL
);
48 case DLL_PROCESS_DETACH
:
50 release_shared_factory(shared_factory
);
56 struct renderingparams
{
57 IDWriteRenderingParams3 IDWriteRenderingParams3_iface
;
62 FLOAT grayscalecontrast
;
63 FLOAT cleartype_level
;
64 DWRITE_PIXEL_GEOMETRY geometry
;
65 DWRITE_RENDERING_MODE1 mode
;
66 DWRITE_GRID_FIT_MODE gridfit
;
69 static inline struct renderingparams
*impl_from_IDWriteRenderingParams3(IDWriteRenderingParams3
*iface
)
71 return CONTAINING_RECORD(iface
, struct renderingparams
, IDWriteRenderingParams3_iface
);
74 static HRESULT WINAPI
renderingparams_QueryInterface(IDWriteRenderingParams3
*iface
, REFIID riid
, void **obj
)
76 struct renderingparams
*This
= impl_from_IDWriteRenderingParams3(iface
);
78 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
80 if (IsEqualIID(riid
, &IID_IDWriteRenderingParams3
) ||
81 IsEqualIID(riid
, &IID_IDWriteRenderingParams2
) ||
82 IsEqualIID(riid
, &IID_IDWriteRenderingParams1
) ||
83 IsEqualIID(riid
, &IID_IDWriteRenderingParams
) ||
84 IsEqualIID(riid
, &IID_IUnknown
))
87 IDWriteRenderingParams3_AddRef(iface
);
96 static ULONG WINAPI
renderingparams_AddRef(IDWriteRenderingParams3
*iface
)
98 struct renderingparams
*This
= impl_from_IDWriteRenderingParams3(iface
);
99 ULONG ref
= InterlockedIncrement(&This
->ref
);
100 TRACE("(%p)->(%d)\n", This
, ref
);
104 static ULONG WINAPI
renderingparams_Release(IDWriteRenderingParams3
*iface
)
106 struct renderingparams
*This
= impl_from_IDWriteRenderingParams3(iface
);
107 ULONG ref
= InterlockedDecrement(&This
->ref
);
109 TRACE("(%p)->(%d)\n", This
, ref
);
117 static FLOAT WINAPI
renderingparams_GetGamma(IDWriteRenderingParams3
*iface
)
119 struct renderingparams
*This
= impl_from_IDWriteRenderingParams3(iface
);
120 TRACE("(%p)\n", This
);
124 static FLOAT WINAPI
renderingparams_GetEnhancedContrast(IDWriteRenderingParams3
*iface
)
126 struct renderingparams
*This
= impl_from_IDWriteRenderingParams3(iface
);
127 TRACE("(%p)\n", This
);
128 return This
->contrast
;
131 static FLOAT WINAPI
renderingparams_GetClearTypeLevel(IDWriteRenderingParams3
*iface
)
133 struct renderingparams
*This
= impl_from_IDWriteRenderingParams3(iface
);
134 TRACE("(%p)\n", This
);
135 return This
->cleartype_level
;
138 static DWRITE_PIXEL_GEOMETRY WINAPI
renderingparams_GetPixelGeometry(IDWriteRenderingParams3
*iface
)
140 struct renderingparams
*This
= impl_from_IDWriteRenderingParams3(iface
);
141 TRACE("(%p)\n", This
);
142 return This
->geometry
;
145 static DWRITE_RENDERING_MODE
rendering_mode_from_mode1(DWRITE_RENDERING_MODE1 mode
)
147 static const DWRITE_RENDERING_MODE rendering_modes
[] = {
148 DWRITE_RENDERING_MODE_DEFAULT
, /* DWRITE_RENDERING_MODE1_DEFAULT */
149 DWRITE_RENDERING_MODE_ALIASED
, /* DWRITE_RENDERING_MODE1_ALIASED */
150 DWRITE_RENDERING_MODE_GDI_CLASSIC
, /* DWRITE_RENDERING_MODE1_GDI_CLASSIC */
151 DWRITE_RENDERING_MODE_GDI_NATURAL
, /* DWRITE_RENDERING_MODE1_GDI_NATURAL */
152 DWRITE_RENDERING_MODE_NATURAL
, /* DWRITE_RENDERING_MODE1_NATURAL */
153 DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC
, /* DWRITE_RENDERING_MODE1_NATURAL_SYMMETRIC */
154 DWRITE_RENDERING_MODE_OUTLINE
, /* DWRITE_RENDERING_MODE1_OUTLINE */
155 DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC
, /* DWRITE_RENDERING_MODE1_NATURAL_SYMMETRIC_DOWNSAMPLED */
158 return rendering_modes
[mode
];
161 static DWRITE_RENDERING_MODE WINAPI
renderingparams_GetRenderingMode(IDWriteRenderingParams3
*iface
)
163 struct renderingparams
*This
= impl_from_IDWriteRenderingParams3(iface
);
165 TRACE("(%p)\n", This
);
167 return rendering_mode_from_mode1(This
->mode
);
170 static FLOAT WINAPI
renderingparams1_GetGrayscaleEnhancedContrast(IDWriteRenderingParams3
*iface
)
172 struct renderingparams
*This
= impl_from_IDWriteRenderingParams3(iface
);
173 TRACE("(%p)\n", This
);
174 return This
->grayscalecontrast
;
177 static DWRITE_GRID_FIT_MODE WINAPI
renderingparams2_GetGridFitMode(IDWriteRenderingParams3
*iface
)
179 struct renderingparams
*This
= impl_from_IDWriteRenderingParams3(iface
);
180 TRACE("(%p)\n", This
);
181 return This
->gridfit
;
184 static DWRITE_RENDERING_MODE1 WINAPI
renderingparams3_GetRenderingMode1(IDWriteRenderingParams3
*iface
)
186 struct renderingparams
*This
= impl_from_IDWriteRenderingParams3(iface
);
187 TRACE("(%p)\n", This
);
191 static const struct IDWriteRenderingParams3Vtbl renderingparamsvtbl
= {
192 renderingparams_QueryInterface
,
193 renderingparams_AddRef
,
194 renderingparams_Release
,
195 renderingparams_GetGamma
,
196 renderingparams_GetEnhancedContrast
,
197 renderingparams_GetClearTypeLevel
,
198 renderingparams_GetPixelGeometry
,
199 renderingparams_GetRenderingMode
,
200 renderingparams1_GetGrayscaleEnhancedContrast
,
201 renderingparams2_GetGridFitMode
,
202 renderingparams3_GetRenderingMode1
205 static HRESULT
create_renderingparams(FLOAT gamma
, FLOAT contrast
, FLOAT grayscalecontrast
, FLOAT cleartype_level
,
206 DWRITE_PIXEL_GEOMETRY geometry
, DWRITE_RENDERING_MODE1 mode
, DWRITE_GRID_FIT_MODE gridfit
,
207 IDWriteRenderingParams3
**params
)
209 struct renderingparams
*This
;
213 if (gamma
<= 0.0f
|| contrast
< 0.0f
|| grayscalecontrast
< 0.0f
|| cleartype_level
< 0.0f
)
216 if ((UINT32
)gridfit
> DWRITE_GRID_FIT_MODE_ENABLED
|| (UINT32
)geometry
> DWRITE_PIXEL_GEOMETRY_BGR
)
219 This
= heap_alloc(sizeof(struct renderingparams
));
220 if (!This
) return E_OUTOFMEMORY
;
222 This
->IDWriteRenderingParams3_iface
.lpVtbl
= &renderingparamsvtbl
;
226 This
->contrast
= contrast
;
227 This
->grayscalecontrast
= grayscalecontrast
;
228 This
->cleartype_level
= cleartype_level
;
229 This
->geometry
= geometry
;
231 This
->gridfit
= gridfit
;
233 *params
= &This
->IDWriteRenderingParams3_iface
;
238 struct localizedpair
{
243 struct localizedstrings
{
244 IDWriteLocalizedStrings IDWriteLocalizedStrings_iface
;
247 struct localizedpair
*data
;
252 static inline struct localizedstrings
*impl_from_IDWriteLocalizedStrings(IDWriteLocalizedStrings
*iface
)
254 return CONTAINING_RECORD(iface
, struct localizedstrings
, IDWriteLocalizedStrings_iface
);
257 static HRESULT WINAPI
localizedstrings_QueryInterface(IDWriteLocalizedStrings
*iface
, REFIID riid
, void **obj
)
259 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
261 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
263 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDWriteLocalizedStrings
))
266 IDWriteLocalizedStrings_AddRef(iface
);
272 return E_NOINTERFACE
;
275 static ULONG WINAPI
localizedstrings_AddRef(IDWriteLocalizedStrings
*iface
)
277 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
278 ULONG ref
= InterlockedIncrement(&This
->ref
);
279 TRACE("(%p)->(%d)\n", This
, ref
);
283 static ULONG WINAPI
localizedstrings_Release(IDWriteLocalizedStrings
*iface
)
285 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
286 ULONG ref
= InterlockedDecrement(&This
->ref
);
288 TRACE("(%p)->(%d)\n", This
, ref
);
293 for (i
= 0; i
< This
->count
; i
++) {
294 heap_free(This
->data
[i
].locale
);
295 heap_free(This
->data
[i
].string
);
298 heap_free(This
->data
);
305 static UINT32 WINAPI
localizedstrings_GetCount(IDWriteLocalizedStrings
*iface
)
307 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
308 TRACE("(%p)\n", This
);
312 static HRESULT WINAPI
localizedstrings_FindLocaleName(IDWriteLocalizedStrings
*iface
,
313 WCHAR
const *locale_name
, UINT32
*index
, BOOL
*exists
)
315 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
318 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_w(locale_name
), index
, exists
);
323 for (i
= 0; i
< This
->count
; i
++) {
324 if (!strcmpiW(This
->data
[i
].locale
, locale_name
)) {
334 static HRESULT WINAPI
localizedstrings_GetLocaleNameLength(IDWriteLocalizedStrings
*iface
, UINT32 index
, UINT32
*length
)
336 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
338 TRACE("(%p)->(%u %p)\n", This
, index
, length
);
340 if (index
>= This
->count
) {
341 *length
= (UINT32
)-1;
345 *length
= strlenW(This
->data
[index
].locale
);
349 static HRESULT WINAPI
localizedstrings_GetLocaleName(IDWriteLocalizedStrings
*iface
, UINT32 index
, WCHAR
*buffer
, UINT32 size
)
351 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
353 TRACE("(%p)->(%u %p %u)\n", This
, index
, buffer
, size
);
355 if (index
>= This
->count
) {
356 if (buffer
) *buffer
= 0;
360 if (size
< strlenW(This
->data
[index
].locale
)+1) {
361 if (buffer
) *buffer
= 0;
362 return E_NOT_SUFFICIENT_BUFFER
;
365 strcpyW(buffer
, This
->data
[index
].locale
);
369 static HRESULT WINAPI
localizedstrings_GetStringLength(IDWriteLocalizedStrings
*iface
, UINT32 index
, UINT32
*length
)
371 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
373 TRACE("(%p)->(%u %p)\n", This
, index
, length
);
375 if (index
>= This
->count
) {
376 *length
= (UINT32
)-1;
380 *length
= strlenW(This
->data
[index
].string
);
384 static HRESULT WINAPI
localizedstrings_GetString(IDWriteLocalizedStrings
*iface
, UINT32 index
, WCHAR
*buffer
, UINT32 size
)
386 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
388 TRACE("(%p)->(%u %p %u)\n", This
, index
, buffer
, size
);
390 if (index
>= This
->count
) {
391 if (buffer
) *buffer
= 0;
395 if (size
< strlenW(This
->data
[index
].string
)+1) {
396 if (buffer
) *buffer
= 0;
397 return E_NOT_SUFFICIENT_BUFFER
;
400 strcpyW(buffer
, This
->data
[index
].string
);
404 static const IDWriteLocalizedStringsVtbl localizedstringsvtbl
= {
405 localizedstrings_QueryInterface
,
406 localizedstrings_AddRef
,
407 localizedstrings_Release
,
408 localizedstrings_GetCount
,
409 localizedstrings_FindLocaleName
,
410 localizedstrings_GetLocaleNameLength
,
411 localizedstrings_GetLocaleName
,
412 localizedstrings_GetStringLength
,
413 localizedstrings_GetString
416 HRESULT
create_localizedstrings(IDWriteLocalizedStrings
**strings
)
418 struct localizedstrings
*This
;
422 This
= heap_alloc(sizeof(struct localizedstrings
));
423 if (!This
) return E_OUTOFMEMORY
;
425 This
->IDWriteLocalizedStrings_iface
.lpVtbl
= &localizedstringsvtbl
;
428 This
->data
= heap_alloc_zero(sizeof(struct localizedpair
));
431 return E_OUTOFMEMORY
;
435 *strings
= &This
->IDWriteLocalizedStrings_iface
;
440 HRESULT
add_localizedstring(IDWriteLocalizedStrings
*iface
, const WCHAR
*locale
, const WCHAR
*string
)
442 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
445 /* make sure there's no duplicates */
446 for (i
= 0; i
< This
->count
; i
++)
447 if (!strcmpW(This
->data
[i
].locale
, locale
))
450 if (This
->count
== This
->alloc
) {
453 ptr
= heap_realloc(This
->data
, 2*This
->alloc
*sizeof(struct localizedpair
));
455 return E_OUTOFMEMORY
;
461 This
->data
[This
->count
].locale
= heap_strdupW(locale
);
462 This
->data
[This
->count
].string
= heap_strdupW(string
);
463 if (!This
->data
[This
->count
].locale
|| !This
->data
[This
->count
].string
) {
464 heap_free(This
->data
[This
->count
].locale
);
465 heap_free(This
->data
[This
->count
].string
);
466 return E_OUTOFMEMORY
;
474 HRESULT
clone_localizedstring(IDWriteLocalizedStrings
*iface
, IDWriteLocalizedStrings
**ret
)
476 struct localizedstrings
*strings
, *strings_clone
;
484 strings
= impl_from_IDWriteLocalizedStrings(iface
);
485 strings_clone
= heap_alloc(sizeof(struct localizedstrings
));
486 if (!strings_clone
) return E_OUTOFMEMORY
;
488 strings_clone
->IDWriteLocalizedStrings_iface
.lpVtbl
= &localizedstringsvtbl
;
489 strings_clone
->ref
= 1;
490 strings_clone
->count
= strings
->count
;
491 strings_clone
->data
= heap_alloc(sizeof(struct localizedpair
) * strings_clone
->count
);
492 if (!strings_clone
->data
) {
493 heap_free(strings_clone
);
494 return E_OUTOFMEMORY
;
496 for (i
= 0; i
< strings_clone
->count
; i
++)
498 strings_clone
->data
[i
].locale
= heap_strdupW(strings
->data
[i
].locale
);
499 strings_clone
->data
[i
].string
= heap_strdupW(strings
->data
[i
].string
);
501 strings_clone
->alloc
= strings_clone
->count
;
503 *ret
= &strings_clone
->IDWriteLocalizedStrings_iface
;
508 void set_en_localizedstring(IDWriteLocalizedStrings
*iface
, const WCHAR
*string
)
510 static const WCHAR enusW
[] = {'e','n','-','U','S',0};
511 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
514 for (i
= 0; i
< This
->count
; i
++) {
515 if (!strcmpiW(This
->data
[i
].locale
, enusW
)) {
516 heap_free(This
->data
[i
].string
);
517 This
->data
[i
].string
= heap_strdupW(string
);
523 struct collectionloader
526 IDWriteFontCollectionLoader
*loader
;
529 struct fontfacecached
532 IDWriteFontFace4
*fontface
;
538 struct list fontfaces
;
539 IDWriteFontFileLoader
*loader
;
542 struct dwritefactory
{
543 IDWriteFactory5 IDWriteFactory5_iface
;
546 IDWriteFontCollection1
*system_collection
;
547 IDWriteFontCollection1
*eudc_collection
;
548 IDWriteGdiInterop1
*gdiinterop
;
549 IDWriteFontFallback
*fallback
;
551 IDWriteLocalFontFileLoader
* localfontfileloader
;
552 struct list localfontfaces
;
554 struct list collection_loaders
;
555 struct list file_loaders
;
558 static inline struct dwritefactory
*impl_from_IDWriteFactory5(IDWriteFactory5
*iface
)
560 return CONTAINING_RECORD(iface
, struct dwritefactory
, IDWriteFactory5_iface
);
563 static void release_fontface_cache(struct list
*fontfaces
)
565 struct fontfacecached
*fontface
, *fontface2
;
567 LIST_FOR_EACH_ENTRY_SAFE(fontface
, fontface2
, fontfaces
, struct fontfacecached
, entry
) {
568 list_remove(&fontface
->entry
);
569 fontface_detach_from_cache(fontface
->fontface
);
574 static void release_fileloader(struct fileloader
*fileloader
)
576 list_remove(&fileloader
->entry
);
577 release_fontface_cache(&fileloader
->fontfaces
);
578 IDWriteFontFileLoader_Release(fileloader
->loader
);
579 heap_free(fileloader
);
582 static void release_dwritefactory(struct dwritefactory
*factory
)
584 struct fileloader
*fileloader
, *fileloader2
;
585 struct collectionloader
*loader
, *loader2
;
587 if (factory
->localfontfileloader
)
588 IDWriteLocalFontFileLoader_Release(factory
->localfontfileloader
);
589 release_fontface_cache(&factory
->localfontfaces
);
591 LIST_FOR_EACH_ENTRY_SAFE(loader
, loader2
, &factory
->collection_loaders
, struct collectionloader
, entry
) {
592 list_remove(&loader
->entry
);
593 IDWriteFontCollectionLoader_Release(loader
->loader
);
597 LIST_FOR_EACH_ENTRY_SAFE(fileloader
, fileloader2
, &factory
->file_loaders
, struct fileloader
, entry
)
598 release_fileloader(fileloader
);
600 if (factory
->system_collection
)
601 IDWriteFontCollection1_Release(factory
->system_collection
);
602 if (factory
->eudc_collection
)
603 IDWriteFontCollection1_Release(factory
->eudc_collection
);
604 if (factory
->fallback
)
605 release_system_fontfallback(factory
->fallback
);
609 static void release_shared_factory(IDWriteFactory5
*iface
)
611 struct dwritefactory
*factory
;
613 factory
= impl_from_IDWriteFactory5(iface
);
614 release_dwritefactory(factory
);
617 static struct fileloader
*factory_get_file_loader(struct dwritefactory
*factory
, IDWriteFontFileLoader
*loader
)
619 struct fileloader
*entry
, *found
= NULL
;
621 LIST_FOR_EACH_ENTRY(entry
, &factory
->file_loaders
, struct fileloader
, entry
) {
622 if (entry
->loader
== loader
) {
631 static struct collectionloader
*factory_get_collection_loader(struct dwritefactory
*factory
,
632 IDWriteFontCollectionLoader
*loader
)
634 struct collectionloader
*entry
, *found
= NULL
;
636 LIST_FOR_EACH_ENTRY(entry
, &factory
->collection_loaders
, struct collectionloader
, entry
) {
637 if (entry
->loader
== loader
) {
646 static HRESULT WINAPI
dwritefactory_QueryInterface(IDWriteFactory5
*iface
, REFIID riid
, void **obj
)
648 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
650 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
652 if (IsEqualIID(riid
, &IID_IDWriteFactory5
) ||
653 IsEqualIID(riid
, &IID_IDWriteFactory4
) ||
654 IsEqualIID(riid
, &IID_IDWriteFactory3
) ||
655 IsEqualIID(riid
, &IID_IDWriteFactory2
) ||
656 IsEqualIID(riid
, &IID_IDWriteFactory1
) ||
657 IsEqualIID(riid
, &IID_IDWriteFactory
) ||
658 IsEqualIID(riid
, &IID_IUnknown
))
661 IDWriteFactory5_AddRef(iface
);
667 return E_NOINTERFACE
;
670 static ULONG WINAPI
dwritefactory_AddRef(IDWriteFactory5
*iface
)
672 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
673 ULONG ref
= InterlockedIncrement(&This
->ref
);
674 TRACE("(%p)->(%d)\n", This
, ref
);
678 static ULONG WINAPI
dwritefactory_Release(IDWriteFactory5
*iface
)
680 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
681 ULONG ref
= InterlockedDecrement(&This
->ref
);
683 TRACE("(%p)->(%d)\n", This
, ref
);
686 release_dwritefactory(This
);
691 static HRESULT WINAPI
dwritefactory_GetSystemFontCollection(IDWriteFactory5
*iface
,
692 IDWriteFontCollection
**collection
, BOOL check_for_updates
)
694 return IDWriteFactory5_GetSystemFontCollection(iface
, FALSE
, (IDWriteFontCollection1
**)collection
,
698 static HRESULT WINAPI
dwritefactory_CreateCustomFontCollection(IDWriteFactory5
*iface
,
699 IDWriteFontCollectionLoader
*loader
, void const *key
, UINT32 key_size
, IDWriteFontCollection
**collection
)
701 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
702 IDWriteFontFileEnumerator
*enumerator
;
703 struct collectionloader
*found
;
706 TRACE("(%p)->(%p %p %u %p)\n", This
, loader
, key
, key_size
, collection
);
713 found
= factory_get_collection_loader(This
, loader
);
717 hr
= IDWriteFontCollectionLoader_CreateEnumeratorFromKey(found
->loader
, (IDWriteFactory
*)iface
,
718 key
, key_size
, &enumerator
);
722 hr
= create_font_collection(iface
, enumerator
, FALSE
, (IDWriteFontCollection1
**)collection
);
723 IDWriteFontFileEnumerator_Release(enumerator
);
727 static HRESULT WINAPI
dwritefactory_RegisterFontCollectionLoader(IDWriteFactory5
*iface
,
728 IDWriteFontCollectionLoader
*loader
)
730 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
731 struct collectionloader
*entry
;
733 TRACE("(%p)->(%p)\n", This
, loader
);
738 if (factory_get_collection_loader(This
, loader
))
739 return DWRITE_E_ALREADYREGISTERED
;
741 entry
= heap_alloc(sizeof(*entry
));
743 return E_OUTOFMEMORY
;
745 entry
->loader
= loader
;
746 IDWriteFontCollectionLoader_AddRef(loader
);
747 list_add_tail(&This
->collection_loaders
, &entry
->entry
);
752 static HRESULT WINAPI
dwritefactory_UnregisterFontCollectionLoader(IDWriteFactory5
*iface
,
753 IDWriteFontCollectionLoader
*loader
)
755 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
756 struct collectionloader
*found
;
758 TRACE("(%p)->(%p)\n", This
, loader
);
763 found
= factory_get_collection_loader(This
, loader
);
767 IDWriteFontCollectionLoader_Release(found
->loader
);
768 list_remove(&found
->entry
);
774 static HRESULT WINAPI
dwritefactory_CreateFontFileReference(IDWriteFactory5
*iface
,
775 WCHAR
const *path
, FILETIME
const *writetime
, IDWriteFontFile
**font_file
)
777 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
782 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_w(path
), writetime
, font_file
);
786 if (!This
->localfontfileloader
)
788 hr
= create_localfontfileloader(&This
->localfontfileloader
);
793 /* get a reference key used by local loader */
794 hr
= get_local_refkey(path
, writetime
, &key
, &key_size
);
798 hr
= create_font_file((IDWriteFontFileLoader
*)This
->localfontfileloader
, key
, key_size
, font_file
);
804 static HRESULT WINAPI
dwritefactory_CreateCustomFontFileReference(IDWriteFactory5
*iface
,
805 void const *reference_key
, UINT32 key_size
, IDWriteFontFileLoader
*loader
, IDWriteFontFile
**font_file
)
807 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
809 TRACE("(%p)->(%p %u %p %p)\n", This
, reference_key
, key_size
, loader
, font_file
);
813 /* local loader is accepted as well */
814 if (!loader
|| !(factory_get_file_loader(This
, loader
) ||
815 (IDWriteFontFileLoader
*)This
->localfontfileloader
== loader
))
818 return create_font_file(loader
, reference_key
, key_size
, font_file
);
821 HRESULT
factory_get_cached_fontface(IDWriteFactory5
*iface
, IDWriteFontFile
* const *font_files
,
822 UINT32 index
, DWRITE_FONT_SIMULATIONS simulations
, IDWriteFontFace
**font_face
, struct list
**cached_list
)
824 struct dwritefactory
*factory
= impl_from_IDWriteFactory5(iface
);
825 struct fontfacecached
*cached
;
826 IDWriteFontFileLoader
*loader
;
827 struct list
*fontfaces
;
835 hr
= IDWriteFontFile_GetReferenceKey(*font_files
, &key
, &key_size
);
839 hr
= IDWriteFontFile_GetLoader(*font_files
, &loader
);
843 if (loader
== (IDWriteFontFileLoader
*)factory
->localfontfileloader
) {
844 fontfaces
= &factory
->localfontfaces
;
845 IDWriteFontFileLoader_Release(loader
);
848 struct fileloader
*fileloader
= factory_get_file_loader(factory
, loader
);
849 IDWriteFontFileLoader_Release(loader
);
852 fontfaces
= &fileloader
->fontfaces
;
855 *cached_list
= fontfaces
;
857 /* search through cache list */
858 LIST_FOR_EACH_ENTRY(cached
, fontfaces
, struct fontfacecached
, entry
) {
859 UINT32 cached_key_size
, count
= 1, cached_face_index
;
860 DWRITE_FONT_SIMULATIONS cached_simulations
;
861 const void *cached_key
;
862 IDWriteFontFile
*file
;
864 cached_face_index
= IDWriteFontFace4_GetIndex(cached
->fontface
);
865 cached_simulations
= IDWriteFontFace4_GetSimulations(cached
->fontface
);
868 if (cached_face_index
!= index
|| cached_simulations
!= simulations
)
871 hr
= IDWriteFontFace4_GetFiles(cached
->fontface
, &count
, &file
);
875 hr
= IDWriteFontFile_GetReferenceKey(file
, &cached_key
, &cached_key_size
);
876 IDWriteFontFile_Release(file
);
880 if (cached_key_size
== key_size
&& !memcmp(cached_key
, key
, key_size
)) {
881 TRACE("returning cached fontface %p\n", cached
->fontface
);
882 *font_face
= (IDWriteFontFace
*)cached
->fontface
;
890 struct fontfacecached
*factory_cache_fontface(struct list
*fontfaces
, IDWriteFontFace4
*fontface
)
892 struct fontfacecached
*cached
;
894 /* new cache entry */
895 cached
= heap_alloc(sizeof(*cached
));
899 cached
->fontface
= fontface
;
900 list_add_tail(fontfaces
, &cached
->entry
);
905 void factory_release_cached_fontface(struct fontfacecached
*cached
)
907 list_remove(&cached
->entry
);
911 static HRESULT WINAPI
dwritefactory_CreateFontFace(IDWriteFactory5
*iface
, DWRITE_FONT_FACE_TYPE req_facetype
,
912 UINT32 files_number
, IDWriteFontFile
* const* font_files
, UINT32 index
, DWRITE_FONT_SIMULATIONS simulations
,
913 IDWriteFontFace
**fontface
)
915 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
916 DWRITE_FONT_FILE_TYPE file_type
;
917 DWRITE_FONT_FACE_TYPE face_type
;
918 struct fontface_desc desc
;
919 struct list
*fontfaces
;
924 TRACE("(%p)->(%d %u %p %u 0x%x %p)\n", This
, req_facetype
, files_number
, font_files
, index
,
925 simulations
, fontface
);
929 if (!is_face_type_supported(req_facetype
))
932 if (req_facetype
!= DWRITE_FONT_FACE_TYPE_OPENTYPE_COLLECTION
&& index
)
935 if (!is_simulation_valid(simulations
))
938 /* check actual file/face type */
939 is_supported
= FALSE
;
940 face_type
= DWRITE_FONT_FACE_TYPE_UNKNOWN
;
941 hr
= IDWriteFontFile_Analyze(*font_files
, &is_supported
, &file_type
, &face_type
, &count
);
948 if (face_type
!= req_facetype
)
949 return DWRITE_E_FILEFORMAT
;
951 hr
= factory_get_cached_fontface(iface
, font_files
, index
, simulations
, fontface
, &fontfaces
);
953 IDWriteFontFace_AddRef(*fontface
);
958 desc
.factory
= iface
;
959 desc
.face_type
= req_facetype
;
960 desc
.files
= font_files
;
961 desc
.files_number
= files_number
;
963 desc
.simulations
= simulations
;
964 desc
.font_data
= NULL
;
965 return create_fontface(&desc
, fontfaces
, (IDWriteFontFace4
**)fontface
);
968 static HRESULT WINAPI
dwritefactory_CreateRenderingParams(IDWriteFactory5
*iface
, IDWriteRenderingParams
**params
)
970 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
974 TRACE("(%p)->(%p)\n", This
, params
);
977 monitor
= MonitorFromPoint(pt
, MONITOR_DEFAULTTOPRIMARY
);
978 return IDWriteFactory5_CreateMonitorRenderingParams(iface
, monitor
, params
);
981 static HRESULT WINAPI
dwritefactory_CreateMonitorRenderingParams(IDWriteFactory5
*iface
, HMONITOR monitor
,
982 IDWriteRenderingParams
**params
)
984 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
985 IDWriteRenderingParams3
*params3
;
986 static int fixme_once
= 0;
989 TRACE("(%p)->(%p %p)\n", This
, monitor
, params
);
992 FIXME("(%p): monitor setting ignored\n", monitor
);
994 /* FIXME: use actual per-monitor gamma factor */
995 hr
= IDWriteFactory5_CreateCustomRenderingParams(iface
, 2.0f
, 0.0f
, 1.0f
, 0.0f
, DWRITE_PIXEL_GEOMETRY_FLAT
,
996 DWRITE_RENDERING_MODE1_DEFAULT
, DWRITE_GRID_FIT_MODE_DEFAULT
, ¶ms3
);
997 *params
= (IDWriteRenderingParams
*)params3
;
1001 static HRESULT WINAPI
dwritefactory_CreateCustomRenderingParams(IDWriteFactory5
*iface
, FLOAT gamma
,
1002 FLOAT enhancedContrast
, FLOAT cleartype_level
, DWRITE_PIXEL_GEOMETRY geometry
, DWRITE_RENDERING_MODE mode
,
1003 IDWriteRenderingParams
**params
)
1005 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1006 IDWriteRenderingParams3
*params3
;
1009 TRACE("(%p)->(%f %f %f %d %d %p)\n", This
, gamma
, enhancedContrast
, cleartype_level
, geometry
, mode
, params
);
1011 if ((UINT32
)mode
> DWRITE_RENDERING_MODE_OUTLINE
) {
1013 return E_INVALIDARG
;
1016 hr
= IDWriteFactory5_CreateCustomRenderingParams(iface
, gamma
, enhancedContrast
, 1.0f
, cleartype_level
, geometry
,
1017 (DWRITE_RENDERING_MODE1
)mode
, DWRITE_GRID_FIT_MODE_DEFAULT
, ¶ms3
);
1018 *params
= (IDWriteRenderingParams
*)params3
;
1022 static HRESULT WINAPI
dwritefactory_RegisterFontFileLoader(IDWriteFactory5
*iface
, IDWriteFontFileLoader
*loader
)
1024 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1025 struct fileloader
*entry
;
1027 TRACE("(%p)->(%p)\n", This
, loader
);
1030 return E_INVALIDARG
;
1032 if ((IDWriteFontFileLoader
*)This
->localfontfileloader
== loader
)
1035 if (factory_get_file_loader(This
, loader
))
1036 return DWRITE_E_ALREADYREGISTERED
;
1038 entry
= heap_alloc(sizeof(*entry
));
1040 return E_OUTOFMEMORY
;
1042 entry
->loader
= loader
;
1043 list_init(&entry
->fontfaces
);
1044 IDWriteFontFileLoader_AddRef(loader
);
1045 list_add_tail(&This
->file_loaders
, &entry
->entry
);
1050 static HRESULT WINAPI
dwritefactory_UnregisterFontFileLoader(IDWriteFactory5
*iface
, IDWriteFontFileLoader
*loader
)
1052 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1053 struct fileloader
*found
;
1055 TRACE("(%p)->(%p)\n", This
, loader
);
1058 return E_INVALIDARG
;
1060 if ((IDWriteFontFileLoader
*)This
->localfontfileloader
== loader
)
1063 found
= factory_get_file_loader(This
, loader
);
1065 return E_INVALIDARG
;
1067 release_fileloader(found
);
1071 static HRESULT WINAPI
dwritefactory_CreateTextFormat(IDWriteFactory5
*iface
, WCHAR
const* family_name
,
1072 IDWriteFontCollection
*collection
, DWRITE_FONT_WEIGHT weight
, DWRITE_FONT_STYLE style
,
1073 DWRITE_FONT_STRETCH stretch
, FLOAT size
, WCHAR
const *locale
, IDWriteTextFormat
**format
)
1075 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1076 IDWriteFontCollection
*syscollection
= NULL
;
1079 TRACE("(%p)->(%s %p %d %d %d %f %s %p)\n", This
, debugstr_w(family_name
), collection
, weight
, style
, stretch
,
1080 size
, debugstr_w(locale
), format
);
1083 hr
= IDWriteFactory5_GetSystemFontCollection(iface
, FALSE
, (IDWriteFontCollection1
**)&syscollection
, FALSE
);
1088 hr
= create_textformat(family_name
, collection
? collection
: syscollection
, weight
, style
, stretch
, size
, locale
, format
);
1090 IDWriteFontCollection_Release(syscollection
);
1094 static HRESULT WINAPI
dwritefactory_CreateTypography(IDWriteFactory5
*iface
, IDWriteTypography
**typography
)
1096 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1097 TRACE("(%p)->(%p)\n", This
, typography
);
1098 return create_typography(typography
);
1101 static HRESULT WINAPI
dwritefactory_GetGdiInterop(IDWriteFactory5
*iface
, IDWriteGdiInterop
**gdi_interop
)
1103 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1106 TRACE("(%p)->(%p)\n", This
, gdi_interop
);
1108 if (This
->gdiinterop
)
1109 IDWriteGdiInterop1_AddRef(This
->gdiinterop
);
1111 hr
= create_gdiinterop(iface
, &This
->gdiinterop
);
1113 *gdi_interop
= (IDWriteGdiInterop
*)This
->gdiinterop
;
1118 static HRESULT WINAPI
dwritefactory_CreateTextLayout(IDWriteFactory5
*iface
, WCHAR
const* string
,
1119 UINT32 length
, IDWriteTextFormat
*format
, FLOAT max_width
, FLOAT max_height
, IDWriteTextLayout
**layout
)
1121 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1122 struct textlayout_desc desc
;
1124 TRACE("(%p)->(%s:%u %p %f %f %p)\n", This
, debugstr_wn(string
, length
), length
, format
, max_width
, max_height
, layout
);
1126 desc
.factory
= iface
;
1127 desc
.string
= string
;
1128 desc
.length
= length
;
1129 desc
.format
= format
;
1130 desc
.max_width
= max_width
;
1131 desc
.max_height
= max_height
;
1132 desc
.is_gdi_compatible
= FALSE
;
1134 desc
.transform
= NULL
;
1135 desc
.use_gdi_natural
= FALSE
;
1136 return create_textlayout(&desc
, layout
);
1139 static HRESULT WINAPI
dwritefactory_CreateGdiCompatibleTextLayout(IDWriteFactory5
*iface
, WCHAR
const* string
,
1140 UINT32 length
, IDWriteTextFormat
*format
, FLOAT max_width
, FLOAT max_height
, FLOAT pixels_per_dip
,
1141 DWRITE_MATRIX
const* transform
, BOOL use_gdi_natural
, IDWriteTextLayout
**layout
)
1143 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1144 struct textlayout_desc desc
;
1146 TRACE("(%p)->(%s:%u %p %f %f %f %p %d %p)\n", This
, debugstr_wn(string
, length
), length
, format
, max_width
,
1147 max_height
, pixels_per_dip
, transform
, use_gdi_natural
, layout
);
1149 desc
.factory
= iface
;
1150 desc
.string
= string
;
1151 desc
.length
= length
;
1152 desc
.format
= format
;
1153 desc
.max_width
= max_width
;
1154 desc
.max_height
= max_height
;
1155 desc
.is_gdi_compatible
= TRUE
;
1156 desc
.ppdip
= pixels_per_dip
;
1157 desc
.transform
= transform
;
1158 desc
.use_gdi_natural
= use_gdi_natural
;
1159 return create_textlayout(&desc
, layout
);
1162 static HRESULT WINAPI
dwritefactory_CreateEllipsisTrimmingSign(IDWriteFactory5
*iface
, IDWriteTextFormat
*format
,
1163 IDWriteInlineObject
**trimming_sign
)
1165 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1166 TRACE("(%p)->(%p %p)\n", This
, format
, trimming_sign
);
1167 return create_trimmingsign(iface
, format
, trimming_sign
);
1170 static HRESULT WINAPI
dwritefactory_CreateTextAnalyzer(IDWriteFactory5
*iface
, IDWriteTextAnalyzer
**analyzer
)
1172 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1173 TRACE("(%p)->(%p)\n", This
, analyzer
);
1174 return get_textanalyzer(analyzer
);
1177 static HRESULT WINAPI
dwritefactory_CreateNumberSubstitution(IDWriteFactory5
*iface
,
1178 DWRITE_NUMBER_SUBSTITUTION_METHOD method
, WCHAR
const* locale
, BOOL ignore_user_override
,
1179 IDWriteNumberSubstitution
**substitution
)
1181 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1182 TRACE("(%p)->(%d %s %d %p)\n", This
, method
, debugstr_w(locale
), ignore_user_override
, substitution
);
1183 return create_numbersubstitution(method
, locale
, ignore_user_override
, substitution
);
1186 static HRESULT WINAPI
dwritefactory_CreateGlyphRunAnalysis(IDWriteFactory5
*iface
, DWRITE_GLYPH_RUN
const *run
,
1187 FLOAT ppdip
, DWRITE_MATRIX
const* transform
, DWRITE_RENDERING_MODE rendering_mode
,
1188 DWRITE_MEASURING_MODE measuring_mode
, FLOAT originX
, FLOAT originY
, IDWriteGlyphRunAnalysis
**analysis
)
1190 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1191 struct glyphrunanalysis_desc desc
;
1193 TRACE("(%p)->(%p %.2f %p %d %d %.2f %.2f %p)\n", This
, run
, ppdip
, transform
, rendering_mode
,
1194 measuring_mode
, originX
, originY
, analysis
);
1196 if (ppdip
<= 0.0f
) {
1198 return E_INVALIDARG
;
1203 desc
.transform
= transform
;
1204 desc
.rendering_mode
= (DWRITE_RENDERING_MODE1
)rendering_mode
;
1205 desc
.measuring_mode
= measuring_mode
;
1206 desc
.gridfit_mode
= DWRITE_GRID_FIT_MODE_DEFAULT
;
1207 desc
.aa_mode
= DWRITE_TEXT_ANTIALIAS_MODE_CLEARTYPE
;
1208 desc
.origin_x
= originX
;
1209 desc
.origin_y
= originY
;
1210 return create_glyphrunanalysis(&desc
, analysis
);
1213 static HRESULT WINAPI
dwritefactory1_GetEudcFontCollection(IDWriteFactory5
*iface
, IDWriteFontCollection
**collection
,
1214 BOOL check_for_updates
)
1216 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1219 TRACE("(%p)->(%p %d)\n", This
, collection
, check_for_updates
);
1221 if (check_for_updates
)
1222 FIXME("checking for eudc updates not implemented\n");
1224 if (This
->eudc_collection
)
1225 IDWriteFontCollection1_AddRef(This
->eudc_collection
);
1227 hr
= get_eudc_fontcollection(iface
, &This
->eudc_collection
);
1229 *collection
= (IDWriteFontCollection
*)This
->eudc_collection
;
1234 static HRESULT WINAPI
dwritefactory1_CreateCustomRenderingParams(IDWriteFactory5
*iface
, FLOAT gamma
,
1235 FLOAT enhcontrast
, FLOAT enhcontrast_grayscale
, FLOAT cleartype_level
, DWRITE_PIXEL_GEOMETRY geometry
,
1236 DWRITE_RENDERING_MODE mode
, IDWriteRenderingParams1
** params
)
1238 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1239 IDWriteRenderingParams3
*params3
;
1242 TRACE("(%p)->(%.2f %.2f %.2f %.2f %d %d %p)\n", This
, gamma
, enhcontrast
, enhcontrast_grayscale
,
1243 cleartype_level
, geometry
, mode
, params
);
1245 if ((UINT32
)mode
> DWRITE_RENDERING_MODE_OUTLINE
) {
1247 return E_INVALIDARG
;
1250 hr
= IDWriteFactory5_CreateCustomRenderingParams(iface
, gamma
, enhcontrast
, enhcontrast_grayscale
,
1251 cleartype_level
, geometry
, (DWRITE_RENDERING_MODE1
)mode
, DWRITE_GRID_FIT_MODE_DEFAULT
, ¶ms3
);
1252 *params
= (IDWriteRenderingParams1
*)params3
;
1256 static HRESULT WINAPI
dwritefactory2_GetSystemFontFallback(IDWriteFactory5
*iface
, IDWriteFontFallback
**fallback
)
1258 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1260 TRACE("(%p)->(%p)\n", This
, fallback
);
1264 if (!This
->fallback
) {
1265 HRESULT hr
= create_system_fontfallback(iface
, &This
->fallback
);
1270 *fallback
= This
->fallback
;
1271 IDWriteFontFallback_AddRef(*fallback
);
1275 static HRESULT WINAPI
dwritefactory2_CreateFontFallbackBuilder(IDWriteFactory5
*iface
,
1276 IDWriteFontFallbackBuilder
**fallbackbuilder
)
1278 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1279 FIXME("(%p)->(%p): stub\n", This
, fallbackbuilder
);
1283 static HRESULT WINAPI
dwritefactory2_TranslateColorGlyphRun(IDWriteFactory5
*iface
, FLOAT originX
, FLOAT originY
,
1284 const DWRITE_GLYPH_RUN
*run
, const DWRITE_GLYPH_RUN_DESCRIPTION
*rundescr
, DWRITE_MEASURING_MODE mode
,
1285 const DWRITE_MATRIX
*transform
, UINT32 palette
, IDWriteColorGlyphRunEnumerator
**colorlayers
)
1287 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1288 TRACE("(%p)->(%.2f %.2f %p %p %d %p %u %p)\n", This
, originX
, originY
, run
, rundescr
, mode
,
1289 transform
, palette
, colorlayers
);
1290 return create_colorglyphenum(originX
, originY
, run
, rundescr
, mode
, transform
, palette
, colorlayers
);
1293 static HRESULT WINAPI
dwritefactory2_CreateCustomRenderingParams(IDWriteFactory5
*iface
, FLOAT gamma
, FLOAT contrast
,
1294 FLOAT grayscalecontrast
, FLOAT cleartype_level
, DWRITE_PIXEL_GEOMETRY geometry
, DWRITE_RENDERING_MODE mode
,
1295 DWRITE_GRID_FIT_MODE gridfit
, IDWriteRenderingParams2
**params
)
1297 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1298 IDWriteRenderingParams3
*params3
;
1301 TRACE("(%p)->(%.2f %.2f %.2f %.2f %d %d %d %p)\n", This
, gamma
, contrast
, grayscalecontrast
, cleartype_level
,
1302 geometry
, mode
, gridfit
, params
);
1304 if ((UINT32
)mode
> DWRITE_RENDERING_MODE_OUTLINE
) {
1306 return E_INVALIDARG
;
1309 hr
= IDWriteFactory5_CreateCustomRenderingParams(iface
, gamma
, contrast
, grayscalecontrast
,
1310 cleartype_level
, geometry
, (DWRITE_RENDERING_MODE1
)mode
, DWRITE_GRID_FIT_MODE_DEFAULT
, ¶ms3
);
1311 *params
= (IDWriteRenderingParams2
*)params3
;
1315 static HRESULT WINAPI
dwritefactory2_CreateGlyphRunAnalysis(IDWriteFactory5
*iface
, const DWRITE_GLYPH_RUN
*run
,
1316 const DWRITE_MATRIX
*transform
, DWRITE_RENDERING_MODE rendering_mode
, DWRITE_MEASURING_MODE measuring_mode
,
1317 DWRITE_GRID_FIT_MODE gridfit_mode
, DWRITE_TEXT_ANTIALIAS_MODE aa_mode
, FLOAT originX
, FLOAT originY
,
1318 IDWriteGlyphRunAnalysis
**analysis
)
1320 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1321 struct glyphrunanalysis_desc desc
;
1323 TRACE("(%p)->(%p %p %d %d %d %d %.2f %.2f %p)\n", This
, run
, transform
, rendering_mode
, measuring_mode
,
1324 gridfit_mode
, aa_mode
, originX
, originY
, analysis
);
1328 desc
.transform
= transform
;
1329 desc
.rendering_mode
= (DWRITE_RENDERING_MODE1
)rendering_mode
;
1330 desc
.measuring_mode
= measuring_mode
;
1331 desc
.gridfit_mode
= gridfit_mode
;
1332 desc
.aa_mode
= aa_mode
;
1333 desc
.origin_x
= originX
;
1334 desc
.origin_y
= originY
;
1335 return create_glyphrunanalysis(&desc
, analysis
);
1338 static HRESULT WINAPI
dwritefactory3_CreateGlyphRunAnalysis(IDWriteFactory5
*iface
, DWRITE_GLYPH_RUN
const *run
,
1339 DWRITE_MATRIX
const *transform
, DWRITE_RENDERING_MODE1 rendering_mode
, DWRITE_MEASURING_MODE measuring_mode
,
1340 DWRITE_GRID_FIT_MODE gridfit_mode
, DWRITE_TEXT_ANTIALIAS_MODE aa_mode
, FLOAT originX
, FLOAT originY
,
1341 IDWriteGlyphRunAnalysis
**analysis
)
1343 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1344 struct glyphrunanalysis_desc desc
;
1346 TRACE("(%p)->(%p %p %d %d %d %d %.2f %.2f %p)\n", This
, run
, transform
, rendering_mode
, measuring_mode
,
1347 gridfit_mode
, aa_mode
, originX
, originY
, analysis
);
1351 desc
.transform
= transform
;
1352 desc
.rendering_mode
= rendering_mode
;
1353 desc
.measuring_mode
= measuring_mode
;
1354 desc
.gridfit_mode
= gridfit_mode
;
1355 desc
.aa_mode
= aa_mode
;
1356 desc
.origin_x
= originX
;
1357 desc
.origin_y
= originY
;
1358 return create_glyphrunanalysis(&desc
, analysis
);
1361 static HRESULT WINAPI
dwritefactory3_CreateCustomRenderingParams(IDWriteFactory5
*iface
, FLOAT gamma
, FLOAT contrast
,
1362 FLOAT grayscale_contrast
, FLOAT cleartype_level
, DWRITE_PIXEL_GEOMETRY pixel_geometry
,
1363 DWRITE_RENDERING_MODE1 rendering_mode
, DWRITE_GRID_FIT_MODE gridfit_mode
, IDWriteRenderingParams3
**params
)
1365 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1367 TRACE("(%p)->(%.2f %.2f %.2f %.2f %d %d %d %p)\n", This
, gamma
, contrast
, grayscale_contrast
, cleartype_level
,
1368 pixel_geometry
, rendering_mode
, gridfit_mode
, params
);
1370 return create_renderingparams(gamma
, contrast
, grayscale_contrast
, cleartype_level
, pixel_geometry
, rendering_mode
,
1371 gridfit_mode
, params
);
1374 static HRESULT WINAPI
dwritefactory3_CreateFontFaceReference_(IDWriteFactory5
*iface
, IDWriteFontFile
*file
,
1375 UINT32 index
, DWRITE_FONT_SIMULATIONS simulations
, IDWriteFontFaceReference
**reference
)
1377 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1379 TRACE("(%p)->(%p %u %x %p)\n", This
, file
, index
, simulations
, reference
);
1381 return create_fontfacereference(iface
, file
, index
, simulations
, reference
);
1384 static HRESULT WINAPI
dwritefactory3_CreateFontFaceReference(IDWriteFactory5
*iface
, WCHAR
const *path
,
1385 FILETIME
const *writetime
, UINT32 index
, DWRITE_FONT_SIMULATIONS simulations
,
1386 IDWriteFontFaceReference
**reference
)
1388 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1389 IDWriteFontFile
*file
;
1392 TRACE("(%p)->(%s %p %u %x, %p)\n", This
, debugstr_w(path
), writetime
, index
, simulations
, reference
);
1394 hr
= IDWriteFactory5_CreateFontFileReference(iface
, path
, writetime
, &file
);
1400 hr
= IDWriteFactory5_CreateFontFaceReference_(iface
, file
, index
, simulations
, reference
);
1401 IDWriteFontFile_Release(file
);
1405 static HRESULT WINAPI
dwritefactory3_GetSystemFontSet(IDWriteFactory5
*iface
, IDWriteFontSet
**fontset
)
1407 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1409 FIXME("(%p)->(%p): stub\n", This
, fontset
);
1414 static HRESULT WINAPI
dwritefactory3_CreateFontSetBuilder(IDWriteFactory5
*iface
, IDWriteFontSetBuilder
**builder
)
1416 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1418 FIXME("(%p)->(%p): stub\n", This
, builder
);
1423 static HRESULT WINAPI
dwritefactory3_CreateFontCollectionFromFontSet(IDWriteFactory5
*iface
, IDWriteFontSet
*fontset
,
1424 IDWriteFontCollection1
**collection
)
1426 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1428 FIXME("(%p)->(%p %p): stub\n", This
, fontset
, collection
);
1433 static HRESULT WINAPI
dwritefactory3_GetSystemFontCollection(IDWriteFactory5
*iface
, BOOL include_downloadable
,
1434 IDWriteFontCollection1
**collection
, BOOL check_for_updates
)
1436 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1439 TRACE("(%p)->(%d %p %d)\n", This
, include_downloadable
, collection
, check_for_updates
);
1441 if (include_downloadable
)
1442 FIXME("remote fonts are not supported\n");
1444 if (check_for_updates
)
1445 FIXME("checking for system font updates not implemented\n");
1447 if (This
->system_collection
)
1448 IDWriteFontCollection1_AddRef(This
->system_collection
);
1450 hr
= get_system_fontcollection(iface
, &This
->system_collection
);
1452 *collection
= This
->system_collection
;
1457 static HRESULT WINAPI
dwritefactory3_GetFontDownloadQueue(IDWriteFactory5
*iface
, IDWriteFontDownloadQueue
**queue
)
1459 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1461 FIXME("(%p)->(%p): stub\n", This
, queue
);
1466 static HRESULT WINAPI
dwritefactory4_TranslateColorGlyphRun(IDWriteFactory5
*iface
, D2D1_POINT_2F baseline_origin
,
1467 DWRITE_GLYPH_RUN
const *run
, DWRITE_GLYPH_RUN_DESCRIPTION
const *run_desc
,
1468 DWRITE_GLYPH_IMAGE_FORMATS desired_formats
, DWRITE_MEASURING_MODE measuring_mode
, DWRITE_MATRIX
const *transform
,
1469 UINT32 palette
, IDWriteColorGlyphRunEnumerator1
**layers
)
1471 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1473 FIXME("(%p)->(%p %p %u %d %p %u %p): stub\n", This
, run
, run_desc
, desired_formats
, measuring_mode
,
1474 transform
, palette
, layers
);
1479 static HRESULT
compute_glyph_origins(DWRITE_GLYPH_RUN
const *run
, DWRITE_MEASURING_MODE measuring_mode
,
1480 D2D1_POINT_2F baseline_origin
, DWRITE_MATRIX
const *transform
, D2D1_POINT_2F
*origins
)
1482 IDWriteFontFace1
*fontface1
= NULL
;
1483 DWRITE_FONT_METRICS metrics
;
1488 rtl_factor
= run
->bidiLevel
& 1 ? -1.0f
: 1.0f
;
1490 if (run
->fontFace
) {
1491 IDWriteFontFace_GetMetrics(run
->fontFace
, &metrics
);
1492 if (FAILED(hr
= IDWriteFontFace_QueryInterface(run
->fontFace
, &IID_IDWriteFontFace1
, (void **)&fontface1
)))
1493 WARN("Failed to get IDWriteFontFace1, %#x.\n", hr
);
1496 for (i
= 0; i
< run
->glyphCount
; i
++) {
1499 /* Use nominal advances if not provided by caller. */
1500 if (run
->glyphAdvances
)
1501 advance
= rtl_factor
* run
->glyphAdvances
[i
];
1506 switch (measuring_mode
)
1508 case DWRITE_MEASURING_MODE_NATURAL
:
1509 if (SUCCEEDED(IDWriteFontFace1_GetDesignGlyphAdvances(fontface1
, 1, run
->glyphIndices
+ i
, &a
,
1511 advance
= rtl_factor
* get_scaled_advance_width(a
, run
->fontEmSize
, &metrics
);
1513 case DWRITE_MEASURING_MODE_GDI_CLASSIC
:
1514 case DWRITE_MEASURING_MODE_GDI_NATURAL
:
1515 if (SUCCEEDED(IDWriteFontFace1_GetGdiCompatibleGlyphAdvances(fontface1
, run
->fontEmSize
,
1516 1.0f
, transform
, measuring_mode
== DWRITE_MEASURING_MODE_GDI_NATURAL
,
1517 run
->isSideways
, 1, run
->glyphIndices
+ i
, &a
)))
1518 advance
= rtl_factor
* floorf(a
* run
->fontEmSize
/ metrics
.designUnitsPerEm
+ 0.5f
);
1525 origins
[i
] = baseline_origin
;
1527 /* Apply offsets. */
1528 if (run
->glyphOffsets
) {
1529 FLOAT advanceoffset
= rtl_factor
* run
->glyphOffsets
[i
].advanceOffset
;
1530 FLOAT ascenderoffset
= -run
->glyphOffsets
[i
].ascenderOffset
;
1532 if (run
->isSideways
) {
1533 origins
[i
].x
+= ascenderoffset
;
1534 origins
[i
].y
+= advanceoffset
;
1537 origins
[i
].x
+= advanceoffset
;
1538 origins
[i
].y
+= ascenderoffset
;
1542 if (run
->isSideways
)
1543 baseline_origin
.y
+= advance
;
1545 baseline_origin
.x
+= advance
;
1549 IDWriteFontFace1_Release(fontface1
);
1553 static HRESULT WINAPI
dwritefactory4_ComputeGlyphOrigins_(IDWriteFactory5
*iface
, DWRITE_GLYPH_RUN
const *run
,
1554 D2D1_POINT_2F baseline_origin
, D2D1_POINT_2F
*origins
)
1556 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1558 TRACE("(%p)->(%p (%f,%f) %p)\n", This
, run
, baseline_origin
.x
, baseline_origin
.y
, origins
);
1560 return compute_glyph_origins(run
, DWRITE_MEASURING_MODE_NATURAL
, baseline_origin
, NULL
, origins
);
1563 static HRESULT WINAPI
dwritefactory4_ComputeGlyphOrigins(IDWriteFactory5
*iface
, DWRITE_GLYPH_RUN
const *run
,
1564 DWRITE_MEASURING_MODE measuring_mode
, D2D1_POINT_2F baseline_origin
, DWRITE_MATRIX
const *transform
,
1565 D2D1_POINT_2F
*origins
)
1567 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1569 TRACE("(%p)->(%p %d (%f,%f) %p %p)\n", This
, run
, measuring_mode
, baseline_origin
.x
, baseline_origin
.y
,
1570 transform
, origins
);
1572 return compute_glyph_origins(run
, measuring_mode
, baseline_origin
, transform
, origins
);
1575 static HRESULT WINAPI
dwritefactory5_CreateFontSetBuilder(IDWriteFactory5
*iface
, IDWriteFontSetBuilder1
**builder
)
1577 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1579 FIXME("(%p)->(%p): stub\n", This
, builder
);
1584 static HRESULT WINAPI
dwritefactory5_CreateInMemoryFontFileLoader(IDWriteFactory5
*iface
, IDWriteFontFileLoader
**loader
)
1586 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1588 FIXME("(%p)->(%p): stub\n", This
, loader
);
1593 static HRESULT WINAPI
dwritefactory5_CreateHttpFontFileLoader(IDWriteFactory5
*iface
, WCHAR
const *referrer_url
, WCHAR
const *extra_headers
,
1594 IDWriteRemoteFontFileLoader
**loader
)
1596 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1598 FIXME("(%p)->(%s %s %p): stub\n", This
, debugstr_w(referrer_url
), wine_dbgstr_w(extra_headers
), loader
);
1603 static DWRITE_CONTAINER_TYPE WINAPI
dwritefactory5_AnalyzeContainerType(IDWriteFactory5
*iface
, void const *data
, UINT32 data_size
)
1605 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1607 FIXME("(%p)->(%p %u): stub\n", This
, data
, data_size
);
1609 return DWRITE_CONTAINER_TYPE_UNKNOWN
;
1612 static HRESULT WINAPI
dwritefactory5_UnpackFontFile(IDWriteFactory5
*iface
, DWRITE_CONTAINER_TYPE container_type
, void const *data
,
1613 UINT32 data_size
, IDWriteFontFileStream
**stream
)
1615 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1617 FIXME("(%p)->(%d %p %u %p): stub\n", This
, container_type
, data
, data_size
, stream
);
1622 static const struct IDWriteFactory5Vtbl dwritefactoryvtbl
= {
1623 dwritefactory_QueryInterface
,
1624 dwritefactory_AddRef
,
1625 dwritefactory_Release
,
1626 dwritefactory_GetSystemFontCollection
,
1627 dwritefactory_CreateCustomFontCollection
,
1628 dwritefactory_RegisterFontCollectionLoader
,
1629 dwritefactory_UnregisterFontCollectionLoader
,
1630 dwritefactory_CreateFontFileReference
,
1631 dwritefactory_CreateCustomFontFileReference
,
1632 dwritefactory_CreateFontFace
,
1633 dwritefactory_CreateRenderingParams
,
1634 dwritefactory_CreateMonitorRenderingParams
,
1635 dwritefactory_CreateCustomRenderingParams
,
1636 dwritefactory_RegisterFontFileLoader
,
1637 dwritefactory_UnregisterFontFileLoader
,
1638 dwritefactory_CreateTextFormat
,
1639 dwritefactory_CreateTypography
,
1640 dwritefactory_GetGdiInterop
,
1641 dwritefactory_CreateTextLayout
,
1642 dwritefactory_CreateGdiCompatibleTextLayout
,
1643 dwritefactory_CreateEllipsisTrimmingSign
,
1644 dwritefactory_CreateTextAnalyzer
,
1645 dwritefactory_CreateNumberSubstitution
,
1646 dwritefactory_CreateGlyphRunAnalysis
,
1647 dwritefactory1_GetEudcFontCollection
,
1648 dwritefactory1_CreateCustomRenderingParams
,
1649 dwritefactory2_GetSystemFontFallback
,
1650 dwritefactory2_CreateFontFallbackBuilder
,
1651 dwritefactory2_TranslateColorGlyphRun
,
1652 dwritefactory2_CreateCustomRenderingParams
,
1653 dwritefactory2_CreateGlyphRunAnalysis
,
1654 dwritefactory3_CreateGlyphRunAnalysis
,
1655 dwritefactory3_CreateCustomRenderingParams
,
1656 dwritefactory3_CreateFontFaceReference_
,
1657 dwritefactory3_CreateFontFaceReference
,
1658 dwritefactory3_GetSystemFontSet
,
1659 dwritefactory3_CreateFontSetBuilder
,
1660 dwritefactory3_CreateFontCollectionFromFontSet
,
1661 dwritefactory3_GetSystemFontCollection
,
1662 dwritefactory3_GetFontDownloadQueue
,
1663 dwritefactory4_TranslateColorGlyphRun
,
1664 dwritefactory4_ComputeGlyphOrigins_
,
1665 dwritefactory4_ComputeGlyphOrigins
,
1666 dwritefactory5_CreateFontSetBuilder
,
1667 dwritefactory5_CreateInMemoryFontFileLoader
,
1668 dwritefactory5_CreateHttpFontFileLoader
,
1669 dwritefactory5_AnalyzeContainerType
,
1670 dwritefactory5_UnpackFontFile
,
1673 static ULONG WINAPI
shareddwritefactory_AddRef(IDWriteFactory5
*iface
)
1675 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1676 TRACE("(%p)\n", This
);
1680 static ULONG WINAPI
shareddwritefactory_Release(IDWriteFactory5
*iface
)
1682 struct dwritefactory
*This
= impl_from_IDWriteFactory5(iface
);
1683 TRACE("(%p)\n", This
);
1687 static const struct IDWriteFactory5Vtbl shareddwritefactoryvtbl
= {
1688 dwritefactory_QueryInterface
,
1689 shareddwritefactory_AddRef
,
1690 shareddwritefactory_Release
,
1691 dwritefactory_GetSystemFontCollection
,
1692 dwritefactory_CreateCustomFontCollection
,
1693 dwritefactory_RegisterFontCollectionLoader
,
1694 dwritefactory_UnregisterFontCollectionLoader
,
1695 dwritefactory_CreateFontFileReference
,
1696 dwritefactory_CreateCustomFontFileReference
,
1697 dwritefactory_CreateFontFace
,
1698 dwritefactory_CreateRenderingParams
,
1699 dwritefactory_CreateMonitorRenderingParams
,
1700 dwritefactory_CreateCustomRenderingParams
,
1701 dwritefactory_RegisterFontFileLoader
,
1702 dwritefactory_UnregisterFontFileLoader
,
1703 dwritefactory_CreateTextFormat
,
1704 dwritefactory_CreateTypography
,
1705 dwritefactory_GetGdiInterop
,
1706 dwritefactory_CreateTextLayout
,
1707 dwritefactory_CreateGdiCompatibleTextLayout
,
1708 dwritefactory_CreateEllipsisTrimmingSign
,
1709 dwritefactory_CreateTextAnalyzer
,
1710 dwritefactory_CreateNumberSubstitution
,
1711 dwritefactory_CreateGlyphRunAnalysis
,
1712 dwritefactory1_GetEudcFontCollection
,
1713 dwritefactory1_CreateCustomRenderingParams
,
1714 dwritefactory2_GetSystemFontFallback
,
1715 dwritefactory2_CreateFontFallbackBuilder
,
1716 dwritefactory2_TranslateColorGlyphRun
,
1717 dwritefactory2_CreateCustomRenderingParams
,
1718 dwritefactory2_CreateGlyphRunAnalysis
,
1719 dwritefactory3_CreateGlyphRunAnalysis
,
1720 dwritefactory3_CreateCustomRenderingParams
,
1721 dwritefactory3_CreateFontFaceReference_
,
1722 dwritefactory3_CreateFontFaceReference
,
1723 dwritefactory3_GetSystemFontSet
,
1724 dwritefactory3_CreateFontSetBuilder
,
1725 dwritefactory3_CreateFontCollectionFromFontSet
,
1726 dwritefactory3_GetSystemFontCollection
,
1727 dwritefactory3_GetFontDownloadQueue
,
1728 dwritefactory4_TranslateColorGlyphRun
,
1729 dwritefactory4_ComputeGlyphOrigins_
,
1730 dwritefactory4_ComputeGlyphOrigins
,
1731 dwritefactory5_CreateFontSetBuilder
,
1732 dwritefactory5_CreateInMemoryFontFileLoader
,
1733 dwritefactory5_CreateHttpFontFileLoader
,
1734 dwritefactory5_AnalyzeContainerType
,
1735 dwritefactory5_UnpackFontFile
,
1738 static void init_dwritefactory(struct dwritefactory
*factory
, DWRITE_FACTORY_TYPE type
)
1740 factory
->IDWriteFactory5_iface
.lpVtbl
= type
== DWRITE_FACTORY_TYPE_SHARED
?
1741 &shareddwritefactoryvtbl
: &dwritefactoryvtbl
;
1743 factory
->localfontfileloader
= NULL
;
1744 factory
->system_collection
= NULL
;
1745 factory
->eudc_collection
= NULL
;
1746 factory
->gdiinterop
= NULL
;
1747 factory
->fallback
= NULL
;
1749 list_init(&factory
->collection_loaders
);
1750 list_init(&factory
->file_loaders
);
1751 list_init(&factory
->localfontfaces
);
1754 void factory_detach_fontcollection(IDWriteFactory5
*iface
, IDWriteFontCollection1
*collection
)
1756 struct dwritefactory
*factory
= impl_from_IDWriteFactory5(iface
);
1757 if (factory
->system_collection
== collection
)
1758 factory
->system_collection
= NULL
;
1759 if (factory
->eudc_collection
== collection
)
1760 factory
->eudc_collection
= NULL
;
1761 IDWriteFactory5_Release(iface
);
1764 void factory_detach_gdiinterop(IDWriteFactory5
*iface
, IDWriteGdiInterop1
*interop
)
1766 struct dwritefactory
*factory
= impl_from_IDWriteFactory5(iface
);
1767 factory
->gdiinterop
= NULL
;
1768 IDWriteFactory5_Release(iface
);
1771 HRESULT WINAPI
DWriteCreateFactory(DWRITE_FACTORY_TYPE type
, REFIID riid
, IUnknown
**ret
)
1773 struct dwritefactory
*factory
;
1776 TRACE("(%d, %s, %p)\n", type
, debugstr_guid(riid
), ret
);
1780 if (type
== DWRITE_FACTORY_TYPE_SHARED
&& shared_factory
)
1781 return IDWriteFactory5_QueryInterface(shared_factory
, riid
, (void**)ret
);
1783 factory
= heap_alloc(sizeof(struct dwritefactory
));
1784 if (!factory
) return E_OUTOFMEMORY
;
1786 init_dwritefactory(factory
, type
);
1788 if (type
== DWRITE_FACTORY_TYPE_SHARED
)
1789 if (InterlockedCompareExchangePointer((void**)&shared_factory
, &factory
->IDWriteFactory5_iface
, NULL
)) {
1790 release_shared_factory(&factory
->IDWriteFactory5_iface
);
1791 return IDWriteFactory5_QueryInterface(shared_factory
, riid
, (void**)ret
);
1794 hr
= IDWriteFactory5_QueryInterface(&factory
->IDWriteFactory5_iface
, riid
, (void**)ret
);
1795 IDWriteFactory5_Release(&factory
->IDWriteFactory5_iface
);