Revert "winex11: Refuse to set the pixel format for HWND_MESSAGE windows."
[wine.git] / dlls / dwrite / main.c
blob09ed3f25e4ff6bf355a491cb7d7898d9db8bbf64
1 /*
2 * DWrite
4 * Copyright 2012 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
29 #include "initguid.h"
30 #include "dwrite.h"
32 #include "dwrite_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
37 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID reserved)
39 switch (reason)
41 case DLL_WINE_PREATTACH:
42 return FALSE; /* prefer native version */
43 case DLL_PROCESS_ATTACH:
44 DisableThreadLibraryCalls( hinstDLL );
45 break;
46 case DLL_PROCESS_DETACH:
47 release_system_fontcollection();
48 break;
50 return TRUE;
53 struct renderingparams {
54 IDWriteRenderingParams IDWriteRenderingParams_iface;
55 LONG ref;
57 FLOAT gamma;
58 FLOAT enh_contrast;
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))
77 *obj = iface;
78 IDWriteRenderingParams_AddRef(iface);
79 return S_OK;
82 *obj = NULL;
84 return E_NOINTERFACE;
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);
92 return 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);
102 if (!ref)
103 heap_free(This);
105 return ref;
108 static FLOAT WINAPI renderingparams_GetGamma(IDWriteRenderingParams *iface)
110 struct renderingparams *This = impl_from_IDWriteRenderingParams(iface);
111 TRACE("(%p)\n", This);
112 return This->gamma;
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);
140 return This->mode;
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;
159 *params = NULL;
161 This = heap_alloc(sizeof(struct renderingparams));
162 if (!This) return E_OUTOFMEMORY;
164 This->IDWriteRenderingParams_iface.lpVtbl = &renderingparamsvtbl;
165 This->ref = 1;
167 This->gamma = gamma;
168 This->enh_contrast = enhancedContrast;
169 This->cleartype_level = cleartype_level;
170 This->geometry = geometry;
171 This->mode = mode;
173 *params = &This->IDWriteRenderingParams_iface;
175 return S_OK;
178 struct localizedpair {
179 WCHAR *locale;
180 WCHAR *string;
183 struct localizedstrings {
184 IDWriteLocalizedStrings IDWriteLocalizedStrings_iface;
185 LONG ref;
187 struct localizedpair *data;
188 UINT32 count;
189 UINT32 alloc;
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))
205 *obj = iface;
206 IDWriteLocalizedStrings_AddRef(iface);
207 return S_OK;
210 *obj = NULL;
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);
220 return 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);
230 if (!ref) {
231 int i;
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);
239 heap_free(This);
242 return ref;
245 static UINT32 WINAPI localizedstrings_GetCount(IDWriteLocalizedStrings *iface)
247 struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface);
248 TRACE("(%p)\n", This);
249 return This->count;
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);
257 return E_NOTIMPL;
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);
264 return E_NOTIMPL;
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);
271 return E_NOTIMPL;
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;
282 return E_FAIL;
285 *length = strlenW(This->data[index].string);
286 return S_OK;
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;
297 return E_FAIL;
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);
306 return S_OK;
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;
325 *strings = NULL;
327 This = heap_alloc(sizeof(struct localizedstrings));
328 if (!This) return E_OUTOFMEMORY;
330 This->IDWriteLocalizedStrings_iface.lpVtbl = &localizedstringsvtbl;
331 This->ref = 1;
332 This->count = 0;
333 This->data = heap_alloc_zero(sizeof(struct localizedpair));
334 if (!This->data) {
335 heap_free(This);
336 return E_OUTOFMEMORY;
338 This->alloc = 1;
340 *strings = &This->IDWriteLocalizedStrings_iface;
342 return S_OK;
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) {
350 This->alloc *= 2;
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);
356 This->count++;
358 return S_OK;
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))
368 *obj = iface;
369 return S_OK;
372 *obj = NULL;
374 return E_NOINTERFACE;
377 static ULONG WINAPI dwritefactory_AddRef(IDWriteFactory *iface)
379 return 2;
382 static ULONG WINAPI dwritefactory_Release(IDWriteFactory *iface)
384 return 1;
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);
402 return E_NOTIMPL;
405 static HRESULT WINAPI dwritefactory_RegisterFontCollectionLoader(IDWriteFactory *iface,
406 IDWriteFontCollectionLoader *loader)
408 FIXME("(%p): stub\n", loader);
409 return E_NOTIMPL;
412 static HRESULT WINAPI dwritefactory_UnregisterFontCollectionLoader(IDWriteFactory *iface,
413 IDWriteFontCollectionLoader *loader)
415 FIXME("(%p): stub\n", loader);
416 return E_NOTIMPL;
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);
423 return E_NOTIMPL;
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);
430 return E_NOTIMPL;
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);
438 return E_NOTIMPL;
441 static HRESULT WINAPI dwritefactory_CreateRenderingParams(IDWriteFactory *iface, IDWriteRenderingParams **params)
443 HMONITOR monitor;
444 POINT pt;
446 TRACE("(%p)\n", params);
448 pt.x = pt.y = 0;
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);
460 if (!fixme_once++)
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);
476 return E_NOTIMPL;
479 static HRESULT WINAPI dwritefactory_UnregisterFontFileLoader(IDWriteFactory *iface, IDWriteFontFileLoader *loader)
481 FIXME("(%p): stub\n", loader);
482 return E_NOTIMPL;
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);
497 return E_NOTIMPL;
500 static HRESULT WINAPI dwritefactory_GetGdiInterop(IDWriteFactory *iface, IDWriteGdiInterop **gdi_interop)
502 TRACE("(%p)\n", gdi_interop);
503 return create_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 FIXME("(%s %u %p %f %f %p): stub\n", debugstr_w(string), len, format, max_width, max_height, layout);
511 if (!format) return E_INVALIDARG;
512 return create_textlayout(string, len, 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, layout);
526 static HRESULT WINAPI dwritefactory_CreateEllipsisTrimmingSign(IDWriteFactory *iface, IDWriteTextFormat *format,
527 IDWriteInlineObject **trimming_sign)
529 FIXME("(%p %p): stub\n", format, trimming_sign);
530 return E_NOTIMPL;
533 static HRESULT WINAPI dwritefactory_CreateTextAnalyzer(IDWriteFactory *iface, IDWriteTextAnalyzer **analyzer)
535 FIXME("(%p): stub\n", analyzer);
536 return E_NOTIMPL;
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);
543 return E_NOTIMPL;
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);
552 return E_NOTIMPL;
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;
592 return S_OK;