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 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD reason
, LPVOID reserved
)
41 case DLL_WINE_PREATTACH
:
42 return FALSE
; /* prefer native version */
43 case DLL_PROCESS_ATTACH
:
44 DisableThreadLibraryCalls( hinstDLL
);
46 case DLL_PROCESS_DETACH
:
47 release_system_fontcollection();
53 struct renderingparams
{
54 IDWriteRenderingParams IDWriteRenderingParams_iface
;
59 FLOAT cleartype_level
;
60 DWRITE_PIXEL_GEOMETRY geometry
;
61 DWRITE_RENDERING_MODE mode
;
64 static inline struct renderingparams
*impl_from_IDWriteRenderingParams(IDWriteRenderingParams
*iface
)
66 return CONTAINING_RECORD(iface
, struct renderingparams
, IDWriteRenderingParams_iface
);
69 static HRESULT WINAPI
renderingparams_QueryInterface(IDWriteRenderingParams
*iface
, REFIID riid
, void **obj
)
71 struct renderingparams
*This
= impl_from_IDWriteRenderingParams(iface
);
73 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
75 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDWriteRenderingParams
))
78 IDWriteRenderingParams_AddRef(iface
);
87 static ULONG WINAPI
renderingparams_AddRef(IDWriteRenderingParams
*iface
)
89 struct renderingparams
*This
= impl_from_IDWriteRenderingParams(iface
);
90 ULONG ref
= InterlockedIncrement(&This
->ref
);
91 TRACE("(%p)->(%d)\n", This
, ref
);
95 static ULONG WINAPI
renderingparams_Release(IDWriteRenderingParams
*iface
)
97 struct renderingparams
*This
= impl_from_IDWriteRenderingParams(iface
);
98 ULONG ref
= InterlockedDecrement(&This
->ref
);
100 TRACE("(%p)->(%d)\n", This
, ref
);
108 static FLOAT WINAPI
renderingparams_GetGamma(IDWriteRenderingParams
*iface
)
110 struct renderingparams
*This
= impl_from_IDWriteRenderingParams(iface
);
111 TRACE("(%p)\n", This
);
115 static FLOAT WINAPI
renderingparams_GetEnhancedContrast(IDWriteRenderingParams
*iface
)
117 struct renderingparams
*This
= impl_from_IDWriteRenderingParams(iface
);
118 TRACE("(%p)\n", This
);
119 return This
->enh_contrast
;
122 static FLOAT WINAPI
renderingparams_GetClearTypeLevel(IDWriteRenderingParams
*iface
)
124 struct renderingparams
*This
= impl_from_IDWriteRenderingParams(iface
);
125 TRACE("(%p)\n", This
);
126 return This
->cleartype_level
;
129 static DWRITE_PIXEL_GEOMETRY WINAPI
renderingparams_GetPixelGeometry(IDWriteRenderingParams
*iface
)
131 struct renderingparams
*This
= impl_from_IDWriteRenderingParams(iface
);
132 TRACE("(%p)\n", This
);
133 return This
->geometry
;
136 static DWRITE_RENDERING_MODE WINAPI
renderingparams_GetRenderingMode(IDWriteRenderingParams
*iface
)
138 struct renderingparams
*This
= impl_from_IDWriteRenderingParams(iface
);
139 TRACE("(%p)\n", This
);
143 static const struct IDWriteRenderingParamsVtbl renderingparamsvtbl
= {
144 renderingparams_QueryInterface
,
145 renderingparams_AddRef
,
146 renderingparams_Release
,
147 renderingparams_GetGamma
,
148 renderingparams_GetEnhancedContrast
,
149 renderingparams_GetClearTypeLevel
,
150 renderingparams_GetPixelGeometry
,
151 renderingparams_GetRenderingMode
154 static HRESULT
create_renderingparams(FLOAT gamma
, FLOAT enhancedContrast
, FLOAT cleartype_level
,
155 DWRITE_PIXEL_GEOMETRY geometry
, DWRITE_RENDERING_MODE mode
, IDWriteRenderingParams
**params
)
157 struct renderingparams
*This
;
161 This
= heap_alloc(sizeof(struct renderingparams
));
162 if (!This
) return E_OUTOFMEMORY
;
164 This
->IDWriteRenderingParams_iface
.lpVtbl
= &renderingparamsvtbl
;
168 This
->enh_contrast
= enhancedContrast
;
169 This
->cleartype_level
= cleartype_level
;
170 This
->geometry
= geometry
;
173 *params
= &This
->IDWriteRenderingParams_iface
;
178 struct localizedpair
{
183 struct localizedstrings
{
184 IDWriteLocalizedStrings IDWriteLocalizedStrings_iface
;
187 struct localizedpair
*data
;
192 static inline struct localizedstrings
*impl_from_IDWriteLocalizedStrings(IDWriteLocalizedStrings
*iface
)
194 return CONTAINING_RECORD(iface
, struct localizedstrings
, IDWriteLocalizedStrings_iface
);
197 static HRESULT WINAPI
localizedstrings_QueryInterface(IDWriteLocalizedStrings
*iface
, REFIID riid
, void **obj
)
199 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
201 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
203 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDWriteLocalizedStrings
))
206 IDWriteLocalizedStrings_AddRef(iface
);
212 return E_NOINTERFACE
;
215 static ULONG WINAPI
localizedstrings_AddRef(IDWriteLocalizedStrings
*iface
)
217 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
218 ULONG ref
= InterlockedIncrement(&This
->ref
);
219 TRACE("(%p)->(%d)\n", This
, ref
);
223 static ULONG WINAPI
localizedstrings_Release(IDWriteLocalizedStrings
*iface
)
225 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
226 ULONG ref
= InterlockedDecrement(&This
->ref
);
228 TRACE("(%p)->(%d)\n", This
, ref
);
233 for (i
= 0; i
< This
->count
; i
++) {
234 heap_free(This
->data
[i
].locale
);
235 heap_free(This
->data
[i
].string
);
238 heap_free(This
->data
);
245 static UINT32 WINAPI
localizedstrings_GetCount(IDWriteLocalizedStrings
*iface
)
247 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
248 TRACE("(%p)\n", This
);
252 static HRESULT WINAPI
localizedstrings_FindLocaleName(IDWriteLocalizedStrings
*iface
,
253 WCHAR
const *locale_name
, UINT32
*index
, BOOL
*exists
)
255 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
256 FIXME("(%p)->(%s %p %p): stub\n", This
, debugstr_w(locale_name
), index
, exists
);
260 static HRESULT WINAPI
localizedstrings_GetLocaleNameLength(IDWriteLocalizedStrings
*iface
, UINT32 index
, UINT32
*length
)
262 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
263 FIXME("(%p)->(%u %p): stub\n", This
, index
, length
);
267 static HRESULT WINAPI
localizedstrings_GetLocaleName(IDWriteLocalizedStrings
*iface
, UINT32 index
, WCHAR
*locale_name
, UINT32 size
)
269 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
270 FIXME("(%p)->(%u %p %u): stub\n", This
, index
, locale_name
, size
);
274 static HRESULT WINAPI
localizedstrings_GetStringLength(IDWriteLocalizedStrings
*iface
, UINT32 index
, UINT32
*length
)
276 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
278 TRACE("(%p)->(%u %p)\n", This
, index
, length
);
280 if (index
>= This
->count
) {
281 *length
= (UINT32
)-1;
285 *length
= strlenW(This
->data
[index
].string
);
289 static HRESULT WINAPI
localizedstrings_GetString(IDWriteLocalizedStrings
*iface
, UINT32 index
, WCHAR
*buffer
, UINT32 size
)
291 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
293 TRACE("(%p)->(%u %p %u)\n", This
, index
, buffer
, size
);
295 if (index
>= This
->count
) {
296 if (buffer
) *buffer
= 0;
300 if (size
< strlenW(This
->data
[index
].string
)+1) {
301 if (buffer
) *buffer
= 0;
302 return E_NOT_SUFFICIENT_BUFFER
;
305 strcpyW(buffer
, This
->data
[index
].string
);
309 static const IDWriteLocalizedStringsVtbl localizedstringsvtbl
= {
310 localizedstrings_QueryInterface
,
311 localizedstrings_AddRef
,
312 localizedstrings_Release
,
313 localizedstrings_GetCount
,
314 localizedstrings_FindLocaleName
,
315 localizedstrings_GetLocaleNameLength
,
316 localizedstrings_GetLocaleName
,
317 localizedstrings_GetStringLength
,
318 localizedstrings_GetString
321 HRESULT
create_localizedstrings(IDWriteLocalizedStrings
**strings
)
323 struct localizedstrings
*This
;
327 This
= heap_alloc(sizeof(struct localizedstrings
));
328 if (!This
) return E_OUTOFMEMORY
;
330 This
->IDWriteLocalizedStrings_iface
.lpVtbl
= &localizedstringsvtbl
;
333 This
->data
= heap_alloc_zero(sizeof(struct localizedpair
));
336 return E_OUTOFMEMORY
;
340 *strings
= &This
->IDWriteLocalizedStrings_iface
;
345 HRESULT
add_localizedstring(IDWriteLocalizedStrings
*iface
, const WCHAR
*locale
, const WCHAR
*string
)
347 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
349 if (This
->count
== This
->alloc
) {
351 This
->data
= heap_realloc(This
->data
, This
->alloc
*sizeof(struct localizedpair
));
354 This
->data
[This
->count
].locale
= heap_strdupW(locale
);
355 This
->data
[This
->count
].string
= heap_strdupW(string
);
361 static HRESULT WINAPI
dwritefactory_QueryInterface(IDWriteFactory
*iface
, REFIID riid
, void **obj
)
363 TRACE("(%s %p)\n", debugstr_guid(riid
), obj
);
365 if (IsEqualIID(riid
, &IID_IUnknown
) ||
366 IsEqualIID(riid
, &IID_IDWriteFactory
))
374 return E_NOINTERFACE
;
377 static ULONG WINAPI
dwritefactory_AddRef(IDWriteFactory
*iface
)
382 static ULONG WINAPI
dwritefactory_Release(IDWriteFactory
*iface
)
387 static HRESULT WINAPI
dwritefactory_GetSystemFontCollection(IDWriteFactory
*iface
,
388 IDWriteFontCollection
**collection
, BOOL check_for_updates
)
390 TRACE("(%p %d)\n", collection
, check_for_updates
);
392 if (check_for_updates
)
393 FIXME("checking for system font updates not implemented\n");
395 return get_system_fontcollection(collection
);
398 static HRESULT WINAPI
dwritefactory_CreateCustomFontCollection(IDWriteFactory
*iface
,
399 IDWriteFontCollectionLoader
*loader
, void const *key
, UINT32 key_size
, IDWriteFontCollection
**collection
)
401 FIXME("(%p %p %u %p): stub\n", loader
, key
, key_size
, collection
);
405 static HRESULT WINAPI
dwritefactory_RegisterFontCollectionLoader(IDWriteFactory
*iface
,
406 IDWriteFontCollectionLoader
*loader
)
408 FIXME("(%p): stub\n", loader
);
412 static HRESULT WINAPI
dwritefactory_UnregisterFontCollectionLoader(IDWriteFactory
*iface
,
413 IDWriteFontCollectionLoader
*loader
)
415 FIXME("(%p): stub\n", loader
);
419 static HRESULT WINAPI
dwritefactory_CreateFontFileReference(IDWriteFactory
*iface
,
420 WCHAR
const *path
, FILETIME
const *writetime
, IDWriteFontFile
**font_file
)
422 FIXME("(%s %p %p): stub\n", debugstr_w(path
), writetime
, font_file
);
426 static HRESULT WINAPI
dwritefactory_CreateCustomFontFileReference(IDWriteFactory
*iface
,
427 void const *reference_key
, UINT32 key_size
, IDWriteFontFileLoader
*loader
, IDWriteFontFile
**font_file
)
429 FIXME("(%p %u %p %p): stub\n", reference_key
, key_size
, loader
, font_file
);
433 static HRESULT WINAPI
dwritefactory_CreateFontFace(IDWriteFactory
*iface
,
434 DWRITE_FONT_FACE_TYPE facetype
, UINT32 files_number
, IDWriteFontFile
* const* font_files
,
435 UINT32 index
, DWRITE_FONT_SIMULATIONS sim_flags
, IDWriteFontFace
**font_face
)
437 FIXME("(%d %u %p %u 0x%x %p): stub\n", facetype
, files_number
, font_files
, index
, sim_flags
, font_face
);
441 static HRESULT WINAPI
dwritefactory_CreateRenderingParams(IDWriteFactory
*iface
, IDWriteRenderingParams
**params
)
446 TRACE("(%p)\n", params
);
449 monitor
= MonitorFromPoint(pt
, MONITOR_DEFAULTTOPRIMARY
);
450 return IDWriteFactory_CreateMonitorRenderingParams(iface
, monitor
, params
);
453 static HRESULT WINAPI
dwritefactory_CreateMonitorRenderingParams(IDWriteFactory
*iface
, HMONITOR monitor
,
454 IDWriteRenderingParams
**params
)
456 static int fixme_once
= 0;
458 TRACE("(%p %p)\n", monitor
, params
);
461 FIXME("(%p): monitor setting ignored\n", monitor
);
462 return IDWriteFactory_CreateCustomRenderingParams(iface
, 0.0, 0.0, 0.0, DWRITE_PIXEL_GEOMETRY_FLAT
,
463 DWRITE_RENDERING_MODE_DEFAULT
, params
);
466 static HRESULT WINAPI
dwritefactory_CreateCustomRenderingParams(IDWriteFactory
*iface
, FLOAT gamma
, FLOAT enhancedContrast
,
467 FLOAT cleartype_level
, DWRITE_PIXEL_GEOMETRY geometry
, DWRITE_RENDERING_MODE mode
, IDWriteRenderingParams
**params
)
469 TRACE("(%f %f %f %d %d %p)\n", gamma
, enhancedContrast
, cleartype_level
, geometry
, mode
, params
);
470 return create_renderingparams(gamma
, enhancedContrast
, cleartype_level
, geometry
, mode
, params
);
473 static HRESULT WINAPI
dwritefactory_RegisterFontFileLoader(IDWriteFactory
*iface
, IDWriteFontFileLoader
*loader
)
475 FIXME("(%p): stub\n", loader
);
479 static HRESULT WINAPI
dwritefactory_UnregisterFontFileLoader(IDWriteFactory
*iface
, IDWriteFontFileLoader
*loader
)
481 FIXME("(%p): stub\n", loader
);
485 static HRESULT WINAPI
dwritefactory_CreateTextFormat(IDWriteFactory
*iface
, WCHAR
const* family_name
,
486 IDWriteFontCollection
*collection
, DWRITE_FONT_WEIGHT weight
, DWRITE_FONT_STYLE style
,
487 DWRITE_FONT_STRETCH stretch
, FLOAT size
, WCHAR
const *locale
, IDWriteTextFormat
**format
)
489 TRACE("(%s %p %d %d %d %f %s %p)\n", debugstr_w(family_name
), collection
, weight
, style
, stretch
,
490 size
, debugstr_w(locale
), format
);
491 return create_textformat(family_name
, collection
, weight
, style
, stretch
, size
, locale
, format
);
494 static HRESULT WINAPI
dwritefactory_CreateTypography(IDWriteFactory
*iface
, IDWriteTypography
**typography
)
496 FIXME("(%p): stub\n", typography
);
500 static HRESULT WINAPI
dwritefactory_GetGdiInterop(IDWriteFactory
*iface
, IDWriteGdiInterop
**gdi_interop
)
502 TRACE("(%p)\n", gdi_interop
);
503 return get_gdiinterop(gdi_interop
);
506 static HRESULT WINAPI
dwritefactory_CreateTextLayout(IDWriteFactory
*iface
, WCHAR
const* string
,
507 UINT32 len
, IDWriteTextFormat
*format
, FLOAT max_width
, FLOAT max_height
, IDWriteTextLayout
**layout
)
509 TRACE("(%s %u %p %f %f %p)\n", debugstr_w(string
), len
, format
, max_width
, max_height
, layout
);
511 if (!format
) return E_INVALIDARG
;
512 return create_textlayout(string
, len
, format
, layout
);
515 static HRESULT WINAPI
dwritefactory_CreateGdiCompatibleTextLayout(IDWriteFactory
*iface
, WCHAR
const* string
,
516 UINT32 len
, IDWriteTextFormat
*format
, FLOAT layout_width
, FLOAT layout_height
, FLOAT pixels_per_dip
,
517 DWRITE_MATRIX
const* transform
, BOOL use_gdi_natural
, IDWriteTextLayout
**layout
)
519 FIXME("(%s:%u %p %f %f %f %p %d %p): semi-stub\n", debugstr_wn(string
, len
), len
, format
, layout_width
, layout_height
,
520 pixels_per_dip
, transform
, use_gdi_natural
, layout
);
522 if (!format
) return E_INVALIDARG
;
523 return create_textlayout(string
, len
, format
, layout
);
526 static HRESULT WINAPI
dwritefactory_CreateEllipsisTrimmingSign(IDWriteFactory
*iface
, IDWriteTextFormat
*format
,
527 IDWriteInlineObject
**trimming_sign
)
529 FIXME("(%p %p): stub\n", format
, trimming_sign
);
533 static HRESULT WINAPI
dwritefactory_CreateTextAnalyzer(IDWriteFactory
*iface
, IDWriteTextAnalyzer
**analyzer
)
535 TRACE("(%p)\n", analyzer
);
536 return get_textanalyzer(analyzer
);
539 static HRESULT WINAPI
dwritefactory_CreateNumberSubstitution(IDWriteFactory
*iface
, DWRITE_NUMBER_SUBSTITUTION_METHOD method
,
540 WCHAR
const* locale
, BOOL ignore_user_override
, IDWriteNumberSubstitution
**substitution
)
542 FIXME("(%d %s %d %p): stub\n", method
, debugstr_w(locale
), ignore_user_override
, substitution
);
546 static HRESULT WINAPI
dwritefactory_CreateGlyphRunAnalysis(IDWriteFactory
*iface
, DWRITE_GLYPH_RUN
const *glyph_run
,
547 FLOAT pixels_per_dip
, DWRITE_MATRIX
const* transform
, DWRITE_RENDERING_MODE rendering_mode
,
548 DWRITE_MEASURING_MODE measuring_mode
, FLOAT baseline_x
, FLOAT baseline_y
, IDWriteGlyphRunAnalysis
**analysis
)
550 FIXME("(%p %f %p %d %d %f %f %p): stub\n", glyph_run
, pixels_per_dip
, transform
, rendering_mode
,
551 measuring_mode
, baseline_x
, baseline_y
, analysis
);
555 static const struct IDWriteFactoryVtbl dwritefactoryvtbl
= {
556 dwritefactory_QueryInterface
,
557 dwritefactory_AddRef
,
558 dwritefactory_Release
,
559 dwritefactory_GetSystemFontCollection
,
560 dwritefactory_CreateCustomFontCollection
,
561 dwritefactory_RegisterFontCollectionLoader
,
562 dwritefactory_UnregisterFontCollectionLoader
,
563 dwritefactory_CreateFontFileReference
,
564 dwritefactory_CreateCustomFontFileReference
,
565 dwritefactory_CreateFontFace
,
566 dwritefactory_CreateRenderingParams
,
567 dwritefactory_CreateMonitorRenderingParams
,
568 dwritefactory_CreateCustomRenderingParams
,
569 dwritefactory_RegisterFontFileLoader
,
570 dwritefactory_UnregisterFontFileLoader
,
571 dwritefactory_CreateTextFormat
,
572 dwritefactory_CreateTypography
,
573 dwritefactory_GetGdiInterop
,
574 dwritefactory_CreateTextLayout
,
575 dwritefactory_CreateGdiCompatibleTextLayout
,
576 dwritefactory_CreateEllipsisTrimmingSign
,
577 dwritefactory_CreateTextAnalyzer
,
578 dwritefactory_CreateNumberSubstitution
,
579 dwritefactory_CreateGlyphRunAnalysis
582 static IDWriteFactory dwritefactory
= { &dwritefactoryvtbl
};
584 HRESULT WINAPI
DWriteCreateFactory(DWRITE_FACTORY_TYPE type
, REFIID riid
, IUnknown
**factory
)
586 TRACE("(%d, %s, %p)\n", type
, debugstr_guid(riid
), factory
);
588 if (!IsEqualIID(riid
, &IID_IDWriteFactory
)) return E_FAIL
;
590 *factory
= (IUnknown
*)&dwritefactory
;