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): semi-stub\n", collection, check_for_updates);
388 return create_fontcollection(collection);
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 TRACE("(%s %p %d %d %d %f %s %p)\n", debugstr_w(family_name), collection, weight, style, stretch,
483 size, debugstr_w(locale), format);
486 FIXME("font collection not supported\n");
488 return create_textformat(family_name, weight, style, stretch, size, locale, format);
491 static HRESULT WINAPI dwritefactory_CreateTypography(IDWriteFactory *iface, IDWriteTypography **typography)
493 FIXME("(%p): stub\n", typography);
497 static HRESULT WINAPI dwritefactory_GetGdiInterop(IDWriteFactory *iface, IDWriteGdiInterop **gdi_interop)
499 TRACE("(%p)\n", gdi_interop);
500 return create_gdiinterop(gdi_interop);
503 static HRESULT WINAPI dwritefactory_CreateTextLayout(IDWriteFactory *iface, WCHAR const* string,
504 UINT32 len, IDWriteTextFormat *format, FLOAT max_width, FLOAT max_height, IDWriteTextLayout **layout)
506 FIXME("(%s %u %p %f %f %p): stub\n", debugstr_w(string), len, format, max_width, max_height, layout);
508 if (!format) return E_INVALIDARG;
509 return create_textlayout(string, len, layout);
512 static HRESULT WINAPI dwritefactory_CreateGdiCompatibleTextLayout(IDWriteFactory *iface, WCHAR const* string,
513 UINT32 len, IDWriteTextFormat *format, FLOAT layout_width, FLOAT layout_height, FLOAT pixels_per_dip,
514 DWRITE_MATRIX const* transform, BOOL use_gdi_natural, IDWriteTextLayout **layout)
516 FIXME("(%s:%u %p %f %f %f %p %d %p): semi-stub\n", debugstr_wn(string, len), len, format, layout_width, layout_height,
517 pixels_per_dip, transform, use_gdi_natural, layout);
519 if (!format) return E_INVALIDARG;
520 return create_textlayout(string, len, layout);
523 static HRESULT WINAPI dwritefactory_CreateEllipsisTrimmingSign(IDWriteFactory *iface, IDWriteTextFormat *format,
524 IDWriteInlineObject **trimming_sign)
526 FIXME("(%p %p): stub\n", format, trimming_sign);
530 static HRESULT WINAPI dwritefactory_CreateTextAnalyzer(IDWriteFactory *iface, IDWriteTextAnalyzer **analyzer)
532 FIXME("(%p): stub\n", analyzer);
536 static HRESULT WINAPI dwritefactory_CreateNumberSubstitution(IDWriteFactory *iface, DWRITE_NUMBER_SUBSTITUTION_METHOD method,
537 WCHAR const* locale, BOOL ignore_user_override, IDWriteNumberSubstitution **substitution)
539 FIXME("(%d %s %d %p): stub\n", method, debugstr_w(locale), ignore_user_override, substitution);
543 static HRESULT WINAPI dwritefactory_CreateGlyphRunAnalysis(IDWriteFactory *iface, DWRITE_GLYPH_RUN const *glyph_run,
544 FLOAT pixels_per_dip, DWRITE_MATRIX const* transform, DWRITE_RENDERING_MODE rendering_mode,
545 DWRITE_MEASURING_MODE measuring_mode, FLOAT baseline_x, FLOAT baseline_y, IDWriteGlyphRunAnalysis **analysis)
547 FIXME("(%p %f %p %d %d %f %f %p): stub\n", glyph_run, pixels_per_dip, transform, rendering_mode,
548 measuring_mode, baseline_x, baseline_y, analysis);
552 static const struct IDWriteFactoryVtbl dwritefactoryvtbl = {
553 dwritefactory_QueryInterface,
554 dwritefactory_AddRef,
555 dwritefactory_Release,
556 dwritefactory_GetSystemFontCollection,
557 dwritefactory_CreateCustomFontCollection,
558 dwritefactory_RegisterFontCollectionLoader,
559 dwritefactory_UnregisterFontCollectionLoader,
560 dwritefactory_CreateFontFileReference,
561 dwritefactory_CreateCustomFontFileReference,
562 dwritefactory_CreateFontFace,
563 dwritefactory_CreateRenderingParams,
564 dwritefactory_CreateMonitorRenderingParams,
565 dwritefactory_CreateCustomRenderingParams,
566 dwritefactory_RegisterFontFileLoader,
567 dwritefactory_UnregisterFontFileLoader,
568 dwritefactory_CreateTextFormat,
569 dwritefactory_CreateTypography,
570 dwritefactory_GetGdiInterop,
571 dwritefactory_CreateTextLayout,
572 dwritefactory_CreateGdiCompatibleTextLayout,
573 dwritefactory_CreateEllipsisTrimmingSign,
574 dwritefactory_CreateTextAnalyzer,
575 dwritefactory_CreateNumberSubstitution,
576 dwritefactory_CreateGlyphRunAnalysis
579 static IDWriteFactory dwritefactory = { &dwritefactoryvtbl };
581 HRESULT WINAPI DWriteCreateFactory(DWRITE_FACTORY_TYPE type, REFIID riid, IUnknown **factory)
583 TRACE("(%d, %s, %p)\n", type, debugstr_guid(riid), factory);
585 if (!IsEqualIID(riid, &IID_IDWriteFactory)) return E_FAIL;
587 *factory = (IUnknown*)&dwritefactory;