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
);
50 struct renderingparams
{
51 IDWriteRenderingParams IDWriteRenderingParams_iface
;
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
))
75 IDWriteRenderingParams_AddRef(iface
);
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
);
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
);
105 static FLOAT WINAPI
renderingparams_GetGamma(IDWriteRenderingParams
*iface
)
107 struct renderingparams
*This
= impl_from_IDWriteRenderingParams(iface
);
108 TRACE("(%p)\n", This
);
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
);
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
;
158 This
= heap_alloc(sizeof(struct renderingparams
));
159 if (!This
) return E_OUTOFMEMORY
;
161 This
->IDWriteRenderingParams_iface
.lpVtbl
= &renderingparamsvtbl
;
165 This
->enh_contrast
= enhancedContrast
;
166 This
->cleartype_level
= cleartype_level
;
167 This
->geometry
= geometry
;
170 *params
= &This
->IDWriteRenderingParams_iface
;
175 struct localizedpair
{
180 struct localizedstrings
{
181 IDWriteLocalizedStrings IDWriteLocalizedStrings_iface
;
184 struct localizedpair
*data
;
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
))
203 IDWriteLocalizedStrings_AddRef(iface
);
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
);
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
);
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
);
242 static UINT32 WINAPI
localizedstrings_GetCount(IDWriteLocalizedStrings
*iface
)
244 struct localizedstrings
*This
= impl_from_IDWriteLocalizedStrings(iface
);
245 TRACE("(%p)\n", This
);
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
);
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
);
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
);
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;
282 *length
= strlenW(This
->data
[index
].string
);
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;
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
);
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
;
324 This
= heap_alloc(sizeof(struct localizedstrings
));
325 if (!This
) return E_OUTOFMEMORY
;
327 This
->IDWriteLocalizedStrings_iface
.lpVtbl
= &localizedstringsvtbl
;
330 This
->data
= heap_alloc_zero(sizeof(struct localizedpair
));
333 return E_OUTOFMEMORY
;
337 *strings
= &This
->IDWriteLocalizedStrings_iface
;
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
) {
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
);
358 static HRESULT WINAPI
dwritefactory_QueryInterface(IDWriteFactory
*iface
, REFIID riid
, void **obj
)
360 TRACE("(%s %p)\n", debugstr_guid(riid
), obj
);
362 if (IsEqualIID(riid
, &IID_IUnknown
) ||
363 IsEqualIID(riid
, &IID_IDWriteFactory
))
371 return E_NOINTERFACE
;
374 static ULONG WINAPI
dwritefactory_AddRef(IDWriteFactory
*iface
)
379 static ULONG WINAPI
dwritefactory_Release(IDWriteFactory
*iface
)
384 static HRESULT WINAPI
dwritefactory_GetSystemFontCollection(IDWriteFactory
*iface
,
385 IDWriteFontCollection
**collection
, BOOL check_for_updates
)
387 FIXME("(%p %d): stub\n", collection
, check_for_updates
);
391 static HRESULT WINAPI
dwritefactory_CreateCustomFontCollection(IDWriteFactory
*iface
,
392 IDWriteFontCollectionLoader
*loader
, void const *key
, UINT32 key_size
, IDWriteFontCollection
**collection
)
394 FIXME("(%p %p %u %p): stub\n", loader
, key
, key_size
, collection
);
398 static HRESULT WINAPI
dwritefactory_RegisterFontCollectionLoader(IDWriteFactory
*iface
,
399 IDWriteFontCollectionLoader
*loader
)
401 FIXME("(%p): stub\n", loader
);
405 static HRESULT WINAPI
dwritefactory_UnregisterFontCollectionLoader(IDWriteFactory
*iface
,
406 IDWriteFontCollectionLoader
*loader
)
408 FIXME("(%p): stub\n", loader
);
412 static HRESULT WINAPI
dwritefactory_CreateFontFileReference(IDWriteFactory
*iface
,
413 WCHAR
const *path
, FILETIME
const *writetime
, IDWriteFontFile
**font_file
)
415 FIXME("(%s %p %p): stub\n", debugstr_w(path
), writetime
, font_file
);
419 static HRESULT WINAPI
dwritefactory_CreateCustomFontFileReference(IDWriteFactory
*iface
,
420 void const *reference_key
, UINT32 key_size
, IDWriteFontFileLoader
*loader
, IDWriteFontFile
**font_file
)
422 FIXME("(%p %u %p %p): stub\n", reference_key
, key_size
, loader
, font_file
);
426 static HRESULT WINAPI
dwritefactory_CreateFontFace(IDWriteFactory
*iface
,
427 DWRITE_FONT_FACE_TYPE facetype
, UINT32 files_number
, IDWriteFontFile
* const* font_files
,
428 UINT32 index
, DWRITE_FONT_SIMULATIONS sim_flags
, IDWriteFontFace
**font_face
)
430 FIXME("(%d %u %p %u 0x%x %p): stub\n", facetype
, files_number
, font_files
, index
, sim_flags
, font_face
);
434 static HRESULT WINAPI
dwritefactory_CreateRenderingParams(IDWriteFactory
*iface
, IDWriteRenderingParams
**params
)
439 TRACE("(%p)\n", params
);
442 monitor
= MonitorFromPoint(pt
, MONITOR_DEFAULTTOPRIMARY
);
443 return IDWriteFactory_CreateMonitorRenderingParams(iface
, monitor
, params
);
446 static HRESULT WINAPI
dwritefactory_CreateMonitorRenderingParams(IDWriteFactory
*iface
, HMONITOR monitor
,
447 IDWriteRenderingParams
**params
)
449 static int fixme_once
= 0;
451 TRACE("(%p %p)\n", monitor
, params
);
454 FIXME("(%p): monitor setting ignored\n", monitor
);
455 return IDWriteFactory_CreateCustomRenderingParams(iface
, 0.0, 0.0, 0.0, DWRITE_PIXEL_GEOMETRY_FLAT
,
456 DWRITE_RENDERING_MODE_DEFAULT
, params
);
459 static HRESULT WINAPI
dwritefactory_CreateCustomRenderingParams(IDWriteFactory
*iface
, FLOAT gamma
, FLOAT enhancedContrast
,
460 FLOAT cleartype_level
, DWRITE_PIXEL_GEOMETRY geometry
, DWRITE_RENDERING_MODE mode
, IDWriteRenderingParams
**params
)
462 TRACE("(%f %f %f %d %d %p)\n", gamma
, enhancedContrast
, cleartype_level
, geometry
, mode
, params
);
463 return create_renderingparams(gamma
, enhancedContrast
, cleartype_level
, geometry
, mode
, params
);
466 static HRESULT WINAPI
dwritefactory_RegisterFontFileLoader(IDWriteFactory
*iface
, IDWriteFontFileLoader
*loader
)
468 FIXME("(%p): stub\n", loader
);
472 static HRESULT WINAPI
dwritefactory_UnregisterFontFileLoader(IDWriteFactory
*iface
, IDWriteFontFileLoader
*loader
)
474 FIXME("(%p): stub\n", loader
);
478 static HRESULT WINAPI
dwritefactory_CreateTextFormat(IDWriteFactory
*iface
, WCHAR
const* family_name
,
479 IDWriteFontCollection
*collection
, DWRITE_FONT_WEIGHT weight
, DWRITE_FONT_STYLE style
,
480 DWRITE_FONT_STRETCH stretch
, FLOAT size
, WCHAR
const *locale
, IDWriteTextFormat
**format
)
482 FIXME("(%s %p %d %d %d %f %s %p): stub\n", debugstr_w(family_name
), collection
, weight
, style
, stretch
,
483 size
, debugstr_w(locale
), format
);
487 static HRESULT WINAPI
dwritefactory_CreateTypography(IDWriteFactory
*iface
, IDWriteTypography
**typography
)
489 FIXME("(%p): stub\n", typography
);
493 static HRESULT WINAPI
dwritefactory_GetGdiInterop(IDWriteFactory
*iface
, IDWriteGdiInterop
**gdi_interop
)
495 TRACE("(%p)\n", gdi_interop
);
496 return create_gdiinterop(gdi_interop
);
499 static HRESULT WINAPI
dwritefactory_CreateTextLayout(IDWriteFactory
*iface
, WCHAR
const* string
,
500 UINT32 len
, IDWriteTextFormat
*format
, FLOAT max_width
, FLOAT max_height
, IDWriteTextLayout
**layout
)
502 FIXME("(%s %u %p %f %f %p): stub\n", debugstr_w(string
), len
, format
, max_width
, max_height
, layout
);
504 if (!format
) return E_INVALIDARG
;
505 return create_textlayout(layout
);
508 static HRESULT WINAPI
dwritefactory_CreateGdiCompatibleTextLayout(IDWriteFactory
*iface
, WCHAR
const* string
,
509 UINT32 len
, IDWriteTextFormat
*format
, FLOAT layout_width
, FLOAT layout_height
, FLOAT pixels_per_dip
,
510 DWRITE_MATRIX
const* transform
, BOOL use_gdi_natural
, IDWriteTextLayout
**layout
)
512 FIXME("(%s:%u %p %f %f %f %p %d %p): semi-stub\n", debugstr_wn(string
, len
), len
, format
, layout_width
, layout_height
,
513 pixels_per_dip
, transform
, use_gdi_natural
, layout
);
515 if (!format
) return E_INVALIDARG
;
516 return create_textlayout(layout
);
519 static HRESULT WINAPI
dwritefactory_CreateEllipsisTrimmingSign(IDWriteFactory
*iface
, IDWriteTextFormat
*format
,
520 IDWriteInlineObject
**trimming_sign
)
522 FIXME("(%p %p): stub\n", format
, trimming_sign
);
526 static HRESULT WINAPI
dwritefactory_CreateTextAnalyzer(IDWriteFactory
*iface
, IDWriteTextAnalyzer
**analyzer
)
528 FIXME("(%p): stub\n", analyzer
);
532 static HRESULT WINAPI
dwritefactory_CreateNumberSubstitution(IDWriteFactory
*iface
, DWRITE_NUMBER_SUBSTITUTION_METHOD method
,
533 WCHAR
const* locale
, BOOL ignore_user_override
, IDWriteNumberSubstitution
**substitution
)
535 FIXME("(%d %s %d %p): stub\n", method
, debugstr_w(locale
), ignore_user_override
, substitution
);
539 static HRESULT WINAPI
dwritefactory_CreateGlyphRunAnalysis(IDWriteFactory
*iface
, DWRITE_GLYPH_RUN
const *glyph_run
,
540 FLOAT pixels_per_dip
, DWRITE_MATRIX
const* transform
, DWRITE_RENDERING_MODE rendering_mode
,
541 DWRITE_MEASURING_MODE measuring_mode
, FLOAT baseline_x
, FLOAT baseline_y
, IDWriteGlyphRunAnalysis
**analysis
)
543 FIXME("(%p %f %p %d %d %f %f %p): stub\n", glyph_run
, pixels_per_dip
, transform
, rendering_mode
,
544 measuring_mode
, baseline_x
, baseline_y
, analysis
);
548 static const struct IDWriteFactoryVtbl dwritefactoryvtbl
= {
549 dwritefactory_QueryInterface
,
550 dwritefactory_AddRef
,
551 dwritefactory_Release
,
552 dwritefactory_GetSystemFontCollection
,
553 dwritefactory_CreateCustomFontCollection
,
554 dwritefactory_RegisterFontCollectionLoader
,
555 dwritefactory_UnregisterFontCollectionLoader
,
556 dwritefactory_CreateFontFileReference
,
557 dwritefactory_CreateCustomFontFileReference
,
558 dwritefactory_CreateFontFace
,
559 dwritefactory_CreateRenderingParams
,
560 dwritefactory_CreateMonitorRenderingParams
,
561 dwritefactory_CreateCustomRenderingParams
,
562 dwritefactory_RegisterFontFileLoader
,
563 dwritefactory_UnregisterFontFileLoader
,
564 dwritefactory_CreateTextFormat
,
565 dwritefactory_CreateTypography
,
566 dwritefactory_GetGdiInterop
,
567 dwritefactory_CreateTextLayout
,
568 dwritefactory_CreateGdiCompatibleTextLayout
,
569 dwritefactory_CreateEllipsisTrimmingSign
,
570 dwritefactory_CreateTextAnalyzer
,
571 dwritefactory_CreateNumberSubstitution
,
572 dwritefactory_CreateGlyphRunAnalysis
575 static IDWriteFactory dwritefactory
= { &dwritefactoryvtbl
};
577 HRESULT WINAPI
DWriteCreateFactory(DWRITE_FACTORY_TYPE type
, REFIID riid
, IUnknown
**factory
)
579 TRACE("(%d, %s, %p)\n", type
, debugstr_guid(riid
), factory
);
581 if (!IsEqualIID(riid
, &IID_IDWriteFactory
)) return E_FAIL
;
583 *factory
= (IUnknown
*)&dwritefactory
;